我无法理解为什么我可以看到一些输出,但无法看到下面代码的某些其他行的输出。我正在使用PAPI和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_L1_DCM) != PAPI_OK)
{
fprintf(file,"PAPI failed to add Load/Store instructions\n");
}
if (PAPI_state(EventSet, &status) != PAPI_OK)
fprintf(file,"PAPI fail\n");
fprintf(file, "State is now %d\n", status);
if (PAPI_start(EventSet) != PAPI_OK)
fprintf(file,"PAPI fail\n");
if (PAPI_state(EventSet, &status) != PAPI_OK)
fprintf(file,"PAPI 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)
test_fail(__FILE__, __LINE__, "PAPI_flops", retval);
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)
{
test_fail(__FILE__, __LINE__, "PAPI_flops", retval);
}
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); //cannot see this output in the `output.txt` file
fflush(file);
fprintf(file,"%s\tPASSED\n", __FILE__);
fflush(file);
fclose(file);
PAPI_shutdown();
exit(0);
}
static void test_fail(char *file, int line, char *call, int retval){
}
在输出文件中,我只看到“State is now”的行。我没有看到"Real_time:\t%f\nProc_time:\t%f\nTotal flpins:\t%lld \nMFLOPS
和其他输出的输出。我尝试使用fflush
,但这也无济于事。有谁知道发生了什么事?