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:
894 bytes
|
| Line | |
|---|
| 1 | #include <mpi.h>
|
|---|
| 2 | #include <stdio.h>
|
|---|
| 3 | #include <stdlib.h>
|
|---|
| 4 | #include <assert.h>
|
|---|
| 5 | #define SIZE 4
|
|---|
| 6 |
|
|---|
| 7 | int main (int argc, char *argv[])
|
|---|
| 8 | {
|
|---|
| 9 | int numtasks, rank, sendcount, recvcount, source;
|
|---|
| 10 | float sendbuf[SIZE];
|
|---|
| 11 | float recvbuf[SIZE * SIZE];
|
|---|
| 12 |
|
|---|
| 13 | MPI_Init(&argc,&argv);
|
|---|
| 14 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|---|
| 15 | MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
|
|---|
| 16 |
|
|---|
| 17 | if (numtasks == SIZE) {
|
|---|
| 18 | source = 1;
|
|---|
| 19 | sendcount = SIZE;
|
|---|
| 20 | recvcount = SIZE;
|
|---|
| 21 | //init sendbuf
|
|---|
| 22 | for(int i=0; i<SIZE; i++)
|
|---|
| 23 | sendbuf[i] = (float)(rank * SIZE + i);
|
|---|
| 24 | MPI_Gather(sendbuf,sendcount,MPI_FLOAT,recvbuf,recvcount,
|
|---|
| 25 | MPI_FLOAT,source,MPI_COMM_WORLD);
|
|---|
| 26 | //assertions
|
|---|
| 27 | if(rank == source){
|
|---|
| 28 | for(int i=0; i<(SIZE*SIZE); i++){
|
|---|
| 29 | printf("recvbuf[%d] : %f\n", i, recvbuf[i]);
|
|---|
| 30 | assert(recvbuf[i] == i);
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
| 33 | }
|
|---|
| 34 | else
|
|---|
| 35 | printf("Must specify %d processors. Terminating.\n",SIZE);
|
|---|
| 36 |
|
|---|
| 37 | MPI_Finalize();
|
|---|
| 38 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.