2012-12-06 35 views
2

我試圖從一個MPI應用程序的文件閱讀。集羣有4個節點,每個節點有12個核心。我已經嘗試運行一個基本的程序來計算排名,這是有效的。當我將它MPI_File_open在運行時拋出一個異常分段故障而使用MPI_File_open

之一儲存您的應用程序處理不好的終止=退出代碼:139

集羣已安裝MPICH2並具有網絡文件系統。我檢查MPI_File_open與像只讀模式不同的參數,MPI_COMM_WORLD等

我可以使用MPI_File_open與網絡文件系統?

int main(int argc, char* argv[]) 
{ 
    int myrank   = 0; 
    int nprocs   = 0; 
    int i    = 0; 
    MPI_Comm icomm = MPI_COMM_WORLD; 
    MPI_Status status; 

    MPI_Info info; 
    MPI_File *fh  = NULL; 

    int   error  = 0; 

    MPI_Init(&argc, &argv); 
    MPI_Barrier(MPI_COMM_WORLD);  // Wait for all processor to start 

    MPI_Comm_size(MPI_COMM_WORLD, &nprocs); // Get number of processes 
    MPI_Comm_rank(MPI_COMM_WORLD, &myrank); // Get own rank 

    usleep(myrank*100000); 
    if (myrank == 1 || myrank == 0) 
     printf("Hello from %d\r\n", myrank); 

    if (myrank == 0) 
    { 
     error = MPI_File_open(MPI_COMM_SELF, "lw1.wei", MPI_MODE_UNIQUE_OPEN, 
           MPI_INFO_NULL, fh); 
     if (error) 
     { 
      printf("Error in opening file\r\n"); 
     } 
     else 
     { 
      printf("File successfully opened\r\n"); 
     } 
     MPI_File_close(fh); 
    } 

    MPI_Barrier(MPI_COMM_WORLD);  //! Wait for all the processors to end 
    MPI_Finalize(); 

    if (myrank == 0) 
    { 
     printf("Number of Processes %d\n\r", nprocs); 
    } 

    return 0; 
} 

回答

2

你忘了打開文件之前分配一個MPI_File對象。通過給fh的地址MPI_File_open(..., &fh)

MPI_File  fh; 

,並打開文件:您既可以改變這一行:

MPI_File *fh  = NULL; 

成。或者,你可以簡單地使用malloc()從堆中分配內存。

MPI_File *fh  = malloc(sizeof(MPI_File)); 
+0

感謝。 MPI_File_open函數失敗,我試圖用NULL指針MPI_File_close。我的錯。 – Apoorv