Skip to content

Commit ea92775

Browse files
authored
Merge pull request #3069 from ggouaillardet/topic/v2.0.x/mpi_pack_unpack
v2.0.x: fix and revamp MPI_Pack and friends
2 parents 0e33453 + 5b8334a commit ea92775

File tree

10 files changed

+188
-220
lines changed

10 files changed

+188
-220
lines changed

ompi/datatype/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# Copyright (c) 2007-2013 Los Alamos National Security, LLC. All rights
1414
# reserved.
1515
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
16+
# Copyright (c) 2016 Research Organization for Information Science
17+
# and Technology (RIST). All rights reserved.
1618
# $COPYRIGHT$
1719
#
1820
# Additional copyrights may follow
@@ -37,6 +39,7 @@ libdatatype_la_SOURCES = \
3739
ompi_datatype_create_vector.c \
3840
ompi_datatype_create_darray.c \
3941
ompi_datatype_create_subarray.c \
42+
ompi_datatype_external.c \
4043
ompi_datatype_external32.c \
4144
ompi_datatype_match_size.c \
4245
ompi_datatype_module.c \

ompi/datatype/ompi_datatype.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
88
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
99
* reserved.
10-
* Copyright (c) 2015 Research Organization for Information Science
10+
* Copyright (c) 2015-2016 Research Organization for Information Science
1111
* and Technology (RIST). All rights reserved.
1212
* $COPYRIGHT$
1313
*
@@ -363,5 +363,16 @@ OMPI_DECLSPEC int ompi_datatype_safeguard_pointer_debug_breakpoint( const void*
363363
int count );
364364
#endif /* OPAL_ENABLE_DEBUG */
365365

