-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpi5.c
34 lines (28 loc) · 762 Bytes
/
mpi5.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
/*
* Copyright (c) 2014 UFSM, UNIPAMPA.
*
* Authors: Joao Lima (UFSM) and Claudio Schepke (Unipampa).
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <mpi.h>
int main(int argc, char **argv) {
char *message = (char *) malloc(sizeof(char) * 30);
int rank, size, length;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
printf("I'm %d of %d\n",rank,size);
if(rank == 0) {
strcpy(message, "Hello_World!");
length = strlen(message);
printf("%d\n", length);
}
MPI_Bcast(&length, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Bcast(message, length + 1, MPI_CHAR, 0, MPI_COMM_WORLD);
if(rank != 0)
printf("(%d) – Received %s\n", rank, message);
MPI_Finalize();
return 0;
}