diff --git a/Makefile b/Makefile index baf96f8bfdf00761304cf284993ed56ba0064369..8c350487dae05d2302c0f7cf27974c533f08e8b1 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,10 @@ CFLAGS = -g -O0 -Wall all: swiftmpistepsim swiftmpifakestepsim swiftmpistepsim: swiftmpistepsim.c mpiuse.c mpiuse.h atomic.h cycle.h clocks.h clocks.c - mpicc $(CFLAGS) -o swiftmpistepsim swiftmpistepsim.c mpiuse.c clocks.c + mpicc $(CFLAGS) -o swiftmpistepsim swiftmpistepsim.c mpiuse.c clocks.c -lpthread swiftmpifakestepsim: swiftmpifakestepsim.c mpiuse.c mpiuse.h atomic.h cycle.h clocks.h clocks.c - mpicc $(CFLAGS) -o swiftmpifakestepsim swiftmpifakestepsim.c mpiuse.c clocks.c + mpicc $(CFLAGS) -o swiftmpifakestepsim swiftmpifakestepsim.c mpiuse.c clocks.c -lpthread clean: rm -f swiftmpistepsim diff --git a/mpiuse.c b/mpiuse.c index 8c52cb5efc717d1ea3c3b1209b8ec8c3764d2161..b8f6ddfa4ca02fba008372b4a945fdb14d595359 100644 --- a/mpiuse.c +++ b/mpiuse.c @@ -263,18 +263,27 @@ struct mpiuse_log_entry *mpiuse_get_log(int ind) { * * @param nr_nodes the number of ranks that will be used. * @param nr_logs the number of logs to generate per rank. - * @param size bytes per message + * @param size bytes per message, unless random when this is the maximum + * and the minimum is 1. + * @param random whether to use random sizes. + * @param seed the random seed, use same for fixed sequences. */ -void mpiuse_log_generate(int nr_nodes, int nr_logs, int size) { +void mpiuse_log_generate(int nr_nodes, int nr_logs, int size, int random, + long int seed) { + + /* Each rank exchanges messages with all the others and each "log" has the + * same size. */ + if (random) srand48(seed); - /* Each rank exchange messages with all the others with a fixed size. */ int tag = 1; for (int k = 0; k < nr_logs; k++) { + int logsize = size; + if (random) logsize = (drand48() * (double)size) + 1; for (int i = 0; i < nr_nodes; i++) { for (int j = 0; j < nr_nodes; j++) { if (i != j) { - mpiuse_log_allocation(i, 1, k, SEND_TYPE, NO_SUBTYPE, 1, size, j, tag); - mpiuse_log_allocation(j, 1, k, RECV_TYPE, NO_SUBTYPE, 1, size, i, tag); + mpiuse_log_allocation(i, 1, k, SEND_TYPE, NO_SUBTYPE, 1, logsize, j, tag); + mpiuse_log_allocation(j, 1, k, RECV_TYPE, NO_SUBTYPE, 1, logsize, i, tag); } } } diff --git a/mpiuse.h b/mpiuse.h index 6f201aa460cbd728183930391bbcabacb91ebd68..46aaad5974ad2115b60e62edaa06b75326c9e070 100644 --- a/mpiuse.h +++ b/mpiuse.h @@ -101,6 +101,7 @@ int mpiuse_nr_logs(void); int mpiuse_nr_ranks(void); void mpiuse_dump_logs(int nranks, const char *logfile); -void mpiuse_log_generate(int nr_nodes, int nr_logs, int size); +void mpiuse_log_generate(int nr_nodes, int nr_logs, int size, int random, + long int seed); #endif /* SWIFT_MPIUSE_H */ diff --git a/swiftmpifakestepsim.c b/swiftmpifakestepsim.c index de832390607765c7ca6afb9238a0ed91f4698307..50887c8c611f6df9a6aab7a611ba147f6e9d90bc 100644 --- a/swiftmpifakestepsim.c +++ b/swiftmpifakestepsim.c @@ -38,6 +38,9 @@ static int verbose = 0; /* Set a data pattern and check we get this back, slow... */ static int datacheck = 0; +/* Fixed seed for pseudorandoms. */ +static long int seed = 1987654321; + /* The local queues. */ static struct mpiuse_log_entry **volatile reqs_queue; static int volatile ind_req = 0; @@ -338,7 +341,8 @@ static void pick_logs(void) { static void usage(char *argv[]) { fprintf(stderr, "Usage: %s [-vf] nr_messages logfile.dat\n", argv[0]); - fprintf(stderr, " options: -v verbose, -d data check, -s size (bytes)\n"); + fprintf(stderr, " options: -v verbose, -d data check, -s size (bytes), -r" + " random from 0 to size\n"); fflush(stderr); } @@ -362,10 +366,12 @@ int main(int argc, char *argv[]) { error("Call to MPI_Comm_rank failed with error %i.", res); /* Handle the command-line, we expect the number of messages to exchange per - * rank an output log and some options. */ + * rank an output log and some options, the interesting ones are a size and + * whether to use a random selection (with a fixed seed). */ int size = 1024; + int random = 0; int opt; - while ((opt = getopt(argc, argv, "vds:")) != -1) { + while ((opt = getopt(argc, argv, "vds:r")) != -1) { switch (opt) { case 'd': datacheck = 1; @@ -373,6 +379,9 @@ int main(int argc, char *argv[]) { case 's': size = atoi(optarg); break; + case 'r': + random = 1; + break; case 'v': verbose = 1; break; @@ -392,9 +401,16 @@ int main(int argc, char *argv[]) { char *logfile = argv[optind + 1]; /* Generate the fake logs for the exchanges. */ - if (myrank == 0) message("Generating %d fake logs for %d ranks of size %d", - nr_logs, nr_nodes, size); - mpiuse_log_generate(nr_nodes, nr_logs, size); + if (myrank == 0) { + if (random) { + message("Generating %d fake logs for %d ranks with random distribution" + " up to size %d", nr_logs, nr_nodes, size); + } else { + message("Generating %d fake logs for %d ranks of size %d", + nr_logs, nr_nodes, size); + } + } + mpiuse_log_generate(nr_nodes, nr_logs, size, random, seed); int nranks = mpiuse_nr_ranks(); /* Each rank requires its own queue, so extract them. */