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