2004-01-25 04:51:49 +03:00
|
|
|
/*
|
2004-10-15 23:31:47 +04:00
|
|
|
* $HEADER$
|
2004-01-25 04:51:49 +03:00
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "ompi_config.h"
|
2004-01-25 04:51:49 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "mpi.h"
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "mpi/c/bindings.h"
|
|
|
|
#include "group/group.h"
|
2004-03-23 00:42:12 +03:00
|
|
|
#include "errhandler/errhandler.h"
|
|
|
|
#include "communicator/communicator.h"
|
2004-01-25 04:51:49 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#if OMPI_HAVE_WEAK_SYMBOLS && OMPI_PROFILING_DEFINES
|
2004-01-25 04:51:49 +03:00
|
|
|
#pragma weak MPI_Group_range_incl = PMPI_Group_range_incl
|
|
|
|
#endif
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#if OMPI_PROFILING_DEFINES
|
2004-04-20 22:50:43 +04:00
|
|
|
#include "mpi/c/profile/defines.h"
|
|
|
|
#endif
|
|
|
|
|
2004-07-30 06:58:53 +04:00
|
|
|
static const char FUNC_NAME[] = "MPI_Group_range_incl";
|
2004-06-23 00:21:35 +04:00
|
|
|
|
|
|
|
|
2004-03-02 03:14:13 +03:00
|
|
|
int MPI_Group_range_incl(MPI_Group group, int n_triplets, int ranges[][3],
|
2004-07-30 06:58:53 +04:00
|
|
|
MPI_Group *new_group)
|
|
|
|
{
|
2004-03-02 03:14:13 +03:00
|
|
|
/* local variables */
|
2004-03-23 00:42:12 +03:00
|
|
|
int new_group_size, proc, first_rank, last_rank;
|
2004-03-02 03:14:13 +03:00
|
|
|
int stride, triplet, index, *elements_int_list, my_group_rank;
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_group_t *group_pointer, *new_group_pointer;
|
|
|
|
ompi_proc_t *my_proc_pointer;
|
2004-03-02 03:14:13 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
group_pointer=(ompi_group_t *)group;
|
2004-03-02 03:14:13 +03:00
|
|
|
|
2004-03-15 05:25:49 +03:00
|
|
|
/* can't act on NULL group */
|
|
|
|
if( MPI_PARAM_CHECK ) {
|
2004-06-23 00:21:35 +04:00
|
|
|
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
|
2004-06-18 23:02:52 +04:00
|
|
|
|
2004-03-23 00:42:12 +03:00
|
|
|
if ( (MPI_GROUP_NULL == group) || (NULL == group) ) {
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
|
2004-06-23 00:21:35 +04:00
|
|
|
FUNC_NAME);
|
2004-03-15 05:25:49 +03:00
|
|
|
}
|
2004-03-02 03:14:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pull out elements
|
|
|
|
*/
|
|
|
|
elements_int_list =
|
|
|
|
(int *) malloc(sizeof(int) * group_pointer->grp_proc_count);
|
|
|
|
if (NULL == elements_int_list) {
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_OTHER,
|
2004-06-23 00:21:35 +04:00
|
|
|
FUNC_NAME);
|
2004-03-02 03:14:13 +03:00
|
|
|
}
|
|
|
|
for (proc = 0; proc < group_pointer->grp_proc_count; proc++) {
|
|
|
|
elements_int_list[proc] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* loop over triplet */
|
|
|
|
new_group_size = 0;
|
|
|
|
for (triplet = 0; triplet < n_triplets; triplet++)
|
|
|
|
{
|
|
|
|
first_rank = ranges[triplet][0];
|
|
|
|
last_rank = ranges[triplet][1];
|
|
|
|
stride = ranges[triplet][2];
|
|
|
|
if(( 0 > first_rank ) || (first_rank > group_pointer->grp_proc_count)) {
|
|
|
|
free(elements_int_list);
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
|
2004-06-23 00:21:35 +04:00
|
|
|
FUNC_NAME);
|
2004-03-02 03:14:13 +03:00
|
|
|
}
|
|
|
|
if((0 > last_rank) || (last_rank > group_pointer->grp_proc_count)) {
|
|
|
|
free(elements_int_list);
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
|
2004-03-23 00:42:12 +03:00
|
|
|
"MPI_Group_range_incl - IV");
|
2004-03-02 03:14:13 +03:00
|
|
|
}
|
|
|
|
if (stride == 0) {
|
|
|
|
free(elements_int_list);
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
|
2004-03-23 00:42:12 +03:00
|
|
|
"MPI_Group_range_incl - V");
|
2004-03-02 03:14:13 +03:00
|
|
|
}
|
|
|
|
if (first_rank < last_rank) {
|
|
|
|
|
|
|
|
if (stride < 0) {
|
|
|
|
free(elements_int_list);
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
|
2004-03-23 00:42:12 +03:00
|
|
|
"MPI_Group_range_incl - VI");
|
2004-03-02 03:14:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* positive stride */
|
|
|
|
index = first_rank;
|
|
|
|
while (index <= last_rank) {
|
|
|
|
/* make sure rank has not already been selected */
|
|
|
|
if (elements_int_list[index] != -1) {
|
|
|
|
free(elements_int_list);
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
|
2004-03-23 00:42:12 +03:00
|
|
|
"MPI_Group_range_incl - VII");
|
2004-03-02 03:14:13 +03:00
|
|
|
}
|
|
|
|
elements_int_list[index] = new_group_size;
|
|
|
|
index += stride;
|
|
|
|
new_group_size++;
|
|
|
|
} /* end while loop */
|
|
|
|
|
|
|
|
} else if (first_rank > last_rank) {
|
|
|
|
|
|
|
|
if (stride > 0){
|
|
|
|
free(elements_int_list);
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
|
2004-03-23 00:42:12 +03:00
|
|
|
"MPI_Group_range_incl - VIII");
|
2004-03-02 03:14:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* negative stride */
|
|
|
|
index = first_rank;
|
|
|
|
while (index >= last_rank) {
|
|
|
|
/* make sure rank has not already been selected */
|
|
|
|
if (elements_int_list[index] != -1) {
|
|
|
|
free(elements_int_list);
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
|
2004-03-23 00:42:12 +03:00
|
|
|
"MPI_Group_range_incl - IX");
|
2004-03-02 03:14:13 +03:00
|
|
|
}
|
|
|
|
elements_int_list[index] = new_group_size;
|
|
|
|
index += stride;
|
|
|
|
new_group_size++;
|
2004-03-26 00:31:43 +03:00
|
|
|
} /* end while loop */
|
2004-03-02 03:14:13 +03:00
|
|
|
|
2004-03-26 00:31:43 +03:00
|
|
|
} else { /* first_rank == last_rank */
|
2004-03-02 03:14:13 +03:00
|
|
|
|
|
|
|
index = first_rank;
|
|
|
|
if (elements_int_list[index] != -1) {
|
|
|
|
free(elements_int_list);
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK,
|
2004-03-23 00:42:12 +03:00
|
|
|
"MPI_Group_range_incl - X");
|
2004-03-02 03:14:13 +03:00
|
|
|
}
|
|
|
|
elements_int_list[index] = new_group_size;
|
|
|
|
new_group_size++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-06 02:51:34 +04:00
|
|
|
if ( 0 == new_group_size ) {
|
|
|
|
*new_group = MPI_GROUP_EMPTY;
|
|
|
|
OBJ_RETAIN(MPI_GROUP_EMPTY);
|
|
|
|
return MPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
/* allocate a new ompi_group_t structure */
|
|
|
|
new_group_pointer=ompi_group_allocate(new_group_size);
|
2004-03-15 05:25:49 +03:00
|
|
|
if( NULL == new_group_pointer ) {
|
|
|
|
free(elements_int_list);
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
|
2004-03-23 00:42:12 +03:00
|
|
|
"MPI_Group_range_incl - X");
|
2004-03-15 05:25:49 +03:00
|
|
|
}
|
|
|
|
|
2004-03-02 03:14:13 +03:00
|
|
|
/* fill in group list */
|
|
|
|
for (proc = 0; proc < group_pointer->grp_proc_count; proc++) {
|
|
|
|
/* if value >= 0, include in the list */
|
|
|
|
if (0 <= elements_int_list[proc] ) {
|
2004-06-15 04:06:33 +04:00
|
|
|
new_group_pointer->grp_proc_pointers[elements_int_list[proc]] =
|
2004-03-02 03:14:13 +03:00
|
|
|
group_pointer->grp_proc_pointers[proc];
|
|
|
|
}
|
|
|
|
} /* end of proc loop */
|
|
|
|
|
2004-03-16 04:18:47 +03:00
|
|
|
/* increment proc reference counters */
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_group_increment_proc_count(new_group_pointer);
|
2004-03-16 04:18:47 +03:00
|
|
|
|
2004-03-02 03:14:13 +03:00
|
|
|
free(elements_int_list);
|
|
|
|
|
|
|
|
/* find my rank */
|
|
|
|
my_group_rank=group_pointer->grp_my_rank;
|
|
|
|
my_proc_pointer=group_pointer->grp_proc_pointers[my_group_rank];
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_set_group_rank(new_group_pointer,my_proc_pointer);
|
2004-03-02 03:14:13 +03:00
|
|
|
|
|
|
|
*new_group = (MPI_Group)new_group_pointer;
|
|
|
|
|
2004-01-25 04:51:49 +03:00
|
|
|
return MPI_SUCCESS;
|
|
|
|
}
|