diff --git a/examples/test_bh_new.c b/examples/test_bh_new.c index 2533cff9a9994a75b4863ed119ad5702f7528482..7bce23e0f91bc119d6565e925e2f9e87ec9de5a4 100644 --- a/examples/test_bh_new.c +++ b/examples/test_bh_new.c @@ -45,9 +45,11 @@ #define ICHECK -1 #define NO_SANITY_CHECKS -#define NO_COM_AS_TASK +#define COM_AS_TASK #define NO_COUNTERS -#define QUADRUPOLES +#define NO_QUADRUPOLES + +double itpms = 1000.0/CPU_TPS; /** Data structure for the particles. */ struct part { @@ -1277,10 +1279,12 @@ void test_bh(int N, int nr_threads, int runs, char *fileName) { int i, k; struct cell *root; struct part *parts; - FILE *file; + FILE *file, *fileTime; struct qsched s; ticks tic, toc_run, tot_setup = 0, tot_run = 0; int countMultipoles = 0, countPairs = 0, countCoMs = 0; + char buffer[200]; + /* Runner function. */ void runner(int type, void * data) { @@ -1406,32 +1410,40 @@ void test_bh(int N, int nr_threads, int runs, char *fileName) { for (k = 0; k < task_type_count; k++) counts[k] = 0; for (k = 0; k < s.count; k++) counts[s.tasks[k].type] += 1; - // char buffer[200]; - // sprintf(buffer, "timings_legacy_%d_%d.dat", cell_maxparts, nr_threads); - // FILE *fileTime = fopen(buffer, "w"); - - /* Loop over the number of runs. */ - for (k = 0; k < 1 /* runs */; k++) { - - countMultipoles = 0; - countPairs = 0; - countCoMs = 0; + if (nr_threads == 1) { - /* Execute the legacy walk. */ - tic = getticks(); - legacy_tree_walk(N, parts, root, ICHECK, &countMultipoles, &countPairs, - &countCoMs); - toc_run = getticks(); + /* Prepare for timing test */ + sprintf(buffer, "timings_legacy_%dM.dat", N/1000000); + fileTime = fopen(buffer, "a"); + tot_run = 0.; + omp_set_num_threads(nr_threads); + + + /* Loop over the number of runs. */ + for (k = 0; k < 1; k++) { + + countMultipoles = 0; + countPairs = 0; + countCoMs = 0; + + /* Execute the legacy walk. */ + tic = getticks(); + legacy_tree_walk(N, parts, root, ICHECK, &countMultipoles, &countPairs, + &countCoMs); + toc_run = getticks(); + + /* Dump some timings. */ + message("%ith legacy run took %lli (= %e) ticks... = %e ms", k, toc_run - tic, + (float)(toc_run - tic), (double)(toc_run - tic) * itpms); + tot_run += toc_run - tic; + } + + message("Time: %fms", (tot_run / runs) * itpms); + fprintf(fileTime, "%d %d %d %f\n", N, nr_threads, runs, (tot_run / runs) * itpms); + fclose(fileTime); - /* Dump some timings. */ - message("%ith legacy run took %lli (= %e) ticks...", k, toc_run - tic, - (float)(toc_run - tic)); - tot_run += toc_run - tic; - // fprintf(fileTime, "%lli %e\n", toc_run - tic, (float)(toc_run - tic)); } - // fclose(fileTime); - printf("task counts: [ %10s %10s %10s %10s %10s ]\n", "self", "pair", "m-poles", "direct", "CoMs"); printf("task counts: [ %10i %10i %10i %10i %10i ] (legacy).\n", 0, 0, @@ -1439,6 +1451,16 @@ void test_bh(int N, int nr_threads, int runs, char *fileName) { printf("task counts: [ %10i %10i %10i %10i %10i ] (new).\n", counts[0], counts[1], counts[2], 0, counts[3]); + + + /* Prepare for timing test */ + sprintf(buffer, "timings_new_%dM.dat", N/1000000); + fileTime = fopen(buffer, "a"); + tot_run = 0.; + + /* Dry run */ + qsched_run(&s, nr_threads, runner); + /* Loop over the number of runs. */ for (k = 0; k < runs; k++) { @@ -1452,11 +1474,21 @@ void test_bh(int N, int nr_threads, int runs, char *fileName) { tic = getticks(); qsched_run(&s, nr_threads, runner); toc_run = getticks(); - message("%ith run took %lli (= %e) ticks...", k, toc_run - tic, - (float)(toc_run - tic)); + message("%ith run took %lli (= %e) ticks... = %e ms", k, toc_run - tic, + (float)(toc_run - tic), (double)(toc_run - tic) * itpms); tot_run += toc_run - tic; } + message("Time: %fms", (tot_run / runs) * itpms); + fprintf(fileTime, "%d %d %d %f\n", N, nr_threads, runs, (tot_run / runs) * itpms); + fclose(fileTime); + + + message("[check] root mass= %f %f", root->legacy.mass, root->new.mass); + message("[check] root CoMx= %f %f", root->legacy.com[0], root->new.com[0]); + message("[check] root CoMy= %f %f", root->legacy.com[1], root->new.com[1]); + message("[check] root CoMz= %f %f", root->legacy.com[2], root->new.com[2]); + #if ICHECK >= 0 for (i = 0; i < N; ++i) diff --git a/examples/test_fmm.c b/examples/test_fmm.c index 8513dbcb3595105ddcaf6e4f4b233c3d7c664a0f..9c5b4608fe6684cf344d799d3a44e75c41675bad 100644 --- a/examples/test_fmm.c +++ b/examples/test_fmm.c @@ -50,6 +50,8 @@ #define COUNTERS #define QUADRUPOLES +double itpms = 1000.0/CPU_TPS; + #include "multipoles.h" @@ -1210,10 +1212,12 @@ void test_bh(int N, int nr_threads, int runs, char *fileName) { int i, k; struct cell *root; struct part *parts; - FILE *file; + FILE *file, *fileTime; struct qsched s; ticks tic, toc_run, tot_setup = 0, tot_run = 0; int countMultipoles = 0, countPairs = 0, countCoMs = 0; + char buffer[200]; + /* Runner function. */ void runner(int type, void * data) { @@ -1264,12 +1268,14 @@ void test_bh(int N, int nr_threads, int runs, char *fileName) { parts[k].x[0] = ((double)rand()) / RAND_MAX; parts[k].x[1] = ((double)rand()) / RAND_MAX; parts[k].x[2] = ((double)rand()) / RAND_MAX; - parts[k].mass = 1.f;//((double)rand()) / RAND_MAX; + parts[k].mass = ((double)rand()) / RAND_MAX; parts[k].a_legacy[0] = 0.0; parts[k].a_legacy[1] = 0.0; parts[k].a_legacy[2] = 0.0; } + /* Regular mesh */ + /* int ii, jj, kk; */ /* for (ii = 0; ii < 8; ++ii) { */ /* for (jj = 0; jj < 8; ++jj) { */ @@ -1332,7 +1338,7 @@ void test_bh(int N, int nr_threads, int runs, char *fileName) { } message("Average number of parts per leaf is %f.", ((double)N) / nr_leaves); -#if 1 //ICHECK > 0 +#if ICHECK > 0 printf("----------------------------------------------------------\n"); /* Do a N^2 interactions calculation */ @@ -1362,32 +1368,40 @@ void test_bh(int N, int nr_threads, int runs, char *fileName) { for (k = 0; k < task_type_count; k++) counts[k] = 0; for (k = 0; k < s.count; k++) counts[s.tasks[k].type] += 1; - // char buffer[200]; - // sprintf(buffer, "timings_legacy_%d_%d.dat", cell_maxparts, nr_threads); - // FILE *fileTime = fopen(buffer, "w"); - - /* Loop over the number of runs. */ - for (k = 0; k < 1 /* runs */; k++) { - - countMultipoles = 0; - countPairs = 0; - countCoMs = 0; + if (nr_threads == 1) { - /* Execute the legacy walk. */ - tic = getticks(); - legacy_tree_walk(N, parts, root, ICHECK, &countMultipoles, &countPairs, - &countCoMs); - toc_run = getticks(); + /* Prepare for timing test */ + sprintf(buffer, "timings_legacy_fmm_%dM.dat", N/1000000); + fileTime = fopen(buffer, "a"); + tot_run = 0.; + omp_set_num_threads(nr_threads); + + + /* Loop over the number of runs. */ + for (k = 0; k < 1; k++) { + + countMultipoles = 0; + countPairs = 0; + countCoMs = 0; + + /* Execute the legacy walk. */ + tic = getticks(); + legacy_tree_walk(N, parts, root, ICHECK, &countMultipoles, &countPairs, + &countCoMs); + toc_run = getticks(); + + /* Dump some timings. */ + message("%ith legacy run took %lli (= %e) ticks... = %e ms", k, toc_run - tic, + (float)(toc_run - tic), (double)(toc_run - tic) * itpms); + tot_run += toc_run - tic; + } + + message("Time: %fms", (tot_run / runs) * itpms); + fprintf(fileTime, "%d %d %d %f\n", N, nr_threads, runs, (tot_run / runs) * itpms); + fclose(fileTime); - /* Dump some timings. */ - message("%ith legacy run took %lli (= %e) ticks...", k, toc_run - tic, - (float)(toc_run - tic)); - tot_run += toc_run - tic; - // fprintf(fileTime, "%lli %e\n", toc_run - tic, (float)(toc_run - tic)); } - // fclose(fileTime); - printf("task counts: [ %10s %10s %10s %10s %10s %10s ]\n", "self", "pair", "m-poles", "direct", "CoMs", "Downpass"); printf("task counts: [ %10i %10i %10i %10i %10i %10i ] (legacy).\n", 0, 0, @@ -1395,6 +1409,15 @@ void test_bh(int N, int nr_threads, int runs, char *fileName) { printf("task counts: [ %10i %10i %10i %10i %10i %10i ] (new).\n", counts[0], counts[1], counts[2], 0, counts[3], counts[4]); + + /* Prepare for timing test */ + sprintf(buffer, "timings_fmm_%dM.dat", N/1000000); + fileTime = fopen(buffer, "a"); + tot_run = 0.; + + /* Dry run */ + qsched_run(&s, nr_threads, runner); + /* Loop over the number of runs. */ for (k = 0; k < runs; k++) { @@ -1411,11 +1434,15 @@ void test_bh(int N, int nr_threads, int runs, char *fileName) { comp_down(root); #endif toc_run = getticks(); - message("%ith run took %lli (= %e) ticks...", k, toc_run - tic, - (float)(toc_run - tic)); + message("%ith run took %lli (= %e) ticks... = %e ms", k, toc_run - tic, + (float)(toc_run - tic), (double)(toc_run - tic) * itpms); tot_run += toc_run - tic; } + message("Time: %fms", (tot_run / runs) * itpms); + fprintf(fileTime, "%d %d %d %f\n", N, nr_threads, runs, (tot_run / runs) * itpms); + fclose(fileTime); + message("[check] root mass= %f %f", root->legacy.mass, root->new.M_000); message("[check] root CoMx= %f %f", root->legacy.com[0], root->new.M_100); message("[check] root CoMy= %f %f", root->legacy.com[1], root->new.M_010);