File: getnodes.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 (144 lines) | stat: -rw-r--r-- 3,275 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
/*
 * 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: getnodes.c,v 6.9 2002/12/12 22:55:38 jsquyres Exp $
 * 
 *	Function:	- multiple node route matching
 */

#include <lam_config.h>
#include <etc_misc.h>
#include <events.h>
#include <net.h>
#include <rreq.h>
#include <typical.h>

#include <errno.h>
#include <unistd.h>


/*
 *	getnodes
 *
 *	Function:	- gets matching node IDs from local router
 *	Accepts: 	- node array
 *			- # array elements
 *			- node type
 *			- node type mask
 *	Returns:	- 0 or ERROR
 */
int
getnodes(int4 *pnodes, int4 nnodes, int4 nodetype, int4 typemask)
{
	struct rreq	*request;	/* router request */
	struct rreply	*reply;		/* router reply */
	struct nmsg	nhreq;		/* request message */
	struct nmsg	nhreply;	/* reply message */

	LAM_ZERO_ME(nhreq);
	LAM_ZERO_ME(nhreply);
/*
 * Set up the router request.
 */
	request = (struct rreq *) nhreq.nh_data;
	request->rq_src_event = -lam_getpid();
	request->rq_request = RQGETNODES;
	request->rq_pid = lam_getpid();		/* for sa_rtr */
	request->rq_nodetype = nodetype;
	request->rq_typemask = typemask;

	nhreq.nh_dl_event = EVROUTER;
	nhreq.nh_node = LOCAL;
	nhreq.nh_event = EVROUTER;
	nhreq.nh_type = RSMART;
	nhreq.nh_flags = 0;
	nhreq.nh_length = 0;
	nhreq.nh_msg = 0;

	nhreply.nh_event = -lam_getpid();
	nhreply.nh_type = 0;
	nhreply.nh_flags = 0;
	nhreply.nh_length = nnodes * sizeof(int);
	nhreply.nh_msg = (char *) pnodes;

	if (dsfr(&nhreq, &nhreply)) {
		return(ERROR);
	}

	reply = (struct rreply *) nhreply.nh_data;

	if (reply->rr_reply) {
		errno = reply->rr_reply;
		return(ERROR);
	} else {
		return(0);
	}
}


/*
 *	getntype
 *
 *	Returns:	- # of nodes with types satisfying the
 *			  given type in all bits that are set
 *			  in the given mask
 *	Accepts:	- nodetype bitfield value
 *			- nodetype bitfield mask
 */
int4
getntype(int4 node_type, int4 type_mask)
{
	struct rreq	*request;	/* router request */
	struct rreply	*reply;		/* router reply */
	struct nmsg	nhreq;		/* request message */
	struct nmsg	nhreply;	/* reply message */

	LAM_ZERO_ME(nhreq);
	LAM_ZERO_ME(nhreply);
/*
 * Set up the router request.
 */
	request = (struct rreq *) nhreq.nh_data;
	request->rq_src_event = -lam_getpid();
	request->rq_request = RQGETNTYPE;
	request->rq_nodetype = node_type;
	request->rq_typemask = type_mask;

	nhreq.nh_dl_event = EVROUTER;
	nhreq.nh_node = LOCAL;
	nhreq.nh_event = EVROUTER;
	nhreq.nh_type = RSMART;
	nhreq.nh_flags = 0;
	nhreq.nh_length = 0;
	nhreq.nh_msg = 0;

	nhreply.nh_event = -lam_getpid();
	nhreply.nh_type = 0;
	nhreply.nh_flags = 0;
	nhreply.nh_length = 0;
	nhreply.nh_msg = 0;

	if (dsfr(&nhreq, &nhreply)) {
		return(ERROR);
	}

	reply = (struct rreply *) nhreply.nh_data;

	if (reply->rr_reply) {
		errno = reply->rr_reply;
		return(ERROR);
	} else {
		return(reply->rr_ntype);
	}
}