Skip to content

Commit 90d7866

Browse files
committed
Another atempted fix for datatypes.
1 parent 09ba412 commit 90d7866

File tree

4 files changed

+22
-44
lines changed

4 files changed

+22
-44
lines changed

src/WrapMPI.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ MPI_Comm_size(manual_conv_comm, &comm_size);
312312
<Code order="convertelse">
313313
comm_copy_attr_keep = comm_copy_attr_fn;
314314
conv_comm_copy_attr_fn = [](MPI_Comm c, int k, void* e, void* i, void* o, int* f) -> int {
315-
YogiMPI_Comm revert_comm = {manPrefix}commToYogi(c);
315+
YogiMPI_Comm revert_comm = Yogi_ResolveComm(&#038;c);
316316
k = {manPrefix}commattrToMPI(k);
317317
auto fn = {manPrefix}copyAttrFn(k);
318318
return fn(revert_comm, k, e, i, o, f);
@@ -324,7 +324,7 @@ conv_comm_copy_attr_fn = [](MPI_Comm c, int k, void* e, void* i, void* o, int* f
324324
<Code order="convertelse">
325325
comm_delete_attr_keep = comm_delete_attr_fn;
326326
conv_comm_delete_attr_fn = [](MPI_Comm c, int k, void* v, void* e) -> int {
327-
YogiMPI_Comm revert_comm = {manPrefix}commToYogi(c);
327+
YogiMPI_Comm revert_comm = Yogi_ResolveComm(&#038;c);
328328
k = {manPrefix}commattrToMPI(k);
329329
auto fn = {manPrefix}delAttrFn(k);
330330
return fn(revert_comm, k, v, e);
@@ -1876,7 +1876,7 @@ MPI_Comm_size(manual_conv_comm, &amp;comm_size);
18761876
<Code order="beforecall">
18771877
YogiMPI_User_function* user_fn_keep = user_fn;
18781878
conv_user_fn = [](void* invec, void* inoutvec, int* len, MPI_Datatype* datatype) -> void {
1879-
YogiMPI_Datatype revert_datatype = {manPrefix}datatypeToYogi(*datatype);
1879+
YogiMPI_Datatype revert_datatype = Yogi_ResolveDatatype(datatype);
18801880
auto fn = {manPrefix}userFn({manPrefix}currentOp);
18811881
return fn(invec, inoutvec, len, &#38;revert_datatype);
18821882
};

src/YogiManager.cxx

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,13 @@ int YogiManager::rootToMPI(int root) {
633633
return root;
634634
}
635635

636+
template <typename T>
637+
int YogiManager::findInPool(std::vector<T> &pool, T item, int counter) {
638+
typename std::vector<T>::iterator it = pool.begin();
639+
it = std::find(pool.begin(), pool.begin() + counter, item);
640+
return it - pool.begin();
641+
}
642+
636643
template <typename T, typename V>
637644
int YogiManager::insertIntoPool(std::vector<T> &pool, T newItem, V marker_in,
638645
int offset, int &counter) {
@@ -670,42 +677,6 @@ int YogiManager::insertIntoPool(std::vector<T> &pool, T newItem, V marker_in,
670677
return delta;
671678
}
672679

673-
template <typename T, typename V>
674-
int YogiManager::insertIntoPoolIfNotFound(std::vector<T> &pool, T newItem, V marker_in, int &counter) {
675-
676-
/* Cast the marker to the type in the pool */
677-
T marker = std::move(static_cast<T>(marker_in));
678-
679-
/* First see if this already exists as a constant. If it does, just
680-
return the equivalent Yogi constant value.
681-
*/
682-
typename std::vector<T>::iterator it = pool.begin();
683-
it = std::find(pool.begin(), pool.begin() + counter, newItem);
684-
if (it != pool.begin() + counter) {
685-
return it - pool.begin();
686-
}
687-
int delta;
688-
689-
/* Then see if the current counter exceeds the size of the vector.
690-
If it does, double it. */
691-
if (counter >= pool.capacity() - 1) {
692-
pool.resize(pool.capacity() * 2, marker);
693-
}
694-
// After the counter, find first instance of marker, replace with newItem.
695-
it = pool.begin();
696-
std::advance(it, counter);
697-
if (std::find(it, pool.end(), marker) != pool.end()) {
698-
delta = std::distance(pool.begin(), std::find(it, pool.end(), marker));
699-
pool.at(delta) = newItem;
700-
}
701-
else {
702-
return -1;
703-
}
704-
// Bump up the counter and return the index.
705-
counter++;
706-
return delta;
707-
}
708-
709680
template <typename T, typename V>
710681
void YogiManager::removeFromPool(std::vector<T> &pool, int index, V marker_in,
711682
int offset, int &counter) {
@@ -877,7 +848,7 @@ YogiMPI_Message YogiManager::messageToYogi(MPI_Message in_message) {
877848
#endif
878849

879850
YogiMPI_Datatype YogiManager::datatypeToYogi(MPI_Datatype in_data) {
880-
return insertIntoPoolIfNotFound(datatypePool, in_data, MPI_DATATYPE_NULL, numDatatypes);
851+
return insertIntoPool(datatypePool, in_data, MPI_DATATYPE_NULL, datatypeOffset, numDatatypes);
881852
}
882853

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

970+
YogiMPI_Datatype YogiManager::datatypeToYogiFindOnly(MPI_Datatype in_data) {
971+
return findInPool(datatypePool, in_data, numDatatypes);
972+
}
973+
999974
// Removing Yogi handles
1000975

1001976
YogiMPI_Comm YogiManager::unmapComm(YogiMPI_Comm to_free) {

src/YogiManager.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class YogiManager
9797
void statusToYogi(MPI_Status * &in_mpi, YogiMPI_Status *& out_yogi,
9898
int count, bool free_mpi = false);
9999

100+
YogiMPI_Datatype datatypeToYogiFindOnly(MPI_Datatype in_data);
101+
100102
void freeRequest(MPI_Request * &to_free);
101103
void freeAint(MPI_Aint * &to_free);
102104
void freeDatatype(MPI_Datatype * &to_free);
@@ -127,11 +129,12 @@ class YogiManager
127129
protected:
128130
YogiManager();
129131
private:
132+
template <typename T>
133+
int findInPool(std::vector<T> &pool, T newItem, int counter);
134+
130135
template <typename T, typename V>
131136
int insertIntoPool(std::vector<T> &pool, T newItem, V marker_in, int offset,
132137
int &counter);
133-
template <typename T, typename V>
134-
int insertIntoPoolIfNotFound(std::vector<T> &pool, T newItem, V marker_in, int &counter);
135138

136139
template <typename T, typename V>
137140
void removeFromPool(std::vector<T> &pool, int index, V marker_in,

src/yogimpi.cxx.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int Yogi_ResolveErrorCode(int *error) {
5252

5353
YogiMPI_Datatype Yogi_ResolveDatatype(void *input_pointer) {
5454
MPI_Datatype *to_resolve = reinterpret_cast<MPI_Datatype *>(input_pointer);
55-
return YogiManager::getInstance()->datatypeToYogi(*to_resolve);
55+
return YogiManager::getInstance()->datatypeToYogiFindOnly(*to_resolve);
5656
}
5757

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

7373
YogiMPI_Offset Yogi_ResolveOffset(void *input_pointer) {
7474
MPI_Offset *to_resolve = reinterpret_cast<MPI_Offset *>(input_pointer);
75-
return YogiManager::getInstance()->aintToYogi(*to_resolve);
75+
return YogiManager::getInstance()->offsetToYogi(*to_resolve);
7676
}
7777

7878
YogiMPI_Win Yogi_ResolveWin(void *input_pointer) {

0 commit comments

Comments
 (0)