test.c 34 KB
Newer Older
1
/*******************************************************************************
2
 * This file is part of SWIFT.
3
4
 * Coypright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk),
 *                    Matthieu Schaller (matthieu.schaller@durham.ac.uk)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 ******************************************************************************/

Pedro Gonnet's avatar
Pedro Gonnet committed
21
22
/* Config parameters. */
#include "../config.h"
Pedro Gonnet's avatar
Pedro Gonnet committed
23
24
25
26
27
28
29
30

/* Some standard headers. */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
#include <math.h>
Pedro Gonnet's avatar
Pedro Gonnet committed
31
32
#include <float.h>
#include <limits.h>
33
#include <fenv.h>
Pedro Gonnet's avatar
Pedro Gonnet committed
34
35
#include <omp.h>

Pedro Gonnet's avatar
Pedro Gonnet committed
36
/* Conditional headers. */
Pedro Gonnet's avatar
Pedro Gonnet committed
37
38
#ifdef HAVE_LIBZ
    #include <zlib.h>
Pedro Gonnet's avatar
Pedro Gonnet committed
39
40
#endif

Pedro Gonnet's avatar
Pedro Gonnet committed
41
/* Local headers. */
42
#include "swift.h"
Pedro Gonnet's avatar
Pedro Gonnet committed
43
44
45
46
47
48

/* Ticks per second on this machine. */
#ifndef CPU_TPS
    #define CPU_TPS 2.67e9
#endif

49
50
51
52
53
/* Engine policy flags. */
#ifndef ENGINE_POLICY
    #define ENGINE_POLICY engine_policy_none
#endif

Pedro Gonnet's avatar
Pedro Gonnet committed
54
55
56
57
58
59
60
61
62
63
/* Error macro. */
#define error(s) { printf( "%s:%s:%i: %s\n" , __FILE__ , __FUNCTION__ , __LINE__ , s ); abort(); }


/**
 * @brief Mapping function to draw a specific cell (gnuplot).
 */

void map_cells_plot ( struct cell *c , void *data ) {

Pedro Gonnet's avatar
Pedro Gonnet committed
64
    int depth = *(int *)data;
Pedro Gonnet's avatar
Pedro Gonnet committed
65
66
    double *l = c->loc, *h = c->h;

Pedro Gonnet's avatar
Pedro Gonnet committed
67
    if ( c->depth <= depth ) {
Pedro Gonnet's avatar
Pedro Gonnet committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    
        printf( "%.16e %.16e %.16e\n" , l[0] , l[1] , l[2] );
        printf( "%.16e %.16e %.16e\n" , l[0]+h[0] , l[1] , l[2] );
        printf( "%.16e %.16e %.16e\n" , l[0]+h[0] , l[1]+h[1] , l[2] );
        printf( "%.16e %.16e %.16e\n\n\n" , l[0] , l[1]+h[1] , l[2] );
    
        printf( "%.16e %.16e %.16e\n" , l[0] , l[1] , l[2]+h[2] );
        printf( "%.16e %.16e %.16e\n" , l[0]+h[0] , l[1] , l[2]+h[2] );
        printf( "%.16e %.16e %.16e\n" , l[0]+h[0] , l[1]+h[1] , l[2]+h[2] );
        printf( "%.16e %.16e %.16e\n\n\n" , l[0] , l[1]+h[1] , l[2]+h[2] );
    
        printf( "%.16e %.16e %.16e\n" , l[0] , l[1] , l[2] );
        printf( "%.16e %.16e %.16e\n" , l[0] , l[1]+h[1] , l[2] );
        printf( "%.16e %.16e %.16e\n" , l[0] , l[1]+h[1] , l[2]+h[2] );
        printf( "%.16e %.16e %.16e\n\n\n" , l[0] , l[1] , l[2]+h[2] );
    
        printf( "%.16e %.16e %.16e\n" , l[0]+h[0] , l[1] , l[2] );
        printf( "%.16e %.16e %.16e\n" , l[0]+h[0] , l[1]+h[1] , l[2] );
        printf( "%.16e %.16e %.16e\n" , l[0]+h[0] , l[1]+h[1] , l[2]+h[2] );
        printf( "%.16e %.16e %.16e\n\n\n" , l[0]+h[0] , l[1] , l[2] +h[2]);
    
        printf( "%.16e %.16e %.16e\n" , l[0] , l[1] , l[2] );
        printf( "%.16e %.16e %.16e\n" , l[0] , l[1] , l[2]+h[2] );
        printf( "%.16e %.16e %.16e\n" , l[0]+h[0] , l[1] , l[2]+h[2] );
        printf( "%.16e %.16e %.16e\n\n\n" , l[0]+h[0] , l[1] , l[2] );
    
        printf( "%.16e %.16e %.16e\n" , l[0] , l[1]+h[1] , l[2] );
        printf( "%.16e %.16e %.16e\n" , l[0] , l[1]+h[1] , l[2]+h[2] );
        printf( "%.16e %.16e %.16e\n" , l[0]+h[0] , l[1]+h[1] , l[2]+h[2] );
        printf( "%.16e %.16e %.16e\n\n\n" , l[0]+h[0] , l[1]+h[1] , l[2] );
        
Pedro Gonnet's avatar
Pedro Gonnet committed
99
        if ( !c->split ) {
Pedro Gonnet's avatar
Pedro Gonnet committed
100
            for ( int k = 0 ; k < c->count ; k++ )
Pedro Gonnet's avatar
Pedro Gonnet committed
101
102
103
104
                printf( "0 0 0 %.16e %.16e %.16e\n" ,
                    c->parts[k].x[0] , c->parts[k].x[1] , c->parts[k].x[2] );
            printf( "\n\n" );
            }
Pedro Gonnet's avatar
Pedro Gonnet committed
105
106
107
108
        /* else
            for ( int k = 0 ; k < 8 ; k++ )
                if ( c->progeny[k] != NULL )
                    map_cells_plot( c->progeny[k] , data ); */
Pedro Gonnet's avatar
Pedro Gonnet committed
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    
        }

    }


/**
 * @brief Mapping function for checking if each part is in its box.
 */

/* void map_check ( struct part *p , struct cell *c , void *data ) {

    if ( p->x[0] < c->loc[0] || p->x[0] > c->loc[0]+c->h[0] ||
         p->x[0] < c->loc[0] || p->x[0] > c->loc[0]+c->h[0] ||
         p->x[0] < c->loc[0] || p->x[0] > c->loc[0]+c->h[0] )
        printf( "map_check: particle %i is outside of its box.\n" , p->id );

    } */


129
130
131
132
/**
 * @brief Mapping function for neighbour count.
 */