366+
OMPI_DECLSPEC int ompi_datatype_pack_external( const char datarep[], const void *inbuf, int incount,
367+
ompi_datatype_t *datatype, void *outbuf,
368+
MPI_Aint outsize, MPI_Aint *position);
369+
370+
OMPI_DECLSPEC int ompi_datatype_unpack_external( const char datarep[], const void *inbuf, MPI_Aint insize,
371+
MPI_Aint *position, void *outbuf, int outcount,
372+
ompi_datatype_t *datatype);
373+
374+
OMPI_DECLSPEC int ompi_datatype_pack_external_size( const char datarep[], int incount,
375+
ompi_datatype_t *datatype, MPI_Aint *size);
376+
366377
END_C_DECLS
367378
#endif /* OMPI_DATATYPE_H_HAS_BEEN_INCLUDED */
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; -*- */
2+
/*
3+
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
4+
* University Research and Technology
5+
* Corporation. All rights reserved.
6+
* Copyright (c) 2004-2016 The University of Tennessee and The University
7+
* of Tennessee Research Foundation. All rights
8+
* reserved.
9+
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
10+
* University of Stuttgart. All rights reserved.
11+
* Copyright (c) 2004-2005 The Regents of the University of California.
12+
* All rights reserved.
13+
* Copyright (c) 2006 Cisco Systems, Inc. All rights reserved.
14+
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
15+
* reserved.
16+
* Copyright (c) 2015-2016 Research Organization for Information Science
17+
* and Technology (RIST). All rights reserved.
18+
* $COPYRIGHT$
19+
*
20+
* Additional copyrights may follow
21+
*
22+
* $HEADER$
23+
*/
24+
25+
#include "ompi_config.h"
26+
#include <stdio.h>
27+
28+
#include "ompi/runtime/params.h"
29+
#include "ompi/communicator/communicator.h"
30+
#include "ompi/datatype/ompi_datatype.h"
31+
#include "opal/datatype/opal_convertor.h"
32+
33+
int ompi_datatype_pack_external(const char datarep[], const void *inbuf, int incount,
34+
ompi_datatype_t *datatype, void *outbuf,
35+
MPI_Aint outsize, MPI_Aint *position)
36+
{
37+
int rc = MPI_SUCCESS;
38+
opal_convertor_t local_convertor;
39+
struct iovec invec;
40+
unsigned int iov_count;
41+
size_t size;
42+
43+
OBJ_CONSTRUCT(&local_convertor, opal_convertor_t);
44+
45+
/* The resulting convertor will be set to the position zero. We have to use
46+
* CONVERTOR_SEND_CONVERSION in order to force the convertor to do anything
47+
* more than just packing the data.
48+
*/
49+
opal_convertor_copy_and_prepare_for_send( ompi_mpi_external32_convertor,
50+
&(datatype->super), incount, (void *) inbuf,
51+
CONVERTOR_SEND_CONVERSION,
52+
&local_convertor );
53+
54+
/* Check for truncation */
55+
opal_convertor_get_packed_size( &local_convertor, &size );
56+
if( (*position + size) > (size_t)outsize ) { /* we can cast as we already checked for < 0 */
57+
OBJ_DESTRUCT( &local_convertor );
58+
return MPI_ERR_TRUNCATE;
59+
}
60+
61+
/* Prepare the iovec with all informations */
62+
invec.iov_base = (char*) outbuf + (*position);
63+
invec.iov_len = size;
64+
65+
/* Do the actual packing */
66+
iov_count = 1;
67+
rc = opal_convertor_pack( &local_convertor, &invec, &iov_count, &size );
68+
*position += size;
69+
OBJ_DESTRUCT( &local_convertor );
70+
71+
/* All done. Note that the convertor returns 1 upon success, not
72+
OMPI_SUCCESS. */
73+
return (rc == 1) ? OMPI_SUCCESS : MPI_ERR_UNKNOWN;
74+
}
75+
76+
int ompi_datatype_unpack_external (const char datarep[], const void *inbuf, MPI_Aint insize,
77+
MPI_Aint *position, void *outbuf, int outcount,
78+
ompi_datatype_t *datatype)
79+
{
80+
int rc = MPI_SUCCESS;
81+
opal_convertor_t local_convertor;
82+
struct iovec outvec;
83+
unsigned int iov_count;
84+
size_t size;
85+
86+
OBJ_CONSTRUCT(&local_convertor, opal_convertor_t);
87+
88+
/* the resulting convertor will be set to the position ZERO */
89+
opal_convertor_copy_and_prepare_for_recv( ompi_mpi_external32_convertor,
90+
&(datatype->super), outcount, outbuf,
91+
0,
92+
&local_convertor );
93+
94+
/* Check for truncation */
95+
opal_convertor_get_packed_size( &local_convertor, &size );
96+
if( (*position + size) > (unsigned int)insize ) {
97+
OBJ_DESTRUCT( &local_convertor );
98+
return MPI_ERR_TRUNCATE;
99+
}
100+
101+
/* Prepare the iovec with all informations */
102+
outvec.iov_base = (char*) inbuf + (*position);
103+
outvec.iov_len = size;
104+
105+
/* Do the actual unpacking */
106+
iov_count = 1;
107+
rc = opal_convertor_unpack( &local_convertor, &outvec, &iov_count, &size );
108+
*position += size;
109+
OBJ_DESTRUCT( &local_convertor );
110+
111+
/* All done. Note that the convertor returns 1 upon success, not
112+
OMPI_SUCCESS. */
113+
return (rc == 1) ? OMPI_SUCCESS : MPI_ERR_UNKNOWN;
114+
}
115+
116+
int ompi_datatype_pack_external_size(const char datarep[], int incount,
117+
ompi_datatype_t *datatype, MPI_Aint *size)
118+
{
119+
opal_convertor_t local_convertor;
120+
size_t length;
121+
122+
OBJ_CONSTRUCT(&local_convertor, opal_convertor_t);
123+
124+
/* the resulting convertor will be set to the position ZERO */
125+
opal_convertor_copy_and_prepare_for_recv( ompi_mpi_external32_convertor,
126+
&(datatype->super), incount, NULL,
127+
CONVERTOR_SEND_CONVERSION,
128+
&local_convertor );
129+
130+
opal_convertor_get_unpacked_size( &local_convertor, &length );
131+
*size = (MPI_Aint)length;
132+
OBJ_DESTRUCT( &local_convertor );
133+
134+
return OMPI_SUCCESS;
135+
}

ompi/datatype/ompi_datatype_module.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2013 The University of Tennessee and The University
6+
* Copyright (c) 2004-2016 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
@@ -38,9 +38,6 @@
3838

3939
#include "mpi.h"
4040

41-
/* by default the debuging is turned off */
42-
int ompi_datatype_dfd = -1;
43-
4441
/**
4542
* This is the number of predefined datatypes. It is different than the MAX_PREDEFINED
4643
* as it include all the optional datatypes (such as MPI_INTEGER?, MPI_REAL?).
@@ -662,12 +659,6 @@ int32_t ompi_datatype_finalize( void )
662659
/* Get rid of the Fortran2C translation table */
663660
OBJ_DESTRUCT(&ompi_datatype_f_to_c_table);
664661

