Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALInference 4.1.9.1-8a6b96f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
LALInferenceBench.c
Go to the documentation of this file.
1/*
2 * LALInferenceBench.c: Benchmark LALInference functions
3 *
4 * Copyright (C) 2015 John Veitch
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with with program; see the file COPYING. If not, write to the
19 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 * MA 02110-1301 USA
21 */
22
23#include <stdio.h>
24#include <lal/LALInference.h>
25#include <lal/LALInferenceInit.h>
26#include <lal/LALInferenceReadData.h>
27#include <lal/LALInferenceCalibrationErrors.h>
28#include <lal/LALInferenceLikelihood.h>
29#include <lal/LALInferenceTemplate.h>
30#include <sys/resource.h>
31
32#ifdef __GNUC__
33#define UNUSED __attribute__ ((unused))
34#else
35#define UNUSED
36#endif
37
38const char HELPSTR[]=\
39"lalinference_bench: Benchmark template and likelihood functions.\n\
40 Options:\n\
41 --Niter : Number of calls to time (delfault 1000) \n\
42 --bench-template : Only benchmark template function\n\
43 --bench-likelihood : Only benchmark likelihood function\n\
44 (defaults to benchmarking both)\n\
45 Example (for 1.0-1.0 binary with seglen 8, srate 4096): \n\
46 $ ./lalinference_bench --psdlength 1000 --psdstart 1 --seglen 8 --srate 4096 --trigtime 0 --ifo H1 --H1-channel LALSimAdLIGO --H1-cache LALSimAdLIGO --dataseed 1324 --Niter 10000 --fix-chirpmass 1.218 --fix-q 1.0\n\n\n\
47";
48
49void fprintf_bench(FILE *fp, struct rusage start, struct rusage end, UINT4 Niter);
50void fprintf_bench(FILE *fp, struct rusage start, struct rusage end, UINT4 Niter)
51{
52 REAL8 utime = (end.ru_utime.tv_sec - start.ru_utime.tv_sec) + 1e-6 * (end.ru_utime.tv_usec - start.ru_utime.tv_usec);
53 REAL8 stime = (end.ru_stime.tv_sec - start.ru_stime.tv_sec) + 1e-6 * (end.ru_stime.tv_usec - start.ru_stime.tv_usec);
54
55 fprintf(fp,"USER Total: %lf s\n",utime);
56 fprintf(fp,"USER Per iteration: %e s\n",utime / (double) Niter);
57
58 fprintf(fp,"SYS Total: %lf s\n",stime);
59 fprintf(fp,"SYS Per iteration: %e s\n",stime / (double) Niter);
60}
61
64{
65 return;
66}
67
68void bench_likelihood(LALInferenceRunState *runState,UINT4 Niter);
70{
71 UINT4 i=0;
72 struct rusage r_usage_start,r_usage_end;
73
74 /* Clear the template */
76
77 LALInferenceTemplateFunction old_templt=runState->threads[0].model->templt;
79
80 fprintf(stdout,"Benchmarking likelihood:\n");
81 getrusage(RUSAGE_SELF, &r_usage_start);
82 for(i=0;i<Niter;i++)
83 {
84 runState->likelihood(runState->threads[0].model->params,runState->data, runState->threads[0].model);
85 }
86 getrusage(RUSAGE_SELF, &r_usage_end);
87 fprintf_bench(stdout, r_usage_start, r_usage_end, Niter);
88 runState->threads[0].model->templt=old_templt;
89
90}
91
92void bench_template(LALInferenceRunState *runState, UINT4 Niter);
94{
95 UINT4 i=0;
96 struct rusage r_usage_start,r_usage_end;
97 fprintf(stdout,"Benchmarking template:\n");
98 getrusage(RUSAGE_SELF, &r_usage_start);
99 for(i=0;i<Niter;i++)
100 {
101 runState->threads[0].model->templt(runState->threads[0].model);
102 }
103 getrusage(RUSAGE_SELF, &r_usage_end);
104 fprintf_bench(stdout, r_usage_start, r_usage_end, Niter);
105}
106
107int main(int argc, char *argv[]){
108 ProcessParamsTable *procParams = NULL,*ppt=NULL;
109 LALInferenceRunState *runState=NULL;
110 UINT4 Niter=1000;
111 UINT4 bench_L=1;
112 UINT4 bench_T=1;
113 int helpflag=0;
114 procParams=LALInferenceParseCommandLine(argc,argv);
115
116 if(LALInferenceGetProcParamVal(procParams,"--help"))
117 {
118 fprintf(stdout,"%s",HELPSTR);
119 bench_T=bench_L=0;
120 helpflag=1;
121 }
122 if((ppt=LALInferenceGetProcParamVal(procParams,"--Niter")))
123 Niter=atoi(ppt->value);
124 if(LALInferenceGetProcParamVal(procParams,"--bench-template"))
125 {
126 bench_T=1; bench_L=0;
127 }
128 if(LALInferenceGetProcParamVal(procParams,"--bench-likelihood"))
129 {
130 bench_T=0; bench_L=1;
131 }
132
133
134 runState = LALInferenceInitRunState(procParams);
135
136 if(runState && !helpflag) {
138
139 /* Simulate calibration errors */
141 }
142
143 /* Set up the template and likelihood functions */
144 LALInferenceInitCBCThreads(runState,1);
146
147 /* Disable waveform caching */
148 if (!helpflag) runState->threads[0].model->waveformCache=NULL;
149
150 if(bench_T)
151 {
152 printf("Template test will run with parameters:\n");
154 printf("\n");
155
156 bench_template(runState,Niter);
157 printf("\n");
158 }
159 if(bench_L)
160 {
161 bench_likelihood(runState,Niter);
162 printf("\n");
163 }
164
165 return(0);
166}
ProcessParamsTable * LALInferenceParseCommandLine(int argc, char *argv[])
void bench_likelihood(LALInferenceRunState *runState, UINT4 Niter)
int main(int argc, char *argv[])
void LALInferenceTemplateNoop(UNUSED LALInferenceModel *model)
void bench_template(LALInferenceRunState *runState, UINT4 Niter)
void fprintf_bench(FILE *fp, struct rusage start, struct rusage end, UINT4 Niter)
const char HELPSTR[]
void LALInferenceApplyCalibrationErrors(LALInferenceIFOData *IFOdata, ProcessParamsTable *commandLine)
LALInferenceRunState * LALInferenceInitRunState(ProcessParamsTable *command_line)
void LALInferenceInitCBCThreads(LALInferenceRunState *run_state, INT4 nthreads)
void LALInferenceInjectInspiralSignal(LALInferenceIFOData *IFOdata, ProcessParamsTable *commandLine)
ProcessParamsTable * ppt
#define fprintf
double e
double REAL8
uint32_t UINT4
ProcessParamsTable * LALInferenceGetProcParamVal(ProcessParamsTable *procparams, const char *name)
Returns the element of the process params table with "name".
void(* LALInferenceTemplateFunction)(struct tagLALInferenceModel *model)
Type declaration for template function, which operates on a LALInferenceIFOData structure *data.
Definition: LALInference.h:377
void LALInferencePrintVariables(LALInferenceVariables *var)
output contents of a 'LALInferenceVariables' structure * / / * (by now only prints names and types,...
Definition: LALInference.c:798
void LALInferenceInitLikelihood(LALInferenceRunState *runState)
Initialisation function which reads runState->commaneLine and sets up the likelihood function accordi...
void LALInferenceTemplateNullFreqdomain(LALInferenceModel *model)
Returns a frequency-domain 'null' template (all zeroes, implying no signal present).
end
start
Structure to constain a model and its parameters.
Definition: LALInference.h:436
LALSimInspiralWaveformCache * waveformCache
Definition: LALInference.h:458
LALInferenceVariables * params
Definition: LALInference.h:437
LALInferenceTemplateFunction templt
Domain of model.
Definition: LALInference.h:440
Structure containing inference run state This includes pointers to the function types required to run...
Definition: LALInference.h:592
ProcessParamsTable * commandLine
Definition: LALInference.h:593
struct tagLALInferenceIFOData * data
Log sample, i.e.
Definition: LALInference.h:601
LALInferenceThreadState * threads
Definition: LALInference.h:612
LALInferenceLikelihoodFunction likelihood
MultiNest prior for the parameters.
Definition: LALInference.h:599
LALInferenceModel * model
Cycle of proposals to call.
Definition: LALInference.h:548
CHAR value[LIGOMETA_VALUE_MAX]
FILE * fp