为什么使用MPI_Close关闭文件时出现错误

时间:2020-05-12 10:22:54

标签: c parallel-processing malloc mpi dna-sequence

我正在使用MPI打开文件并从文件中读取文件,并对数据进行压缩,然后将其重写为另一个文件,因此我打开了两个文件,一个处于读取模式,另一个处于写入和创建模式,

MPI_File_open (MPI_COMM_WORLD, nom, MPI_MODE_RDONLY,
                   MPI_INFO_NULL, &myfile);
 MPI_File_open(MPI_COMM_WORLD,newNom,MPI_MODE_CREATE | MPI_MODE_WRONLY,MPI_INFO_NULL,&fh);

最后,我尝试关闭这两个文件,因为我看到一个错误,即从文件中读取的角色从一个执行变为另一个

 if(rank==0){
        printf("Taille de fichier = %d \n",filesize);
        buf=malloc(600);
        MPI_File_read_at(myfile,0, buf, 500, MPI_CHAR, &status);

        char * endLine = strchr(buf,'\n');
        *endLine='\0';
        tailleTitre=endLine-buf;
        // posititoner le cursuer sur le premier nucleotide
        MPI_File_seek(myfile,tailleTitre+1,MPI_SEEK_SET);
        int debut=getFirstData(myfile);
        printf("Debut  = %d \n",debut);
        int fin = getLastData(myfile);
        printf("FIN  = %d \n",fin);
        total=filesize-tailleTitre-1-debut-fin;
        printf("Total de nom a lire est %d \n",total);
        int residuD = RESTANT(debut);
        int residuF = RESTANT(fin);
        printf("MET = %d \n",total-residuD-residuF);
        int net = partagerNucleotides(total-residuF-residuD,residuD,residuF,P);

        printf("Total net = %d \n",net);
        int nucleotidePerProc = diviserEnMultipleQuatre(net,P);
        int a,b;
        int a0,b0,debut0;
        // Les taches propre au master
        debut0=debut;
        debut=getOffsets(nucleotidePerProc,&a0,&b0,debut);
        printf("Proc 0 == %d == %d ,%d \n",debut0,a0,b0);
        for(int i=1;i<P;i++){
            debut=getOffsets(nucleotidePerProc,&a,&b,debut);
            //MPI_File_read_at(myfile,a,debut,b-a,MPI_CHAR,MPI_STATUSES_IGNORE);
//            MPI_File_read(myfile,buf,b-a,MPI_CHAR,MPI_STATUSES_IGNORE);
            MPI_Send(&a,1,MPI_INTEGER,i,1,MPI_COMM_WORLD);
            MPI_Send(&b,1,MPI_INTEGER,i,1,MPI_COMM_WORLD);
            MPI_Send(&tailleTitre,1,MPI_INTEGER,i,1,MPI_COMM_WORLD);
        }
        buf=malloc(50);
        printf("J ai recu %d et %d  et taille = %d\n",a0,b0,tailleTitre);
        MPI_File_read_at(myfile,20,buf,b-a,MPI_CHAR,MPI_STATUSES_IGNORE);
        printf("%c\n",buf[0]);
        buf[b0-a0]='\0';
        printf("TT : %s\n",buf);
        char * test = malloc(b0-a0);
        compressData(buf,b0-a0,fh,test);
        free(test);



    }

这是我用来从文件中读取数据的代码,它是DNA序列,有时还会得到怪异的结果,我不知道它是否与文件的关闭有关

我尝试调试以查看问题所在,这是一个屏幕截图 enter image description here

该代码在四核计算机上使用命令

执行
mpirun -n 4 ./program

谢谢您的回答

0 个答案:

没有答案
相关问题