multiplex.c File Reference

Include dependency graph for multiplex.c:

Go to the source code of this file.

Defines

#define ERROR_RETURN(retval)   { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }
#define NUM_ITERS   10000000
#define MAX_TO_ADD   6

Functions

void do_flops (int n)
int multiplex (void)
int main (int argc, char **argv)

Variables

double c = 0.11

Define Documentation

#define ERROR_RETURN ( retval   )     { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }

Definition at line 17 of file multiplex.c.

#define MAX_TO_ADD   6

Definition at line 20 of file multiplex.c.

#define NUM_ITERS   10000000

Definition at line 19 of file multiplex.c.


Function Documentation

void do_flops ( int  n  ) 

Definition at line 23 of file multiplex.c.

00024 {
00025     int i;
00026     double a = 0.5;
00027     double b = 6.2;
00028 
00029     for (i=0; i < n; i++)
00030         c += a * b;
00031     return;
00032 }

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 142 of file multiplex.c.

00143 {
00144 
00145    printf("Using %d iterations\n\n", NUM_ITERS);
00146    printf("Does PAPI_multiplex_init() handle lots of events?\n");
00147    multiplex();
00148    exit(0);
00149 }

Here is the call graph for this function:

int multiplex ( void   ) 

Definition at line 35 of file multiplex.c.

00036 {
00037    int retval, i, EventSet = PAPI_NULL, j = 0;
00038    long long *values;
00039    PAPI_event_info_t pset;
00040    int events[MAX_TO_ADD], number;
00041 
00042    /* Initialize the library */
00043    retval = PAPI_library_init(PAPI_VER_CURRENT);
00044    if (retval != PAPI_VER_CURRENT)
00045    {
00046       printf("Library initialization error! \n");
00047       exit(1);
00048    }
00049 
00050    /* initialize multiplex support */
00051    retval = PAPI_multiplex_init();
00052    if (retval != PAPI_OK)
00053       ERROR_RETURN(retval);
00054 
00055    retval = PAPI_create_eventset(&EventSet);
00056    if (retval != PAPI_OK)
00057       ERROR_RETURN(retval);
00058 
00059    /* convert the event set to a multiplex event set */
00060    retval = PAPI_set_multiplex(EventSet);
00061    if (retval != PAPI_OK)
00062       ERROR_RETURN(retval);
00063 /*
00064    retval = PAPI_add_event(EventSet, PAPI_TOT_INS);
00065    if ((retval != PAPI_OK) && (retval != PAPI_ECNFLCT))
00066       ERROR_RETURN(retval);
00067    printf("Adding %s\n", "PAPI_TOT_INS");
00068 */
00069 
00070    for (i = 0; i < PAPI_MAX_PRESET_EVENTS; i++) 
00071    {
00072       retval = PAPI_get_event_info(i | PAPI_PRESET_MASK, &pset);
00073       if (retval != PAPI_OK)
00074          ERROR_RETURN(retval);
00075 
00076       if ((pset.count) && (pset.event_code != PAPI_TOT_CYC)) 
00077       {
00078          printf("Adding %s\n", pset.symbol);
00079 
00080          retval = PAPI_add_event(EventSet, pset.event_code);
00081          if ((retval != PAPI_OK) && (retval != PAPI_ECNFLCT))
00082             ERROR_RETURN(retval);
00083 
00084          if (retval == PAPI_OK) 
00085             printf("Added %s\n", pset.symbol);
00086          else 
00087             printf("Could not add %s due to resource limitation.\n", 
00088                   pset.symbol);
00089 
00090          if (retval == PAPI_OK) 
00091          {
00092             if (++j >= MAX_TO_ADD)
00093                 break;
00094          }
00095       }
00096    }
00097 
00098    values = (long long *) malloc(MAX_TO_ADD * sizeof(long long));
00099    if (values == NULL)
00100    {
00101       printf("Not enough memory available. \n");
00102       exit(1);
00103    }
00104 
00105    if ((retval=PAPI_start(EventSet)) != PAPI_OK)
00106       ERROR_RETURN(retval);
00107 
00108    do_flops(NUM_ITERS);
00109 
00110    retval = PAPI_stop(EventSet, values);
00111    if (retval != PAPI_OK)
00112       ERROR_RETURN(retval);
00113 
00114    /* get the number of events in the event set */
00115    number=MAX_TO_ADD;
00116    if ( (retval = PAPI_list_events(EventSet, events, &number)) != PAPI_OK)
00117       ERROR_RETURN(retval);
00118 
00119    /* print the read result */
00120    for (i = 0; i < MAX_TO_ADD; i++) 
00121    {
00122       retval = PAPI_get_event_info(events[i], &pset);
00123       if (retval != PAPI_OK)
00124          ERROR_RETURN(retval);
00125       printf("Event name: %s  value: %lld \n", pset.symbol, values[i]);
00126    }
00127 
00128    retval = PAPI_cleanup_eventset(EventSet); 
00129    if (retval != PAPI_OK)
00130       ERROR_RETURN(retval);
00131 
00132    retval = PAPI_destroy_eventset(&EventSet);
00133    if (retval != PAPI_OK)
00134       ERROR_RETURN(retval);
00135    
00136    /* free the resources used by PAPI */
00137    PAPI_shutdown();
00138 
00139    return (0);
00140 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

double c = 0.11

Definition at line 22 of file multiplex.c.


Generated on 8 Sep 2016 for PAPI by  doxygen 1.6.1