/* ************************************************************************ */ int main (int argc, char** argv) { struct options options; struct calculation_arguments arguments; struct calculation_results results; struct comm_options comm; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &comm.rank); MPI_Comm_size(MPI_COMM_WORLD, &comm.num_procs); /* get parameters */ AskParams(&options, argc, argv, comm.rank); /* ************************* */ initVariables(&arguments, &results, &options); /* ******************************************* */ if (options.method == METH_JACOBI && comm.num_procs > 1) { allocateMatrices_mpi(&arguments, &comm); initMatrices_mpi(&arguments, &options, &comm); gettimeofday(&start_time, NULL); /* start timer */ calculate_mpi(&arguments, &results, &options, &comm); /* solve the equation */ gettimeofday(&comp_time, NULL); /* stop timer */ if (comm.rank == ROOT) { displayStatistics(&arguments, &results, &options); } DisplayMatrix_mpi(&arguments, &results, &options, comm.rank, comm.num_procs, comm.absoluteStartRow, comm.absoluteStartRow + comm.matrixRows -3); freeMatrices(&arguments); /* free memory */ } else { allocateMatrices(&arguments); /* get and initialize variables and matrices */ initMatrices(&arguments, &options); /* ******************************************* */ gettimeofday(&start_time, NULL); /* start timer */ calculate(&arguments, &results, &options); /* solve the equation */ gettimeofday(&comp_time, NULL); /* stop timer */ displayStatistics(&arguments, &results, &options); DisplayMatrix(&arguments, &results, &options); freeMatrices(&arguments); /* free memory */ } MPI_Finalize(); return 0; }
/* ************************************************************************ */ int main (int argc, char** argv) { struct options options; struct calculation_arguments arguments; struct calculation_results results; // mpi setup --------------------------------------------------------------- MPI_Init(NULL, NULL); int rank, nprocs; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); /* get parameters */ AskParams(&options, argc, argv, rank); initVariables(&arguments, &results, &options, rank, nprocs); // printf("[%d] %" PRIu64 " %" PRIu64 "\n", rank, arguments.offset_start, arguments.offset_end); // get and initialize variables and matrices allocateMatrices(&arguments); initMatrices(&arguments, &options); gettimeofday(&start_time, NULL); /* start timer */ // solve the equation if (options.method == METH_JACOBI) { calculate_mpi(&arguments, &results, &options); } else { calculate(&arguments, &results, &options); } // MPI_Barrier(MPI_COMM_WORLD); // gettimeofday(&comp_time, NULL); /* stop timer */ DisplayMatrix(&arguments, &results, &options); freeMatrices(&arguments); MPI_Finalize(); return 0; }