1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
|
/*
* Copyright (c) 2001-2003 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 1998-2001 University of Notre Dame.
* All rights reserved.
* Copyright (c) 1994-1998 The Ohio State University.
* All rights reserved.
*
* This file is part of the LAM/MPI software package. For license
* information, see the LICENSE file in the top level directory of the
* LAM/MPI source distribution.
*
* $HEADER$
*
* $Id: iccreate.c,v 6.12 2003/02/20 19:45:27 jsquyres Exp $
*
* Function: - create a new inter-communicator
* Accepts: - local intra-communicator
* - local leader
* - peer communicator
* - peer leader
* - tag
* - new inter-communicator (out)
* Returns: - MPI_SUCCESS or error code
*/
#include <stdlib.h>
#include <lam_config.h>
#include <app_mgmt.h>
#include <blktype.h>
#include <mpi.h>
#include <mpisys.h>
#include <lam-ssi-rpi.h>
#include <rpisys.h>
#include <terror.h>
#include <lam-ssi-coll.h>
/*@
MPI_Intercomm_create - Creates an intercommuncator from two
intracommunicators
Input Paramters:
+ lcomm - Local (intra)communicator
. lleader - Rank in local_comm of leader (often 0)
. pcomm - Remote communicator
. pleader - Rank in peer_comm of remote leader (often 0)
- tag - Message tag to use in constructing intercommunicator; if
multiple 'MPI_Intercomm_creates' are being made, they should use
different tags (more precisely, ensure that the local and remote
leaders are using different tags for each 'MPI_intercomm_create').
Output Parameter:
. newcomm - Created intercommunicator
Notes:
The MPI 1.1 Standard contains two mutually exclusive comments on the
input intracommunicators. One says that their repective groups must
be disjoint; the other that the leaders can be the same process.
After some discussion by the MPI Forum, it has been decided that the
groups must be disjoint. Note that the `reason` given for this in the
standard is `not` the reason for this choice; rather, the `other`
operations on intercommunicators (like 'MPI_Intercomm_merge') do not
make sense if the groups are not disjoint.
.N fortran
.N Errors
.N MPI_SUCCESS
.N MPI_ERR_COMM
.N MPI_ERR_TAG
.N MPI_ERR_ARG
.N MPI_ERR_EXHAUSTED
.N MPI_ERR_RANK
.seealso: MPI_Intercomm_merge, MPI_Comm_free, MPI_Comm_remote_group,
MPI_Comm_remote_size
.N ACK
@*/
int MPI_Intercomm_create(MPI_Comm lcomm, int lleader,
MPI_Comm pcomm, int pleader, int tag,
MPI_Comm *newcomm)
{
MPI_Status stat; /* message status */
MPI_Group lgroup; /* local group */
MPI_Group rgroup; /* remote group */
int myrank; /* my rank */
int cid; /* global context ID */
int err; /* error code */
int i; /* favourite index */
int lgsize; /* local group size */
int rgsize; /* remote group size */
int lgbytes; /* local group GPS size */
int rgbytes; /* remote group GPS size */
struct _gps *lprocs; /* local process GPS */
struct _gps *rprocs; /* remote process GPS */
struct _proc *p; /* favourite pointer */
struct _proc **pp; /* another pointer */
struct _gps *pgp; /* yet another pointer */
lam_initerr();
lam_setfunc(BLKMPIICOMMCREATE);
/*
* Check the arguments.
*/
if (lcomm == MPI_COMM_NULL) {
return(lam_errfunc(MPI_COMM_WORLD,
BLKMPIICOMMCREATE, lam_mkerr(MPI_ERR_COMM, EINVAL)));
}
if (LAM_IS_INTER(lcomm)) {
return(lam_errfunc(lcomm,
BLKMPIICOMMCREATE, lam_mkerr(MPI_ERR_COMM, EINVAL)));
}
if (lcomm->c_group->g_myrank == lleader) {
if (pcomm == MPI_COMM_NULL) {
return(lam_errfunc(lcomm, BLKMPIICOMMCREATE,
lam_mkerr(MPI_ERR_COMM, EINVAL)));
}
rgroup = (LAM_IS_INTER(pcomm))
? pcomm->c_rgroup : pcomm->c_group;
if ((pleader < 0) || (pleader >= rgroup->g_nprocs)) {
return(lam_errfunc(pcomm, BLKMPIICOMMCREATE,
lam_mkerr(MPI_ERR_RANK, EINVAL)));
}
}
if (tag < 0) {
return(lam_errfunc(lcomm,
BLKMPIICOMMCREATE, lam_mkerr(MPI_ERR_TAG, EINVAL)));
}
if ((lleader < 0) || (lleader >= lcomm->c_group->g_nprocs)) {
return(lam_errfunc(lcomm,
BLKMPIICOMMCREATE, lam_mkerr(MPI_ERR_RANK, EINVAL)));
}
if (newcomm == 0) {
return(lam_errfunc(lcomm,
BLKMPIICOMMCREATE, lam_mkerr(MPI_ERR_ARG, EINVAL)));
}
#if LAM_WANT_IMPI
/* Remove this when IMPI collectives are implemented */
if (LAM_IS_IMPI(lcomm)) {
return lam_err_comm(lcomm, MPI_ERR_COMM, EINVAL,
"Collectives not yet implemented on IMPI communicators");
}
if (LAM_IS_IMPI(pcomm)) {
return lam_err_comm(pcomm, MPI_ERR_COMM, ENOSYS,
"Collectives not yet implemented on IMPI communicators");
}
#endif
LAM_TRACE(lam_tr_cffstart(BLKMPIICOMMCREATE));
lgroup = lcomm->c_group;
lgsize = lgroup->g_nprocs;
myrank = lgroup->g_myrank;
/* Collectively decide on a new CID. All processes in both
groups get the new CID */
err = lam_coll_alloc_inter_cid(lcomm, lleader, pcomm, pleader,
tag, BLKMPIICOMMCREATE, &cid);
if (err != MPI_SUCCESS)
return(lam_errfunc(lcomm, BLKMPIICOMMCREATE, err));
/* Get the size of the remote group and distribute it to the
local group */
if (lleader == myrank) {
err = MPI_Sendrecv(&lgsize, 1, MPI_INT, pleader, tag,
&rgsize, 1, MPI_INT, pleader, tag,
pcomm, MPI_STATUS_IGNORE);
if (err != MPI_SUCCESS)
return(lam_errfunc(lcomm, BLKMPIICOMMCREATE, err));
}
err = MPI_Bcast(&rgsize, 1, MPI_INT, lleader, lcomm);
if (err != MPI_SUCCESS)
return(lam_errfunc(lcomm, BLKMPIICOMMCREATE, err));
/*
* Allocate remote group process GPS array.
*/
rgbytes = rgsize * sizeof(struct _gps);
rprocs = (struct _gps *) malloc((unsigned) rgbytes);
if (rprocs == 0) {
return(lam_errfunc(lcomm, BLKMPIICOMMCREATE,
lam_mkerr(MPI_ERR_OTHER, errno)));
}
/*
* Leaders exchange process GPS arrays and broadcast them to their group.
*/
if (lleader == myrank) {
lgbytes = lgsize * sizeof(struct _gps);
lprocs = (struct _gps *) malloc((unsigned) lgbytes);
if (lprocs == 0) {
return(lam_errfunc(lcomm, BLKMPIICOMMCREATE,
lam_mkerr(MPI_ERR_OTHER, errno)));
}
/*
* Fill local process GPS.
*/
for (i = 0, pp = lgroup->g_procs; i < lgsize; ++i, ++pp) {
lprocs[i] = (*pp)->p_gps;
}
err = MPI_Sendrecv(lprocs, lgbytes/sizeof(int), MPI_INT,
pleader, tag, rprocs,
rgbytes/sizeof(int), MPI_INT,
pleader, tag, pcomm, &stat);
free((char *) lprocs);
if (err != MPI_SUCCESS) {
free((char *) rprocs);
return(lam_errfunc(lcomm, BLKMPIICOMMCREATE, err));
}
}
err = MPI_Bcast(rprocs, rgbytes/sizeof(int), MPI_INT, lleader, lcomm);
if (err != MPI_SUCCESS) {
free((char *) rprocs);
return(lam_errfunc(lcomm, BLKMPIICOMMCREATE, err));
}
/*
* Create the remote group.
*/
rgroup = (MPI_Group) malloc((unsigned) sizeof(struct _group) +
(rgsize * sizeof(struct _proc **)));
if (rgroup == 0) {
free((char *) rprocs);
return(lam_errfunc(lcomm, BLKMPIICOMMCREATE,
lam_mkerr(MPI_ERR_OTHER, errno)));
}
rgroup->g_nprocs = rgsize;
rgroup->g_myrank = MPI_UNDEFINED;
rgroup->g_refcount = 1;
rgroup->g_f77handle = -1;
rgroup->g_procs = (struct _proc **)
((char *) rgroup + sizeof(struct _group));
for (i = 0, pgp = rprocs; i < rgsize; ++i, ++pgp) {
if ((p = lam_procadd(pgp)) == 0) {
return(lam_errfunc(lcomm, BLKMPIICOMMCREATE,
lam_mkerr(MPI_ERR_OTHER, errno)));
}
if (!(p->p_mode & LAM_PRPIINIT)) {
p->p_mode |= LAM_PCLIENT;
}
p->p_refcount++;
rgroup->g_procs[i] = p;
}
free((char *) rprocs);
/*
* Create the new communicator.
*/
*newcomm = 0;
if (lam_comm_new(cid, lgroup, rgroup, LAM_CINTER, newcomm)) {
return(lam_errfunc(lcomm, BLKMPIICOMMCREATE,
lam_mkerr(MPI_ERR_OTHER, errno)));
}
lgroup->g_refcount++;
(*newcomm)->c_errhdl = lcomm->c_errhdl;
lcomm->c_errhdl->eh_refcount++;
if (!al_insert(lam_comms, newcomm)) {
return(lam_errfunc(lcomm, BLKMPIICOMMCREATE,
lam_mkerr(MPI_ERR_INTERN, errno)));
}
if (lam_tr_comm(*newcomm)) {
return(lam_errfunc(lcomm, BLKMPIICOMMCREATE,
lam_mkerr(MPI_ERR_INTERN, errno)));
}
lam_setcid(cid);
/*
* setup any new processes
*/
if (RPI_ADDPROCS(rgroup->g_procs, rgroup->g_nprocs)) {
return(lam_errfunc(lcomm, BLKMPIICOMMCREATE,
lam_mkerr(MPI_ERR_OTHER, errno)));
}
/* Let the collective SSI modules battle over who will do
collectives on this new communicator. It'll likely be the
same as the one that's on this communicator, but we still
give them the option to do something different anyway... */
if (lam_ssi_coll_base_init_comm(*newcomm) != 0)
return(lam_errfunc(lcomm, BLKMPIICOMMCREATE,
lam_mkerr(MPI_ERR_INTERN, ENOSYS)));
LAM_TRACE(lam_tr_cffend(BLKMPIICOMMCREATE, lleader, lcomm, 0, 0));
lam_resetfunc(BLKMPIICOMMCREATE);
return(MPI_SUCCESS);
}
|