Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "mpi.h"
- using namespace std;
- int main(int argc, char** argv)
- {
- MPI_Init(&argc, &argv);
- int size, rank;
- MPI_Status status;
- MPI_Comm_size(MPI_COMM_WORLD, &size);
- MPI_Comm_rank(MPI_COMM_WORLD, &rank);
- printf("i'm %d \n", rank);
- int* sendarray = new int[2];
- int* rbuf = new int[size * 2];
- int* displs = new int[size];
- int* rcounts = new int[size];
- int i;
- for (i = 0; i < size - 1; ++i) {
- displs[i] = i + i;
- rcounts[i] = 1;
- }
- i = size - 1;
- displs[i] = i + i;
- rcounts[i] = 2;
- sendarray[0] = rank + 1;
- sendarray[1] = rank + 2;
- if (rank != size - 1) printf("otpravl: %d", sendarray[0]);
- else printf("otpravl: %d %d", sendarray[0], sendarray[1]);
- double start_Send = MPI_Wtime();
- MPI_Gatherv(sendarray, rcounts[rank], MPI_INT, rbuf, rcounts, displs,
- MPI_INT, 0, MPI_COMM_WORLD);
- double end_Send = MPI_Wtime();
- if (rank == 0) {
- printf(" rezult:");
- for (int i = 0; i < size * 2; ++i) {
- if (rbuf[i] > 0)
- printf("%d", rbuf[i]);
- else printf("0");
- }
- printf(" vremya work %g", (end_Send - start_Send));
- }
- MPI_Finalize();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement