Commit 487ba92c authored by Alexis SALZMAN's avatar Alexis SALZMAN

[xTool] make xNoDeltaTime works + test case

xNoDeltaTime class was bugged. Now this class is ok and rigorously having the
same API as xDeltaTime class.

With this class that cost nothing (all call to instance method
are optimized out by compiler) we can now consider to let monitoring
instruction to stay in the middle of the code. No more dirty macros are
needed around those instructions. Only at creation time the instance
created is either a xNoDeltaTime or a xDeltaTime object (and macro if
necessary appears only at this level)

A small atomic test case check that xNoDeltaTime do not cost anything.

Be careful to not encapsulated  a xNoDeltaTime or a xDeltaTime object
into a std::function. You would alleviate all the effort to make
xNoDeltaTime to cost nothing. Because std::function itself do cost and
keeping monitoring instructions in the code would then degrade
performances.
parent af6f2b76
This diff is collapsed.
This diff is collapsed.
......@@ -17,6 +17,7 @@ set(LIST
${CMAKE_CURRENT_SOURCE_DIR}/testxMPITag
${CMAKE_CURRENT_SOURCE_DIR}/testSendOnlyKeysTraits
${CMAKE_CURRENT_SOURCE_DIR}/xExportStringDist
${CMAKE_CURRENT_SOURCE_DIR}/xDeltaTime
)
create_tests_from_list(${LIST})
......
enable_testing()
add_test(
NAME xDeltaTime
COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} ${INSTALL_PATH}/${TARGET_NAME} ${MPIEXEC_POSTFLAGS}
WORKING_DIRECTORY ${INSTALL_PATH}
)
add_test(
NAME ndiff_xDeltaTime
COMMAND ${TESTNDIFF}
WORKING_DIRECTORY ${INSTALL_PATH}
)
set_tests_properties(ndiff_xDeltaTime PROPERTIES DEPENDS xDeltaTime )
#include <fstream>
#include "mpi.h"
#include "xDeltaTime.h"
#include "xMPIEnv.h"
using namespace std;
// a function to test monitoring
template <typename DT>
size_t foo(DT &dt, const char *msg)
{
int iddti0 = dt.initAccu(msg);
size_t j = 0, k = 0;
for (size_t i = 0; i < 1000000; ++i)
{
dt.startAccu(iddti0);
k = i - j;
j += k; // some-thing;
dt.endAccu(iddti0);
}
return k + j;
}
int main(int argc, char *argv[])
{
xtool::xMPIEnv::init(argc, argv);
// local variable
MPI_Comm world = MPI_COMM_WORLD;
int proc_id, iddt0;
// get rank for world
MPI_Comm_rank(world, &proc_id);
// testing class
xtool::xDeltaTime dt;
xtool::xNoDeltaTime ndt;
// test with true monitoring
iddt0 = dt.start("foo dt");
foo(dt, "foo dt oper");
dt.end(iddt0);
// test with false monitoring
iddt0 = dt.start("foo ndt");
foo(ndt, "foo ndt oper");
dt.end(iddt0);
// output stats
dt.print();
ndt.print();
// open reference
ofstream ofs("proc_" + std::to_string(proc_id) + "_ref.txt", ios::out | ios::trunc);
// without monitoring time must be null
double val[3];
double mi[3];
double mx[3];
double me[3];
#ifndef NDEBUG
double eps = 1.E-1;
#else
double eps = 1.E-4;
#endif
dt.get("foo ndt", val, mi, mx, me);
ofs << "foo ndt should be null" << std::endl;
ofs << "mi " << ((mi[0] < eps) ? 0. : mi[0]) << " " << ((mi[1] < eps) ? 0. : mi[1]) << " " << ((mi[2] < eps) ? 0. : mi[2])
<< std::endl;
ofs << "mx " << ((mx[0] < eps) ? 0. : mx[0]) << " " << ((mx[1] < eps) ? 0. : mx[1]) << " " << ((mx[2] < eps) ? 0. : mx[2])
<< std::endl;
ofs << "me " << ((me[0] < eps) ? 0. : me[0]) << " " << ((me[1] < eps) ? 0. : me[1]) << " " << ((me[2] < eps) ? 0. : me[2])
<< std::endl;
// ending prog
ofs.close();
xtool::xMPIEnv::finalize();
return 0;
}
foo ndt should be null
mi 0 0 0
mx 0 0 0
me 0 0 0
foo ndt should be null
mi 0 0 0
mx 0 0 0
me 0 0 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment