diff --git a/swiftmpistepsim.c b/swiftmpistepsim.c index 02e8f67757d412cc8f4bc4ed894c0b8cffe6ca1f..81b490013d0b10b69b4bcaa88bed7520e9bec246 100644 --- a/swiftmpistepsim.c +++ b/swiftmpistepsim.c @@ -38,6 +38,9 @@ static int verbose = 0; /* Attempt to keep original injection time differences. */ static int usetics = 1; +/* The wait between injections, nanosecs. */ +static long long waitns = 0; + /* Integer types of send and recv tasks, must match log. */ static const int task_type_send = 22; static const int task_type_recv = 23; @@ -76,10 +79,13 @@ static void injection_runner(int qid) { ticks looptics = 0; double deadtime = 0.0; + struct timespec sleep; + sleep.tv_sec = 0; + while (ind_req[qid] < nr_reqs[qid]) { struct mpiuse_log_entry *log = reqs[ind_req[qid]]; - if (usetics) { + if (usetics && waitns == 0) { /* Expect time between this request and the previous one. */ ticks dt = log->tic - basetic; basetic = log->tic; @@ -96,8 +102,7 @@ static void injection_runner(int qid) { /* Remember to be fair and remove the looptics, then convert to * nanoseconds. */ - //double ns = (double)(dt - looptics) / log_clocks_cpufreq * 1.0e9; - double ns = (double)(looptics) / log_clocks_cpufreq * 1.0e9; + double ns = (double)(dt - looptics) / log_clocks_cpufreq * 1.0e9; if (ns < 1.0e9) { sleep.tv_nsec = (long)ns; } else { @@ -109,6 +114,10 @@ static void injection_runner(int qid) { nanosleep(&sleep, NULL); deadtime += sleep.tv_nsec; } + } else if (waitns != 0) { + sleep.tv_nsec = waitns; + nanosleep(&sleep, NULL); + deadtime += sleep.tv_nsec; } /* Initialise new log elements. */ @@ -392,9 +401,10 @@ static void pick_logs(void) { * @brief usage help. */ static void usage(char *argv[]) { - fprintf(stderr, "Usage: %s [-vf] SWIFT_mpiuse-log-file.dat logfile.dat\n", - argv[0]); - fprintf(stderr, " options: -v verbose, -f fast injections\n"); + fprintf(stderr, "Usage: %s [-vf] [-n nanosec] SWIFT_mpiuse-log-file.dat " + "logfile.dat\n", argv[0]); + fprintf(stderr, " options: -v verbose, -f fast injections, " + "-n nanoseconds to wait\n"); fflush(stderr); } @@ -420,7 +430,7 @@ int main(int argc, char *argv[]) { /* Handle the command-line, we expect a mpiuse data file to read and various * options. */ int opt; - while ((opt = getopt(argc, argv, "vf")) != -1) { + while ((opt = getopt(argc, argv, "vfn:")) != -1) { switch (opt) { case 'f': usetics = 0; @@ -428,6 +438,9 @@ int main(int argc, char *argv[]) { case 'v': verbose = 1; break; + case 'n': + waitns = atoll(optarg); + break; default: if (myrank == 0) usage(argv); return 1; @@ -465,6 +478,7 @@ int main(int argc, char *argv[]) { if (myrank == 0) { message("Start of MPI tests"); message("=================="); + if (waitns > 0) message("adding fixed waits of %lld ns", waitns); } /* Make three threads, one for injecting tasks and two to check for