1818#include "opal/runtime/opal.h"
1919#include "opal/datatype/opal_convertor.h"
2020#include "opal/datatype/opal_datatype_internal.h"
21- // #include <mpi.h>
21+ #include <arpa/inet.h>
22+
23+ static int verbose = 0 ;
24+
25+ typedef int (* checker_t )(void * , void * , ompi_datatype_t * , int , void * );
26+
27+ int check_contiguous ( void * send_buffer , void * packed ,
28+ ompi_datatype_t * datatype , int count , void * arg );
29+
30+ int check_vector ( void * send_buffer , void * packed ,
31+ ompi_datatype_t * datatype , int count , void * arg );
2232
2333static int pack_unpack_datatype ( void * send_data , ompi_datatype_t * datatype , int count ,
24- void * recv_data );
34+ void * recv_data , checker_t validator , void * validator_arg );
2535
2636static void dump_hex (void * what , size_t length );
2737
@@ -137,8 +147,74 @@ int MPI_Unpack_external (const char datarep[], const void *inbuf, MPI_Aint insiz
137147 return (rc == 1 ) ? OMPI_SUCCESS : OMPI_ERROR ;
138148}
139149
150+ int check_contiguous ( void * send_buffer , void * packed ,
151+ ompi_datatype_t * datatype , int count , void * arg )
152+ {
153+ int i ;
154+
155+ if ( (datatype == & ompi_mpi_int .dt ) || (datatype == & ompi_mpi_int32_t .dt ) ) {
156+ uint32_t val ;
157+ for ( i = 0 ; i < count ; i ++ ) {
158+ val = htonl (((uint32_t * )send_buffer )[i ]);
159+ if ( val != ((uint32_t * )packed )[i ] ) {
160+ printf ("Error at position %d expected %x found %x (type %s)\n" ,
161+ i , ((uint32_t * )packed )[i ], ((uint32_t * )send_buffer )[i ], datatype -> name );
162+ return -1 ;
163+ }
164+ }
165+ } else if ( (datatype == & ompi_mpi_short .dt ) || (datatype == & ompi_mpi_int16_t .dt ) ) {
166+ uint16_t val ;
167+ for ( i = 0 ; i < count ; i ++ ) {
168+ val = htons (((uint16_t * )send_buffer )[i ]);
169+ if ( val != ((uint16_t * )packed )[i ] ) {
170+ printf ("Error at position %d expected %x found %x (type %s)\n" ,
171+ i , ((uint16_t * )packed )[i ], ((uint16_t * )send_buffer )[i ], datatype -> name );
172+ return -1 ;
173+ }
174+ }
175+ } else {
176+ printf ("Unknown type\n" );
177+ return -1 ;
178+ }
179+ return 0 ;
180+ }
181+
182+ int check_vector ( void * send_buffer , void * packed ,
183+ ompi_datatype_t * datatype , int count , void * arg )
184+ {
185+ int i ;
186+ ompi_datatype_t * origtype = (ompi_datatype_t * )arg ;
187+
188+ if ( (origtype == & ompi_mpi_int .dt ) || (origtype == & ompi_mpi_int32_t .dt ) ) {
189+ uint32_t val ;
190+ for ( i = 0 ; i < count ; i ++ ) {
191+ val = htonl (((uint32_t * )send_buffer )[2 * i ]);
192+ if ( val != ((uint32_t * )packed )[i ] ) {
193+ printf ("Error at position %d expected %x found %x (type %s)\n" ,
194+ i , ((uint32_t * )packed )[i ], ((uint32_t * )send_buffer )[2 * i ], datatype -> name );
195+ return -1 ;
196+ }
197+ }
198+ } else if ( (origtype == & ompi_mpi_short .dt ) || (origtype == & ompi_mpi_int16_t .dt ) ) {
199+ uint16_t val ;
200+ for ( i = 0 ; i < count ; i ++ ) {
201+ val = htons (((uint16_t * )send_buffer )[2 * i ]);
202+ if ( val != ((uint16_t * )packed )[i ] ) {
203+ printf ("Error at position %d expected %x found %x (type %s)\n" ,
204+ i , ((uint16_t * )packed )[i ], ((uint16_t * )send_buffer )[2 * i ], datatype -> name );
205+ return -1 ;
206+ }
207+ }
208+ } else {
209+ printf ("Unknown %s type\n" , datatype -> name );
210+ return -1 ;
211+ }
212+ return 0 ;
213+ }
214+
140215static int pack_unpack_datatype ( void * send_data , ompi_datatype_t * datatype , int count ,
141- void * recv_data )
216+ void * recv_data ,
217+ checker_t validator , void * validator_arg )
142218{
143219 MPI_Aint position = 0 , buffer_size ;
144220 void * buffer ;
@@ -185,8 +261,8 @@ int main(int argc, char *argv[])
185261 printf ("send data %08x %08x \n" , send_data [0 ], send_data [1 ]);
186262 printf ("data " ); dump_hex (& send_data , sizeof (int32_t ) * 2 ); printf ("\n" );
187263 }
188- (void )pack_unpack_datatype ( send_data , MPI_INT32_T , 2 ,
189- recv_data , check_contiguous , (void * )( ptrdiff_t ) MPI_INT32_T );
264+ (void )pack_unpack_datatype ( send_data , & ompi_mpi_int32_t . dt , 2 ,
265+ recv_data , check_contiguous , (void * )& ompi_mpi_int32_t . dt );
190266 if ( verbose ) {
191267 printf ("recv " ); dump_hex (& recv_data , sizeof (int32_t ) * 2 ); printf ("\n" );
192268 printf ("recv data %08x %08x \n" , recv_data [0 ], recv_data [1 ]);
@@ -205,8 +281,8 @@ int main(int argc, char *argv[])
205281 printf ("send data %08x %08x \n" , send_data [0 ], send_data [1 ]);
206282 printf ("data " ); dump_hex (& send_data , sizeof (int16_t ) * 2 ); printf ("\n" );
207283 }
208- (void )pack_unpack_datatype ( send_data , MPI_INT16_T , 2 ,
209- recv_data , check_contiguous , (void * )( ptrdiff_t ) MPI_INT16_T );
284+ (void )pack_unpack_datatype ( send_data , & ompi_mpi_int16_t . dt , 2 ,
285+ recv_data , check_contiguous , (void * )& ompi_mpi_int16_t . dt );
210286 if ( verbose ) {
211287 printf ("recv " ); dump_hex (& recv_data , sizeof (int16_t ) * 2 ); printf ("\n" );
212288 printf ("recv data %08x %08x \n" , recv_data [0 ], recv_data [1 ]);
@@ -234,16 +310,18 @@ int main(int argc, char *argv[])
234310 }
235311 ompi_datatype_commit (& ddt );
236312
237- printf ("send data %08x %x08x %08x \n" , send_data [0 ], send_data [1 ], send_data [2 ]);
238- printf ("data " ); dump_hex (& send_data , sizeof (int ) * 3 ); printf ("\n" );
239-
240- (void )pack_unpack_datatype ( send_data , ddt , 1 , recv_data );
241-
242- printf ("recv " ); dump_hex (& recv_data , sizeof (int ) * 3 ); printf ("\n" );
243- printf ("recv data %08x %08x %08x \n" , recv_data [0 ], recv_data [1 ], recv_data [2 ]);
313+ if ( verbose ) {
314+ printf ("send data %08x %x08x %08x \n" , send_data [0 ], send_data [1 ], send_data [2 ]);
315+ printf ("data " ); dump_hex (& send_data , sizeof (int32_t ) * 3 ); printf ("\n" );
316+ }
317+ (void )pack_unpack_datatype ( send_data , ddt , 1 , recv_data , check_vector , (void * )& ompi_mpi_int32_t .dt );
318+ if ( verbose ) {
319+ printf ("recv " ); dump_hex (& recv_data , sizeof (int32_t ) * 3 ); printf ("\n" );
320+ printf ("recv data %08x %08x %08x \n" , recv_data [0 ], recv_data [1 ], recv_data [2 ]);
321+ }
244322 ompi_datatype_destroy (& ddt );
245323 if ( (send_data [0 ] != recv_data [0 ]) || (send_data [2 ] != recv_data [2 ]) ) {
246- printf ("Error during external32 pack/unack for vector types\n" );
324+ printf ("Error during external32 pack/unack for vector types (MPI_INT32_T) \n" );
247325 exit (-1 );
248326 }
249327 }
0 commit comments