I can attach PAPI to another process created with fork for example. This works fine for me. What I am trying, however, is to create an eventset and attach it to a thread running within the same process.
The first thing I do in my program is to create all threads by entering a short OpenMP section. After that, I init PAPI and also do a PAPI_thread_init with pthread_self as a parameter. After that, I create an event set and add one to it. Now I use PAPI_list_threads to get the threads. I pick one with a different thread id than the master thread. Then I call PAPI_attach with that thread id and this call fails with an invalid argument error. Doing some debugging showed that the syscall in the function check_permissions in the perf_event.c does not succeed.
What am I doing wrong here? Am I using wrong thread identifiers? Do I need more rights (root)? I also found a "perf_event_paranoid" which is 1 on my system? Do I need to change that?