Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Looks like <a href="http://icl.cs.utk.edu/papi/" rel="noreferrer" title="Performance Application Programming Interface">PAPI</a> has very clean API and works just fine on Ubuntu 11.04. Once it's installed, following app will do what I wanted:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;papi.h&gt; #define NUM_EVENTS 4 void matmul(const double *A, const double *B, double *C, int m, int n, int p) { int i, j, k; for (i = 0; i &lt; m; ++i) for (j = 0; j &lt; p; ++j) { double sum = 0; for (k = 0; k &lt; n; ++k) sum += A[i*n + k] * B[k*p + j]; C[i*p + j] = sum; } } int main(int /* argc */, char ** /* argv[] */) { const int size = 300; double a[size][size]; double b[size][size]; double c[size][size]; int event[NUM_EVENTS] = {PAPI_TOT_INS, PAPI_TOT_CYC, PAPI_BR_MSP, PAPI_L1_DCM }; long long values[NUM_EVENTS]; /* Start counting events */ if (PAPI_start_counters(event, NUM_EVENTS) != PAPI_OK) { fprintf(stderr, "PAPI_start_counters - FAILED\n"); exit(1); } matmul((double *)a, (double *)b, (double *)c, size, size, size); /* Read the counters */ if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK) { fprintf(stderr, "PAPI_read_counters - FAILED\n"); exit(1); } printf("Total instructions: %lld\n", values[0]); printf("Total cycles: %lld\n", values[1]); printf("Instr per cycle: %2.3f\n", (double)values[0] / (double) values[1]); printf("Branches mispredicted: %lld\n", values[2]); printf("L1 Cache misses: %lld\n", values[3]); /* Stop counting events */ if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK) { fprintf(stderr, "PAPI_stoped_counters - FAILED\n"); exit(1); } return 0; } </code></pre> <p>Tested this on Intel Q6600, it supports up to 4 performance events. Your processor may support more or less.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload