diff --git a/src/EOFs.c b/src/EOFs.c index 0cf42fa2bda390114286a32be377b144c88baa9b..664541a43b5993853f424869f7c41a8926e5414a 100644 --- a/src/EOFs.c +++ b/src/EOFs.c @@ -31,6 +31,10 @@ //#define OLD_IMPLEMENTATION #define WEIGHTS 1 +#if defined(_OPENMP) +#include <omp.h> +#endif + #include <limits.h> // LONG_MAX #include <cdi.h> #include "cdo.h" @@ -39,8 +43,6 @@ #include "grid.h" #include "statistic.h" -enum T_EIGEN_MODE {JACOBI, DANIELSON_LANCZOS}; - // NO MISSING VALUE SUPPORT ADDED SO FAR static @@ -114,6 +116,37 @@ void scale_eigvec_time(double *restrict out, int tsID, int nts, int npack, const } +enum T_EIGEN_MODE get_eigenmode(void) +{ + char *envstr = getenv("CDO_SVD_MODE"); + + enum T_EIGEN_MODE eigen_mode = JACOBI; + if ( envstr && !strncmp(envstr, "danielson_lanczos", 17) ) + eigen_mode = DANIELSON_LANCZOS; + else if ( envstr && ! strncmp(envstr, "jacobi", 6) ) + eigen_mode = JACOBI; + else if ( envstr ) { + cdoWarning("Unknown environmental setting %s for CDO_SVD_MODE. Available options are",envstr); + cdoWarning(" - 'jacobi' for a one-sided parallelized jacobi algorithm"); + cdoWarning(" - 'danielson_lanzcos' for the D/L algorithm"); + } + + if ( cdoVerbose ) + cdoPrint("Using CDO_SVD_MODE '%s' from %s", + eigen_mode==JACOBI?"jacobi":"danielson_lanczos", + envstr?"Environment":" default"); + +#if defined(_OPENMP) + if ( omp_get_max_threads() > 1 && eigen_mode == DANIELSON_LANCZOS ) { + cdoWarning("Requested parallel computation with %i Threads ",omp_get_max_threads()); + cdoWarning(" but environmental setting CDO_SVD_MODE causes sequential "); + cdoWarning(" Singular value decomposition"); + } +#endif + + return eigen_mode; +} + void *EOFs(void * argument) { enum {EOF_, EOF_TIME, EOF_SPATIAL}; @@ -162,25 +195,8 @@ void *EOFs(void * argument) operatorInputArg("Number of eigen functions to write out"); int n_eig = parameter2int(operatorArgv()[0]); - - char *envstr = getenv("CDO_SVD_MODE"); - enum T_EIGEN_MODE eigen_mode = JACOBI; - if ( envstr && !strncmp(envstr, "danielson_lanczos", 17) ) - eigen_mode = DANIELSON_LANCZOS; - else if ( envstr && ! strncmp(envstr, "jacobi", 6) ) - eigen_mode = JACOBI; - else if ( envstr ) { - cdoWarning("Unknown environmental setting %s for CDO_SVD_MODE. Available options are",envstr); - cdoWarning(" - 'jacobi' for a one-sided parallelized jacobi algorithm"); - cdoWarning(" - 'danielson_lanzcos' for the D/L algorithm"); - envstr = NULL; - } - - if ( cdoVerbose ) - cdoPrint("Using CDO_SVD_MODE '%s' from %s", - eigen_mode==JACOBI?"jacobi":"danielson_lanczos", - envstr?"Environment":" default"); + enum T_EIGEN_MODE eigen_mode = get_eigenmode(); int streamID1 = streamOpenRead(cdoStreamName(0)); int vlistID1 = streamInqVlist(streamID1); @@ -228,9 +244,9 @@ void *EOFs(void * argument) streamClose(streamID1); - streamID1 = streamOpenRead(cdoStreamName(0)); - vlistID1 = streamInqVlist(streamID1); - taxisID1 = vlistInqTaxis(vlistID1); + streamID1 = streamOpenRead(cdoStreamName(0)); + vlistID1 = streamInqVlist(streamID1); + taxisID1 = vlistInqTaxis(vlistID1); if ( nts < gridsize || operfunc == EOF_TIME ) { @@ -264,8 +280,7 @@ void *EOFs(void * argument) } else if ( grid_space ) { - if ( ((double)gridsize)*gridsize > (double)LONG_MAX ) - cdoAbort("Grid space to large!"); + if ( ((double)gridsize)*gridsize > (double)LONG_MAX ) cdoAbort("Grid space too large!"); if ( n_eig > gridsize ) { diff --git a/src/Eof3d.c b/src/Eof3d.c index fabafffdd49ac86af4a02912ee6a327178a4fba1..7702a4905780110a842476f8b9d306aa832fb5bd 100644 --- a/src/Eof3d.c +++ b/src/Eof3d.c @@ -40,7 +40,7 @@ #include "statistic.h" -enum T_EIGEN_MODE {JACOBI, DANIELSON_LANCZOS}; +enum T_EIGEN_MODE get_eigenmode(void); #define WEIGHTS 1 @@ -48,8 +48,6 @@ enum T_EIGEN_MODE {JACOBI, DANIELSON_LANCZOS}; void *EOF3d(void * argument) { - char *envstr; - enum {EOF3D_, EOF3D_TIME, EOF3D_SPATIAL}; int temp_size = 0; @@ -71,8 +69,6 @@ void *EOF3d(void * argument) double *xvals, *yvals, *zvals; double *df1p, *df2p; - enum T_EIGEN_MODE eigen_mode = JACOBI; - if ( cdoTimer ) { @@ -91,28 +87,7 @@ void *EOF3d(void * argument) operatorInputArg("Number of eigen functions to write out"); int n_eig = parameter2int(operatorArgv()[0]); - envstr = getenv("CDO_SVD_MODE"); - - if ( envstr &&! strncmp(envstr,"danielson_lanczos",17) ) - eigen_mode = DANIELSON_LANCZOS; - else if ( envstr && ! strncmp(envstr,"jacobi",6) ) - eigen_mode = JACOBI; - else if ( envstr ) { - cdoWarning("Unknown environmental setting %s for CDO_SVD_MODE. Available options are",envstr); - cdoWarning(" - 'jacobi' for a one-sided parallelized jacobi algorithm"); - cdoWarning(" - 'danielson_lanzcos' for the D/L algorithm"); - } - - if ( cdoVerbose ) - cdoPrint("Set eigen_mode to %s",eigen_mode == JACOBI? "jacobi" : "danielson_lanczos"); - -#if defined(_OPENMP) - if ( omp_get_max_threads() > 1 && eigen_mode == DANIELSON_LANCZOS ) { - cdoWarning("Requested parallel computation with %i Threads ",omp_get_max_threads()); - cdoWarning(" but environmental setting CDO_SVD_MODE causes sequential "); - cdoWarning(" Singular value decomposition"); - } -#endif + enum T_EIGEN_MODE eigen_mode = get_eigenmode(); int streamID1 = streamOpenRead(cdoStreamName(0)); int vlistID1 = streamInqVlist(streamID1); diff --git a/src/Specinfo.c b/src/Specinfo.c index 9ab51cbba57b91f085cede7c8e23924a95114ffa..2c699242ff7473c2bf2125cd6d9d6da4da89b531 100644 --- a/src/Specinfo.c +++ b/src/Specinfo.c @@ -263,7 +263,7 @@ void *Specinfo(void *argument) len = strlen(operatorArgv()[0]); - if ( (len+1) >= 128 ) cdoAbort("Parameter string to large!"); + if ( (len+1) >= 128 ) cdoAbort("Parameter string too large!"); for ( i = 0; i < len; i++ ) arg[i] = toupper(operatorArgv()[0][i]); arg[len] = 0; diff --git a/src/cdo_int.h b/src/cdo_int.h index cf15b43a21a8d5d01063e786f0b3f5de42190dd7..4ada68e7666eda66f70f58fecb2b7d84daa7a312 100644 --- a/src/cdo_int.h +++ b/src/cdo_int.h @@ -69,6 +69,7 @@ char *strdup(const char *s); #define SET_DATE(dtstr, date, time) (sprintf(dtstr, "%*d%*d", DATE_LEN-6, date, 6, time)) #define DATE_IS_NEQ(dtstr1, dtstr2, len) (memcmp(dtstr1, dtstr2, len) != 0) +enum T_EIGEN_MODE {JACOBI, DANIELSON_LANCZOS}; #if defined(__xlC__) /* performance problems on IBM */ #ifndef DBL_IS_NAN