Travail sur évaluation thread

This commit is contained in:
François Merciol 2018-07-27 14:17:19 +02:00
parent 6aafd77873
commit d0af1d3162
5 changed files with 247 additions and 25 deletions

View File

@ -1,5 +1,6 @@
## DIR #################################
SRC_DIR = .
TST_DIR = $(SRC_DIR)/test
CPP_DIR = $(SRC_DIR)/src
HPP_DIR = $(SRC_DIR)/include
BLD_DIR = build
@ -8,6 +9,11 @@ LIB_DIR = $(BLD_DIR)/lib
OBJ_DIR = $(BLD_DIR)/obj
## PRG #################################
TRSK_MOD = IImage triskeleArrayTreeBase Tree triskeleDebug TreeStats triskeleBase QuadTreeBuilder Option Selected
TRSK_OBJ = $(patsubst %, $(OBJ_DIR)/%.o, $(TRSK_MOD))
TRSK_OBJ_XML = $(TRSK_OBJ) $(OBJ_DIR)/XMLTreeBuilder.o
APG_PRG = apGenerator
APG_SRC = $(patsubst %, $(CPP_DIR)/%.cpp, $(APG_PRG))
APG_OUT = $(patsubst %, $(OUT_DIR)/%, $(APG_PRG))
@ -20,45 +26,57 @@ PRF_PRG = PerfArrayTreeBuilder
PRF_SRC = $(patsubst %, $(CPP_DIR)/%.cpp, $(PRF_PRG))
PRF_OUT = $(patsubst %, $(OUT_DIR)/%, $(PRF_PRG))
TTH_MOD = TestDeal
TTH_PRG = TestThread
TTH_SRC = $(patsubst %, $(TST_DIR)/%.cpp, $(TTH_PRG))
TTH_OBJ = $(patsubst %, $(OBJ_DIR)/%.o, $(TTH_MOD))
TTH_OUT = $(patsubst %, $(OUT_DIR)/%, $(TTH_PRG))
## FLAGS ###############################
# fast and no control
#DFLAGS = -O2 -DNDEBUG -DNO_OTB -DINTEL_TBB_THREAD -DBOOST_DISABLE_ASSERTS
DFLAGS = -O2 -DNDEBUG -DNO_OTB -DINTEL_TBB_THREAD -DBOOST_DISABLE_ASSERTS
# fast but control
#DFLAGS = -O2 -DNDEBUG -DNO_OTB -DINTEL_TBB_THREAD
# debug multi-threaded
#DFLAGS = -g -DENABLE_LOG -DNO_OTB
# debug one thread
DFLAGS = -g -DENABLE_LOG -DNO_OTB -DTHREAD_DISABLE -DENABLE_SMART_LOG
#DFLAGS = -g -DENABLE_LOG -DNO_OTB -DTHREAD_DISABLE -DENABLE_SMART_LOG
IFLAGS = $(DFLAGS) -MMD -I$(HPP_DIR) -I/usr/include/gdal
LFLAGS = -L$(LIB_DIR) -ltriskele -lstdc++ -lpthread -lboost_system -lboost_chrono -lboost_thread -lboost_program_options -lboost_date_time -lboost_serialization -lboost_filesystem -lboost_unit_test_framework -lgdal -ltbb
CC = g++
## RULES ###############################
$(OBJ_DIR)/%.o: $(CPP_DIR)/%.cpp
$(OBJ_DIR)/%.o: $(SRC_DIR)/*/%.cpp
$(CC) $< $(IFLAGS) -cpp -c -o $@
$(OBJ_DIR)/%.o: $(CPP_DIR)/*/%.cpp
$(OBJ_DIR)/%.o: $(SRC_DIR)/*/*/%.cpp
$(CC) $< $(IFLAGS) -cpp -c -o $@
$(OUT_DIR)/%: $(CPP_DIR)/%.cpp
$(CC) $(IFLAGS) $< -L$(LIB_DIR) $(LFLAGS) -cpp -o $@
$(OUT_DIR)/%: $(CPP_DIR)/*/%.cpp
$(OUT_DIR)/%: $(SRC_DIR)/*/%.cpp
$(CC) $(IFLAGS) $< -L$(LIB_DIR) $(LFLAGS) -cpp -o $@
## ENTRIES #############################
all: init libtriskele apGenerator test pref
all: init libtriskele apGenerator test perf
testA: all
test: testA testB testThread
testThread: init $(TTH_OUT)
$(TTH_OUT)
testA: init $(TST_OUT)
$(TST_OUT)
testB: all
testB: init $(APG_OUT)
$(APG_OUT) data/10m.tif data/result.tif --min-tree --max-tree --tos-tree --alpha-tree -A data/areaThresholds.txt -S data/sdThresholds.txt -M data/moiThresholds.txt # --debug
perfA: all
perf: perfA
perfA: init $(PRF_OUT)
$(PRF_OUT) MIN 32 20 1000000
init:
mkdir -p $(OUT_DIR) $(OBJ_DIR) $(LIB_DIR)
clean:
find . -type f '(' -name '#*' -o -name '*~' ')' -print -exec rm -f '{}' \;
@ -73,19 +91,17 @@ libtriskele: $(LIB_DIR)/libtriskele.a
$(APG_OUT): $(APG_SRC) $(LIB_DIR)/libtriskele.a
$(TST_OUT): $(TST_SRC) $(LIB_DIR)/libtriskele.a
$(PRF_OUT): $(PRF_SRC) $(LIB_DIR)/libtriskele.a
$(TTH_OUT): $(TTH_SRC) $(TTH_OBJ) $(LIB_DIR)/libtriskele.a
$(CC) $(IFLAGS) $< $(TTH_OBJ) -L$(LIB_DIR) $(LFLAGS) -cpp -o $@
apGenerator: $(APG_OUT)
test: init $(TST_OUT)
pref: init $(PRF_OUT)
apGenerator: init $(APG_OUT)
## DEPENDS #############################
ALL_OUT = $(APG_OUT)
ALL_OBJ = $(OBJ_DIR)/IImage.o $(OBJ_DIR)/triskeleArrayTreeBase.o $(OBJ_DIR)/Tree.o $(OBJ_DIR)/triskeleDebug.o $(OBJ_DIR)/TreeStats.o $(OBJ_DIR)/triskeleBase.o $(OBJ_DIR)/QuadTreeBuilder.o $(OBJ_DIR)/Option.o $(OBJ_DIR)/Selected.o
ALL_OBJ = $(TRSK_OBJ)
ALL_OBJ_XML = $(OBJ_DIR)/IImage.o $(OBJ_DIR)/triskeleArrayTreeBase.o $(OBJ_DIR)/Tree.o $(OBJ_DIR)/triskeleDebug.o $(OBJ_DIR)/TreeStats.o $(OBJ_DIR)/triskeleBase.o $(OBJ_DIR)/QuadTreeBuilder.o $(OBJ_DIR)/XMLTreeBuilder.o $(OBJ_DIR)/Option.o $(OBJ_DIR)/Selected.o
DEPENDS = ${ALL_OUT:=.d} ${ALL_OBJ:.o=.d}
DEPENDS = ${ALL_OUT:=.d} ${ALL_OBJ:.o=.d} ${TTH_OBJ:.o=.d}
-include ${DEPENDS}
$(LIB_DIR)/libtriskele.a: $(ALL_OBJ)

