tNC4_Par.cc - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
HTML git clone git://src.adamsgaard.dk/pism
DIR Log
DIR Files
DIR Refs
DIR LICENSE
---
tNC4_Par.cc (2739B)
---
1 // Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2019 PISM Authors
2 //
3 // This file is part of PISM.
4 //
5 // PISM is free software; you can redistribute it and/or modify it under the
6 // terms of the GNU General Public License as published by the Free Software
7 // Foundation; either version 3 of the License, or (at your option) any later
8 // version.
9 //
10 // PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with PISM; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 #include "NC4_Par.hh"
20 #include "pism/util/error_handling.hh"
21
22 // netcdf_par.h has to be included *after* mpi.h and after netcdf.h
23 //
24 // note that we don't need to define MPI_INCLUDED because this code is built *only* if we
25 // have a parallel NetCDF library.
26 extern "C" {
27 #include <netcdf.h>
28 #include <netcdf_par.h>
29 }
30
31 namespace pism {
32 namespace io {
33
34 //! \brief Prints an error message; for debugging.
35 static void check(const ErrorLocation &where, int return_code) {
36 if (return_code != NC_NOERR) {
37 throw RuntimeError(where, nc_strerror(return_code));
38 }
39 }
40
41 void NC4_Par::open_impl(const std::string &fname, IO_Mode mode) {
42 MPI_Info info = MPI_INFO_NULL;
43 int stat;
44
45 int open_mode = mode == PISM_READONLY ? NC_NOWRITE : NC_WRITE;
46 open_mode = open_mode | NC_MPIIO;
47
48 stat = nc_open_par(fname.c_str(), open_mode, m_com, info, &m_file_id);
49
50 check(PISM_ERROR_LOCATION, stat);
51 }
52
53 void NC4_Par::create_impl(const std::string &fname) {
54 MPI_Info info = MPI_INFO_NULL;
55 int stat;
56
57 stat = nc_create_par(fname.c_str(),
58 NC_NETCDF4 | NC_MPIIO,
59 m_com, info, &m_file_id);
60
61 check(PISM_ERROR_LOCATION, stat);
62 }
63
64 void NC4_Par::set_access_mode(int varid, bool transposed) const {
65 int stat;
66
67 if (transposed) {
68 // Use independent parallel access mode because it works. It would be
69 // better to use collective mode, but I/O performance is ruined by
70 // the transpose anyway.
71 //
72 // See https://bugtracking.unidata.ucar.edu/browse/NCF-152 for the description of the bug we're
73 // avoiding here.
74 stat = nc_var_par_access(m_file_id, varid, NC_INDEPENDENT); check(PISM_ERROR_LOCATION, stat);
75 } else {
76 // Use collective parallel access mode because it is faster (and because it
77 // works in this case).
78 stat = nc_var_par_access(m_file_id, varid, NC_COLLECTIVE); check(PISM_ERROR_LOCATION, stat);
79 }
80 }
81
82
83
84 } // end of namespace io
85 } // end of namespace pism