Pedro Gonnet's avatar
Pedro Gonnet committed
133
134
135
136
137
138
139
140
141
142
143
void map_cellcheck ( struct cell *c , void *data ) {

    int k, *count = (int *)data;
    struct part *p;
    
    /* Loop over all parts and check if they are in the cell. */
    for ( k = 0 ; k < c->count ; k++ ) {
        *count += 1;
        p = &c->parts[k];
        if ( p->x[0] < c->loc[0] || p->x[1] < c->loc[1] || p->x[2] < c->loc[2] ||
             p->x[0] > c->loc[0] + c->h[0] || p->x[1] > c->loc[1] + c->h[1] || p->x[2] > c->loc[2] + c->h[2] ) {
Pedro Gonnet's avatar
Pedro Gonnet committed
144
            printf( "map_cellcheck: particle at [ %.16e %.16e %.16e ] outside of cell [ %.16e %.16e %.16e ] - [ %.16e %.16e %.16e ].\n" ,
Pedro Gonnet's avatar
Pedro Gonnet committed
145
146
147
148
149
150
151
152
153
154
155
156
157
158
                p->x[0] , p->x[1] , p->x[2] ,
                c->loc[0] , c->loc[1] , c->loc[2] ,
                c->loc[0] + c->h[0] , c->loc[1] + c->h[1] , c->loc[2] + c->h[2] );
            error( "particle out of bounds!" );
            }
        }

    }


/**
 * @brief Mapping function for maxdepth cell count.
 */

159
160
161
162
163
164
165
166
167
168
169
170
171
void map_maxdepth ( struct cell *c , void *data ) {

    int maxdepth = ((int *)data)[0];
    int *count = &((int *)data)[1];
    
    // printf( "%e\n" , p->count );

    if ( c->depth == maxdepth )
        *count += 1;

    }


Pedro Gonnet's avatar
Pedro Gonnet committed
172
173
174
175
176
177
/**
 * @brief Mapping function for neighbour count.
 */

void map_count ( struct part *p , struct cell *c , void *data ) {

178
    double *wcount = (double *)data;
Pedro Gonnet's avatar
Pedro Gonnet committed
179
    
Pedro Gonnet's avatar
Pedro Gonnet committed
180
    // printf( "%i %e %e\n" , p->id , p->count , p->count_dh );
Pedro Gonnet's avatar
Pedro Gonnet committed
181

182
    *wcount += p->density.wcount;
Pedro Gonnet's avatar
Pedro Gonnet committed
183
184
185

    }

Pedro Gonnet's avatar
Pedro Gonnet committed
186
187
188
189
void map_wcount_min ( struct part *p , struct cell *c , void *data ) {

    struct part **p2 = (struct part **)data;
    
190
    if ( p->density.wcount < (*p2)->density.wcount )
Pedro Gonnet's avatar
Pedro Gonnet committed
191
192
193
194
195
196
197
198
        *p2 = p;

    }

void map_wcount_max ( struct part *p , struct cell *c , void *data ) {

    struct part **p2 = (struct part **)data;
    
199
    if ( p->density.wcount > (*p2)->density.wcount )
Pedro Gonnet's avatar
Pedro Gonnet committed
200
201
202
203
        *p2 = p;

    }

204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
void map_h_min ( struct part *p , struct cell *c , void *data ) {

    struct part **p2 = (struct part **)data;
    
    if ( p->h < (*p2)->h )
        *p2 = p;

    }

void map_h_max ( struct part *p , struct cell *c , void *data ) {

    struct part **p2 = (struct part **)data;
    
    if ( p->h > (*p2)->h )
        *p2 = p;

    }

Pedro Gonnet's avatar
Pedro Gonnet committed
222
223
224
225
226
227
228

/**
 * @brief Mapping function for neighbour count.
 */

void map_icount ( struct part *p , struct cell *c , void *data ) {

Pedro Gonnet's avatar
Pedro Gonnet committed
229
    // int *count = (int *)data;
Pedro Gonnet's avatar
Pedro Gonnet committed
230
231
232
    
    // printf( "%i\n" , p->icount );

Pedro Gonnet's avatar
Pedro Gonnet committed
233
    // *count += p->icount;
Pedro Gonnet's avatar
Pedro Gonnet committed
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260

    }


/**
 * @brief Mapping function to print the particle position.
 */

void map_dump ( struct part *p , struct cell *c , void *data ) {

    double *shift = (double *)data;

    printf( "%g\t%g\t%g\n" , p->x[0]-shift[0] , p->x[1]-shift[1] , p->x[2]-shift[2] );

    }


/**
 * @brief Read coordinates from a text file.
 *
 * @param fname The name of the coordinate file.
 * @param parts An array of #part in which to store the coordinates.
 * @param N The number of parts to read.
 */
 
void read_coords ( char *fname , struct part *parts , int N ) {

Pedro Gonnet's avatar
Pedro Gonnet committed
261
#ifdef HAVE_LIBZ
Pedro Gonnet's avatar
Pedro Gonnet committed
262
    gzFile fd;
Pedro Gonnet's avatar
Pedro Gonnet committed
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
    char buff[1024];
    int k;
    
    /* Open the given file. */
    if ( ( fd = gzopen( fname , "r" ) ) == NULL )
        error( "Failed to open coordinate file" );
        
    /* Read the coordinates into the part positions. */
    for ( k = 0 ; k < N ; k++ ) {
        if ( gzgets( fd , buff , 1024 ) == NULL )
            error( "Error reading coordinate file." );
        if ( sscanf( buff , "%lf %lf %lf" , &parts[k].x[0] , &parts[k].x[1] , &parts[k].x[2] ) != 3 ) {
            printf( "read_coords: failed to parse %ith entry.\n" , k );
            error( "Error parsing coordinate file." );
            }
        }
        
    /* Wrap it up. */
    gzclose( fd );
#else
Pedro Gonnet's avatar
Pedro Gonnet committed
283
284
285
286
287
288
289
290
291
292
293
294
295
296
    FILE *fd;
    int k;
    
    /* Open the given file. */
    if ( ( fd = fopen( fname , "r" ) ) == NULL )
        error( "Failed to open coordinate file" );
        
    /* Read the coordinates into the part positions. */
    for ( k = 0 ; k < N ; k++ ) {
        if ( fscanf( fd , "%lf %lf %lf" , &parts[k].x[0] , &parts[k].x[1] , &parts[k].x[2] ) != 3 ) {
            printf( "read_coords: failed to read %ith entry.\n" , k );
            error( "Error reading coordinate file." );
            }
        }
Pedro Gonnet's avatar
Pedro Gonnet committed
297
298
299
300
        
    /* Wrap it up. */
    fclose( fd );
#endif
Pedro Gonnet's avatar
Pedro Gonnet committed
301
302
303
304
305
306
307
308
309
310
311
312
313
314

    }


