Changeset 659


Ignore:
Timestamp:
05/31/09 00:20:31 (16 years ago)
Author:
Eric.Larour
Message:

Finished Dakota responses in parallel

Location:
issm/trunk/src
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/DataSet/DataSet.cpp

    r586 r659  
    317317}
    318318
     319int   DataSet::FindResult(void* pvalue, char* name){
     320
     321        /*Go through a dataset, and find a Result* object
     322         *which field name is "name" : */
     323       
     324        vector<Object*>::iterator object;
     325        Result* result=NULL;
     326
     327        int found=0;
     328
     329        for ( object=objects.begin() ; object < objects.end(); object++ ){
     330
     331                /*Find param type objects: */
     332                if((*object)->Enum()==ResultEnum()){
     333
     334                        /*Ok, this object is a result, recover it and ask which name it has: */
     335                        result=(Result*)(*object);
     336
     337                        if (strcmp(result->GetFieldName(),name)==0){
     338                                /*Ok, this is the one! Recover the value of this result: */
     339                                double** field=NULL;
     340                                field=(double**)pvalue; //not very safe, but hey!
     341                                result->GetField(field);
     342                                found=1;
     343                                break;
     344                        }
     345                }
     346        }
     347        return found;
     348}
     349
     350
    319351Object*   DataSet::FindParamObject(char* name){
    320352
  • issm/trunk/src/c/DataSet/DataSet.h

    r586 r659  
    8181                int   DeleteObject(Object* object);
    8282                void  ComputePressure(Vec p_g);
     83                int   FindResult(void* pvalue, char* name);
    8384
    8485};
  • issm/trunk/src/c/parallel/DakotaResponses.cpp

    r643 r659  
    1414#undef __FUNCT__
    1515#define __FUNCT__ "DakotaResponses"
    16 void DakotaResponses(double* responses,char** responses_descriptors,int numresponses,DataSet* results,int analysis_type,int sub_analysis_type){
     16void DakotaResponses(double* responses,char** responses_descriptors,int numresponses,FemModel* femmodels,DataSet* results,int analysis_type,int sub_analysis_type){
    1717
    18         int i;
     18        int i,j;
     19        int found=0;
    1920        char* response_descriptor=NULL;
     21        int numberofnodes;
     22        FemModel* fem=NULL;
     23        extern int my_rank;
     24
     25        /*recover first model: */
     26        fem=femmodels;
     27
     28        /*some data needed across the responses: */
     29        found=fem->parameters->FindParam((void*)&numberofnodes,"numberofnodes");
     30        if(!found)throw ErrorException(__FUNCT__," could not find numberofnodes in fem model");
     31
    2032
    2133        for(i=0;i<numresponses;i++){
     
    2537                //'min_vx' 'max_vx' 'max_abs_vx' 'min_vy' 'max_vy' 'max_abs_vy' 'min_vel' 'max_vel'
    2638
    27                 if(strcmp(response_descriptor,"min_vel")){
     39                if(strcmp(response_descriptor,"min_vel")==0){
     40                        double* vel=NULL;
     41                        double min_vel=0;
     42               
     43                        found=results->FindResult((void*)&vel,"vel");
     44                        if(!found)throw ErrorException(__FUNCT__," could not find vel to compute min_vel");
    2845
     46                        min_vel=vel[0];
     47                        for(j=1;j<numberofnodes;j++){
     48                                if (vel[j]<min_vel)min_vel=vel[j];
     49                        }
    2950
     51                        if(my_rank==0)responses[i]=min_vel;
     52                       
     53                }
     54                else if(strcmp(response_descriptor,"max_vel")==0){
     55                        double* vel=NULL;
     56                        double max_vel=0;
     57
     58                        found=results->FindResult((void*)&vel,"vel");
     59                        if(!found)throw ErrorException(__FUNCT__," could not find vel to compute max_vel");
     60
     61                        max_vel=vel[0];
     62                        for(j=1;j<numberofnodes;j++){
     63                                if (vel[j]>max_vel)max_vel=vel[j];
     64                        }
     65                        if(my_rank==0)responses[i]=max_vel;
     66                }
     67                else if(strcmp(response_descriptor,"min_vx")==0){
     68                        double* vx=NULL;
     69                        double min_vx=0;
     70                       
     71                        found=results->FindResult((void*)&vx,"vx");
     72                        if(!found)throw ErrorException(__FUNCT__," could not find vx to compute min_vx");
     73
     74                        min_vx=vx[0];
     75                        for(j=1;j<numberofnodes;j++){
     76                                if (vx[j]<min_vx)min_vx=vx[j];
     77                        }
     78                        if(my_rank==0)responses[i]=min_vx;
     79                }
     80                else if(strcmp(response_descriptor,"max_vx")==0){
     81                        double* vx=NULL;
     82                        double max_vx=0;
     83                       
     84                        found=results->FindResult((void*)&vx,"vx");
     85                        if(!found)throw ErrorException(__FUNCT__," could not find vx to compute max_vx");
     86
     87                        max_vx=vx[0];
     88                        for(j=1;j<numberofnodes;j++){
     89                                if (vx[j]>max_vx)max_vx=vx[j];
     90                        }
     91                        if(my_rank==0)responses[i]=max_vx;
     92                }
     93                else if(strcmp(response_descriptor,"max_abs_vx")==0){
     94                        double* vx=NULL;
     95                        double max_abs_vx=0;
     96                       
     97                        found=results->FindResult((void*)&vx,"vx");
     98                        if(!found)throw ErrorException(__FUNCT__," could not find vx to compute max_abs_vx");
     99
     100                        max_abs_vx=fabs(vx[0]);
     101                        for(j=1;j<numberofnodes;j++){
     102                                if (fabs(vx[j])>max_abs_vx)max_abs_vx=fabs(vx[j]);
     103                        }
     104                        if(my_rank==0)responses[i]=max_abs_vx;
     105                }
     106                else if(strcmp(response_descriptor,"min_vy")==0){
     107                        double* vy=NULL;
     108                        double min_vy=0;
     109                       
     110                        found=results->FindResult((void*)&vy,"vy");
     111                        if(!found)throw ErrorException(__FUNCT__," could not find vy to compute min_vy");
     112
     113                        min_vy=vy[0];
     114                        for(j=1;j<numberofnodes;j++){
     115                                if (vy[j]<min_vy)min_vy=vy[j];
     116                        }
     117                        if(my_rank==0)responses[i]=min_vy;
     118                }
     119                else if(strcmp(response_descriptor,"max_vy")==0){
     120                        double* vy=NULL;
     121                        double max_vy=0;
     122                       
     123                        found=results->FindResult((void*)&vy,"vy");
     124                        if(!found)throw ErrorException(__FUNCT__," could not find vy to compute max_vy");
     125
     126                        max_vy=vy[0];
     127                        for(j=1;j<numberofnodes;j++){
     128                                if (vy[j]>max_vy)max_vy=vy[j];
     129                        }
     130                        if(my_rank==0)responses[i]=max_vy;
     131                }
     132                else if(strcmp(response_descriptor,"max_abs_vy")==0){
     133                        double* vy=NULL;
     134                        double max_abs_vy=0;
     135                       
     136                        found=results->FindResult((void*)&vy,"vy");
     137                        if(!found)throw ErrorException(__FUNCT__," could not find vy to compute max_abs_vy");
     138
     139                        max_abs_vy=fabs(vy[0]);
     140                        for(j=1;j<numberofnodes;j++){
     141                                if (fabs(vy[j])>max_abs_vy)max_abs_vy=fabs(vy[j]);
     142                        }
     143                        if(my_rank==0)responses[i]=max_abs_vy;
     144                }
     145                else if(strcmp(response_descriptor,"min_vz")==0){
     146                        double* vz=NULL;
     147                        double min_vz=0;
     148                       
     149                        found=results->FindResult((void*)&vz,"vz");
     150                        if(!found)throw ErrorException(__FUNCT__," could not find vz to compute min_vz");
     151
     152                        min_vz=vz[0];
     153                        for(j=1;j<numberofnodes;j++){
     154                                if (vz[j]<min_vz)min_vz=vz[j];
     155                        }
     156                        if(my_rank==0)responses[i]=min_vz;
     157                }
     158                else if(strcmp(response_descriptor,"max_vz")==0){
     159                        double* vz=NULL;
     160                        double max_vz=0;
     161                       
     162                        found=results->FindResult((void*)&vz,"vz");
     163                        if(!found)throw ErrorException(__FUNCT__," could not find vz to compute max_vz");
     164
     165                        max_vz=vz[0];
     166                        for(j=1;j<numberofnodes;j++){
     167                                if (vz[j]>max_vz)max_vz=vz[j];
     168                        }
     169                        if(my_rank==0)responses[i]=max_vz;
     170                }
     171                else if(strcmp(response_descriptor,"max_abs_vz")==0){
     172                        double* vz=NULL;
     173                        double max_abs_vz=0;
     174                       
     175                        found=results->FindResult((void*)&vz,"vz");
     176                        if(!found)throw ErrorException(__FUNCT__," could not find vz to compute max_abs_vz");
     177
     178                        max_abs_vz=fabs(vz[0]);
     179                        for(j=1;j<numberofnodes;j++){
     180                                if (fabs(vz[j])>max_abs_vz)max_abs_vz=fabs(vz[j]);
     181                        }
     182                        if(my_rank==0)responses[i]=max_abs_vz;
    30183                }
    31184                else throw ErrorException(__FUNCT__,exprintf("%s%s%s"," response descriptor : ",response_descriptor," not supported yet!"));
  • issm/trunk/src/c/parallel/ProcessResults.cpp

    r643 r659  
    2121#include "../shared/shared.h"
    2222
    23 void ProcessResults(DataSet** pnewresults,DataSet* results,FemModel* fems,int analysis_type){
     23void ProcessResults(DataSet** presults,FemModel* fems,int analysis_type){
    2424
    2525        int i,n;
    2626        Result* result=NULL;
    2727        Result* newresult=NULL;
     28       
     29        /*input: */
     30        DataSet* results=NULL;
    2831
    2932        /*output: */
     
    4750        double* vy=NULL;
    4851        double* vz=NULL;
     52        double* vel=NULL;
    4953        Vec     p_g=NULL;
    5054        double* p_g_serial=NULL;
     
    5559        int numberofnodes;
    5660
     61        /*recover input results: */
     62        results=*presults;
     63
    5764        /*Initialize new results: */
    5865        newresults=new DataSet(ResultsEnum());
    5966               
    60 
    6167        /*Recover femmodels first: */
    6268        if(analysis_type==DiagnosticAnalysisEnum()){
     
    101107                                vy=(double*)xmalloc(numberofnodes*sizeof(double));
    102108                                vz=(double*)xmalloc(numberofnodes*sizeof(double));
     109                                vel=(double*)xmalloc(numberofnodes*sizeof(double));
    103110
    104111                                for(i=0;i<numberofnodes;i++){
     
    106113                                        vy[i]=u_g_serial[2*(int)partition[i]+1]*yts;
    107114                                        vz[i]=0;
     115                                        vel[i]=sqrt(pow(vx[i],2)+pow(vy[i],2)+pow(vz[i],2));
    108116                                }
     117
    109118                        }
    110119                        else{
     
    116125                                vy=(double*)xmalloc(numberofnodes*sizeof(double));
    117126                                vz=(double*)xmalloc(numberofnodes*sizeof(double));
     127                                vel=(double*)xmalloc(numberofnodes*sizeof(double));
    118128                                for(i=0;i<numberofnodes;i++){
    119129                                        vx[i]=u_g_serial[4*(int)partition[i]+0]*yts;
    120130                                        vy[i]=u_g_serial[4*(int)partition[i]+1]*yts;
    121131                                        vz[i]=u_g_serial[4*(int)partition[i]+2]*yts;
     132                                        vel[i]=sqrt(pow(vx[i],2)+pow(vy[i],2)+pow(vz[i],2));
    122133                                }
    123134                        }
     
    133144                        newresults->AddObject(newresult);
    134145
     146                        newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"vel",vel,numberofnodes);
     147                        newresults->AddObject(newresult);
     148
    135149                        /*do some cleanup: */
    136150                        xfree((void**)&u_g_serial);
     
    138152                }
    139153                else if(strcmp(result->GetFieldName(),"p_g")==0){
    140 
    141154                        /*easy, p_g is of size numberofnodes, on 1 dof, just repartition: */
    142155                        result->GetField(&p_g);
     
    174187        }
    175188
     189        /*Delete results: */
     190        delete results;
     191
     192
    176193        /*Assign output pointers:*/
    177         *pnewresults=newresults;
    178 
     194        *presults=newresults;
    179195}
    180196
  • issm/trunk/src/c/parallel/SpawnCore.cpp

    r643 r659  
    2424       
    2525        /*output from core solutions: */
    26         Vec u_g=NULL;
    27         Vec p_g=NULL;
     26        DataSet* results=NULL;
    2827
    2928        char** responses_descriptors=NULL;
     
    3433        double* qmu_part=NULL;
    3534        int     qmu_npart;
    36         DataSet* results=NULL;
    3735
    3836        extern int my_rank;
     
    9189        #endif
    9290
     91        _printf_("initialize results:\n");
     92        results=new DataSet(ResultsEnum());
     93
    9394        /*Modify core inputs to reflect the dakota variables inputs: */
    9495        //inputs->UpdateFromDakota(variables,variables_descriptors,numvariables,qmu_part,qmu_npart);
     
    105106        }
    106107
     108        /*Now process the outputs, before computing the dakota responses: */
     109        _printf_("process results:\n");
     110        ProcessResults(&results,femmodels,analysis_type);
     111
    107112        /*compute responses on cpu 0: dummy for now! */
    108         DakotaResponses(responses,responses_descriptors,numresponses,results,analysis_type,sub_analysis_type);
     113        _printf_("compute dakota responses:\n");
     114        DakotaResponses(responses,responses_descriptors,numresponses,femmodels,results,analysis_type,sub_analysis_type);
    109115
    110116        /*Free ressources:*/
    111        
    112         //vectors
    113         VecFree(&u_g);
    114         VecFree(&p_g);
    115        
     117        delete results;
     118
    116119        //variables only on cpu != 0
    117120        if(my_rank!=0){
  • issm/trunk/src/c/parallel/diagnostic.cpp

    r651 r659  
    2323        char* outputfilename=NULL;
    2424        char* lockname=NULL;
    25         char* qmuname=NULL;
     25        char* qmuinname=NULL;
     26        char* qmuoutname=NULL;
     27        char* qmuerrname=NULL;
    2628        int   numberofnodes;
    2729        int   qmu_analysis=0;
     
    3234        /*Results: */
    3335        DataSet* results=NULL;
    34         DataSet* newresults=NULL;
    3536       
    3637        ParameterInputs* inputs=NULL;
     
    5657        outputfilename=argv[3];
    5758        lockname=argv[4];
    58         qmuname=argv[5];
     59        qmuinname=argv[5];
     60        qmuoutname=argv[6];
     61        qmuerrname=argv[7];
    5962
    6063        /*Open handle to data on disk: */
     
    101104                _printf_("calling qmu analysis on diagnostic core:\n");
    102105               
    103                 //qmu(qmuname,&femmodels[0],inputs,DiagnosticAnalysisEnum(),NoneAnalysisEnum());
     106                qmu(qmuinname,qmuoutname,qmuerrname,&femmodels[0],inputs,DiagnosticAnalysisEnum(),NoneAnalysisEnum());
    104107        }
    105108
    106109        _printf_("process results:\n");
    107         ProcessResults(&newresults,results,&femmodels[0],DiagnosticAnalysisEnum()); delete results;
     110        ProcessResults(&results,&femmodels[0],DiagnosticAnalysisEnum());
    108111       
    109112        _printf_("write results to disk:\n");
    110         OutputResults(newresults,outputfilename);
     113        OutputResults(results,outputfilename);
    111114
    112115        _printf_("write lock file:\n");
     
    117120               
    118121        _printf_("closing MPI and Petsc\n");
    119         MPI_Barrier(MPI_COMM_WORLD);
    120 
    121         /*Close MPI libraries: */
    122122        PetscFinalize();
     123       
    123124
    124125        /*end module: */
  • issm/trunk/src/c/parallel/parallel.h

    r643 r659  
    3636void CreateFemModel(FemModel* femmodel,ConstDataHandle MODEL,char* analysis_type,char* sub_analysis_type);
    3737//int BatchDebug(Mat* Kgg,Vec* pg,FemModel* femmodel,char* filename);
    38 void qmu(const char* dakota_input_file,FemModel* femmodels,ParameterInputs* inputs,int analysis_type,int sub_analysis_type);
     38void qmu(const char* dakota_input_file,const char* dakota_output_file,const char* dakota_error_file,FemModel* femmodels,ParameterInputs* inputs,int analysis_type,int sub_analysis_type);
    3939void SpawnCore(double* responses,double* variables,char** variable_descriptors,int numvariables, FemModel* femmodels,ParameterInputs* inputs,int analysis_type,int sub_analysis_type);
    40 void DakotaResponses(double* responses,char** responses_descriptors,int numresponses,DataSet* results,int analysis_type,int sub_analysis_type);
    41 void ProcessResults(DataSet** pnewresults,DataSet* results,FemModel* fems,int analysis_type);
     40void DakotaResponses(double* responses,char** responses_descriptors,int numresponses,FemModel* femmodels, DataSet* results,int analysis_type,int sub_analysis_type);
     41void ProcessResults(DataSet** presults,FemModel* fems,int analysis_type);
    4242
    4343#endif
  • issm/trunk/src/c/parallel/qmu.cpp

    r586 r659  
    2323#include "parallel.h"
    2424
    25 void qmu(const char* dakota_input_file,FemModel* femmodels,ParameterInputs* inputs,int analysis_type,int sub_analysis_type){
     25void qmu(const char* dakota_input_file,const char* dakota_output_file,const char* dakota_error_file, FemModel* femmodels,ParameterInputs* inputs,int analysis_type,int sub_analysis_type){
     26
    2627
    2728        extern int my_rank;
     
    3031
    3132        if(my_rank==0){
    32 
     33       
    3334                // Instantiate/initialize the parallel library and problem description
    3435                // database objects.
     
    4142                problem_db.manage_inputs(dakota_input_file);
    4243                // specify_outputs_restart() is only necessary if specifying non-defaults
    43                 //parallel_lib.specify_outputs_restart(NULL, NULL, NULL, NULL);
     44                parallel_lib.specify_outputs_restart(dakota_output_file,dakota_error_file,NULL, NULL);
    4445
    4546                // Instantiate the Strategy object (which instantiates all Model and
  • issm/trunk/src/c/parallel/thermal.cpp

    r654 r659  
    3535        /*Results: */
    3636        DataSet* results=NULL;
    37         DataSet* newresults=NULL;
    3837       
    3938        ParameterInputs* inputs=NULL;
     
    8988        param=(Param*)femmodels[1].parameters->FindParamObject("p_g");
    9089        femmodels[1].parameters->DeleteObject((Object*)param);
     90
    9191       
    9292        _printf_("call computational core:\n");
     
    9494
    9595        _printf_("process results:\n");
    96         ProcessResults(&newresults,results,&femmodels[0],ThermalAnalysisEnum()); delete results;
     96        ProcessResults(&results,&femmodels[0],ThermalAnalysisEnum());
    9797
    9898        _printf_("write results to disk:\n");
    99         OutputResults(newresults,outputfilename);
     99        OutputResults(results,outputfilename);
    100100
    101101        _printf_("write lock file:\n");
  • issm/trunk/src/m/classes/public/BuildQueueingScriptGeneric.m

    r612 r659  
    2929end
    3030
    31 fprintf(fid,' %s %s.bin %s.outbin %s.lock qmu.in 2> %s.errlog >%s.outlog & ',executionpath,md.name,md.name,md.name,md.name,md.name);
     31fprintf(fid,' %s %s.bin %s.outbin %s.lock %s.qmu.in %s.qmu.out %s.qmu.err 2> %s.errlog >%s.outlog & ',executionpath,md.name,md.name,md.name,md.name,md.name,md.name,md.name,md.name);
    3232fclose(fid);
  • issm/trunk/src/m/classes/public/LaunchQueueJobGeneric.m

    r586 r659  
    2121if strcmpi(hostname,md.cluster),
    2222        if md.qmu_analysis,
    23                 system(['cp ' md.name '.bin' ' ' md.name '.queue qmu/qmu.in ' ' ' executionpath]);
     23                system(['cp ' md.name '.bin' ' ' md.name '.queue qmu/' md.name '.qmu.in ' ' ' executionpath]);
    2424        else
    2525                system(['cp ' md.name '.bin' ' ' md.name '.queue' ' ' executionpath]);
     
    2727else
    2828        if md.qmu_analysis,
    29                 system(['scp ' md.name '.bin' ' ' md.name '.queue qmu/qmu.in ' ' ' md.cluster ':' executionpath]);
     29                system(['scp ' md.name '.bin' ' ' md.name '.queue qmu/' md.name '.qmu.in ' ' ' md.cluster ':' executionpath]);
    3030        else
    3131                system(['scp ' md.name '.bin' ' ' md.name '.queue' ' ' md.cluster ':' executionpath]);
  • issm/trunk/src/m/classes/public/marshall.m

    r649 r659  
    164164                WriteData(fid,responses(i).descriptor,'String',['descriptor' num2str(i-1)]);
    165165        end
     166        WriteData(fid,md.npart,'Integer','npart');
    166167end
    167168       
  • issm/trunk/src/m/solutions/dakota/dakota_in_write.m

    r452 r659  
    2626[pathstr,name,ext,versn] = fileparts(filei);
    2727if isempty(ext)
    28     ext='.in';
     28    ext='.qmu.in';
    2929end
    3030filei2=fullfile(pathstr,[name ext versn]);
  • issm/trunk/src/m/solutions/dakota/qmuin.m

    r586 r659  
    88qmudir ='qmu';
    99%  qmufile can not be changed unless cielo_ice_script.sh is also changed
    10 qmufile='qmu';
     10qmufile=md.name;
    1111ivar   =1;
    1212iresp  =1;
     
    7575    md.qmu_params(iparams).analysis_driver=[ISSM_DIR '/src/m/solutions/dakota/cielo_ice_script.sh'];
    7676end
     77
    7778dakota_in_data(md.qmu_method(imethod),md.variables(ivar),md.responses(iresp),md.qmu_params(iparams),qmufile,package,md);
    7879
    79 system(['rm -rf qmu.m']);
     80
     81system(['rm -rf ' md.name '.m']);
    8082cd ../
    8183
Note: See TracChangeset for help on using the changeset viewer.