00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 #include "converse.h"
00019 
00020 #ifdef CMK_ORIGIN2000
00021 int start_counters(int e0, int e1);
00022 int read_counters(int e0, long long *c0, int e1, long long *c1);
00023 #elif CMK_HAS_COUNTER_PAPI
00024 #include <papi.h>
00025 #endif
00026 
00027 void CmiInitCounters(void)
00028 {
00029 #if CMK_HAS_COUNTER_PAPI
00030   int retval = PAPI_library_init(PAPI_VER_CURRENT);
00031   if (retval != PAPI_VER_CURRENT && retval > 0) { 
00032     printf("PAPI library version mismatch!\n"); 
00033   }
00034 #endif
00035 }
00036 
00037 void CmiStartCounters(int events[], int numEvents)
00038 {
00039 #ifdef CMK_ORIGIN2000
00040   CmiAssert(numEvents >= 2);
00041   if (start_counters(events[0], events[1]) <0) {
00042       perror("start_counters");;
00043   }
00044 #elif CMK_HAS_COUNTER_PAPI
00045   if (PAPI_start_counters(events, numEvents) != PAPI_OK) {
00046       CmiAbort("Failed to read PAPI counters!!\n");
00047   }
00048 #else
00049   
00050   
00051 #endif
00052 }
00053 
00054 
00055 void CmiStopCounters(int events[], CMK_TYPEDEF_INT8 values[], int numEvents)
00056 {
00057 #ifdef CMK_ORIGIN2000
00058   CmiAssert(numEvents >= 2);
00059   if (read_counters(events[0], &values[0], events[1], &values[1]) < 0) perror("read_counters");
00060 #elif CMK_HAS_COUNTER_PAPI
00061   if (PAPI_stop_counters(values, 2) != PAPI_OK) {
00062     CmiAbort("Failed to read PAPI counters!\n");
00063   }
00064 #else
00065   
00066   int i;
00067   for (i=0; i<numEvents; i++) values[i] = 0;
00068 #endif
00069 }
00070 
00071