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) 2006 Cisco Systems, Inc. All rights reserved.
14 * Copyright (c) 2012-2016 Los Alamos National Security, LLC. All rights
15 * reserved.
16 * Copyright (c) 2014-2017 Research Organization for Information Science
17 * and Technology (RIST). All rights reserved.
18 * Copyright (c) 2017-2018 FUJITSU LIMITED. All rights reserved.
19 * $COPYRIGHT$
20 *
21 * Additional copyrights may follow
22 *
23 * $HEADER$
24 */
25 #include "ompi_config.h"
26 #include <stdio.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/mca/pml/pml.h"
33 #include "ompi/request/request.h"
34 #include "ompi/memchecker.h"
35
36 #if OMPI_BUILD_MPI_PROFILING
37 #if OPAL_HAVE_WEAK_SYMBOLS
38 #pragma weak MPI_Startall = PMPI_Startall
39 #endif
40 #define MPI_Startall PMPI_Startall
41 #endif
42
43 static const char FUNC_NAME[] = "MPI_Startall";
44
45
46 int MPI_Startall(int count, MPI_Request requests[])
47 {
48 int i, j;
49 int ret = OMPI_SUCCESS;
50 ompi_request_start_fn_t start_fn = NULL;
51
52 MEMCHECKER(
53 for (j = 0; j < count; j++){
54 memchecker_request(&requests[j]);
55 }
56 );
57
58 if ( MPI_PARAM_CHECK ) {
59 int rc = MPI_SUCCESS;
60 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
61 if (NULL == requests) {
62 rc = MPI_ERR_REQUEST;
63 } else if (count < 0) {
64 rc = MPI_ERR_ARG;
65 } else {
66 for (i = 0; i < count; ++i) {
67 if (NULL == requests[i] ||
68 ! requests[i]->req_persistent ||
69 (OMPI_REQUEST_PML != requests[i]->req_type &&
70 OMPI_REQUEST_COLL != requests[i]->req_type &&
71 OMPI_REQUEST_NOOP != requests[i]->req_type)) {
72 rc = MPI_ERR_REQUEST;
73 break;
74 }
75 }
76 }
77 OMPI_ERRHANDLER_CHECK(rc, MPI_COMM_WORLD, rc, FUNC_NAME);
78 }
79
80 OPAL_CR_ENTER_LIBRARY();
81
82 for (i = 0, j = -1; i < count; ++i) {
83 /* Per MPI it is invalid to start an active request */
84 if (OMPI_REQUEST_INACTIVE != requests[i]->req_state) {
85 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_REQUEST, FUNC_NAME);
86 }
87
88 if (OMPI_REQUEST_NOOP == requests[i]->req_type) {
89 /**
90 * We deal with a MPI_PROC_NULL request. If the request is
91 * already active, fall back to the error case in the default.
92 * Otherwise, mark it active so we can correctly handle it in
93 * the wait*.
94 */
95 requests[i]->req_state = OMPI_REQUEST_ACTIVE;
96 }
97
98 /* Call a req_start callback function per requests which have the
99 * same req_start value. */
100 if (requests[i]->req_start != start_fn) {
101 if (NULL != start_fn && i != 0) {
102 start_fn(i - j, requests + j);
103 }
104 start_fn = requests[i]->req_start;
105 j = i;
106 }
107 }
108
109 if (NULL != start_fn) {
110 start_fn(i - j, requests + j);
111 }
112
113 OPAL_CR_EXIT_LIBRARY();
114 return ret;
115 }
116