/**
 * @brief Read cutoffs from a text file.
 *
 * @param fname The name of the cutoffs file.
 * @param parts An array of #part in which to store the cutoffs.
 * @param N The number of parts to read.
 */
 
void read_cutoffs ( char *fname , struct part *parts , int N ) {

Pedro Gonnet's avatar
Pedro Gonnet committed
315
#ifdef HAVE_LIBZ
Pedro Gonnet's avatar
Pedro Gonnet committed
316
    gzFile fd;
Pedro Gonnet's avatar
Pedro Gonnet committed
317
318
319
320
321
322
323
324
325
326
327
    char buff[1024];
    int k;
    
    /* Open the given file. */
    if ( ( fd = gzopen( fname , "r" ) ) == NULL )
        error( "Failed to open cutoff file" );
        
    /* Read the coordinates into the part positions. */
    for ( k = 0 ; k < N ; k++ ) {
        if ( gzgets( fd , buff , 1024 ) == NULL )
            error( "Error reading cutoff file." );
Pedro Gonnet's avatar
Pedro Gonnet committed
328
        if ( sscanf( buff , "%ef" , &parts[k].h ) != 1 ) {
Pedro Gonnet's avatar
Pedro Gonnet committed
329
330
331
332
333
334
335
336
            printf( "read_cutoffs: failed to parse %ith entry.\n" , k );
            error( "Error parsing cutoff file." );
            }
        }
        
    /* Wrap it up. */
    gzclose( fd );
#else
Pedro Gonnet's avatar
Pedro Gonnet committed
337
338
339
340
341
342
343
344
345
    FILE *fd;
    int k;
    
    /* Open the given file. */
    if ( ( fd = fopen( fname , "r" ) ) == NULL )
        error( "Failed to open cutoff file" );
        
    /* Read the coordinates into the part positions. */
    for ( k = 0 ; k < N ; k++ ) {
Pedro Gonnet's avatar
Pedro Gonnet committed
346
        if ( fscanf( fd , "%ef" , &parts[k].h ) != 1 ) {
Pedro Gonnet's avatar
Pedro Gonnet committed
347
348
349
350
            printf( "read_cutoffs: failed to read %ith entry.\n" , k );
            error( "Error reading cutoff file." );
            }
        }
Pedro Gonnet's avatar
Pedro Gonnet committed
351
352
353
354
        
    /* Wrap it up. */
    fclose( fd );
#endif
Pedro Gonnet's avatar
Pedro Gonnet committed
355
356
357
358
359
360
361
362
363
364
365
366
367
368

    }
    
    
/**
 * @brief Read id from a text file.
 *
 * @param fname The name of the id file.
 * @param parts An array of #part in which to store the dt.
 * @param N The number of parts to read.
 */
 
void read_id ( char *fname , struct part *parts , int N ) {

Pedro Gonnet's avatar
Pedro Gonnet committed
369
#ifdef HAVE_LIBZ
Pedro Gonnet's avatar
Pedro Gonnet committed
370
    gzFile fd;
Pedro Gonnet's avatar
Pedro Gonnet committed
371
372
373
374
375
376
377
378
379
380
381
    char buff[1024];
    int k;
    
    /* Open the given file. */
    if ( ( fd = gzopen( fname , "r" ) ) == NULL )
        error( "Failed to open id file" );
        
    /* Read the coordinates into the part positions. */
    for ( k = 0 ; k < N ; k++ ) {
        if ( gzgets( fd , buff , 1024 ) == NULL )
            error( "Error reading id file." );
382
        if ( sscanf( buff , "%lli" , &parts[k].id ) != 1 ) {
Pedro Gonnet's avatar
Pedro Gonnet committed
383
384
385
386
387
388
389
390
            printf( "read_id: failed to parse %ith entry.\n" , k );
            error( "Error parsing id file." );
            }
        }
        
    /* Wrap it up. */
    gzclose( fd );
#else
Pedro Gonnet's avatar
Pedro Gonnet committed
391
392
393
394
395
396
397
398
399
    FILE *fd;
    int k;
    
    /* Open the given file. */
    if ( ( fd = fopen( fname , "r" ) ) == NULL )
        error( "Failed to open id file" );
        
    /* Read the coordinates into the part positions. */
    for ( k = 0 ; k < N ; k++ ) {
Pedro Gonnet's avatar
Pedro Gonnet committed
400
        if ( fscanf( fd , "%lli" , &parts[k].id ) != 1 ) {
Pedro Gonnet's avatar
Pedro Gonnet committed
401
402
403
404
405
            printf( "read_id: failed to read %ith entry.\n" , k );
            error( "Error reading id file." );
            }
        }

Pedro Gonnet's avatar
Pedro Gonnet committed
406
407
408
409
    /* Wrap it up. */
    fclose( fd );
#endif

Pedro Gonnet's avatar
Pedro Gonnet committed
410
411
412
413
414
415
416
417
418
419
420
421
422
    }
    
    
/**
 * @brief Read dt from a text file.
 *
 * @param fname The name of the dt file.
 * @param parts An array of #part in which to store the dt.
 * @param N The number of parts to read.
 */
 
void read_dt ( char *fname , struct part *parts , int N ) {

Pedro Gonnet's avatar
Pedro Gonnet committed
423
#ifdef HAVE_LIBZ
Pedro Gonnet's avatar
Pedro Gonnet committed
424
    gzFile fd;
Pedro Gonnet's avatar
Pedro Gonnet committed
425
426
427
428
429
430
431
432
433
434
435
    char buff[1024];
    int k;
    
    /* Open the given file. */
    if ( ( fd = gzopen( fname , "r" ) ) == NULL )
        error( "Failed to open dt file" );
        
    /* Read the coordinates into the part positions. */
    for ( k = 0 ; k < N ; k++ ) {
        if ( gzgets( fd , buff , 1024 ) == NULL )
            error( "Error reading id file." );
436
        if ( sscanf( buff , "%f" , &parts[k].dt ) != 1 )
Pedro Gonnet's avatar
Pedro Gonnet committed
437
438
439
440
441
442
            error( "Error parsing dt file." );
        }
        
    /* Wrap it up. */
    gzclose( fd );
#else
Pedro Gonnet's avatar
Pedro Gonnet committed
443
444
445
446
447
448
449
450
451
452
453
454
455
    FILE *fd;
    int k;
    
    /* Open the given file. */
    if ( ( fd = fopen( fname , "r" ) ) == NULL )
        error( "Failed to open dt file" );
        
    /* Read the coordinates into the part positions. */
    for ( k = 0 ; k < N ; k++ ) {
        if ( fscanf( fd , "%ef" , &parts[k].dt ) != 1 )
            error( "Error reading dt file." );
        }

Pedro Gonnet's avatar
Pedro Gonnet committed
456
457
458
459
    /* Wrap it up. */
    fclose( fd );
#endif

Pedro Gonnet's avatar
Pedro Gonnet committed
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
    }
    
    
/**
 * @brief Compute the average number of pairs per particle using
 *      a brute-force O(N^2) computation.
 *
 * @param dim The space dimensions.
 * @param parts The #part array.
 * @param N The number of parts.
 * @param periodic Periodic boundary conditions flag.
 */

void pairs_n2 ( double *dim , struct part *__restrict__ parts , int N , int periodic ) {

Pedro Gonnet's avatar
Pedro Gonnet committed
475
476
477
478
479
    int i, j, k, count = 0;
    // int mj, mk;
    // double maxratio = 1.0;
    double r2, dx[3], rho = 0.0;
    double rho_max = 0.0, rho_min = 100;
Pedro Gonnet's avatar
Pedro Gonnet committed
480
481
    
    /* Loop over all particle pairs. */
Pedro Gonnet's avatar
Pedro Gonnet committed
482
    #pragma omp parallel for schedule(dynamic), default(none), private(k,i,dx,r2), shared(periodic,parts,dim,N,stdout)
Pedro Gonnet's avatar
Pedro Gonnet committed
483
484
    for ( j = 0 ; j < N ; j++ ) {
        if ( j % 1000 == 0 ) {
Pedro Gonnet's avatar
Pedro Gonnet committed
485
            printf( "pairs_n2: j=%i.\n" , j );
Pedro Gonnet's avatar
Pedro Gonnet committed
486
487
488
489
490
491
492
493
494
495
496
497
            fflush(stdout);
            }
        for ( k = j+1 ; k < N ; k++ ) {
            for ( i = 0 ; i < 3 ; i++ ) {
                dx[i] = parts[j].x[i] - parts[k].x[i];
                if ( periodic ) {
                    if ( dx[i] < -dim[i]/2 )
                        dx[i] += dim[i];
                    else if ( dx[i] > dim[i]/2 )
                        dx[i] -= dim[i];
                    }
                }
Pedro Gonnet's avatar
Pedro Gonnet committed
498
            r2 = dx[0]*dx[0] + dx[1]*dx[1] + dx[2]*dx[2];
Pedro Gonnet's avatar
Pedro Gonnet committed
499
            if ( r2 < parts[j].h*parts[j].h || r2 < parts[k].h*parts[k].h ) {
500
                runner_iact_density( r2 , NULL , parts[j].h , parts[k].h , &parts[j] , &parts[k] );
Pedro Gonnet's avatar
Pedro Gonnet committed
501
                /* if ( parts[j].h / parts[k].h > maxratio )
Pedro Gonnet's avatar
Pedro Gonnet committed
502
503
                    #pragma omp critical
                    {
Pedro Gonnet's avatar
Pedro Gonnet committed
504
                    maxratio = parts[j].h / parts[k].h;
Pedro Gonnet's avatar
Pedro Gonnet committed
505
506
                    mj = j; mk = k;
                    }
Pedro Gonnet's avatar
Pedro Gonnet committed
507
                else if ( parts[k].h / parts[j].h > maxratio )
Pedro Gonnet's avatar
Pedro Gonnet committed
508
509
                    #pragma omp critical
                    {
Pedro Gonnet's avatar
Pedro Gonnet committed
510
                    maxratio = parts[k].h / parts[j].h;
Pedro Gonnet's avatar
Pedro Gonnet committed
511
                    mj = j; mk = k;
Pedro Gonnet's avatar
Pedro Gonnet committed
512
                    } */
Pedro Gonnet's avatar
Pedro Gonnet committed
513
514
515
                }
            }
        }
Pedro Gonnet's avatar
Pedro Gonnet committed
516
517
518
        
    /* Aggregate the results. */
    for ( k = 0 ; k < N ; k++ ) {
Pedro Gonnet's avatar
Pedro Gonnet committed
519
        // count += parts[k].icount;
520
521
522
        rho += parts[k].density.wcount;
        rho_min = fmin( parts[k].density.wcount , rho_min );
        rho_min = fmax( parts[k].density.wcount , rho_max );
Pedro Gonnet's avatar
Pedro Gonnet committed
523
        }
Pedro Gonnet's avatar
Pedro Gonnet committed
524
525
            
    /* Dump the result. */
Pedro Gonnet's avatar
Pedro Gonnet committed
526
    printf( "pairs_n2: avg. density per part is %.3f (nr. pairs %.3f).\n" , rho/N + 32.0/3 , ((double)count)/N );
Pedro Gonnet's avatar
Pedro Gonnet committed
527
528
    printf( "pairs_n2: densities are in [ %e , %e ].\n" , rho_min/N + 32.0/3 , rho_max/N + 32.0/3 );
    /* printf( "pairs_n2: maximum ratio between parts %i [%e,%e,%e] and %i [%e,%e,%e] is %.3f/%.3f\n" ,
Pedro Gonnet's avatar
Pedro Gonnet committed
529
530
        mj , parts[mj].x[0] , parts[mj].x[1] , parts[mj].x[2] ,
        mk , parts[mk].x[0] , parts[mk].x[1] , parts[mk].x[2] ,
Pedro Gonnet's avatar
Pedro Gonnet committed
531
532
533
534
535
536
        parts[mj].h , parts[mk].h ); fflush(stdout); */
    fflush(stdout);
            
    }


