Loading [MathJax]/extensions/tex2jax.js
PISM, A Parallel Ice Sheet Model 2.2.2-d6b3a29ca committed by Constantine Khrulev on 2025-03-28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NC4_Par.cc
Go to the documentation of this file.
1// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2020, 2023, 2024 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 "pism/util/io/NC4_Par.hh"
20#include "pism/util/error_handling.hh"
21#include "pism/util/io/IO_Flags.hh"
22
23// netcdf_par.h has to be included *after* mpi.h and after netcdf.h
24//
25// note that we don't need to define MPI_INCLUDED because this code is built *only* if we
26// have a parallel NetCDF library.
27extern "C" {
28#include <netcdf.h>
29#include <netcdf_par.h>
30}
31
32namespace pism {
33namespace io {
34
35//! \brief Prints an error message; for debugging.
36static void check(const ErrorLocation &where, int return_code) {
37 if (return_code != NC_NOERR) {
38 throw RuntimeError(where, nc_strerror(return_code));
39 }
40}
41
42void NC4_Par::open_impl(const std::string &fname, io::Mode mode) {
43 MPI_Info info = MPI_INFO_NULL;
44 int stat;
45
46 int open_mode = mode == io::PISM_READONLY ? NC_NOWRITE : NC_WRITE;
47 open_mode = open_mode | NC_MPIIO;
48
49 stat = nc_open_par(fname.c_str(), open_mode, m_com, info, &m_file_id);
50
52}
53
54void NC4_Par::create_impl(const std::string &fname) {
55 MPI_Info info = MPI_INFO_NULL;
56 int stat;
57
58 stat = nc_create_par(fname.c_str(),
59 NC_NETCDF4 | NC_MPIIO,
60 m_com, info, &m_file_id);
61
63}
64
65void NC4_Par::set_access_mode(int varid) const {
66 int stat;
67
68 // Use collective parallel access mode because it is faster.
69 stat = nc_var_par_access(m_file_id, varid, NC_COLLECTIVE);
71}
72
74 m_compression_level = level;
75}
76
77
78} // end of namespace io
79} // end of namespace pism
unsigned int m_compression_level
Definition NC4File.hh:106
virtual void set_compression_level_impl(int level) const
Definition NC4_Par.cc:73
virtual void open_impl(const std::string &filename, io::Mode mode)
Definition NC4_Par.cc:42
virtual void set_access_mode(int varid) const
Definition NC4_Par.cc:65
virtual void create_impl(const std::string &filename)
Definition NC4_Par.cc:54
MPI_Comm m_com
Definition NCFile.hh:221
#define PISM_ERROR_LOCATION
@ PISM_READONLY
open an existing file for reading only
Definition IO_Flags.hh:68
static void check(const ErrorLocation &where, int return_code)
Prints an error message; for debugging.
Definition NC4_Par.cc:36