Changeset 23643


Ignore:
Timestamp:
01/17/19 15:04:23 (6 years ago)
Author:
Mathieu Morlighem
Message:

CHG: speed up output by not broadcasting to all cpus if only cpu 0 writes the output

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

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/ExternalResults/GenericExternalResult.h

    r23242 r23643  
    719719                }
    720720
    721                 /*Serialize vector*/
    722                 IssmPDouble* serialvalues = this->value->ToMPISerial();
    723                 this->value->GetSize(&rows);
     721                /*Serialize vector on cpu0*/
     722                IssmPDouble* serialvalues = this->value->ToMPISerial0();
    724723
    725724                if(IssmComm::GetRank()==0){
     725                        this->value->GetSize(&rows);
     726
    726727                        /*First write name: */
    727728                        length=(strlen(this->result_name)+1)*sizeof(char);
     
    770771                }
    771772
    772                 /*Serialize vector*/
    773                 serialvalues = this->value->ToMPISerial();
    774                 this->value->GetSize(&rows);
    775 
    776                 pserialvalues=xNew<IssmPDouble>(rows);
    777                 for(i=0;i<rows;i++)pserialvalues[i]=reCast<IssmPDouble>(serialvalues[i]);
     773                /*Serialize vector only on cpu0*/
     774                serialvalues = this->value->ToMPISerial0();
    778775
    779776                if(IssmComm::GetRank()==0){
     777
     778                        /*Make it passive*/
     779                        this->value->GetSize(&rows);
     780                        pserialvalues=xNew<IssmPDouble>(rows);
     781                        for(i=0;i<rows;i++)pserialvalues[i]=reCast<IssmPDouble>(serialvalues[i]);
     782
    780783                        /*First write name: */
    781784                        length=(strlen(this->result_name)+1)*sizeof(char);
     
    794797                        fwrite(&cols,sizeof(int),1,fid);
    795798                        fwrite(pserialvalues,cols*rows*sizeof(IssmPDouble),1,fid);
     799
     800                        /*Clean up*/
     801                        xDelete<IssmPDouble>(pserialvalues);
    796802                }
    797803
    798804                /*Clean up*/
    799                 xDelete<IssmPDouble>(pserialvalues);
    800805                xDelete<IssmDouble>(serialvalues);
    801 
    802806        }
    803807        /*}}}*/
  • issm/trunk-jpl/src/c/toolkits/issm/IssmAbsVec.h

    r23604 r23643  
    4343                virtual void AYPX(IssmAbsVec* X, doubletype a)=0;
    4444                virtual doubletype* ToMPISerial(void)=0;
     45                virtual doubletype* ToMPISerial0(void)=0;
    4546                virtual void Shift(doubletype shift)=0;
    4647                virtual void Copy(IssmAbsVec* to)=0;
  • issm/trunk-jpl/src/c/toolkits/issm/IssmMpiVec.h

    r23605 r23643  
    460460                        /*return: */
    461461                        return buffer;
     462
     463                }
     464                /*}}}*/
     465                doubletype* ToMPISerial0(void){/*{{{*/
     466
     467                        /*FIXME: Should not broadcast to every cpu*/
     468                        return this->ToMPISerial();
    462469
    463470                }
  • issm/trunk-jpl/src/c/toolkits/issm/IssmSeqVec.h

    r23606 r23643  
    218218                }
    219219                /*}}}*/
     220                doubletype* ToMPISerial0(void){/*{{{*/
     221
     222                        return this->ToMPISerial();
     223
     224                }
     225                /*}}}*/
    220226                void Shift(doubletype shift){/*{{{*/
    221227
  • issm/trunk-jpl/src/c/toolkits/issm/IssmVec.h

    r23604 r23643  
    183183                }
    184184                /*}}}*/
     185                doubletype* ToMPISerial0(void){/*{{{*/
     186                        return vector->ToMPISerial0();
     187                }
     188                /*}}}*/
    185189                void Shift(doubletype shift){/*{{{*/
    186190                        vector->Shift(shift);
  • issm/trunk-jpl/src/c/toolkits/objects/Vector.h

    r23604 r23643  
    291291                }
    292292                /*}}}*/
     293                doubletype* ToMPISerial0(void){/*{{{*/
     294
     295                        doubletype* vec_serial=NULL;
     296
     297                        _assert_(this);
     298                        if(type==PetscVecType){
     299                                #ifdef _HAVE_PETSC_
     300                                vec_serial=this->pvector->ToMPISerial0();
     301                                #endif
     302                        }
     303                        else vec_serial=this->ivector->ToMPISerial0();
     304
     305                        return vec_serial;
     306
     307                }
     308                /*}}}*/
    293309                void Shift(doubletype shift){_assert_(this);/*{{{*/
    294310
  • issm/trunk-jpl/src/c/toolkits/petsc/objects/PetscVec.cpp

    r23610 r23643  
    191191
    192192        IssmDouble* vec_serial=NULL;
    193         VecToMPISerial(&vec_serial, this->vector,IssmComm::GetComm());
     193        VecToMPISerial(&vec_serial, this->vector,IssmComm::GetComm(),true);
     194        return vec_serial;
     195
     196}
     197/*}}}*/
     198IssmDouble* PetscVec::ToMPISerial0(void){/*{{{*/
     199
     200        IssmDouble* vec_serial=NULL;
     201        VecToMPISerial(&vec_serial, this->vector,IssmComm::GetComm(),false);
    194202        return vec_serial;
    195203
  • issm/trunk-jpl/src/c/toolkits/petsc/objects/PetscVec.h

    r23604 r23643  
    5151                void        AYPX(PetscVec* X, IssmDouble a);
    5252                IssmDouble* ToMPISerial(void);
     53                IssmDouble* ToMPISerial0(void);
    5354                void        Shift(IssmDouble shift);
    5455                void        Copy(PetscVec* to);
  • issm/trunk-jpl/src/c/toolkits/petsc/patches/VecToMPISerial.cpp

    r16102 r23643  
    1212#include "../../../shared/shared.h"
    1313
    14 int VecToMPISerial(double** pgathered_vector, Vec vector,ISSM_MPI_Comm comm){
     14int VecToMPISerial(double** pgathered_vector, Vec vector,ISSM_MPI_Comm comm,bool broadcast){
    1515
    1616        int i;
     
    4545
    4646        /*Allocate gathered vector on all nodes .*/
    47         gathered_vector=xNew<double>(vector_size);
     47        if(broadcast || my_rank==0){
     48                gathered_vector=xNew<double>(vector_size);
     49        }
    4850
    4951        /*Allocate local vectors*/
     
    8385        }
    8486
    85         /*Now, broadcast gathered_vector from node 0 to other nodes: */
    86         ISSM_MPI_Bcast(gathered_vector,vector_size,ISSM_MPI_PDOUBLE,0,comm);
     87        if(broadcast){
     88                /*Now, broadcast gathered_vector from node 0 to other nodes: */
     89                ISSM_MPI_Bcast(gathered_vector,vector_size,ISSM_MPI_PDOUBLE,0,comm);
     90        }
    8791
    8892        /*Assign output pointers: */
  • issm/trunk-jpl/src/c/toolkits/petsc/patches/petscpatches.h

    r23602 r23643  
    2222Mat NewMat(int M,int N,int connectivity,int numberofdofspernode, ISSM_MPI_Comm comm);
    2323
    24 int VecToMPISerial(double** pgathered_vector, Vec vector,ISSM_MPI_Comm comm);
     24int VecToMPISerial(double** pgathered_vector, Vec vector,ISSM_MPI_Comm comm,bool broadcast=true);
    2525void MatFree(Mat* pmat);
    2626void ISFree(IS* pis);
Note: See TracChangeset for help on using the changeset viewer.