开发者

Opening files in CUDA C

I am trying to open two files(linoteste.ima and sysmattest.dat) they both contain one matrix. After successfully opening the files, when I print them, I only get matrices containing zeros and I don't know what I am doing wrong. This is not a CUDA related problem but a C one, its just that I am opening the files to do matrix multiplica开发者_JS百科tion with CUDA. My code is as follows (I have tried replacing fread with a while cicle to read one element at a time, but it does not work):

    float*matlino=(float*)malloc(sizeof(float)*100*100);
float*matsys=(float*)malloc(sizeof(float)*10000*10000);

//Open linogram
FILE * flino, *fmat;
flino = fopen ("linoteste.ima","r");      //also tried with "rb" instead of "r"
if (flino!=NULL)
{
    fread (matlino,sizeof(float),100*100,flino);
    fclose (flino);
    puts("Linograma aberto com sucesso");
}
else
    puts("impossivel abrir linograma");
printMat(matlino,10,10);

//Open system matrix

fmat = fopen("sysmattest.dat","r"); 
if (fmat!=NULL)
{
    fread (matsys,sizeof(float),10000*10000,fmat);
    fclose (fmat);
    puts("Matriz sistema aberta com sucesso");
}
else
puts("impossivel abrir matriz sistema");

Thanks in advance!


Have you tried fscanf()?

Something like:

if(flino!=NULL)
{
    int i;
    for(i = 0; i < 10000; i++) fscanf(flino, "%f", &malino[i]);
    fclose(flino);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