-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some unit tests for contiguous puts.
- Loading branch information
Bruce J Palmer
committed
Jan 27, 2025
1 parent
4606cc1
commit 2c44aef
Showing
2 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include "group.hpp" | ||
#include "environment.hpp" | ||
#include "alloc.hpp" | ||
#include <iostream> | ||
|
||
/* Test contiguous put operation */ | ||
|
||
#define TEST_SIZE 1048576 | ||
int main(int argc, char **argv) | ||
{ | ||
MPI_Init(&argc, &argv); | ||
CMX::Environment *env = CMX::Environment::instance(&argc,&argv); | ||
int rank, size, nghbr; | ||
{ | ||
CMX::Group *world = env->getWorldGroup(); | ||
rank = world->rank(); | ||
size = world->size(); | ||
int wrank; | ||
MPI_Comm_rank(MPI_COMM_WORLD,&wrank); | ||
if (rank == 0) { | ||
std::cout <<"Number of processors: "<<size<<std::endl; | ||
} | ||
nghbr = (rank+1)%size; | ||
std::vector<void*> ptrs; | ||
|
||
CMX::Allocation alloc; | ||
int64_t bytes = sizeof(long)*TEST_SIZE; | ||
alloc.malloc(bytes,world); | ||
if (rank == 0) { | ||
std::cout <<"Distributed malloc completed"<<std::endl; | ||
} | ||
world->barrier(); | ||
/* access pointers on all processors */ | ||
alloc.access(ptrs); | ||
int i; | ||
long *buf = new long[TEST_SIZE]; | ||
for (i=0; i<TEST_SIZE; i++) { | ||
buf[i] = nghbr*TEST_SIZE+i; | ||
} | ||
int world_nghbr = world->getWorldRank(nghbr); | ||
std::cout<<"Process "<<rank<<" sending data to neighbor " | ||
<<world_nghbr<<std::endl; | ||
alloc.put(buf,ptrs[nghbr],bytes,world_nghbr); | ||
alloc.fenceAll(); | ||
world->barrier(); | ||
long* ptr = static_cast<long*>(alloc.access()); | ||
bool ok = true; | ||
for (i=0; i<TEST_SIZE; i++) { | ||
if (ptr[i] != (long)(i+rank*TEST_SIZE)) { | ||
printf("p[%d] ptr[%d]: %ld expected: %d\n",wrank, | ||
i,ptr[i],i+rank*TEST_SIZE); | ||
ok = false; | ||
} | ||
} | ||
if (!ok) { | ||
std::cout<<"Mismatch found on process "<<rank<<std::endl; | ||
} else if (rank == 0) { | ||
std::cout<<"Contiguous PUT operation is OK"<<std::endl; | ||
} | ||
/* Set all values in allocation to zero */ | ||
for (i=0; i<TEST_SIZE; i++) { | ||
ptr[i] = (long)0; | ||
} | ||
std::cout<<"Process "<<rank<<" sending data to neighbor " | ||
<<world_nghbr<< " using non-blocking put"<<std::endl; | ||
cmx_request req; | ||
alloc.nbput(buf,ptrs[nghbr],bytes,world_nghbr,&req); | ||
alloc.wait(&req); | ||
alloc.fenceAll(); | ||
world->barrier(); | ||
ok = true; | ||
for (i=0; i<TEST_SIZE; i++) { | ||
if (ptr[i] != (long)(i+rank*TEST_SIZE) && ok) { | ||
printf("p[%d] ptr[%d]: %ld expected: %d\n",wrank, | ||
i,ptr[i],i+rank*TEST_SIZE); | ||
ok = false; | ||
} | ||
} | ||
if (!ok) { | ||
std::cout<<"Mismatch found on process "<<rank<<std::endl; | ||
} else if (rank == 0) { | ||
std::cout<<"Contiguous Non-blocking PUT operation is OK"<<std::endl; | ||
} | ||
|
||
alloc.free(); | ||
if (rank == 0) { | ||
std::cout <<"Allocation freed"<<std::endl; | ||
} | ||
} | ||
env->finalize(); | ||
MPI_Finalize(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "comex.h" | ||
#include <stdio.h> | ||
|
||
/* Test contiguous put operation */ | ||
|
||
#define TEST_SIZE 1048576 | ||
int main(int argc, char **argv) | ||
{ | ||
MPI_Init(&argc, &argv); | ||
int rank, size, nghbr; | ||
comex_group_t group = COMEX_GROUP_WORLD; | ||
comex_init(); | ||
{ | ||
int nghbr; | ||
void **ptrs; | ||
size_t bytes; | ||
long *buf; | ||
int i; | ||
int world_nghbr; | ||
long *ptr; | ||
int ok; | ||
|
||
comex_group_rank(group,&rank); | ||
comex_group_size(group,&size); | ||
if (rank == 0) { | ||
printf("Number of processors: %d\n",size); | ||
} | ||
nghbr = (rank+1)%size; | ||
|
||
bytes = sizeof(long)*TEST_SIZE; | ||
ptrs = (void**)malloc(size*sizeof(void*)); | ||
comex_malloc(ptrs,bytes,group); | ||
for (i=0; i<size; i++) { | ||
printf("p[%d] ptrs[%d]: %p\n",rank,i,ptrs[i]); | ||
} | ||
if (rank == 0) { | ||
printf("Distributed malloc completed\n"); | ||
} | ||
comex_barrier(group); | ||
/* access pointers on all processors */ | ||
buf = (long*)malloc(sizeof(long)*TEST_SIZE); | ||
for (i=0; i<TEST_SIZE; i++) { | ||
buf[i] = nghbr*TEST_SIZE+i; | ||
} | ||
comex_group_translate_world(group,nghbr,&world_nghbr); | ||
printf("Process %d sending data to neighbor %d\n",rank, | ||
world_nghbr); | ||
comex_put(buf,ptrs[nghbr],bytes,world_nghbr,group); | ||
comex_fence_all(group); | ||
comex_barrier(group); | ||
ptr = (long*)ptrs[rank]; | ||
ok = 1; | ||
for (i=0; i<TEST_SIZE; i++) { | ||
if (ptr[i] != (long)(i+rank*TEST_SIZE)) { | ||
printf("p[%d] ptr[%d]: %ld expected: %d\n",rank, | ||
i,ptr[i],i+rank*TEST_SIZE); | ||
ok = 0; | ||
break; | ||
} | ||
} | ||
if (!ok) { | ||
printf("Mismatch found on process %d\n",rank); | ||
} else if (rank == 0) { | ||
printf("Contiguous PUT operation is OK %d\n",rank); | ||
} | ||
comex_free(ptrs[rank],group); | ||
if (rank == 0) { | ||
printf("Allocation free\n"); | ||
} | ||
} | ||
comex_finalize(); | ||
MPI_Finalize(); | ||
return 0; | ||
} |