[5725] | 1 | #include "mpiP.h" |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * MPI_Cart_create |
---|
| 5 | * |
---|
| 6 | * create a new communicator, |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | FC_FUNC( mpi_cart_create , MPI_CART_CREATE ) |
---|
| 11 | ( int *comm_old, int *ndims, int *dims, int *periods, |
---|
| 12 | int *reorder, int *comm_cart, int *ierr) |
---|
| 13 | { |
---|
| 14 | *ierr = MPI_Cart_create( *comm_old, *ndims, dims, periods, *reorder, |
---|
| 15 | comm_cart); |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | int MPI_Cart_create( MPI_Comm comm_old, int ndims, int *dims, int *periods, |
---|
| 20 | int reorder, MPI_Comm *comm_cart) |
---|
| 21 | { |
---|
| 22 | int i; |
---|
| 23 | for (i = 0; i < ndims; i++) |
---|
| 24 | if (dims[i] > 1) |
---|
| 25 | { |
---|
| 26 | printf("MPI_Cart_create: Greater dimension than no. of procs\n"); |
---|
| 27 | abort(); |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | MPI_Comm_dup(comm_old, comm_cart); |
---|
| 31 | |
---|
| 32 | return MPI_SUCCESS; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | /* |
---|
| 37 | * MPI_Cart_get |
---|
| 38 | * |
---|
| 39 | * Returns information about the cartesian organization |
---|
| 40 | * of the communicator. |
---|
| 41 | * |
---|
| 42 | * Assuming the user gives right maxdims, the only possible |
---|
| 43 | * dimensions are (1,1,..,1) for however many dimensions |
---|
| 44 | */ |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | FC_FUNC( mpi_cart_get , MPI_CART_GET ) |
---|
| 48 | (int * comm, int * maxdims, int * dims, |
---|
| 49 | int * periods, int * coords, int * ierr) |
---|
| 50 | { |
---|
| 51 | *ierr = MPI_Cart_get(*comm, *maxdims, dims, periods, coords); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | int MPI_Cart_get(MPI_Comm comm, int maxdims, int *dims, |
---|
| 56 | int *periods, int *coords) |
---|
| 57 | { |
---|
| 58 | int i; |
---|
| 59 | for (i=0;i<maxdims;i++) |
---|
| 60 | { |
---|
| 61 | dims[i]=1; |
---|
| 62 | coords[i]=0; |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | /* |
---|
| 69 | * MPI_Cart_coords |
---|
| 70 | * |
---|
| 71 | * Returns the coordinates of a particular rank |
---|
| 72 | * If rank != 0, erroneous. Coordinates must be (0,0) |
---|
| 73 | */ |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | FC_FUNC( mpi_cart_coords , MPI_CART_COORDS) |
---|
| 77 | (int *comm, int *rank, int *maxdims, int *coords, int *ierr) |
---|
| 78 | { |
---|
| 79 | *ierr = MPI_Cart_coords(*comm, *rank, *maxdims, coords); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | int MPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int *coords) |
---|
| 84 | { |
---|
| 85 | int i; |
---|
| 86 | |
---|
| 87 | if (rank != 0) |
---|
| 88 | { |
---|
| 89 | printf("MPI_Cart_coords: Rank != 0\n"); |
---|
| 90 | abort(); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | for (i=0;i<maxdims;i++) |
---|
| 94 | coords[i]=0; |
---|
| 95 | |
---|
| 96 | return MPI_SUCCESS; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | /* |
---|
| 101 | * MPI_Dims_create |
---|
| 102 | * |
---|
| 103 | * A convenience function to distribute nodes among a grid. Since we have one |
---|
| 104 | * node only, every dimension must be "1" or it is erroneous |
---|
| 105 | */ |
---|
| 106 | |
---|
| 107 | FC_FUNC( mpi_dims_create , MPI_DIMS_CREATE ) |
---|
| 108 | (int *nnodes, int *ndims, int * dims, int *ierr) |
---|
| 109 | { |
---|
| 110 | *ierr = MPI_Dims_create(*nnodes, *ndims, dims); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | int MPI_Dims_create(int nnodes, int ndims, int *dims) |
---|
| 115 | { |
---|
| 116 | int i; |
---|
| 117 | |
---|
| 118 | if (nnodes > 1) |
---|
| 119 | { |
---|
| 120 | printf("MPI_Dims_create: More nodes than procs specified.\n"); |
---|
| 121 | abort(); |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | for (i=0; i<ndims; i++) |
---|
| 125 | dims[i] = 1; |
---|
| 126 | |
---|
| 127 | return MPI_SUCCESS; |
---|
| 128 | } |
---|