source: issm/oecreview/Archive/19101-20495/ISSM-19651-19652.diff

Last change on this file was 20498, checked in by Mathieu Morlighem, 9 years ago

CHG: done with Archive/19101-20495

File size: 9.6 KB
  • ../trunk-jpl/src/c/Makefile.am

     
    263263#DAKOTA sources  {{{
    264264if DAKOTA
    265265issm_sources +=       ./classes/Dakota/IssmDirectApplicInterface.h\
    266                                           ./classes/Dakota/IssmParallelDirectApplicInterface.h\
     266                                          ./classes/Dakota/IssmParallelDirectApplicInterface.cpp\
    267267                                          ./modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp\
    268268                                          ./modules/InputUpdateFromVectorDakotax/InputUpdateFromVectorDakotax.cpp\
    269269                                          ./modules/InputUpdateFromMatrixDakotax/InputUpdateFromMatrixDakotax.cpp\
  • ../trunk-jpl/src/c/classes/Dakota/IssmParallelDirectApplicInterface.h

     
    2828#endif
    2929/*}}}*/
    3030
    31 #if defined(_HAVE_DAKOTA_) && _DAKOTA_MAJOR_ >= 6
    3231
    33 /*Dakota include files: {{{*/
     32#if !defined(_WRAPPERS_) && defined(_HAVE_DAKOTA_) && _DAKOTA_MAJOR_ >= 6
     33
    3434#include <DirectApplicInterface.hpp>
    35 /*}}}*/
     35class FemModel;
    3636
    3737namespace SIM {
    3838        class IssmParallelDirectApplicInterface: public Dakota::DirectApplicInterface{
    3939     
     40                private:
     41                        FemModel* femmodel_init;
    4042                public:
    41                         /*these fields are used by core solutions: */
    42                         void *femmodel;
    43                        
    44                         /*Constructors/Destructors{{{*/
    45                         IssmParallelDirectApplicInterface(const Dakota::ProblemDescDB& problem_db, const MPI_Comm& analysis_comm, void* in_femmodel):Dakota::DirectApplicInterface(problem_db){
    46 
    47                                 #ifdef MPI_DEBUG
    48                                   // For testing purposes, output size/rank of the incoming analysis_comm
    49                                   int rank, size;
    50                                   MPI_Comm_rank(analysis_comm, &rank);
    51                                   MPI_Comm_size(analysis_comm, &size);
    52                                   Cout << "In SIM::ParallelDirectApplicInterface ctor, rank = " << rank
    53                                            << " size = " << size << std::endl;
    54                                  #endif // MPI_DEBUG
    55 
    56                                 femmodel = in_femmodel;
    57                         }
    58                         ~IssmParallelDirectApplicInterface(){
    59                         }
    60                         /*}}}*/
    61                
     43                        IssmParallelDirectApplicInterface(const Dakota::ProblemDescDB& problem_db, const MPI_Comm& evaluation_comm, int argc, char** argv);
     44                        ~IssmParallelDirectApplicInterface();
    6245                protected:
    63                        
    6446                        /// execute an analysis code portion of a direct evaluation invocation
    65                         int derived_map_ac(const Dakota::String& driver){/*{{{*/
    66 
    67                                 #ifdef MPI_DEBUG
    68                                         Cout << "analysis server " << analysisServerId << " invoking " << ac_name
    69                                                  << " within SIM::ParallelDirectApplicInterface." << std::endl;
    70                                 #endif // MPI_DEBUG
    71 
    72                                 int i;
    73                                 IssmDouble* variables=NULL;
    74                                 char** variable_descriptors=NULL;
    75                                 char*  variable_descriptor=NULL;
    76                                 IssmDouble* responses=NULL;
    77 
    78                                 /*Before launching analysis, we need to transfer the dakota inputs into Issm
    79                                  *readable variables: */
    80 
    81                                 /*First, the variables: */
    82                                 variables=xNew<IssmDouble>(numACV);
    83                                 for(i=0;i<numACV;i++){
    84                                         variables[i]=xC[i];
    85                                 }
    86                                 /*The descriptors: */
    87                                 variable_descriptors=xNew<char*>(numACV);
    88                                 for(i=0;i<numACV;i++){
    89                                         std::string label=xCLabels[i];
    90                                         variable_descriptor=xNew<char>(strlen(label.c_str())+1);
    91                                         memcpy(variable_descriptor,label.c_str(),(strlen(label.c_str())+1)*sizeof(char));
    92 
    93                                         variable_descriptors[i]=variable_descriptor;
    94                                 }
    95 
    96                                 /*Initialize responses: */
    97                                 responses=xNewZeroInit<IssmDouble>(numFns);
    98 
    99                                 /*run core solution: */
    100                                 //DakotaSpawnCore(responses,numFns, variables,variable_descriptors,numACV,femmodel);
    101 
    102                                 /*populate responses: */
    103                                 for(i=0;i<numFns;i++){
    104                                         fnVals[i]=responses[i];
    105                                 }
    106 
    107                                 /*Free ressources:*/
    108                                 xDelete<IssmDouble>(variables);
    109                                 for(i=0;i<numACV;i++){
    110                                         variable_descriptor=variable_descriptors[i];
    111                                         xDelete<char>(variable_descriptor);
    112                                 }
    113                                 xDelete<char*>(variable_descriptors);
    114                                 xDelete<IssmDouble>(responses);
    115 
    116                                 return 0;
    117                         }/*}}}*/
    118 
    119                         /// no-op hides base error; job batching occurs within wait_local_evaluations()
    120                         //void derived_map_asynch(const Dakota::ParamResponsePair& pair){};
    121 
    122                         /// evaluate the batch of jobs contained in prp_queue
    123                         //void wait_local_evaluations(Dakota::PRPQueue& prp_queue);
    124 
    125                         /// invokes wait_local_evaluations() (no special nowait support)
    126                         //void test_local_evaluations(Dakota::PRPQueue& prp_queue) { wait_local_evaluations(prp_queue); };
    127 
    128                         /// no-op hides default run-time error checks at DirectApplicInterface level
    129                         //void set_communicators_checks(int max_eval_concurrency){};
    130 
    131                 private:
     47                        int derived_map_ac(const Dakota::String& ac_name);
    13248        };
    13349}
    13450/*}}}*/
  • ../trunk-jpl/src/c/classes/Dakota/IssmParallelDirectApplicInterface.cpp

     
     1/*!\file:  see IssmParallelDirectApplicInterface.h for documentation.  */
     2
     3/*Issm Configuration: {{{*/
     4#ifdef HAVE_CONFIG_H
     5#include <config.h>
     6#else
     7#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
     8#endif
     9/*}}}*/
     10
     11#if !defined(_WRAPPERS_) && defined(_HAVE_DAKOTA_) && _DAKOTA_MAJOR_ >= 6
     12
     13#include "../classes.h"
     14#include "../../cores/cores.h"
     15#include "../../modules/modules.h"
     16
     17namespace SIM {
     18        IssmParallelDirectApplicInterface::IssmParallelDirectApplicInterface(const Dakota::ProblemDescDB& problem_db, const MPI_Comm& evaluation_comm, int argc, char** argv) :Dakota::DirectApplicInterface(problem_db){ /*{{{*/
     19
     20                int world_rank;
     21                ISSM_MPI_Comm_rank(ISSM_MPI_COMM_WORLD,&world_rank);
     22               
     23                /*Build an femmodel if you are a slave, using the corresponding communicator:*/
     24                if(world_rank!=0){
     25                        femmodel_init= new FemModel(argc,argv,evaluation_comm);
     26                        femmodel_init->profiler->Tag(StartCore);
     27                }
     28
     29        }
     30        /*}}}*/
     31        IssmParallelDirectApplicInterface::~IssmParallelDirectApplicInterface(){ /*{{{*/
     32
     33                int world_rank;
     34                ISSM_MPI_Comm_rank(ISSM_MPI_COMM_WORLD,&world_rank);
     35               
     36                if(world_rank!=0){
     37
     38                        /*Wrap up: */
     39                        femmodel_init->profiler->Tag(FinishCore);
     40                        femmodel_init->CleanUp(); //only close file pointers on rank 0 of slave 1!
     41
     42                        /*Delete Model: */
     43                        delete femmodel_init;
     44                }
     45        }
     46        /*}}}*/
     47                        int IssmParallelDirectApplicInterface::derived_map_ac(const Dakota::String& ac_name){/*{{{*/
     48
     49                                FemModel* femmodel;
     50                               
     51                                char     **responses_descriptors    = NULL;      //these are our! there are only numresponsedescriptors of them, not d_numresponses!!!
     52                                int        numresponsedescriptors;
     53                                int        solution_type;
     54                                bool       control_analysis         = false;
     55                                void     (*solutioncore)(FemModel*) = NULL;
     56                                bool       nodakotacore             = true;
     57
     58                                int world_rank;
     59                                ISSM_MPI_Comm_rank(ISSM_MPI_COMM_WORLD,&world_rank);
     60
     61                                /*Only have slaves work!:*/
     62                                if(world_rank==0)return 0;
     63
     64                                #ifdef MPI_DEBUG
     65                                Cout << "eval server id" << evalServerId << " invoking " << ac_name << " within SIM::IssmParallelDirectApplicInterface." << std::endl;
     66                                #endif // MPI_DEBUG
     67
     68                                int i;
     69                                IssmDouble* variables=NULL;
     70                                char** variable_descriptors=NULL;
     71                                char*  variable_descriptor=NULL;
     72                                IssmDouble* responses=NULL;
     73
     74                                /*Before launching evaluation, we need to transfer the dakota inputs into Issm readable variables: */
     75
     76                                /*First, the variables: */
     77                                variables=xNew<IssmDouble>(numACV);
     78                                for(i=0;i<numACV;i++){
     79                                        variables[i]=xC[i];
     80                                }
     81                                /*The descriptors: */
     82                                variable_descriptors=xNew<char*>(numACV);
     83                                for(i=0;i<numACV;i++){
     84                                        std::string label=xCLabels[i];
     85                                        variable_descriptor=xNew<char>(strlen(label.c_str())+1);
     86                                        memcpy(variable_descriptor,label.c_str(),(strlen(label.c_str())+1)*sizeof(char));
     87
     88                                        variable_descriptors[i]=variable_descriptor;
     89                                }
     90
     91                                /*Initialize responses: */
     92                                responses=xNewZeroInit<IssmDouble>(numFns);
     93
     94                                /*Make a copy of femmodel, so we start this new evaluation run for this specific sample with a brand
     95                                 * new copy of the model, which has not been tempered with by previous evaluation runs: */
     96
     97                                femmodel=femmodel_init->copy();
     98
     99                                /*retrieve parameters: */
     100                                femmodel->parameters->FindParam(&responses_descriptors,&numresponsedescriptors,QmuResponsedescriptorsEnum);
     101                                femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
     102                                femmodel->parameters->FindParam(&control_analysis,InversionIscontrolEnum);
     103
     104                                /*Modify core inputs in objects contained in femmodel, to reflect the dakota variables inputs: */
     105                                InputUpdateFromDakotax(femmodel,variables,variable_descriptors,numACV);
     106
     107                                /*Determine solution sequence: */
     108                                if(VerboseQmu()) _printf0_("Starting " << EnumToStringx(solution_type) << " core:\n");
     109                                WrapperCorePointerFromSolutionEnum(&solutioncore,femmodel->parameters,solution_type,nodakotacore);
     110
     111                                /*Run the core solution sequence: */
     112                                solutioncore(femmodel);
     113
     114                                /*compute responses: */
     115                                if(VerboseQmu()) _printf0_("compute dakota responses:\n");
     116                                femmodel->DakotaResponsesx(responses,responses_descriptors,numresponsedescriptors,numFns);
     117
     118                                /*populate responses: */
     119                                for(i=0;i<numFns;i++){
     120                                        fnVals[i]=responses[i];
     121                                }
     122
     123                                /*Free ressources:*/
     124                                xDelete<IssmDouble>(variables);
     125                                for(i=0;i<numACV;i++){
     126                                        variable_descriptor=variable_descriptors[i];
     127                                        xDelete<char>(variable_descriptor);
     128                                }
     129                                xDelete<char*>(variable_descriptors);
     130                                xDelete<IssmDouble>(responses);
     131                                delete femmodel;
     132
     133                                return 0;
     134                        }/*}}}*/
     135}
     136#endif
Note: See TracBrowser for help on using the repository browser.