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:
1014 bytes
|
| Line | |
|---|
| 1 | /*
|
|---|
| 2 | Shows a short cut method to create a collection of communicators.
|
|---|
| 3 | All processors with the "same color" will be in the same communicator.
|
|---|
| 4 | In this case the color is either 0 or 1 for even or odd processors.
|
|---|
| 5 | Index gives rank in new communicator.
|
|---|
| 6 | */
|
|---|
| 7 | #include <stdio.h>
|
|---|
| 8 | #include <stdlib.h>
|
|---|
| 9 | #include <mpi.h>
|
|---|
| 10 | #include <math.h>
|
|---|
| 11 | int main(argc,argv)
|
|---|
| 12 | int argc;
|
|---|
| 13 | char *argv[];
|
|---|
| 14 | {
|
|---|
| 15 | int myid, numprocs;
|
|---|
| 16 | int color,Zero_one,new_id,new_nodes;
|
|---|
| 17 | MPI_Comm NEW_COMM;
|
|---|
| 18 | MPI_Init(&argc,&argv);
|
|---|
| 19 | MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
|
|---|
| 20 | MPI_Comm_rank(MPI_COMM_WORLD,&myid);
|
|---|
| 21 | color=myid % 2;
|
|---|
| 22 | MPI_Comm_split(MPI_COMM_WORLD,color,myid,&NEW_COMM);
|
|---|
| 23 | MPI_Comm_rank( NEW_COMM, &new_id);
|
|---|
| 24 | MPI_Comm_rank( NEW_COMM, &new_nodes);
|
|---|
| 25 | Zero_one = -1;
|
|---|
| 26 | if(new_id==0)Zero_one = color;
|
|---|
| 27 | MPI_Bcast(&Zero_one,1,MPI_INT,0, NEW_COMM);
|
|---|
| 28 | if(Zero_one==0)printf("part of even processor communicator \n");
|
|---|
| 29 | if(Zero_one==1)printf("part of odd processor communicator \n");
|
|---|
| 30 | printf("old_id= %d new_id= %d\n", myid, new_id);
|
|---|
| 31 | MPI_Finalize();
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.