[20498] | 1 | Index: ../trunk-jpl/src/c/Makefile.am
|
---|
| 2 | ===================================================================
|
---|
| 3 | --- ../trunk-jpl/src/c/Makefile.am (revision 19651)
|
---|
| 4 | +++ ../trunk-jpl/src/c/Makefile.am (revision 19652)
|
---|
| 5 | @@ -263,7 +263,7 @@
|
---|
| 6 | #DAKOTA sources {{{
|
---|
| 7 | if DAKOTA
|
---|
| 8 | issm_sources += ./classes/Dakota/IssmDirectApplicInterface.h\
|
---|
| 9 | - ./classes/Dakota/IssmParallelDirectApplicInterface.h\
|
---|
| 10 | + ./classes/Dakota/IssmParallelDirectApplicInterface.cpp\
|
---|
| 11 | ./modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp\
|
---|
| 12 | ./modules/InputUpdateFromVectorDakotax/InputUpdateFromVectorDakotax.cpp\
|
---|
| 13 | ./modules/InputUpdateFromMatrixDakotax/InputUpdateFromMatrixDakotax.cpp\
|
---|
| 14 | Index: ../trunk-jpl/src/c/classes/Dakota/IssmParallelDirectApplicInterface.h
|
---|
| 15 | ===================================================================
|
---|
| 16 | --- ../trunk-jpl/src/c/classes/Dakota/IssmParallelDirectApplicInterface.h (revision 19651)
|
---|
| 17 | +++ ../trunk-jpl/src/c/classes/Dakota/IssmParallelDirectApplicInterface.h (revision 19652)
|
---|
| 18 | @@ -28,107 +28,23 @@
|
---|
| 19 | #endif
|
---|
| 20 | /*}}}*/
|
---|
| 21 |
|
---|
| 22 | -#if defined(_HAVE_DAKOTA_) && _DAKOTA_MAJOR_ >= 6
|
---|
| 23 |
|
---|
| 24 | -/*Dakota include files: {{{*/
|
---|
| 25 | +#if !defined(_WRAPPERS_) && defined(_HAVE_DAKOTA_) && _DAKOTA_MAJOR_ >= 6
|
---|
| 26 | +
|
---|
| 27 | #include <DirectApplicInterface.hpp>
|
---|
| 28 | -/*}}}*/
|
---|
| 29 | +class FemModel;
|
---|
| 30 |
|
---|
| 31 | namespace SIM {
|
---|
| 32 | class IssmParallelDirectApplicInterface: public Dakota::DirectApplicInterface{
|
---|
| 33 |
|
---|
| 34 | + private:
|
---|
| 35 | + FemModel* femmodel_init;
|
---|
| 36 | public:
|
---|
| 37 | - /*these fields are used by core solutions: */
|
---|
| 38 | - void *femmodel;
|
---|
| 39 | -
|
---|
| 40 | - /*Constructors/Destructors{{{*/
|
---|
| 41 | - IssmParallelDirectApplicInterface(const Dakota::ProblemDescDB& problem_db, const MPI_Comm& analysis_comm, void* in_femmodel):Dakota::DirectApplicInterface(problem_db){
|
---|
| 42 | -
|
---|
| 43 | - #ifdef MPI_DEBUG
|
---|
| 44 | - // For testing purposes, output size/rank of the incoming analysis_comm
|
---|
| 45 | - int rank, size;
|
---|
| 46 | - MPI_Comm_rank(analysis_comm, &rank);
|
---|
| 47 | - MPI_Comm_size(analysis_comm, &size);
|
---|
| 48 | - Cout << "In SIM::ParallelDirectApplicInterface ctor, rank = " << rank
|
---|
| 49 | - << " size = " << size << std::endl;
|
---|
| 50 | - #endif // MPI_DEBUG
|
---|
| 51 | -
|
---|
| 52 | - femmodel = in_femmodel;
|
---|
| 53 | - }
|
---|
| 54 | - ~IssmParallelDirectApplicInterface(){
|
---|
| 55 | - }
|
---|
| 56 | - /*}}}*/
|
---|
| 57 | -
|
---|
| 58 | + IssmParallelDirectApplicInterface(const Dakota::ProblemDescDB& problem_db, const MPI_Comm& evaluation_comm, int argc, char** argv);
|
---|
| 59 | + ~IssmParallelDirectApplicInterface();
|
---|
| 60 | protected:
|
---|
| 61 | -
|
---|
| 62 | /// execute an analysis code portion of a direct evaluation invocation
|
---|
| 63 | - int derived_map_ac(const Dakota::String& driver){/*{{{*/
|
---|
| 64 | -
|
---|
| 65 | - #ifdef MPI_DEBUG
|
---|
| 66 | - Cout << "analysis server " << analysisServerId << " invoking " << ac_name
|
---|
| 67 | - << " within SIM::ParallelDirectApplicInterface." << std::endl;
|
---|
| 68 | - #endif // MPI_DEBUG
|
---|
| 69 | -
|
---|
| 70 | - int i;
|
---|
| 71 | - IssmDouble* variables=NULL;
|
---|
| 72 | - char** variable_descriptors=NULL;
|
---|
| 73 | - char* variable_descriptor=NULL;
|
---|
| 74 | - IssmDouble* responses=NULL;
|
---|
| 75 | -
|
---|
| 76 | - /*Before launching analysis, we need to transfer the dakota inputs into Issm
|
---|
| 77 | - *readable variables: */
|
---|
| 78 | -
|
---|
| 79 | - /*First, the variables: */
|
---|
| 80 | - variables=xNew<IssmDouble>(numACV);
|
---|
| 81 | - for(i=0;i<numACV;i++){
|
---|
| 82 | - variables[i]=xC[i];
|
---|
| 83 | - }
|
---|
| 84 | - /*The descriptors: */
|
---|
| 85 | - variable_descriptors=xNew<char*>(numACV);
|
---|
| 86 | - for(i=0;i<numACV;i++){
|
---|
| 87 | - std::string label=xCLabels[i];
|
---|
| 88 | - variable_descriptor=xNew<char>(strlen(label.c_str())+1);
|
---|
| 89 | - memcpy(variable_descriptor,label.c_str(),(strlen(label.c_str())+1)*sizeof(char));
|
---|
| 90 | -
|
---|
| 91 | - variable_descriptors[i]=variable_descriptor;
|
---|
| 92 | - }
|
---|
| 93 | -
|
---|
| 94 | - /*Initialize responses: */
|
---|
| 95 | - responses=xNewZeroInit<IssmDouble>(numFns);
|
---|
| 96 | -
|
---|
| 97 | - /*run core solution: */
|
---|
| 98 | - //DakotaSpawnCore(responses,numFns, variables,variable_descriptors,numACV,femmodel);
|
---|
| 99 | -
|
---|
| 100 | - /*populate responses: */
|
---|
| 101 | - for(i=0;i<numFns;i++){
|
---|
| 102 | - fnVals[i]=responses[i];
|
---|
| 103 | - }
|
---|
| 104 | -
|
---|
| 105 | - /*Free ressources:*/
|
---|
| 106 | - xDelete<IssmDouble>(variables);
|
---|
| 107 | - for(i=0;i<numACV;i++){
|
---|
| 108 | - variable_descriptor=variable_descriptors[i];
|
---|
| 109 | - xDelete<char>(variable_descriptor);
|
---|
| 110 | - }
|
---|
| 111 | - xDelete<char*>(variable_descriptors);
|
---|
| 112 | - xDelete<IssmDouble>(responses);
|
---|
| 113 | -
|
---|
| 114 | - return 0;
|
---|
| 115 | - }/*}}}*/
|
---|
| 116 | -
|
---|
| 117 | - /// no-op hides base error; job batching occurs within wait_local_evaluations()
|
---|
| 118 | - //void derived_map_asynch(const Dakota::ParamResponsePair& pair){};
|
---|
| 119 | -
|
---|
| 120 | - /// evaluate the batch of jobs contained in prp_queue
|
---|
| 121 | - //void wait_local_evaluations(Dakota::PRPQueue& prp_queue);
|
---|
| 122 | -
|
---|
| 123 | - /// invokes wait_local_evaluations() (no special nowait support)
|
---|
| 124 | - //void test_local_evaluations(Dakota::PRPQueue& prp_queue) { wait_local_evaluations(prp_queue); };
|
---|
| 125 | -
|
---|
| 126 | - /// no-op hides default run-time error checks at DirectApplicInterface level
|
---|
| 127 | - //void set_communicators_checks(int max_eval_concurrency){};
|
---|
| 128 | -
|
---|
| 129 | - private:
|
---|
| 130 | + int derived_map_ac(const Dakota::String& ac_name);
|
---|
| 131 | };
|
---|
| 132 | }
|
---|
| 133 | /*}}}*/
|
---|
| 134 | Index: ../trunk-jpl/src/c/classes/Dakota/IssmParallelDirectApplicInterface.cpp
|
---|
| 135 | ===================================================================
|
---|
| 136 | --- ../trunk-jpl/src/c/classes/Dakota/IssmParallelDirectApplicInterface.cpp (revision 0)
|
---|
| 137 | +++ ../trunk-jpl/src/c/classes/Dakota/IssmParallelDirectApplicInterface.cpp (revision 19652)
|
---|
| 138 | @@ -0,0 +1,136 @@
|
---|
| 139 | +/*!\file: see IssmParallelDirectApplicInterface.h for documentation. */
|
---|
| 140 | +
|
---|
| 141 | +/*Issm Configuration: {{{*/
|
---|
| 142 | +#ifdef HAVE_CONFIG_H
|
---|
| 143 | +#include <config.h>
|
---|
| 144 | +#else
|
---|
| 145 | +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
| 146 | +#endif
|
---|
| 147 | +/*}}}*/
|
---|
| 148 | +
|
---|
| 149 | +#if !defined(_WRAPPERS_) && defined(_HAVE_DAKOTA_) && _DAKOTA_MAJOR_ >= 6
|
---|
| 150 | +
|
---|
| 151 | +#include "../classes.h"
|
---|
| 152 | +#include "../../cores/cores.h"
|
---|
| 153 | +#include "../../modules/modules.h"
|
---|
| 154 | +
|
---|
| 155 | +namespace SIM {
|
---|
| 156 | + IssmParallelDirectApplicInterface::IssmParallelDirectApplicInterface(const Dakota::ProblemDescDB& problem_db, const MPI_Comm& evaluation_comm, int argc, char** argv) :Dakota::DirectApplicInterface(problem_db){ /*{{{*/
|
---|
| 157 | +
|
---|
| 158 | + int world_rank;
|
---|
| 159 | + ISSM_MPI_Comm_rank(ISSM_MPI_COMM_WORLD,&world_rank);
|
---|
| 160 | +
|
---|
| 161 | + /*Build an femmodel if you are a slave, using the corresponding communicator:*/
|
---|
| 162 | + if(world_rank!=0){
|
---|
| 163 | + femmodel_init= new FemModel(argc,argv,evaluation_comm);
|
---|
| 164 | + femmodel_init->profiler->Tag(StartCore);
|
---|
| 165 | + }
|
---|
| 166 | +
|
---|
| 167 | + }
|
---|
| 168 | + /*}}}*/
|
---|
| 169 | + IssmParallelDirectApplicInterface::~IssmParallelDirectApplicInterface(){ /*{{{*/
|
---|
| 170 | +
|
---|
| 171 | + int world_rank;
|
---|
| 172 | + ISSM_MPI_Comm_rank(ISSM_MPI_COMM_WORLD,&world_rank);
|
---|
| 173 | +
|
---|
| 174 | + if(world_rank!=0){
|
---|
| 175 | +
|
---|
| 176 | + /*Wrap up: */
|
---|
| 177 | + femmodel_init->profiler->Tag(FinishCore);
|
---|
| 178 | + femmodel_init->CleanUp(); //only close file pointers on rank 0 of slave 1!
|
---|
| 179 | +
|
---|
| 180 | + /*Delete Model: */
|
---|
| 181 | + delete femmodel_init;
|
---|
| 182 | + }
|
---|
| 183 | + }
|
---|
| 184 | + /*}}}*/
|
---|
| 185 | + int IssmParallelDirectApplicInterface::derived_map_ac(const Dakota::String& ac_name){/*{{{*/
|
---|
| 186 | +
|
---|
| 187 | + FemModel* femmodel;
|
---|
| 188 | +
|
---|
| 189 | + char **responses_descriptors = NULL; //these are our! there are only numresponsedescriptors of them, not d_numresponses!!!
|
---|
| 190 | + int numresponsedescriptors;
|
---|
| 191 | + int solution_type;
|
---|
| 192 | + bool control_analysis = false;
|
---|
| 193 | + void (*solutioncore)(FemModel*) = NULL;
|
---|
| 194 | + bool nodakotacore = true;
|
---|
| 195 | +
|
---|
| 196 | + int world_rank;
|
---|
| 197 | + ISSM_MPI_Comm_rank(ISSM_MPI_COMM_WORLD,&world_rank);
|
---|
| 198 | +
|
---|
| 199 | + /*Only have slaves work!:*/
|
---|
| 200 | + if(world_rank==0)return 0;
|
---|
| 201 | +
|
---|
| 202 | + #ifdef MPI_DEBUG
|
---|
| 203 | + Cout << "eval server id" << evalServerId << " invoking " << ac_name << " within SIM::IssmParallelDirectApplicInterface." << std::endl;
|
---|
| 204 | + #endif // MPI_DEBUG
|
---|
| 205 | +
|
---|
| 206 | + int i;
|
---|
| 207 | + IssmDouble* variables=NULL;
|
---|
| 208 | + char** variable_descriptors=NULL;
|
---|
| 209 | + char* variable_descriptor=NULL;
|
---|
| 210 | + IssmDouble* responses=NULL;
|
---|
| 211 | +
|
---|
| 212 | + /*Before launching evaluation, we need to transfer the dakota inputs into Issm readable variables: */
|
---|
| 213 | +
|
---|
| 214 | + /*First, the variables: */
|
---|
| 215 | + variables=xNew<IssmDouble>(numACV);
|
---|
| 216 | + for(i=0;i<numACV;i++){
|
---|
| 217 | + variables[i]=xC[i];
|
---|
| 218 | + }
|
---|
| 219 | + /*The descriptors: */
|
---|
| 220 | + variable_descriptors=xNew<char*>(numACV);
|
---|
| 221 | + for(i=0;i<numACV;i++){
|
---|
| 222 | + std::string label=xCLabels[i];
|
---|
| 223 | + variable_descriptor=xNew<char>(strlen(label.c_str())+1);
|
---|
| 224 | + memcpy(variable_descriptor,label.c_str(),(strlen(label.c_str())+1)*sizeof(char));
|
---|
| 225 | +
|
---|
| 226 | + variable_descriptors[i]=variable_descriptor;
|
---|
| 227 | + }
|
---|
| 228 | +
|
---|
| 229 | + /*Initialize responses: */
|
---|
| 230 | + responses=xNewZeroInit<IssmDouble>(numFns);
|
---|
| 231 | +
|
---|
| 232 | + /*Make a copy of femmodel, so we start this new evaluation run for this specific sample with a brand
|
---|
| 233 | + * new copy of the model, which has not been tempered with by previous evaluation runs: */
|
---|
| 234 | +
|
---|
| 235 | + femmodel=femmodel_init->copy();
|
---|
| 236 | +
|
---|
| 237 | + /*retrieve parameters: */
|
---|
| 238 | + femmodel->parameters->FindParam(&responses_descriptors,&numresponsedescriptors,QmuResponsedescriptorsEnum);
|
---|
| 239 | + femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
|
---|
| 240 | + femmodel->parameters->FindParam(&control_analysis,InversionIscontrolEnum);
|
---|
| 241 | +
|
---|
| 242 | + /*Modify core inputs in objects contained in femmodel, to reflect the dakota variables inputs: */
|
---|
| 243 | + InputUpdateFromDakotax(femmodel,variables,variable_descriptors,numACV);
|
---|
| 244 | +
|
---|
| 245 | + /*Determine solution sequence: */
|
---|
| 246 | + if(VerboseQmu()) _printf0_("Starting " << EnumToStringx(solution_type) << " core:\n");
|
---|
| 247 | + WrapperCorePointerFromSolutionEnum(&solutioncore,femmodel->parameters,solution_type,nodakotacore);
|
---|
| 248 | +
|
---|
| 249 | + /*Run the core solution sequence: */
|
---|
| 250 | + solutioncore(femmodel);
|
---|
| 251 | +
|
---|
| 252 | + /*compute responses: */
|
---|
| 253 | + if(VerboseQmu()) _printf0_("compute dakota responses:\n");
|
---|
| 254 | + femmodel->DakotaResponsesx(responses,responses_descriptors,numresponsedescriptors,numFns);
|
---|
| 255 | +
|
---|
| 256 | + /*populate responses: */
|
---|
| 257 | + for(i=0;i<numFns;i++){
|
---|
| 258 | + fnVals[i]=responses[i];
|
---|
| 259 | + }
|
---|
| 260 | +
|
---|
| 261 | + /*Free ressources:*/
|
---|
| 262 | + xDelete<IssmDouble>(variables);
|
---|
| 263 | + for(i=0;i<numACV;i++){
|
---|
| 264 | + variable_descriptor=variable_descriptors[i];
|
---|
| 265 | + xDelete<char>(variable_descriptor);
|
---|
| 266 | + }
|
---|
| 267 | + xDelete<char*>(variable_descriptors);
|
---|
| 268 | + xDelete<IssmDouble>(responses);
|
---|
| 269 | + delete femmodel;
|
---|
| 270 | +
|
---|
| 271 | + return 0;
|
---|
| 272 | + }/*}}}*/
|
---|
| 273 | +}
|
---|
| 274 | +#endif
|
---|