Skip to content

Commit

Permalink
fix broken test
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Dec 22, 2023
1 parent 0090380 commit e0502d5
Show file tree
Hide file tree
Showing 7 changed files with 431 additions and 9 deletions.
26 changes: 26 additions & 0 deletions mpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,30 @@ typedef int MPI_Group;
#define MPI_UNDEFINED (-1)


/* for the datatype decoders */
enum MPIR_Combiner_enum {
MPI_COMBINER_NAMED = 1,
MPI_COMBINER_DUP = 2,
MPI_COMBINER_CONTIGUOUS = 3,
MPI_COMBINER_VECTOR = 4,
MPI_COMBINER_HVECTOR_INTEGER = 5,
MPI_COMBINER_HVECTOR = 6,
MPI_COMBINER_INDEXED = 7,
MPI_COMBINER_HINDEXED_INTEGER = 8,
MPI_COMBINER_HINDEXED = 9,
MPI_COMBINER_INDEXED_BLOCK = 10,
MPI_COMBINER_STRUCT_INTEGER = 11,
MPI_COMBINER_STRUCT = 12,
MPI_COMBINER_SUBARRAY = 13,
MPI_COMBINER_DARRAY = 14,
MPI_COMBINER_F90_REAL = 15,
MPI_COMBINER_F90_COMPLEX = 16,
MPI_COMBINER_F90_INTEGER = 17,
MPI_COMBINER_RESIZED = 18,
MPI_COMBINER_HINDEXED_BLOCK = 19
};


/*
* Data types etc.
*/
Expand All @@ -76,6 +100,8 @@ typedef int MPI_Datatype;

//C types
#define MPI_CHAR (-1)
#define MPI_SIGNED_CHAR (-46)
#define MPI_WCHAR (-47)
#define MPI_SHORT (-2)
#define MPI_INT (-3)
#define MPI_LONG (-4)
Expand Down
3 changes: 2 additions & 1 deletion mpiP.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ typedef struct
int source;
int tag;
int complete;

int count;
MPI_Datatype type; /* needed for test_simple_bindexed2 */
} Req;


Expand Down
7 changes: 4 additions & 3 deletions recv.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

