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-2010 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) 2010 Cisco Systems, Inc. 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 #include "ompi_config.h"
25 #include <stdio.h>
26 #include <limits.h>
27
28 #include "ompi/mpi/c/bindings.h"
29 #include "ompi/runtime/params.h"
30 #include "ompi/communicator/communicator.h"
31 #include "ompi/errhandler/errhandler.h"
32 #include "ompi/datatype/ompi_datatype.h"
33 #include "ompi/memchecker.h"
34
35 #if OMPI_BUILD_MPI_PROFILING
36 #if OPAL_HAVE_WEAK_SYMBOLS
37 #pragma weak MPI_Get_count = PMPI_Get_count
38 #endif
39 #define MPI_Get_count PMPI_Get_count
40 #endif
41
42 static const char FUNC_NAME[] = "MPI_Get_count";
43
44
45 int MPI_Get_count(const MPI_Status *status, MPI_Datatype datatype, int *count)
46 {
47 size_t size = 0, internal_count;
48 int rc = MPI_SUCCESS;
49
50 OPAL_CR_NOOP_PROGRESS();
51
52 MEMCHECKER(
53 if (status != MPI_STATUSES_IGNORE) {
54 /*
55 * Before checking the complete status, we need to reset the definedness
56 * of the MPI_ERROR-field (single-completion calls wait/test).
57 */
58 opal_memchecker_base_mem_defined((void*)&status->MPI_ERROR, sizeof(int));
59 memchecker_status(status);
60 memchecker_datatype(datatype);
61 }
62 );
63
64 if (MPI_PARAM_CHECK) {
65 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
66 OMPI_CHECK_DATATYPE_FOR_RECV(rc, datatype, 1);
67
68 OMPI_ERRHANDLER_CHECK(rc, MPI_COMM_WORLD, rc, FUNC_NAME);
69 }
70
71 if( ompi_datatype_type_size( datatype, &size ) == MPI_SUCCESS ) {
72 if( size == 0 ) {
73 *count = 0;
74 } else {
75 internal_count = status->_ucount / size; /* count the number of complete datatypes */
76 if( (internal_count * size) != status->_ucount ||
77 internal_count > ((size_t) INT_MAX) ) {
78 *count = MPI_UNDEFINED;
79 } else {
80 *count = (int)internal_count;
81 }
82 }
83 }
84 return MPI_SUCCESS;
85 }