Changeset 13589


Ignore:
Timestamp:
10/10/12 20:48:24 (12 years ago)
Author:
Eric.Larour
Message:

CHG: starting transition to model runs where the MPI_Comm is independent
of MPI_COMM_WORLD. To do so, we design a static class IssmComm, which
encapsulate the communicator for the FemModel. FemModel can set its communicator
using a SetStaticComm method.
Adapted EnvironmentInit to return the comm accordingly.
Also put PrintBanner inside the FemModel constructor, as it needs to know about the
communicator to print the banner.

Location:
issm/trunk-jpl/src/c
Files:
2 added
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/Makefile.am

    r13557 r13589  
    6868                                        ./classes/objects/Vertex.cpp\
    6969                                        ./classes/objects/AdolcEdf.h\
     70                                        ./classes/IssmComm.h\
     71                                        ./classes/IssmComm.cpp\
    7072                                        ./classes/Hook.h\
    7173                                        ./classes/Hook.cpp\
     
    343345                                        ./modules/InputConvergencex/InputConvergencex.cpp\
    344346                                        ./modules/InputConvergencex/InputConvergencex.h\
    345                                         ./solutions/PrintBanner.cpp\
    346347                                        ./solutions/convergence.cpp\
    347348                                        ./solutions/ProcessArguments.cpp\
  • issm/trunk-jpl/src/c/classes/FemModel.cpp

    r13574 r13589  
    2121/*Object constructors and destructor*/
    2222/*FUNCTION FemModel::FemModel(int argc,char** argv){{{*/
    23 FemModel::FemModel(int argc,char** argv){
     23FemModel::FemModel(int argc,char** argv,COMM incomm){
    2424
    2525        /*configuration: */
     
    3434        char *petscfilename  = NULL;
    3535        char *rootpath       = NULL;
     36
     37        /*First things first, store the communicator, and set it as a global variable: */
     38        this->comm=incomm;
     39        this->SetStaticComm();
     40
     41        /*Print starting banner:*/
     42        this->PrintBanner();
    3643
    3744        /*Start profiler: */
     
    264271}
    265272/*}}}*/
     273/*FUNCTION FemModel::SetStaticComm {{{*/
     274void FemModel::SetStaticComm(void){
     275
     276        /*This routine sets the global communicator variable hidden inside the IssmComm
     277         *class: */
     278        IssmComm::SetComm(this->comm);
     279
     280}
     281/*}}}*/
     282/*FUNCTION FemModel::PrintBanner {{{*/
     283void FemModel::PrintBanner(void){
     284
     285        _pprintLine_("");
     286        _pprintLine_("Ice Sheet System Model (" << PACKAGE_NAME << ") version " << PACKAGE_VERSION);
     287        _pprintLine_("(website: " << PACKAGE_URL << " contact: " << PACKAGE_BUGREPORT << ")");
     288        _pprintLine_("");
     289
     290}
     291/*}}}*/
    266292
    267293/*Numerics: */
  • issm/trunk-jpl/src/c/classes/FemModel.h

    r13554 r13589  
    4444                Parameters  *parameters;           //one set of parameters, independent of the analysis_type
    4545                Results     *results;              //results that cannot be fit into the elements
     46                COMM        comm;                  //communicator for this particular model
    4647
    4748                /*constructors, destructors: */
    48                 FemModel(int argc,char** argv);
     49                FemModel(int argc,char** argv,COMM comm_init);
    4950                FemModel(char* rootpath, char* inputfilename, char* outputfilename, char* petscfilename, char* lockfilename, const int solution_type,const int* analyses,const int nummodels);
    5051                ~FemModel();
     
    5556                void Solve(void);
    5657                void OutputResults(void);
     58                void SetStaticComm();
     59                void PrintBanner(void);
    5760
    5861                /*Fem: */
  • issm/trunk-jpl/src/c/classes/IoModel.cpp

    r13576 r13589  
    13401340                }
    13411341        }
    1342 #ifdef _HAVE_MPI_
     1342        #ifdef _HAVE_MPI_
    13431343        MPI_Bcast(&found,1,MPI_INT,0,MPI_COMM_WORLD);
    13441344        if(!found)_error_("could not find data with name " << EnumToStringx(data_enum) << " in binary file");
    1345 #endif
     1345        #endif
    13461346
    13471347        /*Broadcast code and vector type: */
    1348 #ifdef _HAVE_MPI_
     1348        #ifdef _HAVE_MPI_
    13491349        MPI_Bcast(&record_code,1,MPI_INT,0,MPI_COMM_WORLD);
    13501350        MPI_Bcast(&vector_type,1,MPI_INT,0,MPI_COMM_WORLD);
    13511351        if(record_code==5) MPI_Bcast(&vector_type,1,MPI_INT,0,MPI_COMM_WORLD);
    1352 #endif
     1352        #endif
    13531353
    13541354        /*Assign output pointers:*/
  • issm/trunk-jpl/src/c/classes/classes.h

    r13530 r13589  
    3131#include "./OptPars.h"
    3232#include "./AdolcEdf.h"
     33#include "./IssmComm.h"
    3334
    3435#endif
  • issm/trunk-jpl/src/c/include/globals.h

    r11942 r13589  
    66#define GLOBALS_H_
    77
     8
     9#include "./types.h"
     10#include "../classes/IssmComm.h"
     11COMM IssmComm::comm;
     12
    813int my_rank=0;
    914int num_procs=1;
  • issm/trunk-jpl/src/c/include/types.h

    r13414 r13589  
    4040#endif
    4141
     42/*Define communicator: */
     43#ifdef _HAVE_MPI_
     44#include "mpi.h"
     45typedef MPI_Comm COMM;
     46#else
     47typedef int COMM;
     48#endif
     49
    4250#endif //ifndef _TYPES_H_
  • issm/trunk-jpl/src/c/solutions/EnvironmentInit.cpp

    r13534 r13589  
    1010#include "../toolkits/toolkits.h"
    1111
    12 void EnvironmentInit(int argc,char** argv){
    13        
    14         extern int my_rank;
    15         extern int num_procs;
     12COMM EnvironmentInit(int argc,char** argv){
    1613
    1714        /*Initialize environments: Petsc, MPI, etc...: */
     
    1916        int ierr=PetscInitialize(&argc,&argv,(char*)0,""); 
    2017        if(ierr) _error_("Could not initialize Petsc");
     18        return MPI_COMM_WORLD;
    2119        #else
    2220        #ifdef _HAVE_MPI_
    2321        MPI_Init(&argc,&argv);
     22        return MPI_COMM_WORLD;
     23        #else
     24        return 1; //return bogus number for comm, which does not exist anyway.
    2425        #endif
    2526        #endif
    2627       
    27         /*Size and rank: */
    28         #ifdef _HAVE_MPI_
    29         MPI_Comm_rank(MPI_COMM_WORLD,&my_rank); 
    30         MPI_Comm_size(MPI_COMM_WORLD,&num_procs);
    31         #endif
     28
    3229}
  • issm/trunk-jpl/src/c/solutions/issm.cpp

    r13554 r13589  
    77int main(int argc,char **argv){
    88
    9         /*Print starting banner:*/
    10         PrintBanner();
     9        COMM comm_init;
    1110
    1211        /*Initialize exception trapping: */
     
    1413
    1514        /*Initialize environment (MPI, PETSC, MUMPS, etc ...)*/
    16         EnvironmentInit(argc,argv);
    17                
     15        comm_init=EnvironmentInit(argc,argv);
     16
     17        /*Hack for now: */
     18        MPI_Comm_rank(comm_init,&my_rank);
     19        MPI_Comm_size(comm_init,&num_procs);
     20
    1821        /*Initialize femmodel from arguments provided command line: */
    19         FemModel *femmodel = new FemModel(argc,argv);
     22        FemModel *femmodel = new FemModel(argc,argv,comm_init);
    2023
    2124        /*Solve: */
  • issm/trunk-jpl/src/c/solutions/solutions.h

    r13554 r13589  
    88#include "../classes/objects/objects.h"
    99#include "../io/io.h"
     10#include "../toolkits/toolkits.h"
    1011
    1112struct OptArgs;
     
    4748void controlrestart(FemModel* femmodel,IssmDouble* J);
    4849void ResetBoundaryConditions(FemModel* femmodel, int analysis_type);
    49 void EnvironmentInit(int argc,char** argv);
     50COMM EnvironmentInit(int argc,char** argv);
    5051void EnvironmentFinalize(void);
    5152int  DakotaSpawnCore(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, void* femmodel,int counter);
Note: See TracChangeset for help on using the changeset viewer.