#include < pcl.h>
int
main(int argc, char **argv)
{
PCL_CNT_TYPE i_result[2];
PCL_FP_CNT_TYPE fp_result[2];
int counter_list[2], res;
unsigned int flags;
PCL_DESCR_TYPE descr;
if(PCLinit(&descr) != PCL_SUCCESS)
printf("unable to allocate PCL handle\n");
/* define events to be measured
(Floating point instructions and cycles)
*/
counter_list[0] = PCL_FP_INSTR;
counter_list[1] = PCL_CYCLES;
/* define in what mode to count (only user mode) */
flags = PCL_MODE_USER;
/* query for functionality */
if ((res = PCLquery(descr, counter_list, 2, flags)) != PCL_SUCCESS)
printf("these two events are not available on this system\n");
else
{
/* start counting */
if ((res = PCLstart(descr, counter_list, 2, flags)) != PCL_SUCCESS)
{
printf("problem with starting two events\n");
exit(1);
}
/* do work */
/* you should include here your piece of code to measure */
/* stop counting */
if ((res = PCLstop(descr, i_result, fp_result, 2)) != PCL_SUCCESS)
printf("problem with stopping two events\n");
else
printf("%15.0f FP-instructions in %15.0f cycles\n",
(double) i_result[0], (double) i_result[1]);
}
if(PCLexit(descr) != PCL_SUCCESS)
printf("unable to deallocate PCL handle\n");
return 0;
}
PROGRAM PCL_test
C*** declarations
INCLUDE 'pclh.f'
INTEGER counter_list(1), flags, res
INTEGER*8 i_result, descr
REAL*8 fp_result
INTEGER PCLquery, PCLstart, PCLstop
EXTERNAL PCLquery, PCLstart, PCLstop
res = PCLinit(descr)
IF(res .NE. PCL_SUCCESS) WRITE(*,*) 'error in PCLinit'
C*** count for user mode
flags = PCL_MODE_USER
C*** count cycles
counter_list(1) = PCL_CYCLES
C*** check if event is available
res = PCLquery(descr, counter_list, 1, flags)
IF(res .EQ. PCL_SUCCESS) THEN
C*** start counting
IF(PCLstart(descr, counter_list, 1, flags) .NE. PCL_SUCCESS) THEN
WRITE(*,*) 'problem with starting event ',counter_list(1)
ENDIF
C*** do some work
C*** stop counting
IF(PCLstop(descr, i_result,fp_result,1) .NE. PCL_SUCCESS) THEN
WRITE(*,*) 'problem with stopping event ',counter_list(1)
ELSE
WRITE(*,*) 'result: ', i_result
ENDIF
ELSE
C*** event not supported
WRITE(*,1001) counter_list(1), res
ENDIF
res = PCLexit(descr)
IF(res .NE. PCL_SUCCESS) WRITE(*,*) 'error in PCLexit'
STOP
END
// import PCL class description
import PCL;
public class pcl_jtest
{
// main program
public static void main(String[] args)
{
int i;
PCL pcl = new PCL(); // instantiate PCL
int mode = pcl.PCL_MODE_USER_SYSTEM;// count mode
int[] events = new int[1]; // events; array required
long[] result = new long[1]; // int results; array required
double[] fp_result = new double[1]; // fp results; array required
long descr = 0;
if(pcl.PCLinit(descr) != pcl.PCL_SUCCESS)
System.out.println("problem with PCLinit");
events[0] = pcl.PCL_ELAPSED_CYCLES;
if(pcl.PCLquery(descr, events, 1, mode) == pcl.PCL_SUCCESS)
{
// start counting
if(pcl.PCLstart(descr, events, 1, mode) != pcl.PCL_SUCCESS)
System.out.println("problem with starting event");
// here comes your code to measure
// stop counting
if(pcl.PCLstop(descr, i_result,fp_result,1) != pcl.PCL_SUCCESS)
System.out.println("problem with stopping event");
// print result for event i
System.out.println(pcl.PCLeventname(events[0])
+ ":" + i_result[0]);
}
if(pcl.PCLexit(descr) != pcl.PCL_SUCCESS)
System.out.println("problem with PCLexit");
}
}