PAPIC:PAPI get thr specific.3
From PAPIDocs
Jump to: navigation, search


  • PAPI_get_thr_specific, PAPI_set_thr_specific - Store or retrieve a pointer to a thread specific data structure


'''C Interface'''
#include <papi.h>
int PAPI_get_thr_specific(int tag, void **ptr); 
int PAPI_set_thr_specific(int tag, void *ptr);


In C, PAPI_set_thr_specific will save ptr into an array indexed by tag. PAPI_get_thr_specific will retrieve the pointer from the array with index tag. There are 2 user available locations and tag can be either PAPI_USR1_TLS or PAPI_USR2_TLS. The array mentioned above is managed by PAPI and allocated to each thread which has called PAPI_thread_init. There are no Fortran equivalent functions.


tag -- An identifier, the value of which is either PAPI_USR1_TLS or PAPI_USR2_TLS. This identifier indicates which of several data structures associated with this thread is to be accessed.

ptr -- A pointer to the memory containing the data structure.


PAPI_EINVAL The tag argument is out of range.


There are no known bugs in these functions.


 HighLevelInfo *state = NULL;
if (retval = PAPI_thread_init(pthread_self) != PAPI_OK)
* Do we have the thread specific data setup yet?
if ((retval = PAPI_get_thr_specific(PAPI_USR1_TLS, (void *) &state))
!= PAPI_OK || state == NULL) {
state = (HighLevelInfo *) malloc(sizeof(HighLevelInfo));
if (state == NULL)
return (PAPI_ESYS);
memset(state, 0, sizeof(HighLevelInfo));
state->EventSet = PAPI_NULL;
if ((retval = PAPI_create_eventset(&state->EventSet)) != PAPI_OK)
return (PAPI_ESYS);
if ((retval=PAPI_set_thr_specific(PAPI_USR1_TLS, state))!=PAPI_OK)
return (retval);

See Also

PAPI_register_thread(3), PAPI_thread_init(3), PAPI_thread_id(3)