Skip to content

Commit

Permalink
Another atempted fix for datatypes.
Browse files Browse the repository at this point in the history
  • Loading branch information
selamberson committed Apr 11, 2024
1 parent 09ba412 commit 90d7866
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 44 deletions.
6 changes: 3 additions & 3 deletions src/WrapMPI.xml
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ MPI_Comm_size(manual_conv_comm, &comm_size);
<Code order="convertelse">
comm_copy_attr_keep = comm_copy_attr_fn;
conv_comm_copy_attr_fn = [](MPI_Comm c, int k, void* e, void* i, void* o, int* f) -> int {
YogiMPI_Comm revert_comm = {manPrefix}commToYogi(c);
YogiMPI_Comm revert_comm = Yogi_ResolveComm(&#038;c);
k = {manPrefix}commattrToMPI(k);
auto fn = {manPrefix}copyAttrFn(k);
return fn(revert_comm, k, e, i, o, f);
Expand All @@ -324,7 +324,7 @@ conv_comm_copy_attr_fn = [](MPI_Comm c, int k, void* e, void* i, void* o, int* f
<Code order="convertelse">
comm_delete_attr_keep = comm_delete_attr_fn;
conv_comm_delete_attr_fn = [](MPI_Comm c, int k, void* v, void* e) -> int {
YogiMPI_Comm revert_comm = {manPrefix}commToYogi(c);
YogiMPI_Comm revert_comm = Yogi_ResolveComm(&#038;c);
k = {manPrefix}commattrToMPI(k);
auto fn = {manPrefix}delAttrFn(k);
return fn(revert_comm, k, v, e);
Expand Down Expand Up @@ -1876,7 +1876,7 @@ MPI_Comm_size(manual_conv_comm, &amp;comm_size);
<Code order="beforecall">
YogiMPI_User_function* user_fn_keep = user_fn;
conv_user_fn = [](void* invec, void* inoutvec, int* len, MPI_Datatype* datatype) -> void {
YogiMPI_Datatype revert_datatype = {manPrefix}datatypeToYogi(*datatype);
YogiMPI_Datatype revert_datatype = Yogi_ResolveDatatype(datatype);
auto fn = {manPrefix}userFn({manPrefix}currentOp);
return fn(invec, inoutvec, len, &#38;revert_datatype);
};
Expand Down
49 changes: 12 additions & 37 deletions src/YogiManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,13 @@ int YogiManager::rootToMPI(int root) {
return root;
}

template <typename T>
int YogiManager::findInPool(std::vector<T> &pool, T item, int counter) {
typename std::vector<T>::iterator it = pool.begin();
it = std::find(pool.begin(), pool.begin() + counter, item);
return it - pool.begin();
}

template <typename T, typename V>
int YogiManager::insertIntoPool(std::vector<T> &pool, T newItem, V marker_in,
int offset, int &counter) {
Expand Down Expand Up @@ -670,42 +677,6 @@ int YogiManager::insertIntoPool(std::vector<T> &pool, T newItem, V marker_in,
return delta;
}

template <typename T, typename V>
int YogiManager::insertIntoPoolIfNotFound(std::vector<T> &pool, T newItem, V marker_in, int &counter) {

/* Cast the marker to the type in the pool */
T marker = std::move(static_cast<T>(marker_in));

/* First see if this already exists as a constant. If it does, just
return the equivalent Yogi constant value.
*/
typename std::vector<T>::iterator it = pool.begin();
it = std::find(pool.begin(), pool.begin() + counter, newItem);
if (it != pool.begin() + counter) {
return it - pool.begin();
}
int delta;

/* Then see if the current counter exceeds the size of the vector.
If it does, double it. */
if (counter >= pool.capacity() - 1) {
pool.resize(pool.capacity() * 2, marker);
}
// After the counter, find first instance of marker, replace with newItem.
it = pool.begin();
std::advance(it, counter);
if (std::find(it, pool.end(), marker) != pool.end()) {
delta = std::distance(pool.begin(), std::find(it, pool.end(), marker));
pool.at(delta) = newItem;
}
else {
return -1;
}
// Bump up the counter and return the index.
counter++;
return delta;
}

template <typename T, typename V>
void YogiManager::removeFromPool(std::vector<T> &pool, int index, V marker_in,
int offset, int &counter) {
Expand Down Expand Up @@ -877,7 +848,7 @@ YogiMPI_Message YogiManager::messageToYogi(MPI_Message in_message) {
#endif

YogiMPI_Datatype YogiManager::datatypeToYogi(MPI_Datatype in_data) {
return insertIntoPoolIfNotFound(datatypePool, in_data, MPI_DATATYPE_NULL, numDatatypes);
return insertIntoPool(datatypePool, in_data, MPI_DATATYPE_NULL, datatypeOffset, numDatatypes);
}

YogiMPI_Errhandler YogiManager::errhandlerToYogi(MPI_Errhandler in_errhandler) {
Expand Down Expand Up @@ -996,6 +967,10 @@ void YogiManager::statusToYogi(MPI_Status * &in_mpi, YogiMPI_Status *& out_yogi,
if (free_mpi) freeStatus(in_mpi);
}

YogiMPI_Datatype YogiManager::datatypeToYogiFindOnly(MPI_Datatype in_data) {
return findInPool(datatypePool, in_data, numDatatypes);
}

// Removing Yogi handles

YogiMPI_Comm YogiManager::unmapComm(YogiMPI_Comm to_free) {
Expand Down
7 changes: 5 additions & 2 deletions src/YogiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class YogiManager
void statusToYogi(MPI_Status * &in_mpi, YogiMPI_Status *& out_yogi,
int count, bool free_mpi = false);

YogiMPI_Datatype datatypeToYogiFindOnly(MPI_Datatype in_data);

void freeRequest(MPI_Request * &to_free);
void freeAint(MPI_Aint * &to_free);
void freeDatatype(MPI_Datatype * &to_free);
Expand Down Expand Up @@ -127,11 +129,12 @@ class YogiManager
protected:
YogiManager();
private:
template <typename T>
int findInPool(std::vector<T> &pool, T newItem, int counter);

template <typename T, typename V>
int insertIntoPool(std::vector<T> &pool, T newItem, V marker_in, int offset,
int &counter);
template <typename T, typename V>
int insertIntoPoolIfNotFound(std::vector<T> &pool, T newItem, V marker_in, int &counter);

template <typename T, typename V>
void removeFromPool(std::vector<T> &pool, int index, V marker_in,
Expand Down
4 changes: 2 additions & 2 deletions src/yogimpi.cxx.in
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int Yogi_ResolveErrorCode(int *error) {

YogiMPI_Datatype Yogi_ResolveDatatype(void *input_pointer) {
MPI_Datatype *to_resolve = reinterpret_cast<MPI_Datatype *>(input_pointer);
return YogiManager::getInstance()->datatypeToYogi(*to_resolve);
return YogiManager::getInstance()->datatypeToYogiFindOnly(*to_resolve);
}

YogiMPI_Comm Yogi_ResolveComm(void *input_pointer) {
Expand All @@ -72,7 +72,7 @@ YogiMPI_Group Yogi_ResolveFortranGroup(int fortran_group) {

YogiMPI_Offset Yogi_ResolveOffset(void *input_pointer) {
MPI_Offset *to_resolve = reinterpret_cast<MPI_Offset *>(input_pointer);
return YogiManager::getInstance()->aintToYogi(*to_resolve);
return YogiManager::getInstance()->offsetToYogi(*to_resolve);
}

YogiMPI_Win Yogi_ResolveWin(void *input_pointer) {
Expand Down

0 comments on commit 90d7866

Please sign in to comment.