Ice Sheet System Model  4.18
Code documentation
Functions
issm_dakota.cpp File Reference

: ISSM DAKOTA main program More...

#include "./issm.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

: ISSM DAKOTA main program

Definition in file issm_dakota.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 16 of file issm_dakota.cpp.

16  {
17 
18  #if defined(_HAVE_DAKOTA_) && _DAKOTA_MAJOR_ >= 6
19 
20  bool parallel=true;
21  char* dakota_input_file=NULL;
22  char* dakota_output_file = NULL;
23  char* dakota_error_file = NULL;
24 
25  /*Define MPI_DEBUG in dakota_global_defs.cpp to cause a hold here*/
26  Dakota::mpi_debug_hold();
27 
28  /*Initialize MPI: */
29  ISSM_MPI_Init(&argc, &argv); // initialize MPI
30 
31  /*Recover file name for dakota input file:*/
32  dakota_input_file=xNew<char>((strlen(argv[2])+strlen(argv[3])+strlen(".qmu.in")+2));
33  sprintf(dakota_input_file,"%s/%s%s",argv[2],argv[3],".qmu.in");
34 
35  dakota_output_file=xNew<char>((strlen(argv[2])+strlen(argv[3])+strlen(".qmu.out")+2));
36  sprintf(dakota_output_file,"%s/%s%s",argv[2],argv[3],".qmu.out");
37 
38  dakota_error_file=xNew<char>((strlen(argv[2])+strlen(argv[3])+strlen(".qmu.err")+2));
39  sprintf(dakota_error_file,"%s/%s%s",argv[2],argv[3],".qmu.err");
40 
41  /* Parse input and construct Dakota LibraryEnvironment, performing input data checks*/
42  Dakota::ProgramOptions opts;
43  opts.input_file(dakota_input_file);
44  opts.output_file(dakota_output_file);
45  opts.error_file(dakota_error_file);
46 
47  /* Defaults constructs the MPIManager, which assumes COMM_WORLD*/
48  Dakota::LibraryEnvironment env(opts);
49 
50  /* get the list of all models matching the specified model, interface, driver:*/
51  Dakota::ModelList filt_models = env.filtered_model_list("single", "direct", "matlab");
52  if (filt_models.empty()) {
53  Cerr << "Error: no parallel interface plugin performed. Check compatibility "
54  << "between parallel\n configuration and selected analysis_driver."
55  << std::endl;
56  Dakota::abort_handler(-1);
57  }
58 
59  Dakota::ProblemDescDB& problem_db = env.problem_description_db();
60  Dakota::ModelLIter ml_iter;
61  size_t model_index = problem_db.get_db_model_node(); // for restoration
62  for (ml_iter = filt_models.begin(); ml_iter != filt_models.end(); ++ml_iter) {
63  // set DB nodes to input specification for this Model
64  problem_db.set_db_model_nodes(ml_iter->model_id());
65 
66  Dakota::Interface& model_interface = ml_iter->derived_interface();
67 
68  // Parallel case: plug in derived Interface object with an analysisComm.
69  // Note: retrieval and passing of analysisComm is necessary only if
70  // parallel operations will be performed in the derived constructor.
71 
72  // retrieve the currently active analysisComm from the Model. In the most
73  // general case, need an array of Comms to cover all Model configurations.
74  const MPI_Comm& analysis_comm = ml_iter->analysis_comm();
75 
76  // don't increment ref count since no other envelope shares this letter
77  model_interface.assign_rep(new
78  SIM::IssmParallelDirectApplicInterface(problem_db, analysis_comm, argc, argv), false);
79  }
80  problem_db.set_db_model_nodes(model_index); // restore
81 
82  /* Execute the environment:*/
83  env.execute();
84 
85  xDelete<char>(dakota_input_file);
86  xDelete<char>(dakota_output_file);
87  xDelete<char>(dakota_error_file);
88 
89  /*Return unix success: */
90  return 0;
91  #else
92  Cout << "ISSM Dakota executable was compiled without support of Dakota! Will just return now!" << "\n";
93  return 1;
94  #endif
95 
96 }
ISSM_MPI_Init
int ISSM_MPI_Init(int *argc, char ***argv)
Definition: issmmpi.cpp:319