Search code examples
parallel-processingmpiopenmpi

MPI_File is incompatible with parameter of the "File" with fscanf


I am trying to parallelize my program with MPI.

   MPI_File fh;                                                     
       MPI_File_open(MPI_COMM_WORLD,"input.txt",MPI_MODE_CREATE|MPI_MODE_RDONLY, MPI_INFO_NULL, &fh);
       if(rank == 0){
               nwords = -1;
               do {
                       err = fscanf(fh, "%[^\n]\n", word[++nwords]);
               } while( err != EOF && nwords < maxwords);
               printf("Read in %d words\n", nwords);
       } 

then I got this error.

 warning #167: argument of type "MPI_File" is incompatible with parameter of type "FILE *__restrict__"
                          err = fscanf(fh, "%[^\n]\n", word[++nwords]);

how can I read a file using MPI_File_open?


Solution

  • MPI_File_open works with MPI_File, and fscanf() works with FILE * and there is no interoperability.

    You have to either - MPI_File_open() and MPI_File_read() - or stick to fopen() and fscanf()

    MPI-IO true potential is unleashed when doing collective IO (e.g. MPI_File_read_all()) and there is no such thing as MPI_File_scanf() so unless you are willing to MPI_File_read_all() and sscanf(), you might want to stick with non MPI subroutines.