File: ccreate.c

package info (click to toggle)
lam 7.1.2-1.4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 54,608 kB
  • ctags: 17,034
  • sloc: ansic: 156,264; sh: 9,976; cpp: 7,699; makefile: 5,589; perl: 476; fortran: 260; asm: 83
file content (165 lines) | stat: -rw-r--r-- 4,112 bytes parent folder | download | duplicates (10)
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
/*
 * 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: ccreate.c,v 6.9 2003/02/20 19:45:27 jsquyres Exp $
 *
 *	Function:	- create a new communicator
 *	Accepts:	- old communicator
 *			- new group
 *			- ptr new communicator
 *	Returns:	- MPI_SUCCESS or error code
 */

#include <stdlib.h>

#include <lam_config.h>
#include <blktype.h>
#include <mpi.h>
#include <mpisys.h>
#include <terror.h>
#include <lam-ssi-coll.h>


/*@

MPI_Comm_create - Creates a new communicator

Input Parameters:
+ comm - communicator (handle) 
- group - group, which is a subset of the group of 'comm'  (handle) 

Output Parameter:
. newcomm - new communicator (handle) 

Notes:

When a communicator is no longer being used, it should be freed with
'MPI_Comm_free'.

.N fortran

.N Errors
.N MPI_SUCCESS
.N MPI_ERR_COMM
.N MPI_ERR_GROUP
.N MPI_ERR_EXHAUSTED
.N MPI_ERR_INTERN

.seealso: MPI_Comm_free

.N ACK
@*/
int MPI_Comm_create(MPI_Comm comm, MPI_Group group, 
		    MPI_Comm *newcomm)
{
	int		cid;			/* global max context ID */
	int		rank;			/* process rank */
	int		err;			/* error code */

	lam_initerr();
	lam_setfunc(BLKMPICOMMCREATE);
/*
 * Check the arguments.
 */
	if (comm == MPI_COMM_NULL) {
		return(lam_errfunc(MPI_COMM_WORLD, BLKMPICOMMCREATE,
				lam_mkerr(MPI_ERR_COMM, EINVAL)));
	}

	if (LAM_IS_INTER(comm)) {
		return(lam_errfunc(comm, BLKMPICOMMCREATE,
				lam_mkerr(MPI_ERR_COMM, EINVAL)));
	}

	if (group == MPI_GROUP_NULL) {
		return(lam_errfunc(comm, BLKMPICOMMCREATE,
				lam_mkerr(MPI_ERR_GROUP, EINVAL)));
	}

	if (newcomm == 0) {
		return(lam_errfunc(comm, BLKMPICOMMCREATE,
				lam_mkerr(MPI_ERR_ARG, EINVAL)));
	}

#if LAM_WANT_IMPI
	/* Remove this when IMPI collectives are implemented */
        if (LAM_IS_IMPI(comm)) {
	  return lam_err_comm(comm, MPI_ERR_COMM, ENOSYS, 
			      "Collectives not yet implemented on IMPI communicators");
	}
#endif

/*
 * Set up tracing.
 */
	LAM_TRACE(lam_tr_cffstart(BLKMPICOMMCREATE));

	/* Collectively decide what the new CID will be.  Processes
	   not in the group participate but do not affect the final
	   CID. */

	rank = group->g_myrank;
	err = lam_coll_alloc_intra_cid(comm, (rank == MPI_UNDEFINED) ? 0 : 1,
				       BLKMPICOMMCREATE, &cid);
	if (err != MPI_SUCCESS) {
		LAM_TRACE(lam_tr_cffend(BLKMPICOMMCREATE, -1, comm, 0, 0));
		lam_resetfunc(BLKMPICOMMCREATE);
		return(lam_errfunc(comm, BLKMPICOMMCREATE, err));
	}

	if (rank == MPI_UNDEFINED) {
		*newcomm = MPI_COMM_NULL;
		LAM_TRACE(lam_tr_cffend(BLKMPICOMMCREATE, -1, comm, 0, 0));
		lam_resetfunc(BLKMPICOMMCREATE);
		return(MPI_SUCCESS);
	}
/*
 * Create the new communicator.
 */
	*newcomm = 0;
	if (lam_comm_new(cid, group, MPI_GROUP_NULL, 0, newcomm)) {
		return(lam_errfunc(comm, BLKMPICOMMCREATE,
				lam_mkerr(MPI_ERR_OTHER, errno)));
	}

	group->g_refcount++;
	(*newcomm)->c_errhdl = comm->c_errhdl;
	comm->c_errhdl->eh_refcount++;

	if (!al_insert(lam_comms, newcomm)) {
		return(lam_errfunc(comm, BLKMPICOMMCREATE,
				lam_mkerr(MPI_ERR_INTERN, errno)));
	}
	
	if (lam_tr_comm(*newcomm)) {
		return(lam_errfunc(comm, BLKMPICOMMCREATE,
				lam_mkerr(MPI_ERR_INTERN, errno)));
	}

 	lam_setcid(cid);

	/* 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(comm, BLKMPICOMMCREATE,
			     lam_mkerr(MPI_ERR_INTERN, ENOSYS)));

	LAM_TRACE(lam_tr_cffend(BLKMPICOMMCREATE, -1, comm, 0, 0));

	lam_resetfunc(BLKMPICOMMCREATE);
	return(MPI_SUCCESS);
}