/* SolarSim.c */ #include "SolarSim.h" int sock = 0; long SIM_STEPS, DT, SAVE; void do_work(AState state) { int i, j; long sim_step; real norm_square, norm; int n = state->particles; vector *r = state->positions; vector *v = state->velocities; vector *a = state->accelerations; real *m = state->masses; sim_step = 0; while( sim_step < SIM_STEPS ) { if( (SAVE != 0) && (sim_step % SAVE == 0) ) { write_state(sock, state); } // compute accelerations memset( a, 0, n * sizeof(vector) ); for( i = 0; i < n-1; i++ ) { for( j = i+1; j < n; j++ ) { compute_acc(r+i, r+j, v+i, v+j, a+i, a+j, m[i], m[j]); } } // update positions and speeds for( i = 0; i < n; i++ ) { update_pos_vel(r+i, v+i, a+i, DT); } sim_step ++; } if( SAVE != 0 ) write_state(sock, state); } int main( int argc, char **argv ) { TState state; double before, after; int i; SIM_STEPS = atol(argv[3]); DT = atol(argv[4]); SAVE = atol(argv[5]); if( SAVE != 0 ) { sock = open( argv[2], O_WRONLY | O_CREAT | O_TRUNC, 644 ); } read_initial( &state, argv[1] ); before = omp_get_wtime(); do_work(&state); after = omp_get_wtime(); if( SAVE != 0 ) { i = 0; write( sock, &i, sizeof(int) ); close(sock); } printf("%li s %lf\n", SIM_STEPS, after-before); return EXIT_SUCCESS; }