source: issm/oecreview/Archive/19101-20495/ISSM-20134-20135.diff

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

CHG: done with Archive/19101-20495

File size: 5.3 KB
  • ../trunk-jpl/src/c/main/issm_slr.cpp

     
     1/*!\file:  issm_slr.cpp
     2 * \brief: ISSM SLR main program.
     3 */
     4
     5#include "./issm.h"
     6
     7int main(int argc,char **argv){
     8
     9        /*diverse:*/
     10        int    nummodels;
     11        int*   commsizes=NULL;
     12        int*   rankzeros=NULL;
     13        char** dirnames=NULL;
     14        char** modelnames=NULL;
     15        int    modelid;
     16        int    earthid;
     17        int    my_rank;
     18        int    count=0;
     19        ISSM_MPI_Comm worldcomm;
     20        ISSM_MPI_Comm modelcomm;
     21        ISSM_MPI_Comm toearthcomm;
     22        ISSM_MPI_Comm* fromicecomms=NULL;
     23
     24        /*Initialize exception trapping: */
     25        ExceptionTrapBegin();
     26
     27        /*Initialize environment (MPI, PETSC, MUMPS, etc ...)*/
     28        worldcomm=EnvironmentInit(argc,argv);
     29       
     30        /*What is my rank?:*/
     31        ISSM_MPI_Comm_rank(worldcomm,&my_rank);
     32
     33        /*How many models are we going to run (along with description and number of dedicated cores):{{{*/
     34        nummodels=(int) strtol(argv[4], (char **)NULL, 10);
     35        commsizes=xNew<int>(nummodels);
     36        dirnames=xNew<char*>(nummodels);
     37        modelnames=xNew<char*>(nummodels);
     38        rankzeros=xNew<int>(nummodels);
     39        for(int i=0;i<nummodels;i++){
     40                char* string=NULL;
     41               
     42                string=xNew<char>(strlen(argv[5+3*i])+1);
     43                xMemCpy<char>(string,argv[5+3*i],strlen(argv[5+3*i])+1);
     44                dirnames[i]=string;
     45               
     46                string=xNew<char>(strlen(argv[5+3*i+1])+1);
     47                xMemCpy<char>(string,argv[5+3*i+1],strlen(argv[5+3*i+1])+1);
     48                modelnames[i]=string;
     49
     50                commsizes[i]=(int) strtol(argv[5+3*i+2], (char **)NULL, 10);
     51        }
     52
     53        /*Figure out which model each cpu will belong to: */
     54        count=0;
     55        for(int i=0;i<nummodels;i++){
     56                if(my_rank>=count && my_rank<(count+commsizes[i])){
     57                        modelid=i;
     58                        break;
     59                }
     60                count+=commsizes[i];
     61        }
     62        /*Buil array of who is rank 0 of their own group:*/
     63        count=0;
     64        for(int i=0;i<nummodels;i++){
     65                rankzeros[i]=count;
     66                count+=commsizes[i];
     67        }
     68        /*}}}*/
     69
     70        /*Split world into sub-communicators for each and every model:*/
     71        MPI_Comm_split(worldcomm,modelid, my_rank, &modelcomm);
     72
     73        /*Build inter communicators:*/
     74        earthid=nummodels-1; //last model to be provided in the argument list if the earth model.
     75        if(modelid==earthid){
     76                fromicecomms=xNew<ISSM_MPI_Comm>(nummodels-1);
     77                for(int i=0;i<earthid;i++){
     78                        MPI_Intercomm_create( modelcomm, 0, worldcomm, rankzeros[i], i, fromicecomms+i); //communicate from local erth comm 9rank 0) to ice comm (rank 0) using modelid tag.
     79                }
     80        }
     81        else{
     82                MPI_Intercomm_create( modelcomm, 0, worldcomm, rankzeros[earthid], modelid, &toearthcomm); //communicate from local ice comm (rank 0) to earth comm (rank 0) using modelid tag.
     83        }
     84
     85        /*Supply specific argc and argv for each sub-communicator (corresponding to each  model specificatiions):{{{*/
     86        char** arguments=xNew<char*>(4);
     87        arguments[0]=xNew<char>(strlen(argv[0])+1); xMemCpy<char>(arguments[0],argv[0],strlen(argv[0])+1); //executable name
     88        arguments[1]=xNew<char>(strlen(argv[1])+1); xMemCpy<char>(arguments[1],argv[1],strlen(argv[1])+1); //solution name
     89        arguments[2]=xNew<char>(strlen(argv[5+3*modelid])+1); xMemCpy<char>(arguments[2],argv[5+3*modelid],strlen(argv[5+3*modelid])+1); //directory name
     90        arguments[3]=xNew<char>(strlen(argv[5+3*modelid+1])+1); xMemCpy<char>(arguments[3],argv[5+3*modelid+1],strlen(argv[5+3*modelid+1])+1); //model name
     91        /*}}}*/
     92
     93        /*Initialize femmodel from arguments provided command line: */
     94        FemModel *femmodel = new FemModel(4,arguments,modelcomm);
     95       
     96        /*Now that the models are initialized, keep communicator information in the parameters datasets of each model: */
     97        femmodel->parameters->AddObject(new IntParam(WorldCommEnum,worldcomm));
     98        femmodel->parameters->AddObject(new IntParam(NumModelsEnum,nummodels));
     99        femmodel->parameters->AddObject(new IntParam(ModelIdEnum,modelid));
     100        femmodel->parameters->AddObject(new IntParam(EarthIdEnum,earthid));
     101        if(modelid==earthid)femmodel->parameters->AddObject(new IntVecParam(IcecapToEarthCommEnum,fromicecomms,nummodels-1));
     102        else femmodel->parameters->AddObject(new IntParam(IcecapToEarthCommEnum,toearthcomm));
     103
     104        /*Solve: */
     105        femmodel->Solve();
     106
     107        /*Output results: */
     108        OutputResultsx(femmodel);
     109
     110        /*Wrap up: */
     111        femmodel->CleanUp();
     112
     113        /*Delete Model: */
     114        delete femmodel;
     115
     116        /*Finalize environment:*/
     117        EnvironmentFinalize();
     118
     119        /*Finalize exception trapping: */
     120        ExceptionTrapEnd();
     121
     122        /*Free ressources:*/
     123        xDelete<int>(commsizes);
     124        for(int i=0;i<nummodels;i++){
     125                char* string=NULL;
     126                string=dirnames[i]; xDelete<char>(string);
     127                string=modelnames[i]; xDelete<char>(string);
     128        }
     129        xDelete<char*>(dirnames);
     130        xDelete<char*>(modelnames);
     131
     132        /*Return unix success: */
     133        return 0;
     134}
  • ../trunk-jpl/src/c/Makefile.am

     
    648648#Executable {{{
    649649if ANDROID
    650650if ANDROIDEXE
    651 bin_PROGRAMS = issm
     651bin_PROGRAMS = issm  issm_slr
    652652else
    653653bin_PROGRAMS =
    654654endif
     
    656656if JAVASCRIPT
    657657bin_PROGRAMS =
    658658else
    659 bin_PROGRAMS = issm
     659bin_PROGRAMS = issm  issm_slr
    660660endif
    661661endif
    662662
     
    676676issm_SOURCES = main/issm.cpp
    677677issm_CXXFLAGS= -fPIC
    678678
     679issm_slr_SOURCES = main/issm_slr.cpp
     680issm_slr_CXXFLAGS= -fPIC
     681
     682
    679683if KRIGING
    680684bin_PROGRAMS += kriging
    681685kriging_SOURCES = main/kriging.cpp
Note: See TracBrowser for help on using the repository browser.