Commit 1850e55b authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

several modifications to sub-task generation, added histogram feature.


Former-commit-id: 3ac5029e4d3915288bc53a2526f3712c3999a580
parent 0700702c
......@@ -382,8 +382,8 @@ void runner_dopair ( struct runner_thread *rt , struct cell *ci , struct cell *c
/* Get a hold of the ith part in ci. */
pi = &parts_i[ sort_i[ pid ].i ];
ri = pi->r - rshift;
di = sort_i[pid].d + ri;
ri = pi->r;
di = sort_i[pid].d + ri - rshift;
if ( di < dj_min )
continue;
......@@ -423,8 +423,8 @@ void runner_dopair ( struct runner_thread *rt , struct cell *ci , struct cell *c
/* Get a hold of the jth part in cj. */
pj = &parts_j[ sort_j[ pjd ].i ];
rj = pj->r + rshift;
dj = sort_j[pjd].d - rj;
rj = pj->r;
dj = sort_j[pjd].d - rj - rshift;
if ( dj > di_max )
continue;
......@@ -448,7 +448,7 @@ void runner_dopair ( struct runner_thread *rt , struct cell *ci , struct cell *c
/* Hit or miss? */
if ( r2 < rj2 && r2 > pi->r*pi->r ) {
iact( r2 , 0 , rj , NULL , &pj->count , NULL , &pj->icount );
iact( r2 , pi->r , rj , NULL , &pj->count , NULL , &pj->icount );
}
......
......@@ -93,6 +93,15 @@ extern int runner_counter[ runner_counter_count ];
#define COUNT(c)
#endif
/* Histogram functions. */
#define runner_hist_a 1.0
#define runner_hist_b 6.0
#define runner_hist_N 99
long long int runner_hist_bins[ runner_hist_N ];
#define runner_hist_hit( x ) __sync_add_and_fetch( &runner_hist_bins[ (int)fmax( 0.0 , fmin( runner_hist_N-1 , ((x) - runner_hist_a) / (runner_hist_b - runner_hist_a) * runner_hist_N ) ) ] , 1 )
/* Get the inlining right. */
#ifndef INLINE
# if __GNUC__ && !__GNUC_STDC_INLINE__
......@@ -113,7 +122,7 @@ extern int runner_counter[ runner_counter_count ];
* @param jo Pointer to where to store the interaction of the ith particle.
*/
__attribute__ ((always_inline)) INLINE void iact ( float r2 , float hi , float hj , float *io , float *jo , int *ic , int *jc ) {
__attribute__ ((always_inline)) INLINE void iact ( float r2 , float hi , float hj , float *force_i , float *force_j , int *count_i , int *count_j ) {
#define KERNEL_COEFF_1 2.546479089470f
#define KERNEL_COEFF_2 15.278874536822f
......@@ -126,33 +135,40 @@ __attribute__ ((always_inline)) INLINE void iact ( float r2 , float hi , float h
float r = sqrtf( r2 );
float ui, uj, wi, wj;
if ( r2 < hi*hi ) {
if ( r2 < hi*hi && !( force_i == NULL && count_i == NULL ) ) {
ui = r / hi;
if ( ui < 0.5 )
wi = KERNEL_COEFF_1 + KERNEL_COEFF_2 * (ui - 1.0f) * ui * ui;
else
wi = KERNEL_COEFF_5 * (1.0f - ui) * (1.0f - ui) * (1.0 - ui);
if ( io != NULL )
*io += NORM_COEFF * wi;
if ( ic != NULL )
*ic += 1;
if ( force_i != NULL )
*force_i += NORM_COEFF * wi;
if ( count_i != NULL )
*count_i += 1;
}
if ( r2 < hj*hj ) {
if ( r2 < hj*hj && !( force_j == NULL && count_j == NULL ) ) {
uj = r / hj;
if ( uj < 0.5 )
wj = KERNEL_COEFF_1 + KERNEL_COEFF_2 * (uj - 1.0f) * uj * uj;
else
wj = KERNEL_COEFF_5 * (1.0f - uj) * (1.0f - uj) * (1.0 - uj);
if ( jo != NULL )
*jo += NORM_COEFF * wj;
if ( jc != NULL )
*jc += 1;
if ( force_j != NULL )
*force_j += NORM_COEFF * wj;
if ( count_j != NULL )
*count_j += 1;
}
#ifdef HIST
if ( hi > hj )
runner_hist_hit( hi / hj );
else
runner_hist_hit( hj / hi );
#endif
}
......
......@@ -468,7 +468,7 @@ void space_splittasks ( struct space *s ) {
case 4: /* ( 1 , 0 , 0 ) */
if ( !ci->progeny[4]->split && !ci->progeny[5]->split && !ci->progeny[6]->split && !ci->progeny[7]->split &&
!cj->progeny[0]->split && !cj->progeny[1]->split && !cj->progeny[2]->split && !cj->progeny[3]->split &&
ci->progeny[4]->count + ci->progeny[5]->count + ci->progeny[6]->count + ci->progeny[7]->count + cj->progeny[0]->count + cj->progeny[1]->count + cj->progeny[2]->count + cj->progeny[3]->count < 1.5*space_splitsize ) {
ci->progeny[4]->count + ci->progeny[5]->count + ci->progeny[6]->count + ci->progeny[7]->count + cj->progeny[0]->count + cj->progeny[1]->count + cj->progeny[2]->count + cj->progeny[3]->count < space_splitsize ) {
t->type = tid_sub; t->flags = 4;
task_addunlock( ci->progeny[4]->sorts[4] , t ); task_addunlock( cj->progeny[0]->sorts[4] , t );
task_addunlock( ci->progeny[5]->sorts[5] , t ); task_addunlock( cj->progeny[0]->sorts[5] , t );
......@@ -626,7 +626,7 @@ void space_splittasks ( struct space *s ) {
case 10: /* ( 0 , 1 , 0 ) */
if ( !ci->progeny[2]->split && !ci->progeny[3]->split && !ci->progeny[6]->split && !ci->progeny[7]->split &&
!cj->progeny[0]->split && !cj->progeny[1]->split && !cj->progeny[4]->split && !cj->progeny[5]->split &&
ci->progeny[2]->count + ci->progeny[3]->count + ci->progeny[6]->count + ci->progeny[7]->count + cj->progeny[0]->count + cj->progeny[1]->count + cj->progeny[4]->count + cj->progeny[5]->count < 1.5*space_splitsize ) {
ci->progeny[2]->count + ci->progeny[3]->count + ci->progeny[6]->count + ci->progeny[7]->count + cj->progeny[0]->count + cj->progeny[1]->count + cj->progeny[4]->count + cj->progeny[5]->count < space_splitsize ) {
t->type = tid_sub; t->flags = 10;
task_addunlock( ci->progeny[2]->sorts[10] , t ); task_addunlock( cj->progeny[0]->sorts[10] , t );
task_addunlock( ci->progeny[3]->sorts[11] , t ); task_addunlock( cj->progeny[0]->sorts[11] , t );
......@@ -718,7 +718,7 @@ void space_splittasks ( struct space *s ) {
case 12: /* ( 0 , 0 , 1 ) */
if ( !ci->progeny[1]->split && !ci->progeny[3]->split && !ci->progeny[5]->split && !ci->progeny[7]->split &&
!cj->progeny[0]->split && !cj->progeny[2]->split && !cj->progeny[4]->split && !cj->progeny[6]->split &&
ci->progeny[1]->count + ci->progeny[3]->count + ci->progeny[5]->count + ci->progeny[7]->count + cj->progeny[0]->count + cj->progeny[2]->count + cj->progeny[4]->count + cj->progeny[6]->count < 1.5*space_splitsize ) {
ci->progeny[1]->count + ci->progeny[3]->count + ci->progeny[5]->count + ci->progeny[7]->count + cj->progeny[0]->count + cj->progeny[2]->count + cj->progeny[4]->count + cj->progeny[6]->count < space_splitsize ) {
t->type = tid_sub; t->flags = 12;
task_addunlock( ci->progeny[1]->sorts[12] , t ); task_addunlock( cj->progeny[0]->sorts[12] , t );
task_addunlock( ci->progeny[3]->sorts[11] , t ); task_addunlock( cj->progeny[0]->sorts[11] , t );
......@@ -880,7 +880,7 @@ void space_maketasks ( struct space *s , int do_sort ) {
maketasks_rec( c->progeny[k] , sort , nr_sort , c );
/* Worth splitting into several tasks? */
if ( c->count > 2*space_splitsize ) {
if ( c->count > 1.5*space_splitsize ) {
/* Make a task for eac pair of progeny. */
for ( j = 0 ; j < 8 ; j++ )
......
......@@ -613,6 +613,12 @@ int main ( int argc , char *argv[] ) {
runner_init( &r , &s , nr_threads , nr_queues , runner_policy_steal | runner_policy_keep );
printf( "main: runner_init took %.3f ms.\n" , ((double)(getticks() - tic)) / CPU_TPS * 1000 ); fflush(stdout);
/* Init the runner history. */
#ifdef HIST
for ( k = 0 ; k < runner_hist_N ; k++ )
runner_hist_bins[k] = 0;
#endif
/* Let loose a runner on the space. */
for ( j = 0 ; j < runs ; j++ ) {
printf( "main: starting run %i/%i with %i threads and %i queues...\n" , j+1 , runs , r.nr_threads , r.nr_queues ); fflush(stdout);
......@@ -647,6 +653,16 @@ int main ( int argc , char *argv[] ) {
fflush(stdout);
}
/* Print the values of the runner histogram. */
#ifdef HIST
printf( "main: runner histogram data:\n" );
for ( k = 0 ; k < runner_hist_N ; k++ )
printf( " %e %e %e\n" ,
runner_hist_a + k * (runner_hist_b - runner_hist_a) / runner_hist_N ,
runner_hist_a + (k + 1) * (runner_hist_b - runner_hist_a) / runner_hist_N ,
(double)runner_hist_bins[k] );
#endif
/* Get the average interactions per particle. */
count = 0;
space_map_parts( &s , &map_count , &count );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment