1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
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-2005 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) 2013 Los Alamos National Security, LLC. All rights
14 * reserved.
15 * Copyright (c) 2015 Research Organization for Information Science
16 * and Technology (RIST). All rights reserved.
17 * $COPYRIGHT$
18 *
19 * Additional copyrights may follow
20 *
21 * $HEADER$
22 */
23
24 #include "ompi_config.h"
25
26 #include "ompi/mpi/c/bindings.h"
27 #include "ompi/runtime/params.h"
28 #include "ompi/communicator/communicator.h"
29 #include "ompi/errhandler/errhandler.h"
30 #include "ompi/datatype/ompi_datatype.h"
31 #include "ompi/memchecker.h"
32
33 #if OMPI_BUILD_MPI_PROFILING
34 #if OPAL_HAVE_WEAK_SYMBOLS
35 #pragma weak MPI_Type_create_struct = PMPI_Type_create_struct
36 #endif
37 #define MPI_Type_create_struct PMPI_Type_create_struct
38 #endif
39
40 static const char FUNC_NAME[] = "MPI_Type_create_struct";
41
42
MPI_Type_create_struct(int count,const int array_of_blocklengths[],const MPI_Aint array_of_displacements[],const MPI_Datatype array_of_types[],MPI_Datatype * newtype)43 int MPI_Type_create_struct(int count,
44 const int array_of_blocklengths[],
45 const MPI_Aint array_of_displacements[],
46 const MPI_Datatype array_of_types[],
47 MPI_Datatype *newtype)
48 {
49 int i, rc;
50
51 if ( count > 0 ) {
52 for ( i = 0; i < count; i++ ) {
53 MEMCHECKER(
54 memchecker_datatype(array_of_types[i]);
55 );
56 }
57 }
58
59 if( MPI_PARAM_CHECK ) {
60 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
61 if( count < 0 ) {
62 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COUNT,
63 FUNC_NAME);
64 } else if( (count > 0) && (NULL == array_of_blocklengths ||
65 NULL == array_of_displacements ||
66 NULL == array_of_types) ) {
67 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG, FUNC_NAME);
68 } else if (NULL == newtype) {
69 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_TYPE, FUNC_NAME);
70 }
71 for ( i = 0; i < count; i++ ){
72 if (NULL == array_of_types[i] ||
73 MPI_DATATYPE_NULL == array_of_types[i]) {
74 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_TYPE,
75 FUNC_NAME);
76 } else if (array_of_blocklengths[i] < 0) {
77 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG,
78 FUNC_NAME);
79 }
80 }
81 }
82
83 OPAL_CR_ENTER_LIBRARY();
84
85 rc = ompi_datatype_create_struct( count, array_of_blocklengths, array_of_displacements,
86 array_of_types, newtype );
87 if( rc != MPI_SUCCESS ) {
88 ompi_datatype_destroy( newtype );
89 OMPI_ERRHANDLER_RETURN( rc, MPI_COMM_WORLD,
90 rc, FUNC_NAME );
91 }
92
93 {
94 const int* a_i[2] = {&count, array_of_blocklengths};
95
96 ompi_datatype_set_args( *newtype, count + 1, a_i, count, array_of_displacements,
97 count, array_of_types, MPI_COMBINER_STRUCT );
98 }
99
100 OPAL_CR_EXIT_LIBRARY();
101 return MPI_SUCCESS;
102 }
103