-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial.cu
executable file
·67 lines (57 loc) · 1.64 KB
/
serial.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include "common.h"
//
// benchmarking program
//
int main( int argc, char **argv )
{
if( find_option( argc, argv, "-h" ) >= 0 )
{
printf( "Options:\n" );
printf( "-h to see this help\n" );
printf( "-n <int> to set the number of particles\n" );
printf( "-o <filename> to specify the output file name\n" );
return 0;
}
int n = read_int( argc, argv, "-n", 1000 );
char *savename = read_string( argc, argv, "-o", NULL );
FILE *fsave = savename ? fopen( savename, "w" ) : NULL;
particle_t *particles = (particle_t*) malloc( n * sizeof(particle_t) );
set_size( n );
init_particles( n, particles );
//
// simulate a number of time steps
//
double simulation_time = read_timer( );
for( int step = 0; step < NSTEPS; step++ )
{
//
// compute forces
//
for( int i = 0; i < n; i++ )
{
particles[i].ax = particles[i].ay = 0;
for (int j = 0; j < n; j++ )
apply_force( particles[i], particles[j] );
}
//
// move particles
//
for( int i = 0; i < n; i++ )
move( particles[i] );
//
// save if necessary
//
if( fsave && (step%SAVEFREQ) == 0 )
save( fsave, n, particles );
}
simulation_time = read_timer( ) - simulation_time;
printf( "n = %d, simulation time = %g seconds\n", n, simulation_time );
free( particles );
if( fsave )
fclose( fsave );
return 0;
}