Skip to content

Commit f3195ef

Browse files
bosilcaggouaillardet
authored andcommitted
Add a test to validate the support for external32.
(back-ported from commit 8da67f5)
1 parent 5a88415 commit f3195ef

File tree

2 files changed

+114
-1
lines changed

2 files changed

+114
-1
lines changed

test/datatype/Makefile.am

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#
1616

1717
if PROJECT_OMPI
18-
MPI_TESTS = checksum position position_noncontig ddt_test ddt_raw unpack_ooo ddt_pack
18+
MPI_TESTS = checksum position position_noncontig ddt_test ddt_raw unpack_ooo ddt_pack external32
1919
MPI_CHECKS = to_self
2020
endif
2121
TESTS = opal_datatype_test $(MPI_TESTS)
@@ -72,3 +72,12 @@ opal_datatype_test_SOURCES = opal_datatype_test.c opal_ddt_lib.c opal_ddt_lib.h
7272
opal_datatype_test_LDFLAGS = $(WRAPPER_EXTRA_LDFLAGS)
7373
opal_datatype_test_LDADD = \
7474
$(top_builddir)/opal/lib@[email protected]
75+
76+
external32_SOURCES = external32.c
77+
external32_LDFLAGS = $(OMPI_PKG_CONFIG_LDFLAGS)
78+
external32_LDADD = \
79+
$(top_builddir)/ompi/libmpi.la \
80+
$(top_builddir)/opal/lib@[email protected]
81+
82+
distclean:
83+
rm -rf *.dSYM .deps .libs *.log *.o *.trs $(check_PROGRAMS) Makefile

test/datatype/external32.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; -*- */
2+
/*
3+
* Copyright (c) 2016 The University of Tennessee and The University
4+
* of Tennessee Research Foundation. All rights
5+
* reserved.
6+
* $COPYRIGHT$
7+
*
8+
* Additional copyrights may follow
9+
*
10+
* $HEADER$
11+
*/
12+
13+
#include <stdio.h>
14+
#include <stdlib.h>
15+
#include <mpi.h>
16+
17+
void dump_hex(void* what, size_t length)
18+
{
19+
int i;
20+
for( i = 0; i < length; i++ ) {
21+
printf("%02x", (unsigned int)(((unsigned char*)what)[i]));
22+
}
23+
}
24+
25+
int pack_unpack_datatype( void* send_data, MPI_Datatype datatype, int count,
26+
void* recv_data )
27+
{
28+
MPI_Aint position = 0, buffer_size;
29+
void* buffer;
30+
int error;
31+
32+
error = MPI_Pack_external_size("external32",
33+
count, datatype, &buffer_size);
34+
if( MPI_SUCCESS != error ) goto return_error_code;
35+
36+
buffer = (void*)malloc(buffer_size);
37+
if( NULL == buffer ) { error = MPI_ERR_UNKNOWN; goto return_error_code; }
38+
39+
error = MPI_Pack_external("external32", (void*)send_data, count, datatype,
40+
buffer, buffer_size, &position);
41+
if( MPI_SUCCESS != error ) goto return_error_code;
42+
43+
printf("packed "); dump_hex(buffer, buffer_size); printf("\n");
44+
45+
position = 0;
46+
error = MPI_Unpack_external("external32", buffer, buffer_size, &position,
47+
recv_data, count, datatype);
48+
if( MPI_SUCCESS != error ) goto return_error_code;
49+
free(buffer);
50+
51+
return_error_code:
52+
return (error == MPI_SUCCESS ? 0 : -1);
53+
}
54+
55+
int main(int argc, char *argv[])
56+
{
57+
MPI_Init(&argc, &argv);
58+
59+
/* Simple contiguous data */
60+
{
61+
int send_data[2] = {1234, 5678};
62+
int recv_data[2] = {-1, -1};
63+
64+
printf("send data %08x %08x \n", send_data[0], send_data[1]);
65+
printf("data "); dump_hex(&send_data, sizeof(int) * 2); printf("\n");
66+
67+
(void)pack_unpack_datatype( send_data, MPI_INT, 2,
68+
recv_data );
69+
70+
printf("recv "); dump_hex(&recv_data, sizeof(int) * 2); printf("\n");
71+
printf("recv data %08x %08x \n", recv_data[0], recv_data[1]);
72+
if( (send_data[0] != recv_data[0]) || (send_data[1] != recv_data[1]) ) {
73+
printf("Error duing external32 pack/unack for contiguous types\n");
74+
exit(-1);
75+
}
76+
}
77+
78+
/* Vector datatype */
79+
printf("\n\nVector datatype\n\n");
80+
{
81+
int send_data[3] = {1234, 0, 5678};
82+
int recv_data[3] = {-1, -1, -1};
83+
MPI_Datatype ddt;
84+
85+
MPI_Type_vector(2, 1, 2, MPI_INT, &ddt);
86+
MPI_Type_commit(&ddt);
87+
printf("send data %08x %x08x %08x \n", send_data[0], send_data[1], send_data[2]);
88+
printf("data "); dump_hex(&send_data, sizeof(int) * 3); printf("\n");
89+
90+
(void)pack_unpack_datatype( send_data, ddt, 1, recv_data );
91+
92+
printf("recv "); dump_hex(&recv_data, sizeof(int) * 3); printf("\n");
93+
printf("recv data %08x %08x %08x \n", recv_data[0], recv_data[1], recv_data[2]);
94+
MPI_Type_free(&ddt);
95+
if( (send_data[0] != recv_data[0]) || (send_data[2] != recv_data[2]) ) {
96+
printf("Error duing external32 pack/unack for vector types\n");
97+
exit(-1);
98+
}
99+
}
100+
101+
MPI_Finalize();
102+
103+
return 0;
104+
}

0 commit comments

Comments
 (0)