1.23
2.0
acw/focus-triggers
main
test-branch
| 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 |
|
|---|
| 18 | int main (int argc, char *argv[])
|
|---|
| 19 | {
|
|---|
| 20 | int numtasks, rank, sendcount, recvcount, source;
|
|---|
| 21 | float 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};
|
|---|
| 26 | float recvbuf[SIZE];
|
|---|
| 27 |
|
|---|
| 28 | MPI_Init(&argc,&argv);
|
|---|
| 29 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|---|
| 30 | MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
|
|---|
| 31 |
|
|---|
| 32 | if (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 | }
|
|---|
| 45 | else
|
|---|
| 46 | printf("Must specify %d processors. Terminating.\n",SIZE);
|
|---|
| 47 |
|
|---|
| 48 | MPI_Finalize();
|
|---|
| 49 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.