-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpi8.c
38 lines (29 loc) · 843 Bytes
/
mpi8.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* Copyright (c) 2014 UFSM, UNIPAMPA.
*
* Authors: Joao Lima (UFSM) and Claudio Schepke (Unipampa).
*/
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
void printvector(int rank, int *buffer) {
int size, i;
MPI_Comm_size(MPI_COMM_WORLD, &size);
for (i = 0; i < size; i++)
printf("rank %d - %d\n", rank, buffer[i]);
}
int main(int argc, char **argv) {
int *sndbuffer, *recvbuffer;
int rank, size, i;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
sndbuffer = (int *)malloc(size*sizeof(int));
recvbuffer = (int *)malloc(size*sizeof(int));
for(i=0; i<size; i++) sndbuffer[i] = i*i+rank;
printvector(rank, sndbuffer);
MPI_Alltoall(sndbuffer, 1, MPI_INT, recvbuffer, 1, MPI_INT, MPI_COMM_WORLD);
printvector(rank, recvbuffer);
MPI_Finalize();
return 0;
}