// apply gravity virtual void ApplyMove(dCustomPlayerController* const controller, dFloat timestep) { // calculate the gravity contribution to the velocity dVector gravityImpulse(0.0f, DEMO_GRAVITY * controller->GetMass() * timestep, 0.0f, 0.0f); dVector totalImpulse(controller->GetImpulse() + gravityImpulse); controller->SetImpulse(totalImpulse); // apply play movement ApplyInputs(controller); }
int main(int argc, char **argv) { int option, steps = 365, delta = 1, body_count; char *input = "init.dat", *output = "result.dat"; bool parallel = false, mpi = false, global_newton = false; long double start; long double px, py; imggen_info img_info; body *bodies = NULL; /* PBM default values */ img_info.gen_img = false; img_info.img_steps = 1000; img_info.img_prefix = "PBM"; img_info.offset = 2; img_info.width = 600; img_info.heigth = 600; /* Read cmdline params */ while ((option = getopt(argc,argv,"phs:d:f:o:i:x:gmn")) != -1) { switch(option) { case 'p': parallel = true; break; case 's': steps = atoi(optarg); break; case 'd': delta = atoi(optarg); break; case 'f': input = optarg; break; case 'o': output = optarg; break; case 'i': img_info.img_prefix = optarg; break; case 'x': img_info.img_steps = atoi(optarg); break; case 'g': img_info.gen_img = true; break; case 'm': mpi = true; break; case 'n': global_newton = true; break; default: printhelp(); return 1; } } /* Init MPI */ MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &mpi_processors); MPI_Comm_rank(MPI_COMM_WORLD, &mpi_self); /* Validate params */ if (steps < 0 || delta < 1 || img_info.img_steps < 1) { m_printf("Wrong parameter value! Will exit!\n Steps: %i | Delta: %i | Input Filepath: %s", steps, delta, input); } bodies = readBodies(fopen(input,"r"), &body_count); if (bodies == NULL) { m_printf("Error while reading input file %s. Will exit now!\n", input); MPI_Finalize(); return 1; } /* Assert that all masses > 0 and any two particles do not share the same position */ if (!examineBodies(bodies, body_count, &img_info.max_x, &img_info.max_y)) { m_printf("Error while reading input file %s. Some value are not permitted!\n", input); printBodies(bodies, body_count); MPI_Finalize(); return 1; } totalImpulse(bodies, body_count, &px, &py); m_printf("Initial total impulse: px = %Le , py = %Le\n", px, py); MPI_Barrier(MPI_COMM_WORLD); start = seconds(); if (parallel) { m_printf("PARALLEL\n"); if (mpi) { m_printf("MPI+OMP\n"); if (global_newton) { m_printf("GLOBAL NEWTON\n"); solve_parallel_mpi_global_newton(bodies, body_count, steps, delta, img_info); } else { solve_parallel_mpi(bodies, body_count, steps, delta, img_info); } } else { m_printf("OMP\n"); solve_parallel(bodies, body_count, steps, delta, img_info); } } else { m_printf("SEQUENTIAL\n"); solve_sequential(bodies, body_count, steps, delta, img_info); } MPI_Barrier(MPI_COMM_WORLD); long double elapsed = seconds() - start; m_printf("Rate of interactions: %Lf\n", interactions(body_count, steps, elapsed)); m_printf("Elapsed time: %Lf\n", elapsed); totalImpulse(bodies, body_count, &px, &py); m_printf("Resulting total impulse: px = %Le , py = %Le\n", px, py); /* Write result to file */ FILE *f = fopen(output,"w"); if (f == NULL) { m_printf("Error while opening output file %s.\n", output); MPI_Finalize(); return 1; } writeBodies(f, bodies, body_count); MPI_Finalize(); return 0; }