source: proiecte/SolarSim/C/Serial/src/SolarSim.c @ 152

Last change on this file since 152 was 152, checked in by (none), 14 years ago
File size: 1.4 KB
Line 
1/* SolarSim.c */
2#include "SolarSim.h"
3
4int sock = 0;
5
6long SIM_STEPS, DT, SAVE;
7
8void
9do_work(AState state) {
10        int i, j;
11        long sim_step;
12        real norm_square, norm;
13        int n = state->particles;
14        vector *r = state->positions;
15        vector *v = state->velocities;
16        vector *a = state->accelerations;
17        real *m = state->masses;
18
19        sim_step = 0;
20        while( sim_step < SIM_STEPS ) {
21                if( (SAVE != 0) && (sim_step % SAVE == 0) ) {
22                        write_state(sock, state);
23                }
24
25                // compute accelerations
26                memset( a, 0, n * sizeof(vector) );
27                for( i = 0; i < n-1; i++ ) {
28                        for( j = i+1; j < n; j++ ) {
29                                compute_acc(r+i, r+j, v+i, v+j, a+i, a+j, m[i], m[j]);
30                        }
31                }
32
33                // update positions and speeds
34                for( i = 0; i < n; i++ ) {
35                        update_pos_vel(r+i, v+i, a+i, DT);
36                }
37
38                sim_step ++;
39        }
40
41        if( SAVE != 0 )
42                write_state(sock, state);
43}
44
45int
46main( int argc, char **argv ) {
47        TState state;
48        double before, after;
49        int i;
50
51        SIM_STEPS = atol(argv[3]);
52        DT = atol(argv[4]);
53        SAVE = atol(argv[5]);
54
55        if( SAVE != 0 ) {
56                sock = open( argv[2], O_WRONLY | O_CREAT | O_TRUNC, 644 );
57        }
58
59        read_initial( &state, argv[1] );
60
61        before = omp_get_wtime();
62        do_work(&state);
63        after = omp_get_wtime();
64
65        if( SAVE != 0 ) {
66                i = 0;
67                write( sock, &i, sizeof(int) );
68                close(sock);
69        }
70
71        printf("%li s %lf\n", SIM_STEPS, after-before);
72
73        return EXIT_SUCCESS;
74}
75
Note: See TracBrowser for help on using the repository browser.