diff --git a/swiftmpistepsim.c b/swiftmpistepsim.c index 9f57fb7b5c7e6d2306835674d4cb3b1ca06e0fb0..b8a660cba292d4dbed9cb556b9e6fd98e6ce52f7 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 = 10000; + /* Integer types of send and recv tasks, must match log. */ static const int task_type_send = 22; static const int task_type_recv = 23; @@ -81,38 +84,16 @@ static void *inject_thread(void *arg) { ticks looptics = 0; double deadtime = 0.0; + struct timespec sleep; + sleep.tv_sec = 0; + while (ind_req < nr_reqs) { struct mpiuse_log_entry *log = reqs_queue[ind_req]; if (usetics) { - /* Expect time between this request and the previous one. */ - ticks dt = log->tic - basetic; - basetic = log->tic; - - /* We guess some time below which we should not attempt to wait, - * otherwise we'll start to overrun, and just inject the next call if we - * are below that (we time the ticks this loop takes without any waiting - * and use that). Otherwise we wait a while. Note we need to convert the - * ticks of the log file into nanoseconds, that requires the original - * CPU frequency. */ - if (dt > looptics) { - struct timespec sleep; - sleep.tv_sec = 0; - - /* Remember to be fair and remove the looptics, then convert to - * nanoseconds. */ - double ns = (double)(dt - looptics) / log_clocks_cpufreq * 1.0e9; - if (ns < 1.0e9) { - sleep.tv_nsec = (long)ns; - } else { - /* Wait more than one second. Must be an error, but complain and - * continue. */ - sleep.tv_nsec = (long)1.0e9; - message("wait greater than one second"); - } - nanosleep(&sleep, NULL); - deadtime += sleep.tv_nsec; - } + sleep.tv_nsec = waitns; + nanosleep(&sleep, NULL); + deadtime += sleep.tv_nsec; } /* Initialise new log elements. */ @@ -151,7 +132,8 @@ static void *inject_thread(void *arg) { /* Set looptics on the first pass. Assumes MPI_Isend and MPI_Irecv are * equally timed. */ if (looptics == 0 && usetics) { - looptics = getticks() - starttics; + /* Not well matched, so try a lower value. */ + looptics = (getticks() - starttics) / 4; if (verbose) message("injection loop took %.3f %s.", clocks_from_ticks(looptics), clocks_getunit()); @@ -355,9 +337,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); } @@ -383,7 +366,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; @@ -391,6 +374,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; @@ -428,6 +414,7 @@ int main(int argc, char *argv[]) { if (myrank == 0) { message("Start of MPI tests"); message("=================="); + message("injecting fixed waits of %lld ns", waitns); } /* Make three threads, one for injecting tasks and two to check for