source: CIVL/examples/mpi/routines/Gather_Scatter/mpi_scatter.c@ dccd621

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since dccd621 was 0baeebd, checked in by Ziqing Luo <ziqing@…>, 12 years ago

cleaned up examples

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

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/******************************************************************************
2* FILE: mpi_scatter.c
3* DESCRIPTION:
4* MPI tutorial example code: Collective Communications
5* AUTHOR: Blaise Barney
6* LAST REVISED: 04/13/05
7******************************************************************************/
8#include "mpi.h"
9#include <stdio.h>
10#include <stdlib.h>
11#include <assert.h>
12#define SIZE 4
13
14#ifdef _CIVL
15$input int _NPROCS=4;
16#endif
17
18int main (int argc, char *argv[])
19{
20int numtasks, rank, sendcount, recvcount, source;
21float sendbuf[SIZE * SIZE] = {
22 1.0, 2.0, 3.0, 4.0,
23 5.0, 6.0, 7.0, 8.0,
24 9.0, 10.0, 11.0, 12.0,
25 13.0, 14.0, 15.0, 16.0};
26float recvbuf[SIZE];
27
28MPI_Init(&argc,&argv);
29MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
31
32if (numtasks == SIZE) {
33 source = 1;
34 sendcount = SIZE;
35 recvcount = SIZE;
36 MPI_Scatter(sendbuf,sendcount,MPI_FLOAT,recvbuf,recvcount,
37 MPI_FLOAT,source,MPI_COMM_WORLD);
38
39 printf("rank= %d Results: %f %f %f %f\n",rank,recvbuf[0],
40 recvbuf[1],recvbuf[2],recvbuf[3]);
41 //add assertions
42 for(int i=0; i<SIZE; i++)
43 assert(recvbuf[i] == *(sendbuf + SIZE * rank + i));
44 }
45else
46 printf("Must specify %d processors. Terminating.\n",SIZE);
47
48MPI_Finalize();
49}
Note: See TracBrowser for help on using the repository browser.