Why do I need to initi PAPI twice?

Why do I need to initi PAPI twice?

Postby faheemkhan » Thu Aug 22, 2013 6:26 am

Hi there,

I'm sorry if this comes as double posting but my previous post somehow disappeared.

Looking at fork.c, I'm wondering why do I need to init PAPI twice? i.e. once in the parent thread and then again in the child thread?

My problem is this... I would like to fork a child and execute some benchmarks and collect data ONLY for those benchmarks executed inside the forked child.

Here's what I am doing right now:

Code: Select all
int main(int argc, char* argv[], char** envp){

   static char* bench;
   pid_t pid;
   int status, ret, i;
   long long events[NUM_EVENTS];
   int br_taken = PAPI_BR_TKN;
   int br_exec = PAPI_BR_CN;
   long long values[NUM_EVENTS];


   for (i=0; i<NUM_EVENTS; i++){
      values[i] = 0;
   }


   bench = argv[1];

   printf("\nParent PID: %d\n", getpid());

   //let's add events to count
      events[0] = br_taken;
      events[1] = br_exec;

   //fork a child for the executable
   if(fork() == 0){

      //init PAPI for child
      initialize_papi("forked PAPI init");
      PAPI_reset(*events);

      ret = PAPI_start_counters((int *) events, NUM_EVENTS);
      if(ret != PAPI_OK){
            printf("Starting Papi coutners failed: %d ", ret);
         }

      execve(bench, argv, envp);

   }else{
      wait(&status);

      if (WEXITSTATUS(status) != 0)
         err_message("WEXITSTATUS is :%d", &status);

      ret =PAPI_read_counters(values, NUM_EVENTS);
      if(ret != PAPI_OK) {
         printf("reading values failed: %d", ret);
      }
   }
   //terminate papi, release all resources
   PAPI_shutdown();

   printf("\n\ncount1 = %10llu and count2 =%10llu \n", values[0], values[1]);
}




am I doing something wrong here?
faheemkhan
 
Posts: 3
Joined: Thu Aug 22, 2013 6:05 am

Re: Why do I need to initi PAPI twice?

Postby faheemkhan » Thu Aug 22, 2013 7:08 am

ok after some more reading up... it appears I need to use Ptrace.
faheemkhan
 
Posts: 3
Joined: Thu Aug 22, 2013 6:05 am


Return to Classic PAPI

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron