Index: ../trunk-jpl/src/c/Makefile.am =================================================================== --- ../trunk-jpl/src/c/Makefile.am (revision 19651) +++ ../trunk-jpl/src/c/Makefile.am (revision 19652) @@ -263,7 +263,7 @@ #DAKOTA sources {{{ if DAKOTA issm_sources += ./classes/Dakota/IssmDirectApplicInterface.h\ - ./classes/Dakota/IssmParallelDirectApplicInterface.h\ + ./classes/Dakota/IssmParallelDirectApplicInterface.cpp\ ./modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp\ ./modules/InputUpdateFromVectorDakotax/InputUpdateFromVectorDakotax.cpp\ ./modules/InputUpdateFromMatrixDakotax/InputUpdateFromMatrixDakotax.cpp\ Index: ../trunk-jpl/src/c/classes/Dakota/IssmParallelDirectApplicInterface.h =================================================================== --- ../trunk-jpl/src/c/classes/Dakota/IssmParallelDirectApplicInterface.h (revision 19651) +++ ../trunk-jpl/src/c/classes/Dakota/IssmParallelDirectApplicInterface.h (revision 19652) @@ -28,107 +28,23 @@ #endif /*}}}*/ -#if defined(_HAVE_DAKOTA_) && _DAKOTA_MAJOR_ >= 6 -/*Dakota include files: {{{*/ +#if !defined(_WRAPPERS_) && defined(_HAVE_DAKOTA_) && _DAKOTA_MAJOR_ >= 6 + #include -/*}}}*/ +class FemModel; namespace SIM { class IssmParallelDirectApplicInterface: public Dakota::DirectApplicInterface{ + private: + FemModel* femmodel_init; public: - /*these fields are used by core solutions: */ - void *femmodel; - - /*Constructors/Destructors{{{*/ - IssmParallelDirectApplicInterface(const Dakota::ProblemDescDB& problem_db, const MPI_Comm& analysis_comm, void* in_femmodel):Dakota::DirectApplicInterface(problem_db){ - - #ifdef MPI_DEBUG - // For testing purposes, output size/rank of the incoming analysis_comm - int rank, size; - MPI_Comm_rank(analysis_comm, &rank); - MPI_Comm_size(analysis_comm, &size); - Cout << "In SIM::ParallelDirectApplicInterface ctor, rank = " << rank - << " size = " << size << std::endl; - #endif // MPI_DEBUG - - femmodel = in_femmodel; - } - ~IssmParallelDirectApplicInterface(){ - } - /*}}}*/ - + IssmParallelDirectApplicInterface(const Dakota::ProblemDescDB& problem_db, const MPI_Comm& evaluation_comm, int argc, char** argv); + ~IssmParallelDirectApplicInterface(); protected: - /// execute an analysis code portion of a direct evaluation invocation - int derived_map_ac(const Dakota::String& driver){/*{{{*/ - - #ifdef MPI_DEBUG - Cout << "analysis server " << analysisServerId << " invoking " << ac_name - << " within SIM::ParallelDirectApplicInterface." << std::endl; - #endif // MPI_DEBUG - - int i; - IssmDouble* variables=NULL; - char** variable_descriptors=NULL; - char* variable_descriptor=NULL; - IssmDouble* responses=NULL; - - /*Before launching analysis, we need to transfer the dakota inputs into Issm - *readable variables: */ - - /*First, the variables: */ - variables=xNew(numACV); - for(i=0;i(numACV); - for(i=0;i(strlen(label.c_str())+1); - memcpy(variable_descriptor,label.c_str(),(strlen(label.c_str())+1)*sizeof(char)); - - variable_descriptors[i]=variable_descriptor; - } - - /*Initialize responses: */ - responses=xNewZeroInit(numFns); - - /*run core solution: */ - //DakotaSpawnCore(responses,numFns, variables,variable_descriptors,numACV,femmodel); - - /*populate responses: */ - for(i=0;i(variables); - for(i=0;i(variable_descriptor); - } - xDelete(variable_descriptors); - xDelete(responses); - - return 0; - }/*}}}*/ - - /// no-op hides base error; job batching occurs within wait_local_evaluations() - //void derived_map_asynch(const Dakota::ParamResponsePair& pair){}; - - /// evaluate the batch of jobs contained in prp_queue - //void wait_local_evaluations(Dakota::PRPQueue& prp_queue); - - /// invokes wait_local_evaluations() (no special nowait support) - //void test_local_evaluations(Dakota::PRPQueue& prp_queue) { wait_local_evaluations(prp_queue); }; - - /// no-op hides default run-time error checks at DirectApplicInterface level - //void set_communicators_checks(int max_eval_concurrency){}; - - private: + int derived_map_ac(const Dakota::String& ac_name); }; } /*}}}*/ Index: ../trunk-jpl/src/c/classes/Dakota/IssmParallelDirectApplicInterface.cpp =================================================================== --- ../trunk-jpl/src/c/classes/Dakota/IssmParallelDirectApplicInterface.cpp (revision 0) +++ ../trunk-jpl/src/c/classes/Dakota/IssmParallelDirectApplicInterface.cpp (revision 19652) @@ -0,0 +1,136 @@ +/*!\file: see IssmParallelDirectApplicInterface.h for documentation. */ + +/*Issm Configuration: {{{*/ +#ifdef HAVE_CONFIG_H +#include +#else +#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" +#endif +/*}}}*/ + +#if !defined(_WRAPPERS_) && defined(_HAVE_DAKOTA_) && _DAKOTA_MAJOR_ >= 6 + +#include "../classes.h" +#include "../../cores/cores.h" +#include "../../modules/modules.h" + +namespace SIM { + IssmParallelDirectApplicInterface::IssmParallelDirectApplicInterface(const Dakota::ProblemDescDB& problem_db, const MPI_Comm& evaluation_comm, int argc, char** argv) :Dakota::DirectApplicInterface(problem_db){ /*{{{*/ + + int world_rank; + ISSM_MPI_Comm_rank(ISSM_MPI_COMM_WORLD,&world_rank); + + /*Build an femmodel if you are a slave, using the corresponding communicator:*/ + if(world_rank!=0){ + femmodel_init= new FemModel(argc,argv,evaluation_comm); + femmodel_init->profiler->Tag(StartCore); + } + + } + /*}}}*/ + IssmParallelDirectApplicInterface::~IssmParallelDirectApplicInterface(){ /*{{{*/ + + int world_rank; + ISSM_MPI_Comm_rank(ISSM_MPI_COMM_WORLD,&world_rank); + + if(world_rank!=0){ + + /*Wrap up: */ + femmodel_init->profiler->Tag(FinishCore); + femmodel_init->CleanUp(); //only close file pointers on rank 0 of slave 1! + + /*Delete Model: */ + delete femmodel_init; + } + } + /*}}}*/ + int IssmParallelDirectApplicInterface::derived_map_ac(const Dakota::String& ac_name){/*{{{*/ + + FemModel* femmodel; + + char **responses_descriptors = NULL; //these are our! there are only numresponsedescriptors of them, not d_numresponses!!! + int numresponsedescriptors; + int solution_type; + bool control_analysis = false; + void (*solutioncore)(FemModel*) = NULL; + bool nodakotacore = true; + + int world_rank; + ISSM_MPI_Comm_rank(ISSM_MPI_COMM_WORLD,&world_rank); + + /*Only have slaves work!:*/ + if(world_rank==0)return 0; + + #ifdef MPI_DEBUG + Cout << "eval server id" << evalServerId << " invoking " << ac_name << " within SIM::IssmParallelDirectApplicInterface." << std::endl; + #endif // MPI_DEBUG + + int i; + IssmDouble* variables=NULL; + char** variable_descriptors=NULL; + char* variable_descriptor=NULL; + IssmDouble* responses=NULL; + + /*Before launching evaluation, we need to transfer the dakota inputs into Issm readable variables: */ + + /*First, the variables: */ + variables=xNew(numACV); + for(i=0;i(numACV); + for(i=0;i(strlen(label.c_str())+1); + memcpy(variable_descriptor,label.c_str(),(strlen(label.c_str())+1)*sizeof(char)); + + variable_descriptors[i]=variable_descriptor; + } + + /*Initialize responses: */ + responses=xNewZeroInit(numFns); + + /*Make a copy of femmodel, so we start this new evaluation run for this specific sample with a brand + * new copy of the model, which has not been tempered with by previous evaluation runs: */ + + femmodel=femmodel_init->copy(); + + /*retrieve parameters: */ + femmodel->parameters->FindParam(&responses_descriptors,&numresponsedescriptors,QmuResponsedescriptorsEnum); + femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum); + femmodel->parameters->FindParam(&control_analysis,InversionIscontrolEnum); + + /*Modify core inputs in objects contained in femmodel, to reflect the dakota variables inputs: */ + InputUpdateFromDakotax(femmodel,variables,variable_descriptors,numACV); + + /*Determine solution sequence: */ + if(VerboseQmu()) _printf0_("Starting " << EnumToStringx(solution_type) << " core:\n"); + WrapperCorePointerFromSolutionEnum(&solutioncore,femmodel->parameters,solution_type,nodakotacore); + + /*Run the core solution sequence: */ + solutioncore(femmodel); + + /*compute responses: */ + if(VerboseQmu()) _printf0_("compute dakota responses:\n"); + femmodel->DakotaResponsesx(responses,responses_descriptors,numresponsedescriptors,numFns); + + /*populate responses: */ + for(i=0;i(variables); + for(i=0;i(variable_descriptor); + } + xDelete(variable_descriptors); + xDelete(responses); + delete femmodel; + + return 0; + }/*}}}*/ +} +#endif