Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/include/mpir_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ extern MPIR_Thread_info_t MPIR_ThreadInfo;
#define MPIR_IS_THREADED 0
#endif

/* We keep an internal 0-based thread_id to facilitate thread tracking */
int MPIR_thread_id(void);

/* ------------------------------------------------------------ */
/* Global thread model, used for non-performance-critical paths */
/* CONSIDER:
Expand Down
20 changes: 20 additions & 0 deletions src/mpi/init/local_proc_attrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@
=== END_MPI_T_CVAR_INFO_BLOCK ===
*/

static MPL_atomic_int_t next_thread_id = MPL_ATOMIC_INT_T_INITIALIZER(0);
#if defined(MPICH_IS_THREADED) && defined(MPL_TLS)
static MPL_TLS int thread_id;
#else
static int thread_id;
#endif

int MPIR_thread_id(void)
{
/* internally thread_id is 1-based so we can tell whether it is valid */
if (thread_id == 0) {
thread_id = MPL_atomic_fetch_add_int(&next_thread_id, 1) + 1;
}
/* externally thread_id is 0-based, so it could be used as an index */
return (thread_id - 1);
}

int MPII_init_local_proc_attrs(int *p_thread_required)
{
int mpi_errno = MPI_SUCCESS;
Expand All @@ -38,6 +55,9 @@ int MPII_init_local_proc_attrs(int *p_thread_required)
/* We need this inorder to implement IS_THREAD_MAIN */
#if (MPICH_THREAD_LEVEL >= MPI_THREAD_SERIALIZED)
MPID_Thread_self(&MPIR_ThreadInfo.main_thread);

int main_id = MPIR_thread_id();
MPIR_Assert(main_id == 0);
#endif
#endif /* MPICH_IS_THREADED */

Expand Down
1 change: 1 addition & 0 deletions src/mpid/ch4/netmod/ofi/ofi_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ MPL_STATIC_INLINE_PREFIX int MPIDI_OFI_recv_event(int vni, struct fi_cq_tagged_e
MPIR_T_PVAR_COUNTER_INC(MULTINIC, nic_recvd_bytes_count[MPIDI_OFI_REQUEST(rreq, nic_num)],
wc->len);
}
printf("OFI_recv_event: thread_id = %d, count = %ld bytes\n", MPIR_thread_id(), count);
#ifndef MPIDI_CH4_DIRECT_NETMOD
int is_cancelled;
MPIDI_anysrc_try_cancel_partner(rreq, &is_cancelled);
Expand Down
4 changes: 2 additions & 2 deletions test/mpi/threads/perf/mt_pt2pt_msgrate.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#define BUFFER_ALIGNMENT 4096

#define MESSAGE_SIZE 8
#define NUM_MESSAGES 64000
#define WINDOW_SIZE 64
#define NUM_MESSAGES 4
#define WINDOW_SIZE 1

#define ERROR_MARGIN 0.05 /* FIXME: a better margin? */

Expand Down