File: gtranks.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 (107 lines) | stat: -rw-r--r-- 2,568 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
/*
 * 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: gtranks.c,v 6.6 2002/12/11 19:15:11 jsquyres Exp $
 *
 *	Function:	- get process ranks in a second group
 *	Accepts:	- first group
 *			- # of processes
 *			- array of ranks in first group
 *			- second group
 *			- array of ranks in second group (returned values)
 *	Returns:	- MPI_SUCCESS or error code
 */

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

/*@

MPI_Group_translate_ranks - Translates the ranks of processes in one
group to those in another group

Input Parameters:
+ g1 - group1 (handle) 
. n - number of ranks in 'r1' and 'r2' arrays (integer)
. r1 - array of zero or more valid ranks in 'g1' 
- g2 - group2 (handle) 

Output Parameter:
. r2 - array of corresponding ranks in 'g2', 'MPI_UNDEFINED' when no
correspondence exists.

.N fortran

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

.N ACK
@*/
int MPI_Group_translate_ranks(MPI_Group g1, int n, 
			      int *r1, MPI_Group g2, int *r2)
{
	int		i, j;			/* favourite indices */
	int		rank;			/* process rank */
	struct _proc	**p1, **p2;		/* gps pointers */

	lam_initerr();
	lam_setfunc(BLKMPIGROUPTRANKS);
/*
 * Check given arguments.
 */
	if ((g1 == MPI_GROUP_NULL) || (g2 == MPI_GROUP_NULL)) {
		return(lam_errfunc(MPI_COMM_WORLD,
			BLKMPIGROUPTRANKS, lam_mkerr(MPI_ERR_GROUP, EINVAL)));
	}

	if (n == 0) {
		lam_resetfunc(BLKMPIGROUPTRANKS);
		return(MPI_SUCCESS);
	}

	if ((n < 0) || (r1 == 0) || (r2 == 0)) {
		return(lam_errfunc(MPI_COMM_WORLD,
			BLKMPIGROUPTRANKS, lam_mkerr(MPI_ERR_ARG, EINVAL)));
	}
/*
 * Loop over the processes, translating their ranks.
 */
	for (i = 0; i < n; ++i) {
		rank = r1[i];

		if ((rank >= 0) && (rank < g1->g_nprocs)) {

			p1 = g1->g_procs + rank;
			p2 = g2->g_procs;

			for (j = 0; j < g2->g_nprocs; ++j, ++p2) {
				if (*p1 == *p2) break;
			}

			r2[i] = (j < g2->g_nprocs) ? j : MPI_UNDEFINED;
		}
		else {
			return(lam_errfunc(MPI_COMM_WORLD,
					   BLKMPIGROUPTRANKS, 
					   lam_mkerr(MPI_ERR_RANK, EINVAL)));
		}
	}

	lam_resetfunc(BLKMPIGROUPTRANKS);
	return(MPI_SUCCESS);
}