LALPulsar  6.1.0.1-fe68b98
ComputeFstat_Resamp_internal.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2013--2015, 2020 Karl Wette
3 // Copyright (C) 2015 Reinhard Prix
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with with program; see the file COPYING. If not, write to the
17 // Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 // MA 02110-1301 USA
19 //
20 
21 #include "config.h"
22 
23 #include <lal/ComputeFstat.h>
24 
25 // ============================================================================================================ //
26 // //
27 // This file should **ONLY** contain definitions that **MUST** be shared between F-statistic resampling methods //
28 // //
29 // ============================================================================================================ //
30 
31 // ---------- Shared constants/defines ---------- //
32 
33 // ---------- Shared macro definitions ---------- //
34 
35 // local macro versions of library functions to avoid calling external functions in GPU-ready code
36 #define GPSDIFF(x,y) (1.0*((x).gpsSeconds - (y).gpsSeconds) + ((x).gpsNanoSeconds - (y).gpsNanoSeconds)*1e-9)
37 #define GPSGETREAL8(x) ( (x)->gpsSeconds + ( (x)->gpsNanoSeconds / XLAL_BILLION_REAL8 ) );
38 #define GPSSETREAL8(gps,r8) do { \
39  (gps).gpsSeconds = (UINT4)floor(r8); \
40  (gps).gpsNanoSeconds = (UINT4)round ( ((r8) - (gps).gpsSeconds) * XLAL_BILLION_REAL8 ); \
41  if ( (gps).gpsNanoSeconds == XLAL_BILLION_INT4 ) { \
42  (gps).gpsSeconds += 1; \
43  (gps).gpsNanoSeconds = 0; \
44  } \
45  } while(0)
46 
47 // ---------- Shared global variables ---------- //
48 
49 // ---------- Shared struct definitions ---------- //
50 
51 // ---------- BEGIN: Resamp-specific timing model data ----------
52 typedef struct tagTimings_t {
53  REAL4 Total; // total time spent in XLALComputeFstatResamp()
54  REAL4 Bary; // time spent (in this call) in barycentric resampling
55  REAL4 Spin; // time spent in spindown+frequency correction
56  REAL4 FFT; // time spent in FFT
57  REAL4 Copy; // time spent copying results from FFT to FabX
58  REAL4 Norm; // time spent normalizing the final Fa,Fb
59  REAL4 Fab2F; // time to compute Fstat from {Fa,Fb}
60  REAL4 Mem; // time to realloc and Memset-0 arrays
61  REAL4 SumFabX; // time to sum_X Fab^X
62  BOOLEAN BufferRecomputed; // did we need to recompute the buffer this time?
63 } Timings_t;
64 
65 // Resamp-specific timing model data
66 typedef struct tagFstatTimingResamp {
67  UINT4 NsampFFT0; // original number of FFT samples (not rounded to power-of-two)
68  UINT4 NsampFFT; // actual number of FFT samples (rounded up to power-of-two if optArgs->resampFFTPowerOf2 == true)
69  REAL4 Resolution; // (internal) frequency resolution 'R' in natural units: df_internal = R / T_FFT\n
70 
71  REAL4 tau0_Fbin; // timing coefficient for all contributions scaling with output frequency-bins
72  REAL4 tau0_spin; // timing coefficient for spindown-correction
73  REAL4 tau0_FFT; // timing coefficient for FFT-time
74  REAL4 tau0_bary; // timing coefficient for barycentering
75 
77 
79 
80 static const char FstatTimingResampHelp[] =
81  "%%%% ----- Resampling-specific timing model -----\n"
82  "%%%% NsampFFT0: original number of FFT samples (not yet rounded up to power-of-two)\n"
83  "%%%% NsampFFT: actual number of FFT samples (rounded to power-of-two if optArgs->resampFFTPowerOf2 == true)\n"
84  "%%%% R: (internal) frequency resolution in natural units: df_internal = R / T_FFT\n"
85  "%%%%\n"
86  "%%%% tau0_Fbin: timing coefficient for all contributions scaling with output frequency-bins\n"
87  "%%%% tau0_spin: timing coefficient for spindown-correction\n"
88  "%%%% tau0_FFT: timing coefficient for FFT-time\n"
89  "%%%% tau0_bary: timing coefficient for barycentering\n"
90  "%%%%\n"
91  "%%%% Resampling F-statistic timing model:\n"
92  "%%%% tauF_core = tau0_Fbin + (NsampFFT/NFbin) * ( R * tau0_spin + 5 * log2(NsampFFT) * tau0_FFT )\n"
93  "%%%% tauF_buffer = R * NsampFFT * tau0_bary / NFbin\n"
94  "%%%%"
95  "";
96 // ---------- END: Resamp-specific timing model data ----------
97 
98 // ---------- Shared internal functions ---------- //
99 
100 static int
102 {
103  XLAL_CHECK( tiRS != NULL, XLAL_EINVAL );
104  XLAL_CHECK( timingModel != NULL, XLAL_EINVAL );
105 
106  // return method-specific timing model values
107  XLAL_INIT_MEM( ( *timingModel ) );
108 
109  UINT4 i = 0;
110  timingModel->names[i] = "NsampFFT0";
111  timingModel->values[i] = tiRS->NsampFFT0;
112 
113  i++;
114  timingModel->names[i] = "NsampFFT";
115  timingModel->values[i] = tiRS->NsampFFT;
116 
117  i++;
118  timingModel->names[i] = "Resolution";
119  timingModel->values[i] = tiRS->Resolution;
120 
121  i++;
122  timingModel->names[i] = "tau0_Fbin";
123  timingModel->values[i] = tiRS->tau0_Fbin;
124 
125  i++;
126  timingModel->names[i] = "tau0_spin";
127  timingModel->values[i] = tiRS->tau0_spin;
128 
129  i++;
130  timingModel->names[i] = "tau0_FFT";
131  timingModel->values[i] = tiRS->tau0_FFT;
132 
133  i++;
134  timingModel->names[i] = "tau0_bary";
135  timingModel->values[i] = tiRS->tau0_bary;
136 
137  timingModel->numVariables = i + 1;
138  timingModel->help = FstatTimingResampHelp;
139 
140  return XLAL_SUCCESS;
141 } // XLALGetFstatTiming_Resamp_intern()
static const char FstatTimingResampHelp[]
static int XLALGetFstatTiming_Resamp_intern(const FstatTimingResamp *tiRS, FstatTimingModel *timingModel)
unsigned char BOOLEAN
#define XLAL_INIT_MEM(x)
uint32_t UINT4
float REAL4
#define XLAL_CHECK(assertion,...)
XLAL_SUCCESS
XLAL_EINVAL
Struct to carry the -statistic method-specific timing model in terms of a list of variable names and...
Definition: ComputeFstat.h:326
REAL4 values[TIMING_MODEL_MAX_VARS]
Definition: ComputeFstat.h:329
const char * help
Definition: ComputeFstat.h:330
const char * names[TIMING_MODEL_MAX_VARS]
Definition: ComputeFstat.h:328