void sc_flops_count (sc_flopinfo_t * fi) { double seconds; float rtime, ptime; long long flpops; seconds = sc_MPI_Wtime (); sc_flops_papi (&rtime, &ptime, &flpops, &fi->mflops); fi->iwtime = seconds - fi->seconds; fi->cwtime += fi->iwtime; fi->iptime = ptime - fi->cptime; fi->cptime = ptime; fi->iflpops = flpops - fi->cflpops; fi->cflpops = flpops; #ifdef SC_PAPI fi->irtime = rtime - fi->crtime; fi->crtime = rtime; #else fi->irtime = (float) fi->iwtime; fi->crtime = (float) fi->cwtime; #endif fi->seconds = seconds; }
void sc_flops_start (sc_flopinfo_t * fi) { float rtime, ptime, mflops; long long flpops; fi->seconds = sc_MPI_Wtime (); sc_flops_papi (&rtime, &ptime, &flpops, &mflops); /* ignore results */ fi->cwtime = 0.; fi->crtime = fi->cptime = 0.; fi->cflpops = 0; fi->iwtime = 0.; fi->irtime = fi->iptime = fi->mflops = 0.; fi->iflpops = 0; }
static void run_load (sc_MPI_Comm mpicomm, p4est_connectivity_t * conn, int level) { int mpiret; double elapsed_create, elapsed_partition, elapsed_balance; #ifdef LOADCONN_VTK char filename[BUFSIZ]; #endif p4est_t *p4est; P4EST_GLOBAL_PRODUCTIONF ("Run load on level %d\n", level); /* create and refine the forest */ mpiret = sc_MPI_Barrier (mpicomm); SC_CHECK_MPI (mpiret); elapsed_create = -sc_MPI_Wtime (); p4est = p4est_new_ext (mpicomm, conn, 0, level, 1, 0, NULL, NULL); level_shift = 4; refine_level = level + level_shift; p4est_refine (p4est, 1, refine_fractal, NULL); elapsed_create += sc_MPI_Wtime (); #ifdef LOADCONN_VTK snprintf (filename, BUFSIZ, "loadconn%d_%02d_C", P4EST_DIM, level); p4est_vtk_write_file (p4est, NULL, filename); #endif /* partition the forest */ mpiret = sc_MPI_Barrier (mpicomm); SC_CHECK_MPI (mpiret); elapsed_partition = -sc_MPI_Wtime (); p4est_partition (p4est, 0, NULL); elapsed_partition += sc_MPI_Wtime (); /* balance the forest */ mpiret = sc_MPI_Barrier (mpicomm); SC_CHECK_MPI (mpiret); elapsed_balance = -sc_MPI_Wtime (); p4est_balance (p4est, P4EST_CONNECT_FULL, NULL); elapsed_balance += sc_MPI_Wtime (); #ifdef LOADCONN_VTK snprintf (filename, BUFSIZ, "loadconn%d_%02d_B", P4EST_DIM, level); p4est_vtk_write_file (p4est, NULL, filename); #endif /* report timings */ P4EST_GLOBAL_PRODUCTIONF ("Timings %d: %g %g %g\n", level, elapsed_create, elapsed_partition, elapsed_balance); p4est_destroy (p4est); }
static void test_loadsave (p4est_connectivity_t * connectivity, const char *prefix, sc_MPI_Comm mpicomm, int mpirank) { int mpiret, retval; unsigned csum, csum2; double elapsed, wtime; p4est_connectivity_t *conn2; p4est_t *p4est, *p4est2; sc_statinfo_t stats[STATS_COUNT]; char conn_name[BUFSIZ]; char p4est_name[BUFSIZ]; snprintf (conn_name, BUFSIZ, "%s.%s", prefix, P4EST_CONN_SUFFIX); snprintf (p4est_name, BUFSIZ, "%s.%s", prefix, P4EST_FOREST_SUFFIX); P4EST_GLOBAL_INFOF ("Using file names %s and %s\n", conn_name, p4est_name); p4est = p4est_new_ext (mpicomm, connectivity, 0, 0, 0, sizeof (int), init_fn, NULL); p4est_refine (p4est, 1, refine_fn, init_fn); test_deflate (p4est); /* save, synchronize, load connectivity and compare */ if (mpirank == 0) { retval = p4est_connectivity_save (conn_name, connectivity); SC_CHECK_ABORT (retval == 0, "connectivity_save failed"); } mpiret = sc_MPI_Barrier (mpicomm); SC_CHECK_MPI (mpiret); wtime = sc_MPI_Wtime (); conn2 = p4est_connectivity_load (conn_name, NULL); elapsed = sc_MPI_Wtime () - wtime; sc_stats_set1 (stats + STATS_CONN_LOAD, elapsed, "conn load"); SC_CHECK_ABORT (p4est_connectivity_is_equal (connectivity, conn2), "load/save connectivity mismatch A"); p4est_connectivity_destroy (conn2); /* save, synchronize, load p4est and compare */ wtime = sc_MPI_Wtime (); p4est_save (p4est_name, p4est, 1); elapsed = sc_MPI_Wtime () - wtime; sc_stats_set1 (stats + STATS_P4EST_SAVE1, elapsed, "p4est save 1"); wtime = sc_MPI_Wtime (); p4est2 = p4est_load (p4est_name, mpicomm, sizeof (int), 1, NULL, &conn2); elapsed = sc_MPI_Wtime () - wtime; sc_stats_set1 (stats + STATS_P4EST_LOAD1a, elapsed, "p4est load 1a"); SC_CHECK_ABORT (p4est_connectivity_is_equal (connectivity, conn2), "load/save connectivity mismatch Ba"); SC_CHECK_ABORT (p4est_is_equal (p4est, p4est2, 1), "load/save p4est mismatch Ba"); p4est_destroy (p4est2); p4est_connectivity_destroy (conn2); wtime = sc_MPI_Wtime (); p4est2 = p4est_load (p4est_name, mpicomm, 0, 0, NULL, &conn2); elapsed = sc_MPI_Wtime () - wtime; sc_stats_set1 (stats + STATS_P4EST_LOAD1b, elapsed, "p4est load 1b"); SC_CHECK_ABORT (p4est_connectivity_is_equal (connectivity, conn2), "load/save connectivity mismatch Bb"); SC_CHECK_ABORT (p4est_is_equal (p4est, p4est2, 0), "load/save p4est mismatch Bb"); test_deflate (p4est2); p4est_destroy (p4est2); p4est_connectivity_destroy (conn2); /* partition and balance */ p4est_partition (p4est, 0, NULL); p4est_balance (p4est, P4EST_CONNECT_FULL, init_fn); csum = p4est_checksum (p4est); sc_stats_set1 (stats + STATS_P4EST_ELEMS, (double) p4est->local_num_quadrants, "p4est elements"); /* save, synchronize, load p4est and compare */ wtime = sc_MPI_Wtime (); p4est_save (p4est_name, p4est, 0); elapsed = sc_MPI_Wtime () - wtime; sc_stats_set1 (stats + STATS_P4EST_SAVE2, elapsed, "p4est save 2"); wtime = sc_MPI_Wtime (); p4est2 = p4est_load (p4est_name, mpicomm, sizeof (int), 0, NULL, &conn2); elapsed = sc_MPI_Wtime () - wtime; sc_stats_set1 (stats + STATS_P4EST_LOAD2, elapsed, "p4est load 2"); SC_CHECK_ABORT (p4est_connectivity_is_equal (connectivity, conn2), "load/save connectivity mismatch C"); SC_CHECK_ABORT (p4est_is_equal (p4est, p4est2, 0), "load/save p4est mismatch C"); p4est_destroy (p4est2); p4est_connectivity_destroy (conn2); /* save, synchronize, load p4est and compare */ wtime = sc_MPI_Wtime (); p4est_save (p4est_name, p4est, 1); elapsed = sc_MPI_Wtime () - wtime; sc_stats_set1 (stats + STATS_P4EST_SAVE3, elapsed, "p4est save 3"); wtime = sc_MPI_Wtime (); p4est2 = p4est_load (p4est_name, mpicomm, sizeof (int), 0, NULL, &conn2); elapsed = sc_MPI_Wtime () - wtime; sc_stats_set1 (stats + STATS_P4EST_LOAD3, elapsed, "p4est load 3"); SC_CHECK_ABORT (p4est_connectivity_is_equal (connectivity, conn2), "load/save connectivity mismatch D"); SC_CHECK_ABORT (p4est_is_equal (p4est, p4est2, 0), "load/save p4est mismatch D"); p4est_destroy (p4est2); p4est_connectivity_destroy (conn2); /* Test autopartition load feature */ wtime = sc_MPI_Wtime (); p4est2 = p4est_load_ext (p4est_name, mpicomm, sizeof (int), 0, 1, 0, NULL, &conn2); elapsed = sc_MPI_Wtime () - wtime; csum2 = p4est_checksum (p4est2); sc_stats_set1 (stats + STATS_P4EST_LOAD4, elapsed, "p4est load 4"); SC_CHECK_ABORT (p4est_connectivity_is_equal (connectivity, conn2), "load/save connectivity mismatch E"); SC_CHECK_ABORT (mpirank != 0 || csum == csum2, "load/save p4est mismatch E"); p4est_destroy (p4est2); p4est_connectivity_destroy (conn2); /* destroy data structures */ p4est_destroy (p4est); /* compute and print timings */ sc_stats_compute (mpicomm, STATS_COUNT, stats); sc_stats_print (p4est_package_id, SC_LP_STATISTICS, STATS_COUNT, stats, 0, 1); }
int main (int argc, char **argv) { int i, i1, i2, i3, i3last, i4, i4last, temp, count; size_t s, swaps1, swaps2, swaps3, total1, total2, total3; ssize_t searched; int *pi; sc_array_t *a1, *a2, *a3, *a4; int mpiret; double start, elapsed_pqueue, elapsed_qsort; mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); sc_init (sc_MPI_COMM_WORLD, 1, 1, NULL, SC_LP_DEFAULT); a1 = sc_array_new (sizeof (int)); a2 = sc_array_new (sizeof (int)); a3 = sc_array_new (sizeof (int)); a4 = sc_array_new (sizeof (int)); #ifdef THEBIGTEST count = 325323; #else count = 3251; #endif SC_INFOF ("Test pqueue with count %d\n", count); start = -sc_MPI_Wtime (); swaps1 = swaps2 = swaps3 = 0; total1 = total2 = total3 = 0; for (i = 0; i < count; ++i) { *(int *) sc_array_push (a1) = i; s = sc_array_pqueue_add (a1, &temp, compar); swaps1 += ((s > 0) ? 1 : 0); total1 += s; *(int *) sc_array_push (a2) = count - i - 1; s = sc_array_pqueue_add (a2, &temp, compar); swaps2 += ((s > 0) ? 1 : 0); total2 += s; *(int *) sc_array_push (a3) = (15 * i) % 172; s = sc_array_pqueue_add (a3, &temp, compar); swaps3 += ((s > 0) ? 1 : 0); total3 += s; } SC_CHECK_ABORT (swaps1 == 0 && total1 == 0, "pqueue_add"); SC_VERBOSEF (" Swaps %lld %lld %lld Total %lld %lld %lld\n", (long long) swaps1, (long long) swaps2, (long long) swaps3, (long long) total1, (long long) total2, (long long) total3); temp = 52; searched = sc_array_bsearch (a1, &temp, compar); SC_CHECK_ABORT (searched != -1, "array_bsearch_index"); pi = (int *) sc_array_index_ssize_t (a1, searched); SC_CHECK_ABORT (*pi == temp, "array_bsearch"); i3last = -1; swaps1 = swaps2 = swaps3 = 0; total1 = total2 = total3 = 0; for (i = 0; i < count; ++i) { s = sc_array_pqueue_pop (a1, &i1, compar); swaps1 += ((s > 0) ? 1 : 0); total1 += s; s = sc_array_pqueue_pop (a2, &i2, compar); swaps2 += ((s > 0) ? 1 : 0); total2 += s; s = sc_array_pqueue_pop (a3, &i3, compar); swaps3 += ((s > 0) ? 1 : 0); total3 += s; SC_CHECK_ABORT (i == i1 && i == i2, "pqueue_pop"); SC_CHECK_ABORT (i3 >= i3last, "pqueue_pop"); i3last = i3; } SC_VERBOSEF (" Swaps %lld %lld %lld Total %lld %lld %lld\n", (long long) swaps1, (long long) swaps2, (long long) swaps3, (long long) total1, (long long) total2, (long long) total3); elapsed_pqueue = start + sc_MPI_Wtime (); sc_array_destroy (a1); sc_array_destroy (a2); sc_array_destroy (a3); SC_INFOF ("Test array sort with count %d\n", count); start = -sc_MPI_Wtime (); /* the resize is done to be comparable with the above procedure */ for (i = 0; i < count; ++i) { *(int *) sc_array_push (a4) = (15 * i) % 172; } sc_array_sort (a4, compar); i4last = -1; for (i = 0; i < count; ++i) { i4 = *(int *) sc_array_index_int (a4, i); SC_CHECK_ABORT (i4 >= i4last, "array_sort"); i4last = i4; } sc_array_resize (a4, 0); elapsed_qsort = start + sc_MPI_Wtime (); SC_STATISTICSF ("Test timings pqueue %g qsort %g\n", elapsed_pqueue, 3. * elapsed_qsort); sc_array_destroy (a4); sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
static void run_bricks (sc_MPI_Comm mpicomm, int per, int l, int rlevel) { int mpiret; int tcount; double elapsed_create, elapsed_partition, elapsed_balance; #ifdef BRICKS_VTK char filename[BUFSIZ]; #endif p4est_connectivity_t *conn; p4est_t *p4est; P4EST_GLOBAL_PRODUCTIONF ("Run bricks on level %d/%d\n", l, rlevel); P4EST_ASSERT (l <= rlevel); /* create and refine the forest */ mpiret = sc_MPI_Barrier (mpicomm); SC_CHECK_MPI (mpiret); elapsed_create = -sc_MPI_Wtime (); tcount = 1 << l; #ifndef P4_TO_P8 conn = p4est_connectivity_new_brick (tcount, tcount, per, per); #else conn = p8est_connectivity_new_brick (tcount, tcount, tcount, per, per, per); #endif p4est = p4est_new_ext (mpicomm, conn, 0, rlevel - l, 1, 0, NULL, NULL); level_shift = 4; refine_level = rlevel - l + level_shift; p4est_refine (p4est, 1, refine_fractal, NULL); elapsed_create += sc_MPI_Wtime (); /* partition the forest */ mpiret = sc_MPI_Barrier (mpicomm); SC_CHECK_MPI (mpiret); elapsed_partition = -sc_MPI_Wtime (); p4est_partition (p4est, 0, NULL); elapsed_partition += sc_MPI_Wtime (); /* balance the forest */ mpiret = sc_MPI_Barrier (mpicomm); SC_CHECK_MPI (mpiret); elapsed_balance = -sc_MPI_Wtime (); p4est_balance (p4est, P4EST_CONNECT_FULL, NULL); elapsed_balance += sc_MPI_Wtime (); /* postprocessing */ P4EST_GLOBAL_PRODUCTIONF ("Timings %g %g %g\n", elapsed_create, elapsed_partition, elapsed_balance); #ifdef BRICKS_VTK snprintf (filename, BUFSIZ, "brick_%02d_%02d_B", rlevel, l); p4est_vtk_write_file (p4est, NULL, filename); #endif p4est_destroy (p4est); p4est_connectivity_destroy (conn); }