0
votes

I am trying to test out using papi, but I am getting some errors that I don't understand why they're occurring. I couldn't find anything online for them. The code is below

I am using PAPI and C.

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <memory.h>
#include <malloc.h>
#include "papi.h"

#define INDEX 100

static void test_fail(char *file, int line, char *call, int retval);

int main(int argc, char **argv) {
    extern void dummy(void *);
    float matrixa[INDEX][INDEX], matrixb[INDEX][INDEX], mresult[INDEX]    [INDEX];
    float real_time, proc_time, mflops;
    long long flpins;
    int retval, status = 0;
    int i,j,k;
    long_long values[1];

    FILE *file; 
    file = fopen("output.txt","w"); 

    retval = PAPI_library_init(PAPI_VER_CURRENT);
    int EventSet = PAPI_NULL;
    PAPI_create_eventset(&EventSet);
    if(PAPI_add_event(EventSet, PAPI_LD_INS) != PAPI_OK)
    {
        fprintf(file,"PAPI failed to add Load/Store instructions\n");
    }

    if (PAPI_state(EventSet, &status) != PAPI_OK)
        fprintf(file,"state fail\n");

    fprintf(file, "State is now %d\n", status);
    if (PAPI_start(EventSet) != PAPI_OK)
        fprintf(file,"start fail\n");

    if (PAPI_state(EventSet, &status) != PAPI_OK)
        fprintf(file,"state2 fail\n");

    fprintf(file, "State is now %d\n", status);

    /* Initialize the Matrix arrays */
    for ( i=0; i<INDEX; i++ ){
        mresult[0][i] = 0.0;
        matrixa[0][i] = matrixb[0][i] = rand()*(float)1.1; }

    if((retval=PAPI_flops( &real_time, &proc_time, &flpins, &mflops))<PAPI_OK)
        fprintf(file,"retval failed\n");

    for (i=0;i<INDEX;i++)
    {
        for(j=0;j<INDEX;j++)
        {
            for(k=0;k<INDEX;k++)
            {
                mresult[i][j]=mresult[i][j] + matrixa[i][k]*matrixb[k][j];
            }
        }
    }

    if((retval=PAPI_flops( &real_time, &proc_time, &flpins, &mflops))        <PAPI_OK)
    {
        fprintf(infile,"ret2 failed\n");
    }

    fprintf(file,"Real_time:\t%f\nProc_time:\t%f\nTotal flpins:\t%lld \nMFLOPS:\t\t%f\n",
            real_time, proc_time, flpins, mflops); 
    fflush(file);
    fprintf(file,"%s\tPASSED\n", __FILE__);
    fflush(file);

    if (PAPI_read(EventSet, values) != PAPI_OK)
      {fprintf(file,"read fail\n");}

      if (PAPI_stop(EventSet, values) != PAPI_OK)
      {fprintf(file,"stop fail\n");}

    if (PAPI_cleanup_eventset(&EventSet) != PAPI_OK)
      {fprintf(file,"cleanup fail\n");}

    if (PAPI_destroy_eventset(&EventSet) != PAPI_OK)
      {fprintf(file,"destroy fail\n");}


      fprintf(file,"\nValues is %f\n", values[0]);
      fflush(file);
      fclose(file);

      PAPI_shutdown();
      exit(0);
    }

In the output file, I just see the below:

    State is now 1
    State is now 2
    retval failed
    ret2 failed
    Real_time:      0.000000
    Proc_time:      0.000000
    Total flpins:   99
    MFLOPS:         0.000000
    PAPI_flops.c    PASSED
    cleanup fail
    destroy fail

I don't understand why ret, ret2, cleanup and destroy failed. Why?

1

1 Answers

0
votes

You can use the PAPI_perror or PAPI_strerror functions to get the error message associated with an error return value. This may help track down why, for example, PAPI_flops is failing. (It could be that there is no support on your system for the required events.)

The reason why PAPI_cleanup_eventset is failing though is because it takes just the integer EventSet, not a pointer to it.

I'd strongly recommend emitting the error return value strings, and also compiling with warnings on — the latter would likely have found the issue with the wrong parameter type.