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:
794 bytes
|
| Rev | Line | |
|---|
| [a9a9973] | 1 | /* Good scatter.
|
|---|
| 2 | */
|
|---|
| 3 | #include<mpi.h>
|
|---|
| 4 | #include<assert.h>
|
|---|
| 5 | #include<stdlib.h>
|
|---|
| 6 |
|
|---|
| 7 | #define COUNT 10
|
|---|
| 8 |
|
|---|
| 9 | int nprocs;
|
|---|
| 10 | int myrank;
|
|---|
| 11 | int root;
|
|---|
| 12 |
|
|---|
| 13 | void main() {
|
|---|
| 14 | int argc;
|
|---|
| 15 | char **argv;
|
|---|
| 16 | double *sendbuf = (double*)NULL;
|
|---|
| 17 | double recvbuf[COUNT];
|
|---|
| 18 | int i;
|
|---|
| 19 |
|
|---|
| 20 | MPI_Init(&argc, &argv);
|
|---|
| 21 | MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
|
|---|
| 22 | MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
|
|---|
| 23 | root = nprocs - 1; // to be different
|
|---|
| 24 | if (myrank == root) {
|
|---|
| 25 | sendbuf = (double*)malloc(COUNT*nprocs*sizeof(double));
|
|---|
| 26 | for (i=0; i<COUNT*nprocs; i++)
|
|---|
| 27 | sendbuf[i] = 1.0*i;
|
|---|
| 28 | }
|
|---|
| [ffbeaa8] | 29 | MPI_Scatter(sendbuf, COUNT, MPI_DOUBLE,
|
|---|
| [a9a9973] | 30 | &recvbuf[0], COUNT, MPI_DOUBLE,
|
|---|
| 31 | root, MPI_COMM_WORLD);
|
|---|
| 32 | if (myrank == root) {
|
|---|
| 33 | free(sendbuf);
|
|---|
| 34 | }
|
|---|
| 35 | for (i=0; i<COUNT; i++) {
|
|---|
| 36 | assert(recvbuf[i] == COUNT*myrank + i);
|
|---|
| 37 | }
|
|---|
| 38 | MPI_Finalize();
|
|---|
| 39 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.