source: CIVL/examples/mpi/collective/scatter2.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 922 bytes
Line 
1/**
2 * This program has an error because not all processes
3 * execute MPI_Barrier and MPI_Scatter in the same order.
4 */
5
6#include<mpi.h>
7#include<stdio.h>
8#include<stdlib.h>
9
10int main(int argc, char* argv[]){
11 int rank;
12 int procs;
13 int* sendbuf, *rcvbuf;
14
15 MPI_Init(&argc,&argv);
16 MPI_Comm_size(MPI_COMM_WORLD, &procs);
17 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
18
19 sendbuf = (int*)malloc(sizeof(int)*procs);
20 rcvbuf = (int*)malloc(sizeof(int));
21 if(rank%2){
22 MPI_Scatter(sendbuf, 1, MPI_INT, rcvbuf, 1, MPI_INT, 0, MPI_COMM_WORLD);
23 MPI_Bcast(sendbuf, 1, MPI_INT, 0, MPI_COMM_WORLD);
24 }else{
25 MPI_Bcast(sendbuf, 1, MPI_INT, 0, MPI_COMM_WORLD);
26 MPI_Scatter(sendbuf, 1, MPI_INT, rcvbuf, 1, MPI_INT, 0, MPI_COMM_WORLD);
27 }
28
29 //printf("process %d receivs %d\n", rank, *rcvbuf);
30 free(sendbuf);
31 free(rcvbuf);
32 MPI_Finalize();
33 exit(0);
34}
Note: See TracBrowser for help on using the repository browser.