source: issm/trunk/src/c/parallel/SpawnCore.cpp@ 643

Last change on this file since 643 was 643, checked in by Eric.Larour, 16 years ago

New framework for results output for parallel solutions . Watch out for bugs...

File size: 3.9 KB
Line 
1/*!\file: SpawnCore.cpp
2 * \brief: run core solution, according to analysis_type and sub_analysis_type
3 */
4
5#ifdef HAVE_CONFIG_H
6 #include "config.h"
7#else
8#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
9#endif
10
11#undef __FUNCT__
12#define __FUNCT__ "SpawnCore"
13
14#include "../objects/objects.h"
15#include "../io/io.h"
16#include "../EnumDefinitions/EnumDefinitions.h"
17#include "../shared/shared.h"
18#include "./parallel.h"
19#include "../include/macros.h"
20
21void SpawnCore(double* responses, double* variables, char** variables_descriptors,int numvariables, FemModel* femmodels,ParameterInputs* inputs,int analysis_type,int sub_analysis_type){
22
23 int i;
24
25 /*output from core solutions: */
26 Vec u_g=NULL;
27 Vec p_g=NULL;
28
29 char** responses_descriptors=NULL;
30 int numresponses;
31 Param* param=NULL;
32 char* string=NULL;
33 int string_length;
34 double* qmu_part=NULL;
35 int qmu_npart;
36 DataSet* results=NULL;
37
38 extern int my_rank;
39
40 /*synchronize all cpus, as CPU 0 is probably late (it is starting the entire dakota strategy!) : */
41 MPI_Barrier(MPI_COMM_WORLD);
42
43 /*First off, recover the responses descriptors for the response functions: */
44 param=(Param*)femmodels[0].parameters->FindParamObject("descriptors");
45 numresponses=param->GetM();
46 param->GetParameterValue(&responses_descriptors);
47
48 /*Recover partitioning for dakota: */
49 femmodels[0].parameters->FindParam((void*)&qmu_npart,"qmu_npart");
50 femmodels[0].parameters->FindParam((void*)&qmu_part,"qmu_part");
51
52 #ifdef _DEBUG_
53 for(i=0;i<numresponses;i++){
54 PetscSynchronizedPrintf(MPI_COMM_WORLD,"descriptor %i: %s\n",i,responses_descriptors[i]);
55 PetscSynchronizedFlush(MPI_COMM_WORLD);
56 }
57 #endif
58
59 /*broadcast variables: only cpu 0 has correct values*/
60 MPI_Bcast(&numvariables,1,MPI_INT,0,MPI_COMM_WORLD);
61 if(my_rank!=0)variables=(double*)xmalloc(numvariables*sizeof(double));
62 MPI_Bcast(variables,numvariables,MPI_DOUBLE,0,MPI_COMM_WORLD);
63
64 #ifdef _DEBUG_
65 for(i=0;i<numvariables;i++){
66 PetscSynchronizedPrintf(MPI_COMM_WORLD,"variable %i: %g\n",i,variables[i]);
67 PetscSynchronizedFlush(MPI_COMM_WORLD);
68 }
69 #endif
70
71 /*broadcast variables_descriptors: */
72 if(my_rank!=0){
73 variables_descriptors=(char**)xmalloc(numvariables*sizeof(char*));
74 }
75 for(i=0;i<numvariables;i++){
76 if(my_rank==0){
77 string=variables_descriptors[i];
78 string_length=(strlen(string)+1)*sizeof(char);
79 }
80 MPI_Bcast(&string_length,1,MPI_INT,0,MPI_COMM_WORLD);
81 if(my_rank!=0)string=(char*)xmalloc(string_length);
82 MPI_Bcast(string,string_length,MPI_CHAR,0,MPI_COMM_WORLD);
83 if(my_rank!=0)variables_descriptors[i]=string;
84 }
85
86 #ifdef _DEBUG_
87 for(i=0;i<numvariables;i++){
88 PetscSynchronizedPrintf(MPI_COMM_WORLD,"variable descriptor %i: %s\n",i,variables_descriptors[i]);
89 PetscSynchronizedFlush(MPI_COMM_WORLD);
90 }
91 #endif
92
93 /*Modify core inputs to reflect the dakota variables inputs: */
94 //inputs->UpdateFromDakota(variables,variables_descriptors,numvariables,qmu_part,qmu_npart);
95
96 /*Run the analysis core solution sequence, with the updated inputs: */
97 if(analysis_type==DiagnosticAnalysisEnum()){
98
99 _printf_("Starting diagnostic core\n");
100 diagnostic_core(results,femmodels,inputs);
101
102 }
103 else{
104 throw ErrorException(__FUNCT__,exprintf("%s%i%s%i%s"," analysis_type ",analysis_type," and sub_analysis_type ",sub_analysis_type," not supported yet!"));
105 }
106
107 /*compute responses on cpu 0: dummy for now! */
108 DakotaResponses(responses,responses_descriptors,numresponses,results,analysis_type,sub_analysis_type);
109
110 /*Free ressources:*/
111
112 //vectors
113 VecFree(&u_g);
114 VecFree(&p_g);
115
116 //variables only on cpu != 0
117 if(my_rank!=0){
118 xfree((void**)&variables);
119 for(i=0;i<numvariables;i++){
120 string=variables_descriptors[i];
121 xfree((void**)&string);
122 }
123 xfree((void**)&variables_descriptors);
124 }
125 //responses descriptors
126 for(i=0;i<numresponses;i++){
127 string=responses_descriptors[i];
128 xfree((void**)&string);
129 }
130 //rest of dynamic allocations.
131 xfree((void**)&responses_descriptors);
132 xfree((void**)&qmu_part);
133}
134
Note: See TracBrowser for help on using the repository browser.