104 #include <lal/FileIO.h>
105 #include <lal/LALgetopt.h>
106 #include <lal/StringInput.h>
115 fprintf(stderr,
"\nlal_fftwf_wisdom -i INPUT_FILE -o OUTPUT_FILE [OPTIONS]:\n");
116 fprintf(stderr,
"This program creates a wisdom file based on an input file specifying transform\n");
117 fprintf(stderr,
"kinds and sizes. This is much like a simplified version of the fftwf-wisdom\n");
118 fprintf(stderr,
"utility provided with FFTW. The transforms to be planned for must be specified\n");
119 fprintf(stderr,
"through the input file, one transform per line, using the format:\n");
120 fprintf(stderr,
" <type><direction><size>\n");
122 fprintf(stderr,
" <type> is 'r' or 'c' for real or complex\n");
123 fprintf(stderr,
" <direction> is 'f' or either 'b' or 'r' for forward or backward/reverse\n");
124 fprintf(stderr,
" <size> is the size of the transform\n");
125 fprintf(stderr,
"Backward and reverse are synonymous, and <type> and <direction> are not case-\n");
126 fprintf(stderr,
"sensitive. For further details and warnings, see the doxygen documentation.\n");
128 fprintf(stderr,
"Options and their behavior are:\n");
130 fprintf(stderr,
" --measurelvl=, -l <int> The measurelvl argument to plan creation calls. The\n");
131 fprintf(stderr,
" lowest level of zero corresponds to no planning,\n");
132 fprintf(stderr,
" whereas the highest level of 3 could take days, de-\n");
133 fprintf(stderr,
" pending on the transform size. Defaults to 3.\n");
134 fprintf(stderr,
" --input=, -i <file> Input file containing transforms to plan. Mandatory.\n");
135 fprintf(stderr,
" --output=, -o <file> File in which to save generated wisdom. Mandatory.\n");
136 fprintf(stderr,
" --wisdom=, -w <file> Existing wisdom file to import. Program exits if this\n");
137 fprintf(stderr,
" option is given but the file is unreadable. Optional.\n");
138 fprintf(stderr,
" --no-system-wisdom, -n By default, system wisdom file /etc/fftw/wisdomf is \n");
139 fprintf(stderr,
" imported. If this option is specified, that import is\n");
140 fprintf(stderr,
" disabled. If the system file is not present or not \n");
141 fprintf(stderr,
" readable, a warning is printed but execution continues.\n");
142 fprintf(stderr,
" --help, -h Print this help message and exit.\n");
143 fprintf(stderr,
"In addition to writing the accumulated wisdom to the specified output file, the\n");
144 fprintf(stderr,
"program also prints to stdout a human-readable description of the wisdom success-\n");
145 fprintf(stderr,
"fully created during this invocation. That description should be appended to the\n");
146 fprintf(stderr,
"corresponding description for any wisdom files (including system) read in.\n");
156 UINT4 transform_size,
159 fftwf_plan genericPlan;
160 void *indata, *outdata;
161 int fwdflag, planning_flags;
163 fwdflag = ( (direc==
'f') || (direc==
'F') );
171 planning_flags = FFTW_UNALIGNED;
176 planning_flags |= FFTW_ESTIMATE;
180 planning_flags |= FFTW_EXHAUSTIVE;
182 #if __GNUC__ >= 7 && !defined __INTEL_COMPILER
186 planning_flags |= FFTW_PATIENT;
188 #if __GNUC__ >= 7 && !defined __INTEL_COMPILER
192 planning_flags |= FFTW_MEASURE;
198 if ( (type==
'r') || (type==
'R') )
201 indata = (
float *) fftwf_malloc(transform_size*
sizeof(
float));
202 outdata = (
float *) fftwf_malloc(transform_size*
sizeof(
float));
204 if ( (!indata) || (!outdata) )
206 if (indata) fftwf_free(indata);
207 if (outdata) fftwf_free(outdata);
211 genericPlan = fftwf_plan_r2r_1d(transform_size,indata,outdata,
212 (fwdflag ? FFTW_R2HC : FFTW_HC2R),
224 fftwf_destroy_plan(genericPlan);
231 indata = (fftwf_complex *) fftwf_malloc(transform_size*
sizeof(fftwf_complex));
232 outdata = (fftwf_complex *) fftwf_malloc(transform_size*
sizeof(fftwf_complex));
234 if ( (!indata) || (!outdata) )
236 if (indata) fftwf_free(indata);
237 if (outdata) fftwf_free(outdata);
241 genericPlan = fftwf_plan_dft_1d(transform_size,indata,outdata,
242 (fwdflag ? FFTW_FORWARD : FFTW_BACKWARD),
255 fftwf_destroy_plan(genericPlan);
270 int main(
int argc,
char **argv)
272 static int measurelvl=3;
274 UINT4 transform_size;
275 char input_line[LINE_MAX];
278 FILE *infp=NULL, *outfp=NULL, *wisfp=NULL;
279 int optindex, optreturn, retval;
294 while ( (optreturn =
LALgetopt_long(argc,argv,
"ni:o:w:l:h",long_options,&optindex)) != -1)
325 fprintf(stderr,
"Error: Could not open input wisdom file %s for reading\n",
LALoptarg);
332 retval = fftwf_import_wisdom_from_file(wisfp);
336 fprintf(stderr,
"Error: Could not read wisdom from input wisdom file %s\n",
LALoptarg);
347 if ( sscanf(
LALoptarg,
"%d",&measurelvl) != 1)
354 if ( (measurelvl<0) || (measurelvl>3) )
356 fprintf(stderr,
"Error: invalid measure level %d.\n",measurelvl);
374 fprintf(stderr,
"Error: You must specify an input file with -i <FILE> or --input=<FILE>\n");
381 fprintf(stderr,
"Error: You must specify an output file with -o <FILE> or --output=<FILE>\n");
390 retval = fftwf_import_system_wisdom();
394 fprintf(stderr,
"Warning: Could not import system wisdom file /etc/fftw/wisdomf\n");
399 fprintf(stderr,
"Skipped import of system wisdom file /etc/fftw/wisdomf\n");
405 while ( (fgets(input_line,LINE_MAX,infp) != NULL) )
407 if (sscanf(input_line,
"%c%c%" LAL_UINT4_FORMAT, &type, &direc, &transform_size) == 3)
410 if ( !( (type==
'r') || (type==
'R') || (type==
'c') || (type==
'C') ) )
412 fprintf(stderr,
"Error: Invalid type specifier %c; must be 'r' (real) or 'c' (complex). ",type);
415 else if ( !( (direc==
'f') || (direc==
'b') || (direc==
'r') || (direc==
'F') || (direc==
'B') || (direc==
'R') ) )
417 fprintf(stderr,
"Error: Invalid direction specifier %c; must be 'f' (forward) or 'b'/'r' (backward/reverse). ",
423 retval =
plan_problem(type,direc,transform_size,measurelvl);
427 type,direc,transform_size);
432 " with measure level %d and FFTW_UNALIGNED\n",
433 ( (type==
'r') || (type==
'R') ) ?
"REAL4" :
"COMPLEX8",
434 ( (direc==
'f') || (direc==
'F') ) ?
"forward" :
"reverse",
435 transform_size, measurelvl);
441 fprintf(stderr,
"Error: Invalid problem specifier. Problem: %s will be skipped\n",input_line);
445 fftwf_export_wisdom_to_file(outfp);
int LALgetopt_long(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
#define required_argument
int main(int argc, char **argv)
Main function.
void print_help(void)
Print basic usage information about the program and exit.
int plan_problem(char type, char direc, UINT4 transform_size, int measurelvl)
Function used only internally, to create an FFTW plan for a specified problem (thereby adding to wisd...
uint32_t UINT4
Four-byte unsigned integer.