Skip to content

Commit 5932287

Browse files
committed
datatype/[un]pack_external[_size]: move subroutines down to ompi/datatype
so it can be directly used by test/datatype/external32
1 parent 63eec55 commit 5932287

File tree

7 files changed

+173
-196
lines changed

7 files changed

+173
-196
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_external.c

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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);
@@ -74,39 +70,12 @@ int MPI_Pack_external(const char datarep[], const void *inbuf, int incount,
7470

7571
OPAL_CR_ENTER_LIBRARY();
7672

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

10677
OPAL_CR_EXIT_LIBRARY();
10778

108-
/* All done. Note that the convertor returns 1 upon success, not
109-
OMPI_SUCCESS. */
110-
OMPI_ERRHANDLER_RETURN((rc == 1) ? OMPI_SUCCESS : OMPI_ERROR,
111-
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);
11281
}

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_external.c

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ int MPI_Unpack_external (const char datarep[], const void *inbuf, MPI_Aint insiz
4646
MPI_Datatype datatype)
4747
{
4848
int rc = MPI_SUCCESS;
49-
opal_convertor_t local_convertor;
50-
struct iovec outvec;
51-
unsigned int iov_count;
52-
size_t size;
5349

5450
MEMCHECKER(
5551
memchecker_datatype(datatype);
@@ -71,36 +67,12 @@ int MPI_Unpack_external (const char datarep[], const void *inbuf, MPI_Aint insiz
7167

7268
OPAL_CR_ENTER_LIBRARY();
7369

74-
OBJ_CONSTRUCT(&local_convertor, opal_convertor_t);
75-
76-
/* the resulting convertor will be set to the position ZERO */
77-
opal_convertor_copy_and_prepare_for_recv( ompi_mpi_external32_convertor,
78-
&(datatype->super), outcount, outbuf,
79-
0,
80-
&local_convertor );
81-
82-
/* Check for truncation */
83-
opal_convertor_get_packed_size( &local_convertor, &size );
84-
if( (*position + size) > (unsigned int)insize ) {
85-
OBJ_DESTRUCT( &local_convertor );
86-
OPAL_CR_EXIT_LIBRARY();
87-
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_TRUNCATE, FUNC_NAME);
88-
}
89-
90-
/* Prepare the iovec with all informations */
91-
outvec.iov_base = (char*) inbuf + (*position);
92-
outvec.iov_len = size;
93-
94-
/* Do the actual unpacking */
95-
iov_count = 1;
96-
rc = opal_convertor_unpack( &local_convertor, &outvec, &iov_count, &size );
97-
*position += size;
98-
OBJ_DESTRUCT( &local_convertor );
70+
rc = ompi_datatype_unpack_external(datarep, inbuf, insize,
71+
position, outbuf, outcount,
72+
datatype);
9973

10074
OPAL_CR_EXIT_LIBRARY();
10175

102-
/* All done. Note that the convertor returns 1 upon success, not
103-
OMPI_SUCCESS. */
104-
OMPI_ERRHANDLER_RETURN((rc == 1) ? OMPI_SUCCESS : OMPI_ERROR,
105-
MPI_COMM_WORLD, MPI_ERR_UNKNOWN, FUNC_NAME);
76+
OMPI_ERRHANDLER_RETURN((OMPI_SUCCESS == rc) ? OMPI_SUCCESS : OMPI_ERROR,
77+
MPI_COMM_WORLD, rc, FUNC_NAME);
10678
}

0 commit comments

Comments
 (0)