Skip to content

Commit 523c482

Browse files
committed
Debug
1 parent cfda693 commit 523c482

1 file changed

Lines changed: 36 additions & 18 deletions

File tree

NF_HEDM/src/FitOrientationOMP.c

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,18 @@ static double problem_function(unsigned n, const double *x, double *grad,
142142
return (1 - FracOverlap);
143143
}
144144

145-
void FitOrientation(const int NrOfFiles, const int nLayers,
146-
const double ExcludePoleAngle, double Lsd[nLayers],
147-
const long long int SizeObsSpots, const double XGrain[3],
148-
const double YGrain[3], double RotMatTilts[3][3],
149-
const double OmegaStart, const double OmegaStep,
150-
const double px, double ybc[nLayers], double zbc[nLayers],
151-
const double gs, double OmegaRanges[MAX_N_OMEGA_RANGES][2],
152-
const int NoOfOmegaRanges,
153-
double BoxSizes[MAX_N_OMEGA_RANGES][4],
154-
double P0[nLayers][3], const int NrPixelsGrid,
155-
int *ObsSpotsInfo, double EulerIn[3], double tol,
156-
double *EulerOutA, double *EulerOutB, double *EulerOutC,
157-
double *ResultFracOverlap, double hkls[5000][4],
158-
double Thetas[5000], int n_hkls, double *Gs) {
145+
void FitOrientation(
146+
const int NrOfFiles, const int nLayers, const double ExcludePoleAngle,
147+
double Lsd[nLayers], const long long int SizeObsSpots,
148+
const double XGrain[3], const double YGrain[3], double RotMatTilts[3][3],
149+
const double OmegaStart, const double OmegaStep, const double px,
150+
double ybc[nLayers], double zbc[nLayers], const double gs,
151+
double OmegaRanges[MAX_N_OMEGA_RANGES][2], const int NoOfOmegaRanges,
152+
double BoxSizes[MAX_N_OMEGA_RANGES][4], double P0[nLayers][3],
153+
const int NrPixelsGrid, int *ObsSpotsInfo, double EulerIn[3], double tol,
154+
double *EulerOutA, double *EulerOutB, double *EulerOutC,
155+
double *ResultFracOverlap, double hkls[5000][4], double Thetas[5000],
156+
int n_hkls, double *Gs, int *out_nevals, int *out_retcode) {
159157
unsigned n;
160158
long int i, j;
161159
n = 3;
@@ -216,8 +214,12 @@ void FitOrientation(const int NrOfFiles, const int nLayers,
216214
nlopt_set_lower_bounds(opt, xl);
217215
nlopt_set_upper_bounds(opt, xu);
218216
nlopt_set_min_objective(opt, problem_function, trp);
217+
nlopt_set_maxeval(opt, 5000);
218+
nlopt_set_ftol_rel(opt, tole);
219219
double minf = 1;
220-
nlopt_optimize(opt, x, &minf);
220+
int retcode = nlopt_optimize(opt, x, &minf);
221+
*out_nevals = (int)nlopt_get_numevals(opt);
222+
*out_retcode = retcode;
221223
nlopt_destroy(opt);
222224
// f_data.P0 was allocated with malloc for the pointer array only, but we
223225
// didn't alloc rows
@@ -847,6 +849,9 @@ int main(int argc, char *argv[]) {
847849
printf("Finished checking orientation grid for point %d. Now fitting %d"
848850
" orientations.\n",
849851
rown, OrientationGoodID);
852+
fflush(stdout);
853+
double tFitStart = omp_get_wtime();
854+
int totalNloptEvals = 0;
850855
double BestFrac, BestEuler[3];
851856
double ResultMatr[7 + (nSaves * 4)], QuatIn[4], QuatOut[4];
852857
double bestRowNr = 0;
@@ -881,11 +886,21 @@ int main(int argc, char *argv[]) {
881886
// which calls problem_function. problem_function needs to allocate
882887
// InPixels internally or be passed it? Let's check problem_function in
883888
// SharedFuncsFit.c first.
889+
int fitNevals = 0, fitRetcode = 0;
884890
FitOrientation(nrFiles, nLayers, ExcludePoleAngle, Lsd, SizeObsSpots,
885891
XG, YG, RotMatTilts, OmegaStart, OmegaStep, px, ybc, zbc,
886892
gs, OmegaRanges, nOmeRang, BoxSizes, P0, NrPixelsGrid,
887893
ObsSpotsInfo, EulerIn, tol, &EulerOutA, &EulerOutB,
888-
&EulerOutC, &FracOut, hkls, Thetas, n_hkls, Gs);
894+
&EulerOutC, &FracOut, hkls, Thetas, n_hkls, Gs,
895+
&fitNevals, &fitRetcode);
896+
totalNloptEvals += fitNevals;
897+
if (i > 0 && i % 100 == 0) {
898+
printf(" Point %d: fitted %d/%d orientations, elapsed %.1fs, "
899+
"last nlopt evals=%d ret=%d\n",
900+
rown, i, OrientationGoodID, omp_get_wtime() - tFitStart,
901+
fitNevals, fitRetcode);
902+
fflush(stdout);
903+
}
889904
Fractions = 1 - FracOut;
890905
if (Fractions >= BestFrac) {
891906
bestRowNr = OrientMatrix[i * 10 + 9]; // Save best RowNr
@@ -933,8 +948,11 @@ int main(int argc, char *argv[]) {
933948
printf("No good ID found.\n");
934949
continue;
935950
}
936-
//~ end = clock();
937-
//~ diftotal = ((double)(end-start))/CLOCKS_PER_SEC;
951+
double tFitElapsed = omp_get_wtime() - tFitStart;
952+
printf("Point %d: fitting done in %.2fs, %d total nlopt evals, "
953+
"bestFrac=%.4f\n",
954+
rown, tFitElapsed, totalNloptEvals, BestFrac);
955+
fflush(stdout);
938956
double outresult[11] = {bestRowNr,
939957
(double)OrientationGoodID,
940958
0,

0 commit comments

Comments
 (0)