HW2: RC4 - Measurements version
This commit is contained in:
+64
-52
@@ -24,6 +24,10 @@ distBuffer_t Data;
|
||||
Log logger;
|
||||
distStat_t localStat, remoteStat;
|
||||
|
||||
// Mersenne seeded from hw if possible. range: [type_min, type_max]
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
//! Performance timers for each one of the "costly" functions
|
||||
Timing Ttotal;
|
||||
Timing TfullSort;
|
||||
@@ -106,9 +110,9 @@ bool get_options(int argc, char* argv[]){
|
||||
}
|
||||
else if (arg == "-h" || arg == "--help") {
|
||||
std::cout << "distbitonic/distbubbletonic - A distributed sort utility\n\n";
|
||||
std::cout << "distbitonic -q <N> [-e] [-p | --pipeline N] [--validation] [--perf] [--ndebug] [-v]\n";
|
||||
std::cout << "distbitonic -q <N> [-e] [-p | --pipeline N] [--validation] [--perf <N>] [--ndebug] [-v]\n";
|
||||
std::cout << "distbitonic -h\n";
|
||||
std::cout << "distbubbletonic -q <N> [-e] [-p | --pipeline N] [--validation] [--perf] [--ndebug] [-v]\n";
|
||||
std::cout << "distbubbletonic -q <N> [-e] [-p | --pipeline N] [--validation] [--perf <N> ] [--ndebug] [-v]\n";
|
||||
std::cout << "distbubbletonic -h\n";
|
||||
std::cout << '\n';
|
||||
std::cout << "Options:\n\n";
|
||||
@@ -123,7 +127,7 @@ bool get_options(int argc, char* argv[]){
|
||||
std::cout << " Request a full validation at the end, performed by process rank 0\n\n";
|
||||
std::cout << " --perf <N> \n";
|
||||
std::cout << " Enable performance timing measurements and prints, and repeat\n";
|
||||
std::cout << " the sorting <N> times to average the measurements\n\n";
|
||||
std::cout << " the sorting <N> times.\n\n";
|
||||
std::cout << " --ndebug\n";
|
||||
std::cout << " Skip debug breakpoint when on debug build.\n\n";
|
||||
std::cout << " -v | --verbose\n";
|
||||
@@ -190,59 +194,67 @@ bool validator(ShadowedDataT& data, mpi_id_t Processes, mpi_id_t rank) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Initializes the environment, must called from each process
|
||||
*
|
||||
* @param argc [int*] POINTER to main's argc argument
|
||||
* @param argv [char***] POINTER to main's argv argument
|
||||
*/
|
||||
void init(int* argc, char*** argv) {
|
||||
// Initialize MPI environment
|
||||
mpi.init(argc, argv);
|
||||
|
||||
// try to read command line (after MPI parsing)
|
||||
if (!get_options(*argc, *argv))
|
||||
exit(1);
|
||||
|
||||
logger << "MPI environment initialized." << " Rank: " << mpi.rank() << " Size: " << mpi.size()
|
||||
<< logger.endl;
|
||||
|
||||
#if defined DEBUG
|
||||
#if defined TESTING
|
||||
/*
|
||||
* In case of a debug build we will wait here until sleep_wait
|
||||
* will reset via debugger. In order to do that the user must attach
|
||||
* debugger to all processes. For example:
|
||||
* $> mpirun -np 2 ./<program path>
|
||||
* $> ps aux | grep <program>
|
||||
* $> gdb <program> <PID1>
|
||||
* $> gdb <program> <PID2>
|
||||
*/
|
||||
volatile bool sleep_wait = false;
|
||||
#else
|
||||
volatile bool sleep_wait = true;
|
||||
#endif
|
||||
while (sleep_wait && !config.ndebug)
|
||||
sleep(1);
|
||||
#endif
|
||||
|
||||
// Prepare vector and timing data
|
||||
Data.resize(config.arraySize);
|
||||
measurements_init();
|
||||
}
|
||||
|
||||
#if !defined TESTING
|
||||
/*!
|
||||
* @return Returns 0, but.... we may throw or exit(1)
|
||||
*/
|
||||
int main(int argc, char* argv[]) try {
|
||||
// Initialize MPI environment
|
||||
mpi.init(&argc, &argv);
|
||||
|
||||
// try to read command line (after MPI parsing)
|
||||
if (!get_options(argc, argv))
|
||||
exit(1);
|
||||
// Init everything
|
||||
init(&argc, &argv);
|
||||
|
||||
logger << "MPI environment initialized." <<
|
||||
" Rank: " << mpi.rank() <<
|
||||
" Size: " << mpi.size() <<
|
||||
logger.endl;
|
||||
|
||||
#if defined DEBUG
|
||||
#if defined TESTING
|
||||
/*
|
||||
* In case of a debug build we will wait here until sleep_wait
|
||||
* will reset via debugger. In order to do that the user must attach
|
||||
* debugger to all processes. For example:
|
||||
* $> mpirun -np 2 ./<program path>
|
||||
* $> ps aux | grep <program>
|
||||
* $> gdb <program> <PID1>
|
||||
* $> gdb <program> <PID2>
|
||||
*/
|
||||
volatile bool sleep_wait = false;
|
||||
#else
|
||||
volatile bool sleep_wait = true;
|
||||
#endif
|
||||
while (sleep_wait && !config.ndebug)
|
||||
sleep(1);
|
||||
#endif
|
||||
|
||||
// Initialize local data
|
||||
logger << "Initialize local array of " << config.arraySize << " elements" << logger.endl;
|
||||
std::random_device rd; // Mersenne seeded from hw if possible. range: [type_min, type_max]
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_int_distribution<distValue_t > dis(
|
||||
std::numeric_limits<distValue_t>::min(),
|
||||
std::numeric_limits<distValue_t>::max()
|
||||
);
|
||||
// Fill vector
|
||||
Data.resize(config.arraySize);
|
||||
std::generate(Data.begin(), Data.end(), [&]() { return dis(gen); });
|
||||
|
||||
// Run distributed sort
|
||||
if (mpi.rank() == 0)
|
||||
logger << "Starting distributed sorting ... ";
|
||||
measurements_init();
|
||||
for (size_t it = 0 ; it < config.perf ; ++it) {
|
||||
// Initialize local data
|
||||
logger << "Initialize local array of " << config.arraySize << " elements" << logger.endl;
|
||||
std::uniform_int_distribution<distValue_t > dis(
|
||||
std::numeric_limits<distValue_t>::min(),
|
||||
std::numeric_limits<distValue_t>::max()
|
||||
);
|
||||
std::generate(Data.begin(), Data.end(), [&]() { return dis(gen); });
|
||||
// Run distributed sort
|
||||
if (mpi.rank() == 0)
|
||||
logger << "Starting distributed sorting ... ";
|
||||
Ttotal.start();
|
||||
#if CODE_VERSION == BUBBLETONIC
|
||||
distBubbletonic(Data, mpi.size(), mpi.rank());
|
||||
@@ -251,9 +263,9 @@ int main(int argc, char* argv[]) try {
|
||||
#endif
|
||||
Ttotal.stop();
|
||||
measurements_next();
|
||||
if (mpi.rank() == 0)
|
||||
logger << " Done." << logger.endl;
|
||||
}
|
||||
if (mpi.rank() == 0)
|
||||
logger << " Done." << logger.endl;
|
||||
|
||||
// Print-outs and validation
|
||||
if (config.perf > 1) {
|
||||
@@ -266,10 +278,10 @@ int main(int argc, char* argv[]) try {
|
||||
if (config.validation) {
|
||||
// If requested, we have the chance to fail!
|
||||
if (mpi.rank() == 0)
|
||||
std::cout << "Results validation ...";
|
||||
std::cout << "[Validation] Results validation ...";
|
||||
bool val = validator(Data, mpi.size(), mpi.rank());
|
||||
if (mpi.rank() == 0)
|
||||
std::cout << ((val) ? "\x1B[32m [PASS] \x1B[0m\n" : " \x1B[32m [FAIL] \x1B[0m\n");
|
||||
std::cout << ((val) ? "\x1B[32m [PASSED] \x1B[0m\n" : " \x1B[32m [FAILED] \x1B[0m\n");
|
||||
}
|
||||
mpi.finalize();
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user