static int mpi_match_send(void *r, void *tag)
{
return( *((int *)tag) == MPI_ANY_TAG ||
// printf("mpi_match_send %d %d\n",*(int *)tag, ((Req *) r)->tag);
return( *((int *)tag) == MPI_ANY_TAG ||
*((int *)tag) == ((Req *)r)->tag );
}

Expand Down Expand Up @@ -53,15 +54,15 @@ int MPI_Irecv(void *buf, int count, MPI_Datatype datatype,
mycomm->num,tag,count,datatype);
#endif


if (source!=0 && source!=MPI_ANY_SOURCE && source!=MPI_PROC_NULL)
{
fprintf(stderr,"MPI_Irecv: bad source %d\n",source);
abort();
}

mpi_alloc_handle(request,(void **)&rreq);

rreq->type = datatype;
rreq->count = count;
if (source==MPI_PROC_NULL)
{
rreq->complete=1;
Expand Down
7 changes: 4 additions & 3 deletions send.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

static int mpi_match_recv(void *r, void *tag)
{
return( ((Req *)r)->tag == MPI_ANY_TAG ||
// printf("mpi_match_recv %d %d\n",*((int *) tag), ((Req *)r)->tag);
return( ((Req *)r)->tag == MPI_ANY_TAG ||
((Req *)r)->tag == *((int *)tag) );
}

Expand Down Expand Up @@ -63,14 +64,14 @@ int MPI_Isend(void *buf, int count, MPI_Datatype datatype,
sreq->complete=1;
return(MPI_SUCCESS);
}

if (( match=AP_list_search_func(mycomm->recvlist,mpi_match_recv,&tag)))
{
rreq=(Req *)AP_listitem_data(match);
AP_list_delete_item(mycomm->recvlist,match);

// memcpy(rreq->buf,buf,count * datatype);
copy_data2(buf, count, datatype, rreq->buf, count, datatype);
// printf("calling copy datatype %d %d %d %d\n",(int) datatype, count, rreq->type, rreq->count);
copy_data2(buf, count, datatype, rreq->buf, rreq->count, rreq->type);
rreq->complete=1;
rreq->source=0;
rreq->tag=tag; /* in case rreq->tag was MPI_ANY_TAG */
Expand Down
76 changes: 75 additions & 1 deletion tests/ctest.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,80 @@ void test_simple_bindexed()
}
}

//block indexed. Same as bindexed except
//send ints

void test_simple_bindexed2()
{
int mpierr;
int blocksize=1;
int len=4;
int displace[len];
MPI_Datatype mtype;
int sbuf[8];
int rbuf[8];
int i;
MPI_Request rcvid;
MPI_Status status;

//block indexed of simple types
printf("\nBlock indexed type of MPI_INT, sending MPI_INT.\n");

for (i=0;i<8;i++){
sbuf[i] = i;
}
for (i=0;i<8;i++){
rbuf[i] = -1;
}
for (i=0;i<len;i++)
displace[i]=1+i*2;

mpierr = MPI_Type_create_indexed_block(len, blocksize, displace,
MPI_INT, &mtype);
mpierr = MPI_Type_commit(&mtype);

#ifdef TEST_INTERNAL
copy_data(&a, &b, indexed_type);
print_typemap(indexed_type);
#else

mpierr = MPI_Irecv(rbuf, 1, mtype,
0, 1, MPI_COMM_WORLD, &rcvid);

mpierr = MPI_Send(sbuf, 4, MPI_INT,
0, 1, MPI_COMM_WORLD);


mpierr = MPI_Wait(&rcvid, &status);
#endif

printf("a = [");
for (i = 0; i < 8; i++)
printf("%d ", sbuf[i]);
printf("]\n");

printf("b = [");
for (i = 0; i < 8; i++)
printf("%d ", rbuf[i]);
printf("]\n");

for (i = 0; i < 8; i++)
if (i%2 == 0)
{
if (rbuf[i] != -1)
{
printf(">>>FAILED: test_simple_bindexed2\n");
errcount++;
return;
}
} else if (rbuf[i] != sbuf[i / 2])
{
printf(">>>FAILED: test_simple_bindexed2\n");
errcount++;
return;
}
}

//hindexed: same as indexed, but
//using byte displacements based off of sizeof(int)
//(no reason why this shouldn't work)
Expand Down Expand Up @@ -946,6 +1020,7 @@ int main(int argc, char ** argv)
test_simple_hvector();
test_simple_indexed();
test_simple_bindexed();
test_simple_bindexed2();
test_simple_hindexed();
test_simple_struct();
test_complex_struct();
Expand All @@ -964,4 +1039,3 @@ int main(int argc, char ** argv)

return(errcount);
}

65 changes: 64 additions & 1 deletion tests/ftest.F90
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ program test
call mpi_init(ierr)

call MPI_GET_LIBRARY_VERSION(version,vlen,ierr)
print *,"MPI Version '",version,"' len=",vlen
print *,"MPI Version '",trim(version),"' len=",vlen

call test_contiguous(ec)
call test_vector(ec)
call test_simple_hvector(ec)
call test_simple_indexed(ec)
call test_simple_bindexed(ec)
call test_simple_bindexed2(ec)
call test_simple_hindexed(ec)
call test_complex_indexed(ec)
call test_packed(ec)
Expand Down Expand Up @@ -240,13 +241,75 @@ subroutine test_simple_bindexed(ec)
call mpi_irecv(b, 1, indexed_type,mpi_any_source,mpi_any_tag, &
mpi_comm_world, req, ierr)
#endif
! Make sure the sent values were received
do i=1,6
if (a(index_test(i)) .ne. b(index_test(i))) then
print *, ">>>FAILED:test_simple_bindexed"
ec = ec+1
return
end if
end do
! Make sure the unsent values were unchanged
do i=1, 10
if (.not. ANY(index_test == i)) then
if (b(i) /= 0) then
print *, ">>>FAILED:test_simple_bindexed"
ec = ec+1
return
end if
end if
end do
end subroutine

!!!!!!!!!!!!!!!!
! Block indexed. All blocks have same length
!!!!!!!!!!!!!!!!

subroutine test_simple_bindexed2(ec)
use mpi
integer ec
integer i
integer, parameter :: count = 4
integer :: disps(count)
integer a(8), b(8)
integer indexed_type
integer ierr
integer req

print *, "Block indexed type, test 2"

do i = 1, 8
a(i) = i
b(i) = -1
end do
do i = 1, count
! disps(i) = 1 + (i * 2)
disps(i) = 1 + ((i-1) * 2)
end do

call mpi_type_create_indexed_block(count,1,disps,mpi_integer, &
indexed_type, ierr)
call mpi_type_commit(indexed_type, ierr)
#ifdef TEST_INTERNAL
call copy_data2(a,1,indexed_type, b,1,indexed_type, ierr)
#else
call mpi_irecv(b, 1, indexed_type,mpi_any_source,mpi_any_tag, &
mpi_comm_world, req, ierr)
call mpi_send(a, 4, MPI_INTEGER,0, 0, mpi_comm_world,req,ierr)
#endif
do i = 1, 8
if (MOD(i-1, 2) == 0) then
if (b(i) /= -1) then
print *, ">>>FAILED:test_simple_bindexed2, b=", b
ec = ec+1
return
end if
else if (b(i) /= a(i / 2)) then
print *, ">>>FAILED:test_simple_bindexed2 a=",a," b=",b
ec = ec+1
return
end if
end do
end subroutine

!!!!!!!!!!!!!!!!
Expand Down
Loading

0 comments on commit e0502d5

Please sign in to comment.