diff --git a/examples/test.c b/examples/test.c index 134a9152b42b2ff0c6e01690c143993d58976f2c..fb3e4c24f8c8cba0f0e74220f1a7cee7933cda68 100644 --- a/examples/test.c +++ b/examples/test.c @@ -554,6 +554,7 @@ int main(int argc, char *argv[]) { int c, icount, j, k, N, periodic = 1; long long N_total = -1; int nr_threads = 1, nr_queues = -1, runs = INT_MAX; + int dump_tasks = 0; int data[2]; double dim[3] = {1.0, 1.0, 1.0}, shift[3] = {0.0, 0.0, 0.0}; double h_max = -1.0, scaling = 1.0; @@ -605,7 +606,7 @@ int main(int argc, char *argv[]) { bzero(&s, sizeof(struct space)); /* Parse the options */ - while ((c = getopt(argc, argv, "a:c:d:f:g:m:oq:r:s:t:w:z:")) != -1) + while ((c = getopt(argc, argv, "a:c:d:f:g:m:q:r:s:t:w:yz:")) != -1) switch (c) { case 'a': if (sscanf(optarg, "%lf", &scaling) != 1) @@ -663,6 +664,9 @@ int main(int argc, char *argv[]) { error("Error parsing sub size."); if (myrank == 0) message("sub size set to %i.", space_subsize); break; + case 'y': + dump_tasks = 1; + break; case 'z': if (sscanf(optarg, "%d", &space_splitsize) != 1) error("Error parsing split size."); @@ -756,7 +760,7 @@ int main(int argc, char *argv[]) { /* Initialize the space with this data. */ tic = getticks(); - space_init(&s, dim, parts, N, periodic, h_max); + space_init(&s, dim, parts, N, periodic, h_max, myrank == 0); if (myrank == 0) message("space_init took %.3f ms.", ((double)(getticks() - tic)) / CPU_TPS * 1000); @@ -796,7 +800,7 @@ int main(int argc, char *argv[]) { /* Initialize the engine with this space. */ tic = getticks(); - message("nr_nodes is %i.", nr_nodes); + if (myrank == 0) message("nr_nodes is %i.", nr_nodes); engine_init(&e, &s, dt_max, nr_threads, nr_queues, nr_nodes, myrank, ENGINE_POLICY | engine_policy_steal); if (myrank == 0) @@ -825,8 +829,9 @@ int main(int argc, char *argv[]) { #else write_output_single(&e, &us); #endif - message("writing particle properties took %.3f ms.", - ((double)(getticks() - tic)) / CPU_TPS * 1000); + if (myrank == 0) + message("writing particle properties took %.3f ms.", + ((double)(getticks() - tic)) / CPU_TPS * 1000); fflush(stdout); } @@ -916,40 +921,43 @@ int main(int argc, char *argv[]) { (double)runner_hist_bins[k]); #endif -/* Dump the task data. */ + /* Dump the task data. */ + if (dump_tasks) { #ifdef WITH_MPI - file_thread = fopen("thread_info_MPI.dat", "w"); - for (j = 0; j < nr_nodes; j++) { - MPI_Barrier(MPI_COMM_WORLD); - if (j == myrank) { - fprintf(file_thread, " %03i 0 0 0 0 %lli 0 0 0 0\n", myrank, e.tic_step); - for (k = 0; k < e.sched.nr_tasks; k++) - if (!e.sched.tasks[k].skip && !e.sched.tasks[k].implicit) - fprintf( - file_thread, " %03i %i %i %i %i %lli %lli %i %i %i\n", myrank, - e.sched.tasks[k].rid, e.sched.tasks[k].type, - e.sched.tasks[k].subtype, (e.sched.tasks[k].cj == NULL), - e.sched.tasks[k].tic, e.sched.tasks[k].toc, - e.sched.tasks[k].ci->count, - (e.sched.tasks[k].cj != NULL) ? e.sched.tasks[k].cj->count : 0, - e.sched.tasks[k].flags); - fflush(stdout); - sleep(1); + file_thread = fopen("thread_info_MPI.dat", "w"); + for (j = 0; j < nr_nodes; j++) { + MPI_Barrier(MPI_COMM_WORLD); + if (j == myrank) { + fprintf(file_thread, " %03i 0 0 0 0 %lli 0 0 0 0\n", myrank, + e.tic_step); + for (k = 0; k < e.sched.nr_tasks; k++) + if (!e.sched.tasks[k].skip && !e.sched.tasks[k].implicit) + fprintf( + file_thread, " %03i %i %i %i %i %lli %lli %i %i %i\n", myrank, + e.sched.tasks[k].rid, e.sched.tasks[k].type, + e.sched.tasks[k].subtype, (e.sched.tasks[k].cj == NULL), + e.sched.tasks[k].tic, e.sched.tasks[k].toc, + e.sched.tasks[k].ci->count, + (e.sched.tasks[k].cj != NULL) ? e.sched.tasks[k].cj->count : 0, + e.sched.tasks[k].flags); + fflush(stdout); + sleep(1); + } } - } - fclose(file_thread); + fclose(file_thread); #else - file_thread = fopen("thread_info.dat", "w"); - for (k = 0; k < e.sched.nr_tasks; k++) - if (!e.sched.tasks[k].skip && !e.sched.tasks[k].implicit) - fprintf(file_thread, " %i %i %i %i %lli %lli %i %i\n", - e.sched.tasks[k].rid, e.sched.tasks[k].type, - e.sched.tasks[k].subtype, (e.sched.tasks[k].cj == NULL), - e.sched.tasks[k].tic, e.sched.tasks[k].toc, - e.sched.tasks[k].ci->count, - (e.sched.tasks[k].cj == NULL) ? 0 : e.sched.tasks[k].cj->count); - fclose(file_thread); + file_thread = fopen("thread_info.dat", "w"); + for (k = 0; k < e.sched.nr_tasks; k++) + if (!e.sched.tasks[k].skip && !e.sched.tasks[k].implicit) + fprintf(file_thread, " %i %i %i %i %lli %lli %i %i\n", + e.sched.tasks[k].rid, e.sched.tasks[k].type, + e.sched.tasks[k].subtype, (e.sched.tasks[k].cj == NULL), + e.sched.tasks[k].tic, e.sched.tasks[k].toc, + e.sched.tasks[k].ci->count, + (e.sched.tasks[k].cj == NULL) ? 0 : e.sched.tasks[k].cj->count); + fclose(file_thread); #endif + } if (with_outputs) { /* Write final output. */ @@ -972,7 +980,7 @@ int main(int argc, char *argv[]) { #endif /* Say goodbye. */ - message("done."); + if (myrank == 0) message("done."); /* All is calm, all is bright. */ return 0; diff --git a/src/engine.c b/src/engine.c index 935b6902e9bdfca6ac364a29d8f971422f893e21..c4f5dccad5c829efd3b1b50211c4f6a06a28e198 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1370,7 +1370,7 @@ void engine_rebuild(struct engine *e) { /* Re-build the space. */ // tic = getticks(); - space_rebuild(e->s, 0.0); + space_rebuild(e->s, 0.0, e->nodeID == 0); // message( "space_rebuild took %.3f ms." , (double)(getticks() - // tic)/CPU_TPS*1000 ); @@ -2041,8 +2041,9 @@ void engine_split(struct engine *e, int *grid) { engine_makeproxies(e); /* Re-allocate the local parts. */ - message("Re-allocating parts array from %i to %i.", s->size_parts, - (int)(s->nr_parts * 1.2)); + if (e->nodeID == 0) + message("Re-allocating parts array from %i to %i.", s->size_parts, + (int)(s->nr_parts * 1.2)); s->size_parts = s->nr_parts * 1.2; struct part *parts_new; struct xpart *xparts_new; @@ -2094,13 +2095,16 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads, for (i = 1; i < maxint; i *= 2) for (j = maxint / i / 2; j < maxint; j += maxint / i) if (j < nr_cores && j != 0) cpuid[k++] = j; -#ifdef WITHMPI - printf("engine_init: cpu map is [ "); + + if (nodeID == 0) { +#ifdef WITH_MPI + message("engine_init: cpu map is [ "); #else - printf("[%03i] engine_init: cpu map is [ ", nodeID); + printf("[%03i] engine_init: cpu map is [ ", nodeID); #endif - for (i = 0; i < nr_cores; i++) printf("%i ", cpuid[i]); - printf("].\n"); + for (i = 0; i < nr_cores; i++) printf("%i ", cpuid[i]); + printf("].\n"); + } } #endif diff --git a/src/space.c b/src/space.c index eeb42f328f3a91439110c832fea93798862869a6..f4d9cda9d367332ea179a5b144fbc9d169c0dd99 100644 --- a/src/space.c +++ b/src/space.c @@ -149,9 +149,10 @@ void space_rebuild_recycle(struct space *s, struct cell *c) { * * @param s The #space. * @param cell_max Maximum cell edge length. + * @param verbose Print messages to stdout or not. */ -void space_regrid(struct space *s, double cell_max) { +void space_regrid(struct space *s, double cell_max, int verbose) { float h_max = s->cell_min / kernel_gamma / space_stretch, dmin; int i, j, k, cdim[3], nr_parts = s->nr_parts; @@ -182,7 +183,7 @@ void space_regrid(struct space *s, double cell_max) { h_max = buff; } #endif - message("h_max is %.3e (cell_max=%.3e).", h_max, cell_max); + if (verbose) message("h_max is %.3e (cell_max=%.3e).", h_max, cell_max); /* Get the new putative cell dimensions. */ for (k = 0; k < 3; k++) @@ -253,7 +254,9 @@ void space_regrid(struct space *s, double cell_max) { } /* Be verbose about the change. */ - message("set cell dimensions to [ %i %i %i ].", cdim[0], cdim[1], cdim[2]); + if (verbose) + message("set cell dimensions to [ %i %i %i ].", cdim[0], cdim[1], + cdim[2]); fflush(stdout); } /* re-build upper-level cells? */ @@ -289,10 +292,11 @@ void space_regrid(struct space *s, double cell_max) { * * @param s The #space in which to update the cells. * @param cell_max Maximal cell size. + * @param verbose Print messages to stdout or not * */ -void space_rebuild(struct space *s, double cell_max) { +void space_rebuild(struct space *s, double cell_max, int verbose) { int j, k, cdim[3], nr_parts = s->nr_parts, nr_gparts = s->nr_gparts; struct cell *restrict c, *restrict cells; @@ -305,7 +309,7 @@ void space_rebuild(struct space *s, double cell_max) { // message( "re)building space..." ); fflush(stdout); /* Re-grid if necessary, or just re-set the cell data. */ - space_regrid(s, cell_max); + space_regrid(s, cell_max, verbose); cells = s->cells; /* Run through the particles and get their cell index. */ @@ -1073,6 +1077,7 @@ struct cell *space_getcell(struct space *s) { * @param N The number of parts in the space. * @param periodic flag whether the domain is periodic or not. * @param h_max The maximal interaction radius. + * @param verbose Print messages to stdout or not * * Makes a grid of edge length > r_max and fills the particles * into the respective cells. Cells containing more than #space_splitsize @@ -1081,7 +1086,7 @@ struct cell *space_getcell(struct space *s) { */ void space_init(struct space *s, double dim[3], struct part *parts, int N, - int periodic, double h_max) { + int periodic, double h_max, int verbose) { /* Store eveything in the space. */ s->dim[0] = dim[0]; @@ -1151,5 +1156,5 @@ void space_init(struct space *s, double dim[3], struct part *parts, int N, if (lock_init(&s->lock) != 0) error("Failed to create space spin-lock."); /* Build the cells and the tasks. */ - space_regrid(s, h_max); + space_regrid(s, h_max, verbose); } diff --git a/src/space.h b/src/space.h index e0bad6773547f813d70943c2ca2703529a0306a8..c12ec46be968d713618c41db5ab1385ed147d33e 100644 --- a/src/space.h +++ b/src/space.h @@ -119,7 +119,7 @@ struct cell *space_getcell(struct space *s); int space_getsid(struct space *s, struct cell **ci, struct cell **cj, double *shift); void space_init(struct space *s, double dim[3], struct part *parts, int N, - int periodic, double h_max); + int periodic, double h_max, int verbose); void space_map_cells_pre(struct space *s, int full, void (*fun)(struct cell *c, void *data), void *data); void space_map_parts(struct space *s, @@ -127,7 +127,7 @@ void space_map_parts(struct space *s, void *data); void space_map_cells_post(struct space *s, int full, void (*fun)(struct cell *c, void *data), void *data); -void space_rebuild(struct space *s, double h_max); +void space_rebuild(struct space *s, double h_max, int verbose); void space_recycle(struct space *s, struct cell *c); void space_split(struct space *s, struct cell *c);