Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int mpi_Gather(int* send_data, int send_count, MPI_Datatype send_datatype, int* recv_data, int recv_count, MPI_Datatype recv_datatype, int root, MPI_Comm communicator)
- {
- int myid, numprocs;
- int* tmp = new int[send_count];
- MPI_Status status;
- MPI_Comm_rank(MPI_COMM_WORLD, &myid);
- MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
- int index = 0;
- if (myid != root)
- {
- MPI_Send(send_data, send_count, MPI_INT, root, 99, MPI_COMM_WORLD);
- }
- else
- {
- for (int i = 0; i < send_count; i++)
- {
- recv_data[index] = send_data[i];
- index++;
- }
- for (int i = 1; i < numprocs; i++)
- {
- MPI_Recv(tmp, recv_count, MPI_INT, i, 99, MPI_COMM_WORLD, &status);
- for (int j = 0; j < send_count; j++)
- {
- recv_data[index] = *tmp;
- *(++tmp);
- index++;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement