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) 2009 Oak Ridge National Labs. All rights reserved.
14 * Copyright (c) 2013 Los Alamos National Security, LLC. All rights
15 * reserved.
16 * Copyright (c) 2015 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
27 #include "ompi/mpi/c/bindings.h"
28 #include "ompi/runtime/params.h"
29 #include "ompi/communicator/communicator.h"
30 #include "ompi/errhandler/errhandler.h"
31 #include "ompi/datatype/ompi_datatype.h"
32 #include "ompi/memchecker.h"
33
34 #if OMPI_BUILD_MPI_PROFILING
35 #if OPAL_HAVE_WEAK_SYMBOLS
36 #pragma weak MPI_Type_size = PMPI_Type_size
37 #endif
38 #define MPI_Type_size PMPI_Type_size
39 #endif
40
41 static const char FUNC_NAME[] = "MPI_Type_size";
42
43 int MPI_Type_size(MPI_Datatype type, int *size)
44 {
45 size_t type_size;
46 MEMCHECKER(
47 memchecker_datatype(type);
48 );
49
50 OPAL_CR_NOOP_PROGRESS();
51
52 if (MPI_PARAM_CHECK) {
53 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
54 if (NULL == type || MPI_DATATYPE_NULL == type) {
55 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_TYPE, FUNC_NAME);
56 } else if (NULL == size) {
57 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG, FUNC_NAME);
58 }
59 }
60
61 opal_datatype_type_size ( &type->super, &type_size);
62
63 *size = (type_size > (size_t) INT_MAX) ? MPI_UNDEFINED : (int) type_size;
64
65 return MPI_SUCCESS;
66 }