source: CIVL/examples/mpi/collective/gather_bad.c@ 77030d0

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 77030d0 was 4ccacf8, checked in by Manchun Zheng <zmanchun@…>, 11 years ago

added some more MPI collective tests.

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

  • Property mode set to 100644
File size: 779 bytes
Line 
1/**
2 * This example demonstrates the usage of MPI collective operations,
3 * which should be called in the same orders for all MPI processes.
4 * This example has an error when there are more than two MPI processes.
5 */
6#include<mpi.h>
7#include<stdlib.h>
8
9int main()
10{
11 int argc;
12 char** argv;
13 int rank;
14 int procs;
15 int* values;
16
17 MPI_Init(&argc,&argv);
18 MPI_Comm_size(MPI_COMM_WORLD, &procs);
19 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
20
21 if (rank == 0) {
22 values = (int*)malloc(sizeof(int)*procs);
23 }else{
24 values = (int*)malloc(sizeof(int));
25 *values = procs + rank;
26 }
27
28 if (rank != 2)
29 MPI_Gather(values, 1, MPI_INT, values, 1, MPI_INT, 0, MPI_COMM_WORLD);
30
31 free(values);
32 MPI_Finalize();
33 return 0;
34}
Note: See TracBrowser for help on using the repository browser.