Skip to content

Commit e3eb6b5

Browse files
authored
Merge pull request #6683 from bosilca/topic/spc_init
Fixed SPC/MPI_T initialization error.
2 parents 008ab98 + 6c75334 commit e3eb6b5

File tree

8 files changed

+51
-46
lines changed

8 files changed

+51
-46
lines changed

ompi/mpi/man/man3/MPI_T_cvar_handle_alloc.3in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ int MPI_T_cvar_handle_alloc(int \fIcvar_index\fP, void *\fIobj_handle\fP,
2020

2121
int MPI_T_cvar_handle_free(MPI_T_cvar_handle *\fIhandle\fP)
2222

23+
.fi
2324
.SH DESCRIPTION
2425
.ft R
2526
MPI_T_cvar_handle_alloc binds the control variable specified in \fIcvar_index\fP to the MPI

ompi/mpi/man/man3/MPI_T_finalize.3in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <mpi.h>
1616
int MPI_T_finalize(void)
1717

18+
.fi
1819
.SH DESCRIPTION
1920
.ft R
2021
MPI_T_finalize() finalizes the MPI tool information interface and must be called the same

ompi/mpi/man/man3/MPI_T_pvar_handle_alloc.3in

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,28 @@
1515
.SH C Syntax
1616
.nf
1717
#include <mpi.h>
18-
int MPI_T_pvar_handle_alloc(int \fIpvar_index\fP, void *\fIobj_handle\fP,
18+
int MPI_T_pvar_handle_alloc(int \fIsession\fP, int \fIpvar_index\fP, void *\fIobj_handle\fP,
1919
MPI_T_pvar_handle *\fIhandle\fP, int *\fIcount\fP)
2020

21-
int MPI_T_pvar_handle_free(MPI_T_pvar_handle *\fIhandle\fP)
21+
int MPI_T_pvar_handle_free(int \fIsession\fP, MPI_T_pvar_handle *\fIhandle\fP)
2222

2323
.SH DESCRIPTION
2424
.ft R
2525
MPI_T_pvar_handle_alloc binds the performance variable specified in \fIpvar_index\fP to the MPI
26-
object specified in \fIobj_handle\fP. If MPI_T_pvar_get_info returns MPI_T_BIND_NO_OBJECT
27-
as the binding for the variable the \fIobj_handle\fP argument is ignored. The number of
28-
values represented by this performance variable is returned in the \fIcount\fP parameter.
26+
object specified in \fIobj_handle\fP in the session identified by the parameter
27+
\fIsession\fP. The object is passed in the argument \fIobj_handle\fP as an
28+
address to a local variable that stores the object’s handle. If
29+
MPI_T_pvar_get_info returns MPI_T_BIND_NO_OBJECT as the binding
30+
for the variable the \fIobj_handle\fP argument is ignored. The handle
31+
allocated to reference the variable is returned in the argument \fIhandle\fP. Upon successful
32+
return, \fIcount\fP contains the number of elements (of the datatype returned by a previous
33+
MPI_T_PVAR_GET_INFO call) used to represent this variable.
34+
35+
The value of \fIpvar_index\fP should be in the range 0 to \fInum_pvar - 1\fP,
36+
where \fInum_pvar\fP is the number of available performance variables as
37+
determined from a prior call to \fIMPI_T_PVAR_GET_NUM\fP. The type of the
38+
MPI object it references must be consistent with the type returned in the
39+
bind argument in a prior call to \fIMPI_T_PVAR_GET_INFO\fP.
2940

3041
MPI_T_pvar_handle_free frees a handle allocated by MPI_T_pvar_handle_alloc and sets the
3142
\fIhandle\fP argument to MPI_T_PVAR_HANDLE_NULL.
@@ -50,11 +61,12 @@ MPI_T_pvar_handle_free() will fail if:
5061
The MPI Tools interface not initialized
5162
.TP 1i
5263
[MPI_T_ERR_INVALID_HANDLE]
53-
The handle is invalid
64+
The handle is invalid or the handle argument passed in is not associated with the session argument
5465

5566

5667
.SH SEE ALSO
5768
.ft R
5869
.nf
5970
MPI_T_pvar_get_info
71+
MPI_T_pvar_get_num
6072

ompi/mpi/man/man3/MPI_T_pvar_session_create.3in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ int MPI_T_pvar_session_create(MPI_T_pvar_session *\fIsession\fP)
1919

2020
int MPI_T_pvar_session_free(MPI_T_pvar_session *\fIsession\fP)
2121

22+
.fi
2223
.SH DESCRIPTION
2324
.ft R
2425
MPI_T_pvar_session_create creates a session for accessing performance variables. The

ompi/mpi/man/man3/MPI_T_pvar_start.3in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ int MPI_T_pvar_start(MPI_T_pvar_session \fIsession\fP, MPI_T_pvar_handle \fIhand
1919

2020
int MPI_T_pvar_stop(MPI_T_pvar_session \fIsession\fP, MPI_T_pvar_handle \fIhandle\fP)
2121

22+
.fi
2223
.SH INPUT PARAMETERS
2324
.ft R
2425
.TP 1i

ompi/mpi/man/man3/MPI_T_pvar_write.3in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Initial address of storage location for variable value.
3333
.SH DESCRIPTION
3434
.ft R
3535
MPI_T_pvar_write attempts to set the value of the performance variable identified by
36-
the handle specified in \fIhandle\fP in the session specified in \fPsession\fI. The
36+
the handle specified in \fIhandle\fP in the session specified in \fIsession\fP. The
3737
value to be written is specified in \fIbuf\fP. The caller must ensure that the buffer
3838
specified in \fIbuf\fP is large enough to hold the entire value of the performance
3939
variable.

ompi/runtime/ompi_spc.c

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/*
2-
* Copyright (c) 2018 The University of Tennessee and The University
2+
* Copyright (c) 2018-2019 The University of Tennessee and The University
33
* of Tennessee Research Foundation. All rights
44
* reserved.
55
*
66
* Copyright (c) 2018 Cisco Systems, Inc. All rights reserved
77
* Copyright (c) 2018 Research Organization for Information Science
88
* and Technology (RIST). All rights reserved.
9+
* Copyright (c) 2019 Mellanox Technologies, Inc.
10+
* All rights reserved.
911
* $COPYRIGHT$
1012
*
1113
* Additional copyrights may follow
@@ -20,10 +22,8 @@ opal_timer_t sys_clock_freq_mhz = 0;
2022
static void ompi_spc_dump(void);
2123

2224
/* Array for converting from SPC indices to MPI_T indices */
23-
OMPI_DECLSPEC int mpi_t_offset = -1;
24-
OMPI_DECLSPEC bool mpi_t_enabled = false;
25-
26-
OPAL_DECLSPEC ompi_communicator_t *ompi_spc_comm = NULL;
25+
static bool mpi_t_enabled = false;
26+
static ompi_communicator_t *ompi_spc_comm = NULL;
2727

2828
typedef struct ompi_spc_event_t {
2929
const char* counter_name;
@@ -185,6 +185,8 @@ static int ompi_spc_notify(mca_base_pvar_t *pvar, mca_base_pvar_event_t event, v
185185
return MPI_SUCCESS;
186186
}
187187

188+
index = (int)(uintptr_t)pvar->ctx; /* Convert from MPI_T pvar index to SPC index */
189+
188190
/* For this event, we need to set count to the number of long long type
189191
* values for this counter. All SPC counters are one long long, so we
190192
* always set count to 1.
@@ -194,14 +196,10 @@ static int ompi_spc_notify(mca_base_pvar_t *pvar, mca_base_pvar_event_t event, v
194196
}
195197
/* For this event, we need to turn on the counter */
196198
else if(MCA_BASE_PVAR_HANDLE_START == event) {
197-
/* Convert from MPI_T pvar index to SPC index */
198-
index = pvar->pvar_index - mpi_t_offset;
199199
SET_SPC_BIT(ompi_spc_attached_event, index);
200200
}
201201
/* For this event, we need to turn off the counter */
202202
else if(MCA_BASE_PVAR_HANDLE_STOP == event) {
203-
/* Convert from MPI_T pvar index to SPC index */
204-
index = pvar->pvar_index - mpi_t_offset;
205203
CLEAR_SPC_BIT(ompi_spc_attached_event, index);
206204
}
207205

@@ -231,7 +229,7 @@ static int ompi_spc_get_count(const struct mca_base_pvar_t *pvar, void *value, v
231229
}
232230

233231
/* Convert from MPI_T pvar index to SPC index */
234-
int index = pvar->pvar_index - mpi_t_offset;
232+
int index = (int)(uintptr_t)pvar->ctx;
235233
/* Set the counter value to the current SPC value */
236234
*counter_value = (long long)ompi_spc_events[index].value;
237235
/* If this is a timer-based counter, convert from cycles to microseconds */
@@ -276,7 +274,7 @@ void ompi_spc_events_init(void)
276274
*/
277275
void ompi_spc_init(void)
278276
{
279-
int i, j, ret, found = 0, all_on = 0;
277+
int i, j, ret, found = 0, all_on = 0, matched = 0;
280278

281279
/* Initialize the clock frequency variable as the CPU's frequency in MHz */
282280
sys_clock_freq_mhz = opal_timer_base_get_freq() / 1000000;
@@ -296,52 +294,43 @@ void ompi_spc_init(void)
296294
}
297295
}
298296

299-
/* Turn on only the counters that were specified in the MCA parameter */
300297
for(i = 0; i < OMPI_SPC_NUM_COUNTERS; i++) {
301-
if(all_on) {
302-
SET_SPC_BIT(ompi_spc_attached_event, i);
303-
mpi_t_enabled = true;
304-
found++;
305-
} else {
306-
/* Note: If no arguments were given, this will be skipped */
298+
/* Reset all timer-based counters */
299+
CLEAR_SPC_BIT(ompi_spc_timer_event, i);
300+
matched = all_on;
301+
302+
if( !matched ) {
303+
/* Turn on only the counters that were specified in the MCA parameter */
307304
for(j = 0; j < num_args; j++) {
308305
if( 0 == strcmp(ompi_spc_events_names[i].counter_name, arg_strings[j]) ) {
309-
SET_SPC_BIT(ompi_spc_attached_event, i);
310-
mpi_t_enabled = true;
311-
found++;
306+
matched = 1;
312307
break;
313308
}
314309
}
315310
}
316311

317-
/* ########################################################################
318-
* ################## Add Timer-Based Counter Enums Here ##################
319-
* ########################################################################
320-
*/
321-
CLEAR_SPC_BIT(ompi_spc_timer_event, i);
312+
if (matched) {
313+
SET_SPC_BIT(ompi_spc_attached_event, i);
314+
mpi_t_enabled = true;
315+
found++;
316+
}
322317

323318
/* Registers the current counter as an MPI_T pvar regardless of whether it's been turned on or not */
324319
ret = mca_base_pvar_register("ompi", "runtime", "spc", ompi_spc_events_names[i].counter_name, ompi_spc_events_names[i].counter_description,
325320
OPAL_INFO_LVL_4, MPI_T_PVAR_CLASS_SIZE,
326321
MCA_BASE_VAR_TYPE_UNSIGNED_LONG_LONG, NULL, MPI_T_BIND_NO_OBJECT,
327322
MCA_BASE_PVAR_FLAG_READONLY | MCA_BASE_PVAR_FLAG_CONTINUOUS,
328-
ompi_spc_get_count, NULL, ompi_spc_notify, NULL);
329-
330-
/* Check to make sure that ret is a valid index and not an error code.
331-
*/
332-
if( ret >= 0 ) {
333-
if( mpi_t_offset == -1 ) {
334-
mpi_t_offset = ret;
335-
}
336-
}
337-
if( (ret < 0) || (ret != (mpi_t_offset + found - 1)) ) {
323+
ompi_spc_get_count, NULL, ompi_spc_notify, (void*)(uintptr_t)i);
324+
if( ret < 0 ) {
338325
mpi_t_enabled = false;
339326
opal_show_help("help-mpi-runtime.txt", "spc: MPI_T disabled", true);
340327
break;
341328
}
342329
}
343-
/* If this is a timer event, sent the corresponding timer_event entry to 1 */
330+
331+
/* If this is a timer event, set the corresponding timer_event entry */
344332
SET_SPC_BIT(ompi_spc_timer_event, OMPI_SPC_MATCH_TIME);
333+
345334
opal_argv_free(arg_strings);
346335
}
347336

test/spc/spc_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ int main(int argc, char **argv)
4444
char name[256], description[256];
4545

4646
/* Counter names to be read by ranks 0 and 1 */
47-
char *counter_names[] = { "runtime_spc_OMPI_BYTES_SENT_USER",
48-
"runtime_spc_OMPI_BYTES_RECEIVED_USER" };
47+
char *counter_names[] = { "runtime_spc_OMPI_SPC_BYTES_SENT_USER",
48+
"runtime_spc_OMPI_SPC_BYTES_RECEIVED_USER" };
4949

5050
MPI_Init(NULL, NULL);
5151
MPI_result = MPI_T_init_thread(MPI_THREAD_SINGLE, &provided);

0 commit comments

Comments
 (0)