Skip to content
Snippets Groups Projects
Commit 0478c9bf authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Updated version of the previous commit that actually compiles with gcc.

parent c2c4b5a1
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ AM_CFLAGS = -g -Wall -Werror -I../src $(OPENMP_CFLAGS) -DCPU_TPS=2.67e9 -DTIMERS ...@@ -26,7 +26,7 @@ AM_CFLAGS = -g -Wall -Werror -I../src $(OPENMP_CFLAGS) -DCPU_TPS=2.67e9 -DTIMERS
AM_LDFLAGS = -lm # -fsanitize=address AM_LDFLAGS = -lm # -fsanitize=address
# Set-up the library # Set-up the library
bin_PROGRAMS = test test_qr test_bh test_bh_2 bin_PROGRAMS = test test_qr test_bh test_bh_2 test_bh_3
# Sources for test # Sources for test
test_SOURCES = test.c test_SOURCES = test.c
...@@ -48,3 +48,8 @@ test_bh_2_SOURCES = test_bh_2.c ...@@ -48,3 +48,8 @@ test_bh_2_SOURCES = test_bh_2.c
test_bh_2_CFLAGS = $(AM_CFLAGS) test_bh_2_CFLAGS = $(AM_CFLAGS)
test_bh_2_LDADD = ../src/.libs/libquicksched.a test_bh_2_LDADD = ../src/.libs/libquicksched.a
# Sources for test_bh_3
test_bh_3_SOURCES = test_bh_3.c
test_bh_3_CFLAGS = $(AM_CFLAGS)
test_bh_3_LDADD = ../src/.libs/libquicksched.a
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
/** Data structure for the particles. */ /** Data structure for the particles. */
struct part { struct part {
double x[3]; double x[3];
double a[3];
double a_legacy[3]; double a_legacy[3];
double a_exact[3]; double a_exact[3];
double mass; double mass;
...@@ -286,9 +287,73 @@ void cell_split ( struct cell *c , struct qsched *s ) { ...@@ -286,9 +287,73 @@ void cell_split ( struct cell *c , struct qsched *s ) {
/* ----------------------------------------------------------------------------------------------- */
/* New tree walk */
/* ----------------------------------------------------------------------------------------------- */
/**
* @brief Compute the center of mass of a given cell.
*
* @param c The #cell.
*/
void comp_com ( struct cell *c ) {
}
/**
* @brief Compute the interactions between all particles in a cell
* and the center of mass of another cell.
*
* @param ci The #cell containing the particles.
* @param cj The #cell containing the center of mass.
*/
void iact_pair_pc ( struct cell *ci , struct cell *cj ) {
}
/**
* @brief Compute the interactions between all particles in a cell.
*
* @param ci The #cell.
* @param cj The other #cell.
*/
void iact_pair ( struct cell *ci , struct cell *cj ) {
}
/**
* @brief Compute the interactions between all particles in a cell.
*
* @param c The #cell.
*/
void iact_self ( struct cell *c ) {
}
/**
* @brief Create the tasks for the cell pair/self.
*
* @param s The #sched in which to create the tasks.
* @param ci The first #cell.
* @param cj The second #cell.
*/
void create_tasks ( struct qsched *s , struct cell *ci , struct cell *cj ) {
}
/* ----------------------------------------------------------------------------------------------- */
/* Legacy tree walk */
/* ----------------------------------------------------------------------------------------------- */
/** /**
* @brief Compute the center of mass of a given cell recursively. * @brief Compute the center of mass of a given cell recursively.
* *
...@@ -298,7 +363,7 @@ void cell_split ( struct cell *c , struct qsched *s ) { ...@@ -298,7 +363,7 @@ void cell_split ( struct cell *c , struct qsched *s ) {
void legacy_comp_com ( struct cell *c , int* countCoMs ) { void legacy_comp_com ( struct cell *c , int* countCoMs ) {
int k, count = c->count; int k, count = c->count;
struct cell *cp, *nextsib; struct cell *cp;
struct part *p, *parts = c->parts; struct part *p, *parts = c->parts;
++(*countCoMs); ++(*countCoMs);
...@@ -389,7 +454,7 @@ void legacy_interact( struct part* parts, int i , struct cell* root , int monito ...@@ -389,7 +454,7 @@ void legacy_interact( struct part* parts, int i , struct cell* root , int monito
int j,k; int j,k;
double r2, dx[3], ir, w; double r2, dx[3], ir, w;
struct cell* cell, *currentcell; struct cell* cell;
cell = root; cell = root;
...@@ -498,7 +563,6 @@ void legacy_interact( struct part* parts, int i , struct cell* root , int monito ...@@ -498,7 +563,6 @@ void legacy_interact( struct part* parts, int i , struct cell* root , int monito
void legacy_tree_walk( int N , struct part* parts , struct cell* root , int monitor , int* countMultipoles, int* countPairs , int* countCoMs ) { void legacy_tree_walk( int N , struct part* parts , struct cell* root , int monitor , int* countMultipoles, int* countPairs , int* countCoMs ) {
int i; int i;
struct cell* last = 0;
/* Compute multipoles (recursively) */ /* Compute multipoles (recursively) */
legacy_comp_com( root , countCoMs ); legacy_comp_com( root , countCoMs );
...@@ -527,6 +591,13 @@ void legacy_tree_walk( int N , struct part* parts , struct cell* root , int moni ...@@ -527,6 +591,13 @@ void legacy_tree_walk( int N , struct part* parts , struct cell* root , int moni
/* ----------------------------------------------------------------------------------------------- */
/* Exact interaction */
/* ----------------------------------------------------------------------------------------------- */
/** /**
* @brief Solve the particle interactions using the stupid N^2 algorithm * @brief Solve the particle interactions using the stupid N^2 algorithm
* *
...@@ -570,6 +641,18 @@ void interact_exact( int N , struct part* parts , int monitor) { ...@@ -570,6 +641,18 @@ void interact_exact( int N , struct part* parts , int monitor) {
/** /**
* @brief Set up and run a task-based Barnes-Hutt N-body solver. * @brief Set up and run a task-based Barnes-Hutt N-body solver.
...@@ -580,13 +663,51 @@ void interact_exact( int N , struct part* parts , int monitor) { ...@@ -580,13 +663,51 @@ void interact_exact( int N , struct part* parts , int monitor) {
void test_bh ( int N , int nr_threads , int runs , char* fileName ) { void test_bh ( int N , int nr_threads , int runs , char* fileName ) {
int i , k; int i , k, dummy;
struct cell *root; struct cell *root;
struct part *parts; struct part *parts;
FILE* file;
struct qsched s; struct qsched s;
ticks tic, toc_run, tot_setup = 0, tot_run = 0, tic_exact, toc_exact; ticks tic, toc_run, tot_setup = 0, tot_run = 0, tic_exact, toc_exact;
int countMultipoles, countPairs, countCoMs; int countMultipoles, countPairs, countCoMs;
/* Runner function. */
void runner ( int type , void *data ) {
ticks tic = getticks();
/* Decode the data. */
struct cell **d = (struct cell **)data;
/* Decode and execute the task. */
switch ( type ) {
case task_type_self:
iact_self( d[0] );
break;
case task_type_pair:
iact_pair( d[0] , d[1] );
break;
case task_type_pair_pc:
iact_pair_pc( d[0] , d[1] );
break;
case task_type_com:
comp_com( d[0] );
break;
default:
error( "Unknown task type." );
}
atomic_add( &task_timers[type] , getticks() - tic );
}
/* Initialize the per-task type timers. */
for ( k = 0 ; k < task_type_count ; k++ )
task_timers[k] = 0;
/* Initialize the scheduler. */ /* Initialize the scheduler. */
qsched_init( &s , nr_threads , qsched_flag_noreown ); qsched_init( &s , nr_threads , qsched_flag_noreown );
...@@ -608,20 +729,21 @@ void test_bh ( int N , int nr_threads , int runs , char* fileName ) { ...@@ -608,20 +729,21 @@ void test_bh ( int N , int nr_threads , int runs , char* fileName ) {
} }
else { else {
FILE* file = fopen( fileName , "r" ); file = fopen( fileName , "r" );
if ( file ) { if ( file ) {
for ( k = 0 ; k < N ; k++ ) { for ( k = 0 ; k < N ; k++ ) {
fscanf( file , "%d" , &parts[k].id ); if( ( dummy = fscanf( file , "%d" , &parts[k].id ) ) );
fscanf( file , "%lf" , &parts[k].x[0] ); if( ( dummy = fscanf( file , "%lf" , &parts[k].x[0] ) ) );
fscanf( file , "%lf" , &parts[k].x[1] ); if( ( dummy = fscanf( file , "%lf" , &parts[k].x[1] ) ) );
fscanf( file , "%lf" , &parts[k].x[2] ); if( ( dummy = fscanf( file , "%lf" , &parts[k].x[2] ) ) );
fscanf( file , "%lf" , &parts[k].mass ); if( ( dummy = fscanf( file , "%lf" , &parts[k].mass ) ) );
parts[k].a_legacy[0] = 0.0; parts[k].a_legacy[0] = 0.0;
parts[k].a_legacy[1] = 0.0; parts[k].a_legacy[1] = 0.0;
parts[k].a_legacy[2] = 0.0; parts[k].a_legacy[2] = 0.0;
} }
fclose( file );
} }
} }
...@@ -646,27 +768,27 @@ void test_bh ( int N , int nr_threads , int runs , char* fileName ) { ...@@ -646,27 +768,27 @@ void test_bh ( int N , int nr_threads , int runs , char* fileName ) {
printf("----------------------------------------------------------\n"); printf("----------------------------------------------------------\n");
/* /\* Create the tasks. *\/ */ /* Create the tasks. */
/* tic = getticks(); */ tic = getticks();
/* create_tasks( &s , root , NULL ); */ create_tasks( &s , root , NULL );
/* tot_setup += getticks() - tic; */ tot_setup += getticks() - tic;
/* /\* Dump the number of tasks. *\/ */ /* Dump the number of tasks. */
/* message( "total nr of tasks: %i." , s.count ); */ message( "total nr of tasks: %i." , s.count );
/* message( "total nr of deps: %i." , s.count_deps ); */ message( "total nr of deps: %i." , s.count_deps );
/* message( "total nr of res: %i." , s.count_res ); */ message( "total nr of res: %i." , s.count_res );
/* message( "total nr of locks: %i." , s.count_locks ); */ message( "total nr of locks: %i." , s.count_locks );
/* message( "total nr of uses: %i." , s.count_uses ); */ message( "total nr of uses: %i." , s.count_uses );
/* int counts[ task_type_count ]; */ int counts[ task_type_count ];
/* for ( k = 0 ; k < task_type_count ; k++ ) */ for ( k = 0 ; k < task_type_count ; k++ )
/* counts[k] = 0; */ counts[k] = 0;
/* for ( k = 0 ; k < s.count ; k++ ) */ for ( k = 0 ; k < s.count ; k++ )
/* counts[ s.tasks[k].type ] += 1; */ counts[ s.tasks[k].type ] += 1;
/* printf( "task counts: [ %8s %8s %8s %8s ]\n" , "self", "direct" , "m-poles" , "CoMs" ); */ printf( "task counts: [ %8s %8s %8s %8s ]\n" , "self", "direct" , "m-poles" , "CoMs" );
/* printf( "task counts: [ " ); */ printf( "task counts: [ " );
/* for ( k = 0 ; k < task_type_count ; k++ ) */ for ( k = 0 ; k < task_type_count ; k++ )
/* printf( "%8i " , counts[k] ); */ printf( "%8i " , counts[k] );
/* printf( "].\n" ); */ printf( "].\n" );
char buffer[200]; char buffer[200];
...@@ -687,7 +809,6 @@ void test_bh ( int N , int nr_threads , int runs , char* fileName ) { ...@@ -687,7 +809,6 @@ void test_bh ( int N , int nr_threads , int runs , char* fileName ) {
countPairs = 0; countPairs = 0;
countCoMs = 0; countCoMs = 0;
/* Execute the legacy walk. */ /* Execute the legacy walk. */
tic = getticks(); tic = getticks();
legacy_tree_walk( N , parts , root , ICHECK , &countMultipoles , &countPairs , &countCoMs ); legacy_tree_walk( N , parts , root , ICHECK , &countMultipoles , &countPairs , &countCoMs );
...@@ -709,23 +830,23 @@ void test_bh ( int N , int nr_threads , int runs , char* fileName ) { ...@@ -709,23 +830,23 @@ void test_bh ( int N , int nr_threads , int runs , char* fileName ) {
/* for ( k = 0 ; k < s.count ; k++ ) */ /* for ( k = 0 ; k < s.count ; k++ ) */
/* printf( " %i %i %lli %lli\n" , s.tasks[k].type , s.tasks[k].qid , s.tasks[k].tic , s.tasks[k].toc ); */ /* printf( " %i %i %lli %lli\n" , s.tasks[k].type , s.tasks[k].qid , s.tasks[k].tic , s.tasks[k].toc ); */
/* /\* Dump the costs. *\/ */ /* Dump the costs. */
/* message( "costs: setup=%lli ticks, run=%lli ticks." , */ message( "costs: setup=%lli ticks, run=%lli ticks." ,
/* tot_setup , tot_run/runs ); */ tot_setup , tot_run/runs );
/* /\* Dump the timers. *\/ */ /* Dump the timers. */
/* for ( k = 0 ; k < qsched_timer_count ; k++ ) */ for ( k = 0 ; k < qsched_timer_count ; k++ )
/* message( "timer %s is %lli ticks." , qsched_timer_names[k] , s.timers[k]/runs ); */ message( "timer %s is %lli ticks." , qsched_timer_names[k] , s.timers[k]/runs );
/* /\* Dump the per-task type timers. *\/ */ /* Dump the per-task type timers. */
/* printf( "task timers: [ " ); */ printf( "task timers: [ " );
/* for ( k = 0 ; k < task_type_count ; k++ ) */ for ( k = 0 ; k < task_type_count ; k++ )
/* printf( "%lli " , task_timers[k]/runs ); */ printf( "%lli " , task_timers[k]/runs );
/* printf( "] ticks.\n" ); */ printf( "] ticks.\n" );
/* Dump the particles to a file */ /* Dump the particles to a file */
FILE* file = fopen( "particle_dump.dat" , "w" ); file = fopen( "particle_dump.dat" , "w" );
fprintf(file, "# a_exact.x a_exact.y a_exact.z a_legacy.x a_legacy.y a_legacy.z a_new.x a_new.y a_new.z\n"); fprintf(file, "# a_exact.x a_exact.y a_exact.z a_legacy.x a_legacy.y a_legacy.z a_new.x a_new.y a_new.z\n");
for ( k = 0 ; k < N ; ++k ) for ( k = 0 ; k < N ; ++k )
fprintf ( file , "%d %e %e %e %e %e %e %e %e %e %e %e %e\n" , fprintf ( file , "%d %e %e %e %e %e %e %e %e %e %e %e %e\n" ,
...@@ -733,7 +854,7 @@ void test_bh ( int N , int nr_threads , int runs , char* fileName ) { ...@@ -733,7 +854,7 @@ void test_bh ( int N , int nr_threads , int runs , char* fileName ) {
parts[k].x[0], parts[k].x[1], parts[k].x[2], parts[k].x[0], parts[k].x[1], parts[k].x[2],
parts[k].a_exact[0] , parts[k].a_exact[1] , parts[k].a_exact[2] , parts[k].a_exact[0] , parts[k].a_exact[1] , parts[k].a_exact[2] ,
parts[k].a_legacy[0] , parts[k].a_legacy[1] , parts[k].a_legacy[2] , parts[k].a_legacy[0] , parts[k].a_legacy[1] , parts[k].a_legacy[2] ,
0., 0., 0. );//parts[k].a[0] , parts[k].a[1] , parts[k].a[2] ); parts[k].a[0] , parts[k].a[1] , parts[k].a[2] );
fclose( file ); fclose( file );
/* Clean up. */ /* Clean up. */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment