source: CIVL/examples/mpi/collective/scatter_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: 812 bytes
RevLine 
[4ccacf8]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 */
[a7f50d5]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 for(int i = 0; i < procs; i++){
24 values[i] = i;
25 }
26 }else{
27 values = (int*)malloc(sizeof(int));
28 }
29
30 if (rank != 2)
31 MPI_Scatter(values, 1, MPI_INT, values, 1, MPI_INT, 0, MPI_COMM_WORLD);
32
33 free(values);
34 MPI_Finalize();
35 return 0;
36}
Note: See TracBrowser for help on using the repository browser.