Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, char** argv)
- {
- float fTimeStart = clock() / (float)CLOCKS_PER_SEC;
- MPI_Init(&argc, &argv);
- int rank;
- int process_count;
- MPI_Comm_rank(MPI_COMM_WORLD, &rank);
- MPI_Comm_size(MPI_COMM_WORLD, &process_count);
- double a = 0;
- double b = PI/2;
- double length = b - a;
- int NUMBER_OF_INTERVALS = 1000000000;
- double dx = (b - a) / NUMBER_OF_INTERVALS;
- int intervals_per_one_rank = NUMBER_OF_INTERVALS / process_count;
- double length_per_rank = (b - a) / process_count;
- double my_a = a + rank * length_per_rank;
- double my_b = a + (rank + 1) * length_per_rank;
- double sum = 0;
- for (int i = 0; i < intervals_per_one_rank; ++i)
- {
- sum += F(my_a + i * dx) * dx;
- }
- double total;
- MPI_Reduce(&sum, &total, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
- if (rank == 0)
- {
- printf("%.10lf\n", total);
- float fTimeStop = clock() / (float)CLOCKS_PER_SEC;
- printf("Working time = %f", -fTimeStart + fTimeStop);
- }
- MPI_Finalize();
- }
Advertisement
Add Comment
Please, Sign In to add comment