Newer
Older
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
for(jj=0; jj< nAstroPSolved;jj++)
{
xAstro[(ii-offset)*nAstroP+mapAstroP[jj]] = xSolution[ii*nAstroPSolved+jj];
}
}
fwrite(xAstro,sizeof(double),(VrIdAstroPDimRecv-offset)*nAstroP,fpAstroR);
testOnStars+=VrIdAstroPDimRecv-offset;
}
free(xAstro);
if(testOnStars!=nStar)
{
printf("Error on xAstro testOnStar =%ld not equal to nmStar=%ld\n",testOnStars,nStar);
MPI_Abort(MPI_COMM_WORLD,1);
exit(EXIT_FAILURE);
}
testOnStars=0;
standardErrorAstro = (double *) calloc(VrIdAstroPDimMax*nAstroP, sizeof(double));
if (!standardErrorAstro)
{
printf("Error allocating standardErrorAstro\n");
MPI_Abort(MPI_COMM_WORLD,1);
exit(EXIT_FAILURE);
}
for(ii=0; ii<VrIdAstroPDim; ii++)
{
for(jj=0; jj< nAstroPSolved;jj++)
{
standardErrorAstro[ii*nAstroP+mapAstroP[jj]] =standardError[ii*nAstroPSolved+jj];
}
}
fwrite(standardErrorAstro,sizeof(double),VrIdAstroPDim*nAstroP,fpAstroR);
testOnStars+=VrIdAstroPDim;
for(kk=1;kk<nproc;kk++)
{
offset=0;
MPI_Recv(&VrIdAstroPDimRecv, 1, MPI_LONG, kk, 12, MPI_COMM_WORLD, &statusMpi);
MPI_Recv(standardError, VrIdAstroPDimRecv*nAstroPSolved , MPI_DOUBLE, kk, 13,MPI_COMM_WORLD, &statusMpi);
if(comlsqr.mapStar[kk][0]==comlsqr.mapStar[kk-1][1]) offset=1;
for(ii=0+offset; ii<VrIdAstroPDimRecv; ii++)
{
for(jj=0; jj< nAstroPSolved;jj++)
{
standardErrorAstro[(ii-offset)*nAstroP+mapAstroP[jj]] = standardError[ii*nAstroPSolved+jj];
}
}
fwrite(standardErrorAstro,sizeof(double),(VrIdAstroPDimRecv-offset)*nAstroP,fpAstroR);
testOnStars+=VrIdAstroPDimRecv-offset;
}
free(standardErrorAstro);
if(testOnStars!=nStar)
{
printf("Error on standardErrorAstro testOnStar =%ld not equal to nmStar=%ld\n",testOnStars,nStar);
MPI_Abort(MPI_COMM_WORLD,1);
exit(EXIT_FAILURE);
}
fclose(fpAstroR);
//////////////////////////////////////////////////////////
}
////////////////////// writing GsrAttitudeParamSolution.bin
fpAttR=fopen(filenameAttResults,"wb");
if (!fpAttR)
{
printf("Error while open %s\n",filenameAttResults);
MPI_Abort(MPI_COMM_WORLD,1);
exit(EXIT_FAILURE);
}
fwrite(&sphereId,sizeof(long),1,fpAttR);
fwrite(&xSolution[VroffsetAttParam],sizeof(double),nAttParam,fpAttR);
fwrite(&standardError[VroffsetAttParam],sizeof(double),nAttParam,fpAttR);
fclose(fpAttR);
//////////////////////////////////////////////////////////
////////////////////// writing GsrInstrParamSolution.bin
fpInstrR=fopen(filenameInstrResults,"wb");
if (!fpInstrR)
{
printf("Error while open %s\n",filenameInstrResults);
MPI_Abort(MPI_COMM_WORLD,1);
exit(EXIT_FAILURE);
}
double *xInstr,*seInstr;
xInstr=(double *) calloc(nInstrParamTot, sizeof(double));
seInstr=(double *) calloc(nInstrParamTot, sizeof(double));
if(nInstrPSolved!=nInstrP)
{
int fixedOffsetCMag = nCCDs;
int fixedOffsetCnu = fixedOffsetCMag+nFoVs*nCCDs;
int fixedOffsetCdelta_eta = fixedOffsetCnu+nCCDs*nPixelColumns;
int fixedOffsetCDelta_eta = fixedOffsetCdelta_eta+3*nFoVs*nCCDs*nTimeIntervals;
int fixedOffsetCdelta_zeta = fixedOffsetCDelta_eta+nCCDs*nPixelColumns;
int counterInstr=0;
if(maInstrFlag){
for(int k=0;k<fixedOffsetCMag;k++){
xInstr[k]=xSolution[VroffsetAttParam+nAttParam+counterInstr];
seInstr[k]=standardError[VroffsetAttParam+nAttParam+counterInstr];
counterInstr++;
}
}
if(nuInstrFlag){
for(int k=fixedOffsetCMag;k<fixedOffsetCnu;k++){
xInstr[k]=xSolution[VroffsetAttParam+nAttParam+counterInstr];
seInstr[k]=standardError[VroffsetAttParam+nAttParam+counterInstr];
counterInstr++;
}
}
if(ssInstrFlag){
for(int k=fixedOffsetCnu;k<fixedOffsetCdelta_eta;k++){
xInstr[k]=xSolution[VroffsetAttParam+nAttParam+counterInstr];
seInstr[k]=standardError[VroffsetAttParam+nAttParam+counterInstr];
counterInstr++;
}
}
if(lsInstrFlag){
for(int k=fixedOffsetCdelta_eta;k<fixedOffsetCDelta_eta;k++){
xInstr[k]=xSolution[VroffsetAttParam+nAttParam+counterInstr];
seInstr[k]=standardError[VroffsetAttParam+nAttParam+counterInstr];
counterInstr++;
}
}
if(ssInstrFlag){
for(int k=fixedOffsetCDelta_eta;k<fixedOffsetCdelta_zeta;k++){
xInstr[k]=xSolution[VroffsetAttParam+nAttParam+counterInstr];
seInstr[k]=standardError[VroffsetAttParam+nAttParam+counterInstr];
counterInstr++;
}
}
if(lsInstrFlag){
for(int k=fixedOffsetCdelta_zeta;k<nInstrParamTot;k++){
xInstr[k]=xSolution[VroffsetAttParam+nAttParam+counterInstr];
seInstr[k]=standardError[VroffsetAttParam+nAttParam+counterInstr];
counterInstr++;
}
}
if(counterInstr!=nInstrParam) {
printf("SEVERE ERROR: counterInstr=%ld does not match nInstrParam=%ld while filling in xInstr and seInstr.\n", counterInstr, nInstrParam);
MPI_Abort(MPI_COMM_WORLD,1);
exit(EXIT_FAILURE);
}
}
fwrite(&sphereId,sizeof(long),1,fpInstrR);
fwrite(xInstr,sizeof(double),nInstrParamTot,fpInstrR);
fwrite(seInstr,sizeof(double),nInstrParamTot,fpInstrR);
fclose(fpInstrR);
free(xInstr);
free(seInstr);
//////////////////////////////////////////////////////////
////////////////////// writing GsrGlobalParamSolution.bin
fpGlobR=fopen(filenameGlobalResults,"wb");
if (!fpGlobR)
{
printf("Error while open %s\n",filenameGlobalResults);
MPI_Abort(MPI_COMM_WORLD,1);
exit(EXIT_FAILURE);
}
fwrite(&sphereId,sizeof(long),1,fpGlobR);
fwrite(&xSolution[VroffsetAttParam+nAttParam+nInstrParam],sizeof(double),nGlobalParam,fpGlobR);
fwrite(&standardError[VroffsetAttParam+nAttParam+nInstrParam],sizeof(double),nGlobalParam,fpGlobR);
fclose(fpGlobR);
//////////////////////////////////////////////////////////
} //if (myid==0)
else
{
//////////////// send for AstroResults.bin
if(nAstroPSolved)
{
MPI_Send(&VrIdAstroPDim, 1, MPI_LONG, 0, 10, MPI_COMM_WORLD);
mpi_send(xSolution, VrIdAstroPDim*nAstroPSolved, MPI_DOUBLE, 0, 11,MPI_COMM_WORLD);
MPI_Send(&VrIdAstroPDim, 1, MPI_LONG, 0, 12, MPI_COMM_WORLD);
MPI_Send(standardError, VrIdAstroPDim*nAstroPSolved , MPI_DOUBLE, 0, 13,MPI_COMM_WORLD);
}
//////////////////////////////////////////////////////////
}
MPI_Barrier(MPI_COMM_WORLD);
// tolti i free() mancanti
free(xSolution);
free(standardError);
if(myid==0) printf("\nEnd run.\n");
seconds[3] = time(NULL);
tot_sec[2] = seconds[3] - seconds[2];
tot_sec[3] = seconds[3] - seconds[0];
if(myid==0) printf("time before lsqr in sec: %ld\ntime for lsqr: %ld\n", tot_sec[0],
tot_sec[1]);
if(myid==0) printf("time after lsqr in sec: %ld\ntime TOTAL: %ld\n", tot_sec[2],
tot_sec[3]);
MPI_Finalize();
exit(EXIT_SUCCESS);
}