Commit 5db670e8 authored by Karl Wette's avatar Karl Wette Committed by Reinhard Prix
Browse files

ComputeFstat_Resamp: cleaner encapsulation of timing info output

- XLALGetResampTimingInfo() replaced by global variables Resamp_tauF1Buf
  and Resamp_tauF1NoBuf, updated at end of ComputeFstat_Resamp()
- XLALAppendResampInfo2File() now fully internal, called at end of
  ComputeFstat_Resamp() with file pointer from FstatOptionalArgs
- Refs #2001
Original: e430dd3e8ae740eebc53cad5ab5a87372f1ed959
parent 65679b16
...@@ -472,11 +472,11 @@ XLALCreateFstatInput ( const SFTCatalog *SFTcatalog, ///< [in] Cata ...@@ -472,11 +472,11 @@ XLALCreateFstatInput ( const SFTCatalog *SFTcatalog, ///< [in] Cata
FstatInput_MethodFuncs *funcs = &input->method_funcs; FstatInput_MethodFuncs *funcs = &input->method_funcs;
if ( input->demod != NULL ) if ( input->demod != NULL )
{ {
XLAL_CHECK_NULL ( SetupFstatInput_Demod ( input->demod, common, funcs, multiSFTs ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK_NULL ( SetupFstatInput_Demod ( input->demod, common, funcs, multiSFTs, optArgs ) == XLAL_SUCCESS, XLAL_EFUNC );
} }
else if ( input->resamp != NULL ) else if ( input->resamp != NULL )
{ {
XLAL_CHECK_NULL ( SetupFstatInput_Resamp ( input->resamp, common, funcs, multiSFTs ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK_NULL ( SetupFstatInput_Resamp ( input->resamp, common, funcs, multiSFTs, optArgs ) == XLAL_SUCCESS, XLAL_EFUNC );
} }
else else
{ {
......
...@@ -157,6 +157,7 @@ typedef struct tagFstatOptionalArgs { ...@@ -157,6 +157,7 @@ typedef struct tagFstatOptionalArgs {
MultiNoiseFloor *injectSqrtSX; ///< Single-sided PSD values for fake Gaussian noise to be added to SFT data. MultiNoiseFloor *injectSqrtSX; ///< Single-sided PSD values for fake Gaussian noise to be added to SFT data.
MultiNoiseFloor *assumeSqrtSX; ///< Single-sided PSD values to be used for computing SFT noise weights instead of from a running median of the SFTs themselves. MultiNoiseFloor *assumeSqrtSX; ///< Single-sided PSD values to be used for computing SFT noise weights instead of from a running median of the SFTs themselves.
FstatInput *prevInput; ///< An \c FstatInput structure from a previous call to XLALCreateFstatInput(); may contain common workspace data than can be re-used to save memory. FstatInput *prevInput; ///< An \c FstatInput structure from a previous call to XLALCreateFstatInput(); may contain common workspace data than can be re-used to save memory.
FILE *timingLogFile; ///< Pointer to a file which might be used to log timing information by some \f$\mathcal{F}\f$-statistic methods.
} FstatOptionalArgs; } FstatOptionalArgs;
#ifdef SWIG // SWIG interface directives #ifdef SWIG // SWIG interface directives
SWIGLAL(COPY_CONSTRUCTOR(tagFstatOptionalArgs)); SWIGLAL(COPY_CONSTRUCTOR(tagFstatOptionalArgs));
......
...@@ -303,14 +303,16 @@ static int ...@@ -303,14 +303,16 @@ static int
SetupFstatInput_Demod ( FstatInput_Demod *demod, SetupFstatInput_Demod ( FstatInput_Demod *demod,
FstatInput_Common *common, FstatInput_Common *common,
FstatInput_MethodFuncs* funcs, FstatInput_MethodFuncs* funcs,
MultiSFTVector *multiSFTs MultiSFTVector *multiSFTs,
) const FstatOptionalArgs *optArgs
)
{ {
// Check input // Check input
XLAL_CHECK ( demod != NULL, XLAL_EFAULT ); XLAL_CHECK ( demod != NULL, XLAL_EFAULT );
XLAL_CHECK ( common != NULL, XLAL_EFAULT ); XLAL_CHECK ( common != NULL, XLAL_EFAULT );
XLAL_CHECK ( funcs != NULL, XLAL_EFAULT ); XLAL_CHECK ( funcs != NULL, XLAL_EFAULT );
XLAL_CHECK ( multiSFTs != NULL, XLAL_EFAULT ); XLAL_CHECK ( multiSFTs != NULL, XLAL_EFAULT );
XLAL_CHECK ( optArgs != NULL, XLAL_EFAULT );
// Save pointer to SFTs // Save pointer to SFTs
demod->multiSFTs = multiSFTs; demod->multiSFTs = multiSFTs;
......
...@@ -72,6 +72,10 @@ typedef struct tagResampTimingInfo ...@@ -72,6 +72,10 @@ typedef struct tagResampTimingInfo
REAL8 tauF1NoBuf; // Resampling timing 'constant': Fstat time per template per detector for an 'unbuffered' usage (different skypos and numFreqBins) REAL8 tauF1NoBuf; // Resampling timing 'constant': Fstat time per template per detector for an 'unbuffered' usage (different skypos and numFreqBins)
} ResampTimingInfo; } ResampTimingInfo;
// hidden global variables used to pass timings to test/benchmark programs
REAL8 Resamp_tauF1Buf = 0.0;
REAL8 Resamp_tauF1NoBuf = 0.0;
typedef struct tagResampWorkspace typedef struct tagResampWorkspace
{ {
// intermediate quantities to interpolate and operate on SRC-frame timeseries // intermediate quantities to interpolate and operate on SRC-frame timeseries
...@@ -107,6 +111,8 @@ struct tagFstatInput_Resamp ...@@ -107,6 +111,8 @@ struct tagFstatInput_Resamp
MultiCOMPLEX8TimeSeries *multiTimeSeries_SRC_a; // multi-detector SRC-frame timeseries, multiplied by AM function a(t) MultiCOMPLEX8TimeSeries *multiTimeSeries_SRC_a; // multi-detector SRC-frame timeseries, multiplied by AM function a(t)
MultiCOMPLEX8TimeSeries *multiTimeSeries_SRC_b; // multi-detector SRC-frame timeseries, multiplied by AM function b(t) MultiCOMPLEX8TimeSeries *multiTimeSeries_SRC_b; // multi-detector SRC-frame timeseries, multiplied by AM function b(t)
FILE *timingLogFile; // file to write timing info to
}; };
...@@ -132,10 +138,6 @@ XLALComputeFaFb_Resamp ( ResampWorkspace *ws, ...@@ -132,10 +138,6 @@ XLALComputeFaFb_Resamp ( ResampWorkspace *ws,
const COMPLEX8TimeSeries *TimeSeries_SRC_b const COMPLEX8TimeSeries *TimeSeries_SRC_b
); );
// pseudo-internal: don't export API but allow using them from test/benchmark codes
int XLALAppendResampInfo2File ( FILE *fp, const FstatInput *input );
int XLALGetResampTimingInfo ( REAL8 *tauF1NoBuf, REAL8 *tauF1Buf, const FstatInput *input );
// ==================== function definitions ==================== // ==================== function definitions ====================
/// ///
...@@ -191,40 +193,21 @@ XLALDestroyResampWorkspace ( void *workspace ) ...@@ -191,40 +193,21 @@ XLALDestroyResampWorkspace ( void *workspace )
} // XLALDestroyResampWorkspace() } // XLALDestroyResampWorkspace()
// return resampling timing coefficients 'tauF1' for buffered and unbuffered calls
int
XLALGetResampTimingInfo ( REAL8 *tauF1NoBuf, REAL8 *tauF1Buf, const FstatInput *input )
{
XLAL_CHECK ( input != NULL, XLAL_EINVAL );
XLAL_CHECK ( input->method >= FMETHOD_RESAMP_GENERIC, XLAL_EINVAL );
const FstatInput_Common *common = &input->common;
const ResampWorkspace *ws = (ResampWorkspace*) common->workspace;
const ResampTimingInfo *ti = &(ws->timingInfo);
(*tauF1NoBuf) = ti->tauF1NoBuf;
(*tauF1Buf) = ti->tauF1Buf;
return XLAL_SUCCESS;
} // XLALGetResampTimingInfo()
/// debug/optimizer helper function: dump internal info from resampling code into a file /// debug/optimizer helper function: dump internal info from resampling code into a file
/// if called with input==NULL, output a header-comment-line static void
int AppendResampInfo2File ( FILE *fp, const FstatInput_Common *common, const FstatInput_Resamp *resamp )
XLALAppendResampInfo2File ( FILE *fp, const FstatInput *input )
{ {
XLAL_CHECK ( fp != NULL, XLAL_EINVAL );
if ( input == NULL ) { // print header on first call
static BOOLEAN print_header = 1;
if ( print_header ) {
fprintf (fp, "%%%%%8s %10s %6s %10s %10s ", fprintf (fp, "%%%%%8s %10s %6s %10s %10s ",
"Nfreq", "NsFFT", "Nsft0", "Ns_DET0", "Ns_SRC0" ); "Nfreq", "NsFFT", "Nsft0", "Ns_DET0", "Ns_SRC0" );
fprintf (fp, "%10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s\n", fprintf (fp, "%10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s\n",
"tauTotal", "tauFFT", "tauBary", "tauSpin", "tauAM", "tauNorm", "tauFab2F", "tauMem", "tauSumFabX", "tauF1NoBuf", "tauF1Buf" ); "tauTotal", "tauFFT", "tauBary", "tauSpin", "tauAM", "tauNorm", "tauFab2F", "tauMem", "tauSumFabX", "tauF1NoBuf", "tauF1Buf" );
return XLAL_SUCCESS; print_header = 0;
} }
XLAL_CHECK ( input->method >= FMETHOD_RESAMP_GENERIC, XLAL_EINVAL );
const FstatInput_Resamp *resamp = input->resamp;
const FstatInput_Common *common = &input->common;
const ResampWorkspace *ws = (ResampWorkspace*) common->workspace; const ResampWorkspace *ws = (ResampWorkspace*) common->workspace;
fprintf (fp, "%10d %10d", ws->numFreqBinsOut, ws->numSamplesFFT ); fprintf (fp, "%10d %10d", ws->numFreqBinsOut, ws->numSamplesFFT );
...@@ -238,9 +221,7 @@ XLALAppendResampInfo2File ( FILE *fp, const FstatInput *input ) ...@@ -238,9 +221,7 @@ XLALAppendResampInfo2File ( FILE *fp, const FstatInput *input )
fprintf (fp, "%10.1e %10.1e %10.1e %10.1e %10.1e %10.1e %10.1e %10.1e %10.1e %10.1e %10.1e\n", fprintf (fp, "%10.1e %10.1e %10.1e %10.1e %10.1e %10.1e %10.1e %10.1e %10.1e %10.1e %10.1e\n",
ti->tauTotal, ti->tauFFT, ti->tauBary, ti->tauSpin, 0.0, ti->tauNorm, ti->tauFab2F, ti->tauMem, ti->tauSumFabX, ti->tauF1NoBuf, ti->tauF1Buf ); ti->tauTotal, ti->tauFFT, ti->tauBary, ti->tauSpin, 0.0, ti->tauNorm, ti->tauFab2F, ti->tauMem, ti->tauSumFabX, ti->tauF1NoBuf, ti->tauF1Buf );
return XLAL_SUCCESS; } // AppendResampInfo2File()
} // XLALAppendResampInfo2File()
// ---------- internal functions ---------- // ---------- internal functions ----------
static void static void
...@@ -260,9 +241,10 @@ DestroyFstatInput_Resamp ( FstatInput_Resamp* resamp ) ...@@ -260,9 +241,10 @@ DestroyFstatInput_Resamp ( FstatInput_Resamp* resamp )
static int static int
SetupFstatInput_Resamp ( FstatInput_Resamp *resamp, SetupFstatInput_Resamp ( FstatInput_Resamp *resamp,
FstatInput_Common *common, FstatInput_Common *common,
FstatInput_MethodFuncs* funcs, FstatInput_MethodFuncs* funcs,
MultiSFTVector *multiSFTs MultiSFTVector *multiSFTs,
const FstatOptionalArgs *optArgs
) )
{ {
// Check input // Check input
...@@ -270,6 +252,7 @@ SetupFstatInput_Resamp ( FstatInput_Resamp *resamp, ...@@ -270,6 +252,7 @@ SetupFstatInput_Resamp ( FstatInput_Resamp *resamp,
XLAL_CHECK ( common != NULL, XLAL_EFAULT ); XLAL_CHECK ( common != NULL, XLAL_EFAULT );
XLAL_CHECK ( funcs != NULL, XLAL_EFAULT ); XLAL_CHECK ( funcs != NULL, XLAL_EFAULT );
XLAL_CHECK ( multiSFTs != NULL, XLAL_EFAULT ); XLAL_CHECK ( multiSFTs != NULL, XLAL_EFAULT );
XLAL_CHECK ( optArgs != NULL, XLAL_EFAULT );
// Convert SFTs into heterodyned complex timeseries [in detector frame] // Convert SFTs into heterodyned complex timeseries [in detector frame]
XLAL_CHECK ( (resamp->multiTimeSeries_DET = XLALMultiSFTVectorToCOMPLEX8TimeSeries ( multiSFTs )) != NULL, XLAL_EFUNC ); XLAL_CHECK ( (resamp->multiTimeSeries_DET = XLALMultiSFTVectorToCOMPLEX8TimeSeries ( multiSFTs )) != NULL, XLAL_EFUNC );
...@@ -347,6 +330,13 @@ SetupFstatInput_Resamp ( FstatInput_Resamp *resamp, ...@@ -347,6 +330,13 @@ SetupFstatInput_Resamp ( FstatInput_Resamp *resamp,
funcs->workspace_dtor = XLALDestroyResampWorkspace; funcs->workspace_dtor = XLALDestroyResampWorkspace;
} // end: if we create our own workspace } // end: if we create our own workspace
#ifdef COLLECT_TIMING
// Set up timing log file
resamp->timingLogFile = optArgs->timingLogFile;
#else
resamp->timingLogFile = NULL;
#endif
return XLAL_SUCCESS; return XLAL_SUCCESS;
} // SetupFstatInput_Resamp() } // SetupFstatInput_Resamp()
...@@ -586,6 +576,15 @@ ComputeFstat_Resamp ( FstatResults* Fstats, ...@@ -586,6 +576,15 @@ ComputeFstat_Resamp ( FstatResults* Fstats,
// compute 'fundamental' timing numbers per template per detector // compute 'fundamental' timing numbers per template per detector
ti->tauF1NoBuf = ti->tauTotal / numFreqBins; ti->tauF1NoBuf = ti->tauTotal / numFreqBins;
ti->tauF1Buf = (ti->tauTotal - ti->tauBary - ti->tauMem) / numFreqBins; ti->tauF1Buf = (ti->tauTotal - ti->tauBary - ti->tauMem) / numFreqBins;
// pass out timings to test/benchmark programs
Resamp_tauF1NoBuf = ti->tauF1NoBuf;
Resamp_tauF1Buf = ti->tauF1Buf;
// write timing info to log file
if ( resamp->timingLogFile != NULL ) {
AppendResampInfo2File ( resamp->timingLogFile, common, resamp );
}
#endif #endif
return XLAL_SUCCESS; return XLAL_SUCCESS;
......
...@@ -51,8 +51,9 @@ typedef struct ...@@ -51,8 +51,9 @@ typedef struct
BOOLEAN runBuffered; // only useful for double-checking and Demod timing BOOLEAN runBuffered; // only useful for double-checking and Demod timing
} UserInput_t; } UserInput_t;
int XLALAppendResampInfo2File ( FILE *fp, const FstatInput *input ); // hidden global variables used to pass timings to test/benchmark programs
int XLALGetResampTimingInfo ( REAL8 *tauF1NoBuf, REAL8 *tauF1Buf, const FstatInput *input ); extern REAL8 Resamp_tauF1Buf;
extern REAL8 Resamp_tauF1NoBuf;
// ---------- main ---------- // ---------- main ----------
int int
...@@ -160,13 +161,6 @@ main ( int argc, char *argv[] ) ...@@ -160,13 +161,6 @@ main ( int argc, char *argv[] )
LIGOTimeGPS endTime = endTime_l; LIGOTimeGPS endTime = endTime_l;
UINT4 numSFTsPerSeg = catalogs[0]->length; UINT4 numSFTsPerSeg = catalogs[0]->length;
FILE *fpInfo = NULL;
if ( (uvar->outputInfo != NULL) && (FstatMethod == FMETHOD_RESAMP_GENERIC) )
{
XLAL_CHECK ( (fpInfo = fopen (uvar->outputInfo, "ab")) != NULL, XLAL_ESYS, "Failed to open '%s' for appending\n", uvar->outputInfo );
XLALAppendResampInfo2File ( fpInfo, NULL ); // create header comment line
}
PulsarSpinRange XLAL_INIT_DECL(spinRange); PulsarSpinRange XLAL_INIT_DECL(spinRange);
LIGOTimeGPS refTime = { startTime.gpsSeconds - 2.3 * uvar->Tseg, 0 }; LIGOTimeGPS refTime = { startTime.gpsSeconds - 2.3 * uvar->Tseg, 0 };
spinRange.refTime = refTime; spinRange.refTime = refTime;
...@@ -195,6 +189,11 @@ main ( int argc, char *argv[] ) ...@@ -195,6 +189,11 @@ main ( int argc, char *argv[] )
optionalArgs.injectSqrtSX = &injectSqrtSX; optionalArgs.injectSqrtSX = &injectSqrtSX;
optionalArgs.FstatMethod = FstatMethod; optionalArgs.FstatMethod = FstatMethod;
if ( (uvar->outputInfo != NULL) && (FstatMethod == FMETHOD_RESAMP_GENERIC) )
{
XLAL_CHECK ( (optionalArgs.timingLogFile = fopen (uvar->outputInfo, "ab")) != NULL, XLAL_ESYS, "Failed to open '%s' for appending\n", uvar->outputInfo );
}
FstatInputVector *inputs; FstatInputVector *inputs;
FstatQuantities whatToCompute = (FSTATQ_2F | FSTATQ_2F_PER_DET); FstatQuantities whatToCompute = (FSTATQ_2F | FSTATQ_2F_PER_DET);
FstatResults *results = NULL; FstatResults *results = NULL;
...@@ -239,13 +238,8 @@ main ( int argc, char *argv[] ) ...@@ -239,13 +238,8 @@ main ( int argc, char *argv[] )
XLAL_CHECK ( XLALComputeFstat ( &results, inputs->data[l], &Doppler, numFreqBins_i, whatToCompute ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALComputeFstat ( &results, inputs->data[l], &Doppler, numFreqBins_i, whatToCompute ) == XLAL_SUCCESS, XLAL_EFUNC );
// ----- output timing details if requested // ----- output timing details if requested
if ( (fpInfo != NULL) ) { tauF1NoBuf_i += Resamp_tauF1NoBuf;
XLALAppendResampInfo2File ( fpInfo, inputs->data[l] ); tauF1Buf_i += Resamp_tauF1Buf;
}
REAL8 tauF1NoBuf_il, tauF1Buf_il;
XLAL_CHECK ( XLALGetResampTimingInfo ( &tauF1NoBuf_il, &tauF1Buf_il, inputs->data[l] ) == XLAL_SUCCESS, XLAL_EFUNC );
tauF1NoBuf_i += tauF1NoBuf_il;
tauF1Buf_i += tauF1Buf_il;
} // for l < numSegments } // for l < numSegments
tauF1NoBuf_i /= uvar->numSegments; tauF1NoBuf_i /= uvar->numSegments;
...@@ -268,8 +262,8 @@ main ( int argc, char *argv[] ) ...@@ -268,8 +262,8 @@ main ( int argc, char *argv[] )
fprintf (stderr, "\nAveraged timings: <tauF1Buf> = %.2g s, <tauF1NoBuf> = %.2g s\n", tauF1Buf, tauF1NoBuf ); fprintf (stderr, "\nAveraged timings: <tauF1Buf> = %.2g s, <tauF1NoBuf> = %.2g s\n", tauF1Buf, tauF1NoBuf );
// ----- free memory ---------- // ----- free memory ----------
if ( fpInfo != NULL ) { if ( optionalArgs.timingLogFile != NULL ) {
fclose ( fpInfo ); fclose ( optionalArgs.timingLogFile );
} }
for ( INT4 l = 0; l < uvar->numSegments; l ++ ) for ( INT4 l = 0; l < uvar->numSegments; l ++ )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment