1515 *                         reserved. 
1616 * Copyright (c) 2015      Research Organization for Information Science 
1717 *                         and Technology (RIST). All rights reserved. 
18+  * Copyright (c) 2016      University of Houston. All rights reserved. 
1819 * $COPYRIGHT$ 
1920 * 
2021 * Additional copyrights may follow 
3435#include  "ompi/mca/io/base/base.h" 
3536#include  "ompi/memchecker.h" 
3637
38+ 
39+ extern  opal_mutex_t  ompi_mpi_file_bootstrap_mutex ;
40+ 
3741#if  OMPI_BUILD_MPI_PROFILING 
3842#if  OPAL_HAVE_WEAK_SYMBOLS 
3943#pragma  weak MPI_File_open = PMPI_File_open
@@ -81,10 +85,20 @@ int MPI_File_open(MPI_Comm comm, const char *filename, int amode,
8185       and MPI_FILE_DELETE are the only two places that it will be 
8286       initialized). */ 
8387
88+     /* For multi-threaded scenarios, initializing the file i/o 
89+        framework and mca infrastructure needs to be protected 
90+        by a mutex, similarly to the other frameworks in 
91+        ompi/runtime/ompi_mpi_init.c 
92+     */ 
93+ 
94+     opal_mutex_lock (& ompi_mpi_file_bootstrap_mutex );
95+ 
8496    rc  =  mca_base_framework_open (& ompi_io_base_framework , 0 );
8597    if  (OMPI_SUCCESS  !=  rc ) {
98+         opal_mutex_unlock (& ompi_mpi_file_bootstrap_mutex );
8699        return  OMPI_ERRHANDLER_INVOKE (MPI_FILE_NULL , rc , FUNC_NAME );
87100    }
101+     opal_mutex_unlock (& ompi_mpi_file_bootstrap_mutex );
88102
89103    OPAL_CR_ENTER_LIBRARY ();
90104
@@ -96,6 +110,5 @@ int MPI_File_open(MPI_Comm comm, const char *filename, int amode,
96110    /* Creating the file handle also selects a component to use, 
97111       creates a module, and calls file_open() on the module.  So 
98112       we're good to go. */ 
99- 
100113    OMPI_ERRHANDLER_RETURN (rc , * fh , rc , FUNC_NAME );
101114}
0 commit comments