2004-02-13 05:20:43 +03:00
|
|
|
/*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "group/group.h"
|
2004-03-19 00:35:28 +03:00
|
|
|
#include "include/constants.h"
|
2004-03-15 05:25:49 +03:00
|
|
|
#include "mpi.h"
|
2004-02-13 05:20:43 +03:00
|
|
|
|
|
|
|
/* define class information */
|
|
|
|
static void lam_group_construct(lam_group_t *);
|
|
|
|
static void lam_group_destruct(lam_group_t *);
|
|
|
|
|
2004-04-14 03:42:31 +04:00
|
|
|
OBJ_CLASS_INSTANCE(lam_group_t,
|
|
|
|
lam_object_t,
|
|
|
|
lam_group_construct,
|
|
|
|
lam_group_destruct);
|
2004-02-13 05:20:43 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Table for Fortran <-> C group handle conversion
|
|
|
|
*/
|
|
|
|
lam_pointer_array_t *lam_group_f_to_c_table;
|
|
|
|
|
2004-03-15 05:25:49 +03:00
|
|
|
/*
|
|
|
|
* MPI_GROUP_EMPTY
|
|
|
|
*/
|
|
|
|
lam_group_t lam_mpi_group_empty = {
|
2004-04-14 03:42:31 +04:00
|
|
|
{ NULL, 0 }, /* base class */
|
|
|
|
0, /* number of processes in group */
|
|
|
|
MPI_PROC_NULL, /* rank in group */
|
|
|
|
LAM_ERROR, /* index in Fortran <-> C translation array */
|
|
|
|
(lam_proc_t **)NULL /* pointers to lam_proc_t structures */
|
2004-03-15 05:25:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2004-04-14 03:42:31 +04:00
|
|
|
* MPI_GROUP_NULL - defining this group makes it much easier to handle
|
|
|
|
* this group with out special case code
|
2004-03-15 05:25:49 +03:00
|
|
|
*/
|
|
|
|
lam_group_t lam_mpi_group_null = {
|
2004-04-14 03:42:31 +04:00
|
|
|
{ NULL, 0 }, /* base class */
|
|
|
|
0, /* number of processes in group */
|
|
|
|
MPI_PROC_NULL, /* rank in group */
|
|
|
|
LAM_ERROR, /* index in Fortran <-> C translation array */
|
|
|
|
(lam_proc_t **)NULL /* pointers to lam_proc_t structures */
|
2004-03-15 05:25:49 +03:00
|
|
|
};
|
|
|
|
|
2004-04-14 03:42:31 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a new group structure
|
2004-02-13 05:20:43 +03:00
|
|
|
*/
|
2004-03-19 09:06:52 +03:00
|
|
|
lam_group_t *lam_group_allocate(int group_size)
|
2004-02-13 05:20:43 +03:00
|
|
|
{
|
|
|
|
/* local variables */
|
|
|
|
lam_group_t *new_group;
|
|
|
|
|
|
|
|
/* create new group group element */
|
2004-04-14 03:42:31 +04:00
|
|
|
new_group = OBJ_NEW(lam_group_t);
|
|
|
|
if (new_group) {
|
|
|
|
if (LAM_ERROR == new_group->grp_f_to_c_index) {
|
2004-03-19 17:25:08 +03:00
|
|
|
OBJ_RELEASE(new_group);
|
2004-04-14 03:42:31 +04:00
|
|
|
new_group = NULL;
|
2004-03-19 17:25:08 +03:00
|
|
|
} else {
|
|
|
|
/* allocate array of (lam_proc_t *)'s, one for each
|
|
|
|
* process in the group */
|
2004-04-14 03:42:31 +04:00
|
|
|
new_group->grp_proc_pointers =
|
|
|
|
malloc(sizeof(lam_proc_t *) * group_size);
|
|
|
|
if (0 < group_size) {
|
2004-03-19 17:25:08 +03:00
|
|
|
/* non-empty group */
|
2004-04-14 03:42:31 +04:00
|
|
|
if (!new_group->grp_proc_pointers) {
|
|
|
|
/* grp_proc_pointers allocation failed */
|
|
|
|
free(new_group);
|
|
|
|
new_group = NULL;
|
|
|
|
}
|
2004-02-13 17:16:30 +03:00
|
|
|
}
|
2004-02-13 05:20:43 +03:00
|
|
|
|
2004-03-19 17:25:08 +03:00
|
|
|
/* set the group size */
|
2004-04-14 03:42:31 +04:00
|
|
|
new_group->grp_proc_count = group_size;
|
2004-03-19 17:25:08 +03:00
|
|
|
}
|
2004-03-19 17:15:16 +03:00
|
|
|
}
|
|
|
|
|
2004-02-13 05:20:43 +03:00
|
|
|
/* return */
|
|
|
|
return new_group;
|
|
|
|
}
|
|
|
|
|
2004-04-14 03:42:31 +04:00
|
|
|
|
2004-03-16 01:14:08 +03:00
|
|
|
/*
|
|
|
|
* increment the reference count of the proc structures
|
|
|
|
*/
|
2004-04-14 03:42:31 +04:00
|
|
|
void lam_group_increment_proc_count(lam_group_t *group)
|
|
|
|
{
|
2004-03-16 01:14:08 +03:00
|
|
|
/* local variable */
|
|
|
|
int proc;
|
|
|
|
|
2004-04-14 03:42:31 +04:00
|
|
|
for (proc = 0; proc < group->grp_proc_count; proc++) {
|
2004-03-16 01:14:08 +03:00
|
|
|
OBJ_RETAIN(group->grp_proc_pointers[proc]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-04-14 03:42:31 +04:00
|
|
|
|
|
|
|
/*
|
2004-02-13 05:20:43 +03:00
|
|
|
* group constructor
|
|
|
|
*/
|
2004-03-19 09:06:52 +03:00
|
|
|
static void lam_group_construct(lam_group_t *new_group)
|
2004-03-16 01:14:08 +03:00
|
|
|
{
|
|
|
|
int ret_val;
|
|
|
|
|
|
|
|
/* assign entry in fortran <-> c translation array */
|
2004-04-14 03:42:31 +04:00
|
|
|
ret_val = lam_pointer_array_add(lam_group_f_to_c_table, new_group);
|
|
|
|
new_group->grp_f_to_c_index = ret_val;
|
2004-02-13 05:20:43 +03:00
|
|
|
|
|
|
|
/* return */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-04-14 03:42:31 +04:00
|
|
|
|
|
|
|
/*
|
2004-02-13 05:20:43 +03:00
|
|
|
* group destructor
|
|
|
|
*/
|
2004-03-19 09:06:52 +03:00
|
|
|
static void lam_group_destruct(lam_group_t *group)
|
2004-03-16 01:14:08 +03:00
|
|
|
{
|
2004-02-14 01:18:38 +03:00
|
|
|
/* release thegrp_proc_pointers memory */
|
2004-04-14 03:42:31 +04:00
|
|
|
if (NULL != group->grp_proc_pointers)
|
2004-02-14 01:18:38 +03:00
|
|
|
free(group->grp_proc_pointers);
|
|
|
|
|
|
|
|
/* reset the lam_group_f_to_c_table entry - make sure that the
|
|
|
|
* entry is in the table */
|
2004-04-14 03:42:31 +04:00
|
|
|
if (NULL != lam_pointer_array_get_item(lam_group_f_to_c_table,
|
|
|
|
group->grp_f_to_c_index)) {
|
2004-02-14 01:18:38 +03:00
|
|
|
lam_pointer_array_set_item(lam_group_f_to_c_table,
|
2004-04-14 03:42:31 +04:00
|
|
|
group->grp_f_to_c_index, NULL);
|
2004-02-14 01:18:38 +03:00
|
|
|
}
|
|
|
|
|
2004-02-13 05:20:43 +03:00
|
|
|
/* return */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-04-14 03:42:31 +04:00
|
|
|
|
|
|
|
/*
|
2004-02-13 05:20:43 +03:00
|
|
|
* Initialize LAM group infrastructure
|
|
|
|
*/
|
2004-02-14 01:18:38 +03:00
|
|
|
int lam_group_init(void)
|
2004-02-13 05:20:43 +03:00
|
|
|
{
|
|
|
|
/* local variables */
|
2004-04-14 03:42:31 +04:00
|
|
|
int return_value, ret_val;
|
2004-03-15 05:25:49 +03:00
|
|
|
|
2004-04-14 03:42:31 +04:00
|
|
|
return_value = LAM_SUCCESS;
|
2004-02-13 05:20:43 +03:00
|
|
|
|
|
|
|
/* initialize lam_group_f_to_c_table */
|
2004-04-14 03:42:31 +04:00
|
|
|
lam_group_f_to_c_table = OBJ_NEW(lam_pointer_array_t);
|
|
|
|
if (NULL == lam_group_f_to_c_table) {
|
2004-03-15 05:25:49 +03:00
|
|
|
return LAM_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add MPI_GROUP_NULL to table */
|
2004-04-14 03:42:31 +04:00
|
|
|
ret_val =
|
|
|
|
lam_pointer_array_add(lam_group_f_to_c_table, &lam_mpi_group_null);
|
|
|
|
if (LAM_ERROR == ret_val) {
|
2004-03-15 05:25:49 +03:00
|
|
|
return LAM_ERROR;
|
|
|
|
};
|
|
|
|
/* make sure that MPI_GROUP_NULL is in location in the table */
|
2004-04-14 03:42:31 +04:00
|
|
|
if (LAM_GROUP_NULL_FORTRAN != ret_val) {
|
2004-03-15 05:25:49 +03:00
|
|
|
return LAM_ERROR;
|
|
|
|
};
|
2004-04-14 03:42:31 +04:00
|
|
|
lam_mpi_group_null.grp_f_to_c_index = ret_val;
|
2004-03-15 05:25:49 +03:00
|
|
|
|
|
|
|
/* add MPI_GROUP_EMPTY to table */
|
2004-04-14 03:42:31 +04:00
|
|
|
ret_val =
|
|
|
|
lam_pointer_array_add(lam_group_f_to_c_table,
|
|
|
|
&lam_mpi_group_empty);
|
|
|
|
if (LAM_ERROR == ret_val) {
|
2004-03-15 05:25:49 +03:00
|
|
|
return LAM_ERROR;
|
|
|
|
};
|
|
|
|
/* make sure that MPI_GROUP_NULL is in location in the table */
|
2004-04-14 03:42:31 +04:00
|
|
|
if (LAM_GROUP_EMPTY_FORTRAN != ret_val) {
|
2004-03-15 05:25:49 +03:00
|
|
|
return LAM_ERROR;
|
|
|
|
};
|
2004-04-14 03:42:31 +04:00
|
|
|
lam_mpi_group_empty.grp_f_to_c_index = ret_val;
|
2004-03-15 05:25:49 +03:00
|
|
|
|
2004-02-13 05:20:43 +03:00
|
|
|
/* return */
|
|
|
|
return return_value;
|
|
|
|
}
|
2004-02-13 19:23:29 +03:00
|
|
|
|
2004-04-14 03:42:31 +04:00
|
|
|
|
|
|
|
/*
|
2004-02-13 19:23:29 +03:00
|
|
|
* Clean up group infrastructure
|
|
|
|
*/
|
2004-04-14 03:42:31 +04:00
|
|
|
int lam_group_finalize(void)
|
|
|
|
{
|
2004-02-13 19:23:29 +03:00
|
|
|
/* local variables */
|
2004-04-14 03:42:31 +04:00
|
|
|
int return_value = LAM_SUCCESS;
|
2004-02-13 19:23:29 +03:00
|
|
|
|
2004-03-15 05:25:49 +03:00
|
|
|
/* remove group for MPI_COMM_WORLD */
|
|
|
|
|
2004-02-13 19:23:29 +03:00
|
|
|
OBJ_RELEASE(lam_group_f_to_c_table);
|
|
|
|
|
|
|
|
/* return */
|
|
|
|
return return_value;
|
2004-03-26 08:00:29 +03:00
|
|
|
}
|