source: CIVL/examples/mpi/collective/matTrans_bad.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: 1.4 KB
Line 
1/**
2 * This exercise presents a simple program to demonstrate the use of MPI_Alltoall.
3 * In this exercise, a 4x4 matrix has been divided into 4 1x4 submatrices.
4 * Each submatrix is stored in the local memory of each process.
5 * Using MPI_Alltoall, each element j of submtarix in process i is replaced by element i
6 * of submatrix in process j. A few bugs have been delibrately introduced into the given program.
7 * Based on our discussion of MPI_Alltoall, can you find the bugs and correct them?
8 *
9 * online source: http://static.msi.umn.edu/tutorial/scicomp/general/MPI/workshop_MPI/src/alltoall/main.html
10 */
11
12#include <stdio.h>
13#include "mpi.h"
14
15int main( int argc, char **argv )
16{
17 int send[4], recv[3];
18 int rank, size, k;
19
20 MPI_Init( &argc, &argv );
21 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
22 MPI_Comm_size( MPI_COMM_WORLD, &size );
23
24 if (size != 4) {
25 printf("Error!:# of processors must be equal to 4\n");
26 printf("Programm aborting....\n");
27 MPI_Abort(MPI_COMM_WORLD, 1);
28 }
29 for (k=0;k<size;k++) send[k] = (k+1) + rank*size;
30
31 printf("%d : send = %d %d %d %d\n", rank, send[0], send[1], send[2], send[3]);
32
33 MPI_Alltoall(&send, 2, MPI_FLOAT, &recv, 1, MPI_INT, MPI_COMM_WORLD);
34
35 printf("%d : recv = %d %d %d %d\n", rank, recv[0], recv[1], recv[2], recv[3]);
36
37 MPI_Finalize();
38 return 0;
39}
Note: See TracBrowser for help on using the repository browser.