PadicoTM

Documentation

« back to PM2 home.
na-group.c
Go to the documentation of this file.
1/*
2 * Padico -- a High Performance Parallel and Distributed Computing Environment
3 * Copyright (c) 2002-2026 INRIA and the University of Rennes 1
4 * Alexandre DENIS <Alexandre.Denis@inria.fr>
5 * Christian PEREZ <Christian.Perez@inria.fr>
6 *
7 * The software has been registered at the Agency for the Protection of
8 * Programs (APP) under the number IDDN.FR.001.260013.000.S.P.2002.000.10000.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
30#include <Padico/Puk.h>
31#include <Padico/Module.h>
32#include <Padico/PadicoTM.h>
33#include <Padico/Topology.h>
34
36
37PADICO_MODULE_HOOK(PadicoControl);
38
39/* ********************************************************* */
40
47
56
59{
60 const char*group_id;
61 int count;
62};
63
66
67static void na_group_destructor(const char*label, struct padico_group_s*group);
68
71
72static struct
73{
79
80static void na_group_destructor(const char*label, struct padico_group_s*group)
81{
83}
84
85/* ********************************************************* */
86
88{
89 const int publish = puk_opt_parse_bool(puk_parse_getattr(e, "publish"));
91
94 {
96 if(node == NULL)
97 {
98 padico_warning("bad node in group.\n");
99 puk_parse_set_rc(e, padico_rc_error("bad node in group"));
100 return;
101 }
103 }
104 if(publish)
105 {
107 }
108 else
109 {
111 }
112}
114{
115 .xml_tag = "PadicoControl:defgroup",
116 .end_handler = &defgroup_end_handler,
117 .required_level = PUK_TRUST_CONTROL
118};
119
120/* ********************************************************* */
121
130
132{
133 .xml_tag = "PadicoControl:killgroup",
134 .start_handler = NULL,
135 .end_handler = &killgroup_end_handler,
136 .required_level = PUK_TRUST_CONTROL
137};
138
140{
141 const char*group_name = puk_parse_getattr(e, "group");
144 if(barrier == NULL)
145 {
146 barrier = padico_malloc(sizeof(struct na_group_barrier_s));
147 barrier->group_id = padico_strdup(group_name);
148 barrier->count = 0;
150 }
151 barrier->count++;
154}
156{
157 .xml_tag = "PadicoControl:barrier-stage1",
158 .start_handler = NULL,
159 .end_handler = &group_barrier_stage1_end_handler,
160 .required_level = PUK_TRUST_CONTROL
161};
162
174{
175 .xml_tag = "PadicoControl:barrier-stage2",
176 .start_handler = NULL,
177 .end_handler = &group_barrier_stage2_end_handler,
178 .required_level = PUK_TRUST_CONTROL
179};
180
181
182/* ********************************************************* */
183
195
197{
200 puk_xml_delete_action("PadicoControl:defgroup");
201 puk_xml_delete_action("PadicoControl:killgroup");
202 puk_xml_delete_action("PadicoControl:barrier-stage1");
203 puk_xml_delete_action("PadicoControl:barrier-stage2");
204}
205
206/* *** Group ************************************************ */
207
209{
211 g->nodes = padico_topo_node_vect_new();
212 g->group_id = padico_strdup(id);
213 return g;
214}
215
217{
218 padico_trace("storing group %s nodes=%zd\n", g->group_id, padico_topo_node_vect_size(g->nodes));
220 padico_group_hashtable_insert(&na_group.groups, g->group_id, g);
222 return 0;
223}
224
232
234{
235 if(node != NULL)
236 {
238 }
239 else
240 {
241 padico_warning("trying to add a NULL node to a group.\n");
242 }
243}
244
246{
248 int i;
249 for(i = 0; i < padico_topo_node_vect_size(g->nodes); i++)
250 {
252 }
254 return ng;
255}
256
261
263{
264 int i;
265 for(i = 0; i < padico_topo_node_vect_size(g->nodes); i++)
266 {
267 if(padico_topo_node_vect_at(g->nodes, i) == node)
268 return i;
269 }
270 return -1;
271}
272
274{
275 return group->group_id;
276}
277
282
283
285{
287 padico_group_hashtable_remove(&na_group.groups, g->group_id);
289 padico_free((void*)g->group_id);
291 padico_free(g);
292}
293
294
317
319{
321 padico_string_printf(cmd, "<kill rc=\"%d\"/>", rc);
322 int i;
323 for(i = 0; i < padico_topo_node_vect_size(group->nodes); i++)
324 {
327 {
329 }
330 }
332}
333
339
342
344{
347 /* build hastable: host -> nodes vect; build hosts index *with order preserved* */
350 {
354 if(v == NULL)
355 {
359 }
361 }
362 /* compute matrix bounds */
364 int maxnodes = 0;
365 {
368 while(v != NULL)
369 {
370 const int size = padico_topo_node_vect_size(v);
371 if(size > maxnodes)
372 maxnodes = size;
374 }
376 }
378 padico_out(40, "maxhosts = %d; maxnodes = %d\n", maxhosts, maxnodes);
379 /* store nodes at their new place in matrix */
380 {
383 {
386 {
388 const int nnode = padico_topo_node_vect_rank(v, i);
390 if(strcmp(distrib, "cyclic") == 0)
391 {
393 matrix[nnode * maxhosts + nhost] = n;
394 }
395 else if(strcmp(distrib, "block") == 0)
396 {
398 matrix[nhost * maxnodes + nnode] = n;
399 }
400 else
401 {
402 padico_fatal("unknown distribution %s\n", distrib);
403 }
404 *i = NULL;
405 }
406 }
407 }
408 /* flatten matrix to eliminate holes, in case number of nodes is not multiple of number of hosts */
410 int k;
411 for(k = 0; k < maxhosts * maxnodes; k++)
412 {
414 if(n != NULL)
415 {
417 padico_out(40, "group: add node %s\n", padico_topo_node_getname(n));
418 }
419 }
420 /* cleanup */
424 return newgroup;
425}
426
427
428/* *** Group-control **************************************** */
429
437{
439 int i;
440 padico_out(40, "sending command to group %s\n%s", group->group_id, cmd);
441 greq->reqs = padico_reqs_vect_new();
442 for(i = 0; i < padico_topo_node_vect_size(group->nodes); i++)
443 {
445 padico_out(60, " %s -> node %d/%zd\n", cmd, i, padico_topo_node_vect_size(group->nodes) );
447 {
450 }
451 }
452 return greq;
453}
454
456{
458 int i;
459 padico_out(50, "waiting ACKs for group %s\n", group->group_id);
460 for(i = 0; i < padico_reqs_vect_size(greq->reqs); i++)
461 {
464 padico_out(50, "waiting reply for grank=%d; req_id=%d\n",
465 i, req->id);
468 if(urc)
469 {
471 }
472 padico_out(50, "got reply from node grank=%d\n", i);
473 }
476 padico_out(50, "request completed on group %s\n", group->group_id);
477 return rc;
478}
479
480/* ** Group barrier **************************************** */
481
483{
486 if(padico_group_size(group) <= 1)
487 return;
489 {
490 /* wait barrier-stage1 */
491 while((barrier == NULL) || (barrier->count < padico_group_size(group) - 1))
492 {
494 if(barrier == NULL)
495 {
497 }
498 if((barrier == NULL) || (barrier->count < padico_group_size(group) - 1))
499 {
500 marcel_cond_wait(&na_group.cond, &na_group.lock);
501 }
503 }
504
505 /* send barrier-stage2 */
506 int i;
507 for(i = 0; i < padico_group_size(group); i++)
508 {
511 {
513 padico_string_printf(msg_stage2, "<PadicoControl:barrier-stage2 group=\"%s\"/>",
517 }
518 }
519 }
520 else
521 {
522 /* init */
523 barrier = padico_malloc(sizeof(struct na_group_barrier_s));
525 barrier->count = 0;
529 /* send barrier-stage1 */
531 padico_string_printf(msg_ready, "<PadicoControl:barrier-stage1 group=\"%s\" node=\"%s\"/>",
535 /* wait barrier-stage2 */
536 while(barrier->count == 0)
537 {
539 marcel_cond_wait(&na_group.cond, &na_group.lock);
541 }
542 }
546 padico_free((char*)barrier->group_id);
548}
assert(slab_size > 0)
ns_rulebucket_hashtable_t h
struct ns_rulebucket_hash_entry_s * e
ssize_t n
Internal definitions for PadicoControl.
return NULL
Definition Shm.h:88
padico_topo_host_t host
struct padico_addrkey_hashtable_s table
Definition addrdb.c:72
static padico_group_t group
void *static bench_vect_buffer_queue_t v
Definition bench_vect.c:22
static int done
Definition console-mod.c:49
static int size
Definition datacheck.c:34
static int rank
Definition datacheck.c:35
static void padico_control_send_oneway(padico_topo_node_t node, const char *msg)
Send a "one way" message on the control channel.
static padico_req_t padico_control_send(padico_topo_node_t node, const char *cmd)
Send a blocking request on the control channel.
typdef struct padico_reqs_vect_s * padico_reqs_vect_t
Definition PadicoTM.h:150
padico_rc_t padico_tm_req_wait(padico_req_t req)
padico_rc_t rc
Definition PadicoTM.h:146
padico_topo_node_t padico_topo_getlocalnode(void)
Definition topology.c:1891
const char * padico_topo_node_getname(padico_topo_node_t node)
Get the canonical name of a node.
Definition topology.c:1917
padico_topo_host_t padico_topo_node_gethost(padico_topo_node_t node)
Get the host hosting a node.
Definition topology.c:1927
typdef struct padico_topo_host_vect_s * padico_topo_host_vect_t
Definition Topology.h:86
typdef struct padico_topo_node_vect_s * padico_topo_node_vect_t
Definition Topology.h:84
padico_topo_uuid_t padico_topo_node_getuuid(padico_topo_node_t node)
Get the UUID of a node.
Definition topology.c:1912
padico_topo_node_t node
Definition na-control.c:65
padico_group_t padico_group_init(const char *id)
Definition na-group.c:208
pthread_cond_t cond
Definition na-group.c:75
pthread_mutex_t lock
Definition na-group.c:74
void padico_control_group_finalize(void)
Definition na-group.c:196
void padico_group_publish(padico_group_t group)
Publishes a group to its members.
Definition na-group.c:295
int padico_group_store(padico_group_t g)
Definition na-group.c:216
static void group_barrier_stage2_end_handler(puk_parse_entity_t e)
Definition na-group.c:163
padico_rc_t padico_group_wait_all(padico_group_t group, padico_group_req_t greq)
Definition na-group.c:455
static struct puk_tag_action_s group_barrier_stage2_action
Definition na-group.c:173
const char * padico_group_name(padico_group_t group)
Definition na-group.c:273
struct na_group_barrier_hashtable_s barriers
Definition na-group.c:77
void padico_control_group_init(void)
Definition na-group.c:184
static struct puk_tag_action_s group_barrier_stage1_action
Definition na-group.c:155
static struct puk_tag_action_s killgroup_action
Definition na-group.c:131
padico_group_t padico_group_dup(padico_group_t g, const char *new_name)
Definition na-group.c:245
static void defgroup_end_handler(puk_parse_entity_t e)
Definition na-group.c:87
padico_group_t padico_group_topology(padico_group_t g, const char *distrib)
create a new group with nodes sorted according to given topology
Definition na-group.c:343
int padico_group_size(padico_group_t g)
Definition na-group.c:257
static void killgroup_end_handler(puk_parse_entity_t e)
Definition na-group.c:122
padico_topo_node_t padico_group_node(padico_group_t g, int rank)
Definition na-group.c:278
void padico_group_barrier(padico_group_t group)
Definition na-group.c:482
static void group_barrier_stage1_end_handler(puk_parse_entity_t e)
Definition na-group.c:139
void padico_group_destroy(padico_group_t g)
Definition na-group.c:284
void padico_group_node_add(padico_group_t g, padico_topo_node_t node)
Definition na-group.c:233
static struct puk_tag_action_s defgroup_action
Definition na-group.c:113
struct padico_group_hashtable_s groups
Definition na-group.c:76
padico_group_req_t padico_group_send_to_all(padico_group_t group, const char *cmd)
Sends a command to each member of a group (except self)
Definition na-group.c:436
int padico_group_rank(padico_group_t g, padico_topo_node_t node)
Rank of the given node in the group.
Definition na-group.c:262
static void na_group_destructor(const char *label, struct padico_group_s *group)
Definition na-group.c:80
void padico_group_kill(padico_group_t group, int rc)
kill all nodes in group
Definition na-group.c:318
static void group_host_table_destructor(padico_topo_host_t host, padico_topo_node_vect_t v)
Definition na-group.c:334
static struct @45 na_group
padico_group_t padico_group_lookup(const char *id)
Definition na-group.c:225
mx_request_t req
Definition psp-mx.c:103
a running barrier
Definition na-group.c:59
const char * group_id
group name; not group pointer, because it may not be created yet when receiving stage1 msgs
Definition na-group.c:60
int count
on node0: number of ready nodes; on other nodes, whether stage2 has been received
Definition na-group.c:61
a group request.
Definition na-group.c:53
padico_reqs_vect_t reqs
Definition na-group.c:54
a group of nodes
Definition na-group.c:43
padico_topo_node_vect_t nodes
Definition na-group.c:45
const char * group_id
Definition na-group.c:44