1 /*
2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3  *                         University Research and Technology
4  *                         Corporation.  All rights reserved.
5  * Copyright (c) 2004-2005 The University of Tennessee and The University
6  *                         of Tennessee Research Foundation.  All rights
7  *                         reserved.
8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9  *                         University of Stuttgart.  All rights reserved.
10  * Copyright (c) 2004-2005 The Regents of the University of California.
11  *                         All rights reserved.
12  * Copyright (c) 2011-2012 Cisco Systems, Inc.  All rights reserved.
13  * Copyright (c) 2015-2017 Research Organization for Information Science
14  *                         and Technology (RIST). All rights reserved.
15  * $COPYRIGHT$
16  *
17  * Additional copyrights may follow
18  *
19  * $HEADER$
20  */
21 
22 #include "ompi_config.h"
23 
24 #include "ompi/mpi/fortran/mpif-h/bindings.h"
25 #include "ompi/constants.h"
26 #include "ompi/communicator/communicator.h"
27 #include "ompi/mpi/fortran/base/constants.h"
28 #include "ompi/mpi/fortran/base/fortran_base_strings.h"
29 
30 #if OMPI_BUILD_MPI_PROFILING
31 #if OPAL_HAVE_WEAK_SYMBOLS
32 #pragma weak PMPI_UNPACK_EXTERNAL = ompi_unpack_external_f
33 #pragma weak pmpi_unpack_external = ompi_unpack_external_f
34 #pragma weak pmpi_unpack_external_ = ompi_unpack_external_f
35 #pragma weak pmpi_unpack_external__ = ompi_unpack_external_f
36 
37 #pragma weak PMPI_Unpack_external_f = ompi_unpack_external_f
38 #pragma weak PMPI_Unpack_external_f08 = ompi_unpack_external_f
39 #else
40 OMPI_GENERATE_F77_BINDINGS (PMPI_UNPACK_EXTERNAL,
41                            pmpi_unpack_external,
42                            pmpi_unpack_external_,
43                            pmpi_unpack_external__,
44                            pompi_unpack_external_f,
45                             (char *datarep, char *inbuf, MPI_Aint *insize, MPI_Aint *position, char *outbuf, MPI_Fint *outcount, MPI_Fint *datatype, MPI_Fint *ierr, int datarep_len),
46                             (datarep, inbuf, insize, position, outbuf, outcount, datatype, ierr, datarep_len) )
47 #endif
48 #endif
49 
50 #if OPAL_HAVE_WEAK_SYMBOLS
51 #pragma weak MPI_UNPACK_EXTERNAL = ompi_unpack_external_f
52 #pragma weak mpi_unpack_external = ompi_unpack_external_f
53 #pragma weak mpi_unpack_external_ = ompi_unpack_external_f
54 #pragma weak mpi_unpack_external__ = ompi_unpack_external_f
55 
56 #pragma weak MPI_Unpack_external_f = ompi_unpack_external_f
57 #pragma weak MPI_Unpack_external_f08 = ompi_unpack_external_f
58 #else
59 #if ! OMPI_BUILD_MPI_PROFILING
60 OMPI_GENERATE_F77_BINDINGS (MPI_UNPACK_EXTERNAL,
61                            mpi_unpack_external,
62                            mpi_unpack_external_,
63                            mpi_unpack_external__,
64                            ompi_unpack_external_f,
65                             (char *datarep, char *inbuf, MPI_Aint *insize, MPI_Aint *position, char *outbuf, MPI_Fint *outcount, MPI_Fint *datatype, MPI_Fint *ierr, int datarep_len),
66                             (datarep, inbuf, insize, position, outbuf, outcount, datatype, ierr, datarep_len) )
67 #else
68 #define ompi_unpack_external_f pompi_unpack_external_f
69 #endif
70 #endif
71 
72 
ompi_unpack_external_f(char * datarep,char * inbuf,MPI_Aint * insize,MPI_Aint * position,char * outbuf,MPI_Fint * outcount,MPI_Fint * datatype,MPI_Fint * ierr,int datarep_len)73 void ompi_unpack_external_f (char *datarep, char *inbuf, MPI_Aint *insize,
74 			    MPI_Aint *position, char *outbuf,
75 			    MPI_Fint *outcount, MPI_Fint *datatype,
76 			    MPI_Fint *ierr, int datarep_len)
77 {
78     int ret, c_ierr;
79     char *c_datarep;
80     MPI_Datatype c_type;
81 
82     c_type = PMPI_Type_f2c(*datatype);
83 
84     /* Convert the fortran string */
85 
86     if (OMPI_SUCCESS != (ret = ompi_fortran_string_f2c(datarep, datarep_len,
87                                                        &c_datarep))) {
88         c_ierr = OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, ret,
89                                         "MPI_PACK_EXTERNAL");
90         if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr);
91         return;
92     }
93 
94     c_ierr = PMPI_Unpack_external(c_datarep, inbuf,
95                                  *insize,
96                                  position,
97                                  OMPI_F2C_BOTTOM(outbuf),
98                                  OMPI_FINT_2_INT(*outcount),
99                                  c_type);
100     if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr);
101 
102     free(c_datarep);
103 }
104