Changeset 13594


Ignore:
Timestamp:
10/10/12 21:21:25 (13 years ago)
Author:
Eric.Larour
Message:

CHG: more changes to switch from my_rank and num_procs to IssmComm::GetSize and IssmComm::GetRank

Location:
issm/trunk-jpl/src/c
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/Container/Elements.cpp

    r13381 r13594  
    168168        int i;
    169169       
    170         extern int my_rank;
    171         extern int num_procs;
     170        int my_rank2;
     171        int num_procs2;
    172172
    173173        Patch  *patch        = NULL;
     
    184184        int    rank;
    185185        int    minrank;
     186       
     187        /*recover my_rank2:*/
     188        my_rank2=IssmComm::GetRank();
     189        num_procs2=IssmComm::GetSize();
    186190
    187191        /*Recover parameters: */
     
    196200                /*Get rank of first cpu that has results*/
    197201                #ifdef _HAVE_MPI_
    198                 if(this->Size()) rank=my_rank;
    199                 else rank=num_procs;
     202                if(this->Size()) rank=my_rank2;
     203                else rank=num_procs2;
    200204                MPI_Allreduce (&rank,&minrank,1,MPI_INT,MPI_MIN,MPI_COMM_WORLD);
    201205                #else
    202                 minrank=my_rank;
     206                minrank=my_rank2;
    203207                #endif
    204208
    205209                /*see what the first element of this partition has in stock (this is common to all partitions)*/
    206                 if(my_rank==minrank){
     210                if(my_rank2==minrank){
    207211                        if(this->Size()==0) _error_("Cannot write results because there is no element??");
    208212                        Element* element=(Element*)this->GetObjectByOffset(0);
     
    216220                if(!numberofresults) return;
    217221                #ifdef _HAVE_MPI_
    218                 if(my_rank!=minrank){
     222                if(my_rank2!=minrank){
    219223                        resultsenums=xNew<int>(numberofresults);
    220224                        resultssizes=xNew<int>(numberofresults);
     
    245249                        /*Serialize and add to results*/
    246250                        vector_serial=vector->ToMPISerial();
    247                         if(my_rank==0){
     251                        if(my_rank2==0){
    248252                                /*No need to add this vector for all cpus*/
    249253                                #ifdef _HAVE_ADOLC_
  • issm/trunk-jpl/src/c/Container/Nodes.cpp

    r13413 r13594  
    5656void  Nodes::DistributeDofs(int analysis_type,int setenum){
    5757
    58         extern int num_procs;
    59         extern int my_rank;
     58        int num_procs2;
     59        int my_rank2;
    6060
    6161        int  i;
     
    6666        int* alltruedofs=NULL;
    6767        int  numnodes=0;
     68       
     69        /*recover my_rank2:*/
     70        my_rank2=IssmComm::GetRank();
     71        num_procs2=IssmComm::GetSize();
    6872
    6973        /*some check: */
     
    8488         * cpus by the total last dofs of the previus cpu, starting from 0.
    8589         * First: get number of dofs for each cpu*/
    86         alldofcount=xNew<int>(num_procs);
     90        alldofcount=xNew<int>(num_procs2);
    8791        #ifdef _HAVE_MPI_
    8892        MPI_Gather(&dofcount,1,MPI_INT,alldofcount,1,MPI_INT,0,MPI_COMM_WORLD);
    89         MPI_Bcast(alldofcount,num_procs,MPI_INT,0,MPI_COMM_WORLD);
     93        MPI_Bcast(alldofcount,num_procs2,MPI_INT,0,MPI_COMM_WORLD);
    9094        #else
    9195        alldofcount[0]=dofcount;
     
    9498        /* Every cpu should start its own dof count at the end of the dofcount from cpu-1*/
    9599        dofcount=0;
    96         if(my_rank!=0){
    97                 for(i=0;i<my_rank;i++){
     100        if(my_rank2!=0){
     101                for(i=0;i<my_rank2;i++){
    98102                        dofcount+=alldofcount[i];
    99103                }
     
    328332void   Nodes::Ranks(int* ranks,int analysis_type){
    329333
    330         extern int my_rank;
     334        int my_rank2;
    331335        int        sid;
     336       
     337        /*recover my_rank2:*/
     338        my_rank2=IssmComm::GetRank();
    332339
    333340        /*Go through nodes, and for each object, report it cpu: */
     
    340347                        /*Plug rank into ranks, according to sid: */
    341348                        sid=node->Sid();
    342                         ranks[sid]=my_rank;
     349                        ranks[sid]=my_rank2;
    343350                }
    344351        }
  • issm/trunk-jpl/src/c/Container/Vertices.cpp

    r13413 r13594  
    4141void  Vertices::DistributePids(int numberofobjects){
    4242
    43         extern int num_procs;
    44         extern int my_rank;
     43        int num_procs2;
     44        int my_rank2;
    4545
    4646        int  i;
     
    4949        int *truepids    = NULL;
    5050        int *alltruepids = NULL;
     51       
     52        /*recover my_rank2:*/
     53        my_rank2=IssmComm::GetRank();
     54        num_procs2=IssmComm::GetSize();
    5155
    5256        /*Go through objects, and distribute pids locally, from 0 to numberofpidsperobject*/
     
    6064         * cpus by the total last pids of the previus cpu, starting from 0.
    6165         * First: get number of pids for each cpu*/
    62         allpidcount=xNew<int>(num_procs);
     66        allpidcount=xNew<int>(num_procs2);
    6367        #ifdef _HAVE_MPI_
    6468        MPI_Gather(&pidcount,1,MPI_INT,allpidcount,1,MPI_INT,0,MPI_COMM_WORLD);
    65         MPI_Bcast(allpidcount,num_procs,MPI_INT,0,MPI_COMM_WORLD);
     69        MPI_Bcast(allpidcount,num_procs2,MPI_INT,0,MPI_COMM_WORLD);
    6670        #else
    6771        allpidcount[0]=pidcount;
     
    7074        /* Every cpu should start its own pid count at the end of the pidcount from cpu-1*/
    7175        pidcount=0;
    72         if(my_rank!=0){
    73                 for(i=0;i<my_rank;i++){
     76        if(my_rank2!=0){
     77                for(i=0;i<my_rank2;i++){
    7478                        pidcount+=allpidcount[i];
    7579                }
     
    111115
    112116        int i;
    113         extern int num_procs;
     117        int num_procs2;
    114118
    115119        int* ranks=NULL;
    116120        int* minranks=NULL;
     121       
     122        /*recover num_procs2:*/
     123        num_procs2=IssmComm::GetSize();
    117124
    118125        /*Allocate ranks: */
     
    120127        minranks=xNew<int>(numberofobjects);
    121128
    122         for(i=0;i<numberofobjects;i++)ranks[i]=num_procs; //no cpu can have rank num_procs. This is the maximum limit.
     129        for(i=0;i<numberofobjects;i++)ranks[i]=num_procs2; //no cpu can have rank num_procs. This is the maximum limit.
    123130
    124131        /*Now go through all our objects and ask them to report to who they belong (which rank): */
     
    177184void   Vertices::Ranks(int* ranks){
    178185
    179         extern int my_rank;
     186        int my_rank2;
    180187        int        sid;
     188       
     189        /*recover my_rank2:*/
     190        my_rank2=IssmComm::GetRank();
    181191
    182192        /*Go through a dataset, and for each object, report it cpu: */
     
    185195                Vertex* vertex=(Vertex*)this->GetObjectByOffset(i);
    186196                sid=vertex->Sid();
    187                 ranks[sid]=my_rank;
    188         }
    189 }
    190 /*}}}*/
     197                ranks[sid]=my_rank2;
     198        }
     199}
     200/*}}}*/
  • issm/trunk-jpl/src/c/classes/IoModel.cpp

    r13589 r13594  
    104104void  IoModel::CheckEnumSync(void){
    105105
    106         extern int my_rank;
     106        int my_rank2;
    107107        int record_enum = 0;
    108108
     109        /*recover my_rank2:*/
     110        my_rank2=IssmComm::GetRank();
     111
    109112        /*Check that some fields have been allocated*/
    110         _assert_(this->fid || my_rank);
     113        _assert_(this->fid || my_rank2);
    111114
    112115        /*Go find in the binary file, the position of the data we want to fetch: */
    113         if(my_rank==0){ //cpu 0
     116        if(my_rank2==0){ //cpu 0
    114117
    115118                /*First set FILE* position to the beginning of the file: */
     
    296299void  IoModel::FetchConstants(void){
    297300
    298         extern int my_rank;
    299         extern int num_procs;
     301        int my_rank2;
    300302       
    301303        /*record descriptions; */
     
    312314        int   string_size;
    313315
     316        /*recover my_rank2:*/
     317        my_rank2=IssmComm::GetRank();
     318
    314319        /*Check that some fields have been allocated*/
    315         _assert_(this->fid || my_rank);
     320        _assert_(this->fid || my_rank2);
    316321        _assert_(this->constants);
    317322
    318323        /*Go find in the binary file, the position of the data we want to fetch: */
    319         if(my_rank==0){ //cpu 0{{{
     324        if(my_rank2==0){ //cpu 0{{{
    320325       
    321326                /*First set FILE* position to the beginning of the file: */
     
    535540void  IoModel::FetchData(bool* pboolean,int data_enum){
    536541
    537         extern int my_rank;
    538         extern int num_procs;
     542        int my_rank2;
    539543       
    540544
     
    543547        int   code;
    544548       
     549        /*recover my_rank2:*/
     550        my_rank2=IssmComm::GetRank();
     551
     552       
    545553        /*Set file pointer to beginning of the data: */
    546554        fid=this->SetFilePointerToData(&code,NULL,data_enum);
     
    549557       
    550558        /*We have to read a boolean from disk. */
    551         if(my_rank==0){ 
     559        if(my_rank2==0){ 
    552560                if(fread(&booleanint,sizeof(int),1,fid)!=1) _error_("could not read boolean ");
    553561        }
     
    565573void  IoModel::FetchData(int* pinteger,int data_enum){
    566574
    567         extern int my_rank;
    568         extern int num_procs;
     575        int my_rank2;
    569576
    570577        /*output: */
     
    572579        int   code;
    573580       
     581        /*recover my_rank2:*/
     582        my_rank2=IssmComm::GetRank();
     583       
    574584        /*Set file pointer to beginning of the data: */
    575585        fid=this->SetFilePointerToData(&code,NULL,data_enum);
     
    578588       
    579589        /*We have to read a integer from disk. First read the dimensions of the integer, then the integer: */
    580         if(my_rank==0){ 
     590        if(my_rank2==0){ 
    581591                if(fread(&integer,sizeof(int),1,fid)!=1) _error_("could not read integer ");
    582592        }
     
    594604
    595605
    596         extern int my_rank;
    597         extern int num_procs;
     606        int my_rank2;
    598607       
    599608
     
    601610        IssmPDouble   scalar;
    602611        int      code;
     612       
     613        /*recover my_rank2:*/
     614        my_rank2=IssmComm::GetRank();
    603615
    604616        /*Set file pointer to beginning of the data: */
     
    608620       
    609621        /*We have to read a scalar from disk. First read the dimensions of the scalar, then the scalar: */
    610         if(my_rank==0){
     622        if(my_rank2==0){
    611623                if(fread(&scalar,sizeof(IssmPDouble),1,fid)!=1)_error_("could not read scalar ");
    612624        }
     
    623635void  IoModel::FetchData(char** pstring,int data_enum){
    624636
    625         extern int my_rank;
    626         extern int num_procs;
     637        int my_rank2;
    627638       
    628639
     
    631642        int   string_size;
    632643        int code=0;
     644       
     645        /*recover my_rank2:*/
     646        my_rank2=IssmComm::GetRank();
    633647
    634648        /*Set file pointer to beginning of the data: */
     
    640654       
    641655        /*We have to read a string from disk. First read the dimensions of the string, then the string: */
    642         if(my_rank==0){ 
     656        if(my_rank2==0){ 
    643657                if(fread(&string_size,sizeof(int),1,fid)!=1) _error_("could not read length of string ");
    644658        }
     
    654668
    655669                /*Read string on node 0, then broadcast: */
    656                 if(my_rank==0){ 
     670                if(my_rank2==0){ 
    657671                        if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string ");
    658672                }
     
    674688void  IoModel::FetchData(int** pmatrix,int* pM,int* pN,int data_enum){
    675689
    676         extern int my_rank;
    677         extern int num_procs;
     690        int my_rank2;
    678691        int i,j;
    679692
     
    684697        int code=0;
    685698        int vector_type=0;
    686 
     699       
     700        /*recover my_rank2:*/
     701        my_rank2=IssmComm::GetRank();
    687702
    688703        /*Set file pointer to beginning of the data: */
     
    695710        /*We have to read a matrix from disk. First read the dimensions of the matrix, then the whole matrix: */
    696711        /*numberofelements: */
    697         if(my_rank==0){ 
     712        if(my_rank2==0){ 
    698713                if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
    699714        }
     
    703718        #endif
    704719
    705         if(my_rank==0){ 
     720        if(my_rank2==0){ 
    706721                if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
    707722        }
     
    715730
    716731                /*Read matrix on node 0, then broadcast: */
    717                 if(my_rank==0){ 
     732                if(my_rank2==0){ 
    718733                        if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
    719734                }
     
    749764void  IoModel::FetchData(IssmDouble** pmatrix,int* pM,int* pN,int data_enum){
    750765
    751         extern int my_rank;
    752         extern int num_procs;
     766        int my_rank2;
    753767
    754768        /*output: */
     
    757771        int code=0;
    758772        int vector_type=0;
     773       
     774        /*recover my_rank2:*/
     775        my_rank2=IssmComm::GetRank();
    759776
    760777        /*Set file pointer to beginning of the data: */
     
    766783        /*We have to read a matrix from disk. First read the dimensions of the matrix, then the whole matrix: */
    767784        /*numberofelements: */
    768         if(my_rank==0){ 
     785        if(my_rank2==0){ 
    769786                if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
    770787        }
     
    773790        #endif
    774791
    775         if(my_rank==0){ 
     792        if(my_rank2==0){ 
    776793                if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
    777794        }
     
    785802
    786803                /*Read matrix on node 0, then broadcast: */
    787                 if(my_rank==0){ 
     804                if(my_rank2==0){ 
    788805                        if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
    789806                }
     
    814831void  IoModel::FetchData(char*** pstrings,int* pnumstrings,int data_enum){
    815832
    816         extern int my_rank;
    817         extern int num_procs;
     833        int my_rank2;
    818834       
    819835        int i;
     
    828844        int   code;
    829845       
     846        /*recover my_rank2:*/
     847        my_rank2=IssmComm::GetRank();
     848
    830849        /*Set file pointer to beginning of the data: */
    831850        fid=this->SetFilePointerToData(&code,NULL,data_enum);
     
    834853       
    835854        /*We have to read a bunch of strings from disk. First read the number of strings, and allocate: */
    836         if(my_rank==0){ 
     855        if(my_rank2==0){ 
    837856                if(fread(&numstrings,sizeof(int),1,fid)!=1) _error_("could not read length of string array");
    838857        }
     
    849868                for(i=0;i<numstrings;i++){
    850869                       
    851                         if(my_rank==0){ 
     870                        if(my_rank2==0){ 
    852871                                if(fread(&string_size,sizeof(int),1,fid)!=1) _error_("could not read length of string ");
    853872                        }
     
    860879
    861880                                /*Read string on node 0, then broadcast: */
    862                                 if(my_rank==0){ 
     881                                if(my_rank2==0){ 
    863882                                        if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string ");
    864883                                }
     
    886905        int i;
    887906
    888         extern int my_rank;
    889         extern int num_procs;
     907        int my_rank2;
    890908
    891909        /*output: */
     
    900918        int     code;
    901919       
     920        /*recover my_rank2:*/
     921        my_rank2=IssmComm::GetRank();
     922
    902923        /*Set file pointer to beginning of the data: */
    903924        fid=this->SetFilePointerToData(&code,NULL,data_enum);
     
    905926       
    906927        /*Now fetch: */
    907         if(my_rank==0){ 
     928        if(my_rank2==0){ 
    908929                if(fread(&numrecords,sizeof(int),1,fid)!=1) _error_("could not read number of records in matrix array ");
    909930        }
     
    928949                for(i=0;i<numrecords;i++){
    929950
    930                         if(my_rank==0){ 
     951                        if(my_rank2==0){ 
    931952                                if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows in " << i << "th matrix of matrix array");
    932953                        }
     
    935956                        #endif
    936957
    937                         if(my_rank==0){ 
     958                        if(my_rank2==0){ 
    938959                                if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns in " << i << "th matrix of matrix array");
    939960                        }
     
    947968
    948969                                /*Read matrix on node 0, then broadcast: */
    949                                 if(my_rank==0){ 
     970                                if(my_rank2==0){ 
    950971                                        if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
    951972                                }
     
    976997void  IoModel::FetchData(Option** poption,int index){
    977998
    978         extern int my_rank;
    979         extern int num_procs;
    980 
    981999        /*output: */
    9821000        int     code;
    9831001        char   *name        = NULL;
    984 
     1002       
    9851003        /*First get option name*/
    9861004        this->FetchData(&name,index);
     
    12611279void IoModel::LastIndex(int *pindex){
    12621280
    1263         extern int my_rank;
     1281        int my_rank2;
    12641282        int        lastindex,index;
    12651283        int        record_length;
     1284       
     1285        /*recover my_rank2:*/
     1286        my_rank2=IssmComm::GetRank();
    12661287
    12671288        /*Go find in the binary file, the position of the data we want to fetch: */
    1268         if(my_rank==0){
     1289        if(my_rank2==0){
    12691290
    12701291                /*First set FILE* position to the beginning of the file: */
     
    12971318FILE* IoModel::SetFilePointerToData(int* pcode,int* pvector_type, int data_enum){
    12981319
    1299         extern int my_rank;
    1300         extern int num_procs;
     1320        int my_rank2;
    13011321
    13021322        int found         = 0;
     
    13061326        int vector_type   = 0; //nodal or elementary
    13071327
     1328        /*recover my_rank2:*/
     1329        my_rank2=IssmComm::GetRank();
     1330
    13081331        /*Go find in the binary file, the position of the data we want to fetch: */
    1309         if(my_rank==0){
     1332        if(my_rank2==0){
    13101333
    13111334                /*First set FILE* position to the beginning of the file: */
  • issm/trunk-jpl/src/c/shared/Exceptions/Exceptions.cpp

    r13363 r13594  
    2929
    3030ErrorException::~ErrorException() throw(){
    31         extern int num_procs;
     31       
     32        int num_procs2;
     33       
     34        /*recover num_procs2:*/
     35        num_procs2=IssmComm::GetSize();
     36
    3237        /*We want the report only for matlab modules, otherwise we get twice the report
    3338         * We assume that if num_procs==1, it is a module (FIXME)*/
    34         if(num_procs==1) this->Report();
     39        if(num_procs2==1) this->Report();
    3540}
    3641
     
    4045
    4146void ErrorException::Report() const{
    42         extern int my_rank;
    43         extern int num_procs;
     47       
     48        int my_rank2;
     49        int num_procs2;
     50       
     51        /*recover my_rank2 and num_procs2:*/
     52        my_rank2=IssmComm::GetRank();
     53        num_procs2=IssmComm::GetSize();
     54
     55
    4456
    4557        if (function_name=="" || file_line==0){ //WINDOWS
     
    4759        }
    4860        else{
    49                 if(num_procs==1){
     61                if(num_procs2==1){
    5062                        _printLine_("\n??? Error using ==> " << file_name.c_str() << ":" << file_line);
    5163                        _printLine_(function_name.c_str() << " error message: " << what() << "\n");
    5264                }
    5365                else{
    54                         _printLine_("\n[" << my_rank << "] ??? Error using ==> " << file_name.c_str() << ":" << file_line);
    55                         _printLine_("[" << my_rank << "] " << function_name.c_str() << " error message: " << what() << "\n");
     66                        _printLine_("\n[" << my_rank2<< "] ??? Error using ==> " << file_name.c_str() << ":" << file_line);
     67                        _printLine_("[" << my_rank2 << "] " << function_name.c_str() << " error message: " << what() << "\n");
    5668                }
    5769        }
Note: See TracChangeset for help on using the changeset viewer.