[472] | 1 | /*
|
---|
| 2 | * ParameterUpdate.c:
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | #include "../../../config.h"
|
---|
| 6 |
|
---|
| 7 | #if defined(_PARALLEL_) && defined(_HAVE_PETSC_)
|
---|
| 8 |
|
---|
| 9 | #include "../include/cielo.h"
|
---|
| 10 | #include "../modules.h"
|
---|
| 11 | #include "./parallel.h"
|
---|
| 12 |
|
---|
| 13 | #undef __FUNCT__
|
---|
| 14 | #define __FUNCT__ "ParameterUpdate"
|
---|
| 15 | #undef CLEANUP
|
---|
| 16 | #define CLEANUP ParameterUpdateLocalCleanup(&gradient);
|
---|
| 17 |
|
---|
| 18 | void ParameterUpdateLocalCleanup(double** pgradient);
|
---|
| 19 |
|
---|
| 20 | int ParameterUpdate(double* search_vector,int step,WorkspaceParams* workspaceparams,BatchParams* batchparams){
|
---|
| 21 |
|
---|
| 22 | /*Error management: */
|
---|
| 23 | int noerr=1;
|
---|
| 24 | int i,j;
|
---|
| 25 | double* parameter=NULL;
|
---|
| 26 | Vec* vec_gradient=NULL;
|
---|
| 27 | double* gradient=NULL;
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | //Go through parameters, and update along gradients, multiplying by search_vector.
|
---|
| 31 | for(i=0;i<workspaceparams->num_control_parameters;i++){
|
---|
| 32 | char* control_type=workspaceparams->control_types[i];
|
---|
| 33 |
|
---|
| 34 | /*Get parameter, and gradient for the parameter: */
|
---|
| 35 | parameter=WorkspaceParamsGetParameter(workspaceparams,control_type);
|
---|
| 36 | vec_gradient=WorkspaceParamsGetParameterGradient(workspaceparams,control_type);
|
---|
| 37 |
|
---|
| 38 | /*serialize gradient: */
|
---|
| 39 | VecToMPISerial(&gradient,vec_gradient);
|
---|
| 40 |
|
---|
| 41 | /*Ok, for this parameter, we have a direction. Update the parameter along
|
---|
| 42 | * the direction, using the search_vector value: */
|
---|
| 43 | for(j=0;j<(int)(workspaceparams->gsize/6);j++){
|
---|
| 44 | parameter[6*j+0]=parameter[6*j+0]-search_vector[i]*workspaceparams->optscal[step]*gradient[6*j+0];
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | /*Now, call on each parameter's self constraining routine: */
|
---|
| 48 | WorkspaceParamsConstrain(workspaceparams,control_type);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | /*Done, just return: */
|
---|
| 52 | EXIT(noerr);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | void ParameterUpdateLocalCleanup(double** pgradient){
|
---|
| 56 | xfree((void**)pgradient);
|
---|
| 57 | return;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | #endif //#if defined(_PARALLEL_) && defined(_HAVE_PETSC_)
|
---|
| 61 |
|
---|