Changeset 13609


Ignore:
Timestamp:
10/10/12 23:53:10 (12 years ago)
Author:
Eric.Larour
Message:

CHG: final transition from extern my_rank and num_procs to IssmComm static class object.

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

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/src/c/classes/FemModel.cpp

    r13589 r13609  
    8484        FILE       *petscoptionsfid = NULL;
    8585        FILE       *output_fid = NULL;
    86         extern int  my_rank;
     86        int         my_rank2;
     87       
     88        /*recover my_rank2:*/
     89        my_rank2=IssmComm::GetRank();
    8790
    8891        /*Open input file on cpu 0: */
    89         if(my_rank==0) IOMODEL = pfopen(inputfilename ,"rb");
     92        if(my_rank2==0) IOMODEL = pfopen(inputfilename ,"rb");
    9093
    9194        /*Initialize internal data: */
     
    127130       
    128131        /*Close input file descriptors: */
    129         if(my_rank==0) pfclose(IOMODEL,inputfilename);
     132        if(my_rank2==0) pfclose(IOMODEL,inputfilename);
    130133
    131134        /*Open output file once for all and add output file name and file descriptor to parameters*/
  • TabularUnified issm/trunk-jpl/src/c/classes/Patch.cpp

    r13607 r13609  
    111111        int         i;
    112112        int         count;
    113         extern int  my_rank;
    114         extern int  num_procs;
     113        int         my_rank2;
     114        int         num_procs2;
    115115        int         total_numrows;
    116116        int         node_numrows;
     
    119119        MPI_Status  status;
    120120        #endif
     121       
     122        /*recover my_rank2:*/
     123        my_rank2=IssmComm::GetRank();
     124        num_procs2=IssmComm::GetSize();
    121125
    122126        /*First, figure out total number of rows combining all the cpus: */
     
    132136
    133137        /*Now, allocate buffer to holds all the values, on node 0: */
    134         if(my_rank==0)total_values=xNew<IssmDouble>(this->numcols*total_numrows);
     138        if(my_rank2==0)total_values=xNew<IssmDouble>(this->numcols*total_numrows);
    135139
    136140        /*Start by copying node 0 values onto total_values: */
    137         if(my_rank==0){
     141        if(my_rank2==0){
    138142                count=0;
    139143                xMemCpy<IssmDouble>(total_values+count,this->values,this->numcols*this->numrows);
     
    143147        /*Now, ask other nodes to send their values: */
    144148        #ifdef _HAVE_MPI_
    145         for (i=1;i<num_procs;i++){
    146                 if (my_rank==i){
     149        for (i=1;i<num_procs2;i++){
     150                if (my_rank2==i){
    147151                        MPI_Send(&this->numrows,1,MPI_INT,0,1,IssmComm::GetComm());   
    148152                        if (this->numrows)MPI_Send(this->values,this->numrows*this->numcols,MPI_DOUBLE,0,1,IssmComm::GetComm());
    149153                }
    150                 if (my_rank==0){
     154                if (my_rank2==0){
    151155                        MPI_Recv(&node_numrows,1,MPI_INT,i,1,IssmComm::GetComm(),&status);
    152156                        if (node_numrows)MPI_Recv(total_values+count,node_numrows*this->numcols,MPI_DOUBLE,i,1,IssmComm::GetComm(),&status);
     
    158162        /*Now, node 0 has total_values, of size total_numrows*this->numcols. Update the fields in the patch, to reflect this new
    159163         * reality. For other cpus, no point in keeping their data anymore: */
    160         if(my_rank==0){
     164        if(my_rank2==0){
    161165                this->numrows=total_numrows;
    162166                xDelete<IssmDouble>(this->values);
  • TabularUnified issm/trunk-jpl/src/c/classes/classes.h

    r13589 r13609  
    55#ifndef ALL_CLASSES_H_
    66#define ALL_CLASSES_H_
     7
    78
    89/*Objects derived classes, which are used in our containers: */
  • TabularUnified issm/trunk-jpl/src/c/classes/objects/ExternalResults/GenericExternalResult.h

    r13414 r13609  
    2020#include "../../../io/io.h"
    2121#include "../../../EnumDefinitions/EnumDefinitions.h"
     22#include "../../../classes/IssmComm.h"
    2223#include "./ExternalResult.h"
    2324/*}}}*/
     
    109110void WriteData(FILE* fid,bool io_gather){ /*{{{*/
    110111                       
    111         extern  int my_rank;
     112        int     my_rank2;
    112113        int     type;
    113114        int     size;
    114115        IssmPDouble  passiveDouble;
    115116       
     117        /*recover my_rank2:*/
     118        my_rank2=IssmComm::GetRank();
     119
    116120        /*return if now on cpu 0: */
    117         if(my_rank)return;
     121        if(my_rank2)return;
    118122
    119123        /*use generic part, same for all ResultTypes: */
     
    201205template <> inline void GenericExternalResult<char*>::WriteData(FILE* fid,bool io_gather){ /*{{{*/
    202206
    203         extern  int my_rank;
     207        int     my_rank2;
    204208        int     type;
    205209        int     length;
     210       
     211        /*recover my_rank2:*/
     212        my_rank2=IssmComm::GetRank();
    206213
    207214        /*return if now on cpu 0: */
    208         if(my_rank)return;
     215        if(my_rank2)return;
    209216
    210217        /*use generic part, same for all ResultTypes: */
     
    280287template <> inline void GenericExternalResult<IssmPDouble*>::WriteData(FILE* fid,bool io_gather){ /*{{{*/
    281288       
    282         extern  int my_rank;
     289        int     my_rank2;
    283290        int     length;
    284291        int     type;
    285292        int     rows,cols;
    286293        char   *name    = NULL;
    287         extern  int my_rank;
    288294        IssmPDouble passiveDouble;
     295       
     296        /*recover my_rank2:*/
     297        my_rank2=IssmComm::GetRank();
    289298
    290299        if(io_gather){
    291300                /*we are gathering the data on cpu 0, don't write on other cpus: */
    292                 if(my_rank) return;
     301                if(my_rank2) return;
    293302        }
    294303
  • TabularUnified issm/trunk-jpl/src/c/include/globals.h

    r13589 r13609  
    99#include "./types.h"
    1010#include "../classes/IssmComm.h"
     11
    1112COMM IssmComm::comm;
    1213
    13 int my_rank=0;
    14 int num_procs=1;
     14//int my_rank=0;
     15//int num_procs=1;
    1516
    1617#endif
  • TabularUnified issm/trunk-jpl/src/c/io/PrintfFunction.cpp

    r13412 r13609  
    1515        char *buffer = NULL;
    1616        int   n,size = 100;
    17         int         string_size;
    18         extern int  my_rank;
     17        int   string_size;
     18        int   my_rank2;
    1919        //variable list of arguments
    2020        va_list args;
     21       
     22        /*recover my_rank2:*/
     23        my_rank2=IssmComm::GetRank();
    2124
    2225        while(true){
     
    4346
    4447        /*Ok, if we are running in parallel, get node 0 to print*/
    45         if(my_rank==0)_printString_(buffer);
     48        if(my_rank2==0)_printString_(buffer);
    4649
    4750        /*Clean up and return*/
     
    5053}
    5154int PrintfFunction(const string & message){
    52         extern int  my_rank;
    53         if(my_rank==0){
     55        int  my_rank2;
     56       
     57        /*recover my_rank2:*/
     58        my_rank2=IssmComm::GetRank();
     59
     60        if(my_rank2==0){
    5461                printf("%s\n",message.c_str());
    5562        }
     
    5764}
    5865int PrintfFunction2(const string & message){
    59         extern int  my_rank;
    60         if(my_rank==0){
     66        int  my_rank2;
     67
     68        /*recover my_rank2:*/
     69        my_rank2=IssmComm::GetRank();
     70
     71        if(my_rank2==0){
    6172                printf("%s",message.c_str());
    6273        }
  • TabularUnified issm/trunk-jpl/src/c/matlab/io/PrintfFunction.cpp

    r13412 r13609  
    1818        int   n,size = 100;
    1919        int         string_size;
    20         extern int  my_rank;
     20        int  my_rank2;
     21       
     22        /*recover my_rank2:*/
     23        my_rank2=IssmComm::GetRank();
    2124
    2225        //variable list of arguments
     
    5053
    5154        /*Ok, if we are running in parallel, get node 0 to print*/
    52         if(my_rank==0)_printString_(buffer);
     55        if(my_rank2==0)_printString_(buffer);
    5356
    5457        /*Clean up and return*/
  • TabularUnified issm/trunk-jpl/src/c/modules/OutputResultsx/OutputResultsx.cpp

    r13325 r13609  
    1818void OutputResultsx(Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,Results* results){
    1919
    20         extern int  my_rank;
     20        int         my_rank2;
    2121        FILE       *fid                     = NULL;
    2222        char       *outputfilename          = NULL;
     
    2929        /*retrieve parameters: */
    3030        parameters->FindParam(&dakota_analysis,QmuIsdakotaEnum);
     31       
     32        /*recover my_rank2:*/
     33        my_rank2=IssmComm::GetRank();
    3134
    3235        if(dakota_analysis){
     
    4245        /*Results do not include the type of solution being run . In parallel, we output results to a filename,
    4346         *therefore, we need to include the solutiontype into the filename: */
    44         if(my_rank==0){
     47        if(my_rank2==0){
    4548                parameters->FindParam(&solutiontype,SolutionTypeEnum);
    4649                EnumToStringx(&solutiontypestring,solutiontype);
     
    6063                if(io_gather){
    6164                        /*Just open the file for output on cpu 0. We are gathering the data on cpu 0 from all other cpus: */
    62                         if(my_rank==0) fid=pfopen(outputfilename ,"wb");
     65                        if(my_rank2==0) fid=pfopen(outputfilename ,"wb");
    6366                }
    6467                else{
    6568                        /*We are opening different  files for output on all cpus. Append the  rank to the filename, and open: */
    6669                        parameters->FindParam(&fid,OutputFilePointerEnum);
    67                         sprintf(cpu_outputfilename,"%s.%i",outputfilename,my_rank);
     70                        sprintf(cpu_outputfilename,"%s.%i",outputfilename,my_rank2);
    6871                        fid=pfopen(cpu_outputfilename ,"wb");
    6972                }
     
    8487          if((step==1) && (time==0)){
    8588          if(io_gather){
    86           if(my_rank==0) pfclose(fid,outputfilename);
     89          if(my_rank2==0) pfclose(fid,outputfilename);
    8790          }
    8891          else pfclose(fid,cpu_outputfilename);
  • TabularUnified issm/trunk-jpl/src/c/solutions/dakota_core.cpp

    r13540 r13609  
    5757        #ifdef _HAVE_DAKOTA_ //only works if dakota library has been compiled in.
    5858       
    59         extern int         my_rank;
     59        int                my_rank2;
    6060        char*              dakota_input_file  = NULL;
    6161        char*              dakota_output_file = NULL;
     
    6969        femmodel->parameters->FindParam(&dakota_output_file,QmuOutNameEnum);
    7070        femmodel->parameters->FindParam(&dakota_error_file,QmuErrNameEnum);
     71       
     72        /*recover my_rank2:*/
     73        my_rank2=IssmComm::GetRank();
    7174
    72         if(my_rank==0){
     75        if(my_rank2==0){
    7376       
    7477                // Instantiate/initialize the parallel library and problem description
  • TabularUnified issm/trunk-jpl/src/c/solutions/issm.cpp

    r13589 r13609  
    1616
    1717        /*Hack for now: */
    18         MPI_Comm_rank(comm_init,&my_rank);
    19         MPI_Comm_size(comm_init,&num_procs);
     18        //MPI_Comm_rank(comm_init,&my_rank);
     19        //MPI_Comm_size(comm_init,&num_procs);
    2020
    2121        /*Initialize femmodel from arguments provided command line: */
  • TabularUnified issm/trunk-jpl/src/c/solutions/kriging.cpp

    r13554 r13609  
    88void ProcessArguments2(char** pbinfilename,char** poutbinfilename,char** plockfilename,char** prootpath,int argc,char **argv);
    99void ProcessInputfile(IssmDouble **px,IssmDouble **py,IssmDouble **pdata,int *pnobs,IssmDouble **px_interp,IssmDouble **py_interp,int *pninterp,Options **poptions,FILE* fid);
     10
     11int my_rank;
     12int num_procs;
    1013
    1114int main(int argc,char **argv){
     
    2124        char *outbinfilename = NULL;
    2225        char *rootpath       = NULL;
     26
     27        MPI_Comm comm;
     28        extern int my_rank;
     29        extern int num_procs;
    2330
    2431        /*Input*/
     
    3946
    4047        /*Initialize environment (MPI, PETSC, MUMPS, etc ...)*/
    41         EnvironmentInit(argc,argv);
     48        comm=EnvironmentInit(argc,argv);
     49
     50        MPI_Comm_size(comm,&num_procs);
     51        MPI_Comm_rank(comm,&my_rank);
    4252
    4353        /*First process inputs*/
Note: See TracChangeset for help on using the changeset viewer.