I am trying to count the number of cache misses, total cycles, etc. per iteration of a for loop inside MatMult_SeqSBAIJ_2() . I've configured PETSc to use PAPI and I am using the PAPI API like shown in the skeletal code below. PAPI always fails (!PAPI_OK) while running ./main . Is there a setting in PAPI or PETSc that I am missing, which enables proper counter sampling inside PETSc?


PAPI_library_init(PAPI_VER_CURRENT); //Initialize PAPI
/*Matrix and vector setup code here. */
/*Destroy matrix here*/

sbaij2.c :

PetscErrorCode MatMult_SeqSBAIJ_2(Mat A,Vec xx,Vec zz)
long long counters[2];
int PAPI_events[2] = {PAPI_TOT_CYC, PAPI_L1_MISSES};
int retval=0;   

PAPI_start_counters( PAPI_events, 2 );

for (i=0; i<mbs;i++)
/*SpMV operations happen here*/
PAPI_read_counters( counters, 2 );

    if ( (retval = PAPI_read_counters(counters, 2)) != PAPI_OK)
    printf("Papi fails!\n");


PAPI_stop_counters( counters, 2 );

  • 1
    $\begingroup$ Welcome to SciComp.SE! Since this is a question solely about configuring PETSc, you should post this on the PETSc mailing list; this site is about questions with a concrete scientific background. $\endgroup$ – Christian Clason Oct 11 '13 at 18:01
  • $\begingroup$ @ChristianClason - we don't have a strong scientific requirement here. The FAQ states "technical computing" questions are welcome. $\endgroup$ – Aron Ahmadia Oct 12 '13 at 15:14
  • $\begingroup$ @Aron - sorry, I was going by what seems to have become consensus after the FEniCS episode: debugging questions should be posted on package-specific fora (see these questions on meta). $\endgroup$ – Christian Clason Oct 12 '13 at 22:12
  • $\begingroup$ @ChristianClason It's a nuanced thing. I'm willing to deal with questions like these when there's a reasonable generality to the topic and the questions show a reasonable amount of effort by the questioner. I'm happy to discuss this further with you on meta, chat, or email if you'd like to talk more about my feelings on this (I'm no longer a moderator, so my opinion is worth as much as yours :) $\endgroup$ – Aron Ahmadia Oct 13 '13 at 5:04

In general you want to know as much about your error as possible when debugging these sorts of problems. In this case, you're not providing enough information with your retval check. See the PAPI documentation on error-handling for more information, but to start, you may want to try:

retval = PAPI_read_counters(counters, 2));
if (retval != PAPI_OK) {
    fprintf(stderr, "PAPI error %d: %s\n", ret, PAPI_strerror(retval));

You can also increase the level of debugging information with PAPI_Set_debug, but you need to make sure that you've got a DEBUG-enabled build of PAPI.

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.