View File

@ -2,8 +2,9 @@
Note aux développeurs
** La TODO list
- refaire le tableau des exemples de traces
- refaire le tableau des exemples de traces (./result/BuildSteps.ods)
- vérifier min et max apla tos
- copier les valeurs de géolocalisation (de input vers output)
- vérifier coupure (avec sens de la monotonie)
- faire un omega-tree
- faire les features-profiles (L, mean, SD, A, MOI)

View File

@ -6,6 +6,8 @@
#endif
#include <boost/thread.hpp>
#include "triskeleDebug.hpp"
namespace triskele {
template<typename DimImg, typename FunctId>

209
test/TestThread.cpp Normal file
View File

@ -0,0 +1,209 @@
#include <iostream>
#include <boost/thread.hpp>
#include <boost/chrono.hpp>
#include "triskeleDealThreads.hpp"
#include "TestThread.hpp"
using namespace std;
using namespace boost::chrono;
using namespace triskele;
using namespace otb;
using namespace otb::triskele;
static string timeTypeLabels [TimeTypeCard] = {
"initStats",
"seqReadStats",
"parReadStats",
"seqWriteStats",
"parWriteStats",
"seqRWStats",
"parRWStats"
};
// ========================================
inline string
TestThread::ns2string (double delta) {
ostringstream oss;
duration<double> ns (delta);
oss.fill ('0');
// typedef duration<int, ratio<86400> > days;
// auto d = duration_cast<days>(ns);
// ns -= d;
auto h = duration_cast<hours> (ns);
ns -= h;
auto m = duration_cast<minutes> (ns);
ns -= m;
oss << setw (2) << h.count () << ":"
<< setw (2) << m.count () << ":"
<< setw (9) << fixed << setprecision (6) << ns.count ();
return oss.str ();
}
// ========================================
template<typename DimImg, typename FunctId>
inline void
nodealThreadRange (const DimImg &maxId, const unsigned int &coreCount, const FunctId &functId/* functId (id) */) {
nodealThread (maxId, coreCount, [&functId] (const unsigned int &threadId, const DimImg &minVal, const DimImg &maxVal) {
for (DimImg id = minVal; id < maxVal; ++id)
functId (id);
});
}
// ----------------------------------------
template<typename DimImg, typename FunctThreadId>
inline void
nodealThreadThreadRange (const DimImg &maxId, const unsigned int &coreCount, const FunctThreadId &functThreadId/* functThreadId (threadId, id) */) {
nodealThread (maxId, coreCount, [&functThreadId] (const unsigned int &threadId, const DimImg &minVal, const DimImg &maxVal) {
for (DimImg id = minVal; id < maxVal; ++id)
functThreadId (threadId, id);
});
}
// ----------------------------------------
template<typename DimImg, typename FunctThreadMinMax>
inline void
nodealThread (const DimImg &maxId, unsigned int coreCount, const FunctThreadMinMax &functThreadMinMax/* functThreadMinMax (threadId, minVal, maxVal) */) {
//DEF_LOG ("dealThreadBound", "coreCount:" << coreCount << " maxId:" << maxId);
if (!maxId || !coreCount)
return;
if (DimImg (coreCount) > maxId)
coreCount = (unsigned int) maxId;
if (coreCount == 1) {
functThreadMinMax (0, 0, maxId);
return;
}
std::vector<DimImg> maxIds = getDealThreadBounds (maxId, coreCount);
for (unsigned int idCopyValInThread = 0; idCopyValInThread < coreCount; ++idCopyValInThread) {
functThreadMinMax (idCopyValInThread, maxIds[idCopyValInThread], maxIds[idCopyValInThread+1]);
}
}
// ========================================
TestThread::TestThread ()
: global (nbItem*coreCount, 0)
{
}
ostream &
TestThread::print (ostream &out, const AlgoStat stats[]) {
out << endl
<< setw (16) << left << "Time" << "\t"
<< setw (15) << left << "Sum" << "\t"
<< setw (3) << left << "Count" << "\t"
<< setw (15) << left << "Mean" << "\t"
<< setw (15) << left << "Min" << "\t"
<< setw (15) << left << "Max" << endl;
for (unsigned int i = 0; i < TimeTypeCard; ++i) {
if (!ba::count (stats[i]))
continue;
out << setw (16) << right << timeTypeLabels[i] << "\t"
<< ns2string (ba::sum (stats[i])) << "\t" << setw (3) << ba::count (stats[i]) << "\t"
<< ns2string (ba::mean (stats[i])) << "\t"
<< ns2string (ba::min (stats[i])) << "\t"
<< ns2string (ba::max (stats[i]))
<< endl << flush;
}
return out;
}
template <typename T>
void
TestThread::fillVector (vector<T> &vect) {
for (size_t i = 0; i < vect.size (); ++i)
vect[i] = (T) std::rand ();
}
// show algin
void
TestThread::multiTest () {
for (unsigned int nbCore = 1; nbCore <= coreCount; ++nbCore) {
for (int i = 0; i < 100; ++i) {
vector<long> sumSeq (nbCore, 0);
vector<long> sumPar (nbCore, 0);
auto start = high_resolution_clock::now ();
fillVector (global);
// lecture seq => faire somme
auto startSeqRead = high_resolution_clock::now ();
nodealThreadThreadRange (nbItem, nbCore, [this, &sumSeq] (const unsigned int &threadId, const DimImg &item) {
sumSeq[threadId] += global[item];
});
// lecture // => faire somme
auto startParRead = high_resolution_clock::now ();
dealThreadThreadRange (nbItem, nbCore, [this, &sumPar] (const unsigned int &threadId, const DimImg &item) {
sumPar[threadId] += global[item];
});
// XXX vérifier égalité de sumSeq sumPar
// écriture seq => écrire idx
// écriture // => écrire idx
// lecture/écriture seq => écrire x/2
// lecture/écriture // => écrire x/2
auto end = high_resolution_clock::now ();
addTime (initStats, duration_cast<duration<double> > (startSeqRead-start).count ());
addTime (seqReadStats, duration_cast<duration<double> > (startParRead-startSeqRead).count ());
addTime (parReadStats, duration_cast<duration<double> > (end-startParRead).count ());
}
print (cout, timeStats);
}
}
// ========================================
int
main (int argc, char** argv) {
cout << "start test" << endl;
srand (time (NULL));
TestThread tt;
tt.multiTest ();
return 0;
}
// namespace utils {
// inline size_t alignSize(size_t size, size_t alignment) {
// return (size+alignment-1)&~(alignment-1);
// }
// template<typename T>
// inline T * alignPtr(T * ptr, uintptr_t alignment) {
// union {
// T *p;
// uintptr_t u;
// } u;
// u.p = ptr;
// u.u = (u.u+alignment-1)&~(alignment-1);
// return u.p;
// }
// }//namespace utils
// void init (Index c, Data const &d) {
// if (count != c) {
// kill ();
// count = c;
// size_t const alignment = 64;
// size_t size = alignment-1
// + utils::alignSize (count*sizeof (Index), alignment)
// + utils::alignSize (count*sizeof (Rank ), alignment)
// + utils::alignSize (count*sizeof (Data ), alignment);
// //memory.reset (new char[size]);
// delete [] memory;
// memory = nullptr;
// memory = new char[size];
// char *ptr = utils::alignPtr (memory, alignment);
// parents = reinterpret_cast<Index*> (ptr);
// ptr += utils::alignSize (count*sizeof (Index), alignment);
// ranks = reinterpret_cast<Rank *> (ptr);
// ptr += utils::alignSize (count*sizeof (Rank ), alignment);
// datas = reinterpret_cast<Data *> (ptr);
// }
// reset (d);
// }

View File

@ -1,6 +0,0 @@
#include <iostream>
int main(int argc, char** argv) {
return 0;
}