* 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;
+
+simgrid::smpi::Group mpi_MPI_GROUP_EMPTY;
MPI_Group MPI_GROUP_EMPTY=&mpi_MPI_GROUP_EMPTY;
namespace simgrid{
-namespace SMPI{
+namespace smpi{
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 */
+ size_=0; /* size */
+ rank_to_index_map_=nullptr; /* rank_to_index_map_ */
+ index_to_rank_map_=nullptr; /* index_to_rank_map_ */
+ refcount_=1; /* refcount_: start > 0 so that this group never gets freed */
}
-Group::Group(int n)
+Group::Group(int n) : size_(n)
{
int i;
-
- 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;
+ rank_to_index_map_ = xbt_new(int, size_);
+ index_to_rank_map_ = xbt_dict_new_homogeneous(xbt_free_f);
+ refcount_ = 1;
+ for (i = 0; i < size_; i++) {
+ rank_to_index_map_[i] = MPI_UNDEFINED;
}
}
if(origin != MPI_GROUP_NULL
&& origin != MPI_GROUP_EMPTY)
{
- m_size = origin->size();
- 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];
+ size_ = origin->size();
+ rank_to_index_map_ = xbt_new(int, size_);
+ index_to_rank_map_ = xbt_dict_new_homogeneous(xbt_free_f);
+ refcount_ = 1;
+ for (i = 0; i < size_; i++) {
+ rank_to_index_map_[i] = origin->rank_to_index_map_[i];
}
- xbt_dict_foreach(origin->m_index_to_rank_map, cursor, key, ptr_rank) {
+ xbt_dict_foreach(origin->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(m_index_to_rank_map, key, cp, nullptr);
+ xbt_dict_set(index_to_rank_map_, key, cp, nullptr);
}
}
}
Group::~Group()
{
- xbt_free(m_rank_to_index_map);
- xbt_dict_free(&m_index_to_rank_map);
-}
-
-void Group::destroy()
-{
- if(this != smpi_comm_group(MPI_COMM_WORLD)
- && this != MPI_GROUP_NULL
- && this != MPI_GROUP_EMPTY)
- this->unuse();
+ xbt_free(rank_to_index_map_);
+ xbt_dict_free(&index_to_rank_map_);
}
void Group::set_mapping(int index, int rank)
{
int * val_rank;
- if (rank < m_size) {
- m_rank_to_index_map[rank] = index;
+ if (rank < size_) {
+ 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(m_index_to_rank_map, key, val_rank, nullptr);
+ xbt_dict_set(index_to_rank_map_, key, val_rank, nullptr);
xbt_free(key);
}
}
{
int index = MPI_UNDEFINED;
- if (0 <= rank && rank < m_size) {
- index = m_rank_to_index_map[rank];
+ if (0 <= rank && rank < size_) {
+ index = rank_to_index_map_[rank];
}
return index;
}
if (this==MPI_GROUP_EMPTY)
return MPI_UNDEFINED;
char * key = bprintf("%d", index);
- ptr_rank = static_cast<int*>(xbt_dict_get_or_null(m_index_to_rank_map, key));
+ ptr_rank = static_cast<int*>(xbt_dict_get_or_null(index_to_rank_map_, key));
xbt_free(key);
if (ptr_rank==nullptr)
return *ptr_rank;
}
-int Group::use()
+void Group::ref()
{
- m_refcount++;
- return m_refcount;
+ refcount_++;
}
-int Group::unuse()
+void Group::unref(Group* group)
{
- m_refcount--;
- if (m_refcount <= 0) {
- delete this;
- return 0;
+ group->refcount_--;
+ if (group->refcount_ <= 0) {
+ delete group;
}
- return m_refcount;
}
int Group::size()
{
- return m_size;
+ return size_;
}
int Group::compare(MPI_Group group2)
{
int result;
- int i, index, rank, sz;
+ int i;
+ int index;
+ int rank;
+ int sz;
result = MPI_IDENT;
- if (m_size != group2->size()) {
+ if (size_ != group2->size()) {
result = MPI_UNEQUAL;
} else {
sz = group2->size();
int Group::incl(int n, int* ranks, MPI_Group* newgroup)
{
- int i=0, index=0;
+ int i=0;
+ int index=0;
if (n == 0) {
*newgroup = MPI_GROUP_EMPTY;
- } else if (n == m_size) {
+ } else if (n == size_) {
*newgroup = this;
- if(this!= smpi_comm_group(MPI_COMM_WORLD)
- && this != MPI_GROUP_NULL
- && this != smpi_comm_group(MPI_COMM_SELF)
+ if(this!= MPI_COMM_WORLD->group()
+ && this != MPI_COMM_SELF->group()
&& this != MPI_GROUP_EMPTY)
- this->use();
+ this->ref();
} else {
*newgroup = new Group(n);
for (i = 0; i < n; i++) {
int Group::group_union(MPI_Group group2, MPI_Group* newgroup)
{
- int size1 = m_size;
+ int size1 = size_;
int size2 = group2->size();
for (int i = 0; i < size2; i++) {
int proc2 = group2->index(i);
if (size1 == 0) {
*newgroup = MPI_GROUP_EMPTY;
} else {
- *newgroup = new simgrid::SMPI::Group(size1);
+ *newgroup = new Group(size1);
size2 = this->size();
for (int i = 0; i < size2; i++) {
int proc1 = this->index(i);
if (size2 == 0) {
*newgroup = MPI_GROUP_EMPTY;
} else {
- *newgroup = new simgrid::SMPI::Group(size2);
+ *newgroup = new Group(size2);
int j=0;
for (int i = 0; i < group2->size(); i++) {
int proc2 = group2->index(i);
int Group::difference(MPI_Group group2, MPI_Group* newgroup)
{
- int newsize = m_size;
- int size2 = m_size;
+ int newsize = size_;
+ int size2 = size_;
for (int i = 0; i < size2; i++) {
int proc1 = this->index(i);
int proc2 = group2->rank(proc1);
if (newsize == 0) {
*newgroup = MPI_GROUP_EMPTY;
} else {
- *newgroup = new simgrid::SMPI::Group(newsize);
+ *newgroup = new Group(newsize);
for (int i = 0; i < size2; i++) {
int proc1 = this->index(i);
int proc2 = group2->rank(proc1);
}
int Group::excl(int n, int *ranks, MPI_Group * newgroup){
- int oldsize = m_size;
+ int oldsize = size_;
int newsize = oldsize - n;
- *newgroup = new simgrid::SMPI::Group(newsize);
- int* to_exclude=xbt_new0(int, m_size);
+ *newgroup = new Group(newsize);
+ int* to_exclude=xbt_new0(int, size_);
for (int i = 0; i < oldsize; i++)
to_exclude[i]=0;
for (int i = 0; i < n; i++)
int newsize = 0;
for (int i = 0; i < n; i++) {
for (int rank = ranges[i][0]; /* First */
- rank >= 0 && rank < m_size; /* Last */
+ rank >= 0 && rank < size_; /* Last */
) {
newsize++;
if(rank == ranges[i][1]){/*already last ?*/
}
}
}
- *newgroup = new simgrid::SMPI::Group(newsize);
+ *newgroup = new 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 */
+ rank >= 0 && rank < size_; /* Last */
) {
int index = this->index(rank);
(*newgroup)->set_mapping(index, j);
}
int Group::range_excl(int n, int ranges[][3], MPI_Group * newgroup){
- int newsize = m_size;
+ int newsize = size_;
for (int i = 0; i < n; i++) {
for (int rank = ranges[i][0]; /* First */
- rank >= 0 && rank < m_size; /* Last */
+ rank >= 0 && rank < size_; /* Last */
) {
newsize--;
if(rank == ranges[i][1]){/*already last ?*/
if (newsize == 0) {
*newgroup = MPI_GROUP_EMPTY;
} else {
- *newgroup = new simgrid::SMPI::Group(newsize);
+ *newgroup = new 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;) {
+ for (int rank = ranges[i][0]; rank >= 0 && rank < size_;) {
if(rank==oldrank){
add = 0;
break;
return MPI_SUCCESS;
}
+MPI_Group Group::f2c(int id) {
+ if(id == -2) {
+ return MPI_GROUP_EMPTY;
+ } else if(F2C::f2c_lookup() != nullptr && id >= 0) {
+ char key[KEY_SIZE];
+ return static_cast<MPI_Group>(xbt_dict_get_or_null(F2C::f2c_lookup(), get_key(key, id)));
+ } else {
+ return static_cast<MPI_Group>(MPI_GROUP_NULL);
+ }
+}
+
}
}