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.2 KB
|
| Rev | Line | |
|---|
| [0a7e736] | 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 | int main (int argc, char *argv[])
|
|---|
| 15 | {
|
|---|
| 16 | int numtasks, rank, sendcount, recvcount, source;
|
|---|
| 17 | float sendbuf[SIZE * SIZE] = {
|
|---|
| 18 | 1.0, 2.0, 3.0, 4.0,
|
|---|
| 19 | 5.0, 6.0, 7.0, 8.0,
|
|---|
| 20 | 9.0, 10.0, 11.0, 12.0,
|
|---|
| 21 | 13.0, 14.0, 15.0, 16.0};
|
|---|
| 22 | float recvbuf[SIZE];
|
|---|
| 23 |
|
|---|
| 24 | MPI_Init(&argc,&argv);
|
|---|
| 25 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|---|
| 26 | MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
|
|---|
| 27 |
|
|---|
| 28 | if (numtasks == SIZE) {
|
|---|
| 29 | source = 1;
|
|---|
| 30 | sendcount = SIZE;
|
|---|
| 31 | recvcount = SIZE;
|
|---|
| 32 | MPI_Scatter(sendbuf,sendcount,MPI_FLOAT,recvbuf,recvcount,
|
|---|
| 33 | MPI_FLOAT,source,MPI_COMM_WORLD);
|
|---|
| 34 |
|
|---|
| 35 | printf("rank= %d Results: %f %f %f %f\n",rank,recvbuf[0],
|
|---|
| 36 | recvbuf[1],recvbuf[2],recvbuf[3]);
|
|---|
| 37 | //add assertions
|
|---|
| 38 | for(int i=0; i<SIZE; i++)
|
|---|
| 39 | assert(recvbuf[i] == *(sendbuf + SIZE * rank + i));
|
|---|
| 40 | }
|
|---|
| 41 | else
|
|---|
| 42 | printf("Must specify %d processors. Terminating.\n",SIZE);
|
|---|
| 43 |
|
|---|
| 44 | MPI_Finalize();
|
|---|
| 45 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.