int main(int argc, char** argv) { sim_param_t params; if (get_params(argc, argv, ¶ms) != 0) exit(-1); sim_state_t* state = init_particles(¶ms); FILE* fp = fopen(params.fname, "w"); int nframes = params.nframes; int npframe = params.npframe; float dt = params.dt; int n = state->n; double t_start = omp_get_wtime(); //write_header(fp, n); write_header(fp, n, nframes, params.h); write_frame_data(fp, n, state, NULL); compute_accel(state, ¶ms); leapfrog_start(state, dt); check_state(state); for (int frame = 1; frame < nframes; ++frame) { for (int i = 0; i < npframe; ++i) { compute_accel(state, ¶ms); leapfrog_step(state, dt); check_state(state); } printf("Frame: %d of %d - %2.1f%%\n",frame, nframes, 100*(float)frame/nframes); write_frame_data(fp, n, state, NULL); } double t_end = omp_get_wtime(); printf("Ran in %g seconds\n", t_end-t_start); fclose(fp); free_state(state); }
int main(){ double x_RK4, x_LF; double v_RK4, v_LF; double t; double T=1E5; double delta_t=1E-1; int n_step = (int)(T/delta_t); double x_step = 0.0; double v_step = 0.0; int i; t=0.0; x_RK4=1.0; v_RK4=0.0; x_LF=1.0; v_LF=0.0; for(i=0;i<n_step;i++){ printf("%f %.15e %.15e %.15e %.15e \n", t, x_RK4, v_RK4, x_LF, v_LF); RK4_step(delta_t, t, &x_RK4, &v_RK4); leapfrog_step(delta_t, t, &x_LF, &v_LF); t += delta_t; } return 0; }
int main(){ double x_RK4, x_LF, x3_RK4,x3_LF; double v_RK4, v_LF, v3_RK4,v3_LF; double t; double x3_CI; double T=2800; double delta_t=6E-3; int n_step = (int)(T/delta_t); double x_step = 0.0, e=1; double v_step = 0.0; int i,j; file1 = fopen("salida3LF.dat", "w"); file2 = fopen("salida3RK4.dat", "w"); t=0.0; x_RK4=0.425; v_RK4=0.0; x3_RK4=0.0; v3_RK4=0.0; x3_LF=0.0; v_LF=0.0; x_LF=0.46; v3_LF=0.0; x3_CI=-0.2; for(j=0;j<100;j++){ x3_LF=x3_CI; v_LF=0.0; x_LF=0.46; v3_LF=0.0; x3_RK4=x3_CI; v_RK4=0.0; x_RK4=0.425; v3_RK4=0.0; for(i=0;i<n_step;i++){ if(fabs(v_LF)<0.0005) fprintf(file1,"%f %.15e %.15e %.15e %.15e \n", t, x_LF, v_LF, x3_LF, v3_LF); if(fabs(v_RK4)<0.0005) fprintf(file2,"%f %.15e %.15e %.15e %.15e \n", t, x_LF, v_LF, x3_RK4, v3_RK4); RK4_step(delta_t,e, t, &x_RK4, &v_RK4, &x3_RK4, &v3_RK4); leapfrog_step(delta_t,e, t, &x_LF, &v_LF,&x3_LF,&v3_LF); t += delta_t; } x3_CI+=0.03; } fclose(file1); fclose(file2); return 0; }
int main(int argc, char** argv) { sim_param_t params; if (get_params(argc, argv, ¶ms) != 0) exit(-1); // Create global sim_state_t* globalState = init_particles(¶ms); #pragma omp parallel shared(globalState, params) { int proc = omp_get_thread_num(); int nproc = omp_get_num_threads(); FILE* fp = fopen(params.fname, "w"); int nframes = params.nframes; int npframe = params.npframe; float dt = params.dt; int n = globalState->n; // Processor information and holder proc_info* pInfo = malloc(sizeof(proc_info)); pInfo->proc = proc; pInfo->nproc = nproc; pInfo->beg = round((proc/(double)nproc)*n); pInfo->end = round(((proc+1)/(double)nproc)*n); pInfo->forceAccu = calloc(3*n, sizeof(float)); // Never used this... if (proc == 0) { printf("Running in parallel with %d processor\n", nproc); } normalize_mass(globalState, pInfo, ¶ms); double t_start = omp_get_wtime(); if (proc == 0) { // We only write for one processor write_header(fp, n, nframes, params.h); write_frame_data(fp, n, globalState, NULL); } if (proc == 0) { hash_particles(globalState, params.h); } //hash_particles_parallel(globalState, pInfo, params.h); #pragma omp barrier // Need the hashing to be done compute_accel(globalState, pInfo, ¶ms); #pragma omp barrier leapfrog_start(globalState, pInfo, dt); check_state(globalState, pInfo); for (int frame = 1; frame < nframes; ++frame) { // We sort according to Z-Morton to ensure locality, need to implement paralle qsort if (frame % 5 == 0) { // Dividing into chunks of sorting each chunk // This alone turned out to better than sorting the entire array qsort(globalState->part+pInfo->beg, pInfo->end-pInfo->beg ,sizeof(particle_t),compPart); // Sorting the array consisting of sorted chunks // This turned out to actually lower the performance. That's why // I commented it. // #pragma omp barrier // if( pInfo->nproc >1 ) arraymerge(globalState->part, globalState->n, pInfo); //#pragma omp barrier*/ // Serial version /*#pragma omp single // Implied barrier qsort(globalState->part, n, sizeof(particle_t), compPart);*/ } /*else if (frame % 49) {*/ /*if (proc == 0) {*/ /*}*/ /*}*/ #pragma omp barrier // Need sort to finish for (int i = 0; i < npframe; ++i) { if (proc == 0 && npframe % 4 == 0) { // Ammortize hashing cost hash_particles(globalState, params.h); } #pragma omp barrier compute_accel(globalState, pInfo, ¶ms); leapfrog_step(globalState, pInfo, dt); check_state(globalState, pInfo); #pragma omp barrier } if (proc == 0) { printf("Frame: %d of %d - %2.1f%%\n",frame, nframes, 100*(float)frame/nframes); write_frame_data(fp, n, globalState, NULL); } } double t_end = omp_get_wtime(); if (proc == 0) { printf("Ran in %g seconds\n", t_end-t_start); } free(pInfo); fclose(fp); } free_state(globalState); }
int main(int argc, char *argv[]) { int touch = 0; int i, N; Event *event; init(&event, &N, argc, argv); /*************************************************************************************************/ /* Launch/Pitch Kick/Gravity turn */ /* First Stage: Flip/Entry burn/Landing burn */ /*************************************************************************************************/ FILE *f, *f1, *f2; f = fopen("Stage1.dat", "w"); f1 = fopen("Points.dat", "w"); f2 = fopen("Stage2.dat", "w"); do{ /* Execute events */ for(i=0;i<N;i++) { if(event[i].stage == 0 && fabs(t-event[i].t) < dt/2) // If an Stage1 event in profile.txt occurs at execute(event[i].name, f1); // this time, execute the event if(event[i].stage == 1 && fabs(t-event[i].t) < dt/2) // Stage2 events execute(event[i].name, f1); } /* End Landing Burn */ if((F9[0].Mf < 5 || (_LBURN && S[0]-Re < 0.01)) && !_MECO3) { // If Alt = 0.1m or Fuel runs out output_telemetry("MECO-3", f1, 0); MSECO(0, &_MECO3); _LBURN = 0; } /* Touchdown */ else if(_release && S[0]<Re && !touch) { // If Alt = 0.0m output_telemetry("Touchdown", NULL, 0); touch = 1; dt = 0.1; } /* SECO1 */ else if((F9[1].Mf < 5 || VA[1] > sqrt(G*Me/S[1])) && !_SECO1) { output_telemetry("SECO-1", f1, 1); MSECO(1, &_SECO1); } /* Advance First stage */ if(!touch) { leapfrog_step(0); output_file(0, f); } /* Advance Second stage */ if(_MECO1) { leapfrog_step(1); output_file(1, f2); } t += dt; } while(!touch); printf("\n"); free(event); fclose(f); fclose(f1); fclose(f2); return 0; }