diff --git a/.gitignore b/.gitignore index 07252f6710e..3424dffb881 100644 --- a/.gitignore +++ b/.gitignore @@ -384,6 +384,7 @@ Makefile.am-stamp # /src/binding/ /src/binding/c/c_binding.c +/src/binding/c/io.c # /src/binding/cxx/ /src/binding/cxx/Makefile.sm diff --git a/Makefile.am b/Makefile.am index 1d4afd58ed4..ab103004b40 100644 --- a/Makefile.am +++ b/Makefile.am @@ -51,9 +51,22 @@ errnames_txt_files = external_subdirs = @mplsrcdir@ @hwlocsrcdir@ @jsonsrcdir@ @yaksasrcdir@ @pmisrcdir@ external_ldflags = @mpllibdir@ @yaksalibdir@ external_libs = @WRAPPER_LIBS@ -mpi_convenience_libs = + +# convenience libs that do not depend on MPI pmpi_convenience_libs = @mpllib@ @hwloclib@ @jsonlib@ @yaksalib@ @pmilib@ +# convenience libs that depend on MPI (either MPI functions or MPI constants) +mpi_convenience_libs = +abi_convenience_libs = + +if BUILD_ROMIO + external_subdirs += src/mpi/romio + mpi_convenience_libs += src/mpi/romio/libromio.la +if BUILD_ABI_LIB + abi_convenience_libs += src/mpi/romio/libromio_abi.la +endif +endif + # NOTE on our semi-unconventional usage of DIST_SUBDIRS: # The automake manual recommends thinking of DIST_SUBDIRS as the list of all # *configured* subdirectories. The normal autotools model involves @@ -124,8 +137,8 @@ if BUILD_PROFILING_LIB lib_LTLIBRARIES += lib/lib@PMPILIBNAME@.la lib_lib@PMPILIBNAME@_la_SOURCES = $(mpi_sources) $(mpi_core_sources) lib_lib@PMPILIBNAME@_la_LDFLAGS = $(external_ldflags) $(ABIVERSIONFLAGS) -lib_lib@PMPILIBNAME@_la_LIBADD = $(external_libs) $(pmpi_convenience_libs) -EXTRA_lib_lib@PMPILIBNAME@_la_DEPENDENCIES = $(pmpi_convenience_libs) +lib_lib@PMPILIBNAME@_la_LIBADD = $(external_libs) $(pmpi_convenience_libs) $(mpi_convenience_libs) +EXTRA_lib_lib@PMPILIBNAME@_la_DEPENDENCIES = $(pmpi_convenience_libs) $(mpi_convenience_libs) # lib@MPILIBNAME@.la might depend on lib@PMPILIBNAME@.la. We add them # in that order to lib_LTLIBRARIES so libtool doesn't get @@ -134,14 +147,8 @@ lib_LTLIBRARIES += lib/lib@MPILIBNAME@.la lib_lib@MPILIBNAME@_la_SOURCES = $(mpi_sources) lib_lib@MPILIBNAME@_la_LDFLAGS = $(ABIVERSIONFLAGS) lib_lib@MPILIBNAME@_la_CPPFLAGS = $(AM_CPPFLAGS) -DMPICH_MPI_FROM_PMPI -lib_lib@MPILIBNAME@_la_LIBADD = lib/lib@PMPILIBNAME@.la $(mpi_convenience_libs) +lib_lib@MPILIBNAME@_la_LIBADD = lib/lib@PMPILIBNAME@.la -if BUILD_ROMIO - # libpromio contains the PMPI symbols (unlike libpmpi, which contains MPI - # symbols) and should be added to libpmpi - lib_lib@PMPILIBNAME@_la_LIBADD += src/mpi/romio/libpromio.la - lib_lib@MPILIBNAME@_la_LIBADD += src/mpi/romio/libromio.la -endif else !BUILD_PROFILING_LIB lib_LTLIBRARIES += lib/lib@MPILIBNAME@.la @@ -151,9 +158,6 @@ lib_lib@MPILIBNAME@_la_CPPFLAGS = $(AM_CPPFLAGS) lib_lib@MPILIBNAME@_la_LIBADD = $(external_libs) $(pmpi_convenience_libs) $(mpi_convenience_libs) EXTRA_lib_lib@MPILIBNAME@_la_DEPENDENCIES = $(pmpi_convenience_libs) $(mpi_convenience_libs) -if BUILD_ROMIO - lib_lib@MPILIBNAME@_la_LIBADD += src/mpi/romio/libromio.la -endif endif !BUILD_PROFILING_LIB if BUILD_ABI_LIB @@ -165,8 +169,8 @@ lib_LTLIBRARIES += lib/lib@PMPIABILIBNAME@.la lib_lib@PMPIABILIBNAME@_la_SOURCES = $(mpi_abi_sources) $(mpi_f77_sources) $(mpi_core_sources) lib_lib@PMPIABILIBNAME@_la_LDFLAGS = $(external_ldflags) $(ABIVERSIONFLAGS) lib_lib@PMPIABILIBNAME@_la_CPPFLAGS = $(AM_CPPFLAGS) -DF77_USE_PMPI $(abi_cppflags) -lib_lib@PMPIABILIBNAME@_la_LIBADD = $(external_libs) $(pmpi_convenience_libs) -EXTRA_lib_lib@PMPIABILIBNAME@_la_DEPENDENCIES = $(pmpi_convenience_libs) +lib_lib@PMPIABILIBNAME@_la_LIBADD = $(external_libs) $(pmpi_convenience_libs) $(abi_convenience_libs) +EXTRA_lib_lib@PMPIABILIBNAME@_la_DEPENDENCIES = $(pmpi_convenience_libs) $(abi_convenience_libs) # lib@MPIABILIBNAME@.la might depend on lib@PMPIABILIBNAME@.la. We add them # in that order to lib_LTLIBRARIES so libtool doesn't get @@ -175,24 +179,17 @@ lib_LTLIBRARIES += lib/lib@MPIABILIBNAME@.la lib_lib@MPIABILIBNAME@_la_SOURCES = $(mpi_abi_sources) lib_lib@MPIABILIBNAME@_la_LDFLAGS = $(ABIVERSIONFLAGS) lib_lib@MPIABILIBNAME@_la_CPPFLAGS = $(AM_CPPFLAGS) -DMPICH_MPI_FROM_PMPI $(abi_cppflags) -lib_lib@MPIABILIBNAME@_la_LIBADD = lib/lib@PMPIABILIBNAME@.la $(mpi_convenience_libs) +lib_lib@MPIABILIBNAME@_la_LIBADD = lib/lib@PMPIABILIBNAME@.la -if BUILD_ROMIO - lib_lib@PMPIABILIBNAME@_la_LIBADD += src/mpi/romio/libpromio_abi.la - lib_lib@MPIABILIBNAME@_la_LIBADD += src/mpi/romio/libromio_abi.la -endif else !BUILD_PROFILING_LIB lib_LTLIBRARIES += lib/lib@MPIABILIBNAME@.la lib_lib@MPIABILIBNAME@_la_SOURCES = $(mpi_abi_sources) $(mpi_core_sources) lib_lib@MPIABILIBNAME@_la_LDFLAGS = $(external_ldflags) $(ABIVERSIONFLAGS) lib_lib@MPIABILIBNAME@_la_CPPFLAGS = $(AM_CPPFLAGS) $(abi_cppflags) -lib_lib@MPIABILIBNAME@_la_LIBADD = $(external_libs) $(pmpi_convenience_libs) $(mpi_convenience_libs) -EXTRA_lib_lib@MPIABILIBNAME@_la_DEPENDENCIES = $(pmpi_convenience_libs) $(mpi_convenience_libs) +lib_lib@MPIABILIBNAME@_la_LIBADD = $(external_libs) $(pmpi_convenience_libs) $(abi_convenience_libs) +EXTRA_lib_lib@MPIABILIBNAME@_la_DEPENDENCIES = $(pmpi_convenience_libs) $(abi_convenience_libs) -if BUILD_ROMIO - lib_lib@MPIABILIBNAME@_la_LIBADD += src/mpi/romio/libromio_abi.la -endif endif !BUILD_PROFILING_LIB endif BUILD_ABI_LIB diff --git a/dummy b/dummy new file mode 100644 index 00000000000..d00491fd7e5 --- /dev/null +++ b/dummy @@ -0,0 +1 @@ +1 diff --git a/maint/gen_abi.py b/maint/gen_abi.py index d449339aabd..826bc747b94 100644 --- a/maint/gen_abi.py +++ b/maint/gen_abi.py @@ -25,6 +25,7 @@ def search(pat, str, flags=0): def main(): load_mpi_abi_h("src/binding/abi/mpi_abi.h") dump_mpi_abi_internal_h("src/binding/abi/mpi_abi_internal.h") + dump_io_abi_internal_h("src/binding/abi/io_abi_internal.h") dump_romio_abi_internal_h("src/mpi/romio/include/romio_abi_internal.h") dump_mpi_abi_util_c("src/binding/abi/mpi_abi_util.c") @@ -101,7 +102,7 @@ def gen_mpi_abi_internal_h(out): for line in output_lines: print(line, file=Out) print("", file=Out) - + print("#endif /* MPI_ABI_INTERNAL_H_INCLUDED */", file=Out) def dump_romio_abi_internal_h(romio_abi_internal_h): @@ -181,6 +182,52 @@ def add_other(out): print("#define ROMIO_ABI_INTERNAL_H_INCLUDED", file=Out) print("", file=Out) + for line in output_lines: + print(line, file=Out) + print("", file=Out) + + print("#endif /* ROMIO_ABI_INTERNAL_H_INCLUDED */", file=Out) + +# similar to romio_abi_internal.h but for use in the mpich io binding +def dump_io_abi_internal_h(io_abi_internal_h): + def gen_io_abi_internal_h(out): + for line in G.abi_h_lines: + if RE.search(r'MPI_ABI_H_INCLUDED', line): + # skip the include guard, harmless + pass + elif RE.match(r'typedef struct.*\bMPI_File;\s*$', line): + out.append("typedef struct ADIOI_FileD *MPI_File;") + elif RE.match(r'(int|double|MPI_\w+) (P?MPI\w+)\((.*)\);', line): + # prototypes, rename param prefix, add MPICH_API_PUBLIC + (T, name, param) = RE.m.group(1,2,3) + if RE.match(r'P?MPI_(File_\w+|Register_datarep\w*)', name): + out.append("%s %s(%s) MPICH_API_PUBLIC;" % (T, name, param)) + else: + out.append("%s %s(%s);" % (T, name, param)) + else: + # replace param prefix + out.append(line.rstrip()) + + def add_mpich_visibility(out): + out.append("#if defined(HAVE_VISIBILITY)") + out.append("#define MPICH_API_PUBLIC __attribute__((visibility (\"default\")))") + out.append("#else") + out.append("#define MPICH_API_PUBLIC") + out.append("#endif") + out.append("") + + # ---- + output_lines = [] + add_mpich_visibility(output_lines) + gen_io_abi_internal_h(output_lines) + + print(" --> [%s]" % io_abi_internal_h) + with open(io_abi_internal_h, "w") as Out: + dump_copyright(Out) + print("#ifndef ROMIO_ABI_INTERNAL_H_INCLUDED", file=Out) + print("#define ROMIO_ABI_INTERNAL_H_INCLUDED", file=Out) + print("", file=Out) + for line in output_lines: print(line, file=Out) print("", file=Out) diff --git a/maint/gen_binding_c.py b/maint/gen_binding_c.py index d2f50ef74b8..ccb37681a2b 100644 --- a/maint/gen_binding_c.py +++ b/maint/gen_binding_c.py @@ -50,10 +50,11 @@ def main(): repl_func['_replaces'].append(func) + # We generate io functions separately for now + io_func_list = [f for f in func_list if f['dir'] == 'io'] + func_list = [f for f in func_list if f['dir'] != 'io'] + # -- Generating code -- - G.out = [] - G.out.append("#include \"mpiimpl.h\"") - G.out.append("") G.doc3_src_txt = [] G.poly_aliases = [] # large-count mansrc aliases G.need_dump_romio_reference = True @@ -64,9 +65,6 @@ def dump_out(file_path): dump_c_file(file_path, G.out) # add to mpi_sources for dump_Makefile_mk() G.mpi_sources.append(file_path) - G.out = [] - G.out.append("#include \"mpiimpl.h\"") - G.out.append("") G.need_dump_romio_reference = True def dump_func(func, manpage_out): @@ -95,52 +93,91 @@ def dump_func_abi(func): dump_mpi_c(func, True) del func['_is_abi'] - # ---- - for func in func_list: - G.err_codes = {} - manpage_out = [] - - if 'replace' in func and 'body' not in func: - continue + def dump_c_binding(): + G.out = [] + G.out.append("#include \"mpiimpl.h\"") + G.out.append("") + for func in func_list: + G.err_codes = {} + manpage_out = [] - dump_func(func, manpage_out) - if '_replaces' in func: - for t_func in func['_replaces']: - dump_func(t_func, manpage_out) + if 'replace' in func and 'body' not in func: + continue - if 'single-source' not in G.opts: - # dump individual functions in separate source files - dump_out(get_func_file_path(func, c_dir)) + dump_func(func, manpage_out) + if '_replaces' in func: + for t_func in func['_replaces']: + dump_func(t_func, manpage_out) - if 'single-source' in G.opts: - # otherwise, dump all functions in binding.c - dump_out(c_dir + "/c_binding.c") + if 'single-source' not in G.opts: + # dump individual functions in separate source files + dump_out(get_func_file_path(func, c_dir)) + G.out = [] + G.out.append("#include \"mpiimpl.h\"") + G.out.append("") - # ---- dump c_binding_abi.c - G.out = [] - G.out.append("#include \"mpiimpl.h\"") - G.out.append("#include \"mpi_abi_util.h\"") - G.out.append("") + if 'single-source' in G.opts: + # otherwise, dump all functions in binding.c + dump_out(c_dir + "/c_binding.c") - for func in func_list: - if 'replace' in func and 'body' not in func: - continue + def dump_c_binding_abi(): + G.out = [] + G.out.append("#include \"mpiimpl.h\"") + G.out.append("#include \"mpi_abi_util.h\"") + G.out.append("") - if re.match(r'MPIX_', func['name']): - if re.match(r'MPIX_(Grequest_|Type_iov)', func['name']): - # needed by ROMIO - pass - else: + for func in func_list: + if 'replace' in func and 'body' not in func: continue - dump_func_abi(func) - if '_replaces' in func: - for t_func in func['_replaces']: - dump_func_abi(t_func) - abi_file_path = abi_dir + "/c_binding_abi.c" - G.check_write_path(abi_file_path) - dump_c_file(abi_file_path, G.out) - G.out = [] + if re.match(r'MPIX_', func['name']): + if re.match(r'MPIX_(Grequest_|Type_iov)', func['name']): + # needed by ROMIO + pass + else: + continue + dump_func_abi(func) + if '_replaces' in func: + for t_func in func['_replaces']: + dump_func_abi(t_func) + + abi_file_path = abi_dir + "/c_binding_abi.c" + G.check_write_path(abi_file_path) + dump_c_file(abi_file_path, G.out) + + def dump_io_funcs(): + G.out = [] + G.out.append("#include \"mpiimpl.h\"") + G.out.append("#include \"mpir_io_impl.h\"") + G.out.append("") + + for func in io_func_list: + G.err_codes = {} + manpage_out = [] + dump_func(func, manpage_out) + + dump_out(c_dir + "/io.c") + + def dump_io_funcs_abi(): + G.out = [] + G.out.append("#include \"mpichconf.h\"") + G.out.append("#include \"io_abi_internal.h\"") + G.out.append("#include \"mpir_io_impl.h\"") + G.out.append("#include ") + G.out.append("") + + for func in io_func_list: + dump_func_abi(func) + + abi_file_path = abi_dir + "/io_abi.c" + G.check_write_path(abi_file_path) + dump_c_file(abi_file_path, G.out) + + # ---- + dump_c_binding() + dump_c_binding_abi() + dump_io_funcs() + dump_io_funcs_abi() if 'output-mansrc' in G.opts: f = c_dir + '/mansrc/' + 'poly_aliases.lst' @@ -154,6 +191,7 @@ def dump_func_abi(func): G.check_write_path("src/include/mpi_proto.h") dump_Makefile_mk("%s/Makefile.mk" % c_dir) dump_mpir_impl_h("src/include/mpir_impl.h") + dump_mpir_io_impl_h("src/include/mpir_io_impl.h") dump_errnames_txt("%s/errnames.txt" % c_dir) dump_qmpi_register_h("src/mpi_t/qmpi_register.h") dump_mpi_proto_h("src/include/mpi_proto.h") diff --git a/maint/gen_binding_f08.py b/maint/gen_binding_f08.py index 77df0964c94..0af0904b764 100644 --- a/maint/gen_binding_f08.py +++ b/maint/gen_binding_f08.py @@ -19,13 +19,6 @@ def main(): G.check_write_path("%s/wrappers_f/" % f08_dir) G.check_write_path("%s/wrappers_c/" % f08_dir) func_list = load_C_func_list(binding_dir, True) # suppress noise - if "no-mpiio" in G.opts: - # a few MPI_File_xxx functions are already in (MPI_File_xxx_errhandler) - func_list = [f for f in func_list if not f['name'].startswith('MPI_File_')] - else: - # FIXME: until romio interface is generated - func_list.extend(get_mpiio_func_list()) - func_list.append(G.FUNCS['mpi_f_sync_reg']) # preprocess get_real_POLY_kinds() diff --git a/maint/gen_binding_f77.py b/maint/gen_binding_f77.py index c4bbd43c367..dc56f779c31 100644 --- a/maint/gen_binding_f77.py +++ b/maint/gen_binding_f77.py @@ -19,14 +19,7 @@ def main(): func_list = load_C_func_list(binding_dir, True) # suppress noise - if "no-mpiio" in G.opts: - # a few MPI_File_xxx functions are already in (MPI_File_xxx_errhandler) - func_list = [f for f in func_list if not f['name'].startswith('MPI_File_')] - else: - # FIXME: until romio interface is generated - func_list.extend(get_mpiio_func_list()) func_list.extend(get_f77_dummy_func_list()) - func_list.append(G.FUNCS['mpi_f_sync_reg']) # preprocess for func in func_list: diff --git a/maint/gen_binding_f90.py b/maint/gen_binding_f90.py index f71e6a1bdf4..2aa95c9defa 100644 --- a/maint/gen_binding_f90.py +++ b/maint/gen_binding_f90.py @@ -17,10 +17,6 @@ def main(): f90_dir = "src/binding/fortran/use_mpi" G.check_write_path("%s/" % f90_dir) func_list = load_C_func_list(binding_dir, True) # suppress noise - if "no-mpiio" in G.opts: - func_list = [f for f in func_list if not f['name'].startswith('MPI_File_')] - else: - func_list.extend(get_mpiio_func_list()) func_list.extend(get_f77_dummy_func_list()) def has_cptr(func): diff --git a/maint/local_python/__init__.py b/maint/local_python/__init__.py index 08c41ff53c2..6a025b387da 100644 --- a/maint/local_python/__init__.py +++ b/maint/local_python/__init__.py @@ -62,6 +62,7 @@ def check_write_path(path): mpi_sources = [] mpi_declares = [] impl_declares = [] + io_impl_declares = [] mpi_errnames = [] mpix_symbols = {} diff --git a/maint/local_python/binding_c.py b/maint/local_python/binding_c.py index f219ee4e194..773b16bc8fd 100644 --- a/maint/local_python/binding_c.py +++ b/maint/local_python/binding_c.py @@ -81,14 +81,18 @@ def dump_romio_reference(name): dump_profiling(func) - if 'polymorph' in func: + skip_wrappers = False + if func['dir'] == 'io' and '_is_abi' in func: + # The mpi-abi version of io bindings does not have access to MPICH internals (i.e. mpiimpl.h) + dump_function_io(func) + skip_wrappers = True + elif 'polymorph' in func: # MPII_ function to support C/Fortran Polymorphism, eg MPI_Comm_get_attr G.out.append("#ifndef MPICH_MPI_FROM_PMPI") dump_function_internal(func, kind="polymorph") G.out.append("#endif /* MPICH_MPI_FROM_PMPI */") G.out.append("") - if 'polymorph' in func: dump_function_internal(func, kind="call-polymorph") elif 'replace' in func and 'body' not in func: pass @@ -96,7 +100,9 @@ def dump_romio_reference(name): dump_function_internal(func, kind="normal") G.out.append("") - if '_is_abi' in func: + if skip_wrappers: + pass + elif '_is_abi' in func: dump_abi_wrappers(func, func['_is_large']) else: # Create the MPI and QMPI wrapper functions that will call the above, "real" version of the @@ -208,6 +214,40 @@ def dump_mpix_symbols(): print("", file=Out) print("#endif /* MPIR_IMPL_H_INCLUDED */", file=Out) +def dump_mpir_io_impl_h(f): + print(" --> [%s]" %f) + with open(f, "w") as Out: + for l in G.copyright_c: + print(l, file=Out) + print("#ifndef MPIR_IO_IMPL_H_INCLUDED", file=Out) + print("#define MPIR_IO_IMPL_H_INCLUDED", file=Out) + print("", file=Out) + + # io_abi.c doesn't have access to MPICH internal + print("#ifdef BUILD_MPI_ABI", file=Out) + print("#define MPIR_ERR_RECOVERABLE 0", file=Out) + print("#define MPIR_ERR_FATAL 1", file=Out) + print("int MPIR_Err_create_code(int, int, const char[], int, int, const char[], const char[], ...);", file=Out) + print("int MPIR_Err_return_comm(void *, const char[], int);", file=Out) + print("#endif", file=Out) + print("", file=Out) + + print("void MPIR_Ext_cs_enter(void);", file=Out) + print("void MPIR_Ext_cs_exit(void);", file=Out) + print("#ifndef HAVE_ROMIO", file=Out) + print("#define MPIO_Err_return_file(fh, errorcode) MPIR_Err_return_comm((void *)0, __func__, errorcode)", file=Out) + print("#else", file=Out) + print("MPI_Fint MPIR_File_c2f_impl(MPI_File fh);", file=Out) + print("MPI_File MPIR_File_f2c_impl(MPI_Fint fh);", file=Out) + print("int MPIO_Err_return_file(MPI_File fh, int errorcode);", file=Out) + print("#endif", file=Out) + + print("", file=Out) + for l in G.io_impl_declares: + print(l, file=Out) + print("", file=Out) + print("#endif /* MPIR_IO_IMPL_H_INCLUDED */", file=Out) + def filter_out_abi(): funcname = None for l in G.out: @@ -552,8 +592,10 @@ def process_func_parameters(func): do_handle_ptr = 0 (kind, name) = (p['kind'], p['name']) - if '_has_comm' not in func and kind == "COMMUNICATOR" and p['param_direction'] == 'in': + if '_has_comm' not in func and kind == "COMMUNICATOR" and p['param_direction'] == 'in' and func['name'] != "MPI_File_open": func['_has_comm'] = name + elif kind == "FILE" and p['param_direction'] == 'in' and func['dir'] == 'io': + func['_has_file'] = name elif name == "win": func['_has_win'] = name elif name == "session": @@ -733,7 +775,7 @@ def process_func_parameters(func): elif RE.match(r'F90_(COMM|ERRHANDLER|FILE|GROUP|INFO|MESSAGE|OP|REQUEST|SESSION|DATATYPE|WIN)', kind): # no validation for these kinds pass - elif RE.match(r'(POLY)?(DTYPE_STRIDE_BYTES|DISPLACEMENT_AINT_COUNT)$', kind): + elif RE.match(r'(POLY)?(DTYPE_STRIDE_BYTES|DISPLACEMENT_AINT_COUNT|OFFSET)$', kind): # e.g. stride in MPI_Type_vector, MPI_Type_create_resized pass elif is_pointer_type(p): @@ -741,7 +783,11 @@ def process_func_parameters(func): else: print("Missing error checking: func=%s, name=%s, kind=%s" % (func_name, name, kind), file=sys.stderr) - if do_handle_ptr == 1: + if func['dir'] == 'io': + # pass io function parameters as is + impl_arg_list.append(name) + impl_param_list.append(get_impl_param(func, p)) + elif do_handle_ptr == 1: if p['param_direction'] == 'inout': # assume only one such parameter func['_has_handle_inout'] = p @@ -810,6 +856,48 @@ def dump_copy_right(): G.out.append(" */") G.out.append("") +def dump_function_io(func): + is_large = func['_is_large'] + parameters = "" + for p in func['c_parameters']: + parameters = parameters + ", " + p['name'] + + func_decl = get_declare_function(func, is_large) + + dump_line_with_break(func_decl) + G.out.append("{") + G.out.append("INDENT") + if "impl" in func and func['impl'] == "direct": + dump_function_direct(func) + else: + G.out.append("int mpi_errno = MPI_SUCCESS;") + if not '_skip_global_cs' in func: + G.out.append("MPIR_Ext_cs_enter();") + G.out.append("") + G.out.append("#ifndef HAVE_ROMIO") + if not '_is_abi' in func: + G.out.append("mpi_errno = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, __func__, __LINE__, MPI_ERR_OTHER, \"**notimpl\", 0);") + else: + G.out.append("mpi_errno = MPI_ERR_INTERN;") + G.out.append("goto fn_fail;"); + G.out.append("#else") + dump_body_of_routine(func) + G.out.append("#endif") + G.out.append("") + G.out.append("fn_exit:") + if not '_skip_global_cs' in func: + G.out.append("MPIR_Ext_cs_exit();") + G.out.append("return mpi_errno;") + G.out.append("fn_fail:") + if '_has_file' in func: + G.out.append("mpi_errno = MPIO_Err_return_file(%s, mpi_errno);" % func['_has_file']) + else: + G.out.append("mpi_errno = MPIO_Err_return_file(MPI_FILE_NULL, mpi_errno);") + G.out.append("goto fn_exit;") + G.out.append("DEDENT") + G.out.append("}") + G.out.append("") + def dump_qmpi_wrappers(func, is_large): parameters = "" for p in func['c_parameters']: @@ -1387,6 +1475,25 @@ def check_large_parameters(func): func['_poly_in_list'].append(p) def dump_function_normal(func): + def dump_global_cs_enter(): + if not '_skip_global_cs' in func: + G.out.append("") + if func['dir'] == 'mpit': + G.out.append("MPIR_T_THREAD_CS_ENTER();") + elif func['dir'] == 'io': + G.out.append("MPIR_Ext_cs_enter();") + else: + G.out.append("MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);") + def dump_global_cs_exit(): + if not '_skip_global_cs' in func: + G.out.append("") + if func['dir'] == 'mpit': + G.out.append("MPIR_T_THREAD_CS_EXIT();") + elif func['dir'] == 'io': + G.out.append("MPIR_Ext_cs_exit();") + else: + G.out.append("MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);") + # ---- G.out.append("int mpi_errno = MPI_SUCCESS;") if '_handle_ptr_list' in func: for p in func['_handle_ptr_list']: @@ -1405,12 +1512,7 @@ def dump_function_normal(func): else: G.out.append("MPIR_ERRTEST_INITIALIZED_ORDIE();") - if not '_skip_global_cs' in func: - G.out.append("") - if func['dir'] == 'mpit': - G.out.append("MPIR_T_THREAD_CS_ENTER();") - else: - G.out.append("MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);") + dump_global_cs_enter() G.out.append("MPIR_FUNC_TERSE_ENTER;") if '_handle_ptr_list' in func: @@ -1466,41 +1568,6 @@ def dump_function_normal(func): check_early_returns(func) G.out.append("") - # ---- - def dump_body_of_routine(): - do_threadcomm = False - if RE.search(r'threadcomm', func['extra'], re.IGNORECASE): - do_threadcomm = True - G.out.append("#ifdef ENABLE_THREADCOMM") - dump_if_open("comm_ptr->threadcomm") - dump_body_threadcomm(func) - dump_else_open() - G.out.append("#endif") - dump_else_close() - - if 'body' in func: - if func['_is_large'] and func['_poly_impl'] == "separate": - if 'code-large_count' not in func: - raise Exception("%s missing large count code block." % func['name']) - for l in func['code-large_count']: - G.out.append(l) - else: - for l in func['body']: - G.out.append(l) - elif 'impl' in func: - if RE.match(r'mpid', func['impl'], re.IGNORECASE): - dump_body_impl(func, "mpid") - elif RE.match(r'topo_fns->(\w+)', func['impl'], re.IGNORECASE): - dump_body_topo_fns(func, RE.m.group(1)) - else: - print("Error: unhandled special impl: [%s]" % func['impl']) - elif func['dir'] == 'coll': - dump_body_coll(func) - else: - dump_body_impl(func, "mpir") - - if do_threadcomm: - dump_if_close() # ---- G.out.append("/* ... body of routine ... */") @@ -1511,34 +1578,18 @@ def dump_body_of_routine(): G.out.append("goto fn_exit;") dump_if_close() - if func['_is_large'] and 'code-large_count' not in func: - # BIG but internally is using MPI_Aint - impl_args_save = copy.copy(func['_impl_arg_list']) - - dump_if_open("sizeof(MPI_Count) == sizeof(MPI_Aint)") - # Same size, just casting the _impl_arg_list - add_poly_impl_cast(func) - dump_body_of_routine() + need_endif = False + if func['dir'] == 'io' and not 'return' in func: + G.out.append("#ifndef HAVE_ROMIO") + G.out.append("mpi_errno = MPIR_Err_create_code(mpi_errno, MPIR_ERR_RECOVERABLE, __func__, __LINE__, MPI_ERR_OTHER, \"**notimpl\", 0);") + G.out.append("goto fn_fail;") + G.out.append("#else") + need_endif = True - dump_else() - # Need filter to check limits and potentially swap args - func['_impl_arg_list'] = copy.copy(impl_args_save) - G.out.append("/* MPI_Count is bigger than MPI_Aint */") - dump_poly_pre_filter(func) - dump_body_of_routine() - dump_poly_post_filter(func) - - dump_if_close() + dump_body_of_routine(func) - elif not func['_is_large'] and func['_has_poly'] and func['_poly_impl'] != "separate": - # SMALL but internally is using MPI_Aint - dump_poly_pre_filter(func) - dump_body_of_routine() - dump_poly_post_filter(func) - - else: - # normal - dump_body_of_routine() + if need_endif: + G.out.append("#endif") G.out.append("/* ... end of body of routine ... */") @@ -1548,12 +1599,8 @@ def dump_body_of_routine(): for l in func['_clean_up']: G.out.append(l) G.out.append("MPIR_FUNC_TERSE_EXIT;") + dump_global_cs_exit() - if not '_skip_global_cs' in func: - if func['dir'] == 'mpit': - G.out.append("MPIR_T_THREAD_CS_EXIT();") - else: - G.out.append("MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);") G.out.append("return mpi_errno;") G.out.append("") G.out.append("fn_fail:") @@ -1697,7 +1744,10 @@ def push_impl_decl(func, impl_name=None): mpir_name = re.sub(r'^MPIX?_', 'MPIR_', func['name']) G.impl_declares.append("int %s(%s);" % (mpir_name, params)) # dump MPIR_Xxx_impl(...) - G.impl_declares.append("int %s(%s);" % (impl_name, params)) + if func['dir'] == 'io': + G.io_impl_declares.append("int %s(%s);" % (impl_name, params)) + else: + G.impl_declares.append("int %s(%s);" % (impl_name, params)) def push_threadcomm_impl_decl(func): impl_name = re.sub(r'^mpix?_(comm_)?', 'MPIR_Threadcomm_', func['name'].lower()) @@ -1959,6 +2009,75 @@ def dump_body_reduce_equal(func): dump_line_with_break("mpi_errno = %s(%s);" % (impl, args)) dump_error_check("") +def dump_body_of_routine(func): + def dump_body_normal(): + if 'body' in func: + if func['_is_large'] and func['_poly_impl'] == "separate": + if 'code-large_count' not in func: + raise Exception("%s missing large count code block." % func['name']) + for l in func['code-large_count']: + G.out.append(l) + else: + for l in func['body']: + G.out.append(l) + elif 'impl' in func: + if RE.match(r'mpid', func['impl'], re.IGNORECASE): + dump_body_impl(func, "mpid") + elif RE.match(r'topo_fns->(\w+)', func['impl'], re.IGNORECASE): + dump_body_topo_fns(func, RE.m.group(1)) + else: + print("Error: unhandled special impl: [%s]" % func['impl']) + elif func['dir'] == 'coll': + dump_body_coll(func) + else: + dump_body_impl(func, "mpir") + + def dump_body_internal(): + do_threadcomm = False + if RE.search(r'threadcomm', func['extra'], re.IGNORECASE): + do_threadcomm = True + G.out.append("#ifdef ENABLE_THREADCOMM") + dump_if_open("comm_ptr->threadcomm") + dump_body_threadcomm(func) + dump_else_open() + G.out.append("#endif") + dump_else_close() + + dump_body_normal() + + if do_threadcomm: + dump_if_close() + + # ---- + if func['_is_large'] and 'code-large_count' not in func: + # BIG but internally is using MPI_Aint + impl_args_save = copy.copy(func['_impl_arg_list']) + + dump_if_open("sizeof(MPI_Count) == sizeof(MPI_Aint)") + # Same size, just casting the _impl_arg_list + add_poly_impl_cast(func) + dump_body_internal() + + dump_else() + # Need filter to check limits and potentially swap args + func['_impl_arg_list'] = copy.copy(impl_args_save) + G.out.append("/* MPI_Count is bigger than MPI_Aint */") + dump_poly_pre_filter(func) + dump_body_internal() + dump_poly_post_filter(func) + + dump_if_close() + + elif not func['_is_large'] and func['_has_poly'] and func['_poly_impl'] != "separate": + # SMALL but internally is using MPI_Aint + dump_poly_pre_filter(func) + dump_body_internal() + dump_poly_post_filter(func) + + else: + # normal + dump_body_internal() + def dump_function_replace(func, repl_call): G.out.append("int mpi_errno = MPI_SUCCESS;") @@ -1995,6 +2114,8 @@ def dump_mpi_fn_fail(func): G.out.append("mpi_errno = MPIR_Err_return_comm(%s_ptr, __func__, mpi_errno);" % func['_has_comm']) elif '_has_win' in func: G.out.append("mpi_errno = MPIR_Err_return_win(win_ptr, __func__, mpi_errno);") + elif '_has_file' in func: + G.out.append("mpi_errno = MPIO_Err_return_file(%s, mpi_errno);" % func['_has_file']) elif RE.match(r'mpi_session_init', func['name'], re.IGNORECASE): G.out.append("mpi_errno = MPIR_Err_return_session_init(errhandler_ptr, __func__, mpi_errno);") elif '_has_session' in func: @@ -2003,6 +2124,8 @@ def dump_mpi_fn_fail(func): G.out.append("mpi_errno = MPIR_Err_return_comm_create_from_group(errhandler_ptr, __func__, mpi_errno);") elif '_has_group' in func: G.out.append("mpi_errno = MPIR_Err_return_group(%s_ptr, __func__, mpi_errno);" % func['_has_group']) + elif re.match(r'MPI_File_(delete|open|close)', func['name']): + G.out.append("mpi_errno = MPIO_Err_return_file(MPI_FILE_NULL, mpi_errno);") else: G.out.append("mpi_errno = MPIR_Err_return_comm(0, __func__, mpi_errno);") @@ -2027,9 +2150,9 @@ def get_fn_fail_create_code(func): fmt = 'p' elif kind in fmt_codes: fmt = fmt_codes[kind] - elif mapping[kind] == "int": + elif mapping[kind] == "int" or mapping[kind] == "MPI_Fint": fmt = 'd' - elif mapping[kind] == "MPI_Aint": + elif mapping[kind] == "MPI_Aint" or mapping[kind] == "MPI_Offset": fmt = 'L' elif mapping[kind] == "MPI_Count": fmt = 'c' diff --git a/maint/local_python/binding_common.py b/maint/local_python/binding_common.py index f53603e5c05..edaff6ca917 100644 --- a/maint/local_python/binding_common.py +++ b/maint/local_python/binding_common.py @@ -119,7 +119,9 @@ def get_C_param(param, func, mapping): if param['func_type']: param_type = param['func_type'] if mapping['_name'].startswith("BIG_"): - param_type += "_c" + # hard list the limited number of large count function types + if re.match(r'MPI_User_function|MPI_Datarep_conversion_function', param_type): + param_type += "_c" if param_type in G.mpix_symbols: param_type = re.sub(r'MPI_', 'MPIX_', param_type) diff --git a/src/binding/abi/Makefile.mk b/src/binding/abi/Makefile.mk index 197a48e3c19..199d860b5e9 100644 --- a/src/binding/abi/Makefile.mk +++ b/src/binding/abi/Makefile.mk @@ -9,6 +9,7 @@ include_HEADERS += src/binding/abi/mpi_abi.h mpi_abi_sources += \ src/binding/abi/mpi_abi_util.c \ - src/binding/abi/c_binding_abi.c + src/binding/abi/c_binding_abi.c \ + src/binding/abi/io_abi.c endif BUILD_ABI_LIB diff --git a/src/binding/c/async_api.txt b/src/binding/c/async_api.txt index b3d0e0f9d01..9a948c2faef 100644 --- a/src/binding/c/async_api.txt +++ b/src/binding/c/async_api.txt @@ -13,6 +13,7 @@ MPIX_Async_get_state: .return: EXTRA_STATE async_thing: ASYNC_THING, [opaque pointer for async thing] .impl: direct + .skip: validate-ASYNC_THING { return MPIR_Async_thing_get_state(async_thing); } @@ -22,6 +23,7 @@ MPIX_Async_spawn: poll_fn: FUNCTION, func_type=MPIX_Async_poll_function, [user defined poll function for progressing async things] extra_state: EXTRA_STATE, [extra state for callback function] stream: STREAM, [stream object] + .skip: validate-ASYNC_THING { mpi_errno = MPIR_Async_thing_spawn(async_thing, poll_fn, extra_state, stream_ptr); if (mpi_errno) goto fn_fail; diff --git a/src/binding/c/datatype_api.txt b/src/binding/c/datatype_api.txt index 63234904e81..495023c5dbb 100644 --- a/src/binding/c/datatype_api.txt +++ b/src/binding/c/datatype_api.txt @@ -201,15 +201,6 @@ MPI_Unpack_external: } } -MPI_Register_datarep: not_implemented - .desc: Register a set of user-provided data conversion -{ - /* FIXME UNIMPLEMENTED */ - mpi_errno = - MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, __func__, __LINE__, MPI_ERR_OTHER, - "**notimpl", 0); -} - MPI_Status_set_elements: .desc: Set the number of elements in a status { diff --git a/src/binding/c/io_api.txt b/src/binding/c/io_api.txt new file mode 100644 index 00000000000..02d3257b74f --- /dev/null +++ b/src/binding/c/io_api.txt @@ -0,0 +1,208 @@ +# vim: set ft=c: + +MPI_File_open: + .desc: Opens a file + .skip: validate-amode + +MPI_File_close: + .desc: Closes a file + +MPI_File_delete: + .desc: Deletes a file + +MPI_File_c2f: + .desc: Translates a C file handle to a Fortran file handle + .impl: direct +{ +#ifndef HAVE_ROMIO + return 0; +#else + return MPIR_File_c2f_impl(file); +#endif +} + +MPI_File_f2c: + .desc: Translates a Fortran file handle to a C file handle + .impl: direct +{ +#ifndef HAVE_ROMIO + return 0; +#else + return MPIR_File_f2c_impl(file); +#endif +} + +MPI_File_sync: + .desc: Causes all previous writes to be transferred + +MPI_File_get_amode: + .desc: Returns the file access mode + .skip: global_cs + +MPI_File_get_atomicity: + .desc: Returns the atomicity mode + .skip: global_cs + +MPI_File_get_byte_offset: + .desc: Returns the absolute byte position in + .skip: global_cs + +MPI_File_get_type_extent: + .desc: Returns the extent of datatype in the file + .poly_impl: use_aint + +MPI_File_get_group: + .desc: Returns the group of processes that + +MPI_File_get_info: + .desc: Returns the hints for a file that are actually being used by MPI + +MPI_File_get_position: + .desc: Returns the current position of the + +MPI_File_get_position_shared: + .desc: Returns the current position of the + +MPI_File_get_size: + .desc: Returns the file size + .skip: global_cs + +MPI_File_get_view: + .desc: Returns the file view + +MPI_File_iread_all: + .desc: Nonblocking collective read using individual file pointer + +MPI_File_iread_at_all: + .desc: Nonblocking collective read using explicit offset + +MPI_File_iread_at: + .desc: Nonblocking read using explicit offset + +MPI_File_iread: + .desc: Nonblocking read using individual file pointer + +MPI_File_iread_shared: + .desc: Nonblocking read using shared file pointer + +MPI_File_iwrite_all: + .desc: Nonblocking collective write using individual file pointer + +MPI_File_iwrite_at_all: + .desc: Nonblocking collective write using explicit offset + +MPI_File_iwrite_at: + .desc: Nonblocking write using explicit offset + +MPI_File_iwrite: + .desc: Nonblocking write using individual file pointer + +MPI_File_iwrite_shared: + .desc: Nonblocking write using shared file pointer + +MPI_File_open: + .desc: Opens a file + +MPI_File_preallocate: + .desc: Preallocates storage space for a file + +MPI_File_read_at_all_begin: + .desc: Begin a split collective read using explicit offset + +MPI_File_read_at_all_end: + .desc: Complete a split collective read using + +MPI_File_read_all_begin: + .desc: Begin a split collective read using individual file pointer + +MPI_File_read_all: + .desc: Collective read using individual file pointer + +MPI_File_read_all_end: + .desc: Complete a split collective read using + +MPI_File_read_at_all: + .desc: Collective read using explicit offset + +MPI_File_read_at: + .desc: Read using explicit offset + +MPI_File_read: + .desc: Read using individual file pointer + +MPI_File_read_ordered_begin: + .desc: Begin a split collective read using shared file pointer + +MPI_File_read_ordered: + .desc: Collective read using shared file pointer + +MPI_File_read_ordered_end: + .desc: Complete a split collective read using shared file pointer + +MPI_File_read_shared: + .desc: Read using shared file pointer + +MPI_File_seek: + .desc: Updates the individual file pointer + .skip: validate-whence + +MPI_File_seek_shared: + .desc: Updates the shared file pointer + .skip: validate-whence + +MPI_File_set_atomicity: + .desc: Sets the atomicity mode + +MPI_File_set_info: + .desc: Sets new values for the hints associated with a file + +MPI_File_set_size: + .desc: Sets the file size + +MPI_File_set_view: + .desc: Sets the file view +{ -- error_check -- disp + if (disp != MPI_DISPLACEMENT_CURRENT) { + MPIR_ERRTEST_ARGNEG(disp, "disp", mpi_errno); + } +} + +MPI_File_write_at_all_begin: + .desc: Begin a split collective write using + +MPI_File_write_at_all_end: + .desc: Complete a split collective write using explicit offset + +MPI_File_write_all_begin: + .desc: Begin a split collective write using + +MPI_File_write_all: + .desc: Collective write using individual file pointer + +MPI_File_write_all_end: + .desc: Complete a split collective write using individual file pointer + +MPI_File_write_at_all: + .desc: Collective write using explicit offset + +MPI_File_write_at: + .desc: Write using explicit offset + +MPI_File_write: + .desc: Write using individual file pointer + +MPI_File_write_ordered_begin: + .desc: Begin a split collective write using shared file pointer + +MPI_File_write_ordered: + .desc: Collective write using shared file pointer + +MPI_File_write_ordered_end: + .desc: Complete a split collective write using shared file pointer + +MPI_File_write_shared: + .desc: Write using shared file pointer + +MPI_Register_datarep: + .desc: Register a set of user-provided data conversion + .poly_impl: separate diff --git a/src/binding/cxx/buildiface b/src/binding/cxx/buildiface index 1c6ae9e4784..83f4106235c 100755 --- a/src/binding/cxx/buildiface +++ b/src/binding/cxx/buildiface @@ -1736,14 +1736,7 @@ sub print_call_args { if (defined($mytopclass{$lctype})) { $lctype = $mytopclass{$lctype}; } - # Handle the MPIO_Request problem (temp until ROMIO uses - # MPI_Requests) - $cast = ""; - if ($parm =~ /MPI_Request/ && - $class eq "file") { - $cast = "(MPIO_Request *)"; - } - print $OUTFD "$cast&(v$count.the_real_$lctype)"; + print $OUTFD "&(v$count.the_real_$lctype)"; } else { print $OUTFD "&v$count"; diff --git a/src/glue/romio/all_romio_symbols b/src/glue/romio/all_romio_symbols index 84ee707b680..fc6696376fb 100755 --- a/src/glue/romio/all_romio_symbols +++ b/src/glue/romio/all_romio_symbols @@ -138,7 +138,9 @@ while () { print OUTFD "${tab}{\n"; for ($x = 0; $x <= $#arglist; $x++) { - print OUTFD "${tab}${tab}$arglist[$x]"; + my $a = $arglist[$x]; + $a =~ s/MPIO_Request/MPI_Request/; + print OUTFD "${tab}${tab}$a"; if ($arglist[$x] =~ /\*/) { print OUTFD " = NULL;\n"; } diff --git a/src/include/mpi.h.in b/src/include/mpi.h.in index 1180c3f17a1..299813d2cf5 100644 --- a/src/include/mpi.h.in +++ b/src/include/mpi.h.in @@ -504,6 +504,9 @@ static const MPI_Datatype mpich_mpi_offset MPICH_ATTR_TYPE_TAG(MPI_Offset) = MPI #define MPI_MAX_PSET_NAME_LEN 256 #define MPI_MAX_INFO_KEY 255 #define MPI_MAX_INFO_VAL 1024 +#define MPI_MAX_DATAREP_STRING 128 + +#define MPI_DISPLACEMENT_CURRENT ((MPI_Offset) -54278278) /* MPI-3 window flavors */ typedef enum MPIR_Win_flavor { @@ -622,6 +625,21 @@ enum MPIR_Combiner_enum { #define MPI_THREAD_SERIALIZED 2 #define MPI_THREAD_MULTIPLE 3 +/* MPI-IO constants */ +#define MPI_MODE_RDONLY 2 /* ADIO_RDONLY */ +#define MPI_MODE_RDWR 8 /* ADIO_RDWR */ +#define MPI_MODE_WRONLY 4 /* ADIO_WRONLY */ +#define MPI_MODE_CREATE 1 /* ADIO_CREATE */ +#define MPI_MODE_EXCL 64 /* ADIO_EXCL */ +#define MPI_MODE_DELETE_ON_CLOSE 16 /* ADIO_DELETE_ON_CLOSE */ +#define MPI_MODE_UNIQUE_OPEN 32 /* ADIO_UNIQUE_OPEN */ +#define MPI_MODE_APPEND 128 /* ADIO_APPEND */ +#define MPI_MODE_SEQUENTIAL 256 /* ADIO_SEQUENTIAL */ + +#define MPI_SEEK_SET 600 +#define MPI_SEEK_CUR 602 +#define MPI_SEEK_END 604 + /* MPI's error classes */ #define MPI_SUCCESS 0 /* Successful return code */ /* Communication argument parameters */ @@ -1027,7 +1045,6 @@ typedef struct MPIX_Iov { /* We require that the C compiler support prototypes */ #include -@HAVE_ROMIO@ #endif /* BUILD_MPI_ABI */ #if defined(__cplusplus) diff --git a/src/mpi/Makefile.mk b/src/mpi/Makefile.mk index 8d7c4236ee6..b0fa296ff04 100644 --- a/src/mpi/Makefile.mk +++ b/src/mpi/Makefile.mk @@ -22,30 +22,5 @@ include $(top_srcdir)/src/mpi/topo/Makefile.mk include $(top_srcdir)/src/mpi/stream/Makefile.mk include $(top_srcdir)/src/mpi/threadcomm/Makefile.mk -if BUILD_ROMIO -SUBDIRS += src/mpi/romio -DIST_SUBDIRS += src/mpi/romio -MANDOC_SUBDIRS += src/mpi/romio -HTMLDOC_SUBDIRS += src/mpi/romio - -# This was previously a hard copy (not a symlink) performed by config.status -# (specified via AC_CONFIG_COMMANDS). Ideally we would eliminate this "copy" -# altogether and just set -Iromio_include_dir, but MPE2's build system uses -# $(top_builddir)/bin/mpicc that can't handle more than one include dir. -# -# Using a symlink allows us to avoid trying to capture the full dependency chain -# of MPICH/mpio.h --> ROMIO/mpio.h --> ROMIO/mpio.h.in --> ROMIO/config.status --> ...MORE_AUTOTOOLS... -BUILT_SOURCES += $(top_builddir)/src/include/mpio.h -$(top_builddir)/src/include/mpio.h: $(top_builddir)/src/mpi/romio/include/mpio.h - if test ! -h $(top_builddir)/src/include/mpio.h ; then \ - rm -f $(top_builddir)/src/include/mpio.h ; \ - ( cd $(top_builddir)/src/include && \ - $(LN_S) ../mpi/romio/include/mpio.h ) ; \ - fi - -DISTCLEANFILES += $(top_builddir)/src/include/mpio.h - -endif BUILD_ROMIO - # dir is present but currently intentionally unbuilt #include $(top_srcdir)/src/mpi/io/Makefile.mk diff --git a/src/mpi/errhan/errnames.txt b/src/mpi/errhan/errnames.txt index 9198104035d..35c8c01fac6 100644 --- a/src/mpi/errhan/errnames.txt +++ b/src/mpi/errhan/errnames.txt @@ -923,8 +923,6 @@ is too big (> MPIU_SHMW_GHND_SZ) **mpi_attr_get %C %d %p %p:MPI_Attr_get(%C, keyval=%d, attr_value=%p, flag=%p) failed **mpi_attr_delete:MPI_Attr_delete failed **mpi_attr_delete %C %d:MPI_Attr_delete(%C, keyval=%d) failed -**mpi_register_datarep:MPI_Register_datarep failed -**mpi_register_datarep %s %p %p %p %p:MPI_Register_datarep(datarep=%s, read_conversion_fn=%p, write_conversion_fn=%p, dtype_file_extent_fn=%p, extra_state=%p) failed # MPIR functions diff --git a/src/mpi/romio/adio/include/adioi.h b/src/mpi/romio/adio/include/adioi.h index e89ade18e20..ed59e99730f 100644 --- a/src/mpi/romio/adio/include/adioi.h +++ b/src/mpi/romio/adio/include/adioi.h @@ -715,7 +715,7 @@ typedef struct ADIOI_OneSidedStripeParms { ADIO_Offset *stripeWriteLens; int amountOfStripedDataExpected; /* used to determine holes in this segment thereby requiring a rmw */ /* These 2 elements enable ADIOI_OneSidedWriteAggregation to be called multiple times but only */ - /* perform the potientially computationally costly flattening of the source buffer just once */ + /* perform the potentially computationally costly flattening of the source buffer just once */ MPI_Aint bufTypeExtent; ADIOI_Flatlist_node *flatBuf; /* These three elements track the state of the source buffer advancement through multiple calls */ @@ -786,68 +786,6 @@ void ADIOI_FAKE_IwriteStrided(ADIO_File fd, const void *buf, MPI_Aint count, ADIO_Offset offset, ADIO_Request * request, int *error_code); void ADIOI_FAKE_IOComplete(ADIO_Request * request, ADIO_Status * status, int *error_code); - -/* File I/O common functionality */ -int MPIOI_File_read(MPI_File fh, - MPI_Offset offset, - int file_ptr_type, - void *buf, MPI_Aint count, MPI_Datatype datatype, char *myname, - MPI_Status * status); -int MPIOI_File_write(MPI_File fh, MPI_Offset offset, int file_ptr_type, const void *buf, - MPI_Aint count, MPI_Datatype datatype, char *myname, MPI_Status * status); -int MPIOI_File_read_all(MPI_File fh, MPI_Offset offset, int file_ptr_type, void *buf, - MPI_Aint count, MPI_Datatype datatype, char *myname, MPI_Status * status); -int MPIOI_File_write_all(MPI_File fh, MPI_Offset offset, int file_ptr_type, const void *buf, - MPI_Aint count, MPI_Datatype datatype, char *myname, MPI_Status * status); -int MPIOI_File_read_all_begin(MPI_File fh, MPI_Offset offset, int file_ptr_type, void *buf, - MPI_Aint count, MPI_Datatype datatype, char *myname); -int MPIOI_File_write_all_begin(MPI_File fh, MPI_Offset offset, int file_ptr_type, const void *buf, - MPI_Aint count, MPI_Datatype datatype, char *myname); -int MPIOI_File_read_all_end(MPI_File fh, void *buf, char *myname, MPI_Status * status); -int MPIOI_File_write_all_end(MPI_File fh, const void *buf, char *myname, MPI_Status * status); -int MPIOI_File_iwrite(MPI_File fh, - MPI_Offset offset, - int file_ptr_type, - const void *buf, - MPI_Aint count, MPI_Datatype datatype, char *myname, MPI_Request * request); -int MPIOI_File_iread(MPI_File fh, - MPI_Offset offset, - int file_ptr_type, - void *buf, - MPI_Aint count, MPI_Datatype datatype, char *myname, MPI_Request * request); -int MPIOI_File_iwrite_all(MPI_File fh, - MPI_Offset offset, - int file_ptr_type, - const void *buf, - MPI_Aint count, MPI_Datatype datatype, char *myname, - MPI_Request * request); -int MPIOI_File_iread_all(MPI_File fh, MPI_Offset offset, int file_ptr_type, void *buf, - MPI_Aint count, MPI_Datatype datatype, char *myname, - MPI_Request * request); - -int MPIOI_File_read_ordered(MPI_File fh, void *buf, MPI_Aint count, - MPI_Datatype datatype, MPI_Status * status); -int MPIOI_File_read_ordered_begin(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype); -int MPIOI_File_read_shared(MPI_File fh, void *buf, MPI_Aint count, - MPI_Datatype datatype, MPI_Status * status); -int MPIOI_File_iread_shared(MPI_File fh, void *buf, MPI_Aint count, - MPI_Datatype datatype, MPI_Request * request); -int MPIOI_File_write_ordered(MPI_File fh, const void *buf, MPI_Aint count, - MPI_Datatype datatype, MPI_Status * status); -int MPIOI_File_write_ordered_begin(MPI_File fh, const void *buf, MPI_Aint count, - MPI_Datatype datatype); -int MPIOI_File_write_shared(MPI_File fh, const void *buf, MPI_Aint count, MPI_Datatype datatype, - MPI_Status * status); -int MPIOI_File_iwrite_shared(MPI_File fh, const void *buf, MPI_Aint count, MPI_Datatype datatype, - MPIO_Request * request); - -typedef void (*MPIOI_VOID_FN) (void *); -int MPIOI_Register_datarep(const char *datarep, - MPIOI_VOID_FN * read_conversion_fn, - MPIOI_VOID_FN * write_conversion_fn, - MPI_Datarep_extent_function * dtype_file_extent_fn, - void *extra_state, int is_large); - /* Unix-style file locking */ #if defined(F_SETLKW64) diff --git a/src/mpi/romio/adio/include/adioi_error.h b/src/mpi/romio/adio/include/adioi_error.h index 580465d98ff..0a125833c88 100644 --- a/src/mpi/romio/adio/include/adioi_error.h +++ b/src/mpi/romio/adio/include/adioi_error.h @@ -19,8 +19,7 @@ myname, __LINE__, \ MPI_ERR_FILE, \ "**iobadfh", 0); \ - error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code); \ - goto fn_exit; \ + goto fn_fail; \ } /* TODO could add more glue code to help check for handle validity, or perhaps @@ -33,8 +32,7 @@ (myname_), __LINE__, \ MPI_ERR_COMM, \ "**commnull", 0); \ - error_code_ = MPIO_Err_return_file(MPI_FILE_NULL, (error_code_)); \ - goto fn_exit; \ + goto fn_fail; \ } \ } while (0) @@ -45,8 +43,7 @@ myname, __LINE__, \ MPI_ERR_COUNT, \ "**iobadcount", 0); \ - error_code = MPIO_Err_return_file(fh, error_code); \ - goto fn_exit; \ + goto fn_fail; \ } #define MPIO_CHECK_COUNT_SIZE(fh, count, datatype_size, myname, error_code) \ @@ -56,8 +53,7 @@ myname, __LINE__, \ MPI_ERR_ARG, \ "**iobadcount", 0); \ - error_code = MPIO_Err_return_file(fh, error_code); \ - goto fn_exit; \ + goto fn_fail; \ } #define MPIO_CHECK_DATATYPE(fh, datatype, myname, error_code) \ @@ -74,8 +70,7 @@ MPIO_DATATYPE_ISCOMMITTED(datatype, error_code); \ } \ if (error_code != MPI_SUCCESS) { \ - error_code = MPIO_Err_return_file(fh, error_code); \ - goto fn_exit; \ + goto fn_fail; \ } \ } while (0) @@ -86,8 +81,7 @@ myname, __LINE__, \ MPI_ERR_ACCESS, \ "**iowronly", 0); \ - error_code = MPIO_Err_return_file(fh, error_code); \ - goto fn_exit; \ + goto fn_fail; \ } #define MPIO_CHECK_WRITABLE(fh, myname, error_code) \ @@ -98,8 +92,7 @@ MPI_ERR_READ_ONLY, \ "**iordonly", \ 0); \ - error_code = MPIO_Err_return_file(fh, error_code); \ - goto fn_exit; \ + goto fn_fail; \ } #define MPIO_CHECK_NOT_SEQUENTIAL_MODE(fh, myname, error_code) \ @@ -109,8 +102,7 @@ myname, __LINE__, \ MPI_ERR_UNSUPPORTED_OPERATION, \ "**ioamodeseq", 0); \ - error_code = MPIO_Err_return_file(fh, error_code); \ - goto fn_exit; \ + goto fn_fail; \ } #define MPIO_CHECK_INTEGRAL_ETYPE(fh, count, dtype_size, myname, error_code) \ @@ -118,8 +110,7 @@ error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, \ myname, __LINE__, MPI_ERR_IO, \ "**ioetype", 0); \ - error_code = MPIO_Err_return_file(fh, error_code); \ - goto fn_exit; \ + goto fn_fail; \ } #define MPIO_CHECK_FS_SUPPORTS_SHARED(fh, myname, error_code) \ @@ -130,8 +121,7 @@ myname, __LINE__, \ MPI_ERR_UNSUPPORTED_OPERATION, \ "**iosharedunsupported", 0); \ - error_code = MPIO_Err_return_file(fh, error_code); \ - goto fn_exit; \ + goto fn_fail; \ } /* MPIO_ERR_CREATE_CODE_XXX macros are used to clean up creation of @@ -165,7 +155,7 @@ /* Check MPI_Info object by calling MPI_Info_dup, if the info object is valid then the dup operation will succeed */ /* a collective check for error makes this macro collective */ -#define MPIO_CHECK_INFO_ALL(info, error_code, comm) { \ +#define MPIO_CHECK_INFO_ALL(info, myname, error_code, comm) { \ MPI_Info dupinfo; \ int tmp_err = MPI_SUCCESS; \ if (info == MPI_INFO_NULL) { \ diff --git a/src/mpi/romio/configure.ac b/src/mpi/romio/configure.ac index da28bbd5761..6a42e3254d1 100644 --- a/src/mpi/romio/configure.ac +++ b/src/mpi/romio/configure.ac @@ -21,7 +21,7 @@ dnl AC_CONFIG_AUX_DIR(../../../confdb) dnl Set the directory that contains the required install-sh, config.sub, dnl and config.guess . Make sure that these are updated (in MPICH, use dnl the top-level confdb files). This separate directory is used for -dnl the moment to allow ROMIO to be separatedly distributed. +dnl the moment to allow ROMIO to be separately distributed. dnl scripts. AC_CONFIG_AUX_DIR([confdb]) AC_CONFIG_MACRO_DIR([confdb]) @@ -105,6 +105,8 @@ AC_ARG_VAR([FROM_OMPI],[set to "yes" if building ROMIO inside of Open MPI]) FROM_OMPI=${FROM_OMPI:-no} if test "$FROM_OMPI" = 1 ; then FROM_OMPI=yes ; fi +AM_CONDITIONAL([BUILD_BINDING], [test "$FROM_MPICH" != "yes"]) + # MPL AC_ARG_VAR([MPLLIBNAME],[can be used to override the name of the MPL library (default: "mpl")]) MPLLIBNAME=${MPLLIBNAME:-"mpl"} @@ -516,8 +518,6 @@ fi ]) if test "$pac_cv_int_hold_pointer" != yes ; then AC_DEFINE(INT_LT_POINTER,1,[Define if int smaller than pointer]) - dnl Switch to a conforming name (start with HAVE or USE) - AC_DEFINE(HAVE_INT_LT_POINTER,1,[Define if int smaller than pointer]) fi # LL is the printf-style format name for output of a MPI_Offset. @@ -693,7 +693,9 @@ AM_CONDITIONAL([BUILD_MPIO_ERRHAN],[false]) # if we don't have weak symbol support, we must build a separate convenience # library in order to provide the "PMPI_" symbols -AM_CONDITIONAL([BUILD_PROFILING_LIB],[test "x$HAVE_WEAK_SYMBOLS" = "x0"]) +# MPICH will generate separate binding layer, thus we can skip PROFILING LIB +# if build inside MPICH +AM_CONDITIONAL([BUILD_PROFILING_LIB],[test "x$HAVE_WEAK_SYMBOLS" = "x0" -a "$FROM_MPICH" != "yes"]) # disable visibility if building profiling library if test "x$HAVE_WEAK_SYMBOLS" = "x0" ; then VISIBILITY_CFLAGS="" diff --git a/src/mpi/romio/include/mpio.h.in b/src/mpi/romio/include/mpio.h.in index c0322fdb1ad..6aa84e38b6e 100644 --- a/src/mpi/romio/include/mpio.h.in +++ b/src/mpi/romio/include/mpio.h.in @@ -82,6 +82,8 @@ typedef int MPI_Fint; # define MPI_MAX_INFO_VAL 1024 #endif +#ifndef MPI_MODE_RDONLY +/* only define these if they are not defined in mpi.h */ #define MPI_MODE_RDONLY 2 /* ADIO_RDONLY */ #define MPI_MODE_RDWR 8 /* ADIO_RDWR */ #define MPI_MODE_WRONLY 4 /* ADIO_WRONLY */ @@ -92,26 +94,28 @@ typedef int MPI_Fint; #define MPI_MODE_APPEND 128 /* ADIO_APPEND */ #define MPI_MODE_SEQUENTIAL 256 /* ADIO_SEQUENTIAL */ -#define MPI_DISPLACEMENT_CURRENT -54278278 - -#ifndef MPICH -/* FIXME: Make sure that we get a consistent definition of MPI_FILE_NULL - in MPICH */ -/* MPICH defines null object handles differently */ -#define MPI_FILE_NULL ((MPI_File) 0) -#endif -#define MPIO_REQUEST_NULL ((MPIO_Request) 0) - #define MPI_SEEK_SET 600 #define MPI_SEEK_CUR 602 #define MPI_SEEK_END 604 +#define MPI_DISPLACEMENT_CURRENT -54278278 + /* Open MPI: don't define MPI_MAX_DATAREP_STRING here; it's defined in OMPI's mpi.h. */ #ifndef OPEN_MPI #define MPI_MAX_DATAREP_STRING 128 #endif +#endif + +#ifndef MPICH +/* FIXME: Make sure that we get a consistent definition of MPI_FILE_NULL + in MPICH */ +/* MPICH defines null object handles differently */ +#define MPI_FILE_NULL ((MPI_File) 0) +#endif +#define MPIO_REQUEST_NULL ((MPIO_Request) 0) + #ifndef HAVE_MPI_DARRAY_SUBARRAY /* *INDENT-OFF* */ @HAVE_MPI_DARRAY_SUBARRAY@ diff --git a/src/mpi/romio/mpi-io/Makefile.mk b/src/mpi/romio/mpi-io/Makefile.mk index 4005d8252c3..621fa85016f 100644 --- a/src/mpi/romio/mpi-io/Makefile.mk +++ b/src/mpi/romio/mpi-io/Makefile.mk @@ -9,6 +9,7 @@ include $(top_srcdir)/mpi-io/fortran/Makefile.mk AM_CPPFLAGS += -I$(top_builddir)/mpi-io -I$(top_srcdir)/mpi-io noinst_HEADERS += mpi-io/mpioimpl.h mpi-io/mpioprof.h +if BUILD_BINDING romio_mpi_sources += \ mpi-io/close.c \ mpi-io/delete.c \ @@ -68,10 +69,12 @@ romio_mpi_sources += \ mpi-io/write_ordb.c \ mpi-io/write_orde.c \ mpi-io/write_sh.c +endif BUILD_BINDING # non-MPI/PMPI sources that will be included in libromio romio_other_sources += \ + mpi-io/io_impl.c \ mpi-io/mpich_fileutil.c \ mpi-io/mpir-mpioinit.c \ mpi-io/mpiu_greq.c \ diff --git a/src/mpi/romio/mpi-io/close.c b/src/mpi/romio/mpi-io/close.c index 8e894982557..89608ac2553 100644 --- a/src/mpi/romio/mpi-io/close.c +++ b/src/mpi/romio/mpi-io/close.c @@ -34,67 +34,21 @@ Input Parameters: int MPI_File_close(MPI_File * fh) { int error_code; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_CLOSE"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_WSTART(fl_xmpi, BLKMPIFILECLOSE, TRDTBLOCK, *adio_fh); -#endif /* MPI_hpux */ ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(*fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - if (ADIO_Feature(adio_fh, ADIO_SHARED_FP)) { - ADIOI_Free((adio_fh)->shared_fp_fname); - /* POSIX semantics say a deleted file remains available until all - * processes close the file. But since when was NFS posix-compliant? - */ - /* this used to be gated by the lack of the UNLINK_AFTER_CLOSE feature, - * but a race condition in GPFS necessated this. See ticket #2214 */ - MPI_Barrier((adio_fh)->comm); - if ((adio_fh)->shared_fp_fd != ADIO_FILE_NULL) { - MPI_File *fh_shared = &(adio_fh->shared_fp_fd); - ADIO_Close((adio_fh)->shared_fp_fd, &error_code); - MPIO_File_free(fh_shared); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - goto fn_fail; - /* --END ERROR HANDLING-- */ - } - } - - /* Because ROMIO expects the MPI library to provide error handler management - * routines but it doesn't ever participate in MPI_File_close, we have to - * somehow inform the MPI library that we no longer hold a reference to any - * user defined error handler. We do this by setting the errhandler at this - * point to MPI_ERRORS_RETURN. */ - error_code = MPI_File_set_errhandler(*fh, MPI_ERRORS_RETURN); - if (error_code != MPI_SUCCESS) - goto fn_fail; - - ADIO_Close(adio_fh, &error_code); - MPIO_File_free(fh); + error_code = MPIR_File_close_impl(fh); /* --BEGIN ERROR HANDLING-- */ if (error_code != MPI_SUCCESS) goto fn_fail; /* --END ERROR HANDLING-- */ -#ifdef MPI_hpux - HPMP_IO_WEND(fl_xmpi); -#endif /* MPI_hpux */ - fn_exit: ROMIO_THREAD_CS_EXIT(); return error_code; fn_fail: /* --BEGIN ERROR HANDLING-- */ - error_code = MPIO_Err_return_file(adio_fh, error_code); + error_code = MPIO_Err_return_file(MPIO_File_resolve(*fh), error_code); goto fn_exit; /* --END ERROR HANDLING-- */ } diff --git a/src/mpi/romio/mpi-io/delete.c b/src/mpi/romio/mpi-io/delete.c index 634f606b47c..0b8924ecf41 100644 --- a/src/mpi/romio/mpi-io/delete.c +++ b/src/mpi/romio/mpi-io/delete.c @@ -35,61 +35,19 @@ Input Parameters: @*/ int MPI_File_delete(ROMIO_CONST char *filename, MPI_Info info) { - int error_code, file_system, known_fstype; - char *tmp; - ADIOI_Fns *fsops; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEDELETE, TRDTBLOCK, MPI_FILE_NULL, MPI_DATATYPE_NULL, -1); -#endif /* MPI_hpux */ - - MPL_UNREFERENCED_ARG(info); + int error_code; ROMIO_THREAD_CS_ENTER(); - MPIR_MPIOInit(&error_code); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - /* resolve file system type from file name; this is a collective call */ - known_fstype = ADIO_ResolveFileType(MPI_COMM_SELF, filename, &file_system, &fsops, &error_code); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) { - /* ADIO_ResolveFileType() will print as informative a message as it - * possibly can or call MPIR_Err_setmsg. We just need to propagate - * the error up. In the PRINT_ERR_MSG case MPI_Abort has already - * been called as well, so we probably didn't even make it this far. - */ - error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code); - goto fn_exit; + error_code = MPIR_File_delete_impl(filename, info); + if (error_code) { + goto fn_fail; } - /* --END ERROR HANDLING-- */ - - if (known_fstype) { - /* filename contains a known file system type prefix, such as "ufs:". - * skip prefixes on file names if they have more than one character; - * single-character prefixes are assumed to be windows drive - * specifications (e.g. c:\foo) and are left alone. - */ - tmp = strchr(filename, ':'); - if (tmp > filename + 1) - filename = tmp + 1; - } - - /* call the fs-specific delete function */ - (fsops->ADIOI_xxx_Delete) (filename, &error_code); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code); - /* --END ERROR HANDLING-- */ - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, MPI_FILE_NULL, MPI_DATATYPE_NULL, -1); -#endif /* MPI_hpux */ fn_exit: ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/fsync.c b/src/mpi/romio/mpi-io/fsync.c index 74d90abc43b..7fc38c3b5a4 100644 --- a/src/mpi/romio/mpi-io/fsync.c +++ b/src/mpi/romio/mpi-io/fsync.c @@ -35,37 +35,17 @@ Input Parameters: int MPI_File_sync(MPI_File fh) { int error_code; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_SYNC"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILESYNC, TRDTBLOCK, adio_fh, MPI_DATATYPE_NULL, -1); -#endif /* MPI_hpux */ ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - /* --BEGIN ERROR HANDLING-- */ - if ((adio_fh == NULL) || ((adio_fh)->cookie != ADIOI_FILE_COOKIE)) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobadfh", 0); - error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code); - goto fn_exit; + error_code = MPIR_File_sync_impl(fh); + if (error_code) { + goto fn_fail; } - MPIO_CHECK_WRITABLE(fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIO_Flush(adio_fh, &error_code); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, adio_fh, MPI_DATATYPE_NULL, -1); -#endif /* MPI_hpux */ fn_exit: ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/get_amode.c b/src/mpi/romio/mpi-io/get_amode.c index c22df2482a5..d2d6d6ea7b8 100644 --- a/src/mpi/romio/mpi-io/get_amode.c +++ b/src/mpi/romio/mpi-io/get_amode.c @@ -37,18 +37,16 @@ Output Parameters: @*/ int MPI_File_get_amode(MPI_File fh, int *amode) { - int error_code = MPI_SUCCESS; - static char myname[] = "MPI_FILE_GET_AMODE"; - ADIO_File adio_fh; + int error_code; - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - *amode = adio_fh->orig_access_mode; + error_code = MPIR_File_get_amode_impl(fh, amode); + if (error_code) { + goto fn_fail; + } fn_exit: return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/get_atom.c b/src/mpi/romio/mpi-io/get_atom.c index 4b846b2aaf7..14c5912f8f1 100644 --- a/src/mpi/romio/mpi-io/get_atom.c +++ b/src/mpi/romio/mpi-io/get_atom.c @@ -38,17 +38,15 @@ Output Parameters: int MPI_File_get_atomicity(MPI_File fh, int *flag) { int error_code; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_GET_ATOMICITY"; - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - *flag = adio_fh->atomicity; + error_code = MPIR_File_get_atomicity_impl(fh, flag); + if (error_code) { + goto fn_fail; + } fn_exit: - return MPI_SUCCESS; + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/get_bytoff.c b/src/mpi/romio/mpi-io/get_bytoff.c index 2de8383e719..c33c4308457 100644 --- a/src/mpi/romio/mpi-io/get_bytoff.c +++ b/src/mpi/romio/mpi-io/get_bytoff.c @@ -42,27 +42,15 @@ Output Parameters: int MPI_File_get_byte_offset(MPI_File fh, MPI_Offset offset, MPI_Offset * disp) { int error_code; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_GET_BYTE_OFFSET"; - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - - if (offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; + error_code = MPIR_File_get_byte_offset_impl(fh, offset, disp); + if (error_code) { + goto fn_fail; } - MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_Get_byte_offset(adio_fh, offset, disp); - fn_exit: - - return MPI_SUCCESS; + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/get_extent.c b/src/mpi/romio/mpi-io/get_extent.c index bba3f6c93c3..03cfa5b04c8 100644 --- a/src/mpi/romio/mpi-io/get_extent.c +++ b/src/mpi/romio/mpi-io/get_extent.c @@ -51,23 +51,17 @@ Output Parameters: int MPI_File_get_type_extent(MPI_File fh, MPI_Datatype datatype, MPI_Aint * extent) { int error_code; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_GET_TYPE_EXTENT"; - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - /* --END ERROR HANDLING-- */ - - /* FIXME: handle other file data representations */ - - MPI_Aint lb; - error_code = PMPI_Type_get_extent(datatype, &lb, extent); + error_code = MPIR_File_get_type_extent_impl(fh, datatype, extent); + if (error_code) { + goto fn_fail; + } fn_exit: return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -88,22 +82,18 @@ Output Parameters: int MPI_File_get_type_extent_c(MPI_File fh, MPI_Datatype datatype, MPI_Count * extent) { int error_code; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_GET_TYPE_EXTENT"; - - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - /* --END ERROR HANDLING-- */ - /* FIXME: handle other file data representations */ + MPI_Aint extent_i; + error_code = MPIR_File_get_type_extent_impl(fh, datatype, &extent_i); + if (error_code) { + goto fn_fail; + } - MPI_Aint lb_i, extent_i; - error_code = PMPI_Type_get_extent(datatype, &lb_i, &extent_i); *extent = extent_i; fn_exit: return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/get_group.c b/src/mpi/romio/mpi-io/get_group.c index b124c869c9e..11efdc64345 100644 --- a/src/mpi/romio/mpi-io/get_group.c +++ b/src/mpi/romio/mpi-io/get_group.c @@ -39,25 +39,17 @@ Output Parameters: int MPI_File_get_group(MPI_File fh, MPI_Group * group) { int error_code; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_GET_GROUP"; - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - - /* note: this will return the group of processes that called open, but - * with deferred open this might not be the group of processes that - * actually opened the file from the file system's perspective - */ - error_code = MPI_Comm_group(adio_fh->comm, group); + error_code = MPIR_File_get_group_impl(fh, group); + if (error_code) { + goto fn_fail; + } fn_exit: ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/get_info.c b/src/mpi/romio/mpi-io/get_info.c index d258a827043..3568be85a65 100644 --- a/src/mpi/romio/mpi-io/get_info.c +++ b/src/mpi/romio/mpi-io/get_info.c @@ -38,24 +38,17 @@ Output Parameters: int MPI_File_get_info(MPI_File fh, MPI_Info * info_used) { int error_code; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_GET_INFO"; - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - error_code = MPI_Info_dup(adio_fh->info, info_used); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ + error_code = MPIR_File_get_info_impl(fh, info_used); + if (error_code) { + goto fn_fail; + } fn_exit: ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/get_posn.c b/src/mpi/romio/mpi-io/get_posn.c index e2e64938c4f..0daa5e7d6af 100644 --- a/src/mpi/romio/mpi-io/get_posn.c +++ b/src/mpi/romio/mpi-io/get_posn.c @@ -41,18 +41,17 @@ Output Parameters: int MPI_File_get_position(MPI_File fh, MPI_Offset * offset) { int error_code; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_GET_POSITION"; + ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_Get_position(adio_fh, offset); + error_code = MPIR_File_get_position_impl(fh, offset); + if (error_code) { + goto fn_fail; + } fn_exit: - return MPI_SUCCESS; + ROMIO_THREAD_CS_EXIT(); + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/get_posn_sh.c b/src/mpi/romio/mpi-io/get_posn_sh.c index ee626f2c554..0c1c26c6868 100644 --- a/src/mpi/romio/mpi-io/get_posn_sh.c +++ b/src/mpi/romio/mpi-io/get_posn_sh.c @@ -39,25 +39,17 @@ Output Parameters: int MPI_File_get_position_shared(MPI_File fh, MPI_Offset * offset) { int error_code; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_GET_POSITION_SHARED"; + ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code); - MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code); - - ADIO_Get_shared_fp(adio_fh, 0, offset, &error_code); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ + error_code = MPIR_File_get_position_shared_impl(fh, offset); + if (error_code) { + goto fn_fail; + } fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/get_size.c b/src/mpi/romio/mpi-io/get_size.c index e26fde6b3d8..610d27c48cf 100644 --- a/src/mpi/romio/mpi-io/get_size.c +++ b/src/mpi/romio/mpi-io/get_size.c @@ -38,47 +38,15 @@ Output Parameters: int MPI_File_get_size(MPI_File fh, MPI_Offset * size) { int error_code; - ADIO_File adio_fh; - ADIO_Fcntl_t *fcntl_struct; - static char myname[] = "MPI_FILE_GET_SIZE"; -#ifdef MPI_hpux - int fl_xmpi; - HPMP_IO_START(fl_xmpi, BLKMPIFILEGETSIZE, TRDTBLOCK, adio_fh, MPI_DATATYPE_NULL, -1); -#endif /* MPI_hpux */ - - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - if (size == NULL) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, - "**nullptr", "**nullptr %s", "size"); + error_code = MPIR_File_get_size_impl(fh, size); + if (error_code) { goto fn_fail; } - /* --END ERROR HANDLING-- */ - - ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code); - - fcntl_struct = (ADIO_Fcntl_t *) ADIOI_Malloc(sizeof(ADIO_Fcntl_t)); - ADIO_Fcntl(adio_fh, ADIO_FCNTL_GET_FSIZE, fcntl_struct, &error_code); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - *size = fcntl_struct->fsize; - ADIOI_Free(fcntl_struct); - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, adio_fh, MPI_DATATYPE_NULL, -1); -#endif /* MPI_hpux */ fn_exit: return error_code; fn_fail: - /* --BEGIN ERROR HANDLING-- */ error_code = MPIO_Err_return_file(fh, error_code); goto fn_exit; - /* --END ERROR HANDLING-- */ } diff --git a/src/mpi/romio/mpi-io/get_view.c b/src/mpi/romio/mpi-io/get_view.c index 33607c61d43..27b30977eb2 100644 --- a/src/mpi/romio/mpi-io/get_view.c +++ b/src/mpi/romio/mpi-io/get_view.c @@ -42,59 +42,17 @@ int MPI_File_get_view(MPI_File fh, MPI_Offset * disp, MPI_Datatype * etype, MPI_Datatype * filetype, char *datarep) { int error_code; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_GET_VIEW"; - int is_predef; - MPI_Datatype copy_etype, copy_filetype; - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - - if (datarep == NULL) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iodatarepnomem", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - *disp = adio_fh->disp; - ADIOI_Strncpy(datarep, - (adio_fh->is_external32 ? "external32" : "native"), MPI_MAX_DATAREP_STRING); - - ADIOI_Type_ispredef(adio_fh->etype, &is_predef); - if (is_predef) - *etype = adio_fh->etype; - else { -#ifdef MPIIMPL_HAVE_MPI_COMBINER_DUP - MPI_Type_dup(adio_fh->etype, ©_etype); -#else - MPI_Type_contiguous(1, adio_fh->etype, ©_etype); -#endif - - MPI_Type_commit(©_etype); - *etype = copy_etype; - } - ADIOI_Type_ispredef(adio_fh->filetype, &is_predef); - if (is_predef) - *filetype = adio_fh->filetype; - else { -#ifdef MPIIMPL_HAVE_MPI_COMBINER_DUP - MPI_Type_dup(adio_fh->filetype, ©_filetype); -#else - MPI_Type_contiguous(1, adio_fh->filetype, ©_filetype); -#endif - - MPI_Type_commit(©_filetype); - *filetype = copy_filetype; + error_code = MPIR_File_get_view_impl(fh, disp, etype, filetype, datarep); + if (error_code) { + goto fn_fail; } fn_exit: ROMIO_THREAD_CS_EXIT(); - - return MPI_SUCCESS; + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/glue/mpich/mpio_file.c b/src/mpi/romio/mpi-io/glue/mpich/mpio_file.c index 0ffb5efcf1d..54906393b8a 100644 --- a/src/mpi/romio/mpi-io/glue/mpich/mpio_file.c +++ b/src/mpi/romio/mpi-io/glue/mpich/mpio_file.c @@ -39,7 +39,7 @@ void MPIO_File_free(MPI_File * mpi_fh) MPI_File MPIO_File_f2c(MPI_Fint fh) { #ifndef INT_LT_POINTER - return (MPI_File) ((void *) fh); + return (MPI_File) ((void *) (intptr_t) fh); /* the extra cast is to get rid of a compiler warning on Exemplar. * The warning is because MPI_File points to a structure containing * longlongs, which may be 8-byte aligned. But MPI_Fint itself @@ -58,7 +58,7 @@ MPI_File MPIO_File_f2c(MPI_Fint fh) MPI_Fint MPIO_File_c2f(MPI_File fh) { #ifndef INT_LT_POINTER - return (MPI_Fint) fh; + return (MPI_Fint) (intptr_t) fh; #else int i; diff --git a/src/mpi/romio/mpi-io/io_impl.c b/src/mpi/romio/mpi-io/io_impl.c new file mode 100644 index 00000000000..7ccb9f20f99 --- /dev/null +++ b/src/mpi/romio/mpi-io/io_impl.c @@ -0,0 +1,3081 @@ +/* + * Copyright (C) by Argonne National Laboratory + * See COPYRIGHT in top-level directory + */ + +#include "mpioimpl.h" + +/* for user-definde reduce operator */ +#include "adio_extern.h" + +static int MPIOI_File_iread(MPI_File fh, MPI_Offset offset, int file_ptr_type, + void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request); +static int MPIOI_File_iread_all(MPI_File fh, MPI_Offset offset, int file_ptr_type, + void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request); +static int MPIOI_File_iread_shared(MPI_File fh, void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Request * request); +static int MPIOI_File_iwrite(MPI_File fh, MPI_Offset offset, int file_ptr_type, + const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request); +static int MPIOI_File_iwrite_all(MPI_File fh, MPI_Offset offset, int file_ptr_type, + const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request); +static int MPIOI_File_iwrite_shared(MPI_File fh, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPIO_Request * request); +static int MPIOI_File_read(MPI_File fh, MPI_Offset offset, int file_ptr_type, + void *buf, MPI_Aint count, MPI_Datatype datatype, MPI_Status * status); +static int MPIOI_File_read_all(MPI_File fh, MPI_Offset offset, int file_ptr_type, + void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status); +static int MPIOI_File_read_all_begin(MPI_File fh, MPI_Offset offset, int file_ptr_type, + void *buf, MPI_Aint count, MPI_Datatype datatype); +static int MPIOI_File_read_all_end(MPI_File fh, void *buf, MPI_Status * status); +static int MPIOI_File_read_ordered(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status); +static int MPIOI_File_read_ordered_begin(MPI_File fh, + void *buf, MPI_Aint count, MPI_Datatype datatype); +static int MPIOI_File_read_ordered_end(MPI_File fh, void *buf, MPI_Status * status); +static int MPIOI_File_read_shared(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status); +static int MPIOI_File_write(MPI_File fh, MPI_Offset offset, int file_ptr_type, + const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status); +static int MPIOI_File_write_all(MPI_File fh, MPI_Offset offset, int file_ptr_type, + const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status); +static int MPIOI_File_write_all_begin(MPI_File fh, MPI_Offset offset, int file_ptr_type, + const void *buf, MPI_Aint count, MPI_Datatype datatype); +static int MPIOI_File_write_all_end(MPI_File fh, const void *buf, MPI_Status * status); +static int MPIOI_File_write_ordered(MPI_File fh, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Status * status); +static int MPIOI_File_write_ordered_begin(MPI_File fh, const void *buf, MPI_Aint count, + MPI_Datatype datatype); +static int MPIOI_File_write_ordered_end(MPI_File fh, const void *buf, MPI_Status * status); +static int MPIOI_File_write_shared(MPI_File fh, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Status * status); + +typedef void (*MPIOI_VOID_FN) (void *); +static int MPIOI_Register_datarep(const char *datarep, + MPIOI_VOID_FN * read_conversion_fn, + MPIOI_VOID_FN * write_conversion_fn, + MPI_Datarep_extent_function * dtype_file_extent_fn, + void *extra_state, int is_large); + +int MPIR_File_open_impl(MPI_Comm comm, ROMIO_CONST char *filename, int amode, + MPI_Info info, MPI_File * fh) +{ + int error_code = MPI_SUCCESS; + MPI_Comm dupcomm = MPI_COMM_NULL; + + MPIO_CHECK_COMM(comm, __func__, error_code); + MPIO_CHECK_INFO_ALL(info, __func__, error_code, comm); + + int flag; + error_code = MPI_Comm_test_inter(comm, &flag); + if (error_code || flag) { + error_code = MPIO_Err_create_code(error_code, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_COMM, "**commnotintra", 0); + goto fn_fail; + } + + if (((amode & MPI_MODE_RDONLY) ? 1 : 0) + ((amode & MPI_MODE_RDWR) ? 1 : 0) + + ((amode & MPI_MODE_WRONLY) ? 1 : 0) != 1) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_AMODE, "**fileamodeone", 0); + goto fn_fail; + } + + if ((amode & MPI_MODE_RDONLY) && ((amode & MPI_MODE_CREATE) || (amode & MPI_MODE_EXCL))) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_AMODE, "**fileamoderead", 0); + goto fn_fail; + } + + if ((amode & MPI_MODE_RDWR) && (amode & MPI_MODE_SEQUENTIAL)) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_AMODE, "**fileamodeseq", 0); + goto fn_fail; + } + + MPI_Comm_dup(comm, &dupcomm); + + /* Check if ADIO has been initialized. If not, initialize it */ + MPIR_MPIOInit(&error_code); + if (error_code != MPI_SUCCESS) + goto fn_fail; + + /* check if amode is the same on all processes: at first glance, one might try + * to use a built-in operator like MPI_BAND, but we need every mpi process to + * agree the amode was not the same. Consider process A with + * MPI_MODE_CREATE|MPI_MODE_RDWR, and B with MPI_MODE_RDWR: MPI_BAND yields + * MPI_MODE_RDWR. A determines amodes are different, but B proceeds having not + * detected an error */ + int tmp_amode = 0; + MPI_Allreduce(&amode, &tmp_amode, 1, MPI_INT, ADIO_same_amode, dupcomm); + + if (tmp_amode == ADIO_AMODE_NOMATCH) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_NOT_SAME, "**fileamodediff", + 0); + goto fn_fail; + } + + int file_system = -1, known_fstype; + ADIOI_Fns *fsops; + /* resolve file system type from file name; this is a collective call */ + known_fstype = ADIO_ResolveFileType(dupcomm, filename, &file_system, &fsops, &error_code); + if (error_code != MPI_SUCCESS) { + /* ADIO_ResolveFileType() will print as informative a message as it + * possibly can or call MPIO_Err_setmsg. We just need to propagate + * the error up. + */ + goto fn_fail; + } + + if (known_fstype) { + /* filename contains a known file system type prefix, such as "ufs:". + * strip off prefix if there is one, but only skip prefixes + * if they are greater than length one to allow for windows + * drive specifications (e.g. c:\...) + */ + char *tmp = strchr(filename, ':'); + if (tmp > filename + 1) { + filename = tmp + 1; + } + } + + /* use default values for disp, etype, filetype */ + *fh = ADIO_Open(comm, dupcomm, filename, file_system, fsops, amode, 0, + MPI_BYTE, MPI_BYTE, info, ADIO_PERM_NULL, &error_code); + + if (error_code != MPI_SUCCESS) { + goto fn_fail; + } + + /* if MPI_MODE_SEQUENTIAL requested, file systems cannot do explicit offset + * or independent file pointer accesses, leaving not much else aside from + * shared file pointer accesses. */ + if (!ADIO_Feature((*fh), ADIO_SHARED_FP) && (amode & MPI_MODE_SEQUENTIAL)) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, + MPI_ERR_UNSUPPORTED_OPERATION, "**iosequnsupported", 0); + ADIO_Close(*fh, &error_code); + goto fn_fail; + } + + /* determine name of file that will hold the shared file pointer */ + /* can't support shared file pointers on a file system that doesn't + * support file locking. */ + if ((error_code == MPI_SUCCESS) && ADIO_Feature((*fh), ADIO_SHARED_FP)) { + int rank; + MPI_Comm_rank(dupcomm, &rank); + ADIOI_Shfp_fname(*fh, rank, &error_code); + if (error_code != MPI_SUCCESS) + goto fn_fail; + + /* if MPI_MODE_APPEND, set the shared file pointer to end of file. + * indiv. file pointer already set to end of file in ADIO_Open. + * Here file view is just bytes. */ + if ((*fh)->access_mode & MPI_MODE_APPEND) { + if (rank == (*fh)->hints->ranklist[0]) /* only one person need set the sharedfp */ + ADIO_Set_shared_fp(*fh, (*fh)->fp_ind, &error_code); + MPI_Barrier(dupcomm); + } + } + + fn_exit: + return error_code; + fn_fail: + if (dupcomm != MPI_COMM_NULL) + MPI_Comm_free(&dupcomm); + goto fn_exit; +} + +int MPIR_File_close_impl(MPI_File * fh) +{ + int error_code = MPI_SUCCESS; + + ADIO_File adio_fh; + adio_fh = MPIO_File_resolve(*fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + /* --END ERROR HANDLING-- */ + + if (ADIO_Feature(adio_fh, ADIO_SHARED_FP)) { + ADIOI_Free((adio_fh)->shared_fp_fname); + /* POSIX semantics say a deleted file remains available until all + * processes close the file. But since when was NFS posix-compliant? + */ + /* this used to be gated by the lack of the UNLINK_AFTER_CLOSE feature, + * but a race condition in GPFS necessated this. See ticket #2214 */ + MPI_Barrier((adio_fh)->comm); + if ((adio_fh)->shared_fp_fd != ADIO_FILE_NULL) { + MPI_File *fh_shared = &(adio_fh->shared_fp_fd); + ADIO_Close((adio_fh)->shared_fp_fd, &error_code); + MPIO_File_free(fh_shared); + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + } + } + + /* Because ROMIO expects the MPI library to provide error handler management + * routines but it doesn't ever participate in MPI_File_close, we have to + * somehow inform the MPI library that we no longer hold a reference to any + * user defined error handler. We do this by setting the errhandler at this + * point to MPI_ERRORS_RETURN. */ + error_code = PMPI_File_set_errhandler(*fh, MPI_ERRORS_RETURN); + if (error_code != MPI_SUCCESS) + goto fn_fail; + + ADIO_Close(adio_fh, &error_code); + MPIO_File_free(fh); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_delete_impl(const char *filename, MPI_Info info) +{ + int error_code = MPI_SUCCESS; + int file_system, known_fstype; + char *tmp; + ADIOI_Fns *fsops; + + MPL_UNREFERENCED_ARG(info); + + MPIR_MPIOInit(&error_code); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + /* resolve file system type from file name; this is a collective call */ + known_fstype = ADIO_ResolveFileType(MPI_COMM_SELF, filename, &file_system, &fsops, &error_code); + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) { + /* ADIO_ResolveFileType() will print as informative a message as it + * possibly can or call MPIR_Err_setmsg. We just need to propagate + * the error up. In the PRINT_ERR_MSG case MPI_Abort has already + * been called as well, so we probably didn't even make it this far. + */ + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + if (known_fstype) { + /* filename contains a known file system type prefix, such as "ufs:". + * skip prefixes on file names if they have more than one character; + * single-character prefixes are assumed to be windows drive + * specifications (e.g. c:\foo) and are left alone. + */ + tmp = strchr(filename, ':'); + if (tmp > filename + 1) + filename = tmp + 1; + } + + /* call the fs-specific delete function */ + (fsops->ADIOI_xxx_Delete) (filename, &error_code); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_get_amode_impl(MPI_File fh, int *amode) +{ + int error_code = MPI_SUCCESS; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + *amode = adio_fh->orig_access_mode; + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_get_atomicity_impl(MPI_File fh, int *flag) +{ + int error_code = MPI_SUCCESS; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + *flag = adio_fh->atomicity; + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_get_byte_offset_impl(MPI_File fh, MPI_Offset offset, MPI_Offset * disp) +{ + int error_code = MPI_SUCCESS; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + if (offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); + goto fn_fail; + } + + MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, __func__, error_code); + /* --END ERROR HANDLING-- */ + + ADIOI_Get_byte_offset(adio_fh, offset, disp); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_get_group_impl(MPI_File fh, MPI_Group * group) +{ + int error_code = MPI_SUCCESS; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + /* note: this will return the group of processes that called open, but + * with deferred open this might not be the group of processes that + * actually opened the file from the file system's perspective + */ + error_code = MPI_Comm_group(adio_fh->comm, group); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_get_info_impl(MPI_File fh, MPI_Info * info_used) +{ + int error_code = MPI_SUCCESS; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + error_code = MPI_Info_dup(adio_fh->info, info_used); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_get_position_impl(MPI_File fh, MPI_Offset * offset) +{ + int error_code = MPI_SUCCESS; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, __func__, error_code); + + ADIOI_Get_position(adio_fh, offset); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_get_position_shared_impl(MPI_File fh, MPI_Offset * offset) +{ + int error_code = MPI_SUCCESS; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, __func__, error_code); + MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, __func__, error_code); + + ADIOI_TEST_DEFERRED(adio_fh, __func__, &error_code); + + ADIO_Get_shared_fp(adio_fh, 0, offset, &error_code); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_get_size_impl(MPI_File fh, MPI_Offset * size) +{ + int error_code = MPI_SUCCESS; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + if (size == NULL) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, + "**nullptr", "**nullptr %s", "size"); + goto fn_fail; + } + + ADIOI_TEST_DEFERRED(adio_fh, __func__, &error_code); + + ADIO_Fcntl_t *fcntl_struct; + fcntl_struct = (ADIO_Fcntl_t *) ADIOI_Malloc(sizeof(ADIO_Fcntl_t)); + ADIO_Fcntl(adio_fh, ADIO_FCNTL_GET_FSIZE, fcntl_struct, &error_code); + if (error_code != MPI_SUCCESS) { + goto fn_fail; + } + + *size = fcntl_struct->fsize; + ADIOI_Free(fcntl_struct); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_get_type_extent_impl(MPI_File fh, MPI_Datatype datatype, MPI_Aint * extent) +{ + int error_code = MPI_SUCCESS; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + + /* FIXME: handle other file data representations */ + + MPI_Aint lb_i, extent_i; + error_code = PMPI_Type_get_extent(datatype, &lb_i, &extent_i); + *extent = extent_i; + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_get_view_impl(MPI_File fh, MPI_Offset * disp, MPI_Datatype * etype, + MPI_Datatype * filetype, char *datarep) +{ + int error_code = MPI_SUCCESS; + int is_predef; + MPI_Datatype copy_etype, copy_filetype; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + if (datarep == NULL) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iodatarepnomem", 0); + goto fn_exit; + } + /* --END ERROR HANDLING-- */ + + *disp = adio_fh->disp; + ADIOI_Strncpy(datarep, + (adio_fh->is_external32 ? "external32" : "native"), MPI_MAX_DATAREP_STRING); + + ADIOI_Type_ispredef(adio_fh->etype, &is_predef); + if (is_predef) + *etype = adio_fh->etype; + else { +#ifdef MPIIMPL_HAVE_MPI_COMBINER_DUP + MPI_Type_dup(adio_fh->etype, ©_etype); +#else + MPI_Type_contiguous(1, adio_fh->etype, ©_etype); +#endif + + MPI_Type_commit(©_etype); + *etype = copy_etype; + } + ADIOI_Type_ispredef(adio_fh->filetype, &is_predef); + if (is_predef) + *filetype = adio_fh->filetype; + else { +#ifdef MPIIMPL_HAVE_MPI_COMBINER_DUP + MPI_Type_dup(adio_fh->filetype, ©_filetype); +#else + MPI_Type_contiguous(1, adio_fh->filetype, ©_filetype); +#endif + + MPI_Type_commit(©_filetype); + *filetype = copy_filetype; + } + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_iread_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request) +{ + return MPIOI_File_iread(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, buf, count, datatype, request); +} + +int MPIR_File_iread_all_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request) +{ + return MPIOI_File_iread_all(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, buf, count, datatype, request); +} + +int MPIR_File_iread_at_impl(MPI_File fh, MPI_Offset offset, void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Request * request) +{ + return MPIOI_File_iread(fh, offset, ADIO_EXPLICIT_OFFSET, buf, count, datatype, request); +} + +int MPIR_File_iread_at_all_impl(MPI_File fh, MPI_Offset offset, void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Request * request) +{ + return MPIOI_File_iread_all(fh, offset, ADIO_EXPLICIT_OFFSET, buf, count, datatype, request); +} + +int MPIR_File_iread_shared_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request) +{ + return MPIOI_File_iread_shared(fh, buf, count, datatype, request); +} + +int MPIR_File_iwrite_impl(MPI_File fh, const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request) +{ + return MPIOI_File_iwrite(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, buf, count, datatype, request); +} + +int MPIR_File_iwrite_all_impl(MPI_File fh, const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request) +{ + return MPIOI_File_iwrite_all(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, + buf, count, datatype, request); +} + +int MPIR_File_iwrite_at_impl(MPI_File fh, MPI_Offset offset, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Request * request) +{ + return MPIOI_File_iwrite(fh, offset, ADIO_EXPLICIT_OFFSET, buf, count, datatype, request); +} + +int MPIR_File_iwrite_at_all_impl(MPI_File fh, MPI_Offset offset, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Request * request) +{ + return MPIOI_File_iwrite_all(fh, offset, ADIO_EXPLICIT_OFFSET, buf, count, datatype, request); +} + +int MPIR_File_iwrite_shared_impl(MPI_File fh, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Request * request) +{ + return MPIOI_File_iwrite_shared(fh, buf, count, datatype, request); +} + +int MPIR_File_preallocate_impl(MPI_File fh, MPI_Offset size) +{ + int error_code = MPI_SUCCESS; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + if (size < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobadsize", 0); + goto fn_fail; + } + + MPI_Offset tmp_sz, max_sz, min_sz; + tmp_sz = size; + MPI_Allreduce(&tmp_sz, &max_sz, 1, ADIO_OFFSET, MPI_MAX, adio_fh->comm); + MPI_Allreduce(&tmp_sz, &min_sz, 1, ADIO_OFFSET, MPI_MIN, adio_fh->comm); + + if (max_sz != min_sz) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**notsame", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + if (size == 0) + goto fn_exit; + + ADIOI_TEST_DEFERRED(adio_fh, __func__, &error_code); + + int mynod = 0; + MPI_Comm_rank(adio_fh->comm, &mynod); + if (!mynod) { + ADIO_Fcntl_t *fcntl_struct; + fcntl_struct = (ADIO_Fcntl_t *) ADIOI_Malloc(sizeof(ADIO_Fcntl_t)); + fcntl_struct->diskspace = size; + ADIO_Fcntl(adio_fh, ADIO_FCNTL_SET_DISKSPACE, fcntl_struct, &error_code); + ADIOI_Free(fcntl_struct); + } + MPI_Barrier(adio_fh->comm); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_read_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status) +{ + return MPIOI_File_read(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, buf, count, datatype, status); +} + +int MPIR_File_read_all_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status) +{ + return MPIOI_File_read_all(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, buf, count, datatype, status); +} + +int MPIR_File_read_all_begin_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype) +{ + return MPIOI_File_read_all_begin(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, buf, count, datatype); +} + +int MPIR_File_read_all_end_impl(MPI_File fh, void *buf, MPI_Status * status) +{ + return MPIOI_File_read_all_end(fh, buf, status); +} + +int MPIR_File_read_at_impl(MPI_File fh, MPI_Offset offset, void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Status * status) +{ + return MPIOI_File_read(fh, offset, ADIO_EXPLICIT_OFFSET, buf, count, datatype, status); +} + +int MPIR_File_read_at_all_impl(MPI_File fh, MPI_Offset offset, void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Status * status) +{ + return MPIOI_File_read_all(fh, offset, ADIO_EXPLICIT_OFFSET, buf, count, datatype, status); +} + +int MPIR_File_read_at_all_begin_impl(MPI_File fh, MPI_Offset offset, void *buf, MPI_Aint count, + MPI_Datatype datatype) +{ + return MPIOI_File_read_all_begin(fh, offset, ADIO_EXPLICIT_OFFSET, buf, count, datatype); +} + +int MPIR_File_read_at_all_end_impl(MPI_File fh, void *buf, MPI_Status * status) +{ + return MPIOI_File_read_all_end(fh, buf, status); +} + +int MPIR_File_read_ordered_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status) +{ + return MPIOI_File_read_ordered(fh, buf, count, datatype, status); +} + +int MPIR_File_read_ordered_begin_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype) +{ + return MPIOI_File_read_ordered_begin(fh, buf, count, datatype); +} + +int MPIR_File_read_ordered_end_impl(MPI_File fh, void *buf, MPI_Status * status) +{ + return MPIOI_File_read_ordered_end(fh, buf, status); +} + +int MPIR_File_read_shared_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status) +{ + return MPIOI_File_read_shared(fh, buf, count, datatype, status); +} + +int MPIR_File_seek_impl(MPI_File fh, MPI_Offset offset, int whence) +{ + int error_code = MPI_SUCCESS; + MPI_Offset curr_offset, eof_offset; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, __func__, error_code); + + switch (whence) { + case MPI_SEEK_SET: + /* --BEGIN ERROR HANDLING-- */ + if (offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, + MPIR_ERR_RECOVERABLE, __func__, + __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + break; + case MPI_SEEK_CUR: + /* find offset corr. to current location of file pointer */ + ADIOI_Get_position(adio_fh, &curr_offset); + offset += curr_offset; + + /* --BEGIN ERROR HANDLING-- */ + if (offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, + MPIR_ERR_RECOVERABLE, __func__, + __LINE__, MPI_ERR_ARG, "**ionegoffset", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + break; + case MPI_SEEK_END: + /* we can in many cases do seeks w/o a file actually opened, but not in + * the MPI_SEEK_END case */ + ADIOI_TEST_DEFERRED(adio_fh, "MPI_File_seek", &error_code); + + /* find offset corr. to end of file */ + ADIOI_Get_eof_offset(adio_fh, &eof_offset); + offset += eof_offset; + + /* --BEGIN ERROR HANDLING-- */ + if (offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, + MPIR_ERR_RECOVERABLE, __func__, + __LINE__, MPI_ERR_ARG, "**ionegoffset", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + break; + default: + /* --BEGIN ERROR HANDLING-- */ + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobadwhence", 0); + goto fn_fail; + /* --END ERROR HANDLING-- */ + } + + ADIO_SeekIndividual(adio_fh, offset, ADIO_SEEK_SET, &error_code); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_seek_shared_impl(MPI_File fh, MPI_Offset offset, int whence) +{ + int error_code = MPI_SUCCESS; + MPI_Offset curr_offset, eof_offset; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, __func__, error_code); + MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, __func__, error_code); + /* --END ERROR HANDLING-- */ + + MPI_Offset tmp_offset; + tmp_offset = offset; + MPI_Bcast(&tmp_offset, 1, ADIO_OFFSET, 0, adio_fh->comm); + /* --BEGIN ERROR HANDLING-- */ + if (tmp_offset != offset) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**notsame", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + int tmp_whence; + tmp_whence = whence; + MPI_Bcast(&tmp_whence, 1, MPI_INT, 0, adio_fh->comm); + /* --BEGIN ERROR HANDLING-- */ + if (tmp_whence != whence) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobadwhence", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + ADIOI_TEST_DEFERRED(adio_fh, "MPI_File_seek_shared", &error_code); + + int myrank; + MPI_Comm_rank(adio_fh->comm, &myrank); + + if (!myrank) { + switch (whence) { + case MPI_SEEK_SET: + /* --BEGIN ERROR HANDLING-- */ + if (offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, + MPIR_ERR_RECOVERABLE, + __func__, __LINE__, + MPI_ERR_ARG, "**iobadoffset", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + break; + case MPI_SEEK_CUR: + /* get current location of shared file pointer */ + ADIO_Get_shared_fp(adio_fh, 0, &curr_offset, &error_code); + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, + MPIR_ERR_FATAL, + __func__, __LINE__, + MPI_ERR_INTERN, "**iosharedfailed", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + offset += curr_offset; + /* --BEGIN ERROR HANDLING-- */ + if (offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, + MPIR_ERR_RECOVERABLE, + __func__, __LINE__, + MPI_ERR_ARG, "**ionegoffset", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + break; + case MPI_SEEK_END: + /* find offset corr. to end of file */ + ADIOI_Get_eof_offset(adio_fh, &eof_offset); + offset += eof_offset; + /* --BEGIN ERROR HANDLING-- */ + if (offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, + MPIR_ERR_RECOVERABLE, + __func__, __LINE__, + MPI_ERR_ARG, "**ionegoffset", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + break; + default: + /* --BEGIN ERROR HANDLING-- */ + error_code = MPIO_Err_create_code(MPI_SUCCESS, + MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, + "**iobadwhence", 0); + goto fn_fail; + /* --END ERROR HANDLING-- */ + } + + ADIO_Set_shared_fp(adio_fh, offset, &error_code); + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, + MPIR_ERR_FATAL, + __func__, __LINE__, + MPI_ERR_INTERN, "**iosharedfailed", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + } + + /* FIXME: explain why the barrier is necessary */ + MPI_Barrier(adio_fh->comm); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_set_atomicity_impl(MPI_File fh, int flag) +{ + int error_code = MPI_SUCCESS; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + ADIOI_TEST_DEFERRED(adio_fh, __func__, &error_code); + + if (flag) + flag = 1; /* take care of non-one values! */ + + /* check if flag is the same on all processes */ + int tmp_flag; + tmp_flag = flag; + MPI_Bcast(&tmp_flag, 1, MPI_INT, 0, adio_fh->comm); + + /* --BEGIN ERROR HANDLING-- */ + if (tmp_flag != flag) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**notsame", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + if (adio_fh->atomicity == flag) { + error_code = MPI_SUCCESS; + goto fn_exit; + } + + ADIO_Fcntl_t *fcntl_struct; + fcntl_struct = (ADIO_Fcntl_t *) ADIOI_Malloc(sizeof(ADIO_Fcntl_t)); + fcntl_struct->atomicity = flag; + ADIO_Fcntl(adio_fh, ADIO_FCNTL_SET_ATOMICITY, fcntl_struct, &error_code); + /* TODO: what do we do with this error code? */ + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + + ADIOI_Free(fcntl_struct); + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_set_info_impl(MPI_File fh, MPI_Info info) +{ + int error_code = MPI_SUCCESS; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + MPIO_CHECK_INFO_ALL(info, __func__, error_code, fh->comm); + + /* set new info */ + ADIO_SetInfo(adio_fh, info, &error_code); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_set_size_impl(MPI_File fh, MPI_Offset size) +{ + int error_code = MPI_SUCCESS; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, __func__, error_code); + + if (size < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobadsize", 0); + goto fn_fail; + } + MPIO_CHECK_WRITABLE(fh, __func__, error_code); + + MPI_Offset tmp_sz, max_sz, min_sz; + tmp_sz = size; + MPI_Allreduce(&tmp_sz, &max_sz, 1, ADIO_OFFSET, MPI_MAX, adio_fh->comm); + MPI_Allreduce(&tmp_sz, &min_sz, 1, ADIO_OFFSET, MPI_MIN, adio_fh->comm); + + /* --BEGIN ERROR HANDLING-- */ + if (max_sz != min_sz) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**notsame", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + if (!ADIO_Feature(adio_fh, ADIO_SCALABLE_RESIZE)) { + /* rare stupid file systems (like NFS) need to carry out resize on all + * processes */ + ADIOI_TEST_DEFERRED(adio_fh, "MPI_File_set_size", &error_code); + } + + ADIO_Resize(adio_fh, size, &error_code); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_set_view_impl(MPI_File fh, MPI_Offset disp, MPI_Datatype etype, MPI_Datatype filetype, + const char *datarep, MPI_Info info) +{ + int error_code = MPI_SUCCESS; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + if ((disp < 0) && (disp != MPI_DISPLACEMENT_CURRENT)) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobaddisp", 0); + goto fn_fail; + } + + /* rudimentary checks for incorrect etype/filetype. */ + if (etype == MPI_DATATYPE_NULL) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**ioetype", 0); + goto fn_fail; + } + MPIO_DATATYPE_ISCOMMITTED(etype, error_code); + if (error_code != MPI_SUCCESS) { + goto fn_fail; + } + + if (filetype == MPI_DATATYPE_NULL) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iofiletype", 0); + goto fn_fail; + } + MPIO_DATATYPE_ISCOMMITTED(filetype, error_code); + if (error_code != MPI_SUCCESS) { + goto fn_fail; + } + + if ((adio_fh->access_mode & MPI_MODE_SEQUENTIAL) && (disp != MPI_DISPLACEMENT_CURRENT)) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iodispifseq", 0); + goto fn_fail; + } + + if ((disp == MPI_DISPLACEMENT_CURRENT) && !(adio_fh->access_mode & MPI_MODE_SEQUENTIAL)) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iodispifseq", 0); + goto fn_fail; + } + MPIO_CHECK_INFO_ALL(info, __func__, error_code, adio_fh->comm); + /* --END ERROR HANDLING-- */ + + MPI_Count filetype_size, etype_size; + MPI_Type_size_x(filetype, &filetype_size); + MPI_Type_size_x(etype, &etype_size); + + /* --BEGIN ERROR HANDLING-- */ + if (etype_size != 0 && filetype_size % etype_size != 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iofiletype", 0); + goto fn_fail; + } + + if ((datarep == NULL) || (strcmp(datarep, "native") && + strcmp(datarep, "NATIVE") && + strcmp(datarep, "external32") && + strcmp(datarep, "EXTERNAL32") && + strcmp(datarep, "internal") && strcmp(datarep, "INTERNAL"))) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, + MPI_ERR_UNSUPPORTED_DATAREP, "**unsupporteddatarep", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + if (disp == MPI_DISPLACEMENT_CURRENT) { + ADIO_Offset shared_fp, byte_off; + + MPI_Barrier(adio_fh->comm); + ADIO_Get_shared_fp(adio_fh, 0, &shared_fp, &error_code); + /* TODO: check error code */ + + MPI_Barrier(adio_fh->comm); + ADIOI_Get_byte_offset(adio_fh, shared_fp, &byte_off); + /* TODO: check error code */ + + disp = byte_off; + } + + ADIO_Set_view(adio_fh, disp, etype, filetype, info, &error_code); + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) { + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + /* reset shared file pointer to zero */ + if (ADIO_Feature(adio_fh, ADIO_SHARED_FP) && (adio_fh->shared_fp_fd != ADIO_FILE_NULL)) { + /* only one process needs to set it to zero, but I don't want to + * create the shared-file-pointer file if shared file pointers have + * not been used so far. Therefore, every process that has already + * opened the shared-file-pointer file sets the shared file pointer + * to zero. If the file was not opened, the value is automatically + * zero. Note that shared file pointer is stored as no. of etypes + * relative to the current view, whereas indiv. file pointer is + * stored in bytes. */ + + ADIO_Set_shared_fp(adio_fh, 0, &error_code); + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + } + + if (ADIO_Feature(adio_fh, ADIO_SHARED_FP)) { + MPI_Barrier(adio_fh->comm); /* for above to work correctly */ + } + if (strcmp(datarep, "external32") && strcmp(datarep, "EXTERNAL32")) + adio_fh->is_external32 = 0; + else + adio_fh->is_external32 = 1; + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_sync_impl(MPI_File fh) +{ + int error_code = MPI_SUCCESS; + + ADIO_File adio_fh = MPIO_File_resolve(fh); + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + if ((adio_fh == NULL) || ((adio_fh)->cookie != ADIOI_FILE_COOKIE)) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobadfh", 0); + goto fn_fail; + } + + MPIO_CHECK_WRITABLE(fh, __func__, error_code); + + ADIO_Flush(adio_fh, &error_code); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +int MPIR_File_write_impl(MPI_File fh, const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status) +{ + return MPIOI_File_write(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, buf, count, datatype, status); +} + +int MPIR_File_write_all_impl(MPI_File fh, const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status) +{ + return MPIOI_File_write_all(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, buf, count, datatype, status); +} + +int MPIR_File_write_all_begin_impl(MPI_File fh, const void *buf, MPI_Aint count, + MPI_Datatype datatype) +{ + return MPIOI_File_write_all_begin(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, buf, count, datatype); +} + +int MPIR_File_write_all_end_impl(MPI_File fh, const void *buf, MPI_Status * status) +{ + return MPIOI_File_write_all_end(fh, buf, status); +} + +int MPIR_File_write_at_impl(MPI_File fh, MPI_Offset offset, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Status * status) +{ + return MPIOI_File_write(fh, offset, ADIO_EXPLICIT_OFFSET, buf, count, datatype, status); +} + +int MPIR_File_write_at_all_impl(MPI_File fh, MPI_Offset offset, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Status * status) +{ + return MPIOI_File_write_all(fh, offset, ADIO_EXPLICIT_OFFSET, buf, count, datatype, status); +} + +int MPIR_File_write_at_all_begin_impl(MPI_File fh, MPI_Offset offset, const void *buf, + MPI_Aint count, MPI_Datatype datatype) +{ + return MPIOI_File_write_all_begin(fh, offset, ADIO_EXPLICIT_OFFSET, buf, count, datatype); +} + +int MPIR_File_write_at_all_end_impl(MPI_File fh, const void *buf, MPI_Status * status) +{ + return MPIOI_File_write_all_end(fh, buf, status); +} + +int MPIR_File_write_ordered_impl(MPI_File fh, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Status * status) +{ + return MPIOI_File_write_ordered(fh, buf, count, datatype, status); +} + +int MPIR_File_write_ordered_begin_impl(MPI_File fh, const void *buf, MPI_Aint count, + MPI_Datatype datatype) +{ + return MPIOI_File_write_ordered_begin(fh, buf, count, datatype); +} + +int MPIR_File_write_ordered_end_impl(MPI_File fh, const void *buf, MPI_Status * status) +{ + return MPIOI_File_write_ordered_end(fh, buf, status); +} + +int MPIR_File_write_shared_impl(MPI_File fh, const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status) +{ + return MPIOI_File_write_shared(fh, buf, count, datatype, status); +} + +int MPIR_Register_datarep_impl(ROMIO_CONST char *datarep, + MPI_Datarep_conversion_function * read_conversion_fn, + MPI_Datarep_conversion_function * write_conversion_fn, + MPI_Datarep_extent_function * dtype_file_extent_fn, + void *extra_state) +{ + int is_large = false; + return MPIOI_Register_datarep(datarep, (MPIOI_VOID_FN *) read_conversion_fn, + (MPIOI_VOID_FN *) write_conversion_fn, + dtype_file_extent_fn, extra_state, is_large); +} + +int MPIR_Register_datarep_large_impl(ROMIO_CONST char *datarep, + MPI_Datarep_conversion_function_c * read_conversion_fn, + MPI_Datarep_conversion_function_c * write_conversion_fn, + MPI_Datarep_extent_function * dtype_file_extent_fn, + void *extra_state) +{ + int is_large = true; + return MPIOI_Register_datarep(datarep, (MPIOI_VOID_FN *) read_conversion_fn, + (MPIOI_VOID_FN *) write_conversion_fn, + dtype_file_extent_fn, extra_state, is_large); +} + +MPI_Fint MPIR_File_c2f_impl(MPI_File fh) +{ + return MPIO_File_c2f(fh); +} + +MPI_File MPIR_File_f2c_impl(MPI_Fint fh) +{ + return MPIO_File_f2c(fh); +} + +/* internal routines */ + +static int MPIOI_File_iread(MPI_File fh, MPI_Offset offset, int file_ptr_type, + void *buf, MPI_Aint count, MPI_Datatype datatype, MPI_Request * request) +{ + int error_code, buftype_is_contig, filetype_is_contig; + MPI_Count datatype_size; + ADIO_Status status; + ADIO_File adio_fh; + ADIO_Offset off, bufsize; + MPI_Offset nbytes = 0; + void *xbuf = NULL, *e32_buf = NULL, *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + + if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + MPI_Type_size_x(datatype, &datatype_size); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_READABLE(adio_fh, __func__, error_code); + MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); + ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig); + + ADIOI_TEST_DEFERRED(adio_fh, __func__, &error_code); + + xbuf = buf; + if (adio_fh->is_external32) { + MPI_Aint e32_size = 0; + error_code = MPIU_datatype_full_size(datatype, &e32_size); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + e32_buf = ADIOI_Malloc(e32_size * count); + xbuf = e32_buf; + } else { + MPIO_GPU_HOST_ALLOC(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + + if (buftype_is_contig && filetype_is_contig) { + /* convert count and offset to bytes */ + bufsize = datatype_size * count; + + if (file_ptr_type == ADIO_EXPLICIT_OFFSET) { + off = adio_fh->disp + adio_fh->etype_size * offset; + } else { + off = adio_fh->fp_ind; + } + + if (!(adio_fh->atomicity)) + ADIO_IreadContig(adio_fh, xbuf, count, datatype, file_ptr_type, + off, request, &error_code); + else { + /* to maintain strict atomicity semantics with other concurrent + * operations, lock (exclusive) and call blocking routine */ + if (ADIO_Feature(adio_fh, ADIO_LOCKS)) { + ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize); + } + + ADIO_ReadContig(adio_fh, xbuf, count, datatype, file_ptr_type, + off, &status, &error_code); + + if (ADIO_Feature(adio_fh, ADIO_LOCKS)) { + ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize); + } + if (error_code == MPI_SUCCESS) { + nbytes = count * datatype_size; + } + MPIO_Completed_request_create(&adio_fh, nbytes, &error_code, request); + } + } else + ADIO_IreadStrided(adio_fh, xbuf, count, datatype, file_ptr_type, + offset, request, &error_code); + + if (e32_buf != NULL) { + error_code = MPIU_read_external32_conversion_fn(buf, datatype, count, e32_buf); + ADIOI_Free(e32_buf); + } + + MPIO_GPU_SWAP_BACK(host_buf, buf, count, datatype); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_iread_all(MPI_File fh, MPI_Offset offset, int file_ptr_type, + void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request) +{ + int error_code; + MPI_Count datatype_size; + ADIO_File adio_fh; + void *xbuf = NULL, *e32_buf = NULL, *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + + if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + MPI_Type_size_x(datatype, &datatype_size); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_READABLE(adio_fh, __func__, error_code); + MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + xbuf = buf; + if (adio_fh->is_external32) { + MPI_Aint e32_size = 0; + error_code = MPIU_datatype_full_size(datatype, &e32_size); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + e32_buf = ADIOI_Malloc(e32_size * count); + xbuf = e32_buf; + } else { + MPIO_GPU_HOST_ALLOC(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + + ADIO_IreadStridedColl(adio_fh, xbuf, count, datatype, file_ptr_type, + offset, request, &error_code); + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + + if (e32_buf != NULL) { + error_code = MPIU_read_external32_conversion_fn(buf, datatype, count, e32_buf); + ADIOI_Free(e32_buf); + } + + MPIO_GPU_SWAP_BACK(host_buf, buf, count, datatype); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_iread_shared(MPI_File fh, void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Request * request) +{ + int error_code, buftype_is_contig, filetype_is_contig; + ADIO_Offset bufsize; + ADIO_File adio_fh; + MPI_Count datatype_size, incr; + MPI_Status status; + ADIO_Offset off, shared_fp; + MPI_Offset nbytes = 0; + void *xbuf = NULL, *e32_buf = NULL, *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + /* --END ERROR HANDLING-- */ + + MPI_Type_size_x(datatype, &datatype_size); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); + ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig); + + ADIOI_TEST_DEFERRED(adio_fh, __func__, &error_code); + + incr = (count * datatype_size) / adio_fh->etype_size; + ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code); + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) { + /* note: ADIO_Get_shared_fp should have set up error code already? */ + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + xbuf = buf; + if (adio_fh->is_external32) { + MPI_Aint e32_size = 0; + error_code = MPIU_datatype_full_size(datatype, &e32_size); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + e32_buf = ADIOI_Malloc(e32_size * count); + xbuf = e32_buf; + } else { + MPIO_GPU_HOST_ALLOC(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + + if (buftype_is_contig && filetype_is_contig) { + /* convert count and shared_fp to bytes */ + bufsize = datatype_size * count; + off = adio_fh->disp + adio_fh->etype_size * shared_fp; + if (!(adio_fh->atomicity)) { + ADIO_IreadContig(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, + off, request, &error_code); + } else { + /* to maintain strict atomicity semantics with other concurrent + * operations, lock (exclusive) and call blocking routine */ + + if (adio_fh->file_system != ADIO_NFS) { + ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize); + } + + ADIO_ReadContig(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, + off, &status, &error_code); + + if (adio_fh->file_system != ADIO_NFS) { + ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize); + } + if (error_code == MPI_SUCCESS) { + nbytes = count * datatype_size; + } + MPIO_Completed_request_create(&adio_fh, nbytes, &error_code, request); + } + } else { + ADIO_IreadStrided(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, + shared_fp, request, &error_code); + } + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + + if (e32_buf != NULL) { + error_code = MPIU_read_external32_conversion_fn(buf, datatype, count, e32_buf); + ADIOI_Free(e32_buf); + } + + MPIO_GPU_SWAP_BACK(host_buf, buf, count, datatype); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_iwrite(MPI_File fh, MPI_Offset offset, int file_ptr_type, + const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request) +{ + int error_code, buftype_is_contig, filetype_is_contig; + MPI_Count datatype_size; + ADIO_Status status; + ADIO_Offset off, bufsize; + ADIO_File adio_fh; + MPI_Offset nbytes = 0; + void *e32buf = NULL; + const void *xbuf = NULL; + void *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + + if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + MPI_Type_size_x(datatype, &datatype_size); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_WRITABLE(adio_fh, __func__, error_code); + MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); + ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig); + + ADIOI_TEST_DEFERRED(adio_fh, __func__, &error_code); + + xbuf = buf; + if (adio_fh->is_external32) { + error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + xbuf = e32buf; + } else { + MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + + if (buftype_is_contig && filetype_is_contig) { + /* convert sizes to bytes */ + bufsize = datatype_size * count; + if (file_ptr_type == ADIO_EXPLICIT_OFFSET) { + off = adio_fh->disp + adio_fh->etype_size * offset; + } else { + off = adio_fh->fp_ind; + } + + if (!(adio_fh->atomicity)) { + ADIO_IwriteContig(adio_fh, xbuf, count, datatype, file_ptr_type, + off, request, &error_code); + } else { + /* to maintain strict atomicity semantics with other concurrent + * operations, lock (exclusive) and call blocking routine */ + if (ADIO_Feature(adio_fh, ADIO_LOCKS)) { + ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize); + } + + ADIO_WriteContig(adio_fh, xbuf, count, datatype, file_ptr_type, off, + &status, &error_code); + + if (ADIO_Feature(adio_fh, ADIO_LOCKS)) { + ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize); + } + if (error_code == MPI_SUCCESS) { + nbytes = count * datatype_size; + } + + MPIO_Completed_request_create(&adio_fh, nbytes, &error_code, request); + } + } else { + ADIO_IwriteStrided(adio_fh, xbuf, count, datatype, file_ptr_type, + offset, request, &error_code); + } + + MPIO_GPU_HOST_FREE(host_buf, count, datatype); + + fn_exit: + if (e32buf != NULL) + ADIOI_Free(e32buf); + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_iwrite_all(MPI_File fh, MPI_Offset offset, int file_ptr_type, + const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request) +{ + int error_code; + MPI_Count datatype_size; + ADIO_File adio_fh; + void *e32buf = NULL; + const void *xbuf = NULL; + void *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + + if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + MPI_Type_size_x(datatype, &datatype_size); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_WRITABLE(adio_fh, __func__, error_code); + MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + xbuf = buf; + if (adio_fh->is_external32) { + error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + xbuf = e32buf; + } else { + MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + + ADIO_IwriteStridedColl(adio_fh, xbuf, count, datatype, file_ptr_type, + offset, request, &error_code); + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + + MPIO_GPU_HOST_FREE(host_buf, count, datatype); + + fn_exit: + if (e32buf != NULL) + ADIOI_Free(e32buf); + + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_iwrite_shared(MPI_File fh, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPIO_Request * request) +{ + int error_code, buftype_is_contig, filetype_is_contig; + ADIO_File adio_fh; + ADIO_Offset incr, bufsize; + MPI_Count datatype_size; + ADIO_Status status; + ADIO_Offset off, shared_fp; + void *e32buf = NULL; + const void *xbuf = NULL; + void *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + /* --END ERROR HANDLING-- */ + + MPI_Type_size_x(datatype, &datatype_size); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); + ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig); + + ADIOI_TEST_DEFERRED(adio_fh, __func__, &error_code); + + incr = (count * datatype_size) / adio_fh->etype_size; + ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code); + if (error_code != MPI_SUCCESS) { + /* note: ADIO_Get_shared_fp should have set up error code already? */ + goto fn_fail; + } + + xbuf = buf; + if (adio_fh->is_external32) { + error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + xbuf = e32buf; + } else { + MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + + /* contiguous or strided? */ + if (buftype_is_contig && filetype_is_contig) { + /* convert sizes to bytes */ + bufsize = datatype_size * count; + off = adio_fh->disp + adio_fh->etype_size * shared_fp; + if (!(adio_fh->atomicity)) + ADIO_IwriteContig(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, + off, request, &error_code); + else { + /* to maintain strict atomicity semantics with other concurrent + * operations, lock (exclusive) and call blocking routine */ + + if (adio_fh->file_system != ADIO_NFS) + ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize); + + ADIO_WriteContig(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, + off, &status, &error_code); + + if (adio_fh->file_system != ADIO_NFS) + ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize); + + MPIO_Completed_request_create(&adio_fh, bufsize, &error_code, request); + } + } else + ADIO_IwriteStrided(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, + shared_fp, request, &error_code); + + MPIO_GPU_HOST_FREE(host_buf, count, datatype); + + fn_exit: + if (e32buf != NULL) + ADIOI_Free(e32buf); + + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_read(MPI_File fh, MPI_Offset offset, int file_ptr_type, + void *buf, MPI_Aint count, MPI_Datatype datatype, MPI_Status * status) +{ + int error_code, buftype_is_contig, filetype_is_contig; + MPI_Count datatype_size; + ADIO_File adio_fh; + ADIO_Offset off, bufsize; + void *xbuf = NULL, *e32_buf = NULL, *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + + if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + MPI_Type_size_x(datatype, &datatype_size); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + if (count * datatype_size == 0) { +#ifdef HAVE_STATUS_SET_BYTES + MPIR_Status_set_bytes(status, datatype, 0); +#endif + error_code = MPI_SUCCESS; + goto fn_exit; + } + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_READABLE(adio_fh, __func__, error_code); + MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, __func__, error_code); + /* --END ERROR HANDLING-- */ + + ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); + ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig); + + ADIOI_TEST_DEFERRED(adio_fh, __func__, &error_code); + + xbuf = buf; + if (adio_fh->is_external32) { + MPI_Aint e32_size = 0; + error_code = MPIU_datatype_full_size(datatype, &e32_size); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + e32_buf = ADIOI_Malloc(e32_size * count); + xbuf = e32_buf; + } else { + MPIO_GPU_HOST_ALLOC(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + + if (buftype_is_contig && filetype_is_contig) { + /* convert count and offset to bytes */ + bufsize = datatype_size * count; + if (file_ptr_type == ADIO_EXPLICIT_OFFSET) { + off = adio_fh->disp + adio_fh->etype_size * offset; + } else { /* ADIO_INDIVIDUAL */ + + off = adio_fh->fp_ind; + } + + /* if atomic mode requested, lock (exclusive) the region, because + * there could be a concurrent noncontiguous request. + */ + if ((adio_fh->atomicity) && ADIO_Feature(adio_fh, ADIO_LOCKS)) { + ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize); + } + + ADIO_ReadContig(adio_fh, xbuf, count, datatype, file_ptr_type, off, status, &error_code); + + if ((adio_fh->atomicity) && ADIO_Feature(adio_fh, ADIO_LOCKS)) { + ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize); + } + } else { + ADIO_ReadStrided(adio_fh, xbuf, count, datatype, file_ptr_type, + offset, status, &error_code); + /* For strided and atomic mode, locking is done in ADIO_ReadStrided */ + } + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + + if (e32_buf != NULL) { + error_code = MPIU_read_external32_conversion_fn(buf, datatype, count, e32_buf); + ADIOI_Free(e32_buf); + } + + MPIO_GPU_SWAP_BACK(host_buf, buf, count, datatype); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_read_all(MPI_File fh, MPI_Offset offset, int file_ptr_type, + void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status) +{ + int error_code; + MPI_Count datatype_size; + ADIO_File adio_fh; + void *xbuf = NULL, *e32_buf = NULL, *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + + if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + MPI_Type_size_x(datatype, &datatype_size); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_READABLE(adio_fh, __func__, error_code); + MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + xbuf = buf; + if (adio_fh->is_external32) { + MPI_Aint e32_size = 0; + error_code = MPIU_datatype_full_size(datatype, &e32_size); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + e32_buf = ADIOI_Malloc(e32_size * count); + xbuf = e32_buf; + } else { + MPIO_GPU_HOST_ALLOC(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + + ADIO_ReadStridedColl(adio_fh, xbuf, count, datatype, file_ptr_type, + offset, status, &error_code); + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + + if (e32_buf != NULL) { + error_code = MPIU_read_external32_conversion_fn(buf, datatype, count, e32_buf); + ADIOI_Free(e32_buf); + } + + MPIO_GPU_SWAP_BACK(host_buf, buf, count, datatype); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_read_all_begin(MPI_File fh, MPI_Offset offset, int file_ptr_type, + void *buf, MPI_Aint count, MPI_Datatype datatype) +{ + int error_code; + MPI_Count datatype_size; + ADIO_File adio_fh; + void *xbuf = NULL, *e32_buf = NULL, *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + + if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + MPI_Type_size_x(datatype, &datatype_size); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_READABLE(adio_fh, __func__, error_code); + MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, __func__, error_code); + + if (adio_fh->split_coll_count) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_IO, "**iosplitcoll", 0); + goto fn_fail; + } + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + adio_fh->split_coll_count = 1; + + xbuf = buf; + if (adio_fh->is_external32) { + MPI_Aint e32_size = 0; + error_code = MPIU_datatype_full_size(datatype, &e32_size); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + e32_buf = ADIOI_Malloc(e32_size * count); + xbuf = e32_buf; + } else { + MPIO_GPU_HOST_ALLOC(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + + ADIO_ReadStridedColl(adio_fh, xbuf, count, datatype, file_ptr_type, + offset, &adio_fh->split_status, &error_code); + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + + if (e32_buf != NULL) { + error_code = MPIU_read_external32_conversion_fn(buf, datatype, count, e32_buf); + ADIOI_Free(e32_buf); + } + + MPIO_GPU_SWAP_BACK(host_buf, buf, count, datatype); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_read_all_end(MPI_File fh, void *buf, MPI_Status * status) +{ + int error_code = MPI_SUCCESS; + ADIO_File adio_fh; + + MPL_UNREFERENCED_ARG(buf); + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + if (!(adio_fh->split_coll_count)) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_IO, "**iosplitcollnone", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + +#ifdef HAVE_STATUS_SET_BYTES + if (status != MPI_STATUS_IGNORE) + *status = adio_fh->split_status; +#endif + adio_fh->split_coll_count = 0; + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_read_ordered(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status) +{ + int error_code, nprocs, myrank; + ADIO_Offset incr; + MPI_Count datatype_size; + int source, dest; + ADIO_Offset shared_fp = 0; + ADIO_File adio_fh; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + /* --END ERROR HANDLING-- */ + + MPI_Type_size_x(datatype, &datatype_size); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + ADIOI_TEST_DEFERRED(adio_fh, "MPI_File_read_ordered", &error_code); + + MPI_Comm_size(adio_fh->comm, &nprocs); + MPI_Comm_rank(adio_fh->comm, &myrank); + + incr = (count * datatype_size) / adio_fh->etype_size; + + /* Use a message as a 'token' to order the operations */ + source = myrank - 1; + dest = myrank + 1; + if (source < 0) + source = MPI_PROC_NULL; + if (dest >= nprocs) + dest = MPI_PROC_NULL; + MPI_Recv(NULL, 0, MPI_BYTE, source, 0, adio_fh->comm, MPI_STATUS_IGNORE); + + ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code); + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) { + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + MPI_Send(NULL, 0, MPI_BYTE, dest, 0, adio_fh->comm); + + ADIO_ReadStridedColl(adio_fh, buf, count, datatype, ADIO_EXPLICIT_OFFSET, + shared_fp, status, &error_code); + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + + fn_exit: + /* FIXME: Check for error code from ReadStridedColl? */ + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_read_ordered_begin(MPI_File fh, + void *buf, MPI_Aint count, MPI_Datatype datatype) +{ + int error_code, nprocs, myrank; + MPI_Count datatype_size; + int source, dest; + ADIO_Offset shared_fp, incr; + ADIO_File adio_fh; + void *xbuf = NULL, *e32_buf = NULL, *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + + if (adio_fh->split_coll_count) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_IO, "**iosplitcoll", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + adio_fh->split_coll_count = 1; + + + MPI_Type_size_x(datatype, &datatype_size); + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + ADIOI_TEST_DEFERRED(adio_fh, __func__, &error_code); + + MPI_Comm_size(adio_fh->comm, &nprocs); + MPI_Comm_rank(adio_fh->comm, &myrank); + + incr = (count * datatype_size) / adio_fh->etype_size; + /* Use a message as a 'token' to order the operations */ + source = myrank - 1; + dest = myrank + 1; + if (source < 0) + source = MPI_PROC_NULL; + if (dest >= nprocs) + dest = MPI_PROC_NULL; + MPI_Recv(NULL, 0, MPI_BYTE, source, 0, adio_fh->comm, MPI_STATUS_IGNORE); + + ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code); + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) { + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + MPI_Send(NULL, 0, MPI_BYTE, dest, 0, adio_fh->comm); + + xbuf = buf; + if (adio_fh->is_external32) { + MPI_Aint e32_size = 0; + error_code = MPIU_datatype_full_size(datatype, &e32_size); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + e32_buf = ADIOI_Malloc(e32_size * count); + xbuf = e32_buf; + } else { + MPIO_GPU_HOST_ALLOC(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + + + ADIO_ReadStridedColl(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, + shared_fp, &adio_fh->split_status, &error_code); + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + + if (e32_buf != NULL) { + error_code = MPIU_read_external32_conversion_fn(buf, datatype, count, e32_buf); + ADIOI_Free(e32_buf); + } + + MPIO_GPU_SWAP_BACK(host_buf, buf, count, datatype); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_read_ordered_end(MPI_File fh, void *buf, MPI_Status * status) +{ + int error_code = MPI_SUCCESS; + ADIO_File adio_fh; + + MPL_UNREFERENCED_ARG(buf); + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + if (!(adio_fh->split_coll_count)) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_IO, "**iosplitcollnone", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + +#ifdef HAVE_STATUS_SET_BYTES + if (status != MPI_STATUS_IGNORE) + *status = adio_fh->split_status; +#endif + adio_fh->split_coll_count = 0; + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_read_shared(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status) +{ + int error_code, buftype_is_contig, filetype_is_contig; + MPI_Count datatype_size; + ADIO_Offset off, shared_fp, incr, bufsize; + ADIO_File adio_fh; + void *xbuf = NULL, *e32_buf = NULL, *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + /* --END ERROR HANDLING-- */ + + MPI_Type_size_x(datatype, &datatype_size); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + if (count * datatype_size == 0) { +#ifdef HAVE_STATUS_SET_BYTES + MPIR_Status_set_bytes(status, datatype, 0); +#endif + error_code = MPI_SUCCESS; + goto fn_exit; + } + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_READABLE(adio_fh, __func__, error_code); + MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, __func__, error_code); + /* --END ERROR HANDLING-- */ + + ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); + ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig); + + ADIOI_TEST_DEFERRED(adio_fh, __func__, &error_code); + + incr = (count * datatype_size) / adio_fh->etype_size; + + ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code); + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) { + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + xbuf = buf; + if (adio_fh->is_external32) { + MPI_Aint e32_size = 0; + error_code = MPIU_datatype_full_size(datatype, &e32_size); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + e32_buf = ADIOI_Malloc(e32_size * count); + xbuf = e32_buf; + } else { + MPIO_GPU_HOST_ALLOC(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + + /* contiguous or strided? */ + if (buftype_is_contig && filetype_is_contig) { + /* convert count and shared_fp to bytes */ + bufsize = datatype_size * count; + off = adio_fh->disp + adio_fh->etype_size * shared_fp; + + /* if atomic mode requested, lock (exclusive) the region, because there + * could be a concurrent noncontiguous request. On NFS, locking + * is done in the ADIO_ReadContig. */ + + if ((adio_fh->atomicity) && (adio_fh->file_system != ADIO_NFS)) + ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize); + + ADIO_ReadContig(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, + off, status, &error_code); + + if ((adio_fh->atomicity) && (adio_fh->file_system != ADIO_NFS)) + ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize); + } else { + ADIO_ReadStrided(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, + shared_fp, status, &error_code); + /* For strided and atomic mode, locking is done in ADIO_ReadStrided */ + } + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + + if (e32_buf != NULL) { + error_code = MPIU_read_external32_conversion_fn(buf, datatype, count, e32_buf); + ADIOI_Free(e32_buf); + } + + MPIO_GPU_SWAP_BACK(host_buf, buf, count, datatype); + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_write(MPI_File fh, MPI_Offset offset, int file_ptr_type, + const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status) +{ + int error_code, buftype_is_contig, filetype_is_contig; + MPI_Count datatype_size; + ADIO_Offset off, bufsize; + ADIO_File adio_fh; + void *e32buf = NULL; + const void *xbuf = NULL; + void *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + + if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + MPI_Type_size_x(datatype, &datatype_size); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + if (count * datatype_size == 0) { +#ifdef HAVE_STATUS_SET_BYTES + MPIR_Status_set_bytes(status, datatype, 0); +#endif + error_code = MPI_SUCCESS; + goto fn_exit; + } + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_WRITABLE(adio_fh, __func__, error_code); + MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, __func__, error_code); + /* --END ERROR HANDLING-- */ + + ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); + ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig); + + ADIOI_TEST_DEFERRED(adio_fh, __func__, &error_code); + + xbuf = buf; + if (adio_fh->is_external32) { + error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + xbuf = e32buf; + } else { + MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + + if (buftype_is_contig && filetype_is_contig) { + /* convert bufcount and offset to bytes */ + bufsize = datatype_size * count; + if (file_ptr_type == ADIO_EXPLICIT_OFFSET) { + off = adio_fh->disp + adio_fh->etype_size * offset; + } else { /* ADIO_INDIVIDUAL */ + + off = adio_fh->fp_ind; + } + + /* if atomic mode requested, lock (exclusive) the region, because + * there could be a concurrent noncontiguous request. Locking doesn't + * work on some parallel file systems, and on NFS it is done in the + * ADIO_WriteContig. + */ + + if ((adio_fh->atomicity) && ADIO_Feature(adio_fh, ADIO_LOCKS)) { + ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize); + } + + ADIO_WriteContig(adio_fh, xbuf, count, datatype, file_ptr_type, off, status, &error_code); + + if ((adio_fh->atomicity) && ADIO_Feature(adio_fh, ADIO_LOCKS)) { + ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize); + } + } else { + /* For strided and atomic mode, locking is done in ADIO_WriteStrided */ + ADIO_WriteStrided(adio_fh, xbuf, count, datatype, file_ptr_type, + offset, status, &error_code); + } + + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + + MPIO_GPU_HOST_FREE(host_buf, count, datatype); + + fn_exit: + if (e32buf != NULL) + ADIOI_Free(e32buf); + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_write_all(MPI_File fh, MPI_Offset offset, int file_ptr_type, + const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status) +{ + int error_code; + MPI_Count datatype_size; + ADIO_File adio_fh; + void *e32buf = NULL; + const void *xbuf = NULL; + void *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + + if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + MPI_Type_size_x(datatype, &datatype_size); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_WRITABLE(adio_fh, __func__, error_code); + MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + xbuf = buf; + if (adio_fh->is_external32) { + error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + xbuf = e32buf; + } else { + MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + ADIO_WriteStridedColl(adio_fh, xbuf, count, datatype, file_ptr_type, + offset, status, &error_code); + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + + MPIO_GPU_HOST_FREE(host_buf, count, datatype); + + fn_exit: + if (e32buf != NULL) + ADIOI_Free(e32buf); + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_write_all_begin(MPI_File fh, MPI_Offset offset, int file_ptr_type, + const void *buf, MPI_Aint count, MPI_Datatype datatype) +{ + int error_code; + MPI_Count datatype_size; + ADIO_File adio_fh; + void *e32buf = NULL; + const void *xbuf = NULL; + void *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, __func__, error_code); + + if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); + goto fn_fail; + } + + if (adio_fh->split_coll_count) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_IO, "**iosplitcoll", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + adio_fh->split_coll_count = 1; + + MPI_Type_size_x(datatype, &datatype_size); + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + + xbuf = buf; + if (adio_fh->is_external32) { + error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + xbuf = e32buf; + } else { + MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + + adio_fh->split_datatype = datatype; + ADIO_WriteStridedColl(adio_fh, xbuf, count, datatype, file_ptr_type, + offset, &adio_fh->split_status, &error_code); + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + + MPIO_GPU_HOST_FREE(host_buf, count, datatype); + + fn_exit: + if (e32buf != NULL) + ADIOI_Free(e32buf); + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_write_all_end(MPI_File fh, const void *buf, MPI_Status * status) +{ + int error_code; + ADIO_File adio_fh; + + MPL_UNREFERENCED_ARG(buf); + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + if (!(adio_fh->split_coll_count)) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_IO, "**iosplitcollnone", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + +#ifdef HAVE_STATUS_SET_BYTES + /* FIXME - we should really ensure that the split_datatype remains + * valid by incrementing the ref count in the write_allb.c routine + * and decrement it here after setting the bytes */ + if (status != MPI_STATUS_IGNORE) + *status = adio_fh->split_status; +#endif + adio_fh->split_coll_count = 0; + + error_code = MPI_SUCCESS; + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_write_ordered(MPI_File fh, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Status * status) +{ + int error_code, nprocs, myrank; + ADIO_Offset incr; + MPI_Count datatype_size; + int source, dest; + ADIO_Offset shared_fp; + ADIO_File adio_fh; + void *e32buf = NULL; + const void *xbuf; + void *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + /* --END ERROR HANDLING-- */ + + MPI_Type_size_x(datatype, &datatype_size); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + ADIOI_TEST_DEFERRED(adio_fh, __func__, &error_code); + + MPI_Comm_size(adio_fh->comm, &nprocs); + MPI_Comm_rank(adio_fh->comm, &myrank); + + incr = (count * datatype_size) / adio_fh->etype_size; + /* Use a message as a 'token' to order the operations */ + source = myrank - 1; + dest = myrank + 1; + if (source < 0) + source = MPI_PROC_NULL; + if (dest >= nprocs) + dest = MPI_PROC_NULL; + MPI_Recv(NULL, 0, MPI_BYTE, source, 0, adio_fh->comm, MPI_STATUS_IGNORE); + + ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code); + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL, + __func__, __LINE__, MPI_ERR_INTERN, "**iosharedfailed", + 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + MPI_Send(NULL, 0, MPI_BYTE, dest, 0, adio_fh->comm); + + xbuf = buf; + if (adio_fh->is_external32) { + error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + xbuf = e32buf; + } else { + MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + + ADIO_WriteStridedColl(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, + shared_fp, status, &error_code); + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + + MPIO_GPU_HOST_FREE(host_buf, count, datatype); + + fn_exit: + if (e32buf != NULL) + ADIOI_Free(e32buf); + /* FIXME: Check for error code from WriteStridedColl? */ + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_write_ordered_begin(MPI_File fh, const void *buf, MPI_Aint count, + MPI_Datatype datatype) +{ + int error_code, nprocs, myrank; + ADIO_Offset incr; + MPI_Count datatype_size; + int source, dest; + ADIO_Offset shared_fp; + ADIO_File adio_fh; + void *e32buf = NULL; + const void *xbuf = NULL; + void *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + + if (adio_fh->split_coll_count) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_IO, "**iosplitcoll", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + adio_fh->split_coll_count = 1; + + MPI_Type_size_x(datatype, &datatype_size); + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + ADIOI_TEST_DEFERRED(adio_fh, __func__, &error_code); + + MPI_Comm_size(adio_fh->comm, &nprocs); + MPI_Comm_rank(adio_fh->comm, &myrank); + + incr = (count * datatype_size) / adio_fh->etype_size; + /* Use a message as a 'token' to order the operations */ + source = myrank - 1; + dest = myrank + 1; + if (source < 0) + source = MPI_PROC_NULL; + if (dest >= nprocs) + dest = MPI_PROC_NULL; + MPI_Recv(NULL, 0, MPI_BYTE, source, 0, adio_fh->comm, MPI_STATUS_IGNORE); + + ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code); + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL, + __func__, __LINE__, MPI_ERR_INTERN, "**iosharedfailed", + 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + MPI_Send(NULL, 0, MPI_BYTE, dest, 0, adio_fh->comm); + + xbuf = buf; + if (adio_fh->is_external32) { + error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + xbuf = e32buf; + } else { + MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + + ADIO_WriteStridedColl(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, + shared_fp, &adio_fh->split_status, &error_code); + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + + MPIO_GPU_HOST_FREE(host_buf, count, datatype); + + fn_exit: + /* FIXME: Check for error code from WriteStridedColl? */ + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_write_ordered_end(MPI_File fh, const void *buf, MPI_Status * status) +{ + int error_code = MPI_SUCCESS; + ADIO_File adio_fh; + + MPL_UNREFERENCED_ARG(buf); + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + + if (!(adio_fh->split_coll_count)) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + __func__, __LINE__, MPI_ERR_IO, "**iosplitcollnone", 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + +#ifdef HAVE_STATUS_SET_BYTES + if (status != MPI_STATUS_IGNORE) + *status = adio_fh->split_status; +#endif + adio_fh->split_coll_count = 0; + + + fn_exit: + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_File_write_shared(MPI_File fh, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Status * status) +{ + int error_code, buftype_is_contig, filetype_is_contig; + ADIO_Offset bufsize; + MPI_Count datatype_size, incr; + ADIO_Offset off, shared_fp; + ADIO_File adio_fh; + void *e32buf = NULL; + const void *xbuf = NULL; + void *host_buf = NULL; + + adio_fh = MPIO_File_resolve(fh); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_FILE_HANDLE(adio_fh, __func__, error_code); + MPIO_CHECK_COUNT(adio_fh, count, __func__, error_code); + MPIO_CHECK_DATATYPE(adio_fh, datatype, __func__, error_code); + /* --END ERROR HANDLING-- */ + + MPI_Type_size_x(datatype, &datatype_size); + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, __func__, error_code); + /* --END ERROR HANDLING-- */ + + if (count * datatype_size == 0) { +#ifdef HAVE_STATUS_SET_BYTES + MPIR_Status_set_bytes(status, datatype, 0); +#endif + error_code = MPI_SUCCESS; + goto fn_exit; + } + + /* --BEGIN ERROR HANDLING-- */ + MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, __func__, error_code); + MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, __func__, error_code); + /* --END ERROR HANDLING-- */ + + ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); + ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig); + + ADIOI_TEST_DEFERRED(adio_fh, __func__, &error_code); + + incr = (count * datatype_size) / adio_fh->etype_size; + + ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code); + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL, + __func__, __LINE__, MPI_ERR_INTERN, "**iosharedfailed", + 0); + goto fn_fail; + } + /* --END ERROR HANDLING-- */ + + xbuf = buf; + if (adio_fh->is_external32) { + error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + xbuf = e32buf; + } else { + MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); + if (host_buf != NULL) { + xbuf = host_buf; + } + } + + if (buftype_is_contig && filetype_is_contig) { + /* convert bufocunt and shared_fp to bytes */ + bufsize = datatype_size * count; + off = adio_fh->disp + adio_fh->etype_size * shared_fp; + + /* if atomic mode requested, lock (exclusive) the region, because there + * could be a concurrent noncontiguous request. On NFS, locking is + * done in the ADIO_WriteContig. */ + + if ((adio_fh->atomicity) && (adio_fh->file_system != ADIO_NFS)) + ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize); + + ADIO_WriteContig(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, + off, status, &error_code); + + if ((adio_fh->atomicity) && (adio_fh->file_system != ADIO_NFS)) + ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize); + } else { + ADIO_WriteStrided(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, + shared_fp, status, &error_code); + /* For strided and atomic mode, locking is done in ADIO_WriteStrided */ + } + + /* --BEGIN ERROR HANDLING-- */ + if (error_code != MPI_SUCCESS) + goto fn_fail; + /* --END ERROR HANDLING-- */ + + MPIO_GPU_HOST_FREE(host_buf, count, datatype); + + fn_exit: + if (e32buf != NULL) + ADIOI_Free(e32buf); + return error_code; + fn_fail: + goto fn_exit; +} + +static int MPIOI_Register_datarep(const char *datarep, + MPIOI_VOID_FN * read_conversion_fn, + MPIOI_VOID_FN * write_conversion_fn, + MPI_Datarep_extent_function * dtype_file_extent_fn, + void *extra_state, int is_large) +{ + int error_code; + ADIOI_Datarep *adio_datarep; + static char myname[] = "MPI_REGISTER_DATAREP"; + + ROMIO_THREAD_CS_ENTER(); + + /* --BEGIN ERROR HANDLING-- */ + /* check datarep name (use strlen instead of strnlen because + * strnlen is not portable) */ + if (datarep == NULL || strlen(datarep) < 1 || strlen(datarep) > MPI_MAX_DATAREP_STRING) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, + MPIR_ERR_RECOVERABLE, + myname, __LINE__, MPI_ERR_ARG, "**datarepname", 0); + error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code); + goto fn_exit; + } + /* --END ERROR HANDLING-- */ + + MPIR_MPIOInit(&error_code); + if (error_code != MPI_SUCCESS) + goto fn_exit; + + /* --BEGIN ERROR HANDLING-- */ + /* check datarep isn't already registered */ + for (adio_datarep = ADIOI_Datarep_head; adio_datarep; adio_datarep = adio_datarep->next) { + if (!strncmp(datarep, adio_datarep->name, MPI_MAX_DATAREP_STRING)) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, + MPIR_ERR_RECOVERABLE, + myname, __LINE__, + MPI_ERR_DUP_DATAREP, + "**datarepused", "**datarepused %s", datarep); + error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code); + goto fn_exit; + } + } + + /* Check Non-NULL Read and Write conversion function pointer */ + /* Read and Write conversions are currently not supported. */ + if ((read_conversion_fn != NULL) || (write_conversion_fn != NULL)) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, + myname, __LINE__, + MPI_ERR_CONVERSION, "**drconvnotsupported", 0); + + error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code); + goto fn_exit; + } + + /* check extent function pointer */ + if (dtype_file_extent_fn == NULL) { + error_code = MPIO_Err_create_code(MPI_SUCCESS, + MPIR_ERR_RECOVERABLE, + myname, __LINE__, MPI_ERR_ARG, "**datarepextent", 0); + error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code); + goto fn_exit; + } + /* --END ERROR HANDLING-- */ + + adio_datarep = ADIOI_Malloc(sizeof(ADIOI_Datarep)); + adio_datarep->name = ADIOI_Strdup(datarep); + adio_datarep->state = extra_state; + adio_datarep->is_large = is_large; + if (is_large) { + adio_datarep->u.large.read_conv_fn = + (MPI_Datarep_conversion_function_c *) read_conversion_fn; + adio_datarep->u.large.write_conv_fn = + (MPI_Datarep_conversion_function_c *) write_conversion_fn; + } else { + adio_datarep->u.small.read_conv_fn = (MPI_Datarep_conversion_function *) read_conversion_fn; + adio_datarep->u.small.write_conv_fn = + (MPI_Datarep_conversion_function *) write_conversion_fn; + } + adio_datarep->extent_fn = dtype_file_extent_fn; + adio_datarep->next = ADIOI_Datarep_head; + + ADIOI_Datarep_head = adio_datarep; + + error_code = MPI_SUCCESS; + + fn_exit: + ROMIO_THREAD_CS_EXIT(); + + return error_code; +} diff --git a/src/mpi/romio/mpi-io/iotest.c b/src/mpi/romio/mpi-io/iotest.c index 1c15633b847..8db06b07cf3 100644 --- a/src/mpi/romio/mpi-io/iotest.c +++ b/src/mpi/romio/mpi-io/iotest.c @@ -45,13 +45,6 @@ int MPIO_Test(MPIO_Request * request, int *flag, MPI_Status * status) { int error_code; static char myname[] = "MPIO_TEST"; -#ifdef MPI_hpux - int fl_xmpi; - - if (*request != MPIO_REQUEST_NULL) { - HPMP_IO_WSTART(fl_xmpi, BLKMPIOTEST, TRDTSYSTEM, (*request)->fd); - } -#endif /* MPI_hpux */ ROMIO_THREAD_CS_ENTER(); @@ -78,9 +71,6 @@ int MPIO_Test(MPIO_Request * request, int *flag, MPI_Status * status) break; } -#ifdef MPI_hpux - HPMP_IO_WEND(fl_xmpi); -#endif /* MPI_hpux */ fn_exit: ROMIO_THREAD_CS_EXIT(); diff --git a/src/mpi/romio/mpi-io/iowait.c b/src/mpi/romio/mpi-io/iowait.c index a624d9763f4..97ef4c6edd3 100644 --- a/src/mpi/romio/mpi-io/iowait.c +++ b/src/mpi/romio/mpi-io/iowait.c @@ -45,13 +45,6 @@ int MPIO_Wait(MPIO_Request * request, MPI_Status * status) int error_code; static char myname[] = "MPIO_WAIT"; -#ifdef MPI_hpux - int fl_xmpi; - - if (*request != MPIO_REQUEST_NULL) { - HPMP_IO_WSTART(fl_xmpi, BLKMPIOWAIT, TRDTBLOCK, (*request)->fd); - } -#endif /* MPI_hpux */ ROMIO_THREAD_CS_ENTER(); @@ -79,9 +72,6 @@ int MPIO_Wait(MPIO_Request * request, MPI_Status * status) break; } -#ifdef MPI_hpux - HPMP_IO_WEND(fl_xmpi); -#endif /* MPI_hpux */ fn_exit: ROMIO_THREAD_CS_EXIT(); diff --git a/src/mpi/romio/mpi-io/iread.c b/src/mpi/romio/mpi-io/iread.c index 0d004fdaaea..43480685d9b 100644 --- a/src/mpi/romio/mpi-io/iread.c +++ b/src/mpi/romio/mpi-io/iread.c @@ -59,28 +59,20 @@ Output Parameters: @*/ int MPI_File_iread(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Request * request) { - int error_code = MPI_SUCCESS; - static char myname[] = "MPI_FILE_IREAD"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEIREAD, TRDTSYSTEM, fh, datatype, count); -#endif /* MPI_hpux */ - - - error_code = MPIOI_File_iread(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, - buf, count, datatype, myname, request); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(fh, error_code); - /* --END ERROR HANDLING-- */ + int error_code; + ROMIO_THREAD_CS_ENTER(); -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_iread_impl(fh, buf, count, datatype, request); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -107,135 +99,18 @@ Output Parameters: int MPI_File_iread_c(MPI_File fh, void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Request * request) { - int error_code = MPI_SUCCESS; - static char myname[] = "MPI_FILE_IREAD"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEIREAD, TRDTSYSTEM, fh, datatype, count); -#endif /* MPI_hpux */ - - - error_code = MPIOI_File_iread(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, - buf, count, datatype, myname, request); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(fh, error_code); - /* --END ERROR HANDLING-- */ - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ - - return error_code; -} - -/* prevent multiple definitions of this routine */ -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_iread(MPI_File fh, MPI_Offset offset, int file_ptr_type, void *buf, MPI_Aint count, - MPI_Datatype datatype, char *myname, MPI_Request * request) -{ - int error_code, buftype_is_contig, filetype_is_contig; - MPI_Count datatype_size; - ADIO_Status status; - ADIO_File adio_fh; - ADIO_Offset off, bufsize; - MPI_Offset nbytes = 0; - void *xbuf = NULL, *e32_buf = NULL, *host_buf = NULL; - + int error_code; ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - - if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - MPI_Type_size_x(datatype, &datatype_size); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_READABLE(adio_fh, myname, error_code); - MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); - ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig); - - ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code); - - xbuf = buf; - if (adio_fh->is_external32) { - MPI_Aint e32_size = 0; - error_code = MPIU_datatype_full_size(datatype, &e32_size); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - e32_buf = ADIOI_Malloc(e32_size * count); - xbuf = e32_buf; - } else { - MPIO_GPU_HOST_ALLOC(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } - } - - if (buftype_is_contig && filetype_is_contig) { - /* convert count and offset to bytes */ - bufsize = datatype_size * count; - - if (file_ptr_type == ADIO_EXPLICIT_OFFSET) { - off = adio_fh->disp + adio_fh->etype_size * offset; - } else { - off = adio_fh->fp_ind; - } - - if (!(adio_fh->atomicity)) - ADIO_IreadContig(adio_fh, xbuf, count, datatype, file_ptr_type, - off, request, &error_code); - else { - /* to maintain strict atomicity semantics with other concurrent - * operations, lock (exclusive) and call blocking routine */ - if (ADIO_Feature(adio_fh, ADIO_LOCKS)) { - ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize); - } - - ADIO_ReadContig(adio_fh, xbuf, count, datatype, file_ptr_type, - off, &status, &error_code); - - if (ADIO_Feature(adio_fh, ADIO_LOCKS)) { - ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize); - } - if (error_code == MPI_SUCCESS) { - nbytes = count * datatype_size; - } - MPIO_Completed_request_create(&adio_fh, nbytes, &error_code, request); - } - } else - ADIO_IreadStrided(adio_fh, xbuf, count, datatype, file_ptr_type, - offset, request, &error_code); - - if (e32_buf != NULL) { - error_code = MPIU_read_external32_conversion_fn(buf, datatype, count, e32_buf); - ADIOI_Free(e32_buf); + error_code = MPIR_File_iread_impl(fh, buf, count, datatype, request); + if (error_code) { + goto fn_fail; } - MPIO_GPU_SWAP_BACK(host_buf, buf, count, datatype); - fn_exit: ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/iread_all.c b/src/mpi/romio/mpi-io/iread_all.c index 7aa7dbd7d32..da2556b3132 100644 --- a/src/mpi/romio/mpi-io/iread_all.c +++ b/src/mpi/romio/mpi-io/iread_all.c @@ -62,27 +62,19 @@ int MPI_File_iread_all(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Request * request) { int error_code; - static char myname[] = "MPI_FILE_IREAD_ALL"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEREADALL, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - error_code = MPIOI_File_iread_all(fh, (MPI_Offset) 0, - ADIO_INDIVIDUAL, buf, count, datatype, myname, request); + ROMIO_THREAD_CS_ENTER(); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) { - error_code = MPIO_Err_return_file(fh, error_code); + error_code = MPIR_File_iread_all_impl(fh, buf, count, datatype, request); + if (error_code) { + goto fn_fail; } - /* --END ERROR HANDLING-- */ - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -110,103 +102,17 @@ int MPI_File_iread_all_c(MPI_File fh, void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Request * request) { int error_code; - static char myname[] = "MPI_FILE_IREAD_ALL"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEREADALL, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - error_code = MPIOI_File_iread_all(fh, (MPI_Offset) 0, - ADIO_INDIVIDUAL, buf, count, datatype, myname, request); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) { - error_code = MPIO_Err_return_file(fh, error_code); - } - /* --END ERROR HANDLING-- */ - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ - - return error_code; -} - -/* Note: MPIOI_File_iread_all also used by MPI_File_iread_at_all */ -/* prevent multiple definitions of this routine */ -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_iread_all(MPI_File fh, - MPI_Offset offset, - int file_ptr_type, - void *buf, - MPI_Aint count, MPI_Datatype datatype, char *myname, MPI_Request * request) -{ - int error_code; - MPI_Count datatype_size; - ADIO_File adio_fh; - void *xbuf = NULL, *e32_buf = NULL, *host_buf = NULL; - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - - if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - MPI_Type_size_x(datatype, &datatype_size); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_READABLE(adio_fh, myname, error_code); - MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - xbuf = buf; - if (adio_fh->is_external32) { - MPI_Aint e32_size = 0; - error_code = MPIU_datatype_full_size(datatype, &e32_size); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - e32_buf = ADIOI_Malloc(e32_size * count); - xbuf = e32_buf; - } else { - MPIO_GPU_HOST_ALLOC(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } - } - - ADIO_IreadStridedColl(adio_fh, xbuf, count, datatype, file_ptr_type, - offset, request, &error_code); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - - if (e32_buf != NULL) { - error_code = MPIU_read_external32_conversion_fn(buf, datatype, count, e32_buf); - ADIOI_Free(e32_buf); + error_code = MPIR_File_iread_all_impl(fh, buf, count, datatype, request); + if (error_code) { + goto fn_fail; } - MPIO_GPU_SWAP_BACK(host_buf, buf, count, datatype); - fn_exit: ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/iread_at.c b/src/mpi/romio/mpi-io/iread_at.c index 5381301903a..1d0b2262969 100644 --- a/src/mpi/romio/mpi-io/iread_at.c +++ b/src/mpi/romio/mpi-io/iread_at.c @@ -62,28 +62,19 @@ int MPI_File_iread_at(MPI_File fh, MPI_Offset offset, void *buf, int count, MPI_ MPIO_Request * request) { int error_code; - static char myname[] = "MPI_FILE_IREAD_AT"; + ROMIO_THREAD_CS_ENTER(); -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEIREADAT, TRDTSYSTEM, fh, datatype, count); -#endif /* MPI_hpux */ - - - error_code = MPIOI_File_iread(fh, offset, ADIO_EXPLICIT_OFFSET, buf, - count, datatype, myname, request); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(fh, error_code); - /* --END ERROR HANDLING-- */ - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_iread_at_impl(fh, offset, buf, count, datatype, request); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -112,26 +103,17 @@ int MPI_File_iread_at_c(MPI_File fh, MPI_Offset offset, void *buf, MPI_Count cou MPI_Datatype datatype, MPIO_Request * request) { int error_code; - static char myname[] = "MPI_FILE_IREAD_AT"; - -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEIREADAT, TRDTSYSTEM, fh, datatype, count); -#endif /* MPI_hpux */ - - - error_code = MPIOI_File_iread(fh, offset, ADIO_EXPLICIT_OFFSET, buf, - count, datatype, myname, request); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(fh, error_code); - /* --END ERROR HANDLING-- */ + ROMIO_THREAD_CS_ENTER(); -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_iread_at_impl(fh, offset, buf, count, datatype, request); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/iread_atall.c b/src/mpi/romio/mpi-io/iread_atall.c index 55d8fb2ae43..8688a0f13a3 100644 --- a/src/mpi/romio/mpi-io/iread_atall.c +++ b/src/mpi/romio/mpi-io/iread_atall.c @@ -63,26 +63,19 @@ int MPI_File_iread_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count, MPI_Datatype datatype, MPI_Request * request) { int error_code; - static char myname[] = "MPI_FILE_IREAD_AT_ALL"; -#ifdef MPI_hpux - int fl_xmpi; + ROMIO_THREAD_CS_ENTER(); - HPMP_IO_START(fl_xmpi, BLKMPIFILEIREADATALL, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - error_code = MPIOI_File_iread_all(fh, offset, ADIO_EXPLICIT_OFFSET, buf, - count, datatype, myname, request); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(fh, error_code); - /* --END ERROR HANDLING-- */ - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_iread_at_all_impl(fh, offset, buf, count, datatype, request); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -111,24 +104,17 @@ int MPI_File_iread_at_all_c(MPI_File fh, MPI_Offset offset, void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Request * request) { int error_code; - static char myname[] = "MPI_FILE_IREAD_AT_ALL"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEIREADATALL, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - error_code = MPIOI_File_iread_all(fh, offset, ADIO_EXPLICIT_OFFSET, buf, - count, datatype, myname, request); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(fh, error_code); - /* --END ERROR HANDLING-- */ + ROMIO_THREAD_CS_ENTER(); -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_iread_at_all_impl(fh, offset, buf, count, datatype, request); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/iread_sh.c b/src/mpi/romio/mpi-io/iread_sh.c index ab4733deebc..66688d723b0 100644 --- a/src/mpi/romio/mpi-io/iread_sh.c +++ b/src/mpi/romio/mpi-io/iread_sh.c @@ -61,7 +61,20 @@ Output Parameters: int MPI_File_iread_shared(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Request * request) { - return MPIOI_File_iread_shared(fh, buf, count, datatype, request); + int error_code; + ROMIO_THREAD_CS_ENTER(); + + error_code = MPIR_File_iread_shared_impl(fh, buf, count, datatype, request); + if (error_code) { + goto fn_fail; + } + + fn_exit: + ROMIO_THREAD_CS_EXIT(); + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -84,117 +97,18 @@ Output Parameters: int MPI_File_iread_shared_c(MPI_File fh, void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Request * request) { - return MPIOI_File_iread_shared(fh, buf, count, datatype, request); -} - -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_iread_shared(MPI_File fh, void *buf, MPI_Aint count, - MPI_Datatype datatype, MPI_Request * request) -{ - int error_code, buftype_is_contig, filetype_is_contig; - ADIO_Offset bufsize; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_IREAD_SHARED"; - MPI_Count datatype_size, incr; - MPI_Status status; - ADIO_Offset off, shared_fp; - MPI_Offset nbytes = 0; - void *xbuf = NULL, *e32_buf = NULL, *host_buf = NULL; - + int error_code; ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - /* --END ERROR HANDLING-- */ - - MPI_Type_size_x(datatype, &datatype_size); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, myname, error_code); - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); - ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig); - - ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code); - - incr = (count * datatype_size) / adio_fh->etype_size; - ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) { - /* note: ADIO_Get_shared_fp should have set up error code already? */ - MPIO_Err_return_file(adio_fh, error_code); - } - /* --END ERROR HANDLING-- */ - - xbuf = buf; - if (adio_fh->is_external32) { - MPI_Aint e32_size = 0; - error_code = MPIU_datatype_full_size(datatype, &e32_size); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - e32_buf = ADIOI_Malloc(e32_size * count); - xbuf = e32_buf; - } else { - MPIO_GPU_HOST_ALLOC(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } + error_code = MPIR_File_iread_shared_impl(fh, buf, count, datatype, request); + if (error_code) { + goto fn_fail; } - if (buftype_is_contig && filetype_is_contig) { - /* convert count and shared_fp to bytes */ - bufsize = datatype_size * count; - off = adio_fh->disp + adio_fh->etype_size * shared_fp; - if (!(adio_fh->atomicity)) { - ADIO_IreadContig(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, - off, request, &error_code); - } else { - /* to maintain strict atomicity semantics with other concurrent - * operations, lock (exclusive) and call blocking routine */ - - if (adio_fh->file_system != ADIO_NFS) { - ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize); - } - - ADIO_ReadContig(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, - off, &status, &error_code); - - if (adio_fh->file_system != ADIO_NFS) { - ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize); - } - if (error_code == MPI_SUCCESS) { - nbytes = count * datatype_size; - } - MPIO_Completed_request_create(&adio_fh, nbytes, &error_code, request); - } - } else { - ADIO_IreadStrided(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, - shared_fp, request, &error_code); - } - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - - if (e32_buf != NULL) { - error_code = MPIU_read_external32_conversion_fn(buf, datatype, count, e32_buf); - ADIOI_Free(e32_buf); - } - - MPIO_GPU_SWAP_BACK(host_buf, buf, count, datatype); - fn_exit: ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/iwrite.c b/src/mpi/romio/mpi-io/iwrite.c index 4ad48e579b2..2a7c00818ac 100644 --- a/src/mpi/romio/mpi-io/iwrite.c +++ b/src/mpi/romio/mpi-io/iwrite.c @@ -59,28 +59,20 @@ Output Parameters: int MPI_File_iwrite(MPI_File fh, ROMIO_CONST void *buf, int count, MPI_Datatype datatype, MPI_Request * request) { - int error_code = MPI_SUCCESS; - static char myname[] = "MPI_FILE_IWRITE"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEIWRITE, TRDTSYSTEM, fh, datatype, count); -#endif /* MPI_hpux */ - - - error_code = MPIOI_File_iwrite(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, - buf, count, datatype, myname, request); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(fh, error_code); - /* --END ERROR HANDLING-- */ + int error_code; + ROMIO_THREAD_CS_ENTER(); -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_iwrite_impl(fh, buf, count, datatype, request); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -107,134 +99,18 @@ Output Parameters: int MPI_File_iwrite_c(MPI_File fh, ROMIO_CONST void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Request * request) { - int error_code = MPI_SUCCESS; - static char myname[] = "MPI_FILE_IWRITE"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEIWRITE, TRDTSYSTEM, fh, datatype, count); -#endif /* MPI_hpux */ - - - error_code = MPIOI_File_iwrite(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, - buf, count, datatype, myname, request); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(fh, error_code); - /* --END ERROR HANDLING-- */ - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ - - return error_code; -} - -/* prevent multiple definitions of this routine */ -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_iwrite(MPI_File fh, - MPI_Offset offset, - int file_ptr_type, - const void *buf, - MPI_Aint count, MPI_Datatype datatype, char *myname, MPI_Request * request) -{ - int error_code, buftype_is_contig, filetype_is_contig; - MPI_Count datatype_size; - ADIO_Status status; - ADIO_Offset off, bufsize; - ADIO_File adio_fh; - MPI_Offset nbytes = 0; - void *e32buf = NULL; - const void *xbuf = NULL; - void *host_buf = NULL; - + int error_code; ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - - if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - MPI_Type_size_x(datatype, &datatype_size); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_WRITABLE(adio_fh, myname, error_code); - MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); - ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig); - - ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code); - - xbuf = buf; - if (adio_fh->is_external32) { - error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - xbuf = e32buf; - } else { - MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } - } - if (buftype_is_contig && filetype_is_contig) { - /* convert sizes to bytes */ - bufsize = datatype_size * count; - if (file_ptr_type == ADIO_EXPLICIT_OFFSET) { - off = adio_fh->disp + adio_fh->etype_size * offset; - } else { - off = adio_fh->fp_ind; - } - - if (!(adio_fh->atomicity)) { - ADIO_IwriteContig(adio_fh, xbuf, count, datatype, file_ptr_type, - off, request, &error_code); - } else { - /* to maintain strict atomicity semantics with other concurrent - * operations, lock (exclusive) and call blocking routine */ - if (ADIO_Feature(adio_fh, ADIO_LOCKS)) { - ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize); - } - - ADIO_WriteContig(adio_fh, xbuf, count, datatype, file_ptr_type, off, - &status, &error_code); - - if (ADIO_Feature(adio_fh, ADIO_LOCKS)) { - ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize); - } - if (error_code == MPI_SUCCESS) { - nbytes = count * datatype_size; - } - - MPIO_Completed_request_create(&adio_fh, nbytes, &error_code, request); - } - } else { - ADIO_IwriteStrided(adio_fh, xbuf, count, datatype, file_ptr_type, - offset, request, &error_code); + error_code = MPIR_File_iwrite_impl(fh, buf, count, datatype, request); + if (error_code) { + goto fn_fail; } - MPIO_GPU_HOST_FREE(host_buf, count, datatype); - fn_exit: - if (e32buf != NULL) - ADIOI_Free(e32buf); ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/iwrite_all.c b/src/mpi/romio/mpi-io/iwrite_all.c index 8cf23cda761..a7ef2100faf 100644 --- a/src/mpi/romio/mpi-io/iwrite_all.c +++ b/src/mpi/romio/mpi-io/iwrite_all.c @@ -62,21 +62,19 @@ int MPI_File_iwrite_all(MPI_File fh, ROMIO_CONST void *buf, int count, MPI_Datatype datatype, MPI_Request * request) { int error_code; - static char myname[] = "MPI_FILE_IWRITE_ALL"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEIWRITEALL, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - error_code = MPIOI_File_iwrite_all(fh, (MPI_Offset) 0, - ADIO_INDIVIDUAL, buf, count, datatype, myname, request); + ROMIO_THREAD_CS_ENTER(); -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_iwrite_all_impl(fh, buf, count, datatype, request); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -104,95 +102,17 @@ int MPI_File_iwrite_all_c(MPI_File fh, ROMIO_CONST void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Request * request) { int error_code; - static char myname[] = "MPI_FILE_IWRITE_ALL"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEIWRITEALL, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - error_code = MPIOI_File_iwrite_all(fh, (MPI_Offset) 0, - ADIO_INDIVIDUAL, buf, count, datatype, myname, request); - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ - - return error_code; -} - -/* Note: MPIOI_File_iwrite_all also used by MPI_File_iwrite_at_all */ -/* prevent multiple definitions of this routine */ -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_iwrite_all(MPI_File fh, - MPI_Offset offset, - int file_ptr_type, - const void *buf, - MPI_Aint count, MPI_Datatype datatype, char *myname, - MPI_Request * request) -{ - int error_code; - MPI_Count datatype_size; - ADIO_File adio_fh; - void *e32buf = NULL; - const void *xbuf = NULL; - void *host_buf = NULL; - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - - if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; + error_code = MPIR_File_iwrite_all_impl(fh, buf, count, datatype, request); + if (error_code) { + goto fn_fail; } - /* --END ERROR HANDLING-- */ - - MPI_Type_size_x(datatype, &datatype_size); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_WRITABLE(adio_fh, myname, error_code); - MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - xbuf = buf; - if (adio_fh->is_external32) { - error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - xbuf = e32buf; - } else { - MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } - } - - ADIO_IwriteStridedColl(adio_fh, xbuf, count, datatype, file_ptr_type, - offset, request, &error_code); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - - MPIO_GPU_HOST_FREE(host_buf, count, datatype); fn_exit: - if (e32buf != NULL) - ADIOI_Free(e32buf); ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/iwrite_at.c b/src/mpi/romio/mpi-io/iwrite_at.c index 0549d3d96fe..49bcc55c107 100644 --- a/src/mpi/romio/mpi-io/iwrite_at.c +++ b/src/mpi/romio/mpi-io/iwrite_at.c @@ -63,30 +63,19 @@ int MPI_File_iwrite_at(MPI_File fh, MPI_Offset offset, ROMIO_CONST void *buf, int count, MPI_Datatype datatype, MPIO_Request * request) { int error_code; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_IWRITE_AT"; - -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEIWRITEAT, TRDTSYSTEM, fh, datatype, count); -#endif /* MPI_hpux */ - - - adio_fh = MPIO_File_resolve(fh); - - error_code = MPIOI_File_iwrite(adio_fh, offset, ADIO_EXPLICIT_OFFSET, buf, - count, datatype, myname, request); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count) -#endif /* MPI_hpux */ - return error_code; + ROMIO_THREAD_CS_ENTER(); + + error_code = MPIR_File_iwrite_at_impl(fh, offset, buf, count, datatype, request); + if (error_code) { + goto fn_fail; + } + + fn_exit: + ROMIO_THREAD_CS_EXIT(); + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -115,28 +104,17 @@ int MPI_File_iwrite_at_c(MPI_File fh, MPI_Offset offset, ROMIO_CONST void *buf, MPI_Count count, MPI_Datatype datatype, MPIO_Request * request) { int error_code; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_IWRITE_AT"; - -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEIWRITEAT, TRDTSYSTEM, fh, datatype, count); -#endif /* MPI_hpux */ - - - adio_fh = MPIO_File_resolve(fh); - - error_code = MPIOI_File_iwrite(adio_fh, offset, ADIO_EXPLICIT_OFFSET, buf, - count, datatype, myname, request); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count) -#endif /* MPI_hpux */ - return error_code; + ROMIO_THREAD_CS_ENTER(); + + error_code = MPIR_File_iwrite_at_impl(fh, offset, buf, count, datatype, request); + if (error_code) { + goto fn_fail; + } + + fn_exit: + ROMIO_THREAD_CS_EXIT(); + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/iwrite_atall.c b/src/mpi/romio/mpi-io/iwrite_atall.c index 73c88a7020a..73743e4fd0b 100644 --- a/src/mpi/romio/mpi-io/iwrite_atall.c +++ b/src/mpi/romio/mpi-io/iwrite_atall.c @@ -63,20 +63,19 @@ int MPI_File_iwrite_at_all(MPI_File fh, MPI_Offset offset, ROMIO_CONST void *buf int count, MPI_Datatype datatype, MPI_Request * request) { int error_code; - static char myname[] = "MPI_FILE_IWRITE_AT_ALL"; -#ifdef MPI_hpux - int fl_xmpi; + ROMIO_THREAD_CS_ENTER(); - HPMP_IO_START(fl_xmpi, BLKMPIFILEIWRITEATALL, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_iwrite_at_all_impl(fh, offset, buf, count, datatype, request); + if (error_code) { + goto fn_fail; + } - error_code = MPIOI_File_iwrite_all(fh, offset, ADIO_EXPLICIT_OFFSET, - buf, count, datatype, myname, request); - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -105,18 +104,17 @@ int MPI_File_iwrite_at_all_c(MPI_File fh, MPI_Offset offset, ROMIO_CONST void *b MPI_Count count, MPI_Datatype datatype, MPI_Request * request) { int error_code; - static char myname[] = "MPI_FILE_IWRITE_AT_ALL"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEIWRITEATALL, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ + ROMIO_THREAD_CS_ENTER(); - error_code = MPIOI_File_iwrite_all(fh, offset, ADIO_EXPLICIT_OFFSET, - buf, count, datatype, myname, request); + error_code = MPIR_File_iwrite_at_all_impl(fh, offset, buf, count, datatype, request); + if (error_code) { + goto fn_fail; + } -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/iwrite_sh.c b/src/mpi/romio/mpi-io/iwrite_sh.c index 122b6dbdeec..69eff1c4ac1 100644 --- a/src/mpi/romio/mpi-io/iwrite_sh.c +++ b/src/mpi/romio/mpi-io/iwrite_sh.c @@ -61,7 +61,20 @@ Output Parameters: int MPI_File_iwrite_shared(MPI_File fh, ROMIO_CONST void *buf, int count, MPI_Datatype datatype, MPIO_Request * request) { - return MPIOI_File_iwrite_shared(fh, buf, count, datatype, request); + int error_code; + ROMIO_THREAD_CS_ENTER(); + + error_code = MPIR_File_iwrite_shared_impl(fh, buf, count, datatype, request); + if (error_code) { + goto fn_fail; + } + + fn_exit: + ROMIO_THREAD_CS_EXIT(); + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -88,102 +101,18 @@ Output Parameters: int MPI_File_iwrite_shared_c(MPI_File fh, ROMIO_CONST void *buf, MPI_Count count, MPI_Datatype datatype, MPIO_Request * request) { - return MPIOI_File_iwrite_shared(fh, buf, count, datatype, request); -} - -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_iwrite_shared(MPI_File fh, const void *buf, MPI_Aint count, - MPI_Datatype datatype, MPIO_Request * request) -{ - int error_code, buftype_is_contig, filetype_is_contig; - ADIO_File adio_fh; - ADIO_Offset incr, bufsize; - MPI_Count datatype_size; - ADIO_Status status; - ADIO_Offset off, shared_fp; - static char myname[] = "MPI_FILE_IWRITE_SHARED"; - void *e32buf = NULL; - const void *xbuf = NULL; - void *host_buf = NULL; - + int error_code; ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - /* --END ERROR HANDLING-- */ - - MPI_Type_size_x(datatype, &datatype_size); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, myname, error_code); - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); - ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig); - - ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code); - - incr = (count * datatype_size) / adio_fh->etype_size; - ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code); - if (error_code != MPI_SUCCESS) { - /* note: ADIO_Get_shared_fp should have set up error code already? */ - MPIO_Err_return_file(adio_fh, error_code); + error_code = MPIR_File_iwrite_shared_impl(fh, buf, count, datatype, request); + if (error_code) { + goto fn_fail; } - xbuf = buf; - if (adio_fh->is_external32) { - error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - xbuf = e32buf; - } else { - MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } - } - - /* contiguous or strided? */ - if (buftype_is_contig && filetype_is_contig) { - /* convert sizes to bytes */ - bufsize = datatype_size * count; - off = adio_fh->disp + adio_fh->etype_size * shared_fp; - if (!(adio_fh->atomicity)) - ADIO_IwriteContig(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, - off, request, &error_code); - else { - /* to maintain strict atomicity semantics with other concurrent - * operations, lock (exclusive) and call blocking routine */ - - if (adio_fh->file_system != ADIO_NFS) - ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize); - - ADIO_WriteContig(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, - off, &status, &error_code); - - if (adio_fh->file_system != ADIO_NFS) - ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize); - - MPIO_Completed_request_create(&adio_fh, bufsize, &error_code, request); - } - } else - ADIO_IwriteStrided(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, - shared_fp, request, &error_code); - - MPIO_GPU_HOST_FREE(host_buf, count, datatype); - fn_exit: - if (e32buf != NULL) - ADIOI_Free(e32buf); ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/mpioimpl.h b/src/mpi/romio/mpi-io/mpioimpl.h index c1956e99d96..403a43efe40 100644 --- a/src/mpi/romio/mpi-io/mpioimpl.h +++ b/src/mpi/romio/mpi-io/mpioimpl.h @@ -88,8 +88,102 @@ void MPIR_MPIOInit(int *error_code); #include "mpioprof.h" #endif /* MPIO_BUILD_PROFILING */ -#ifdef MPI_hpux -#include "mpioinst.h" -#endif /* MPI_hpux */ +int MPIR_File_close_impl(MPI_File * fh); +int MPIR_File_delete_impl(const char *filename, MPI_Info info); +int MPIR_File_get_amode_impl(MPI_File fh, int *amode); +int MPIR_File_get_atomicity_impl(MPI_File fh, int *flag); +int MPIR_File_get_byte_offset_impl(MPI_File fh, MPI_Offset offset, MPI_Offset * disp); +int MPIR_File_get_group_impl(MPI_File fh, MPI_Group * group); +int MPIR_File_get_info_impl(MPI_File fh, MPI_Info * info_used); +int MPIR_File_get_position_impl(MPI_File fh, MPI_Offset * offset); +int MPIR_File_get_position_shared_impl(MPI_File fh, MPI_Offset * offset); +int MPIR_File_get_size_impl(MPI_File fh, MPI_Offset * size); +int MPIR_File_get_type_extent_impl(MPI_File fh, MPI_Datatype datatype, MPI_Aint * extent); +int MPIR_File_get_view_impl(MPI_File fh, MPI_Offset * disp, MPI_Datatype * etype, + MPI_Datatype * filetype, char *datarep); +int MPIR_File_iread_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request); +int MPIR_File_iread_all_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request); +int MPIR_File_iread_at_impl(MPI_File fh, MPI_Offset offset, void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Request * request); +int MPIR_File_iread_at_all_impl(MPI_File fh, MPI_Offset offset, void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Request * request); +int MPIR_File_iread_shared_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request); +int MPIR_File_iwrite_impl(MPI_File fh, const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request); +int MPIR_File_iwrite_all_impl(MPI_File fh, const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Request * request); +int MPIR_File_iwrite_at_impl(MPI_File fh, MPI_Offset offset, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Request * request); +int MPIR_File_iwrite_at_all_impl(MPI_File fh, MPI_Offset offset, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Request * request); +int MPIR_File_iwrite_shared_impl(MPI_File fh, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Request * request); +int MPIR_File_open_impl(MPI_Comm comm, const char *filename, int amode, MPI_Info info, + MPI_File * fh); +int MPIR_File_preallocate_impl(MPI_File fh, MPI_Offset size); +int MPIR_File_read_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status); +int MPIR_File_read_all_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status); +int MPIR_File_read_all_begin_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype); +int MPIR_File_read_all_end_impl(MPI_File fh, void *buf, MPI_Status * status); +int MPIR_File_read_at_impl(MPI_File fh, MPI_Offset offset, void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Status * status); +int MPIR_File_read_at_all_impl(MPI_File fh, MPI_Offset offset, void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Status * status); +int MPIR_File_read_at_all_begin_impl(MPI_File fh, MPI_Offset offset, void *buf, MPI_Aint count, + MPI_Datatype datatype); +int MPIR_File_read_at_all_end_impl(MPI_File fh, void *buf, MPI_Status * status); +int MPIR_File_read_ordered_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status); +int MPIR_File_read_ordered_begin_impl(MPI_File fh, void *buf, MPI_Aint count, + MPI_Datatype datatype); +int MPIR_File_read_ordered_end_impl(MPI_File fh, void *buf, MPI_Status * status); +int MPIR_File_read_shared_impl(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status); +int MPIR_File_seek_impl(MPI_File fh, MPI_Offset offset, int whence); +int MPIR_File_seek_shared_impl(MPI_File fh, MPI_Offset offset, int whence); +int MPIR_File_set_atomicity_impl(MPI_File fh, int flag); +int MPIR_File_set_info_impl(MPI_File fh, MPI_Info info); +int MPIR_File_set_size_impl(MPI_File fh, MPI_Offset size); +int MPIR_File_set_view_impl(MPI_File fh, MPI_Offset disp, MPI_Datatype etype, MPI_Datatype filetype, + const char *datarep, MPI_Info info); +int MPIR_File_sync_impl(MPI_File fh); +int MPIR_File_write_impl(MPI_File fh, const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status); +int MPIR_File_write_all_impl(MPI_File fh, const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status); +int MPIR_File_write_all_begin_impl(MPI_File fh, const void *buf, MPI_Aint count, + MPI_Datatype datatype); +int MPIR_File_write_all_end_impl(MPI_File fh, const void *buf, MPI_Status * status); +int MPIR_File_write_at_impl(MPI_File fh, MPI_Offset offset, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Status * status); +int MPIR_File_write_at_all_impl(MPI_File fh, MPI_Offset offset, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Status * status); +int MPIR_File_write_at_all_begin_impl(MPI_File fh, MPI_Offset offset, const void *buf, + MPI_Aint count, MPI_Datatype datatype); +int MPIR_File_write_at_all_end_impl(MPI_File fh, const void *buf, MPI_Status * status); +int MPIR_File_write_ordered_impl(MPI_File fh, const void *buf, MPI_Aint count, + MPI_Datatype datatype, MPI_Status * status); +int MPIR_File_write_ordered_begin_impl(MPI_File fh, const void *buf, MPI_Aint count, + MPI_Datatype datatype); +int MPIR_File_write_ordered_end_impl(MPI_File fh, const void *buf, MPI_Status * status); +int MPIR_File_write_shared_impl(MPI_File fh, const void *buf, MPI_Aint count, MPI_Datatype datatype, + MPI_Status * status); +int MPIR_Register_datarep_impl(const char *datarep, + MPI_Datarep_conversion_function * read_conversion_fn, + MPI_Datarep_conversion_function * write_conversion_fn, + MPI_Datarep_extent_function * dtype_file_extent_fn, + void *extra_state); +int MPIR_Register_datarep_large_impl(const char *datarep, + MPI_Datarep_conversion_function_c * read_conversion_fn, + MPI_Datarep_conversion_function_c * write_conversion_fn, + MPI_Datarep_extent_function * dtype_file_extent_fn, + void *extra_state); +MPI_Fint MPIR_File_c2f_impl(MPI_File fh); +MPI_File MPIR_File_f2c_impl(MPI_Fint fh); #endif /* MPIOIMPL_H_INCLUDED */ diff --git a/src/mpi/romio/mpi-io/open.c b/src/mpi/romio/mpi-io/open.c index 251acbadaac..990ab739d74 100644 --- a/src/mpi/romio/mpi-io/open.c +++ b/src/mpi/romio/mpi-io/open.c @@ -24,9 +24,6 @@ int MPI_File_open(MPI_Comm comm, const char *filename, int amode, MPI_Info info, #include "mpioprof.h" #endif -/* for user-definde reduce operator */ -#include "adio_extern.h" - /* */ #if !defined(HAVE_WEAK_SYMBOLS) && !defined(MPIO_BUILD_PROFILING) void *dummy_refs_MPI_File_open[] = { @@ -35,8 +32,6 @@ void *dummy_refs_MPI_File_open[] = { }; #endif -extern int ADIO_Init_keyval; - /*@ MPI_File_open - Opens a file @@ -54,150 +49,20 @@ Output Parameters: int MPI_File_open(MPI_Comm comm, ROMIO_CONST char *filename, int amode, MPI_Info info, MPI_File * fh) { - int error_code = MPI_SUCCESS, file_system, flag, tmp_amode = 0, rank; - int known_fstype; - char *tmp; - MPI_Comm dupcomm = MPI_COMM_NULL; - ADIOI_Fns *fsops; - static char myname[] = "MPI_FILE_OPEN"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_OPEN_START(fl_xmpi, comm); -#endif /* MPI_hpux */ + int error_code = MPI_SUCCESS; ROMIO_THREAD_CS_ENTER(); - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_COMM(comm, myname, error_code); - MPIO_CHECK_INFO_ALL(info, error_code, comm); - /* --END ERROR HANDLING-- */ - - error_code = MPI_Comm_test_inter(comm, &flag); - /* --BEGIN ERROR HANDLING-- */ - if (error_code || flag) { - error_code = MPIO_Err_create_code(error_code, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_COMM, "**commnotintra", 0); - goto fn_fail; - } - - if (((amode & MPI_MODE_RDONLY) ? 1 : 0) + ((amode & MPI_MODE_RDWR) ? 1 : 0) + - ((amode & MPI_MODE_WRONLY) ? 1 : 0) != 1) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_AMODE, "**fileamodeone", 0); - goto fn_fail; - } - - if ((amode & MPI_MODE_RDONLY) && ((amode & MPI_MODE_CREATE) || (amode & MPI_MODE_EXCL))) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_AMODE, "**fileamoderead", 0); - goto fn_fail; - } - - if ((amode & MPI_MODE_RDWR) && (amode & MPI_MODE_SEQUENTIAL)) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_AMODE, "**fileamodeseq", 0); - goto fn_fail; - } - - MPI_Comm_dup(comm, &dupcomm); - -/* check if ADIO has been initialized. If not, initialize it */ - MPIR_MPIOInit(&error_code); + error_code = MPIR_File_open_impl(comm, filename, amode, info, fh); if (error_code != MPI_SUCCESS) goto fn_fail; -/* check if amode is the same on all processes: at first glance, one might try - * to use a built-in operator like MPI_BAND, but we need every mpi process to - * agree the amode was not the same. Consider process A with - * MPI_MODE_CREATE|MPI_MODE_RDWR, and B with MPI_MODE_RDWR: MPI_BAND yields - * MPI_MODE_RDWR. A determines amodes are different, but B proceeds having not - * detected an error */ - MPI_Allreduce(&amode, &tmp_amode, 1, MPI_INT, ADIO_same_amode, dupcomm); - - if (tmp_amode == ADIO_AMODE_NOMATCH) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_NOT_SAME, "**fileamodediff", 0); - goto fn_fail; - } - /* --END ERROR HANDLING-- */ - - file_system = -1; - - /* resolve file system type from file name; this is a collective call */ - known_fstype = ADIO_ResolveFileType(dupcomm, filename, &file_system, &fsops, &error_code); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) { - /* ADIO_ResolveFileType() will print as informative a message as it - * possibly can or call MPIO_Err_setmsg. We just need to propagate - * the error up. - */ - goto fn_fail; - } - /* --END ERROR HANDLING-- */ - - if (known_fstype) { - /* filename contains a known file system type prefix, such as "ufs:". - * strip off prefix if there is one, but only skip prefixes - * if they are greater than length one to allow for windows - * drive specifications (e.g. c:\...) - */ - tmp = strchr(filename, ':'); - if (tmp > filename + 1) { - filename = tmp + 1; - } - } -/* use default values for disp, etype, filetype */ - - *fh = ADIO_Open(comm, dupcomm, filename, file_system, fsops, amode, 0, - MPI_BYTE, MPI_BYTE, info, ADIO_PERM_NULL, &error_code); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) { - goto fn_fail; - } - /* --END ERROR HANDLING-- */ - - /* if MPI_MODE_SEQUENTIAL requested, file systems cannot do explicit offset - * or independent file pointer accesses, leaving not much else aside from - * shared file pointer accesses. */ - if (!ADIO_Feature((*fh), ADIO_SHARED_FP) && (amode & MPI_MODE_SEQUENTIAL)) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, - MPI_ERR_UNSUPPORTED_OPERATION, "**iosequnsupported", 0); - ADIO_Close(*fh, &error_code); - goto fn_fail; - } - - /* determine name of file that will hold the shared file pointer */ - /* can't support shared file pointers on a file system that doesn't - * support file locking. */ - if ((error_code == MPI_SUCCESS) && ADIO_Feature((*fh), ADIO_SHARED_FP)) { - MPI_Comm_rank(dupcomm, &rank); - ADIOI_Shfp_fname(*fh, rank, &error_code); - if (error_code != MPI_SUCCESS) - goto fn_fail; - - /* if MPI_MODE_APPEND, set the shared file pointer to end of file. - * indiv. file pointer already set to end of file in ADIO_Open. - * Here file view is just bytes. */ - if ((*fh)->access_mode & MPI_MODE_APPEND) { - if (rank == (*fh)->hints->ranklist[0]) /* only one person need set the sharedfp */ - ADIO_Set_shared_fp(*fh, (*fh)->fp_ind, &error_code); - MPI_Barrier(dupcomm); - } - } -#ifdef MPI_hpux - HPMP_IO_OPEN_END(fl_xmpi, *fh, comm); -#endif /* MPI_hpux */ fn_exit: ROMIO_THREAD_CS_EXIT(); return error_code; fn_fail: /* --BEGIN ERROR HANDLING-- */ - if (dupcomm != MPI_COMM_NULL) - MPI_Comm_free(&dupcomm); error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code); goto fn_exit; /* --END ERROR HANDLING-- */ diff --git a/src/mpi/romio/mpi-io/prealloc.c b/src/mpi/romio/mpi-io/prealloc.c index d2d479e587f..cd44af4cea6 100644 --- a/src/mpi/romio/mpi-io/prealloc.c +++ b/src/mpi/romio/mpi-io/prealloc.c @@ -35,72 +35,18 @@ Input Parameters: @*/ int MPI_File_preallocate(MPI_File fh, MPI_Offset size) { - ADIO_Fcntl_t *fcntl_struct; - int error_code = 0, mynod = 0; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_PREALLOCATE"; - MPI_Offset tmp_sz, max_sz, min_sz; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEPREALLOCATE, TRDTBLOCK, adio_fh, MPI_DATATYPE_NULL, -1); -#endif /* MPI_hpux */ - + int error_code; ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - - if (size < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobadsize", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - - tmp_sz = size; - MPI_Allreduce(&tmp_sz, &max_sz, 1, ADIO_OFFSET, MPI_MAX, adio_fh->comm); - MPI_Allreduce(&tmp_sz, &min_sz, 1, ADIO_OFFSET, MPI_MIN, adio_fh->comm); - - if (max_sz != min_sz) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**notsame", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; + error_code = MPIR_File_preallocate_impl(fh, size); + if (error_code) { + goto fn_fail; } - /* --END ERROR HANDLING-- */ - - if (size == 0) - goto fn_exit; - - ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code); - - MPI_Comm_rank(adio_fh->comm, &mynod); - if (!mynod) { - fcntl_struct = (ADIO_Fcntl_t *) ADIOI_Malloc(sizeof(ADIO_Fcntl_t)); - fcntl_struct->diskspace = size; - ADIO_Fcntl(adio_fh, ADIO_FCNTL_SET_DISKSPACE, fcntl_struct, &error_code); - ADIOI_Free(fcntl_struct); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - } - MPI_Barrier(adio_fh->comm); - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, adio_fh, MPI_DATATYPE_NULL, -1); -#endif /* MPI_hpux */ - fn_exit: ROMIO_THREAD_CS_EXIT(); - - /* TODO: bcast result? */ - if (!mynod) - return error_code; - else - return MPI_SUCCESS; + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/rd_atallb.c b/src/mpi/romio/mpi-io/rd_atallb.c index 0d6ed95fcf1..e2722010702 100644 --- a/src/mpi/romio/mpi-io/rd_atallb.c +++ b/src/mpi/romio/mpi-io/rd_atallb.c @@ -58,12 +58,19 @@ int MPI_File_read_at_all_begin(MPI_File fh, MPI_Offset offset, void *buf, int count, MPI_Datatype datatype) { int error_code; - static char myname[] = "MPI_FILE_READ_AT_ALL_BEGIN"; + ROMIO_THREAD_CS_ENTER(); - error_code = MPIOI_File_read_all_begin(fh, offset, - ADIO_EXPLICIT_OFFSET, buf, count, datatype, myname); + error_code = MPIR_File_read_at_all_begin_impl(fh, offset, buf, count, datatype); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -87,10 +94,17 @@ int MPI_File_read_at_all_begin_c(MPI_File fh, MPI_Offset offset, void *buf, MPI_Count count, MPI_Datatype datatype) { int error_code; - static char myname[] = "MPI_FILE_READ_AT_ALL_BEGIN"; + ROMIO_THREAD_CS_ENTER(); - error_code = MPIOI_File_read_all_begin(fh, offset, - ADIO_EXPLICIT_OFFSET, buf, count, datatype, myname); + error_code = MPIR_File_read_at_all_begin_impl(fh, offset, buf, count, datatype); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/rd_atalle.c b/src/mpi/romio/mpi-io/rd_atalle.c index d24825faa8c..d129a85d62b 100644 --- a/src/mpi/romio/mpi-io/rd_atalle.c +++ b/src/mpi/romio/mpi-io/rd_atalle.c @@ -40,10 +40,17 @@ Output Parameters: int MPI_File_read_at_all_end(MPI_File fh, void *buf, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_READ_AT_ALL_END"; + ROMIO_THREAD_CS_ENTER(); + error_code = MPIR_File_read_at_all_end_impl(fh, buf, status); + if (error_code) { + goto fn_fail; + } - error_code = MPIOI_File_read_all_end(fh, buf, myname, status); - + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/read.c b/src/mpi/romio/mpi-io/read.c index b6d25a92325..b7c3a40fed0 100644 --- a/src/mpi/romio/mpi-io/read.c +++ b/src/mpi/romio/mpi-io/read.c @@ -58,21 +58,19 @@ Output Parameters: int MPI_File_read(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_READ"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEREAD, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - error_code = MPIOI_File_read(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, buf, - count, datatype, myname, status); + ROMIO_THREAD_CS_ENTER(); -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_read_impl(fh, buf, count, datatype, status); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -98,138 +96,17 @@ int MPI_File_read_c(MPI_File fh, void *buf, MPI_Count count, MPI_Datatype dataty MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_READ"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEREAD, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - error_code = MPIOI_File_read(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, buf, - count, datatype, myname, status); - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ - - return error_code; -} - -/* prevent multiple definitions of this routine */ -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_read(MPI_File fh, - MPI_Offset offset, - int file_ptr_type, - void *buf, MPI_Aint count, MPI_Datatype datatype, char *myname, - MPI_Status * status) -{ - int error_code, buftype_is_contig, filetype_is_contig; - MPI_Count datatype_size; - ADIO_File adio_fh; - ADIO_Offset off, bufsize; - void *xbuf = NULL, *e32_buf = NULL, *host_buf = NULL; - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - - if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - MPI_Type_size_x(datatype, &datatype_size); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - if (count * datatype_size == 0) { -#ifdef HAVE_STATUS_SET_BYTES - MPIR_Status_set_bytes(status, datatype, 0); -#endif - error_code = MPI_SUCCESS; - goto fn_exit; - } - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_READABLE(adio_fh, myname, error_code); - MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); - ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig); - - ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code); - - xbuf = buf; - if (adio_fh->is_external32) { - MPI_Aint e32_size = 0; - error_code = MPIU_datatype_full_size(datatype, &e32_size); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - e32_buf = ADIOI_Malloc(e32_size * count); - xbuf = e32_buf; - } else { - MPIO_GPU_HOST_ALLOC(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } + error_code = MPIR_File_read_impl(fh, buf, count, datatype, status); + if (error_code) { + goto fn_fail; } - if (buftype_is_contig && filetype_is_contig) { - /* convert count and offset to bytes */ - bufsize = datatype_size * count; - if (file_ptr_type == ADIO_EXPLICIT_OFFSET) { - off = adio_fh->disp + adio_fh->etype_size * offset; - } else { /* ADIO_INDIVIDUAL */ - - off = adio_fh->fp_ind; - } - - /* if atomic mode requested, lock (exclusive) the region, because - * there could be a concurrent noncontiguous request. - */ - if ((adio_fh->atomicity) && ADIO_Feature(adio_fh, ADIO_LOCKS)) { - ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize); - } - - ADIO_ReadContig(adio_fh, xbuf, count, datatype, file_ptr_type, off, status, &error_code); - - if ((adio_fh->atomicity) && ADIO_Feature(adio_fh, ADIO_LOCKS)) { - ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize); - } - } else { - ADIO_ReadStrided(adio_fh, xbuf, count, datatype, file_ptr_type, - offset, status, &error_code); - /* For strided and atomic mode, locking is done in ADIO_ReadStrided */ - } - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - - if (e32_buf != NULL) { - error_code = MPIU_read_external32_conversion_fn(buf, datatype, count, e32_buf); - ADIOI_Free(e32_buf); - } - - MPIO_GPU_SWAP_BACK(host_buf, buf, count, datatype); - fn_exit: ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/read_all.c b/src/mpi/romio/mpi-io/read_all.c index 32b3ae306b7..9e4c5f115fe 100644 --- a/src/mpi/romio/mpi-io/read_all.c +++ b/src/mpi/romio/mpi-io/read_all.c @@ -58,21 +58,19 @@ Output Parameters: int MPI_File_read_all(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_READ_ALL"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEREADALL, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - error_code = MPIOI_File_read_all(fh, (MPI_Offset) 0, - ADIO_INDIVIDUAL, buf, count, datatype, myname, status); + ROMIO_THREAD_CS_ENTER(); -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_read_all_impl(fh, buf, count, datatype, status); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -98,97 +96,17 @@ int MPI_File_read_all_c(MPI_File fh, void *buf, MPI_Count count, MPI_Datatype da MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_READ_ALL"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEREADALL, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - error_code = MPIOI_File_read_all(fh, (MPI_Offset) 0, - ADIO_INDIVIDUAL, buf, count, datatype, myname, status); - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ - - return error_code; -} - -/* Note: MPIOI_File_read_all also used by MPI_File_read_at_all */ -/* prevent multiple definitions of this routine */ -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_read_all(MPI_File fh, - MPI_Offset offset, - int file_ptr_type, - void *buf, - MPI_Aint count, MPI_Datatype datatype, char *myname, MPI_Status * status) -{ - int error_code; - MPI_Count datatype_size; - ADIO_File adio_fh; - void *xbuf = NULL, *e32_buf = NULL, *host_buf = NULL; - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - - if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - MPI_Type_size_x(datatype, &datatype_size); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_READABLE(adio_fh, myname, error_code); - MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - xbuf = buf; - if (adio_fh->is_external32) { - MPI_Aint e32_size = 0; - error_code = MPIU_datatype_full_size(datatype, &e32_size); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - e32_buf = ADIOI_Malloc(e32_size * count); - xbuf = e32_buf; - } else { - MPIO_GPU_HOST_ALLOC(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } + error_code = MPIR_File_read_all_impl(fh, buf, count, datatype, status); + if (error_code) { + goto fn_fail; } - ADIO_ReadStridedColl(adio_fh, xbuf, count, datatype, file_ptr_type, - offset, status, &error_code); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - - if (e32_buf != NULL) { - error_code = MPIU_read_external32_conversion_fn(buf, datatype, count, e32_buf); - ADIOI_Free(e32_buf); - } - - MPIO_GPU_SWAP_BACK(host_buf, buf, count, datatype); - fn_exit: ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/read_allb.c b/src/mpi/romio/mpi-io/read_allb.c index ae7d6231877..c5443c89268 100644 --- a/src/mpi/romio/mpi-io/read_allb.c +++ b/src/mpi/romio/mpi-io/read_allb.c @@ -54,12 +54,19 @@ Output Parameters: int MPI_File_read_all_begin(MPI_File fh, void *buf, int count, MPI_Datatype datatype) { int error_code; - static char myname[] = "MPI_FILE_READ_ALL_BEGIN"; + ROMIO_THREAD_CS_ENTER(); - error_code = MPIOI_File_read_all_begin(fh, (MPI_Offset) 0, - ADIO_INDIVIDUAL, buf, count, datatype, myname); + error_code = MPIR_File_read_all_begin_impl(fh, buf, count, datatype); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -81,95 +88,17 @@ Output Parameters: int MPI_File_read_all_begin_c(MPI_File fh, void *buf, MPI_Count count, MPI_Datatype datatype) { int error_code; - static char myname[] = "MPI_FILE_READ_ALL_BEGIN"; - - error_code = MPIOI_File_read_all_begin(fh, (MPI_Offset) 0, - ADIO_INDIVIDUAL, buf, count, datatype, myname); - - return error_code; -} - -/* prevent multiple definitions of this routine */ -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_read_all_begin(MPI_File fh, - MPI_Offset offset, - int file_ptr_type, - void *buf, MPI_Aint count, MPI_Datatype datatype, char *myname) -{ - int error_code; - MPI_Count datatype_size; - ADIO_File adio_fh; - void *xbuf = NULL, *e32_buf = NULL, *host_buf = NULL; - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - - if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; + error_code = MPIR_File_read_all_begin_impl(fh, buf, count, datatype); + if (error_code) { + goto fn_fail; } - /* --END ERROR HANDLING-- */ - - MPI_Type_size_x(datatype, &datatype_size); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_READABLE(adio_fh, myname, error_code); - MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code); - - if (adio_fh->split_coll_count) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_IO, "**iosplitcoll", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - adio_fh->split_coll_count = 1; - - xbuf = buf; - if (adio_fh->is_external32) { - MPI_Aint e32_size = 0; - error_code = MPIU_datatype_full_size(datatype, &e32_size); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - e32_buf = ADIOI_Malloc(e32_size * count); - xbuf = e32_buf; - } else { - MPIO_GPU_HOST_ALLOC(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } - } - - ADIO_ReadStridedColl(adio_fh, xbuf, count, datatype, file_ptr_type, - offset, &adio_fh->split_status, &error_code); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - - if (e32_buf != NULL) { - error_code = MPIU_read_external32_conversion_fn(buf, datatype, count, e32_buf); - ADIOI_Free(e32_buf); - } - - MPIO_GPU_SWAP_BACK(host_buf, buf, count, datatype); fn_exit: ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/read_alle.c b/src/mpi/romio/mpi-io/read_alle.c index f24b10c58da..df5346678d0 100644 --- a/src/mpi/romio/mpi-io/read_alle.c +++ b/src/mpi/romio/mpi-io/read_alle.c @@ -40,46 +40,17 @@ Output Parameters: int MPI_File_read_all_end(MPI_File fh, void *buf, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_IREAD"; - - error_code = MPIOI_File_read_all_end(fh, buf, myname, status); - - return error_code; -} - -/* prevent multiple definitions of this routine */ -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_read_all_end(MPI_File fh, void *buf, char *myname, MPI_Status * status) -{ - int error_code = MPI_SUCCESS; - ADIO_File adio_fh; - - MPL_UNREFERENCED_ARG(buf); - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - - if (!(adio_fh->split_coll_count)) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_IO, "**iosplitcollnone", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; + error_code = MPIR_File_read_all_end_impl(fh, buf, status); + if (error_code) { + goto fn_fail; } - /* --END ERROR HANDLING-- */ - -#ifdef HAVE_STATUS_SET_BYTES - if (status != MPI_STATUS_IGNORE) - *status = adio_fh->split_status; -#endif - adio_fh->split_coll_count = 0; fn_exit: ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/read_at.c b/src/mpi/romio/mpi-io/read_at.c index 5458e15b562..239998e4c28 100644 --- a/src/mpi/romio/mpi-io/read_at.c +++ b/src/mpi/romio/mpi-io/read_at.c @@ -60,22 +60,19 @@ int MPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count, MPI_Datatype datatype, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_READ_AT"; -#ifdef MPI_hpux - int fl_xmpi; + ROMIO_THREAD_CS_ENTER(); - HPMP_IO_START(fl_xmpi, BLKMPIFILEREADAT, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - /* ADIOI_File_read() defined in mpi-io/read.c */ - error_code = MPIOI_File_read(fh, offset, ADIO_EXPLICIT_OFFSET, buf, - count, datatype, myname, status); - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_read_at_impl(fh, offset, buf, count, datatype, status); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -101,20 +98,17 @@ int MPI_File_read_at_c(MPI_File fh, MPI_Offset offset, void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_READ_AT"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEREADAT, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - /* ADIOI_File_read() defined in mpi-io/read.c */ - error_code = MPIOI_File_read(fh, offset, ADIO_EXPLICIT_OFFSET, buf, - count, datatype, myname, status); + ROMIO_THREAD_CS_ENTER(); -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_read_at_impl(fh, offset, buf, count, datatype, status); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/read_atall.c b/src/mpi/romio/mpi-io/read_atall.c index 340f7620f91..483658c0fd8 100644 --- a/src/mpi/romio/mpi-io/read_atall.c +++ b/src/mpi/romio/mpi-io/read_atall.c @@ -61,21 +61,19 @@ int MPI_File_read_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count, MPI_Datatype datatype, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_IREAD_AT"; -#ifdef MPI_hpux - int fl_xmpi; + ROMIO_THREAD_CS_ENTER(); - HPMP_IO_START(fl_xmpi, BLKMPIFILEREADATALL, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - error_code = MPIOI_File_read_all(fh, offset, ADIO_EXPLICIT_OFFSET, buf, - count, datatype, myname, status); - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_read_at_all_impl(fh, offset, buf, count, datatype, status); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -101,19 +99,17 @@ int MPI_File_read_at_all_c(MPI_File fh, MPI_Offset offset, void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_IREAD_AT"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEREADATALL, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - error_code = MPIOI_File_read_all(fh, offset, ADIO_EXPLICIT_OFFSET, buf, - count, datatype, myname, status); + ROMIO_THREAD_CS_ENTER(); -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_read_at_all_impl(fh, offset, buf, count, datatype, status); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/read_ord.c b/src/mpi/romio/mpi-io/read_ord.c index 2984ca8f95a..eb678140299 100644 --- a/src/mpi/romio/mpi-io/read_ord.c +++ b/src/mpi/romio/mpi-io/read_ord.c @@ -59,7 +59,20 @@ Output Parameters: int MPI_File_read_ordered(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status * status) { - return MPIOI_File_read_ordered(fh, buf, count, datatype, status); + int error_code; + ROMIO_THREAD_CS_ENTER(); + + error_code = MPIR_File_read_ordered_impl(fh, buf, count, datatype, status); + if (error_code) { + goto fn_fail; + } + + fn_exit: + ROMIO_THREAD_CS_EXIT(); + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -83,77 +96,18 @@ Output Parameters: int MPI_File_read_ordered_c(MPI_File fh, void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status * status) { - return MPIOI_File_read_ordered(fh, buf, count, datatype, status); -} - -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_read_ordered(MPI_File fh, void *buf, MPI_Aint count, - MPI_Datatype datatype, MPI_Status * status) -{ - int error_code, nprocs, myrank; - ADIO_Offset incr; - MPI_Count datatype_size; - int source, dest; - static char myname[] = "MPI_FILE_READ_ORDERED"; - ADIO_Offset shared_fp = 0; - ADIO_File adio_fh; - + int error_code; ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - /* --END ERROR HANDLING-- */ - - MPI_Type_size_x(datatype, &datatype_size); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, myname, error_code); - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_TEST_DEFERRED(adio_fh, "MPI_File_read_ordered", &error_code); - - MPI_Comm_size(adio_fh->comm, &nprocs); - MPI_Comm_rank(adio_fh->comm, &myrank); - - incr = (count * datatype_size) / adio_fh->etype_size; - - /* Use a message as a 'token' to order the operations */ - source = myrank - 1; - dest = myrank + 1; - if (source < 0) - source = MPI_PROC_NULL; - if (dest >= nprocs) - dest = MPI_PROC_NULL; - MPI_Recv(NULL, 0, MPI_BYTE, source, 0, adio_fh->comm, MPI_STATUS_IGNORE); - - ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) { - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; + error_code = MPIR_File_read_ordered_impl(fh, buf, count, datatype, status); + if (error_code) { + goto fn_fail; } - /* --END ERROR HANDLING-- */ - - MPI_Send(NULL, 0, MPI_BYTE, dest, 0, adio_fh->comm); - - ADIO_ReadStridedColl(adio_fh, buf, count, datatype, ADIO_EXPLICIT_OFFSET, - shared_fp, status, &error_code); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ fn_exit: ROMIO_THREAD_CS_EXIT(); - - /* FIXME: Check for error code from ReadStridedColl? */ return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/read_ordb.c b/src/mpi/romio/mpi-io/read_ordb.c index baf6f0bc31a..a98a4c9a9fe 100644 --- a/src/mpi/romio/mpi-io/read_ordb.c +++ b/src/mpi/romio/mpi-io/read_ordb.c @@ -53,7 +53,20 @@ Output Parameters: @*/ int MPI_File_read_ordered_begin(MPI_File fh, void *buf, int count, MPI_Datatype datatype) { - return MPIOI_File_read_ordered_begin(fh, buf, count, datatype); + int error_code; + ROMIO_THREAD_CS_ENTER(); + + error_code = MPIR_File_read_ordered_begin_impl(fh, buf, count, datatype); + if (error_code) { + goto fn_fail; + } + + fn_exit: + ROMIO_THREAD_CS_EXIT(); + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -74,107 +87,18 @@ Output Parameters: @*/ int MPI_File_read_ordered_begin_c(MPI_File fh, void *buf, MPI_Count count, MPI_Datatype datatype) { - return MPIOI_File_read_ordered_begin(fh, buf, count, datatype); -} - -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_read_ordered_begin(MPI_File fh, void *buf, MPI_Aint count, MPI_Datatype datatype) -{ - int error_code, nprocs, myrank; - MPI_Count datatype_size; - int source, dest; - ADIO_Offset shared_fp, incr; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_READ_ORDERED_BEGIN"; - void *xbuf = NULL, *e32_buf = NULL, *host_buf = NULL; - + int error_code; ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - - if (adio_fh->split_coll_count) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_IO, "**iosplitcoll", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - adio_fh->split_coll_count = 1; - - - MPI_Type_size_x(datatype, &datatype_size); - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, myname, error_code); - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code); - - MPI_Comm_size(adio_fh->comm, &nprocs); - MPI_Comm_rank(adio_fh->comm, &myrank); - - incr = (count * datatype_size) / adio_fh->etype_size; - /* Use a message as a 'token' to order the operations */ - source = myrank - 1; - dest = myrank + 1; - if (source < 0) - source = MPI_PROC_NULL; - if (dest >= nprocs) - dest = MPI_PROC_NULL; - MPI_Recv(NULL, 0, MPI_BYTE, source, 0, adio_fh->comm, MPI_STATUS_IGNORE); - - ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) { - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - MPI_Send(NULL, 0, MPI_BYTE, dest, 0, adio_fh->comm); - - xbuf = buf; - if (adio_fh->is_external32) { - MPI_Aint e32_size = 0; - error_code = MPIU_datatype_full_size(datatype, &e32_size); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - e32_buf = ADIOI_Malloc(e32_size * count); - xbuf = e32_buf; - } else { - MPIO_GPU_HOST_ALLOC(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } + error_code = MPIR_File_read_ordered_begin_impl(fh, buf, count, datatype); + if (error_code) { + goto fn_fail; } - - ADIO_ReadStridedColl(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, - shared_fp, &adio_fh->split_status, &error_code); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - - if (e32_buf != NULL) { - error_code = MPIU_read_external32_conversion_fn(buf, datatype, count, e32_buf); - ADIOI_Free(e32_buf); - } - - MPIO_GPU_SWAP_BACK(host_buf, buf, count, datatype); - fn_exit: ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/read_orde.c b/src/mpi/romio/mpi-io/read_orde.c index c1385393e20..c55a110eabb 100644 --- a/src/mpi/romio/mpi-io/read_orde.c +++ b/src/mpi/romio/mpi-io/read_orde.c @@ -38,35 +38,18 @@ Output Parameters: @*/ int MPI_File_read_ordered_end(MPI_File fh, void *buf, MPI_Status * status) { - int error_code = MPI_SUCCESS; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_READ_ORDERED_END"; - - MPL_UNREFERENCED_ARG(buf); - + int error_code; ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - - if (!(adio_fh->split_coll_count)) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_IO, "**iosplitcollnone", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; + error_code = MPIR_File_read_ordered_end_impl(fh, buf, status); + if (error_code) { + goto fn_fail; } - /* --END ERROR HANDLING-- */ - -#ifdef HAVE_STATUS_SET_BYTES - if (status != MPI_STATUS_IGNORE) - *status = adio_fh->split_status; -#endif - adio_fh->split_coll_count = 0; fn_exit: ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/read_sh.c b/src/mpi/romio/mpi-io/read_sh.c index 08bacfe8cf2..246b0150047 100644 --- a/src/mpi/romio/mpi-io/read_sh.c +++ b/src/mpi/romio/mpi-io/read_sh.c @@ -59,7 +59,20 @@ Output Parameters: int MPI_File_read_shared(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status * status) { - return MPIOI_File_read_shared(fh, buf, count, datatype, status); + int error_code; + ROMIO_THREAD_CS_ENTER(); + + error_code = MPIR_File_read_shared_impl(fh, buf, count, datatype, status); + if (error_code) { + goto fn_fail; + } + + fn_exit: + ROMIO_THREAD_CS_EXIT(); + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -83,120 +96,18 @@ Output Parameters: int MPI_File_read_shared_c(MPI_File fh, void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status * status) { - return MPIOI_File_read_shared(fh, buf, count, datatype, status); -} - -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_read_shared(MPI_File fh, void *buf, MPI_Aint count, - MPI_Datatype datatype, MPI_Status * status) -{ - int error_code, buftype_is_contig, filetype_is_contig; - static char myname[] = "MPI_FILE_READ_SHARED"; - MPI_Count datatype_size; - ADIO_Offset off, shared_fp, incr, bufsize; - ADIO_File adio_fh; - void *xbuf = NULL, *e32_buf = NULL, *host_buf = NULL; - + int error_code; ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - /* --END ERROR HANDLING-- */ - - MPI_Type_size_x(datatype, &datatype_size); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - if (count * datatype_size == 0) { -#ifdef HAVE_STATUS_SET_BYTES - MPIR_Status_set_bytes(status, datatype, 0); -#endif - error_code = MPI_SUCCESS; - goto fn_exit; - } - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_READABLE(adio_fh, myname, error_code); - MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); - ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig); - - ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code); - - incr = (count * datatype_size) / adio_fh->etype_size; - - ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) { - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - xbuf = buf; - if (adio_fh->is_external32) { - MPI_Aint e32_size = 0; - error_code = MPIU_datatype_full_size(datatype, &e32_size); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - e32_buf = ADIOI_Malloc(e32_size * count); - xbuf = e32_buf; - } else { - MPIO_GPU_HOST_ALLOC(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } - } - - /* contiguous or strided? */ - if (buftype_is_contig && filetype_is_contig) { - /* convert count and shared_fp to bytes */ - bufsize = datatype_size * count; - off = adio_fh->disp + adio_fh->etype_size * shared_fp; - - /* if atomic mode requested, lock (exclusive) the region, because there - * could be a concurrent noncontiguous request. On NFS, locking - * is done in the ADIO_ReadContig. */ - - if ((adio_fh->atomicity) && (adio_fh->file_system != ADIO_NFS)) - ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize); - - ADIO_ReadContig(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, - off, status, &error_code); - - if ((adio_fh->atomicity) && (adio_fh->file_system != ADIO_NFS)) - ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize); - } else { - ADIO_ReadStrided(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, - shared_fp, status, &error_code); - /* For strided and atomic mode, locking is done in ADIO_ReadStrided */ + error_code = MPIR_File_read_shared_impl(fh, buf, count, datatype, status); + if (error_code) { + goto fn_fail; } - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - - if (e32_buf != NULL) { - error_code = MPIU_read_external32_conversion_fn(buf, datatype, count, e32_buf); - ADIOI_Free(e32_buf); - } - - MPIO_GPU_SWAP_BACK(host_buf, buf, count, datatype); - fn_exit: ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/register_datarep.c b/src/mpi/romio/mpi-io/register_datarep.c index 635847845c6..b85bb874ac6 100644 --- a/src/mpi/romio/mpi-io/register_datarep.c +++ b/src/mpi/romio/mpi-io/register_datarep.c @@ -52,7 +52,7 @@ Input Parameters: native representation (function) . write_conversion_fn - function invoked to convert from native representation to file representation (function) -. dtype_file_extent_fn - function invoked to get the exted of a datatype as represented +. dtype_file_extent_fn - function invoked to get the extent of a datatype as represented in the file (function) - extra_state - pointer to extra state that is passed to each of the three functions @@ -73,10 +73,21 @@ int MPI_Register_datarep(ROMIO_CONST char *datarep, MPI_Datarep_conversion_function * write_conversion_fn, MPI_Datarep_extent_function * dtype_file_extent_fn, void *extra_state) { - int is_large = false; - return MPIOI_Register_datarep(datarep, (MPIOI_VOID_FN *) read_conversion_fn, - (MPIOI_VOID_FN *) write_conversion_fn, - dtype_file_extent_fn, extra_state, is_large); + int error_code; + ROMIO_THREAD_CS_ENTER(); + + error_code = MPIR_Register_datarep_impl(datarep, read_conversion_fn, write_conversion_fn, + dtype_file_extent_fn, extra_state); + if (error_code) { + goto fn_fail; + } + + fn_exit: + ROMIO_THREAD_CS_EXIT(); + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code); + goto fn_exit; } /* large count function */ @@ -92,7 +103,7 @@ Input Parameters: native representation (function) . write_conversion_fn - function invoked to convert from native representation to file representation (function) -. dtype_file_extent_fn - function invoked to get the exted of a datatype as represented +. dtype_file_extent_fn - function invoked to get the extent of a datatype as represented in the file (function) - extra_state - pointer to extra state that is passed to each of the three functions @@ -112,101 +123,20 @@ int MPI_Register_datarep_c(ROMIO_CONST char *datarep, MPI_Datarep_conversion_function_c * read_conversion_fn, MPI_Datarep_conversion_function_c * write_conversion_fn, MPI_Datarep_extent_function * dtype_file_extent_fn, void *extra_state) -{ - int is_large = true; - return MPIOI_Register_datarep(datarep, (MPIOI_VOID_FN *) read_conversion_fn, - (MPIOI_VOID_FN *) write_conversion_fn, - dtype_file_extent_fn, extra_state, is_large); -} - -#ifdef MPIO_BUILD_PROFILING -int MPIOI_Register_datarep(const char *datarep, - MPIOI_VOID_FN * read_conversion_fn, - MPIOI_VOID_FN * write_conversion_fn, - MPI_Datarep_extent_function * dtype_file_extent_fn, - void *extra_state, int is_large) { int error_code; - ADIOI_Datarep *adio_datarep; - static char myname[] = "MPI_REGISTER_DATAREP"; - ROMIO_THREAD_CS_ENTER(); - /* --BEGIN ERROR HANDLING-- */ - /* check datarep name (use strlen instead of strnlen because - * strnlen is not portable) */ - if (datarep == NULL || strlen(datarep) < 1 || strlen(datarep) > MPI_MAX_DATAREP_STRING) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, - MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**datarepname", 0); - error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - MPIR_MPIOInit(&error_code); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - /* --BEGIN ERROR HANDLING-- */ - /* check datarep isn't already registered */ - for (adio_datarep = ADIOI_Datarep_head; adio_datarep; adio_datarep = adio_datarep->next) { - if (!strncmp(datarep, adio_datarep->name, MPI_MAX_DATAREP_STRING)) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, - MPIR_ERR_RECOVERABLE, - myname, __LINE__, - MPI_ERR_DUP_DATAREP, - "**datarepused", "**datarepused %s", datarep); - error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code); - goto fn_exit; - } - } - - /* Check Non-NULL Read and Write conversion function pointer */ - /* Read and Write conversions are currently not supported. */ - if ((read_conversion_fn != NULL) || (write_conversion_fn != NULL)) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, - MPI_ERR_CONVERSION, "**drconvnotsupported", 0); - - error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code); - goto fn_exit; + error_code = MPIR_Register_datarep_large_impl(datarep, read_conversion_fn, write_conversion_fn, + dtype_file_extent_fn, extra_state); + if (error_code) { + goto fn_fail; } - /* check extent function pointer */ - if (dtype_file_extent_fn == NULL) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, - MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**datarepextent", 0); - error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - adio_datarep = ADIOI_Malloc(sizeof(ADIOI_Datarep)); - adio_datarep->name = ADIOI_Strdup(datarep); - adio_datarep->state = extra_state; - adio_datarep->is_large = is_large; - if (is_large) { - adio_datarep->u.large.read_conv_fn = - (MPI_Datarep_conversion_function_c *) read_conversion_fn; - adio_datarep->u.large.write_conv_fn = - (MPI_Datarep_conversion_function_c *) write_conversion_fn; - } else { - adio_datarep->u.small.read_conv_fn = (MPI_Datarep_conversion_function *) read_conversion_fn; - adio_datarep->u.small.write_conv_fn = - (MPI_Datarep_conversion_function *) write_conversion_fn; - } - adio_datarep->extent_fn = dtype_file_extent_fn; - adio_datarep->next = ADIOI_Datarep_head; - - ADIOI_Datarep_head = adio_datarep; - - error_code = MPI_SUCCESS; - fn_exit: ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/seek.c b/src/mpi/romio/mpi-io/seek.c index 4be25b87831..881652a2d58 100644 --- a/src/mpi/romio/mpi-io/seek.c +++ b/src/mpi/romio/mpi-io/seek.c @@ -38,97 +38,17 @@ Input Parameters: int MPI_File_seek(MPI_File fh, MPI_Offset offset, int whence) { int error_code; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_SEEK"; - MPI_Offset curr_offset, eof_offset; - -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILESEEK, TRDTBLOCK, adio_fh, MPI_DATATYPE_NULL, -1); -#endif /* MPI_hpux */ - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - switch (whence) { - case MPI_SEEK_SET: - /* --BEGIN ERROR HANDLING-- */ - if (offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, - MPIR_ERR_RECOVERABLE, myname, - __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - break; - case MPI_SEEK_CUR: - /* find offset corr. to current location of file pointer */ - ADIOI_Get_position(adio_fh, &curr_offset); - offset += curr_offset; - - /* --BEGIN ERROR HANDLING-- */ - if (offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, - MPIR_ERR_RECOVERABLE, myname, - __LINE__, MPI_ERR_ARG, "**ionegoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - break; - case MPI_SEEK_END: - /* we can in many cases do seeks w/o a file actually opened, but not in - * the MPI_SEEK_END case */ - ADIOI_TEST_DEFERRED(adio_fh, "MPI_File_seek", &error_code); - - /* find offset corr. to end of file */ - ADIOI_Get_eof_offset(adio_fh, &eof_offset); - offset += eof_offset; - - /* --BEGIN ERROR HANDLING-- */ - if (offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, - MPIR_ERR_RECOVERABLE, myname, - __LINE__, MPI_ERR_ARG, "**ionegoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - break; - default: - /* --BEGIN ERROR HANDLING-- */ - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobadwhence", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - /* --END ERROR HANDLING-- */ + error_code = MPIR_File_seek_impl(fh, offset, whence); + if (error_code) { + goto fn_fail; } - ADIO_SeekIndividual(adio_fh, offset, ADIO_SEEK_SET, &error_code); - /* TODO: what do we do with this error? */ - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, adio_fh, MPI_DATATYPE_NULL, -1); -#endif /* MPI_hpux */ - - error_code = MPI_SUCCESS; - fn_exit: ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/seek_sh.c b/src/mpi/romio/mpi-io/seek_sh.c index 8ae6e6b3282..15e7fbfdf49 100644 --- a/src/mpi/romio/mpi-io/seek_sh.c +++ b/src/mpi/romio/mpi-io/seek_sh.c @@ -36,133 +36,18 @@ Input Parameters: @*/ int MPI_File_seek_shared(MPI_File fh, MPI_Offset offset, int whence) { - int error_code = MPI_SUCCESS, tmp_whence, myrank; - static char myname[] = "MPI_FILE_SEEK_SHARED"; - MPI_Offset curr_offset, eof_offset, tmp_offset; - ADIO_File adio_fh; - + int error_code; ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code); - MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - tmp_offset = offset; - MPI_Bcast(&tmp_offset, 1, ADIO_OFFSET, 0, adio_fh->comm); - /* --BEGIN ERROR HANDLING-- */ - if (tmp_offset != offset) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**notsame", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - tmp_whence = whence; - MPI_Bcast(&tmp_whence, 1, MPI_INT, 0, adio_fh->comm); - /* --BEGIN ERROR HANDLING-- */ - if (tmp_whence != whence) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobadwhence", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - ADIOI_TEST_DEFERRED(adio_fh, "MPI_File_seek_shared", &error_code); - - MPI_Comm_rank(adio_fh->comm, &myrank); - - if (!myrank) { - switch (whence) { - case MPI_SEEK_SET: - /* --BEGIN ERROR HANDLING-- */ - if (offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, - MPIR_ERR_RECOVERABLE, - myname, __LINE__, - MPI_ERR_ARG, "**iobadoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - break; - case MPI_SEEK_CUR: - /* get current location of shared file pointer */ - ADIO_Get_shared_fp(adio_fh, 0, &curr_offset, &error_code); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, - MPIR_ERR_FATAL, - myname, __LINE__, - MPI_ERR_INTERN, "**iosharedfailed", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - offset += curr_offset; - /* --BEGIN ERROR HANDLING-- */ - if (offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, - MPIR_ERR_RECOVERABLE, - myname, __LINE__, - MPI_ERR_ARG, "**ionegoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - break; - case MPI_SEEK_END: - /* find offset corr. to end of file */ - ADIOI_Get_eof_offset(adio_fh, &eof_offset); - offset += eof_offset; - /* --BEGIN ERROR HANDLING-- */ - if (offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, - MPIR_ERR_RECOVERABLE, - myname, __LINE__, - MPI_ERR_ARG, "**ionegoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - break; - default: - /* --BEGIN ERROR HANDLING-- */ - error_code = MPIO_Err_create_code(MPI_SUCCESS, - MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, - "**iobadwhence", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - /* --END ERROR HANDLING-- */ - } - - ADIO_Set_shared_fp(adio_fh, offset, &error_code); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, - MPIR_ERR_FATAL, - myname, __LINE__, - MPI_ERR_INTERN, "**iosharedfailed", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - + error_code = MPIR_File_seek_shared_impl(fh, offset, whence); + if (error_code) { + goto fn_fail; } - /* FIXME: explain why the barrier is necessary */ - MPI_Barrier(adio_fh->comm); - - error_code = MPI_SUCCESS; - fn_exit: ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/set_atom.c b/src/mpi/romio/mpi-io/set_atom.c index b16ddff0be1..6b44f39aa9e 100644 --- a/src/mpi/romio/mpi-io/set_atom.c +++ b/src/mpi/romio/mpi-io/set_atom.c @@ -35,56 +35,18 @@ Input Parameters: @*/ int MPI_File_set_atomicity(MPI_File fh, int flag) { - int error_code, tmp_flag; - static char myname[] = "MPI_FILE_SET_ATOMICITY"; - ADIO_Fcntl_t *fcntl_struct; - ADIO_File adio_fh; - + int error_code; ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code); - - if (flag) - flag = 1; /* take care of non-one values! */ - -/* check if flag is the same on all processes */ - tmp_flag = flag; - MPI_Bcast(&tmp_flag, 1, MPI_INT, 0, adio_fh->comm); - - /* --BEGIN ERROR HANDLING-- */ - if (tmp_flag != flag) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**notsame", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; + error_code = MPIR_File_set_atomicity_impl(fh, flag); + if (error_code) { + goto fn_fail; } - /* --END ERROR HANDLING-- */ - - if (adio_fh->atomicity == flag) { - error_code = MPI_SUCCESS; - goto fn_exit; - } - - - fcntl_struct = (ADIO_Fcntl_t *) ADIOI_Malloc(sizeof(ADIO_Fcntl_t)); - fcntl_struct->atomicity = flag; - ADIO_Fcntl(adio_fh, ADIO_FCNTL_SET_ATOMICITY, fcntl_struct, &error_code); - /* TODO: what do we do with this error code? */ - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_Free(fcntl_struct); fn_exit: ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/set_info.c b/src/mpi/romio/mpi-io/set_info.c index cddbaa0c34a..bf96f5d922b 100644 --- a/src/mpi/romio/mpi-io/set_info.c +++ b/src/mpi/romio/mpi-io/set_info.c @@ -36,30 +36,17 @@ Input Parameters: int MPI_File_set_info(MPI_File fh, MPI_Info info) { int error_code; - static char myname[] = "MPI_FILE_SET_INFO"; - ADIO_File adio_fh; - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_INFO_ALL(info, error_code, fh->comm); - /* --END ERROR HANDLING-- */ - - /* set new info */ - ADIO_SetInfo(adio_fh, info, &error_code); + error_code = MPIR_File_set_info_impl(fh, info); + if (error_code) { + goto fn_fail; + } fn_exit: - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - ROMIO_THREAD_CS_EXIT(); - return error_code; fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/set_size.c b/src/mpi/romio/mpi-io/set_size.c index c57256460c6..01c49df6be1 100644 --- a/src/mpi/romio/mpi-io/set_size.c +++ b/src/mpi/romio/mpi-io/set_size.c @@ -36,66 +36,17 @@ Input Parameters: int MPI_File_set_size(MPI_File fh, MPI_Offset size) { int error_code; - ADIO_File adio_fh; - static char myname[] = "MPI_FILE_SET_SIZE"; - MPI_Offset tmp_sz, max_sz, min_sz; - -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILESETSIZE, TRDTBLOCK, adio_fh, MPI_DATATYPE_NULL, -1); -#endif /* MPI_hpux */ - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code); - - if (size < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobadsize", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - MPIO_CHECK_WRITABLE(fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - tmp_sz = size; - MPI_Allreduce(&tmp_sz, &max_sz, 1, ADIO_OFFSET, MPI_MAX, adio_fh->comm); - MPI_Allreduce(&tmp_sz, &min_sz, 1, ADIO_OFFSET, MPI_MIN, adio_fh->comm); - - /* --BEGIN ERROR HANDLING-- */ - if (max_sz != min_sz) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**notsame", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - if (!ADIO_Feature(adio_fh, ADIO_SCALABLE_RESIZE)) { - /* rare stupid file systems (like NFS) need to carry out resize on all - * processes */ - ADIOI_TEST_DEFERRED(adio_fh, "MPI_File_set_size", &error_code); + error_code = MPIR_File_set_size_impl(fh, size); + if (error_code) { + goto fn_fail; } - ADIO_Resize(adio_fh, size, &error_code); - /* TODO: what to do with error code? */ - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, adio_fh, MPI_DATATYPE_NULL, -1); -#endif /* MPI_hpux */ - fn_exit: ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/set_view.c b/src/mpi/romio/mpi-io/set_view.c index 261c9a8f77d..81bbe911732 100644 --- a/src/mpi/romio/mpi-io/set_view.c +++ b/src/mpi/romio/mpi-io/set_view.c @@ -41,145 +41,18 @@ Input Parameters: int MPI_File_set_view(MPI_File fh, MPI_Offset disp, MPI_Datatype etype, MPI_Datatype filetype, ROMIO_CONST char *datarep, MPI_Info info) { - int error_code = MPI_SUCCESS; - MPI_Count filetype_size, etype_size; - static char myname[] = "MPI_FILE_SET_VIEW"; - ADIO_Offset shared_fp, byte_off; - ADIO_File adio_fh; - + int error_code; ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - - if ((disp < 0) && (disp != MPI_DISPLACEMENT_CURRENT)) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobaddisp", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - - /* rudimentary checks for incorrect etype/filetype. */ - if (etype == MPI_DATATYPE_NULL) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**ioetype", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - MPIO_DATATYPE_ISCOMMITTED(etype, error_code); - if (error_code != MPI_SUCCESS) { - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - - if (filetype == MPI_DATATYPE_NULL) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iofiletype", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - MPIO_DATATYPE_ISCOMMITTED(filetype, error_code); - if (error_code != MPI_SUCCESS) { - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - - if ((adio_fh->access_mode & MPI_MODE_SEQUENTIAL) && (disp != MPI_DISPLACEMENT_CURRENT)) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iodispifseq", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - - if ((disp == MPI_DISPLACEMENT_CURRENT) && !(adio_fh->access_mode & MPI_MODE_SEQUENTIAL)) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iodispifseq", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - MPIO_CHECK_INFO_ALL(info, error_code, adio_fh->comm); - /* --END ERROR HANDLING-- */ - - MPI_Type_size_x(filetype, &filetype_size); - MPI_Type_size_x(etype, &etype_size); - - /* --BEGIN ERROR HANDLING-- */ - if (etype_size != 0 && filetype_size % etype_size != 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iofiletype", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; + error_code = MPIR_File_set_view_impl(fh, disp, etype, filetype, datarep, info); + if (error_code) { + goto fn_fail; } - if ((datarep == NULL) || (strcmp(datarep, "native") && - strcmp(datarep, "NATIVE") && - strcmp(datarep, "external32") && - strcmp(datarep, "EXTERNAL32") && - strcmp(datarep, "internal") && strcmp(datarep, "INTERNAL"))) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, - MPI_ERR_UNSUPPORTED_DATAREP, "**unsupporteddatarep", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - if (disp == MPI_DISPLACEMENT_CURRENT) { - MPI_Barrier(adio_fh->comm); - ADIO_Get_shared_fp(adio_fh, 0, &shared_fp, &error_code); - /* TODO: check error code */ - - MPI_Barrier(adio_fh->comm); - ADIOI_Get_byte_offset(adio_fh, shared_fp, &byte_off); - /* TODO: check error code */ - - disp = byte_off; - } - - ADIO_Set_view(adio_fh, disp, etype, filetype, info, &error_code); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) { - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - /* reset shared file pointer to zero */ - if (ADIO_Feature(adio_fh, ADIO_SHARED_FP) && (adio_fh->shared_fp_fd != ADIO_FILE_NULL)) { - /* only one process needs to set it to zero, but I don't want to - * create the shared-file-pointer file if shared file pointers have - * not been used so far. Therefore, every process that has already - * opened the shared-file-pointer file sets the shared file pointer - * to zero. If the file was not opened, the value is automatically - * zero. Note that shared file pointer is stored as no. of etypes - * relative to the current view, whereas indiv. file pointer is - * stored in bytes. */ - - ADIO_Set_shared_fp(adio_fh, 0, &error_code); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - } - - if (ADIO_Feature(adio_fh, ADIO_SHARED_FP)) { - MPI_Barrier(adio_fh->comm); /* for above to work correctly */ - } - if (strcmp(datarep, "external32") && strcmp(datarep, "EXTERNAL32")) - adio_fh->is_external32 = 0; - else - adio_fh->is_external32 = 1; - fn_exit: ROMIO_THREAD_CS_EXIT(); - return error_code; fn_fail: - /* --BEGIN ERROR HANDLING-- */ error_code = MPIO_Err_return_file(fh, error_code); goto fn_exit; - /* --END ERROR HANDLING-- */ } diff --git a/src/mpi/romio/mpi-io/wr_atallb.c b/src/mpi/romio/mpi-io/wr_atallb.c index 1832d60c8c0..4b97b58b8aa 100644 --- a/src/mpi/romio/mpi-io/wr_atallb.c +++ b/src/mpi/romio/mpi-io/wr_atallb.c @@ -57,12 +57,19 @@ int MPI_File_write_at_all_begin(MPI_File fh, MPI_Offset offset, ROMIO_CONST void int count, MPI_Datatype datatype) { int error_code; - static char myname[] = "MPI_FILE_WRITE_AT_ALL_BEGIN"; + ROMIO_THREAD_CS_ENTER(); - error_code = MPIOI_File_write_all_begin(fh, offset, - ADIO_EXPLICIT_OFFSET, buf, count, datatype, myname); + error_code = MPIR_File_write_at_all_begin_impl(fh, offset, buf, count, datatype); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -85,10 +92,17 @@ int MPI_File_write_at_all_begin_c(MPI_File fh, MPI_Offset offset, ROMIO_CONST vo MPI_Count count, MPI_Datatype datatype) { int error_code; - static char myname[] = "MPI_FILE_WRITE_AT_ALL_BEGIN"; + ROMIO_THREAD_CS_ENTER(); - error_code = MPIOI_File_write_all_begin(fh, offset, - ADIO_EXPLICIT_OFFSET, buf, count, datatype, myname); + error_code = MPIR_File_write_at_all_begin_impl(fh, offset, buf, count, datatype); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/wr_atalle.c b/src/mpi/romio/mpi-io/wr_atalle.c index 53a1be53f07..f2a3d5e0bd8 100644 --- a/src/mpi/romio/mpi-io/wr_atalle.c +++ b/src/mpi/romio/mpi-io/wr_atalle.c @@ -39,9 +39,17 @@ Output Parameters: int MPI_File_write_at_all_end(MPI_File fh, ROMIO_CONST void *buf, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_WRITE_AT_ALL_END"; + ROMIO_THREAD_CS_ENTER(); - error_code = MPIOI_File_write_all_end(fh, buf, myname, status); + error_code = MPIR_File_write_at_all_end_impl(fh, buf, status); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/write.c b/src/mpi/romio/mpi-io/write.c index 3bb91ed4411..56e0f01668c 100644 --- a/src/mpi/romio/mpi-io/write.c +++ b/src/mpi/romio/mpi-io/write.c @@ -58,21 +58,19 @@ int MPI_File_write(MPI_File fh, ROMIO_CONST void *buf, int count, MPI_Datatype datatype, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_WRITE"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEWRITE, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - error_code = MPIOI_File_write(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, buf, - count, datatype, myname, status); + ROMIO_THREAD_CS_ENTER(); -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_write_impl(fh, buf, count, datatype, status); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -97,139 +95,17 @@ int MPI_File_write_c(MPI_File fh, ROMIO_CONST void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_WRITE"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEWRITE, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - error_code = MPIOI_File_write(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, buf, - count, datatype, myname, status); - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ - - return error_code; -} - -/* prevent multiple definitions of this routine */ -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_write(MPI_File fh, - MPI_Offset offset, - int file_ptr_type, - const void *buf, - MPI_Aint count, MPI_Datatype datatype, char *myname, MPI_Status * status) -{ - int error_code, buftype_is_contig, filetype_is_contig; - MPI_Count datatype_size; - ADIO_Offset off, bufsize; - ADIO_File adio_fh; - void *e32buf = NULL; - const void *xbuf = NULL; - void *host_buf = NULL; - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - - if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - MPI_Type_size_x(datatype, &datatype_size); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - if (count * datatype_size == 0) { -#ifdef HAVE_STATUS_SET_BYTES - MPIR_Status_set_bytes(status, datatype, 0); -#endif - error_code = MPI_SUCCESS; - goto fn_exit; - } - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_WRITABLE(adio_fh, myname, error_code); - MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); - ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig); - - ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code); - - xbuf = buf; - if (adio_fh->is_external32) { - error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - xbuf = e32buf; - } else { - MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } + error_code = MPIR_File_write_impl(fh, buf, count, datatype, status); + if (error_code) { + goto fn_fail; } - if (buftype_is_contig && filetype_is_contig) { - /* convert bufcount and offset to bytes */ - bufsize = datatype_size * count; - if (file_ptr_type == ADIO_EXPLICIT_OFFSET) { - off = adio_fh->disp + adio_fh->etype_size * offset; - } else { /* ADIO_INDIVIDUAL */ - - off = adio_fh->fp_ind; - } - - /* if atomic mode requested, lock (exclusive) the region, because - * there could be a concurrent noncontiguous request. Locking doesn't - * work on some parallel file systems, and on NFS it is done in the - * ADIO_WriteContig. - */ - - if ((adio_fh->atomicity) && ADIO_Feature(adio_fh, ADIO_LOCKS)) { - ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize); - } - - ADIO_WriteContig(adio_fh, xbuf, count, datatype, file_ptr_type, off, status, &error_code); - - if ((adio_fh->atomicity) && ADIO_Feature(adio_fh, ADIO_LOCKS)) { - ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize); - } - } else { - /* For strided and atomic mode, locking is done in ADIO_WriteStrided */ - ADIO_WriteStrided(adio_fh, xbuf, count, datatype, file_ptr_type, - offset, status, &error_code); - } - - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - - MPIO_GPU_HOST_FREE(host_buf, count, datatype); - fn_exit: - if (e32buf != NULL) - ADIOI_Free(e32buf); ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/write_all.c b/src/mpi/romio/mpi-io/write_all.c index f96118b3630..b4ca47ce5f2 100644 --- a/src/mpi/romio/mpi-io/write_all.c +++ b/src/mpi/romio/mpi-io/write_all.c @@ -59,21 +59,19 @@ int MPI_File_write_all(MPI_File fh, ROMIO_CONST void *buf, int count, MPI_Datatype datatype, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_WRITE_ALL"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEWRITEALL, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - error_code = MPIOI_File_write_all(fh, (MPI_Offset) 0, - ADIO_INDIVIDUAL, buf, count, datatype, myname, status); + ROMIO_THREAD_CS_ENTER(); -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_write_all_impl(fh, buf, count, datatype, status); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -98,92 +96,17 @@ int MPI_File_write_all_c(MPI_File fh, ROMIO_CONST void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_WRITE_ALL"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEWRITEALL, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - error_code = MPIOI_File_write_all(fh, (MPI_Offset) 0, - ADIO_INDIVIDUAL, buf, count, datatype, myname, status); - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ - - return error_code; -} - -/* prevent multiple definitions of this routine */ -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_write_all(MPI_File fh, - MPI_Offset offset, - int file_ptr_type, - const void *buf, - MPI_Aint count, MPI_Datatype datatype, char *myname, MPI_Status * status) -{ - int error_code; - MPI_Count datatype_size; - ADIO_File adio_fh; - void *e32buf = NULL; - const void *xbuf = NULL; - void *host_buf = NULL; - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - - if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; + error_code = MPIR_File_write_all_impl(fh, buf, count, datatype, status); + if (error_code) { + goto fn_fail; } - /* --END ERROR HANDLING-- */ - - MPI_Type_size_x(datatype, &datatype_size); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_WRITABLE(adio_fh, myname, error_code); - MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - xbuf = buf; - if (adio_fh->is_external32) { - error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - xbuf = e32buf; - } else { - MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } - } - ADIO_WriteStridedColl(adio_fh, xbuf, count, datatype, file_ptr_type, - offset, status, &error_code); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - - MPIO_GPU_HOST_FREE(host_buf, count, datatype); fn_exit: - if (e32buf != NULL) - ADIOI_Free(e32buf); ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/write_allb.c b/src/mpi/romio/mpi-io/write_allb.c index 54544be2a4a..e8b216e4a64 100644 --- a/src/mpi/romio/mpi-io/write_allb.c +++ b/src/mpi/romio/mpi-io/write_allb.c @@ -53,12 +53,19 @@ Input Parameters: int MPI_File_write_all_begin(MPI_File fh, ROMIO_CONST void *buf, int count, MPI_Datatype datatype) { int error_code; - static char myname[] = "MPI_FILE_WRITE_ALL_BEGIN"; + ROMIO_THREAD_CS_ENTER(); - error_code = MPIOI_File_write_all_begin(fh, (MPI_Offset) 0, - ADIO_INDIVIDUAL, buf, count, datatype, myname); + error_code = MPIR_File_write_all_begin_impl(fh, buf, count, datatype); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -80,92 +87,17 @@ int MPI_File_write_all_begin_c(MPI_File fh, ROMIO_CONST void *buf, MPI_Count cou MPI_Datatype datatype) { int error_code; - static char myname[] = "MPI_FILE_WRITE_ALL_BEGIN"; - - error_code = MPIOI_File_write_all_begin(fh, (MPI_Offset) 0, - ADIO_INDIVIDUAL, buf, count, datatype, myname); - - return error_code; -} - -/* prevent multiple definitions of this routine */ -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_write_all_begin(MPI_File fh, - MPI_Offset offset, - int file_ptr_type, - const void *buf, MPI_Aint count, MPI_Datatype datatype, char *myname) -{ - int error_code; - MPI_Count datatype_size; - ADIO_File adio_fh; - void *e32buf = NULL; - const void *xbuf = NULL; - void *host_buf = NULL; - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code); - - if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_ARG, "**iobadoffset", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; + error_code = MPIR_File_write_all_begin_impl(fh, buf, count, datatype); + if (error_code) { + goto fn_fail; } - if (adio_fh->split_coll_count) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_IO, "**iosplitcoll", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - adio_fh->split_coll_count = 1; - - MPI_Type_size_x(datatype, &datatype_size); - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - - xbuf = buf; - if (adio_fh->is_external32) { - error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - xbuf = e32buf; - } else { - MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } - } - - adio_fh->split_datatype = datatype; - ADIO_WriteStridedColl(adio_fh, xbuf, count, datatype, file_ptr_type, - offset, &adio_fh->split_status, &error_code); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - - MPIO_GPU_HOST_FREE(host_buf, count, datatype); - fn_exit: - if (e32buf != NULL) - ADIOI_Free(e32buf); ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/write_alle.c b/src/mpi/romio/mpi-io/write_alle.c index 02809dc5338..b109ec1a3dc 100644 --- a/src/mpi/romio/mpi-io/write_alle.c +++ b/src/mpi/romio/mpi-io/write_alle.c @@ -39,51 +39,17 @@ Output Parameters: int MPI_File_write_all_end(MPI_File fh, ROMIO_CONST void *buf, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_WRITE_ALL_END"; - - error_code = MPIOI_File_write_all_end(fh, buf, myname, status); - - return error_code; -} - -/* prevent multiple definitions of this routine */ -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_write_all_end(MPI_File fh, const void *buf, char *myname, MPI_Status * status) -{ - int error_code; - ADIO_File adio_fh; - - MPL_UNREFERENCED_ARG(buf); - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - - if (!(adio_fh->split_coll_count)) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_IO, "**iosplitcollnone", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; + error_code = MPIR_File_write_all_end_impl(fh, buf, status); + if (error_code) { + goto fn_fail; } - /* --END ERROR HANDLING-- */ - -#ifdef HAVE_STATUS_SET_BYTES - /* FIXME - we should really ensure that the split_datatype remains - * valid by incrementing the ref count in the write_allb.c routine - * and decrement it here after setting the bytes */ - if (status != MPI_STATUS_IGNORE) - *status = adio_fh->split_status; -#endif - adio_fh->split_coll_count = 0; - - error_code = MPI_SUCCESS; fn_exit: ROMIO_THREAD_CS_EXIT(); - return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/write_at.c b/src/mpi/romio/mpi-io/write_at.c index f87fcf30b52..3f496599bc5 100644 --- a/src/mpi/romio/mpi-io/write_at.c +++ b/src/mpi/romio/mpi-io/write_at.c @@ -61,22 +61,19 @@ int MPI_File_write_at(MPI_File fh, MPI_Offset offset, ROMIO_CONST void *buf, int count, MPI_Datatype datatype, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_WRITE_AT"; -#ifdef MPI_hpux - int fl_xmpi; + ROMIO_THREAD_CS_ENTER(); - HPMP_IO_START(fl_xmpi, BLKMPIFILEWRITEAT, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - /* MPIOI_File_write() defined in mpi-io/write.c */ - error_code = MPIOI_File_write(fh, offset, ADIO_EXPLICIT_OFFSET, buf, - count, datatype, myname, status); - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_write_at_impl(fh, offset, buf, count, datatype, status); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -102,20 +99,17 @@ int MPI_File_write_at_c(MPI_File fh, MPI_Offset offset, ROMIO_CONST void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_WRITE_AT"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEWRITEAT, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ - - /* MPIOI_File_write() defined in mpi-io/write.c */ - error_code = MPIOI_File_write(fh, offset, ADIO_EXPLICIT_OFFSET, buf, - count, datatype, myname, status); + ROMIO_THREAD_CS_ENTER(); -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_write_at_impl(fh, offset, buf, count, datatype, status); + if (error_code) { + goto fn_fail; + } + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/write_atall.c b/src/mpi/romio/mpi-io/write_atall.c index 8985983d320..23e00c39a98 100644 --- a/src/mpi/romio/mpi-io/write_atall.c +++ b/src/mpi/romio/mpi-io/write_atall.c @@ -61,20 +61,19 @@ int MPI_File_write_at_all(MPI_File fh, MPI_Offset offset, ROMIO_CONST void *buf, int count, MPI_Datatype datatype, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_WRITE_AT_ALL"; -#ifdef MPI_hpux - int fl_xmpi; + ROMIO_THREAD_CS_ENTER(); - HPMP_IO_START(fl_xmpi, BLKMPIFILEWRITEATALL, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ + error_code = MPIR_File_write_at_all_impl(fh, offset, buf, count, datatype, status); + if (error_code) { + goto fn_fail; + } - error_code = MPIOI_File_write_all(fh, offset, ADIO_EXPLICIT_OFFSET, - buf, count, datatype, myname, status); - -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -100,18 +99,17 @@ int MPI_File_write_at_all_c(MPI_File fh, MPI_Offset offset, ROMIO_CONST void *bu MPI_Count count, MPI_Datatype datatype, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_WRITE_AT_ALL"; -#ifdef MPI_hpux - int fl_xmpi; - - HPMP_IO_START(fl_xmpi, BLKMPIFILEWRITEATALL, TRDTBLOCK, fh, datatype, count); -#endif /* MPI_hpux */ + ROMIO_THREAD_CS_ENTER(); - error_code = MPIOI_File_write_all(fh, offset, ADIO_EXPLICIT_OFFSET, - buf, count, datatype, myname, status); + error_code = MPIR_File_write_at_all_impl(fh, offset, buf, count, datatype, status); + if (error_code) { + goto fn_fail; + } -#ifdef MPI_hpux - HPMP_IO_END(fl_xmpi, fh, datatype, count); -#endif /* MPI_hpux */ + fn_exit: + ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/write_ord.c b/src/mpi/romio/mpi-io/write_ord.c index 7bfcb7ef421..859b89849a1 100644 --- a/src/mpi/romio/mpi-io/write_ord.c +++ b/src/mpi/romio/mpi-io/write_ord.c @@ -59,7 +59,20 @@ Output Parameters: int MPI_File_write_ordered(MPI_File fh, ROMIO_CONST void *buf, int count, MPI_Datatype datatype, MPI_Status * status) { - return MPIOI_File_write_ordered(fh, buf, count, datatype, status); + int error_code; + ROMIO_THREAD_CS_ENTER(); + + error_code = MPIR_File_write_ordered_impl(fh, buf, count, datatype, status); + if (error_code) { + goto fn_fail; + } + + fn_exit: + ROMIO_THREAD_CS_EXIT(); + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -83,100 +96,18 @@ Output Parameters: int MPI_File_write_ordered_c(MPI_File fh, ROMIO_CONST void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status * status) { - return MPIOI_File_write_ordered(fh, buf, count, datatype, status); -} - -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_write_ordered(MPI_File fh, const void *buf, MPI_Aint count, - MPI_Datatype datatype, MPI_Status * status) -{ - int error_code, nprocs, myrank; - ADIO_Offset incr; - MPI_Count datatype_size; - int source, dest; - static char myname[] = "MPI_FILE_WRITE_ORDERED"; - ADIO_Offset shared_fp; - ADIO_File adio_fh; - void *e32buf = NULL; - const void *xbuf; - void *host_buf = NULL; - + int error_code; ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - /* --END ERROR HANDLING-- */ - - MPI_Type_size_x(datatype, &datatype_size); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, myname, error_code); - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code); - - MPI_Comm_size(adio_fh->comm, &nprocs); - MPI_Comm_rank(adio_fh->comm, &myrank); - - incr = (count * datatype_size) / adio_fh->etype_size; - /* Use a message as a 'token' to order the operations */ - source = myrank - 1; - dest = myrank + 1; - if (source < 0) - source = MPI_PROC_NULL; - if (dest >= nprocs) - dest = MPI_PROC_NULL; - MPI_Recv(NULL, 0, MPI_BYTE, source, 0, adio_fh->comm, MPI_STATUS_IGNORE); - - ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL, - myname, __LINE__, MPI_ERR_INTERN, "**iosharedfailed", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; + error_code = MPIR_File_write_ordered_impl(fh, buf, count, datatype, status); + if (error_code) { + goto fn_fail; } - /* --END ERROR HANDLING-- */ - - MPI_Send(NULL, 0, MPI_BYTE, dest, 0, adio_fh->comm); - - xbuf = buf; - if (adio_fh->is_external32) { - error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - xbuf = e32buf; - } else { - MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } - } - - ADIO_WriteStridedColl(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, - shared_fp, status, &error_code); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - - MPIO_GPU_HOST_FREE(host_buf, count, datatype); fn_exit: - if (e32buf != NULL) - ADIOI_Free(e32buf); ROMIO_THREAD_CS_EXIT(); - - /* FIXME: Check for error code from WriteStridedColl? */ return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/src/mpi/romio/mpi-io/write_ordb.c b/src/mpi/romio/mpi-io/write_ordb.c index d01f9f53fbb..7f19e7ac6ff 100644 --- a/src/mpi/romio/mpi-io/write_ordb.c +++ b/src/mpi/romio/mpi-io/write_ordb.c @@ -55,7 +55,20 @@ Output Parameters: int MPI_File_write_ordered_begin(MPI_File fh, ROMIO_CONST void *buf, int count, MPI_Datatype datatype) { - return MPIOI_File_write_ordered_begin(fh, buf, count, datatype); + int error_code; + ROMIO_THREAD_CS_ENTER(); + + error_code = MPIR_File_write_ordered_begin_impl(fh, buf, count, datatype); + if (error_code) { + goto fn_fail; + } + + fn_exit: + ROMIO_THREAD_CS_EXIT(); + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -77,105 +90,21 @@ Output Parameters: int MPI_File_write_ordered_begin_c(MPI_File fh, ROMIO_CONST void *buf, MPI_Count count, MPI_Datatype datatype) { - return MPIOI_File_write_ordered_begin(fh, buf, count, datatype); -} - -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_write_ordered_begin(MPI_File fh, const void *buf, MPI_Aint count, - MPI_Datatype datatype) -{ - int error_code, nprocs, myrank; - ADIO_Offset incr; - MPI_Count datatype_size; - int source, dest; - static char myname[] = "MPI_FILE_WRITE_ORDERED_BEGIN"; - ADIO_Offset shared_fp; - ADIO_File adio_fh; - void *e32buf = NULL; - const void *xbuf = NULL; - void *host_buf = NULL; - + int error_code; ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - - if (adio_fh->split_coll_count) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_IO, "**iosplitcoll", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; + error_code = MPIR_File_write_ordered_begin_impl(fh, buf, count, datatype); + if (error_code) { + goto fn_fail; } - /* --END ERROR HANDLING-- */ - - adio_fh->split_coll_count = 1; - - MPI_Type_size_x(datatype, &datatype_size); - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, myname, error_code); - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code); - - MPI_Comm_size(adio_fh->comm, &nprocs); - MPI_Comm_rank(adio_fh->comm, &myrank); - - incr = (count * datatype_size) / adio_fh->etype_size; - /* Use a message as a 'token' to order the operations */ - source = myrank - 1; - dest = myrank + 1; - if (source < 0) - source = MPI_PROC_NULL; - if (dest >= nprocs) - dest = MPI_PROC_NULL; - MPI_Recv(NULL, 0, MPI_BYTE, source, 0, adio_fh->comm, MPI_STATUS_IGNORE); - - ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL, - myname, __LINE__, MPI_ERR_INTERN, "**iosharedfailed", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - MPI_Send(NULL, 0, MPI_BYTE, dest, 0, adio_fh->comm); - - xbuf = buf; - if (adio_fh->is_external32) { - error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - xbuf = e32buf; - } else { - MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } - } - - ADIO_WriteStridedColl(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, - shared_fp, &adio_fh->split_status, &error_code); - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - - MPIO_GPU_HOST_FREE(host_buf, count, datatype); fn_exit: ROMIO_THREAD_CS_EXIT(); - - /* FIXME: Check for error code from WriteStridedColl? */ return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } + +#ifdef MPIO_BUILD_PROFILING #endif diff --git a/src/mpi/romio/mpi-io/write_orde.c b/src/mpi/romio/mpi-io/write_orde.c index a99aa0cbb14..515c18d7fc2 100644 --- a/src/mpi/romio/mpi-io/write_orde.c +++ b/src/mpi/romio/mpi-io/write_orde.c @@ -39,34 +39,17 @@ Output Parameters: int MPI_File_write_ordered_end(MPI_File fh, ROMIO_CONST void *buf, MPI_Status * status) { int error_code; - static char myname[] = "MPI_FILE_WRITE_ORDERED_END"; - ADIO_File adio_fh; - - MPL_UNREFERENCED_ARG(buf); - ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - - if (!(adio_fh->split_coll_count)) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, - myname, __LINE__, MPI_ERR_IO, "**iosplitcollnone", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; + error_code = MPIR_File_write_ordered_end_impl(fh, buf, status); + if (error_code) { + goto fn_fail; } - /* --END ERROR HANDLING-- */ - -#ifdef HAVE_STATUS_SET_BYTES - if (status != MPI_STATUS_IGNORE) - *status = adio_fh->split_status; -#endif - adio_fh->split_coll_count = 0; - fn_exit: ROMIO_THREAD_CS_EXIT(); - return MPI_SUCCESS; + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } diff --git a/src/mpi/romio/mpi-io/write_sh.c b/src/mpi/romio/mpi-io/write_sh.c index c96dc02b1cb..d4d610d2083 100644 --- a/src/mpi/romio/mpi-io/write_sh.c +++ b/src/mpi/romio/mpi-io/write_sh.c @@ -59,7 +59,20 @@ Output Parameters: int MPI_File_write_shared(MPI_File fh, ROMIO_CONST void *buf, int count, MPI_Datatype datatype, MPI_Status * status) { - return MPIOI_File_write_shared(fh, buf, count, datatype, status); + int error_code; + ROMIO_THREAD_CS_ENTER(); + + error_code = MPIR_File_write_shared_impl(fh, buf, count, datatype, status); + if (error_code) { + goto fn_fail; + } + + fn_exit: + ROMIO_THREAD_CS_EXIT(); + return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } /* large count function */ @@ -83,117 +96,18 @@ Output Parameters: int MPI_File_write_shared_c(MPI_File fh, ROMIO_CONST void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status * status) { - return MPIOI_File_write_shared(fh, buf, count, datatype, status); -} - -#ifdef MPIO_BUILD_PROFILING -int MPIOI_File_write_shared(MPI_File fh, const void *buf, MPI_Aint count, - MPI_Datatype datatype, MPI_Status * status) -{ - int error_code, buftype_is_contig, filetype_is_contig; - ADIO_Offset bufsize; - static char myname[] = "MPI_FILE_READ_SHARED"; - MPI_Count datatype_size, incr; - ADIO_Offset off, shared_fp; - ADIO_File adio_fh; - void *e32buf = NULL; - const void *xbuf = NULL; - void *host_buf = NULL; - + int error_code; ROMIO_THREAD_CS_ENTER(); - adio_fh = MPIO_File_resolve(fh); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code); - MPIO_CHECK_COUNT(adio_fh, count, myname, error_code); - MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code); - /* --END ERROR HANDLING-- */ - - MPI_Type_size_x(datatype, &datatype_size); - - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code); - /* --END ERROR HANDLING-- */ - - if (count * datatype_size == 0) { -#ifdef HAVE_STATUS_SET_BYTES - MPIR_Status_set_bytes(status, datatype, 0); -#endif - error_code = MPI_SUCCESS; - goto fn_exit; + error_code = MPIR_File_write_shared_impl(fh, buf, count, datatype, status); + if (error_code) { + goto fn_fail; } - /* --BEGIN ERROR HANDLING-- */ - MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code); - MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, myname, error_code); - /* --END ERROR HANDLING-- */ - - ADIOI_Datatype_iscontig(datatype, &buftype_is_contig); - ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig); - - ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code); - - incr = (count * datatype_size) / adio_fh->etype_size; - - ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code); - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) { - error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL, - myname, __LINE__, MPI_ERR_INTERN, "**iosharedfailed", 0); - error_code = MPIO_Err_return_file(adio_fh, error_code); - goto fn_exit; - } - /* --END ERROR HANDLING-- */ - - xbuf = buf; - if (adio_fh->is_external32) { - error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf); - if (error_code != MPI_SUCCESS) - goto fn_exit; - - xbuf = e32buf; - } else { - MPIO_GPU_HOST_SWAP(host_buf, buf, count, datatype); - if (host_buf != NULL) { - xbuf = host_buf; - } - } - - if (buftype_is_contig && filetype_is_contig) { - /* convert bufocunt and shared_fp to bytes */ - bufsize = datatype_size * count; - off = adio_fh->disp + adio_fh->etype_size * shared_fp; - - /* if atomic mode requested, lock (exclusive) the region, because there - * could be a concurrent noncontiguous request. On NFS, locking is - * done in the ADIO_WriteContig. */ - - if ((adio_fh->atomicity) && (adio_fh->file_system != ADIO_NFS)) - ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize); - - ADIO_WriteContig(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, - off, status, &error_code); - - if ((adio_fh->atomicity) && (adio_fh->file_system != ADIO_NFS)) - ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize); - } else { - ADIO_WriteStrided(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET, - shared_fp, status, &error_code); - /* For strided and atomic mode, locking is done in ADIO_WriteStrided */ - } - - /* --BEGIN ERROR HANDLING-- */ - if (error_code != MPI_SUCCESS) - error_code = MPIO_Err_return_file(adio_fh, error_code); - /* --END ERROR HANDLING-- */ - - MPIO_GPU_HOST_FREE(host_buf, count, datatype); - fn_exit: - if (e32buf != NULL) - ADIOI_Free(e32buf); ROMIO_THREAD_CS_EXIT(); return error_code; + fn_fail: + error_code = MPIO_Err_return_file(fh, error_code); + goto fn_exit; } -#endif diff --git a/test/mpi/io/resized.c b/test/mpi/io/resized.c index 8f357ab18d7..797706c4871 100644 --- a/test/mpi/io/resized.c +++ b/test/mpi/io/resized.c @@ -51,7 +51,18 @@ int main(int argc, char **argv) strcpy(filename, *argv); } - MPI_File_delete(filename, MPI_INFO_NULL); + /* delete the file in case it exists. If it exists, it should return MPI_ERR_NO_SUCH_FILE */ + mpi_errno = MPI_File_delete(filename, MPI_INFO_NULL); + if (mpi_errno != MPI_SUCCESS) { + int error_class = 0; + MPI_Error_class(mpi_errno, &error_class); + if (error_class != MPI_ERR_NO_SUCH_FILE) { + printf + ("MPI_File_delete returned error code %x, error class %x, expect error class MPI_ERR_NO_SUCH_FILE\n", + mpi_errno, error_class); + errs++; + } + } /* create a resized type comprising an integer with an lb at sizeof(int) and extent = 3*sizeof(int) */ lb = sizeof(int);