Ignore:
Timestamp:
05/31/18 10:44:24 (7 years ago)
Author:
Mathieu Morlighem
Message:

merged trunk-jpl and trunk for revision 22820

Location:
issm/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk

  • issm/trunk/src

  • issm/trunk/src/c/classes/ExternalResults/GenericExternalResult.h

    r22758 r22822  
    179179
    180180} /*}}}*/
     181void  Transpose(void){ /*{{{*/
     182        _error_("not implemented yet");
     183} /*}}}*/
    181184char* GetResultName(void){ /*{{{*/
    182185                char* name = xNew<char>(strlen(this->result_name)+1);
     
    594597
    595598}  /*}}}*/
    596 
    597 /*Specific instantiations for IssmDouble*: */
     599template <> inline void GenericExternalResult<IssmPDouble*>::Transpose(void){/*{{{*/
     600
     601
     602        /*Perform transpose only if we have a matrix*/
     603        if(M>1 && N>1){
     604                IssmPDouble* temp=xNew<IssmPDouble>(M*N);
     605                for(int i=0;i<M;i++){
     606                        for(int j=0;j<N;j++){
     607                                temp[j*M+i] = value[i*N+j];
     608                        }
     609                }
     610                xDelete<IssmPDouble>(this->value);
     611                this->value = temp;
     612        }
     613
     614        /*Switch dimensions*/
     615        int temp2 = this->N;
     616        this->N = this->M;
     617        this->M = temp2;
     618
     619
     620
     621} /*}}}*/
     622
     623        /*Specific instantiations for IssmDouble*: */
    598624#if defined(_HAVE_ADOLC_) && !defined(_WRAPPERS_)  //We hook off this specific specialization when not running ADOLC, otherwise we get a redeclaration with the next specialization.
    599 template <> inline void GenericExternalResult<IssmDouble*>::WriteData(FILE* fid,bool io_gather){ /*{{{*/
    600 
    601         int     i;
    602         int     my_rank;
    603         int     type;
    604         int     rows,cols;
    605         char   *name    = NULL;
    606         IssmPDouble passiveDouble;
    607         IssmPDouble* passiveDoubles;
    608 
    609         /*recover my_rank:*/
    610         my_rank=IssmComm::GetRank();
    611 
    612         if(io_gather){
    613                 /*we are gathering the data on cpu 0, don't write on other cpus: */
    614                 if(my_rank) return;
    615         }
    616 
    617         /*First write enum: */
    618         int length=(strlen(this->result_name)+1)*sizeof(char);
    619         fwrite(&length,sizeof(int),1,fid);
    620         fwrite(this->result_name,length,1,fid);
    621 
    622         /*Now write time and step: */
    623         passiveDouble=reCast<IssmPDouble>(time);
    624         fwrite(&passiveDouble,sizeof(IssmPDouble),1,fid);
    625         fwrite(&step,sizeof(int),1,fid);
    626 
    627         /*writing a IssmDouble array, type is 3:*/
    628         type=3;
    629         fwrite(&type,sizeof(int),1,fid);
    630         rows=this->M;
    631         fwrite(&rows,sizeof(int),1,fid);
    632         cols=this->N;
    633         fwrite(&cols,sizeof(int),1,fid);
    634 
    635         passiveDoubles=xNew<IssmPDouble>(this->M*this->N);
    636         for (i=0;i<this->M*this->N;i++)passiveDoubles[i]=reCast<IssmPDouble>(value[i]);
    637         fwrite(passiveDoubles,cols*rows*sizeof(IssmPDouble),1,fid);
    638         xDelete<IssmPDouble>(passiveDoubles);
    639 
    640 }
    641 /*}}}*/
    642 #endif
    643 
    644 /*Specifics instantiations for Vector*/
    645 template <> inline GenericExternalResult<Vector<IssmPDouble>*>::GenericExternalResult(int in_id, int in_enum_type,Vector<IssmPDouble>* in_values, int in_M,int in_N,int in_step,IssmDouble in_time){/*{{{*/
    646         _error_("instanciation not correct");
    647 }
    648 /*}}}*/
    649 template <> inline GenericExternalResult<Vector<IssmPDouble>*>::GenericExternalResult(int in_id, int in_enum_type,Vector<IssmPDouble>* in_value,int in_step, IssmDouble in_time){ /*{{{*/
    650         id = in_id;
    651         M  = 0;
    652         N  = 0;
    653 
    654         /*Convert enum to name*/
    655         EnumToStringx(&this->result_name,in_enum_type);
    656 
    657         step = in_step;
    658         time = in_time;
    659 
    660         value = in_value;
    661 } /*}}}*/
    662 template <> inline GenericExternalResult<Vector<IssmPDouble>*>::~GenericExternalResult(){ /*{{{*/
    663         xDelete<char>(this->result_name);
    664         delete value;
    665 } /*}}}*/
    666 template <> inline void GenericExternalResult<Vector<IssmPDouble>*>::Echo(void){ /*{{{*/
    667 
    668         _printf_("GenericExternalResult<Vector<IssmPDouble>*>:\n");
    669         this->GenericEcho();
    670         this->value->Echo();
    671 
    672 } /*}}}*/
    673 template <> inline void GenericExternalResult<Vector<IssmPDouble>*>::DeepEcho(void){ /*{{{*/
    674 
    675         this->Echo();
    676 
    677 } /*}}}*/
    678 template <> inline Object* GenericExternalResult<Vector<IssmPDouble>*>::copy(void){ /*{{{*/
    679         return new GenericExternalResult<Vector<IssmPDouble>*>(this->id,StringToEnumx(this->result_name),this->value,this->step,this->time);
    680 } /*}}}*/
    681 #if defined(_HAVE_ADOLC_) && !defined(_WRAPPERS_)  //We hook off this specific specialization when not running ADOLC, otherwise we get a redeclaration with the next specialization.
    682 template <> inline void GenericExternalResult<Vector<IssmPDouble>*>::WriteData(FILE* fid,bool io_gather){ /*{{{*/
    683 
    684         char *name   = NULL;
    685         int   length,rows,cols=1;
    686 
    687         if(!io_gather){
    688                 _error_("not supported yet");
    689         }
    690 
    691         /*Serialize vector*/
    692         IssmPDouble* serialvalues = this->value->ToMPISerial();
    693         this->value->GetSize(&rows);
    694 
    695         if(IssmComm::GetRank()==0){
    696                 /*First write name: */
    697                 length=(strlen(this->result_name)+1)*sizeof(char);
     625        template <> inline void GenericExternalResult<IssmDouble*>::WriteData(FILE* fid,bool io_gather){ /*{{{*/
     626
     627                int     i;
     628                int     my_rank;
     629                int     type;
     630                int     rows,cols;
     631                char   *name    = NULL;
     632                IssmPDouble passiveDouble;
     633                IssmPDouble* passiveDoubles;
     634
     635                /*recover my_rank:*/
     636                my_rank=IssmComm::GetRank();
     637
     638                if(io_gather){
     639                        /*we are gathering the data on cpu 0, don't write on other cpus: */
     640                        if(my_rank) return;
     641                }
     642
     643                /*First write enum: */
     644                int length=(strlen(this->result_name)+1)*sizeof(char);
    698645                fwrite(&length,sizeof(int),1,fid);
    699646                fwrite(this->result_name,length,1,fid);
    700647
    701648                /*Now write time and step: */
    702                 IssmPDouble passiveDouble=reCast<IssmPDouble>(time);
     649                passiveDouble=reCast<IssmPDouble>(time);
    703650                fwrite(&passiveDouble,sizeof(IssmPDouble),1,fid);
    704651                fwrite(&step,sizeof(int),1,fid);
    705652
    706653                /*writing a IssmDouble array, type is 3:*/
    707                 int type=3;
     654                type=3;
    708655                fwrite(&type,sizeof(int),1,fid);
     656                rows=this->M;
    709657                fwrite(&rows,sizeof(int),1,fid);
     658                cols=this->N;
    710659                fwrite(&cols,sizeof(int),1,fid);
    711                 fwrite(serialvalues,cols*rows*sizeof(IssmPDouble),1,fid);
    712         }
    713 
    714         /*Clean up*/
    715         xDelete<IssmPDouble>(serialvalues);
    716 
    717 }
    718 /*}}}*/
     660
     661                passiveDoubles=xNew<IssmPDouble>(this->M*this->N);
     662                for (i=0;i<this->M*this->N;i++)passiveDoubles[i]=reCast<IssmPDouble>(value[i]);
     663                fwrite(passiveDoubles,cols*rows*sizeof(IssmPDouble),1,fid);
     664                xDelete<IssmPDouble>(passiveDoubles);
     665
     666        }
     667        /*}}}*/
    719668#endif
    720 template <> inline int GenericExternalResult<Vector<IssmPDouble>*>::ObjectEnum(void){ /*{{{*/
    721         return NoneEnum;
    722         /*???? FIXME*/
    723 } /*}}}*/
    724 
    725 /*Specifics instantiations for Vector<IssmDouble>*/
    726 template <> inline void GenericExternalResult<Vector<IssmDouble>*>::WriteData(FILE* fid,bool io_gather){ /*{{{*/
    727 
    728         int i;
    729         char *name   = NULL;
    730         int   length,rows,cols=1;
    731         IssmDouble*  serialvalues = NULL;
    732         IssmPDouble* pserialvalues = NULL;
    733 
    734         if(!io_gather){
    735                 _error_("not supported yet");
    736         }
    737 
    738         /*Serialize vector*/
    739         serialvalues = this->value->ToMPISerial();
    740         this->value->GetSize(&rows);
    741        
    742         pserialvalues=xNew<IssmPDouble>(rows);
    743         for(i=0;i<rows;i++)pserialvalues[i]=reCast<IssmPDouble>(serialvalues[i]);
    744 
    745         if(IssmComm::GetRank()==0){
    746                 /*First write name: */
    747                 length=(strlen(this->result_name)+1)*sizeof(char);
    748                 fwrite(&length,sizeof(int),1,fid);
    749                 fwrite(this->result_name,length,1,fid);
    750 
    751                 /*Now write time and step: */
    752                 IssmPDouble passiveDouble=reCast<IssmPDouble>(time);
    753                 fwrite(&passiveDouble,sizeof(IssmPDouble),1,fid);
    754                 fwrite(&step,sizeof(int),1,fid);
    755 
    756                 /*writing a IssmDouble array, type is 3:*/
    757                 int type=3;
    758                 fwrite(&type,sizeof(int),1,fid);
    759                 fwrite(&rows,sizeof(int),1,fid);
    760                 fwrite(&cols,sizeof(int),1,fid);
    761                 fwrite(pserialvalues,cols*rows*sizeof(IssmPDouble),1,fid);
    762         }
    763 
    764         /*Clean up*/
    765         xDelete<IssmPDouble>(pserialvalues);
    766         xDelete<IssmDouble>(serialvalues);
    767 
    768 }
    769 /*}}}*/
    770 template <> inline void GenericExternalResult<Vector<IssmDouble>*>::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){/*{{{*/
    771 
    772         _error_("GenericExternalResult instantiated for type Vector<IssmDouble>* called " << result_name << " not implemented yet");
    773 
    774 }  /*}}}*/
     669
     670        /*Specifics instantiations for Vector*/
     671        template <> inline GenericExternalResult<Vector<IssmPDouble>*>::GenericExternalResult(int in_id, int in_enum_type,Vector<IssmPDouble>* in_values, int in_M,int in_N,int in_step,IssmDouble in_time){/*{{{*/
     672                _error_("instanciation not correct");
     673        }
     674        /*}}}*/
     675        template <> inline GenericExternalResult<Vector<IssmPDouble>*>::GenericExternalResult(int in_id, int in_enum_type,Vector<IssmPDouble>* in_value,int in_step, IssmDouble in_time){ /*{{{*/
     676                id = in_id;
     677                M  = 0;
     678                N  = 0;
     679
     680                /*Convert enum to name*/
     681                EnumToStringx(&this->result_name,in_enum_type);
     682
     683                step = in_step;
     684                time = in_time;
     685
     686                value = in_value;
     687        } /*}}}*/
     688        template <> inline GenericExternalResult<Vector<IssmPDouble>*>::~GenericExternalResult(){ /*{{{*/
     689                xDelete<char>(this->result_name);
     690                delete value;
     691        } /*}}}*/
     692        template <> inline void GenericExternalResult<Vector<IssmPDouble>*>::Echo(void){ /*{{{*/
     693
     694                _printf_("GenericExternalResult<Vector<IssmPDouble>*>:\n");
     695                this->GenericEcho();
     696                this->value->Echo();
     697
     698        } /*}}}*/
     699        template <> inline void GenericExternalResult<Vector<IssmPDouble>*>::DeepEcho(void){ /*{{{*/
     700
     701                this->Echo();
     702
     703        } /*}}}*/
     704        template <> inline Object* GenericExternalResult<Vector<IssmPDouble>*>::copy(void){ /*{{{*/
     705                return new GenericExternalResult<Vector<IssmPDouble>*>(this->id,StringToEnumx(this->result_name),this->value,this->step,this->time);
     706        } /*}}}*/
     707#if defined(_HAVE_ADOLC_) && !defined(_WRAPPERS_)  //We hook off this specific specialization when not running ADOLC, otherwise we get a redeclaration with the next specialization.
     708        template <> inline void GenericExternalResult<Vector<IssmPDouble>*>::WriteData(FILE* fid,bool io_gather){ /*{{{*/
     709
     710                char *name   = NULL;
     711                int   length,rows,cols=1;
     712
     713                if(!io_gather){
     714                        _error_("not supported yet");
     715                }
     716
     717                /*Serialize vector*/
     718                IssmPDouble* serialvalues = this->value->ToMPISerial();
     719                this->value->GetSize(&rows);
     720
     721                if(IssmComm::GetRank()==0){
     722                        /*First write name: */
     723                        length=(strlen(this->result_name)+1)*sizeof(char);
     724                        fwrite(&length,sizeof(int),1,fid);
     725                        fwrite(this->result_name,length,1,fid);
     726
     727                        /*Now write time and step: */
     728                        IssmPDouble passiveDouble=reCast<IssmPDouble>(time);
     729                        fwrite(&passiveDouble,sizeof(IssmPDouble),1,fid);
     730                        fwrite(&step,sizeof(int),1,fid);
     731
     732                        /*writing a IssmDouble array, type is 3:*/
     733                        int type=3;
     734                        fwrite(&type,sizeof(int),1,fid);
     735                        fwrite(&rows,sizeof(int),1,fid);
     736                        fwrite(&cols,sizeof(int),1,fid);
     737                        fwrite(serialvalues,cols*rows*sizeof(IssmPDouble),1,fid);
     738                }
     739
     740                /*Clean up*/
     741                xDelete<IssmPDouble>(serialvalues);
     742
     743        }
     744        /*}}}*/
     745#endif
     746        template <> inline int GenericExternalResult<Vector<IssmPDouble>*>::ObjectEnum(void){ /*{{{*/
     747                return NoneEnum;
     748                /*???? FIXME*/
     749        } /*}}}*/
     750
     751        /*Specifics instantiations for Vector<IssmDouble>*/
     752        template <> inline void GenericExternalResult<Vector<IssmDouble>*>::WriteData(FILE* fid,bool io_gather){ /*{{{*/
     753
     754                int i;
     755                char *name   = NULL;
     756                int   length,rows,cols=1;
     757                IssmDouble*  serialvalues = NULL;
     758                IssmPDouble* pserialvalues = NULL;
     759
     760                if(!io_gather){
     761                        _error_("not supported yet");
     762                }
     763
     764                /*Serialize vector*/
     765                serialvalues = this->value->ToMPISerial();
     766                this->value->GetSize(&rows);
     767
     768                pserialvalues=xNew<IssmPDouble>(rows);
     769                for(i=0;i<rows;i++)pserialvalues[i]=reCast<IssmPDouble>(serialvalues[i]);
     770
     771                if(IssmComm::GetRank()==0){
     772                        /*First write name: */
     773                        length=(strlen(this->result_name)+1)*sizeof(char);
     774                        fwrite(&length,sizeof(int),1,fid);
     775                        fwrite(this->result_name,length,1,fid);
     776
     777                        /*Now write time and step: */
     778                        IssmPDouble passiveDouble=reCast<IssmPDouble>(time);
     779                        fwrite(&passiveDouble,sizeof(IssmPDouble),1,fid);
     780                        fwrite(&step,sizeof(int),1,fid);
     781
     782                        /*writing a IssmDouble array, type is 3:*/
     783                        int type=3;
     784                        fwrite(&type,sizeof(int),1,fid);
     785                        fwrite(&rows,sizeof(int),1,fid);
     786                        fwrite(&cols,sizeof(int),1,fid);
     787                        fwrite(pserialvalues,cols*rows*sizeof(IssmPDouble),1,fid);
     788                }
     789
     790                /*Clean up*/
     791                xDelete<IssmPDouble>(pserialvalues);
     792                xDelete<IssmDouble>(serialvalues);
     793
     794        }
     795        /*}}}*/
     796        template <> inline void GenericExternalResult<Vector<IssmDouble>*>::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){/*{{{*/
     797
     798                _error_("GenericExternalResult instantiated for type Vector<IssmDouble>* called " << result_name << " not implemented yet");
     799
     800        }  /*}}}*/
    775801
    776802#endif  /* _EXTERNAL_RESULTOBJECT_H */
Note: See TracChangeset for help on using the changeset viewer.