1 /*
2  * Copyright (C) by Argonne National Laboratory
3  *     See COPYRIGHT in top-level directory
4  */
5 
6 #include "mpiimpl.h"
7 
8 /* -- Begin Profiling Symbol Block for routine MPI_T_category_get_pvars */
9 #if defined(HAVE_PRAGMA_WEAK)
10 #pragma weak MPI_T_category_get_pvars = PMPI_T_category_get_pvars
11 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
12 #pragma _HP_SECONDARY_DEF PMPI_T_category_get_pvars  MPI_T_category_get_pvars
13 #elif defined(HAVE_PRAGMA_CRI_DUP)
14 #pragma _CRI duplicate MPI_T_category_get_pvars as PMPI_T_category_get_pvars
15 #elif defined(HAVE_WEAK_ATTRIBUTE)
16 int MPI_T_category_get_pvars(int cat_index, int len, int indices[])
17     __attribute__ ((weak, alias("PMPI_T_category_get_pvars")));
18 #endif
19 /* -- End Profiling Symbol Block */
20 
21 /* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
22    the MPI routines */
23 #ifndef MPICH_MPI_FROM_PMPI
24 #undef MPI_T_category_get_pvars
25 #define MPI_T_category_get_pvars PMPI_T_category_get_pvars
26 
27 /* any non-MPI functions go here, especially non-static ones */
28 
MPIR_T_category_get_pvars_impl(int cat_index,int len,int indices[])29 int MPIR_T_category_get_pvars_impl(int cat_index, int len, int indices[])
30 {
31     int mpi_errno = MPI_SUCCESS;
32     cat_table_entry_t *cat;
33     int i, num_pvars, count;
34 
35     cat = (cat_table_entry_t *) utarray_eltptr(cat_table, cat_index);
36     num_pvars = utarray_len(cat->pvar_indices);
37     count = len < num_pvars ? len : num_pvars;
38 
39     for (i = 0; i < count; i++) {
40         indices[i] = *(int *) utarray_eltptr(cat->pvar_indices, i);
41     }
42 
43     return mpi_errno;
44 }
45 
46 #endif /* MPICH_MPI_FROM_PMPI */
47 
48 /*@
49 MPI_T_category_get_pvars - Get performance variables in a category
50 
51 Input Parameters:
52 + cat_index - index of the category to be queried, in the range [0,N-1] (integer)
53 - len - the length of the indices array (integer)
54 
55 Output Parameters:
56 . indices - an integer array of size len, indicating performance variable indices (array of integers)
57 
58 .N ThreadSafe
59 
60 .N Errors
61 .N MPI_SUCCESS
62 .N MPI_T_ERR_NOT_INITIALIZED
63 .N MPI_T_ERR_INVALID_INDEX
64 @*/
MPI_T_category_get_pvars(int cat_index,int len,int indices[])65 int MPI_T_category_get_pvars(int cat_index, int len, int indices[])
66 {
67     int mpi_errno = MPI_SUCCESS;
68 
69     MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_T_CATEGORY_GET_PVARS);
70     MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
71     MPIR_T_THREAD_CS_ENTER();
72     MPIR_FUNC_TERSE_ENTER(MPID_STATE_MPI_T_CATEGORY_GET_PVARS);
73 
74     /* Validate parameters */
75 #ifdef HAVE_ERROR_CHECKING
76     {
77         MPID_BEGIN_ERROR_CHECKS;
78         {
79             MPIR_ERRTEST_CAT_INDEX(cat_index, mpi_errno);
80             if (len != 0)
81                 MPIR_ERRTEST_ARGNULL(indices, "indices", mpi_errno);
82         }
83         MPID_END_ERROR_CHECKS;
84     }
85 #endif /* HAVE_ERROR_CHECKING */
86 
87     /* ... body of routine ...  */
88 
89     if (len == 0)
90         goto fn_exit;
91 
92     mpi_errno = MPIR_T_category_get_pvars_impl(cat_index, len, indices);
93     MPIR_ERR_CHECK(mpi_errno);
94 
95     /* ... end of body of routine ... */
96 
97   fn_exit:
98     MPIR_FUNC_TERSE_EXIT(MPID_STATE_MPI_T_CATEGORY_GET_PVARS);
99     MPIR_T_THREAD_CS_EXIT();
100     return mpi_errno;
101 
102   fn_fail:
103     /* --BEGIN ERROR HANDLING-- */
104 #ifdef HAVE_ERROR_CHECKING
105     {
106         mpi_errno =
107             MPIR_Err_create_code(mpi_errno, MPIR_ERR_RECOVERABLE, __func__, __LINE__, MPI_ERR_OTHER,
108                                  "**mpi_t_category_get_pvars",
109                                  "**mpi_t_category_get_pvars %d %d %p", cat_index, len, indices);
110     }
111 #endif
112     mpi_errno = MPIR_Err_return_comm(NULL, __func__, mpi_errno);
113     goto fn_exit;
114     /* --END ERROR HANDLING-- */
115 }
116