Skip to content

Commit 21f59b8

Browse files
committed
Merge pull request #1509 from ggouaillardet/topic/external_support2
Add support for packing to/from external32 format.
2 parents 7eca2f9 + 5932287 commit 21f59b8

16 files changed

+715
-185
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/mpi/c/pack.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2005 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-2008 High Performance Computing Center Stuttgart,
@@ -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;
48+
int rc = MPI_SUCCESS;
4949
opal_convertor_t local_convertor;
5050
struct iovec invec;
5151
unsigned int iov_count;
@@ -67,9 +67,11 @@ int MPI_Pack(const void *inbuf, int incount, MPI_Datatype datatype,
6767
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME);
6868
} else if (outsize < 0) {
6969
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME);
70-
} else if (MPI_DATATYPE_NULL == datatype || NULL == datatype) {
71-
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TYPE, FUNC_NAME);
7270
}
71+
OMPI_CHECK_DATATYPE_FOR_SEND(rc, datatype, incount);
72+
OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME);
73+
OMPI_CHECK_USER_BUFFER(rc, inbuf, datatype, incount);
74+
OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME);
7375
}
7476

7577
OPAL_CR_ENTER_LIBRARY();

ompi/mpi/c/pack_external.c

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2005 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-2008 High Performance Computing Center Stuttgart,
@@ -46,11 +46,7 @@ int MPI_Pack_external(const char datarep[], const void *inbuf, int incount,
4646
MPI_Datatype datatype, void *outbuf,
4747
MPI_Aint outsize, MPI_Aint *position)
4848
{
49-
int rc;
50-
opal_convertor_t local_convertor;
51-
struct iovec invec;
52-
unsigned int iov_count;
53-
size_t size;
49+
int rc = MPI_SUCCESS;
5450

5551
MEMCHECKER(
5652
memchecker_datatype(datatype);
@@ -65,46 +61,21 @@ int MPI_Pack_external(const char datarep[], const void *inbuf, int incount,
6561
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COUNT, FUNC_NAME);
6662
} else if (outsize < 0) {
6763
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG, FUNC_NAME);
68-
} else if (MPI_DATATYPE_NULL == datatype || NULL == datatype) {
69-
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_TYPE, FUNC_NAME);
7064
}
65+
OMPI_CHECK_DATATYPE_FOR_SEND(rc, datatype, incount);
66+
OMPI_ERRHANDLER_CHECK(rc, MPI_COMM_WORLD, rc, FUNC_NAME);
67+
OMPI_CHECK_USER_BUFFER(rc, inbuf, datatype, incount);
68+
OMPI_ERRHANDLER_CHECK(rc, MPI_COMM_WORLD, rc, FUNC_NAME);
7169
}
7270

7371
OPAL_CR_ENTER_LIBRARY();
7472

75-
OBJ_CONSTRUCT(&local_convertor, opal_convertor_t);
76-
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-
OPAL_CR_EXIT_LIBRARY();
91-
return OMPI_ERRHANDLER_INVOKE( MPI_COMM_WORLD, MPI_ERR_TRUNCATE, FUNC_NAME );
92-
}
93-
94-
/* Prepare the iovec with all informations */
95-
invec.iov_base = (char*) outbuf + (*position);
96-
invec.iov_len = size;
97-
98-
/* Do the actual packing */
99-
iov_count = 1;
100-
rc = opal_convertor_pack( &local_convertor, &invec, &iov_count, &size );
101-
*position += size;
102-
OBJ_DESTRUCT( &local_convertor );
73+
rc = ompi_datatype_pack_external(datarep, inbuf, incount,
74+
datatype, outbuf,
75+
outsize, position);
10376

10477
OPAL_CR_EXIT_LIBRARY();
10578

106-
/* All done. Note that the convertor returns 1 upon success, not
107-
OMPI_SUCCESS. */
108-
OMPI_ERRHANDLER_RETURN((rc == 1) ? OMPI_SUCCESS : OMPI_ERROR,
109-
MPI_COMM_WORLD, MPI_ERR_UNKNOWN, FUNC_NAME);
79+
OMPI_ERRHANDLER_RETURN((OMPI_SUCCESS == rc) ? OMPI_SUCCESS : OMPI_ERROR,
80+
MPI_COMM_WORLD, rc, FUNC_NAME);
11081
}

ompi/mpi/c/pack_external_size.c

Lines changed: 7 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-2016 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);
@@ -63,18 +62,10 @@ int MPI_Pack_external_size(const char datarep[], int incount,
6362

6463
OPAL_CR_ENTER_LIBRARY();
6564

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

ompi/mpi/c/unpack.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
33
* University Research and Technology
44
* Corporation. All rights reserved.
5-
* Copyright (c) 2004-2005 The University of Tennessee and The University
5+
* Copyright (c) 2004-2016 The University of Tennessee and The University
66
* of Tennessee Research Foundation. All rights
77
* reserved.
88
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
@@ -43,7 +43,7 @@ int MPI_Unpack(const void *inbuf, int insize, int *position,
4343
void *outbuf, int outcount, MPI_Datatype datatype,
4444
MPI_Comm comm)
4545
{
46-
int rc = 1;
46+
int rc = MPI_SUCCESS;
4747
opal_convertor_t local_convertor;
4848
struct iovec outvec;
4949
unsigned int iov_count;
@@ -70,9 +70,10 @@ int MPI_Unpack(const void *inbuf, int insize, int *position,
7070
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME);
7171
}
7272

73-
if (MPI_DATATYPE_NULL == datatype || NULL == datatype) {
74-
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TYPE, FUNC_NAME);
75-
}
73+
OMPI_CHECK_DATATYPE_FOR_RECV(rc, datatype, outcount);
74+
OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME);
75+
OMPI_CHECK_USER_BUFFER(rc, outbuf, datatype, outcount);
76+
OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME);
7677
}
7778

7879
OPAL_CR_ENTER_LIBRARY();
@@ -103,12 +104,11 @@ int MPI_Unpack(const void *inbuf, int insize, int *position,
103104

104105
/* All done. Note that the convertor returns 1 upon success, not
105106
OMPI_SUCCESS. */
106-
107+
rc = (1 == rc) ? OMPI_SUCCESS : OMPI_ERROR;
107108
}
108109

109110
OPAL_CR_EXIT_LIBRARY();
110111

111112
OMPI_ERRHANDLER_RETURN((rc == 1) ? OMPI_SUCCESS : OMPI_ERROR,
112113
comm, MPI_ERR_UNKNOWN, FUNC_NAME);
113-
114114
}

0 commit comments

Comments
 (0)