537
void pairs_single ( double *dim , long long int pid , struct part *__restrict__ parts , int N , int periodic ) {
Pedro Gonnet's avatar
Pedro Gonnet committed
538
539
540
541
542

    int i, k;
    // int mj, mk;
    // double maxratio = 1.0;
    double r2, dx[3];
543
544
545
    float fdx[3];
    struct part p;
    // double ih = 12.0/6.25;
546
547
548
549
550
    
    /* Find "our" part. */
    for ( k = 0 ; k < N && parts[k].id != pid ; k++ );
    if ( k == N )
        error( "Part not found." );
551
    p = parts[k];
552
    printf( "pairs_single: part[%i].id == %lli.\n" , k , pid );
Pedro Gonnet's avatar
Pedro Gonnet committed
553
    
554
555
556
557
558
    p.rho = 0.0;
    p.density.wcount = 0.0;
    // p.icount = 0;
    p.rho_dh = 0.0;
            
Pedro Gonnet's avatar
Pedro Gonnet committed
559
560
    /* Loop over all particle pairs. */
    for ( k = 0 ; k < N ; k++ ) {
561
        if ( parts[k].id == p.id )
Pedro Gonnet's avatar
Pedro Gonnet committed
562
563
            continue;
        for ( i = 0 ; i < 3 ; i++ ) {
564
            dx[i] = p.x[i] - parts[k].x[i];
Pedro Gonnet's avatar
Pedro Gonnet committed
565
566
567
568
569
570
            if ( periodic ) {
                if ( dx[i] < -dim[i]/2 )
                    dx[i] += dim[i];
                else if ( dx[i] > dim[i]/2 )
                    dx[i] -= dim[i];
                }
571
            fdx[i] = dx[i];
Pedro Gonnet's avatar
Pedro Gonnet committed
572
            }
573
574
575
576
577
        r2 = fdx[0]*fdx[0] + fdx[1]*fdx[1] + fdx[2]*fdx[2];
        if ( r2 < p.h*p.h ) {
            runner_iact_nonsym_density( r2 , fdx , p.h , parts[k].h , &p , &parts[k] );
            /* printf( "pairs_simple: interacting particles %lli [%i,%i,%i] and %lli [%i,%i,%i], r=%e.\n" ,
                pid , (int)(p.x[0]*ih) , (int)(p.x[1]*ih) , (int)(p.x[2]*ih) ,
578
                parts[k].id , (int)(parts[k].x[0]*ih) , (int)(parts[k].x[1]*ih) , (int)(parts[k].x[2]*ih) ,
579
                sqrtf(r2) ); */
Pedro Gonnet's avatar
Pedro Gonnet committed
580
581
582
583
            }
        }
        
    /* Dump the result. */
584
    printf( "pairs_single: wcount of part %lli (h=%e) is %f.\n" , p.id , p.h , p.density.wcount + 32.0/3 );
Pedro Gonnet's avatar
Pedro Gonnet committed
585
    fflush(stdout);
Pedro Gonnet's avatar
Pedro Gonnet committed
586
    
Pedro Gonnet's avatar
Pedro Gonnet committed
587
588
589
590
591
592
593
594
595
596
597
598
599
    }


/**
 * @brief Find the pairs of a single particle
 *
 * @param dim The space dimensions.
 * @param parts The #part array.
 * @param N The number of parts.
 * @param periodic Periodic boundary conditions flag.
 * @param target the index of the target particle.
 */

Pedro Gonnet's avatar
Pedro Gonnet committed
600
void pairs_single_old ( double *dim , struct part *__restrict__ parts , int N , int periodic , int target ) {
Pedro Gonnet's avatar
Pedro Gonnet committed
601
602

    int i, k, tid;
Pedro Gonnet's avatar
Pedro Gonnet committed
603
    double r, tx[3], th, dx[3];
Pedro Gonnet's avatar
Pedro Gonnet committed
604
605
606
607
    
    /* Get the target position and radius. */
    for ( k = 0 ; k < 3 ; k++ )
        tx[k] = parts[target].x[k];
Pedro Gonnet's avatar
Pedro Gonnet committed
608
    th = parts[target].h;
Pedro Gonnet's avatar
Pedro Gonnet committed
609
610
611
    tid = parts[target].id;
    
    /* Loop over all particle pairs. */
Pedro Gonnet's avatar
Pedro Gonnet committed
612
    #pragma omp parallel for schedule(dynamic), default(none), private(k,i,dx,r), shared(target,tx,th,tid,periodic,parts,dim,N)
Pedro Gonnet's avatar
Pedro Gonnet committed
613
614
615
616
617
618
619
620
621
622
623
624
625
    for ( k = 0 ; k < N ; k++ ) {
        if ( k == target )
            continue;
        for ( i = 0 ; i < 3 ; i++ ) {
            dx[i] = tx[i] - parts[k].x[i];
            if ( periodic ) {
                if ( dx[i] < -dim[i]/2 )
                    dx[i] += dim[i];
                else if ( dx[i] > dim[i]/2 )
                    dx[i] -= dim[i];
                }
            }
        r = sqrt( dx[0]*dx[0] + dx[1]*dx[1] + dx[2]*dx[2] );
Pedro Gonnet's avatar
Pedro Gonnet committed
626
        if ( r < th )
627
            printf( "pairs_single: %i %lli [%e,%e,%e] %e\n" ,
Pedro Gonnet's avatar
Pedro Gonnet committed
628
629
630
631
                tid , parts[k].id , dx[0] , dx[1] , dx[2] , r );
        }
            
    }
632
633
634
635
636
637
638
639
640
641
642
643
    
    
/**
 * @brief Test the kernel function by dumping it in the interval [0,1].
 *
 * @param N number of intervals in [0,1].
 */
 
void kernel_dump ( int N ) {

    int k;
    float x, w, dw_dx;
644
645
646
    float x4[4] = {0.0f,0.0f,0.0f,0.0f};
    float w4[4] = {0.0f,0.0f,0.0f,0.0f};
    // float dw_dx4[4] __attribute__ ((aligned (16)));
647
648

    for ( k = 0 ; k <= N ; k++ ) {
649
        x = ((float)k) / N;
Pedro Gonnet's avatar
Pedro Gonnet committed
650
        x4[3] = x4[2]; x4[2] = x4[1]; x4[1] = x4[0]; x4[0] = x;
651
        kernel_deval( x , &w , &dw_dx );
652
        // kernel_deval_vec( (vector *)x4 , (vector *)w4 , (vector *)dw_dx4 );
Pedro Gonnet's avatar
Pedro Gonnet committed
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
        printf( " %e %e %e %e %e %e %e\n" , x , w , dw_dx , w4[0] , w4[1] , w4[2] , w4[3] );
        }

    }


/**
 * @brief Test the density function by dumping it for two random parts.
 *
 * @param N number of intervals in [0,1].
 */
 
