The worm is in the apple.
--- /dev/null
+/* Copyright (c) 2016. The SimGrid Team. All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef SIMGRID_SMPI_FORWARD_HPP
+#define SIMGRID_SMPI_FORWARD_HPP
+
+
+#ifdef __cplusplus
+
+#include <boost/intrusive_ptr.hpp>
+namespace simgrid {
+namespace SMPI {
+
+class Group;
+
+}
+}
+
+typedef simgrid::SMPI::Group SMPI_Group;
+
+#else
+
+typedef struct SMPI_Group SMPI_Group;
+
+#endif
+
+#endif
#include <xbt/function_types.h>
#include "simgrid/datatypes.h"
+#include "forward.hpp"
+
#ifdef _WIN32
#define MPI_CALL(type,name,args) \
type name args; \
struct s_smpi_mpi_topology;
typedef struct s_smpi_mpi_topology *MPI_Topology;
-
-struct s_smpi_mpi_group;
-typedef struct s_smpi_mpi_group *MPI_Group;
+
+typedef SMPI_Group* MPI_Group;
#define MPI_GROUP_NULL ((MPI_Group)NULL)
* See COPYRIGHT in top-level directory.
*/
#include "colls_private.h"
+#include "src/smpi/smpi_group.hpp"
extern int (*MV2_Bcast_function) (void *buffer, int count, MPI_Datatype datatype,
}
int* leaders_map = smpi_comm_get_leaders_map(comm);
- leader_of_root = smpi_group_rank(smpi_comm_group(comm),leaders_map[root]);
- leader_root = smpi_group_rank(smpi_comm_group(leader_comm),leaders_map[root]);
+ leader_of_root = smpi_comm_group(comm)->rank(leaders_map[root]);
+ leader_root = smpi_comm_group(leader_comm)->rank(leaders_map[root]);
if (local_size > 1) {
*/
#include "colls_private.h"
-
+#include "src/smpi/smpi_group.hpp"
#define MPIR_Gather_MV2_Direct smpi_coll_tuned_gather_ompi_basic_linear
#define MPIR_Gather_MV2_two_level_Direct smpi_coll_tuned_gather_ompi_basic_linear
}
leader_comm = smpi_comm_get_leaders_comm(comm);
int* leaders_map = smpi_comm_get_leaders_map(comm);
- leader_of_root = smpi_group_rank(smpi_comm_group(comm),leaders_map[root]);
- leader_root = smpi_group_rank(smpi_comm_group(leader_comm),leaders_map[root]);
+ leader_of_root = smpi_comm_group(comm)->rank(leaders_map[root]);
+ leader_root = smpi_comm_group(leader_comm)->rank(leaders_map[root]);
/* leader_root is the rank of the leader of the root in leader_comm.
* leader_root is to be used as the root of the inter-leader gather ops
*/
*/
#include "colls_private.h"
+#include "src/smpi/smpi_group.hpp"
#define MV2_INTRA_SHMEM_REDUCE_MSG 2048
#define mv2_g_shmem_coll_max_msg_size (1 << 17)
leader_comm = smpi_comm_get_leaders_comm(comm);
int* leaders_map = smpi_comm_get_leaders_map(comm);
- leader_of_root = smpi_group_rank(smpi_comm_group(comm),leaders_map[root]);
- leader_root = smpi_group_rank(smpi_comm_group(leader_comm),leaders_map[root]);
+ leader_of_root = smpi_comm_group(comm)->rank(leaders_map[root]);
+ leader_root = smpi_comm_group(leader_comm)->rank(leaders_map[root]);
is_commutative=smpi_op_is_commute(op);
* See COPYRIGHT in top-level directory.
*/
#include "colls_private.h"
+#include "src/smpi/smpi_group.hpp"
#define MPIR_Scatter_MV2_Binomial smpi_coll_tuned_scatter_ompi_binomial
#define MPIR_Scatter_MV2_Direct smpi_coll_tuned_scatter_ompi_basic_linear
leader_comm = smpi_comm_get_leaders_comm(comm);
int* leaders_map = smpi_comm_get_leaders_map(comm);
- leader_of_root = smpi_group_rank(smpi_comm_group(comm),leaders_map[root]);
- leader_root = smpi_group_rank(smpi_comm_group(leader_comm),leaders_map[root]);
+ leader_of_root = smpi_comm_group(comm)->rank(leaders_map[root]);
+ leader_root = smpi_comm_group(leader_comm)->rank(leaders_map[root]);
/* leader_root is the rank of the leader of the root in leader_comm.
* leader_root is to be used as the root of the inter-leader gather ops
*/
}
leader_comm = smpi_comm_get_leaders_comm(comm);
int* leaders_map = smpi_comm_get_leaders_map(comm);
- leader_of_root = smpi_group_rank(smpi_comm_group(comm),leaders_map[root]);
- leader_root = smpi_group_rank(smpi_comm_group(leader_comm),leaders_map[root]);
+ leader_of_root = smpi_comm_group(comm)->rank(leaders_map[root]);
+ leader_root = smpi_comm_group(leader_comm)->rank(leaders_map[root]);
/* leader_root is the rank of the leader of the root in leader_comm.
* leader_root is to be used as the root of the inter-leader gather ops
*/
XBT_PRIVATE void smpi_op_set_fortran(MPI_Op op);
XBT_PRIVATE void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len, MPI_Datatype * datatype);
-XBT_PRIVATE MPI_Group smpi_group_new(int size);
-XBT_PRIVATE MPI_Group smpi_group_copy(MPI_Group origin);
-XBT_PRIVATE void smpi_group_destroy(MPI_Group group);
-XBT_PRIVATE void smpi_group_set_mapping(MPI_Group group, int index, int rank);
-XBT_PRIVATE int smpi_group_index(MPI_Group group, int rank);
-XBT_PRIVATE int smpi_group_rank(MPI_Group group, int index);
-XBT_PRIVATE int smpi_group_use(MPI_Group group);
-XBT_PRIVATE int smpi_group_unuse(MPI_Group group);
-XBT_PRIVATE int smpi_group_size(MPI_Group group);
-XBT_PRIVATE int smpi_group_compare(MPI_Group group1, MPI_Group group2);
-XBT_PRIVATE int smpi_group_incl(MPI_Group group, int n, int* ranks, MPI_Group* newgroup);
XBT_PRIVATE MPI_Topology smpi_comm_topo(MPI_Comm comm);
XBT_PRIVATE MPI_Comm smpi_comm_new(MPI_Group group, MPI_Topology topo);
#include "surf/surf.h"
#include "simgrid/sg_config.h"
#include "smpi/smpi_utils.hpp"
+#include "src/smpi/smpi_group.hpp"
#include "colls/colls.h"
#include <simgrid/s4u/host.hpp>
{
MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process_index(),
- smpi_group_index(smpi_comm_group(comm), dst), tag, comm, PERSISTENT | SEND | PREPARED);
+ smpi_comm_group(comm)->index(dst), tag, comm, PERSISTENT | SEND | PREPARED);
return request;
}
{
MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process_index(),
- smpi_group_index(smpi_comm_group(comm), dst), tag, comm, PERSISTENT | SSEND | SEND | PREPARED);
+ smpi_comm_group(comm)->index(dst), tag, comm, PERSISTENT | SSEND | SEND | PREPARED);
return request;
}
{
MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype,
- src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : smpi_group_index(smpi_comm_group(comm), src),
+ src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : smpi_comm_group(comm)->index(src),
smpi_process_index(), tag, comm, PERSISTENT | RECV | PREPARED);
return request;
}
{
MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
request = build_request(buf==MPI_BOTTOM ? nullptr : buf , count, datatype, smpi_process_index(),
- smpi_group_index(smpi_comm_group(comm), dst), tag,comm, PERSISTENT | ISEND | SEND | PREPARED);
+ smpi_comm_group(comm)->index(dst), tag,comm, PERSISTENT | ISEND | SEND | PREPARED);
return request;
}
{
MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process_index(),
- smpi_group_index(smpi_comm_group(comm), dst), tag, comm, NON_PERSISTENT | ISEND | SEND);
+ smpi_comm_group(comm)->index(dst), tag, comm, NON_PERSISTENT | ISEND | SEND);
smpi_mpi_start(request);
return request;
}
{
MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process_index(),
- smpi_group_index(smpi_comm_group(comm), dst), tag,comm, NON_PERSISTENT | ISEND | SSEND | SEND);
+ smpi_comm_group(comm)->index(dst), tag,comm, NON_PERSISTENT | ISEND | SSEND | SEND);
smpi_mpi_start(request);
return request;
}
{
MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE :
- smpi_group_index(smpi_comm_group(comm), src), smpi_process_index(), tag,
+ smpi_comm_group(comm)->index(src), smpi_process_index(), tag,
comm, PERSISTENT | RECV | PREPARED);
return request;
}
{
MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE :
- smpi_group_index(smpi_comm_group(comm), src), smpi_process_index(), tag, comm,
+ smpi_comm_group(comm)->index(src), smpi_process_index(), tag, comm,
NON_PERSISTENT | RECV);
smpi_mpi_start(request);
return request;
{
MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process_index(),
- smpi_group_index(smpi_comm_group(comm), dst), tag, comm, NON_PERSISTENT | SEND);
+ smpi_comm_group(comm)->index(dst), tag, comm, NON_PERSISTENT | SEND);
smpi_mpi_start(request);
smpi_mpi_wait(&request, MPI_STATUS_IGNORE);
{
MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process_index(),
- smpi_group_index(smpi_comm_group(comm), dst), tag, comm, NON_PERSISTENT | SSEND | SEND);
+ smpi_comm_group(comm)->index(dst), tag, comm, NON_PERSISTENT | SSEND | SEND);
smpi_mpi_start(request);
smpi_mpi_wait(&request, MPI_STATUS_IGNORE);
MPI_Request requests[2];
MPI_Status stats[2];
int myid=smpi_process_index();
- if ((smpi_group_index(smpi_comm_group(comm), dst) == myid) && (smpi_group_index(smpi_comm_group(comm), src) == myid)){
+ if ((smpi_comm_group(comm)->index(dst) == myid) && (smpi_comm_group(comm)->index(src) == myid)){
smpi_datatype_copy(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype);
return;
}
if(!((req->detached != 0) && ((req->flags & SEND) != 0)) && ((req->flags & PREPARED) == 0)){
if(status != MPI_STATUS_IGNORE) {
int src = req->src == MPI_ANY_SOURCE ? req->real_src : req->src;
- status->MPI_SOURCE = smpi_group_rank(smpi_comm_group(req->comm), src);
+ status->MPI_SOURCE = smpi_comm_group(req->comm)->rank(src);
status->MPI_TAG = req->tag == MPI_ANY_TAG ? req->real_tag : req->tag;
status->MPI_ERROR = req->truncated != 0 ? MPI_ERR_TRUNCATE : MPI_SUCCESS;
// this handles the case were size in receive differs from size in send
void smpi_mpi_iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status){
MPI_Request request = build_request(nullptr, 0, MPI_CHAR, source == MPI_ANY_SOURCE ? MPI_ANY_SOURCE :
- smpi_group_index(smpi_comm_group(comm), source), smpi_comm_rank(comm), tag, comm, PERSISTENT | RECV);
+ smpi_comm_group(comm)->index(source), smpi_comm_rank(comm), tag, comm, PERSISTENT | RECV);
// to avoid deadlock, we have to sleep some time here, or the timer won't advance and we will only do iprobe simcalls
// (especially when used as a break condition, such as while(MPI_Iprobe(...)) ... )
MPI_Request req = static_cast<MPI_Request>(sync_comm->src_data);
*flag = 1;
if(status != MPI_STATUS_IGNORE && (req->flags & PREPARED) == 0) {
- status->MPI_SOURCE = smpi_group_rank(smpi_comm_group(comm), req->src);
+ status->MPI_SOURCE = smpi_comm_group(comm)->rank(req->src);
status->MPI_TAG = req->tag;
status->MPI_ERROR = MPI_SUCCESS;
status->count = req->real_size;
#include <xbt/ex.hpp>
#include <simgrid/s4u/host.hpp>
+#include <src/smpi/smpi_group.hpp>
#include "private.h"
#include "smpi_mpi_dt_private.h"
if(smpi_privatize_global_variables){ //we need to switch as the called function may silently touch global variables
smpi_switch_data_segment(smpi_process_index());
}
- MPI_Group cp=smpi_group_copy(smpi_comm_group(comm));
+ MPI_Group cp=new simgrid::SMPI::Group(smpi_comm_group(comm));
(*newcomm) = smpi_comm_new(cp, smpi_comm_topo(comm));
int ret = MPI_SUCCESS;
{
if (comm == MPI_COMM_UNINITIALIZED)
comm = smpi_process_comm_world();
- return smpi_group_size(smpi_comm_group(comm));
+ return smpi_comm_group(comm)->getsize();
}
int smpi_comm_rank(MPI_Comm comm)
{
if (comm == MPI_COMM_UNINITIALIZED)
comm = smpi_process_comm_world();
- return smpi_group_rank(smpi_comm_group(comm), smpi_process_index());
+ return smpi_comm_group(comm)->rank(smpi_process_index());
}
void smpi_comm_get_name (MPI_Comm comm, char* name, int* len)
rankmap[2 * count + 1] = recvbuf[2 * i + 1];
count++;
qsort(rankmap, count, 2 * sizeof(int), &smpi_compare_rankmap);
- group_out = smpi_group_new(count);
+ group_out = new simgrid::SMPI::Group(count);
if (i == 0) {
group_root = group_out; /* Save root's group */
}
for (int j = 0; j < count; j++) {
- int index = smpi_group_index(group, rankmap[2 * j]);
- smpi_group_set_mapping(group_out, index, j);
+ int index = group->index(rankmap[2 * j]);
+ group_out->set_mapping(index, j);
}
MPI_Request* requests = xbt_new(MPI_Request, count);
int reqs = 0;
for (int j = 0; j < count; j++) {
if(rankmap[2 * j] != 0) {
- group_snd[reqs]=smpi_group_copy(group_out);
+ group_snd[reqs]=new simgrid::SMPI::Group(group_out);
requests[reqs] = smpi_mpi_isend(&(group_snd[reqs]), 1, MPI_PTR, rankmap[2 * j], system_tag, comm);
reqs++;
}
}
if(i != 0) {
- smpi_group_destroy(group_out);
+ group_out->destroy();
}
smpi_mpi_waitall(reqs, requests, MPI_STATUS_IGNORE);
xbt_free(requests);
void smpi_comm_use(MPI_Comm comm){
if (comm == MPI_COMM_UNINITIALIZED)
comm = smpi_process_comm_world();
- smpi_group_use(comm->group);
+ comm->group->use();
comm->refcount++;
}
if (comm == MPI_COMM_UNINITIALIZED)
comm = smpi_process_comm_world();
comm->refcount--;
- smpi_group_unuse(comm->group);
+ comm->group->unuse();
if(comm->refcount==0){
smpi_comm_cleanup_smp(comm);
xbt_swag_foreach(process, process_list) {
int index = process->pid -1;
- if(smpi_group_rank(smpi_comm_group(comm), index)!=MPI_UNDEFINED){
+ if(smpi_comm_group(comm)->rank(index)!=MPI_UNDEFINED){
intra_comm_size++;
//the process is in the comm
if(index < min_index)
}
}
XBT_DEBUG("number of processes deployed on my node : %d", intra_comm_size);
- MPI_Group group_intra = smpi_group_new(intra_comm_size);
+ MPI_Group group_intra = new simgrid::SMPI::Group(intra_comm_size);
i=0;
process = nullptr;
xbt_swag_foreach(process, process_list) {
int index = process->pid -1;
- if(smpi_group_rank(smpi_comm_group(comm), index)!=MPI_UNDEFINED){
- smpi_group_set_mapping(group_intra, index, i);
+ if(smpi_comm_group(comm)->rank(index)!=MPI_UNDEFINED){
+ group_intra->set_mapping(index, i);
i++;
}
}
}
qsort(leader_list, leader_group_size, sizeof(int),compare_ints);
- MPI_Group leaders_group = smpi_group_new(leader_group_size);
+ MPI_Group leaders_group = new simgrid::SMPI::Group(leader_group_size);
MPI_Comm leader_comm = MPI_COMM_NULL;
if(MPI_COMM_WORLD!=MPI_COMM_UNINITIALIZED && comm!=MPI_COMM_WORLD){
//create leader_communicator
for (i=0; i< leader_group_size;i++)
- smpi_group_set_mapping(leaders_group, leader_list[i], i);
+ leaders_group->set_mapping(leader_list[i], i);
leader_comm = smpi_comm_new(leaders_group, nullptr);
smpi_comm_set_leaders_comm(comm, leader_comm);
smpi_comm_set_intra_comm(comm, comm_intra);
//create intracommunicator
}else{
for (i=0; i< leader_group_size;i++)
- smpi_group_set_mapping(leaders_group, leader_list[i], i);
+ leaders_group->set_mapping(leader_list[i], i);
if(smpi_comm_get_leaders_comm(comm)==MPI_COMM_NULL){
leader_comm = smpi_comm_new(leaders_group, nullptr);
smpi_comm_set_leaders_comm(comm, leader_comm);
}else{
leader_comm=smpi_comm_get_leaders_comm(comm);
- smpi_group_unuse(leaders_group);
+ leaders_group->unuse();
}
smpi_process_set_comm_intra(comm_intra);
}
}
// Are the ranks blocked ? = allocated contiguously on the SMP nodes
int is_blocked=1;
- int prev=smpi_group_rank(smpi_comm_group(comm), smpi_group_index(smpi_comm_group(comm_intra), 0));
+ int prev=smpi_comm_group(comm)->rank(smpi_comm_group(comm_intra)->index(0));
for (i=1; i<my_local_size; i++){
- int that=smpi_group_rank(smpi_comm_group(comm),smpi_group_index(smpi_comm_group(comm_intra), i));
+ int that=smpi_comm_group(comm)->rank(smpi_comm_group(comm_intra)->index(i));
if(that!=prev+1){
is_blocked=0;
break;
#include "xbt/dict.h"
#include "xbt/log.h"
#include "xbt/sysdep.h"
+#include <src/smpi/smpi_group.hpp>
static xbt_dict_t smpi_instances = nullptr;
extern int process_count;
xbt_assert(instance, "Error, unknown instance %s", instance_id);
if(instance->comm_world == MPI_COMM_NULL){
- MPI_Group group = smpi_group_new(instance->size);
+ MPI_Group group = new simgrid::SMPI::Group(instance->size);
instance->comm_world = smpi_comm_new(group, nullptr);
}
instance->present_processes++;
index_to_process_data[index]=instance->index+rank;
- smpi_group_set_mapping(smpi_comm_group(instance->comm_world), index, rank);
+ smpi_comm_group(instance->comm_world)->set_mapping(index, rank);
*bar = instance->finalization_barrier;
*comm = &instance->comm_world;
}
char *name = nullptr;
xbt_dict_foreach(smpi_instances, cursor, name, instance) {
if(instance->comm_world!=MPI_COMM_NULL)
- while (smpi_group_unuse(smpi_comm_group(instance->comm_world)) > 0);
+ while (smpi_comm_group(instance->comm_world)->unuse() > 0);
xbt_free(instance->comm_world);
MSG_barrier_destroy(instance->finalization_barrier);
}
#include "src/mc/mc_replay.h"
#include "src/msg/msg_private.h"
#include "src/simix/smx_private.h"
+#include "src/smpi/smpi_group.hpp"
#include "surf/surf.h"
#include "xbt/replay.h"
{
smpi_process_data_t data = smpi_process_data();
if(data->comm_self==MPI_COMM_NULL){
- MPI_Group group = smpi_group_new(1);
+ MPI_Group group = new simgrid::SMPI::Group(1);
data->comm_self = smpi_comm_new(group, nullptr);
- smpi_group_set_mapping(group, smpi_process_index(), 0);
+ group->set_mapping(smpi_process_index(), 0);
}
return data->comm_self;
//if the process was launched through smpirun script we generate a global mpi_comm_world
//if not, we let MPI_COMM_NULL, and the comm world will be private to each mpi instance
if(smpirun){
- group = smpi_group_new(process_count);
+ group = new simgrid::SMPI::Group(process_count);
MPI_COMM_WORLD = smpi_comm_new(group, nullptr);
MPI_Attr_put(MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, reinterpret_cast<void *>(process_count));
msg_bar_t bar = MSG_barrier_init(process_count);
for (i = 0; i < process_count; i++) {
- smpi_group_set_mapping(group, i, i);
+ group->set_mapping(i, i);
process_data[i]->finalization_barrier = bar;
}
}
smpi_bench_destroy();
if (MPI_COMM_WORLD != MPI_COMM_UNINITIALIZED){
- while (smpi_group_unuse(smpi_comm_group(MPI_COMM_WORLD)) > 0);
+ while (smpi_comm_group(MPI_COMM_WORLD)->unuse() > 0);
MSG_barrier_destroy(process_data[0]->finalization_barrier);
}else{
smpi_deployment_cleanup_instances();
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "private.h"
+#include "smpi_group.hpp"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_group, smpi, "Logging specific to SMPI (group)");
+simgrid::SMPI::Group mpi_MPI_GROUP_EMPTY;
+MPI_Group MPI_GROUP_EMPTY=&mpi_MPI_GROUP_EMPTY;
-typedef struct s_smpi_mpi_group {
- int size;
- int *rank_to_index_map;
- xbt_dict_t index_to_rank_map;
- int refcount;
-} s_smpi_mpi_group_t;
+namespace simgrid{
+namespace SMPI{
-static s_smpi_mpi_group_t mpi_MPI_GROUP_EMPTY = {
- 0, /* size */
- nullptr, /* rank_to_index_map */
- nullptr, /* index_to_rank_map */
- 1, /* refcount: start > 0 so that this group never gets freed */
-};
-
-MPI_Group MPI_GROUP_EMPTY = &mpi_MPI_GROUP_EMPTY;
+Group::Group()
+{
+ m_size=0; /* size */
+ m_rank_to_index_map=nullptr; /* m_rank_to_index_map */
+ m_index_to_rank_map=nullptr; /* m_index_to_rank_map */
+ m_refcount=1; /* m_refcount: start > 0 so that this group never gets freed */
+}
-MPI_Group smpi_group_new(int size)
+Group::Group(int n)
{
- MPI_Group group;
int i;
- group = xbt_new(s_smpi_mpi_group_t, 1);
- group->size = size;
- group->rank_to_index_map = xbt_new(int, size);
- group->index_to_rank_map = xbt_dict_new_homogeneous(xbt_free_f);
- group->refcount = 1;
- for (i = 0; i < size; i++) {
- group->rank_to_index_map[i] = MPI_UNDEFINED;
+ m_size = n;
+ m_rank_to_index_map = xbt_new(int, m_size);
+ m_index_to_rank_map = xbt_dict_new_homogeneous(xbt_free_f);
+ m_refcount = 1;
+ for (i = 0; i < m_size; i++) {
+ m_rank_to_index_map[i] = MPI_UNDEFINED;
}
-
- return group;
}
-MPI_Group smpi_group_copy(MPI_Group origin)
+Group::Group(MPI_Group origin)
{
- MPI_Group group=origin;
char *key;
char *ptr_rank;
xbt_dict_cursor_t cursor = nullptr;
if(origin != MPI_GROUP_NULL
&& origin != MPI_GROUP_EMPTY)
{
- group = xbt_new(s_smpi_mpi_group_t, 1);
- group->size = origin->size;
- group->rank_to_index_map = xbt_new(int, group->size);
- group->index_to_rank_map = xbt_dict_new_homogeneous(xbt_free_f);
- group->refcount = 1;
- for (i = 0; i < group->size; i++) {
- group->rank_to_index_map[i] = origin->rank_to_index_map[i];
+ m_size = origin->getsize();
+ m_rank_to_index_map = xbt_new(int, m_size);
+ m_index_to_rank_map = xbt_dict_new_homogeneous(xbt_free_f);
+ m_refcount = 1;
+ for (i = 0; i < m_size; i++) {
+ m_rank_to_index_map[i] = origin->m_rank_to_index_map[i];
}
- xbt_dict_foreach(origin->index_to_rank_map, cursor, key, ptr_rank) {
+ xbt_dict_foreach(origin->m_index_to_rank_map, cursor, key, ptr_rank) {
int * cp = static_cast<int*>(xbt_malloc(sizeof(int)));
*cp=*reinterpret_cast<int*>(ptr_rank);
- xbt_dict_set(group->index_to_rank_map, key, cp, nullptr);
+ xbt_dict_set(m_index_to_rank_map, key, cp, nullptr);
}
}
+}
- return group;
+Group::~Group()
+{
+ xbt_free(m_rank_to_index_map);
+ xbt_dict_free(&m_index_to_rank_map);
}
-void smpi_group_destroy(MPI_Group group)
+void Group::destroy()
{
- if(group!= smpi_comm_group(MPI_COMM_WORLD)
- && group != MPI_GROUP_NULL
- && group != MPI_GROUP_EMPTY)
- smpi_group_unuse(group);
+ if(this != smpi_comm_group(MPI_COMM_WORLD)
+ && this != MPI_GROUP_NULL
+ && this != MPI_GROUP_EMPTY)
+ this->unuse();
}
-void smpi_group_set_mapping(MPI_Group group, int index, int rank)
+void Group::set_mapping(int index, int rank)
{
int * val_rank;
- if (rank < group->size) {
- group->rank_to_index_map[rank] = index;
+ if (rank < m_size) {
+ m_rank_to_index_map[rank] = index;
if (index!=MPI_UNDEFINED ) {
val_rank = static_cast<int *>(xbt_malloc(sizeof(int)));
*val_rank = rank;
char * key = bprintf("%d", index);
- xbt_dict_set(group->index_to_rank_map, key, val_rank, nullptr);
+ xbt_dict_set(m_index_to_rank_map, key, val_rank, nullptr);
xbt_free(key);
}
}
}
-int smpi_group_index(MPI_Group group, int rank)
+int Group::index(int rank)
{
int index = MPI_UNDEFINED;
- if (0 <= rank && rank < group->size) {
- index = group->rank_to_index_map[rank];
+ if (0 <= rank && rank < m_size) {
+ index = m_rank_to_index_map[rank];
}
return index;
}
-int smpi_group_rank(MPI_Group group, int index)
+int Group::rank(int index)
{
int * ptr_rank = nullptr;
- if (group==MPI_GROUP_EMPTY)
+ if (this==MPI_GROUP_EMPTY)
return MPI_UNDEFINED;
char * key = bprintf("%d", index);
- ptr_rank = static_cast<int*>(xbt_dict_get_or_null(group->index_to_rank_map, key));
+ ptr_rank = static_cast<int*>(xbt_dict_get_or_null(m_index_to_rank_map, key));
xbt_free(key);
if (ptr_rank==nullptr)
return *ptr_rank;
}
-int smpi_group_use(MPI_Group group)
+int Group::use()
{
- group->refcount++;
- return group->refcount;
+ m_refcount++;
+ return m_refcount;
}
-int smpi_group_unuse(MPI_Group group)
+int Group::unuse()
{
- group->refcount--;
- if (group->refcount <= 0) {
- xbt_free(group->rank_to_index_map);
- xbt_dict_free(&group->index_to_rank_map);
- xbt_free(group);
+ m_refcount--;
+ if (m_refcount <= 0) {
+ delete this;
return 0;
}
- return group->refcount;
+ return m_refcount;
}
-int smpi_group_size(MPI_Group group)
+int Group::getsize()
{
- return group->size;
+ return m_size;
}
-int smpi_group_compare(MPI_Group group1, MPI_Group group2)
+int Group::compare(MPI_Group group2)
{
int result;
- int i, index, rank, size;
+ int i, index, rank, sz;
result = MPI_IDENT;
- if (smpi_group_size(group1) != smpi_group_size(group2)) {
+ if (m_size != group2->getsize()) {
result = MPI_UNEQUAL;
} else {
- size = smpi_group_size(group2);
- for (i = 0; i < size; i++) {
- index = smpi_group_index(group1, i);
- rank = smpi_group_rank(group2, index);
+ sz = group2->getsize();
+ for (i = 0; i < sz; i++) {
+ index = this->index(i);
+ rank = group2->rank(index);
if (rank == MPI_UNDEFINED) {
result = MPI_UNEQUAL;
break;
return result;
}
-int smpi_group_incl(MPI_Group group, int n, int* ranks, MPI_Group* newgroup)
+int Group::incl(int n, int* ranks, MPI_Group* newgroup)
{
int i=0, index=0;
if (n == 0) {
*newgroup = MPI_GROUP_EMPTY;
- } else if (n == smpi_group_size(group)) {
- *newgroup = group;
- if(group!= smpi_comm_group(MPI_COMM_WORLD)
- && group != MPI_GROUP_NULL
- && group != smpi_comm_group(MPI_COMM_SELF)
- && group != MPI_GROUP_EMPTY)
- smpi_group_use(group);
+ } else if (n == m_size) {
+ *newgroup = this;
+ if(this!= smpi_comm_group(MPI_COMM_WORLD)
+ && this != MPI_GROUP_NULL
+ && this != smpi_comm_group(MPI_COMM_SELF)
+ && this != MPI_GROUP_EMPTY)
+ this->use();
} else {
- *newgroup = smpi_group_new(n);
+ *newgroup = new Group(n);
for (i = 0; i < n; i++) {
- index = smpi_group_index(group, ranks[i]);
- smpi_group_set_mapping(*newgroup, index, i);
+ index = this->index(ranks[i]);
+ (*newgroup)->set_mapping(index, i);
+ }
+ }
+ return MPI_SUCCESS;
+}
+
+int Group::group_union(MPI_Group group2, MPI_Group* newgroup)
+{
+ int size1 = m_size;
+ int size2 = group2->getsize();
+ for (int i = 0; i < size2; i++) {
+ int proc2 = group2->index(i);
+ int proc1 = this->rank(proc2);
+ if (proc1 == MPI_UNDEFINED) {
+ size1++;
+ }
+ }
+ if (size1 == 0) {
+ *newgroup = MPI_GROUP_EMPTY;
+ } else {
+ *newgroup = new simgrid::SMPI::Group(size1);
+ size2 = this->getsize();
+ for (int i = 0; i < size2; i++) {
+ int proc1 = this->index(i);
+ (*newgroup)->set_mapping(proc1, i);
+ }
+ for (int i = size2; i < size1; i++) {
+ int proc2 = group2->index(i - size2);
+ (*newgroup)->set_mapping(proc2, i);
+ }
+ }
+ return MPI_SUCCESS;
+}
+
+int Group::intersection(MPI_Group group2, MPI_Group* newgroup)
+{
+ int size2 = group2->getsize();
+ for (int i = 0; i < size2; i++) {
+ int proc2 = group2->index(i);
+ int proc1 = this->rank(proc2);
+ if (proc1 == MPI_UNDEFINED) {
+ size2--;
+ }
+ }
+ if (size2 == 0) {
+ *newgroup = MPI_GROUP_EMPTY;
+ } else {
+ *newgroup = new simgrid::SMPI::Group(size2);
+ int j=0;
+ for (int i = 0; i < group2->getsize(); i++) {
+ int proc2 = group2->index(i);
+ int proc1 = this->rank(proc2);
+ if (proc1 != MPI_UNDEFINED) {
+ (*newgroup)->set_mapping(proc2, j);
+ j++;
+ }
}
}
return MPI_SUCCESS;
}
+
+int Group::difference(MPI_Group group2, MPI_Group* newgroup)
+{
+ int newsize = m_size;
+ int size2 = m_size;
+ for (int i = 0; i < size2; i++) {
+ int proc1 = this->index(i);
+ int proc2 = group2->rank(proc1);
+ if (proc2 != MPI_UNDEFINED) {
+ newsize--;
+ }
+ }
+ if (newsize == 0) {
+ *newgroup = MPI_GROUP_EMPTY;
+ } else {
+ *newgroup = new simgrid::SMPI::Group(newsize);
+ for (int i = 0; i < size2; i++) {
+ int proc1 = this->index(i);
+ int proc2 = group2->rank(proc1);
+ if (proc2 == MPI_UNDEFINED) {
+ (*newgroup)->set_mapping(proc1, i);
+ }
+ }
+ }
+ return MPI_SUCCESS;
+}
+
+int Group::excl(int n, int *ranks, MPI_Group * newgroup){
+ int oldsize = m_size;
+ int newsize = oldsize - n;
+ *newgroup = new simgrid::SMPI::Group(newsize);
+ int* to_exclude=xbt_new0(int, m_size);
+ for (int i = 0; i < oldsize; i++)
+ to_exclude[i]=0;
+ for (int i = 0; i < n; i++)
+ to_exclude[ranks[i]]=1;
+ int j = 0;
+ for (int i = 0; i < oldsize; i++) {
+ if(to_exclude[i]==0){
+ int index = this->index(i);
+ (*newgroup)->set_mapping(index, j);
+ j++;
+ }
+ }
+ xbt_free(to_exclude);
+ return MPI_SUCCESS;
+
+}
+
+int Group::range_incl(int n, int ranges[][3], MPI_Group * newgroup){
+ int newsize = 0;
+ for (int i = 0; i < n; i++) {
+ for (int rank = ranges[i][0]; /* First */
+ rank >= 0 && rank < m_size; /* Last */
+ ) {
+ newsize++;
+ if(rank == ranges[i][1]){/*already last ?*/
+ break;
+ }
+ rank += ranges[i][2]; /* Stride */
+ if (ranges[i][0] < ranges[i][1]) {
+ if (rank > ranges[i][1])
+ break;
+ } else {
+ if (rank < ranges[i][1])
+ break;
+ }
+ }
+ }
+ *newgroup = new simgrid::SMPI::Group(newsize);
+ int j = 0;
+ for (int i = 0; i < n; i++) {
+ for (int rank = ranges[i][0]; /* First */
+ rank >= 0 && rank < m_size; /* Last */
+ ) {
+ int index = this->index(rank);
+ (*newgroup)->set_mapping(index, j);
+ j++;
+ if(rank == ranges[i][1]){/*already last ?*/
+ break;
+ }
+ rank += ranges[i][2]; /* Stride */
+ if (ranges[i][0] < ranges[i][1]) {
+ if (rank > ranges[i][1])
+ break;
+ } else {
+ if (rank < ranges[i][1])
+ break;
+ }
+ }
+ }
+ return MPI_SUCCESS;
+}
+
+int Group::range_excl(int n, int ranges[][3], MPI_Group * newgroup){
+ int newsize = m_size;
+ for (int i = 0; i < n; i++) {
+ for (int rank = ranges[i][0]; /* First */
+ rank >= 0 && rank < m_size; /* Last */
+ ) {
+ newsize--;
+ if(rank == ranges[i][1]){/*already last ?*/
+ break;
+ }
+ rank += ranges[i][2]; /* Stride */
+ if (ranges[i][0] < ranges[i][1]) {
+ if (rank > ranges[i][1])
+ break;
+ } else {
+ if (rank < ranges[i][1])
+ break;
+ }
+ }
+ }
+ if (newsize == 0) {
+ *newgroup = MPI_GROUP_EMPTY;
+ } else {
+ *newgroup = new simgrid::SMPI::Group(newsize);
+ int newrank = 0;
+ int oldrank = 0;
+ while (newrank < newsize) {
+ int add = 1;
+ for (int i = 0; i < n; i++) {
+ for (int rank = ranges[i][0]; rank >= 0 && rank < m_size;) {
+ if(rank==oldrank){
+ add = 0;
+ break;
+ }
+ if(rank == ranges[i][1]){/*already last ?*/
+ break;
+ }
+ rank += ranges[i][2]; /* Stride */
+ if (ranges[i][0]<ranges[i][1]){
+ if (rank > ranges[i][1])
+ break;
+ }else{
+ if (rank < ranges[i][1])
+ break;
+ }
+ }
+ }
+ if(add==1){
+ int index = this->index(oldrank);
+ (*newgroup)->set_mapping(index, newrank);
+ newrank++;
+ }
+ oldrank++;
+ }
+ }
+ return MPI_SUCCESS;
+}
+
+}
+}
--- /dev/null
+/* Copyright (c) 2010, 2013-2015. The SimGrid Team.
+ * All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "private.h"
+
+namespace simgrid{
+namespace SMPI{
+
+class Group {
+ private:
+ int m_size;
+ int *m_rank_to_index_map;
+ xbt_dict_t m_index_to_rank_map;
+ int m_refcount;
+ public:
+
+ Group();
+ Group(int size);
+ Group(Group* origin);
+ ~Group();
+
+ void destroy();
+ void set_mapping(int index, int rank);
+ int index(int rank);
+ int rank(int index);
+ int use();
+ int unuse();
+ int getsize();
+ int compare(MPI_Group group2);
+ int incl(int n, int* ranks, MPI_Group* newgroup);
+ int excl(int n, int *ranks, MPI_Group * newgroup);
+ int group_union(MPI_Group group2, MPI_Group* newgroup);
+ int intersection(MPI_Group group2, MPI_Group* newgroup);
+ int difference(MPI_Group group2, MPI_Group* newgroup);
+ int range_incl(int n, int ranges[][3], MPI_Group * newgroup);
+ int range_excl(int n, int ranges[][3], MPI_Group * newgroup);
+};
+}
+}
* under the terms of the license (GNU LGPL) which comes with this package. */
#include <simgrid/s4u/host.hpp>
+#include <src/smpi/smpi_group.hpp>
#include <xbt/ex.hpp>
#include "private.h"
if (group == nullptr) {
return MPI_ERR_ARG;
} else {
- smpi_group_destroy(*group);
+ (*group)->destroy();
*group = MPI_GROUP_NULL;
return MPI_SUCCESS;
}
} else if (size == nullptr) {
return MPI_ERR_ARG;
} else {
- *size = smpi_group_size(group);
+ *size = group->getsize();
return MPI_SUCCESS;
}
}
} else if (rank == nullptr) {
return MPI_ERR_ARG;
} else {
- *rank = smpi_group_rank(group, smpi_process_index());
+ *rank = group->rank(smpi_process_index());
return MPI_SUCCESS;
}
}
if(ranks1[i]==MPI_PROC_NULL){
ranks2[i]=MPI_PROC_NULL;
}else{
- int index = smpi_group_index(group1, ranks1[i]);
- ranks2[i] = smpi_group_rank(group2, index);
+ int index = group1->index(ranks1[i]);
+ ranks2[i] = group2->rank(index);
}
}
return MPI_SUCCESS;
} else if (result == nullptr) {
return MPI_ERR_ARG;
} else {
- *result = smpi_group_compare(group1, group2);
+ *result = group1->compare(group2);
return MPI_SUCCESS;
}
}
} else if (newgroup == nullptr) {
return MPI_ERR_ARG;
} else {
- int size = smpi_group_size(group1);
- int size2 = smpi_group_size(group2);
- for (int i = 0; i < size2; i++) {
- int proc2 = smpi_group_index(group2, i);
- int proc1 = smpi_group_rank(group1, proc2);
- if (proc1 == MPI_UNDEFINED) {
- size++;
- }
- }
- if (size == 0) {
- *newgroup = MPI_GROUP_EMPTY;
- } else {
- *newgroup = smpi_group_new(size);
- size2 = smpi_group_size(group1);
- for (int i = 0; i < size2; i++) {
- int proc1 = smpi_group_index(group1, i);
- smpi_group_set_mapping(*newgroup, proc1, i);
- }
- for (int i = size2; i < size; i++) {
- int proc2 = smpi_group_index(group2, i - size2);
- smpi_group_set_mapping(*newgroup, proc2, i);
- }
- }
- return MPI_SUCCESS;
+ return group1->group_union(group2, newgroup);
}
}
} else if (newgroup == nullptr) {
return MPI_ERR_ARG;
} else {
- int size = smpi_group_size(group2);
- for (int i = 0; i < size; i++) {
- int proc2 = smpi_group_index(group2, i);
- int proc1 = smpi_group_rank(group1, proc2);
- if (proc1 == MPI_UNDEFINED) {
- size--;
- }
- }
- if (size == 0) {
- *newgroup = MPI_GROUP_EMPTY;
- } else {
- *newgroup = smpi_group_new(size);
- int j=0;
- for (int i = 0; i < smpi_group_size(group2); i++) {
- int proc2 = smpi_group_index(group2, i);
- int proc1 = smpi_group_rank(group1, proc2);
- if (proc1 != MPI_UNDEFINED) {
- smpi_group_set_mapping(*newgroup, proc2, j);
- j++;
- }
- }
- }
- return MPI_SUCCESS;
+ return group1->intersection(group2,newgroup);
}
}
} else if (newgroup == nullptr) {
return MPI_ERR_ARG;
} else {
- int size = smpi_group_size(group1);
- int size2 = size;
- for (int i = 0; i < size2; i++) {
- int proc1 = smpi_group_index(group1, i);
- int proc2 = smpi_group_rank(group2, proc1);
- if (proc2 != MPI_UNDEFINED) {
- size--;
- }
- }
- if (size == 0) {
- *newgroup = MPI_GROUP_EMPTY;
- } else {
- *newgroup = smpi_group_new(size);
- for (int i = 0; i < size2; i++) {
- int proc1 = smpi_group_index(group1, i);
- int proc2 = smpi_group_rank(group2, proc1);
- if (proc2 == MPI_UNDEFINED) {
- smpi_group_set_mapping(*newgroup, proc1, i);
- }
- }
- }
- return MPI_SUCCESS;
+ return group1->difference(group2,newgroup);
}
}
} else if (newgroup == nullptr) {
return MPI_ERR_ARG;
} else {
- return smpi_group_incl(group, n, ranks, newgroup);
+ return group->incl(n, ranks, newgroup);
}
}
*newgroup = group;
if (group != smpi_comm_group(MPI_COMM_WORLD)
&& group != smpi_comm_group(MPI_COMM_SELF) && group != MPI_GROUP_EMPTY)
- smpi_group_use(group);
- } else if (n == smpi_group_size(group)) {
+ group->use();
+ return MPI_SUCCESS;
+ } else if (n == group->getsize()) {
*newgroup = MPI_GROUP_EMPTY;
+ return MPI_SUCCESS;
} else {
- int oldsize = smpi_group_size(group);
- int newsize = oldsize - n;
- *newgroup = smpi_group_new(newsize);
-
- int* to_exclude=xbt_new0(int, smpi_group_size(group));
- for (int i = 0; i < oldsize; i++)
- to_exclude[i]=0;
- for (int i = 0; i < n; i++)
- to_exclude[ranks[i]]=1;
-
- int j = 0;
- for (int i = 0; i < oldsize; i++) {
- if(to_exclude[i]==0){
- int index = smpi_group_index(group, i);
- smpi_group_set_mapping(*newgroup, index, j);
- j++;
- }
- }
-
- xbt_free(to_exclude);
+ return group->excl(n,ranks,newgroup);
}
- return MPI_SUCCESS;
}
}
} else {
if (n == 0) {
*newgroup = MPI_GROUP_EMPTY;
+ return MPI_SUCCESS;
} else {
- int size = 0;
- for (int i = 0; i < n; i++) {
- for (int rank = ranges[i][0]; /* First */
- rank >= 0 && rank < smpi_group_size(group); /* Last */
- ) {
- size++;
- if(rank == ranges[i][1]){/*already last ?*/
- break;
- }
- rank += ranges[i][2]; /* Stride */
- if (ranges[i][0] < ranges[i][1]) {
- if (rank > ranges[i][1])
- break;
- } else {
- if (rank < ranges[i][1])
- break;
- }
- }
- }
-
- *newgroup = smpi_group_new(size);
- int j = 0;
- for (int i = 0; i < n; i++) {
- for (int rank = ranges[i][0]; /* First */
- rank >= 0 && rank < smpi_group_size(group); /* Last */
- ) {
- int index = smpi_group_index(group, rank);
- smpi_group_set_mapping(*newgroup, index, j);
- j++;
- if(rank == ranges[i][1]){/*already last ?*/
- break;
- }
- rank += ranges[i][2]; /* Stride */
- if (ranges[i][0] < ranges[i][1]) {
- if (rank > ranges[i][1])
- break;
- } else {
- if (rank < ranges[i][1])
- break;
- }
- }
- }
+ return group->range_incl(n,ranges,newgroup);
}
- return MPI_SUCCESS;
}
}
*newgroup = group;
if (group != smpi_comm_group(MPI_COMM_WORLD) && group != smpi_comm_group(MPI_COMM_SELF) &&
group != MPI_GROUP_EMPTY)
- smpi_group_use(group);
+ group->use();
+ return MPI_SUCCESS;
} else {
- int size = smpi_group_size(group);
- for (int i = 0; i < n; i++) {
- for (int rank = ranges[i][0]; /* First */
- rank >= 0 && rank < smpi_group_size(group); /* Last */
- ) {
- size--;
- if(rank == ranges[i][1]){/*already last ?*/
- break;
- }
- rank += ranges[i][2]; /* Stride */
- if (ranges[i][0] < ranges[i][1]) {
- if (rank > ranges[i][1])
- break;
- } else {
- if (rank < ranges[i][1])
- break;
- }
- }
- }
- if (size == 0) {
- *newgroup = MPI_GROUP_EMPTY;
- } else {
- *newgroup = smpi_group_new(size);
- int newrank = 0;
- int oldrank = 0;
- while (newrank < size) {
- int add = 1;
- for (int i = 0; i < n; i++) {
- for (int rank = ranges[i][0]; rank >= 0 && rank < smpi_group_size(group);) {
- if(rank==oldrank){
- add = 0;
- break;
- }
- if(rank == ranges[i][1]){/*already last ?*/
- break;
- }
- rank += ranges[i][2]; /* Stride */
- if (ranges[i][0]<ranges[i][1]){
- if (rank > ranges[i][1])
- break;
- }else{
- if (rank < ranges[i][1])
- break;
- }
- }
- }
- if(add==1){
- int index = smpi_group_index(group, oldrank);
- smpi_group_set_mapping(*newgroup, index, newrank);
- newrank++;
- }
- oldrank++;
- }
- }
+ return group->range_excl(n,ranges,newgroup);
}
- return MPI_SUCCESS;
}
}
} else {
*group = smpi_comm_group(comm);
if (*group != smpi_comm_group(MPI_COMM_WORLD) && *group != MPI_GROUP_NULL && *group != MPI_GROUP_EMPTY)
- smpi_group_use(*group);
+ (*group)->use();
return MPI_SUCCESS;
}
}
if (comm1 == comm2) { /* Same communicators means same groups */
*result = MPI_IDENT;
} else {
- *result = smpi_group_compare(smpi_comm_group(comm1), smpi_comm_group(comm2));
+ *result = smpi_comm_group(comm1)->compare(smpi_comm_group(comm2));
if (*result == MPI_IDENT) {
*result = MPI_CONGRUENT;
}
return MPI_ERR_GROUP;
} else if (newcomm == nullptr) {
return MPI_ERR_ARG;
- } else if(smpi_group_rank(group,smpi_process_index())==MPI_UNDEFINED){
+ } else if(group->rank(smpi_process_index())==MPI_UNDEFINED){
*newcomm= MPI_COMM_NULL;
return MPI_SUCCESS;
}else{
- smpi_group_use(group);
+ group->use();
*newcomm = smpi_comm_new(group, nullptr);
return MPI_SUCCESS;
}
} else if (src == MPI_PROC_NULL) {
*request = MPI_REQUEST_NULL;
retval = MPI_SUCCESS;
- } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
+ } else if (src!=MPI_ANY_SOURCE && (src >= smpi_comm_group(comm)->getsize() || src <0)){
retval = MPI_ERR_RANK;
} else if ((count < 0) || (buf==nullptr && count > 0)) {
retval = MPI_ERR_COUNT;
} else {
int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
- int src_traced = smpi_group_index(smpi_comm_group(comm), src);
+ int src_traced = smpi_comm_group(comm)->index(src);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
extra->type = TRACING_IRECV;
} else if (dst == MPI_PROC_NULL) {
*request = MPI_REQUEST_NULL;
retval = MPI_SUCCESS;
- } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
+ } else if (dst >= smpi_comm_group(comm)->getsize() || dst <0){
retval = MPI_ERR_RANK;
} else if ((count < 0) || (buf==nullptr && count > 0)) {
retval = MPI_ERR_COUNT;
retval = MPI_ERR_TAG;
} else {
int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
- int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
+ int dst_traced = smpi_comm_group(comm)->index(dst);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
extra->type = TRACING_ISEND;
extra->src = rank;
} else if (dst == MPI_PROC_NULL) {
*request = MPI_REQUEST_NULL;
retval = MPI_SUCCESS;
- } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
+ } else if (dst >= smpi_comm_group(comm)->getsize() || dst <0){
retval = MPI_ERR_RANK;
} else if ((count < 0)|| (buf==nullptr && count > 0)) {
retval = MPI_ERR_COUNT;
retval = MPI_ERR_TAG;
} else {
int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
- int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
+ int dst_traced = smpi_comm_group(comm)->index(dst);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
extra->type = TRACING_ISSEND;
extra->src = rank;
smpi_empty_status(status);
status->MPI_SOURCE = MPI_PROC_NULL;
retval = MPI_SUCCESS;
- } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
+ } else if (src!=MPI_ANY_SOURCE && (src >= smpi_comm_group(comm)->getsize() || src <0)){
retval = MPI_ERR_RANK;
} else if ((count < 0) || (buf==nullptr && count > 0)) {
retval = MPI_ERR_COUNT;
retval = MPI_ERR_TAG;
} else {
int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
- int src_traced = smpi_group_index(smpi_comm_group(comm), src);
+ int src_traced = smpi_comm_group(comm)->index(src);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
extra->type = TRACING_RECV;
extra->src = src_traced;
// the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
if (status != MPI_STATUS_IGNORE) {
- src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
+ src_traced = smpi_comm_group(comm)->index(status->MPI_SOURCE);
if (!TRACE_smpi_view_internals()) {
TRACE_smpi_recv(rank, src_traced, rank, tag);
}
retval = MPI_ERR_COMM;
} else if (dst == MPI_PROC_NULL) {
retval = MPI_SUCCESS;
- } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
+ } else if (dst >= smpi_comm_group(comm)->getsize() || dst <0){
retval = MPI_ERR_RANK;
} else if ((count < 0) || (buf == nullptr && count > 0)) {
retval = MPI_ERR_COUNT;
retval = MPI_ERR_TAG;
} else {
int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
- int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
+ int dst_traced = smpi_comm_group(comm)->index(dst);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
extra->type = TRACING_SEND;
extra->src = rank;
retval = MPI_ERR_COMM;
} else if (dst == MPI_PROC_NULL) {
retval = MPI_SUCCESS;
- } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
+ } else if (dst >= smpi_comm_group(comm)->getsize() || dst <0){
retval = MPI_ERR_RANK;
} else if ((count < 0) || (buf==nullptr && count > 0)) {
retval = MPI_ERR_COUNT;
retval = MPI_ERR_TAG;
} else {
int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
- int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
+ int dst_traced = smpi_comm_group(comm)->index(dst);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
extra->type = TRACING_SSEND;
extra->src = rank;
smpi_empty_status(status);
status->MPI_SOURCE = MPI_PROC_NULL;
retval = MPI_SUCCESS;
- }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
- (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
+ }else if (dst >= smpi_comm_group(comm)->getsize() || dst <0 ||
+ (src!=MPI_ANY_SOURCE && (src >= smpi_comm_group(comm)->getsize() || src <0))){
retval = MPI_ERR_RANK;
} else if ((sendcount < 0 || recvcount<0) ||
(sendbuf==nullptr && sendcount > 0) || (recvbuf==nullptr && recvcount>0)) {
} else {
int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
- int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
- int src_traced = smpi_group_index(smpi_comm_group(comm), src);
+ int dst_traced = smpi_comm_group(comm)->index(dst);
+ int src_traced = smpi_comm_group(comm)->index(src);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
extra->type = TRACING_SENDRECV;
extra->src = src_traced;
if (is_wait_for_receive) {
if(src_traced==MPI_ANY_SOURCE)
src_traced = (status!=MPI_STATUS_IGNORE) ?
- smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
+ smpi_comm_group(comm)->rank(status->MPI_SOURCE) :
src_traced;
TRACE_smpi_recv(rank, src_traced, dst_traced, tag_traced);
}
if (is_wait_for_receive) {
if(savedvals[*index].src==MPI_ANY_SOURCE)
src_traced = (status != MPI_STATUSES_IGNORE)
- ? smpi_group_rank(smpi_comm_group(savedvals[*index].comm), status->MPI_SOURCE)
+ ? smpi_comm_group(savedvals[*index].comm)->rank(status->MPI_SOURCE)
: savedvals[*index].src;
TRACE_smpi_recv(rank_traced, src_traced, dst_traced, savedvals[*index].tag);
}
if (is_wait_for_receive) {
if(src_traced==MPI_ANY_SOURCE)
src_traced = (status!=MPI_STATUSES_IGNORE) ?
- smpi_group_rank(smpi_comm_group(savedvals[i].comm), status[i].MPI_SOURCE) : savedvals[i].src;
+ smpi_comm_group(savedvals[i].comm)->rank(status[i].MPI_SOURCE) : savedvals[i].src;
TRACE_smpi_recv(rank_traced, src_traced, dst_traced,savedvals[i].tag);
}
}
retval = MPI_ERR_ARG;
} else {
int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
- int root_traced = smpi_group_index(smpi_comm_group(comm), root);
+ int root_traced = smpi_comm_group(comm)->index(root);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
extra->type = TRACING_BCAST;
sendtmptype=recvtype;
}
int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
- int root_traced = smpi_group_index(smpi_comm_group(comm), root);
+ int root_traced = smpi_comm_group(comm)->index(root);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
extra->type = TRACING_GATHER;
extra->root = root_traced;
}
int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
- int root_traced = smpi_group_index(smpi_comm_group(comm), root);
+ int root_traced = smpi_comm_group(comm)->index(root);
int i = 0;
int size = smpi_comm_size(comm);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
recvcount = sendcount;
}
int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
- int root_traced = smpi_group_index(smpi_comm_group(comm), root);
+ int root_traced = smpi_comm_group(comm)->index(root);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
extra->type = TRACING_SCATTER;
extra->root = root_traced;
recvcount = sendcounts[smpi_comm_rank(comm)];
}
int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
- int root_traced = smpi_group_index(smpi_comm_group(comm), root);
+ int root_traced = smpi_comm_group(comm)->index(root);
int i = 0;
int size = smpi_comm_size(comm);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
retval = MPI_ERR_ARG;
} else {
int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
- int root_traced = smpi_group_index(smpi_comm_group(comm), root);
+ int root_traced = smpi_comm_group(comm)->index(root);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
extra->type = TRACING_REDUCE;
int known = 0;
return MPI_ERR_WIN;
}else {
smpi_mpi_win_get_group(win, group);
- smpi_group_use(*group);
+ (*group)->use();
return MPI_SUCCESS;
}
}
int rank = smpi_process_index();
MPI_Group group;
smpi_mpi_win_get_group(win, &group);
- int src_traced = smpi_group_index(group, target_rank);
+ int src_traced = group->index(target_rank);
TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
int rank = smpi_process_index();
MPI_Group group;
smpi_mpi_win_get_group(win, &group);
- int dst_traced = smpi_group_index(group, target_rank);
+ int dst_traced = group->index(target_rank);
TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, nullptr);
TRACE_smpi_send(rank, rank, dst_traced, SMPI_RMA_TAG, origin_count*smpi_datatype_size(origin_datatype));
int rank = smpi_process_index();
MPI_Group group;
smpi_mpi_win_get_group(win, &group);
- int src_traced = smpi_group_index(group, target_rank);
+ int src_traced = group->index(target_rank);
TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
#include "private.h"
#include "xbt/replay.h"
+#include "src/smpi/smpi_group.hpp"
#include <unordered_map>
#include <vector>
int rank = smpi_process_index();
- int dst_traced = smpi_group_rank(smpi_comm_group(MPI_COMM_WORLD), to);
+ int dst_traced = smpi_comm_group(MPI_COMM_WORLD)->rank(to);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
extra->type = TRACING_SEND;
extra->send_size = size;
MPI_CURRENT_TYPE= MPI_DEFAULT_TYPE;
int rank = smpi_process_index();
- int dst_traced = smpi_group_rank(smpi_comm_group(MPI_COMM_WORLD), to);
+ int dst_traced = smpi_comm_group(MPI_COMM_WORLD)->rank(to);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
extra->type = TRACING_ISEND;
extra->send_size = size;
MPI_CURRENT_TYPE= MPI_DEFAULT_TYPE;
int rank = smpi_process_index();
- int src_traced = smpi_group_rank(smpi_comm_group(MPI_COMM_WORLD), from);
+ int src_traced = smpi_comm_group(MPI_COMM_WORLD)->rank(from);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
extra->type = TRACING_RECV;
MPI_CURRENT_TYPE= MPI_DEFAULT_TYPE;
int rank = smpi_process_index();
- int src_traced = smpi_group_rank(smpi_comm_group(MPI_COMM_WORLD), from);
+ int src_traced = smpi_comm_group(MPI_COMM_WORLD)->rank(from);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
extra->type = TRACING_IRECV;
extra->send_size = size;
int rank = request->comm != MPI_COMM_NULL ? smpi_comm_rank(request->comm) : -1;
MPI_Group group = smpi_comm_group(request->comm);
- int src_traced = smpi_group_rank(group, request->src);
- int dst_traced = smpi_group_rank(group, request->dst);
+ int src_traced = group->rank(request->src);
+ int dst_traced = group->rank(request->dst);
int is_wait_for_receive = request->recv;
instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
extra->type = TRACING_WAIT;
}
int rank = smpi_process_index();
- int root_traced = smpi_group_index(smpi_comm_group(MPI_COMM_WORLD), root);
+ int root_traced = smpi_comm_group(MPI_COMM_WORLD)->index(root);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
extra->type = TRACING_BCAST;
}
int rank = smpi_process_index();
- int root_traced = smpi_group_rank(smpi_comm_group(MPI_COMM_WORLD), root);
+ int root_traced = smpi_comm_group(MPI_COMM_WORLD)->rank(root);
instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
extra->type = TRACING_REDUCE;
extra->send_size = comm_size;
#include "private.h"
#include <vector>
+#include "src/smpi/smpi_group.hpp"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_rma, smpi, "Logging specific to SMPI (RMA operations)");
if(target_rank != smpi_comm_rank(win->comm)){
//prepare send_request
MPI_Request sreq = smpi_rma_send_init(origin_addr, origin_count, origin_datatype, smpi_process_index(),
- smpi_group_index(smpi_comm_group(win->comm),target_rank), SMPI_RMA_TAG+1, win->comm, MPI_OP_NULL);
+ smpi_comm_group(win->comm)->index(target_rank), SMPI_RMA_TAG+1, win->comm, MPI_OP_NULL);
//prepare receiver request
MPI_Request rreq = smpi_rma_recv_init(recv_addr, target_count, target_datatype, smpi_process_index(),
- smpi_group_index(smpi_comm_group(win->comm),target_rank), SMPI_RMA_TAG+1, recv_win->comm, MPI_OP_NULL);
+ smpi_comm_group(win->comm)->index(target_rank), SMPI_RMA_TAG+1, recv_win->comm, MPI_OP_NULL);
//push request to receiver's win
xbt_mutex_acquire(recv_win->mut);
if(target_rank != smpi_comm_rank(win->comm)){
//prepare send_request
MPI_Request sreq = smpi_rma_send_init(send_addr, target_count, target_datatype,
- smpi_group_index(smpi_comm_group(win->comm),target_rank), smpi_process_index(), SMPI_RMA_TAG+2, send_win->comm,
+ smpi_comm_group(win->comm)->index(target_rank), smpi_process_index(), SMPI_RMA_TAG+2, send_win->comm,
MPI_OP_NULL);
//prepare receiver request
MPI_Request rreq = smpi_rma_recv_init(origin_addr, origin_count, origin_datatype,
- smpi_group_index(smpi_comm_group(win->comm),target_rank), smpi_process_index(), SMPI_RMA_TAG+2, win->comm,
+ smpi_comm_group(win->comm)->index(target_rank), smpi_process_index(), SMPI_RMA_TAG+2, win->comm,
MPI_OP_NULL);
//start the send, with another process than us as sender.
//As the tag will be used for ordering of the operations, add count to it
//prepare send_request
MPI_Request sreq = smpi_rma_send_init(origin_addr, origin_count, origin_datatype,
- smpi_process_index(), smpi_group_index(smpi_comm_group(win->comm),target_rank), SMPI_RMA_TAG+3+win->count, win->comm, op);
+ smpi_process_index(), smpi_comm_group(win->comm)->index(target_rank), SMPI_RMA_TAG+3+win->count, win->comm, op);
//prepare receiver request
MPI_Request rreq = smpi_rma_recv_init(recv_addr, target_count, target_datatype,
- smpi_process_index(), smpi_group_index(smpi_comm_group(win->comm),target_rank), SMPI_RMA_TAG+3+win->count, recv_win->comm, op);
+ smpi_process_index(), smpi_comm_group(win->comm)->index(target_rank), SMPI_RMA_TAG+3+win->count, recv_win->comm, op);
win->count++;
//push request to receiver's win
//naive, blocking implementation.
int i = 0;
int j = 0;
- int size = smpi_group_size(group);
+ int size = group->getsize();
MPI_Request* reqs = xbt_new0(MPI_Request, size);
while (j != size) {
- int src = smpi_group_index(group, j);
+ int src = group->index(j);
if (src != smpi_process_index() && src != MPI_UNDEFINED) {
reqs[i] = smpi_irecv_init(nullptr, 0, MPI_CHAR, src, SMPI_RMA_TAG + 4, MPI_COMM_WORLD);
i++;
xbt_free(reqs);
win->opened++; //we're open for business !
win->group=group;
- smpi_group_use(group);
+ group->use();
return MPI_SUCCESS;
}
//let's make a synchronous send here
int i = 0;
int j = 0;
- int size = smpi_group_size(group);
+ int size = group->getsize();
MPI_Request* reqs = xbt_new0(MPI_Request, size);
while(j!=size){
- int dst=smpi_group_index(group,j);
+ int dst=group->index(j);
if(dst!=smpi_process_index() && dst!=MPI_UNDEFINED){
reqs[i]=smpi_mpi_send_init(nullptr, 0, MPI_CHAR, dst, SMPI_RMA_TAG+4, MPI_COMM_WORLD);
i++;
xbt_free(reqs);
win->opened++; //we're open for business !
win->group=group;
- smpi_group_use(group);
+ group->use();
return MPI_SUCCESS;
}
XBT_DEBUG("Entering MPI_Win_Complete");
int i = 0;
int j = 0;
- int size = smpi_group_size(win->group);
+ int size = win->group->getsize();
MPI_Request* reqs = xbt_new0(MPI_Request, size);
while(j!=size){
- int dst=smpi_group_index(win->group,j);
+ int dst=win->group->index(j);
if(dst!=smpi_process_index() && dst!=MPI_UNDEFINED){
reqs[i]=smpi_mpi_send_init(nullptr, 0, MPI_CHAR, dst, SMPI_RMA_TAG+5, MPI_COMM_WORLD);
i++;
}
xbt_mutex_release(win->mut);
- smpi_group_unuse(win->group);
+ win->group->unuse();
win->opened--; //we're closed for business !
return MPI_SUCCESS;
}
//naive, blocking implementation.
XBT_DEBUG("Entering MPI_Win_Wait");
int i=0,j=0;
- int size = smpi_group_size(win->group);
+ int size = win->group->getsize();
MPI_Request* reqs = xbt_new0(MPI_Request, size);
while(j!=size){
- int src=smpi_group_index(win->group,j);
+ int src=win->group->index(j);
if(src!=smpi_process_index() && src!=MPI_UNDEFINED){
reqs[i]=smpi_irecv_init(nullptr, 0, MPI_CHAR, src,SMPI_RMA_TAG+5, MPI_COMM_WORLD);
i++;
}
xbt_mutex_release(win->mut);
- smpi_group_unuse(win->group);
+ win->group->unuse();
win->opened--; //we're opened for business !
return MPI_SUCCESS;
}
#include "xbt/sysdep.h"
#include "smpi/smpi.h"
+#include "src/smpi/smpi_group.hpp"
#include "private.h"
#include <vector>
#include <math.h>
}
newCart = smpi_cart_topo_create(ndims);
oldGroup = smpi_comm_group(comm_old);
- newGroup = smpi_group_new(newSize);
+ newGroup = new simgrid::SMPI::Group(newSize);
for (int i = 0 ; i < newSize ; i++) {
- smpi_group_set_mapping(newGroup, smpi_group_index(oldGroup, i), i);
+ newGroup->set_mapping(oldGroup->index(i), i);
}
newCart->topo.cart->nnodes = newSize;
} else {
if (rank == 0) {
newCart = smpi_cart_topo_create(ndims);
- *comm_cart = smpi_comm_new(smpi_group_copy(smpi_comm_group(MPI_COMM_SELF)), newCart);
+ *comm_cart = smpi_comm_new(new simgrid::SMPI::Group(smpi_comm_group(MPI_COMM_SELF)), newCart);
} else {
*comm_cart = MPI_COMM_NULL;
}