FV3 Bundle
UtilitiesFV3JEDI.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2018 UCAR
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #include <mpi.h>
9 #include <unistd.h>
10 #include <string>
11 #include "eckit/config/Configuration.h"
12 #include "oops/parallel/mpi/mpi.h"
13 #include "oops/util/abor1_cpp.h"
14 #include "oops/util/Logger.h"
16 
17 namespace eckit {
18  class Configuration;
19 }
20 
21 namespace fv3jedi {
22 
23 // -----------------------------------------------------------------------------
24 
25 void stageFv3Files(const eckit::Configuration &conf) {
26  oops::Log::trace() << "Staging fv3 input.nml and field_table" << std::endl;
27 
28  // Get processor ID
29  int world_rank = oops::mpi::comm().rank();
30 
31  // Only one processor needs to move the files
32  if (world_rank == 0) {
33  // Remove anything currently present
34  std::remove("input.nml");
35  std::remove("field_table");
36 
37  // User provided input files for this geom/state/model etc
38  if (conf.has("nml_file")) {
39  std::string nml_file = conf.getString("nml_file");
40  symlink(nml_file.c_str(), "./input.nml");
41  } else {
42  ABORT("input.nml not in configuration");
43  }
44  if (conf.has("trc_file")) {
45  std::string trc_file = conf.getString("trc_file");
46  symlink(trc_file.c_str(), "./field_table");
47  } else {
48  ABORT("field_table not in configuration");
49  }
50 
51  // User may also be requesting the tlm/adm nml file
52  if (conf.has("nml_file_pert")) {
53  oops::Log::trace() << "Also staging fv3 inputpert.nml" << std::endl;
54  std::remove("inputpert.nml");
55  std::string nml_file_pert = conf.getString("nml_file_pert");
56  symlink(nml_file_pert.c_str(), "./inputpert.nml");
57  }
58  }
59 
60  // Nobody moves until files are in place
61  oops::mpi::comm().barrier();
62 }
63 
64 // -----------------------------------------------------------------------------
65 
66 void stageFv3Input(const eckit::Configuration &conf) {
67  oops::Log::trace() << "Staging fv3 input.nml" << std::endl;
68 
69  // Get processor ID
70  int world_rank = oops::mpi::comm().rank();
71 
72  // Only one processor needs to move the files
73  if (world_rank == 0) {
74  // Remove anything currently present
75  std::remove("input.nml");
76 
77  // User provided input files for this geom/state/model etc
78  if (conf.has("nml_file")) {
79  std::string nml_file = conf.getString("nml_file");
80  symlink(nml_file.c_str(), "./input.nml");
81  } else {
82  ABORT("input.nml not in configuration");
83  }
84  }
85 
86  // Nobody moves until files are in place
87  oops::mpi::comm().barrier();
88 }
89 
90 // -----------------------------------------------------------------------------
91 
93  oops::Log::trace() << "Removing fv3 input.nml and field_table" << std::endl;
94 
95  // Get processor ID
96  int world_rank = oops::mpi::comm().rank();
97 
98  // No file deletion until everyone catches up
99  oops::mpi::comm().barrier();
100 
101  // Only one processor needs to move the files
102  if (world_rank == 0) {
103  std::remove("input.nml");
104  std::remove("field_table");
105 
106  // And inputpert if it is there
107  std::remove("inputpert.nml");
108  }
109 }
110 
111 // -----------------------------------------------------------------------------
112 
114  oops::Log::trace() << "Removing fv3 input.nml" << std::endl;
115 
116  // Get processor ID
117  int world_rank = oops::mpi::comm().rank();
118 
119  // No file deletion until everyone catches up
120  oops::mpi::comm().barrier();
121 
122  // Only one processor needs to move the files
123  if (world_rank == 0) {
124  std::remove("input.nml");
125  }
126 }
127 
128 // -----------------------------------------------------------------------------
129 
130 } // namespace fv3jedi
void removeFv3Files()
void stageFv3Files(const eckit::Configuration &conf)
void removeFv3Input()
Definition: conf.py:1
const eckit::mpi::Comm & comm()
Definition: mpi.cc:16
void stageFv3Input(const eckit::Configuration &conf)