void density_dump ( int N ) {

    int k;
    float r2[4] = {0.0f,0.0f,0.0f,0.0f}, hi[4], hj[4];
    struct part *pi[4], *pj[4], Pi[4], Pj[4];
    
    /* Init the interaction parameters. */
    for ( k = 0 ; k < 4 ; k++ ) {
673
674
        Pi[k].mass = 1.0f; Pi[k].rho = 0.0f; Pi[k].density.wcount = 0.0f;
        Pj[k].mass = 1.0f; Pj[k].rho = 0.0f; Pj[k].density.wcount = 0.0f;
Pedro Gonnet's avatar
Pedro Gonnet committed
675
676
677
678
679
680
681
682
683
        hi[k] = 1.0;
        hj[k] = 1.0;
        pi[k] = &Pi[k];
        pj[k] = &Pj[k];
        }

    for ( k = 0 ; k <= N ; k++ ) {
        r2[3] = r2[2]; r2[2] = r2[1]; r2[1] = r2[0];
        r2[0] = ((float)k) / N;
684
        Pi[0].density.wcount = 0; Pj[0].density.wcount = 0;
Pedro Gonnet's avatar
Pedro Gonnet committed
685
        runner_iact_density( r2[0] , NULL , hi[0] , hj[0] , &Pi[0] , &Pj[0] );
686
687
688
689
690
        printf( " %e %e %e" , r2[0] , Pi[0].density.wcount , Pj[0].density.wcount );
        Pi[0].density.wcount = 0; Pj[0].density.wcount = 0;
        Pi[1].density.wcount = 0; Pj[1].density.wcount = 0;
        Pi[2].density.wcount = 0; Pj[2].density.wcount = 0;
        Pi[3].density.wcount = 0; Pj[3].density.wcount = 0;
Pedro Gonnet's avatar
Pedro Gonnet committed
691
        runner_iact_vec_density( r2 , NULL , hi , hj , pi , pj );
692
        printf( " %e %e %e %e\n" , Pi[0].density.wcount , Pi[1].density.wcount , Pi[2].density.wcount , Pi[3].density.wcount );
693
694
695
        }

    }
Pedro Gonnet's avatar
Pedro Gonnet committed
696
697
698
699
700
701
702
703
704


/**
 * @brief Main routine that loads a few particles and generates some output.
 *
 */
 