665-
#if defined(VERBOSE)
666-
if( ompi_datatype_dfd != -1 )
667-
opal_output_close( ompi_datatype_dfd );
668-
ompi_datatype_dfd = -1;
669-
#endif /* VERBOSE */
670-
671662
/* release the local convertors (external32 and local) */
672663
ompi_datatype_default_convertors_fini();
673664

ompi/mpi/c/pack.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Copyright (c) 2006 Cisco Systems, Inc. All rights reserved.
1414
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
1515
* reserved.
16-
* Copyright (c) 2015 Research Organization for Information Science
16+
* Copyright (c) 2015-2017 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
1818
* $COPYRIGHT$
1919
*
@@ -45,7 +45,7 @@ static const char FUNC_NAME[] = "MPI_Pack";
4545
int MPI_Pack(const void *inbuf, int incount, MPI_Datatype datatype,
4646
void *outbuf, int outsize, int *position, MPI_Comm comm)
4747
{
48-
int rc = MPI_SUCCESS;
48+
int rc = MPI_SUCCESS, ret;
4949
opal_convertor_t local_convertor;
5050
struct iovec invec;
5151
unsigned int iov_count;
@@ -92,12 +92,14 @@ int MPI_Pack(const void *inbuf, int incount, MPI_Datatype datatype,
9292

9393
/* Do the actual packing */
9494
iov_count = 1;
95-
rc = opal_convertor_pack( &local_convertor, &invec, &iov_count, &size );
95+
ret = opal_convertor_pack( &local_convertor, &invec, &iov_count, &size );
9696
*position += size;
9797
OBJ_DESTRUCT( &local_convertor );
9898

9999
/* All done. Note that the convertor returns 1 upon success, not
100-
OMPI_SUCCESS. */
101-
OMPI_ERRHANDLER_RETURN((rc == 1) ? OMPI_SUCCESS : OMPI_ERROR,
102-
comm, MPI_ERR_UNKNOWN, FUNC_NAME);
100+
OPAL_SUCCESS. */
101+
if (1 != ret) {
102+
rc = OMPI_ERROR;
103+
}
104+
OMPI_ERRHANDLER_RETURN(rc, comm, MPI_ERR_UNKNOWN, FUNC_NAME);
103105
}

ompi/mpi/c/pack_external.c

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Copyright (c) 2006 Cisco Systems, Inc. All rights reserved.
1414
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
1515
* reserved.
16-
* Copyright (c) 2015 Research Organization for Information Science
16+
* Copyright (c) 2015-2017 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
1818
* $COPYRIGHT$
1919
*
@@ -47,10 +47,6 @@ int MPI_Pack_external(const char datarep[], const void *inbuf, int incount,
4747
MPI_Aint outsize, MPI_Aint *position)
4848
{
4949
int rc = MPI_SUCCESS;
50-
opal_convertor_t local_convertor;
51-
struct iovec invec;
52-
unsigned int iov_count;
53-
size_t size;
5450

5551
MEMCHECKER(
5652
memchecker_datatype(datatype);
@@ -72,36 +68,9 @@ int MPI_Pack_external(const char datarep[], const void *inbuf, int incount,
7268
OMPI_ERRHANDLER_CHECK(rc, MPI_COMM_WORLD, rc, FUNC_NAME);
7369
}
7470

75-
OBJ_CONSTRUCT(&local_convertor, opal_convertor_t);
71+
rc = ompi_datatype_pack_external(datarep, inbuf, incount,
72+
datatype, outbuf,
73+
outsize, position);
7674

77-
/* The resulting convertor will be set to the position zero. We have to use
78-
* CONVERTOR_SEND_CONVERSION in order to force the convertor to do anything
79-
* more than just packing the data.
80-
*/
81-
opal_convertor_copy_and_prepare_for_send( ompi_mpi_external32_convertor,
82-
&(datatype->super), incount, (void *) inbuf,
83-
CONVERTOR_SEND_CONVERSION,
84-
&local_convertor );
85-
86-
/* Check for truncation */
87-
opal_convertor_get_packed_size( &local_convertor, &size );
88-
if( (*position + size) > (size_t)outsize ) { /* we can cast as we already checked for < 0 */
89-
OBJ_DESTRUCT( &local_convertor );
90-
return OMPI_ERRHANDLER_INVOKE( MPI_COMM_WORLD, MPI_ERR_TRUNCATE, FUNC_NAME );
91-
}
92-
93-
/* Prepare the iovec with all informations */
94-
invec.iov_base = (char*) outbuf + (*position);
95-
invec.iov_len = size;
96-
97-
/* Do the actual packing */
98-
iov_count = 1;
99-
rc = opal_convertor_pack( &local_convertor, &invec, &iov_count, &size );
100-
*position += size;
101-
OBJ_DESTRUCT( &local_convertor );
102-
103-
/* All done. Note that the convertor returns 1 upon success, not
104-
OMPI_SUCCESS. */
105-
OMPI_ERRHANDLER_RETURN((rc == 1) ? OMPI_SUCCESS : OMPI_ERROR,
106-
MPI_COMM_WORLD, MPI_ERR_UNKNOWN, FUNC_NAME);
75+
OMPI_ERRHANDLER_RETURN(rc, MPI_COMM_WORLD, rc, FUNC_NAME);
10776
}

ompi/mpi/c/pack_external_size.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Copyright (c) 2006 Cisco Systems, Inc. All rights reserved.
1414
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
1515
* reserved.
16-
* Copyright (c) 2015 Research Organization for Information Science
16+
* Copyright (c) 2015-2017 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
1818
* $COPYRIGHT$
1919
*
@@ -45,8 +45,7 @@ static const char FUNC_NAME[] = "MPI_Pack_external_size";
4545
int MPI_Pack_external_size(const char datarep[], int incount,
4646
MPI_Datatype datatype, MPI_Aint *size)
4747
{
48-
opal_convertor_t local_convertor;
49-
size_t length;
48+
int rc = MPI_SUCCESS;
5049

5150
MEMCHECKER(
5251
memchecker_datatype(datatype);
@@ -62,17 +61,7 @@ int MPI_Pack_external_size(const char datarep[], int incount,
6261
}
6362

6463

65-
OBJ_CONSTRUCT(&local_convertor, opal_convertor_t);
66-
67-
/* the resulting convertor will be set to the position ZERO */
68-
opal_convertor_copy_and_prepare_for_recv( ompi_mpi_external32_convertor,
69-
&(datatype->super), incount, NULL,
70-
CONVERTOR_SEND_CONVERSION,
71-
&local_convertor );
72-
73-
opal_convertor_get_unpacked_size( &local_convertor, &length );
74-
*size = (MPI_Aint)length;
75-
OBJ_DESTRUCT( &local_convertor );
76-
77-
return OMPI_SUCCESS;
64+
rc = ompi_datatype_pack_external_size(datarep, incount,
65+
datatype, size);
66+
OMPI_ERRHANDLER_RETURN(rc, MPI_COMM_WORLD, rc, FUNC_NAME);
7867
}

ompi/mpi/c/unpack.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
1212
* Copyright (c) 2006-2013 Cisco Systems, Inc. All rights reserved.
13-
* Copyright (c) 2015 Research Organization for Information Science
13+
* Copyright (c) 2015-2017 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
1515
* $COPYRIGHT$
1616
*
@@ -78,6 +78,7 @@ int MPI_Unpack(const void *inbuf, int insize, int *position,
7878

7979

8080
if( insize > 0 ) {
81+
int ret;
8182
OBJ_CONSTRUCT( &local_convertor, opal_convertor_t );
8283
/* the resulting convertor will be set the the position ZERO */
8384
opal_convertor_copy_and_prepare_for_recv( ompi_mpi_local_convertor, &(datatype->super),
@@ -96,15 +97,15 @@ int MPI_Unpack(const void *inbuf, int insize, int *position,
9697

9798
/* Do the actual unpacking */
9899
iov_count = 1;
99-
rc = opal_convertor_unpack( &local_convertor, &outvec, &iov_count, &size );
100+
ret = opal_convertor_unpack( &local_convertor, &outvec, &iov_count, &size );
100101
*position += size;
101102
OBJ_DESTRUCT( &local_convertor );
102-
103103
/* All done. Note that the convertor returns 1 upon success, not
104-
OMPI_SUCCESS. */
105-
rc = (1 == rc) ? OMPI_SUCCESS : OMPI_ERROR;
104+
OPAL_SUCCESS. */
105+
if (1 != ret) {
106+
rc = OMPI_ERROR;
107+
}
106108
}
107109

108-
OMPI_ERRHANDLER_RETURN((rc == 1) ? OMPI_SUCCESS : OMPI_ERROR,
109-
comm, MPI_ERR_UNKNOWN, FUNC_NAME);
110+
OMPI_ERRHANDLER_RETURN(rc, comm, MPI_ERR_UNKNOWN, FUNC_NAME);
110111
}

0 commit comments

Comments
 (0)