File: gexcl.c

package info (click to toggle)
lam 7.1.4-8
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 56,404 kB
  • sloc: ansic: 156,541; sh: 9,991; cpp: 7,699; makefile: 5,621; perl: 488; fortran: 260; asm: 83
file content (176 lines) | stat: -rw-r--r-- 4,017 bytes parent folder | download | duplicates (11)
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
/*
 * Copyright (c) 2001-2002 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: gexcl.c,v 6.6 2002/12/11 19:15:11 jsquyres Exp $
 *
 *	Function:	- form new group by exclusion
 *	Accepts:	- original group
 *			- # of processes to exclude
 *			- ranks
 *			- ptr new group
 *	Returns:	- MPI_SUCCESS or error code
 */

#include <stdlib.h>

#include <blktype.h>
#include <mpi.h>
#include <mpisys.h>
#include <rpisys.h>
#include <terror.h>

/*@

MPI_Group_excl - Produces a group by reordering an existing group and
taking only unlisted members

Input Parameters:
+ g - group (handle) 
. n - number of elements in array 'ranks' (integer) 
- ranks - array of integer ranks in 'g' not to appear in 'png' 

Output Parameter:
. png - new group derived from above, preserving the order defined by
'group' (handle)

Notes:

Each of the ranks to exclude must be a valid rank in the group and all
elements must be distinct or the function is erroneous.

When a group is no longer being used, it should be freed with
'MPI_Group_free'.

.N fortran

.N Errors
.N MPI_SUCCESS
.N MPI_ERR_GROUP
.N MPI_ERR_ARG
.N MPI_ERR_RANK

.seealso: MPI_Group_free

.N ACK
@*/
int MPI_Group_excl(MPI_Group g, int n, int *ranks, 
		   MPI_Group *png)
{
	int		i, j;
	int		*r;
	int		nproc;			/* # processes */
	struct _proc	**pi, **pj;		/* processes in groups */
	MPI_Group	ng;			/* new group */

	lam_initerr_m();
	lam_setfunc_m(BLKMPIGROUPEXCL);
/*
 * Check the arguments.
 */
	if (g == MPI_GROUP_NULL) {
		return(lam_errfunc(MPI_COMM_WORLD,
			BLKMPIGROUPEXCL, lam_mkerr(MPI_ERR_GROUP, EINVAL)));
	}

	if ((png == 0) || ((n > 0) && (ranks == 0))
			|| (n < 0) || (n > g->g_nprocs)) {
		return(lam_errfunc(MPI_COMM_WORLD,
			BLKMPIGROUPEXCL, lam_mkerr(MPI_ERR_ARG, EINVAL)));
	}
/*
 * Handle the trivial cases.
 */
	if (n == 0) {
		*png = g;
		g->g_refcount++;
		lam_resetfunc_m(BLKMPIGROUPEXCL);
		return(MPI_SUCCESS);
	}
/*
 * Get the # of processes in the new group.
 * Flag the excluded processes.
 */
	nproc = g->g_nprocs - n;
	pi = g->g_procs;

	for (r = ranks, i = 0; i < n; ++i, ++r) {

		if ((*r < 0) || (*r >= g->g_nprocs)
				|| (pi[*r]->p_mode & LAM_PFLAG)) {
			
			for (r = ranks, j = 0; j < i; ++j, ++r) {
				pi[*r]->p_mode &= ~LAM_PFLAG;
			}
			return(lam_errfunc(MPI_COMM_WORLD, BLKMPIGROUPEXCL,
					   lam_mkerr(MPI_ERR_RANK, EINVAL)));
		} else {
			pi[*r]->p_mode |= LAM_PFLAG;
		}
	}
/*
 * Handle the empty difference case.
 */
	if (nproc == 0) {
		*png = MPI_GROUP_EMPTY;
		MPI_GROUP_EMPTY->g_refcount++;

		for (i = 0, pi = g->g_procs; i < g->g_nprocs; ++i, ++pi) {
			(*pi)->p_mode &= ~LAM_PFLAG;
		}

		lam_resetfunc_m(BLKMPIGROUPEXCL);
		return(MPI_SUCCESS);
	}
/*
 * Allocate a new group.
 */
	ng = (MPI_Group) malloc((unsigned) sizeof(struct _group) +
					(nproc * sizeof(struct _proc *)));
	if (ng == 0) {
		for (i = 0, pi = g->g_procs; i < g->g_nprocs; ++i, ++pi) {
			(*pi)->p_mode &= ~LAM_PFLAG;
		}

		return(lam_errfunc(MPI_COMM_WORLD, BLKMPIGROUPEXCL,
				lam_mkerr(MPI_ERR_OTHER, errno)));
	}

	*png = ng;
	ng->g_nprocs = nproc;
	ng->g_myrank = MPI_UNDEFINED;
	ng->g_refcount = 1;
	ng->g_f77handle = -1;
	ng->g_procs = (struct _proc **) ((char *) ng + sizeof(struct _group));
/*
 * Fill the new group processes.
 */
	pj = ng->g_procs;

	for (i = 0, pi = g->g_procs; i < g->g_nprocs; ++i, ++pi) {

		if ((*pi)->p_mode & LAM_PFLAG) {
			(*pi)->p_mode &= ~LAM_PFLAG;
		} else {
			if (*pi == lam_myproc) {
				ng->g_myrank = (int) (pj - ng->g_procs);
			}
			(*pi)->p_refcount++;
			*pj = *pi;
			++pj;
		}
	}

	lam_resetfunc_m(BLKMPIGROUPEXCL);
	return(MPI_SUCCESS);
}