int main ( int argc , char *argv[] ) {

705
    int c, icount, j, k, N = 100, periodic = 1;
Pedro Gonnet's avatar
Pedro Gonnet committed
706
    int nr_threads = 1, nr_queues = -1, runs = INT_MAX;
707
    int data[2];
Pedro Gonnet's avatar
Pedro Gonnet committed
708
    double dim[3] = { 1.0 , 1.0 , 1.0 }, shift[3] = { 0.0 , 0.0 , 0.0 };
709
    double /*r_min = 0.01, r_max = 0.1,*/ h_max = -1.0 , scaling = 1.0, rho = 0.0;
Pedro Gonnet's avatar
Pedro Gonnet committed
710
    double clock = DBL_MAX;
Pedro Gonnet's avatar
Pedro Gonnet committed
711
    struct part *parts = NULL, *p;
Pedro Gonnet's avatar
Pedro Gonnet committed
712
    struct space s;
Pedro Gonnet's avatar
Pedro Gonnet committed
713
    struct engine e;
714
    char ICfileName[200];
715
    float dt_max = 0.0f;
Pedro Gonnet's avatar
Pedro Gonnet committed
716
717
    ticks tic;
    
718
719
720
    /* Choke on FP-exceptions. */
    feenableexcept( FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW );
    
Pedro Gonnet's avatar
Pedro Gonnet committed
721
722
    /* Init the space. */
    bzero( &s , sizeof(struct space) );
723
724

    /* Parse the options */
Pedro Gonnet's avatar
Pedro Gonnet committed
725
    while ( ( c = getopt( argc , argv  , "a:c:d:f:m:q:r:s:t:w:z:" ) ) != -1 )
726
727
728
729
730
731
732
      switch( c )
	{
	case 'a':
	  if ( sscanf( optarg , "%lf" , &scaling ) != 1 )
	    error( "Error parsing cutoff scaling." );
	  printf( "main: scaling cutoff by %.3f.\n" , scaling ); fflush(stdout);
	  break;
Pedro Gonnet's avatar
Pedro Gonnet committed
733
734
735
736
737
	case 'c':
	  if ( sscanf( optarg , "%lf" , &clock ) != 1 )
	    error( "Error parsing clock." );
	  printf( "main: clock set to %.3e.\n" , clock ); fflush(stdout);
	  break;
738
	case 'd':
739
	  if ( sscanf( optarg , "%f" , &dt_max ) != 1 )
740
	    error( "Error parsing timestep." );
Pedro Gonnet's avatar
Pedro Gonnet committed
741
	  printf( "main: dt set to %e.\n" , dt_max ); fflush(stdout);
742
743
744
745
746
747
	  break;
	case 'f':
	  if( !strcpy(ICfileName, optarg))
	    error("Error parsing IC file name.");
	  printf("main: IC to be read from file '%s'\n", ICfileName);
	  break;
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
	case 'm':
	  if ( sscanf( optarg , "%lf" , &h_max ) != 1 )
	    error( "Error parsing h_max." );
	  printf( "main: maximum h set to %e.\n" , h_max ); fflush(stdout);
	  break;
	case 'q':
	  if ( sscanf( optarg , "%d" , &nr_queues ) != 1 )
	    error( "Error parsing number of queues." );
	  break;
	case 'r':
	  if ( sscanf( optarg , "%d" , &runs ) != 1 )
	    error( "Error parsing number of runs." );
	  break;
	case 's':
	  if ( sscanf( optarg , "%lf %lf %lf" , &shift[0] , &shift[1] , &shift[2] ) != 3 )
	    error( "Error parsing shift." );
	  printf( "main: will shift parts by [ %.3f %.3f %.3f ].\n" , shift[0] , shift[1] , shift[2] );
	  break;
	case 't':
	  if ( sscanf( optarg , "%d" , &nr_threads ) != 1 )
	    error( "Error parsing number of threads." );
	  omp_set_num_threads( nr_threads );
	  break;
771
772
773
774
775
	case 'w':
	  if ( sscanf( optarg , "%d" , &space_subsize ) != 1 )
	    error( "Error parsing sub size." );
	  printf( "main: sub size set to %i.\n" , space_subsize );
	  break;
776
777
778
779
780
781
782
783
784
785
	case 'z':
	  if ( sscanf( optarg , "%d" , &space_splitsize ) != 1 )
	    error( "Error parsing split size." );
	  printf( "main: split size set to %i.\n" , space_splitsize );
	  break;
	case '?':
	  error( "Unknown option." );
	  break;

	}
786
            
787

788
    /* How large are the parts? */
789
790
791
792
    printf( "main: sizeof(struct part) is %li bytes.\n" , (long int)sizeof( struct part ));

    /* Read particles and space information from (GADGET) IC */
    tic = getticks();
793
    read_ic( ICfileName , dim , &parts , &N , &periodic );
794
795
796
    printf( "main: reading particle properties took %.3f ms.\n" , ((double)(getticks() - tic)) / CPU_TPS * 1000 ); fflush(stdout);
    
    /* Apply h scaling */
Pedro Gonnet's avatar
Pedro Gonnet committed
797
    if( scaling != 1.0 )
798
      for ( k = 0 ; k < N ; k++ )
799
	    parts[k].h *= scaling;
800
801
802
803
    
    /* Apply shift */
    if(shift[0] !=0 || shift[1] !=0 || shift[2] !=0 )
      for ( k = 0 ; k < N ; k++ ) {
Pedro Gonnet's avatar
Pedro Gonnet committed
804
805
806
	    parts[k].x[0] += shift[0];
	    parts[k].x[1] += shift[1];
	    parts[k].x[2] += shift[2];
807
808
      }

809
    /* Dump the first few particles. */
810
    // for(k=0; k<10; ++k)
811
    //   printParticle(parts, k, N);
812
813
814
815
    // printParticle( parts , 6178 , N );
    // pairs_single( dim , 8525152967533 , parts , N , periodic );
    // printParticle( parts , 515150 );
    // printParticle( parts , 494849 );
816
817
818
            
    /* Dump the kernel to make sure its ok. */
    // kernel_dump( 100 );
Pedro Gonnet's avatar
Pedro Gonnet committed
819
    // density_dump( 100 );
Pedro Gonnet's avatar
Pedro Gonnet committed
820
821
    
    /* Get the brute-force number of pairs. */
822
    // pairs_n2( dim , parts , N , periodic );
823
    // pairs_single( dim , 5245989477229 , parts , N , periodic );
Pedro Gonnet's avatar
Pedro Gonnet committed
824
    // fflush( stdout );
Pedro Gonnet's avatar
Pedro Gonnet committed
825
826
827
828
829
830
831
832
833
    
    /* Set default number of queues. */
    if ( nr_queues < 0 )
        nr_queues = nr_threads;
            
    /* Initialize the space with this data. */
    tic = getticks();
    space_init( &s , dim , parts , N , periodic , h_max );
    printf( "main: space_init took %.3f ms.\n" , ((double)(getticks() - tic)) / CPU_TPS * 1000 ); fflush(stdout);
834

835
    /* Set the default time step to 1.0f. */
836
    printf( "main: dt_max is %f.\n" , dt_max );
837
    
Pedro Gonnet's avatar
Pedro Gonnet committed
838
839
840
841
842
843
    /* Say a few nice things about the space we just created. */
    printf( "main: space dimensions are [ %.3f %.3f %.3f ].\n" , s.dim[0] , s.dim[1] , s.dim[2] );
    printf( "main: space %s periodic.\n" , s.periodic ? "is" : "isn't" );
    printf( "main: highest-level cell dimensions are [ %i %i %i ].\n" , s.cdim[0] , s.cdim[1] , s.cdim[2] );
    printf( "main: %i parts in %i cells.\n" , s.nr_parts , s.tot_cells );
    printf( "main: maximum depth is %d.\n" , s.maxdepth );
844
    // printf( "main: cutoffs in [ %g %g ].\n" , s.h_min , s.h_max ); fflush(stdout);
Pedro Gonnet's avatar
Pedro Gonnet committed
845
    
Pedro Gonnet's avatar
Pedro Gonnet committed
846
    /* Verify that each particle is in it's propper cell. */
Pedro Gonnet's avatar
Pedro Gonnet committed
847
    icount = 0;
848
    space_map_cells_pre( &s , 0 , &map_cellcheck , &icount );
Pedro Gonnet's avatar
Pedro Gonnet committed
849
    printf( "main: map_cellcheck picked up %i parts.\n" , icount );
Pedro Gonnet's avatar
Pedro Gonnet committed
850
    
851
    data[0] = s.maxdepth; data[1] = 0;
852
    space_map_cells_pre( &s , 0 , &map_maxdepth , data );
853
854
    printf( "main: nr of cells at depth %i is %i.\n" , data[0] , data[1] );
    
Pedro Gonnet's avatar
Pedro Gonnet committed
855
856
857
858
859
    /* Dump the particle positions. */
    // space_map_parts( &s , &map_dump , shift );
    
    /* Initialize the runner with this space. */
    tic = getticks();
860
    engine_init( &e , &s , dt_max , nr_threads , nr_queues , ENGINE_POLICY | engine_policy_steal );
Pedro Gonnet's avatar
Pedro Gonnet committed
861
    printf( "main: engine_init took %.3f ms.\n" , ((double)(getticks() - tic)) / CPU_TPS * 1000 ); fflush(stdout);
862
863
864

    /* Write the state of the system as it is before starting time integration. */
    tic = getticks();
865
    write_output(&e);
866
    printf( "main: writing particle properties took %.3f ms.\n" , ((double)(getticks() - tic)) / CPU_TPS * 1000 ); fflush(stdout);
Pedro Gonnet's avatar
Pedro Gonnet committed
867
    
868
869
870
871
872
873
    /* Init the runner history. */
    #ifdef HIST
    for ( k = 0 ; k < runner_hist_N ; k++ )
        runner_hist_bins[k] = 0;
    #endif
    
Pedro Gonnet's avatar
Pedro Gonnet committed
874
875
876
877
878
879
880
881
882
883
    /* Inauguration speech. */
    if ( runs < INT_MAX )
        printf( "main: starting for %i steps with %i threads and %i queues...\n" , runs , e.nr_threads , e.nr_queues );
    else
        printf( "main: starting for t=%.3e with %i threads and %i queues...\n" , clock , e.nr_threads , e.nr_queues );
    fflush(stdout);
    
    /* Legend. */
    printf( "# step time e_tot e_kin e_temp dt dt_step count dt_min dt_max\n" );
    
Pedro Gonnet's avatar
Pedro Gonnet committed
884
    /* Let loose a runner on the space. */
Pedro Gonnet's avatar
Pedro Gonnet committed
885
    for ( j = 0 ; j < runs && e.time < clock ; j++ ) {
886
    
Pedro Gonnet's avatar
Pedro Gonnet committed
887
        // printf( "main: starting run %i/%i (t=%.3e) with %i threads and %i queues...\n" , j+1 , runs , e.time , e.nr_threads , e.nr_queues ); fflush(stdout);
888
        timers_reset( timers_mask_all );
Pedro Gonnet's avatar
Pedro Gonnet committed
889
890
891
892
        #ifdef COUNTER
            for ( k = 0 ; k < runner_counter_count ; k++ )
                runner_counter[k] = 0;
        #endif
893
894
895
        
        /* Take a step. */
        engine_step( &e , 0 );
896

897
        if(j % 100 == 0)
898
            write_output(&e);
899
	
900
        
901
        /* Dump the first few particles. */
902
903
904
905
906
907
        // for(k=0; k<10; ++k)
        //   printParticle(parts, k);
        // printParticle( parts , 6178 , N );
        // printParticle( parts , 515150 );
        // printParticle( parts , 494849 );
        // pairs_single( dim , 432732 , parts , N , periodic );
908
909
    
        /* Get the particle with the lowest h. */
910
        /* p = &s.parts[0];
911
912
        space_map_parts( &s , &map_h_min , &p );
        printf( "main: particle %lli/%i at [ %e %e %e ] has minimum h=%.3e (h_dt=%.3e).\n" ,
913
	        p->id , (int)(p - s.parts) , p->x[0] , p->x[1] , p->x[2] , p->h , p->force.h_dt ); */
914
915

        /* Get the particle with the highest h. */
916
        /* p = &s.parts[0];
917
918
        space_map_parts( &s , &map_h_max , &p );
        printf( "main: particle %lli/%i at [ %e %e %e ] has maximum h=%.3e (h_dt=%.3e).\n" ,
919
920
921
922
923
924
925
	        p->id , (int)(p - s.parts) , p->x[0] , p->x[1] , p->x[2] , p->h , p->force.h_dt ); */
    
        /* Get the particle with the lowest dt. */
        /* p = &s.parts[0];
        for ( k = 0 ; k < s.nr_parts ; k++ )
            if ( s.parts[k].dt < p->dt )
                p = &s.parts[k];
926
        printf( "main: particle %lli/%i at [ %e %e %e ] has smallest dt=%e (h=%.3e,u=%.3e).\n" ,
927
928
	        p->id , (int)(p - s.parts) , p->x[0] , p->x[1] , p->x[2] , p->dt , p->h , p->u ); */
        
Pedro Gonnet's avatar
Pedro Gonnet committed
929
930
931
932
933
934
935
936
937
938
939
940
941
        /* Get the particle with the highest e_kin. */
        p = &s.parts[0];
        double a2, a2_max = p->a[0]*p->a[0] + p->a[1]*p->a[1] + p->a[2]*p->a[2];
        for ( k = 0 ; k < s.nr_parts ; k++ ) {
            a2 = s.parts[k].a[0]*s.parts[k].a[0] + s.parts[k].a[1]*s.parts[k].a[1] + s.parts[k].a[2]*s.parts[k].a[2];
            if ( a2 > a2_max ) {
                p = &s.parts[k];
                a2_max = a2;
                }
            }
        /* printf( "main: particle %lli/%i at [ %e %e %e ] has largest ekin=%e.\n" ,
	        p->id , (int)(p - s.parts) , p->x[0] , p->x[1] , p->x[2] , ekin_max ); */
        
942
        /* Output. */
Pedro Gonnet's avatar
Pedro Gonnet committed
943
        #ifdef TIMER
Pedro Gonnet's avatar
Pedro Gonnet committed
944
            /* printf( "main: runner timers are [ %.3f" , timers[0]/CPU_TPS*1000 );
945
946
            for ( k = 1 ; k < timer_count ; k++ )
                printf( " %.3f" , ((double)timers[k])/CPU_TPS*1000 );
Pedro Gonnet's avatar
Pedro Gonnet committed
947
948
            printf( " ] ms.\n" ); */
            /* printf( "main: queue timers are [ %.3f" , queue_timer[0]/CPU_TPS*1000 );
949
            for ( k = 1 ; k < queue_timer_count ; k++ ) 
Pedro Gonnet's avatar
Pedro Gonnet committed
950
                printf( " %.3f" , ((double)queue_timer[k])/CPU_TPS*1000 );
951
952
            for ( k = 0 ; k < queue_timer_count ; k++ )
                queue_timer[k] = 0;
Pedro Gonnet's avatar
Pedro Gonnet committed
953
            printf( " ] ms.\n" );
Pedro Gonnet's avatar
Pedro Gonnet committed
954
            printf( "main: cell timers are [ %.3f" , cell_timer[0]/CPU_TPS*1000 );
955
            for ( k = 1 ; k < cell_timer_count ; k++ ) 
Pedro Gonnet's avatar
Pedro Gonnet committed
956
                printf( " %.3f" , ((double)cell_timer[k])/CPU_TPS*1000 );
957
958
            for ( k = 0 ; k < cell_timer_count ; k++ )
                cell_timer[k] = 0;
Pedro Gonnet's avatar
Pedro Gonnet committed
959
            printf( " ] ms.\n" ); */
Pedro Gonnet's avatar
Pedro Gonnet committed
960
        #else
Pedro Gonnet's avatar
Pedro Gonnet committed
961
            printf( "main: engine_run with %i threads took %.3f ms.\n" , nr_threads , ((double)(getticks() - tic)) / CPU_TPS * 1000 );
Pedro Gonnet's avatar
Pedro Gonnet committed
962
963
964
965
966
967
968
        #endif
        #ifdef COUNTER
            printf( "main: runner counters are [ %d" , runner_counter[0] );
            for ( k = 1 ; k < runner_counter_count ; k++ )
                printf( " %d" , runner_counter[k] );
            printf( " ].\n" );
        #endif
Pedro Gonnet's avatar
Pedro Gonnet committed
969
        /* printf( "main: engine queue lengths are [ %i" , e.queues[0].count );
Pedro Gonnet's avatar
Pedro Gonnet committed
970
971
        for ( k = 1 ; k < e.nr_queues ; k++ )
            printf( " %i" , e.queues[k].count );
Pedro Gonnet's avatar
Pedro Gonnet committed
972
        printf( " ].\n" );
Pedro Gonnet's avatar
Pedro Gonnet committed
973
974
975
976
977
978
979
980
981
982
983
        fflush(stdout); */
        
        /* Dump a line of agregate output. */
        printf( "%i %e %e %e %e %e %e %i %e %e" ,
            j , e.time ,
            e.ekin+e.epot , e.ekin , e.epot ,
            e.dt , e.dt_step , e.count_step ,
            e.dt_min , e.dt_max );
        for ( k = 0 ; k < timer_count ; k++ )
            printf( " %.3f" , ((double)timers[k])/CPU_TPS*1000 );
        printf( " %lli %e\n" , p->id , a2_max ); fflush(stdout);
984
        
Pedro Gonnet's avatar
Pedro Gonnet committed
985
986
        }
        
987
988
989
990
991
992
993
994
995
996
    /* 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
        
Pedro Gonnet's avatar
Pedro Gonnet committed
997
998
999
1000
    /* Loop over the parts directly. */
    // for ( k = 0 ; k < N ; k++ )
    //     printf( " %i %e %e\n" , s.parts[k].id , s.parts[k].count , s.parts[k].count_dh );
    
For faster browsing, not all history is shown. View entire blame