MIDAPACK - MIcrowave Data Analysis PACKage  1.1b
Parallel software tools for high performance CMB DA analysis
 All Data Structures Files Functions Variables Typedefs Groups Pages
toeplitz.h
Go to the documentation of this file.
1 
59 #ifndef TOEPLITZ_H_
60 #define TOEPLITZ_H_
61 
62 #ifdef W_MPI
63 #include <mpi.h>
64 #endif
65 
66 #ifdef W_OPENMP
67 #include <omp.h>
68 #endif
69 
70 #include <fftw3.h>
71 #include <stdlib.h>
72 #include <stdio.h>
73 #include <math.h>
74 #include <string.h>
75 
76 //=========================================================================
77 //Basic functions definition
78 #define max(a,b) (((a) > (b)) ? (a) : (b))
79 #define min(a,b) (((a) < (b)) ? (a) : (b))
80 
81 //=========================================================================
82 //Fixed parameters
83 
84 
86 
88 #ifndef MPI_USER_TAG
89 #define MPI_USER_TAG 123
90 #endif
91 
92 //Define this parameter to use fftw multithreading
93 //This is not fully tested
94 #ifndef fftw_MULTITHREADING
95 #define fftw_MULTITHREADING
96 #endif
97 
99 
101 #ifndef NFFT_DEFAULT
102 #define NFFT_DEFAULT 1 /*1*/
103 #endif
104 
105 
107 
111 #ifndef FFTW_FLAG_AUTO
112 #define FFTW_FLAG_AUTO FFTW_ESTIMATE
113 #endif
114 
115 
116 //Parameters to define the computational strategy
117 #ifndef FLAG_STGY
118 #define FLAG_STGY
119 
120 #define FLAG_BS 0 //0:auto 1:fixed 2:zero 3:3lambda 4:4lambda 5:formula2
121 #define FLAG_NFFT 0 //0:auto 1:fixed 2:numthreads 3:fftwthreads
122 #define FLAG_FFTW FFTW_FLAG_AUTO //ESTIMATE, MEASURE, PATIENT, EXHAUSTIVE. Default is MEASURE
123 #define FLAG_NO_RSHP 0 //0:auto 1:yes 1:no
124 #define FLAG_NOFFT 0 //0:auto 1:yes 1:no
125 #define FLAG_BLOCKINGCOMM 0 //0:auto 1:noblocking 2:blocking
126 #define FIXED_NFFT 0 //fixed init value for nfft
127 #define FIXED_BS 0 //fixed init value for blockside
128 #define FLAG_VERBOSE 0
129 #define FLAG_SKIP_BUILD_GAPPY_BLOCKS 0
130 #define FLAG_PARAM_DISTMIN_FIXED 0
131 #define FLAG_PRECOMPUTE_LVL 0 //0: no precompute 1: precompute plans 2: precomputes Toeplitz and plans
132 
133 #endif
134 
135 //=========================================================================
136 //Global parameters
137 
138 extern int VERBOSE;
139 extern int PRINT_RANK;
140 
141 //=========================================================================
142 //Strutures definition
143 
144 
145 typedef struct Block {
146  int64_t idv;
147  double *T_block; //pointer of the Toeplitz data
148  int lambda;
149  int n;
150 /* For precomputed fftw
151  int bs;
152  int nfft;
153  fftw_complex *T_fft;
154  fftw_complex *V_fft;
155  double *V_rfft;
156  fftw_plan plan_f;
157  fftw_plan plan_b;
158  fftw_plan plan_f_T;
159 */
160 } Block;
161 
162 
163 typedef struct Flag {
164  int flag_bs; //bs used formula
165  int flag_nfft;
167  int flag_no_rshp; //with or without
170  int fixed_nfft; //init value for nfft
171  int fixed_bs; //long long int
176 } Flag;
177 
178 typedef struct Gap {
179  int64_t *id0gap;
180  int *lgap;
181  int ngap;
182 } Gap;
183 
184 
185 typedef struct Tpltz {
186  int64_t nrow; //n total
187  int m_cw; //V column number in the linear row-wise order (vect row-wise order)
188  int m_rw; //V column number in the uniform row-wise order (matrix row-wise order)
192  int64_t idp;
195  MPI_Comm comm;
196 } Tpltz;
197 
198 
199 //=========================================================================
200 //Groups definition for documentation
201 
248 //=========================================================================
249 // User routines definition (API)
250 
251 //Wizard routines
252 int stbmmProd( Tpltz Nm1, double *V);
253 
254 
255 //Sequential routines (group 11)
256 int tpltz_init(int n, int lambda, int *nfft, int *blocksize, fftw_complex **T_fft, double *T, fftw_complex **V_fft, double **V_rfft, fftw_plan *plan_f, fftw_plan *plan_b, Flag flag_stgy);
257 
258 int tpltz_cleanup(fftw_complex **T_fft, fftw_complex **V_fft, double **V_rfft,fftw_plan *plan_f, fftw_plan *plan_b);
259 
260 int stmm_core(double **V, int n, int m, double *T, fftw_complex *T_fft, int blocksize, int lambda, fftw_complex *V_fft, double *V_rfft, int nfft, fftw_plan plan_f, fftw_plan plan_b, int flag_offset, int flag_nofft);
261 
262 int stmm_main(double **V, int n, int m, int id0, int l, double *T, fftw_complex *T_fft, int lambda, fftw_complex *V_fft, double *V_rfft, fftw_plan plan_f, fftw_plan plan_b, int blocksize, int nfft, Flag flag_stgy);
263 
264 int stmm(double **V, int n, int m, double *T, int lambda, Flag flag_stgy);
265 
266 //int stbmm(double **V, int nrow, int m, int m_rowwise, Block *tpltzblocks, int nb_blocks_local, int nb_blocks_all, int idp, int local_V_size, Flag flag_stgy);
267 
268 //int gstbmm(double **V, int nrow, int m, int m_rowwise, Block *tpltzblocks, int nb_blocks_local, int nb_blocks_all, int id0p, int local_V_size, int *id0gap, int *lgap, int ngap,Flag flag_stgy);
269 
270 int stbmm(double **V, int nrow, int m_cw, int m_rw, Block *tpltzblocks, int nb_blocks, int64_t idp, int local_V_size, Flag flag_stgy);
271 
272 int gstbmm(double **V, int nrow, int m_cw, int m_rw, Block *tpltzblocks, int nb_blocks, int64_t idp, int local_V_size, int64_t *id0gap, int *lgap, int ngap, Flag flag_stgy);
273 
274 
275 int reset_gaps(double **V, int id0,int local_V_size, int m, int nrow, int m_rowwise, int64_t *id0gap, int *lgap, int ngap);
276 
277 
278 //Mpi routines (group 12)
279 #ifdef W_MPI
280 int mpi_stmm(double **V, int n, int m, int id0, int l, double *T, int lambda, Flag flag_stgy, MPI_Comm comm);
281 
282 int mpi_stbmm(double **V, int64_t nrow, int m, int m_rowwise, Block *tpltzblocks, int nb_blocks_local, int nb_blocks_all, int64_t idp, int local_V_size, Flag flag_stgy, MPI_Comm comm);
283 
284 int mpi_gstbmm(double **V, int nrow, int m, int m_rowwise, Block *tpltzblocks, int nb_blocks_local, int nb_blocks_all, int id0p, int local_V_size, int64_t *id0gap, int *lgap, int ngap, Flag flag_stgy, MPI_Comm comm);
285 
286 #endif
287 
288 
289 //=========================================================================
290 // User routines definition
291 
292 //Low level routines (group 21)
293 int flag_stgy_init_auto(Flag *flag_stgy);
294 
295 int flag_stgy_init_zeros(Flag *flag_stgy);
296 
297 int flag_stgy_init_defined(Flag *flag_stgy);
298 
299 int print_flag_stgy_init(Flag flag_stgy);
300 
301 int define_blocksize(int n, int lambda, int bs_flag, int fixed_bs);
302 
303 int define_nfft(int n_thread, int flag_nfft, int fixed_nfft);
304 
306 
307 int rhs_init_fftw(int *nfft, int fft_size, fftw_complex **V_fft, double **V_rfft, fftw_plan *plan_f, fftw_plan *plan_b, int fftw_flag);
308 
309 int circ_init_fftw(double *T, int fft_size, int lambda, fftw_complex **T_fft);
310 
311 int scmm_direct(int fft_size, int nfft, fftw_complex *C_fft, int ncol, double *V_rfft, double **CV, fftw_complex *V_fft, fftw_plan plan_f_V, fftw_plan plan_b_CV);
312 
313 int scmm_basic(double **V, int blocksize, int m, fftw_complex *C_fft, double **CV, fftw_complex *V_fft, double *V_rfft, int nfft, fftw_plan plan_f_V, fftw_plan plan_b_CV);
314 
315 int stmm_simple_basic(double **V, int n, int m, double *T, int lambda, double **TV);
316 
317 int build_gappy_blocks(int nrow, int m, Block *tpltzblocks, int nb_blocks_local, int nb_blocks_all, int64_t *id0gap, int *lgap, int ngap, Block *tpltzblocks_gappy, int *nb_blocks_gappy_final, int flag_param_distmin_fixed);
318 
319 
320 //Internal routines (group 22)
321 int print_error_message(int error_number, char const *file, int line);
322 
323 int copy_block(int ninrow, int nincol, double *Vin, int noutrow, int noutcol, double *Vout, int inrow, int incol, int nblockrow, int nblockcol, int outrow, int outcol, double norm, int set_zero_flag);
324 
325 int vect2nfftblock(double *V1, int v1_size, double *V2, int fft_size, int nfft, int lambda);
326 
327 int nfftblock2vect(double *V2, int fft_size, int nfft, int lambda, double *V1, int v1_size);
328 
329 int get_overlapping_blocks_params(int nbloc, Block *tpltzblocks, int local_V_size, int64_t nrow, int64_t idp, int64_t *idpnew, int *local_V_size_new, int *nnew, int *ifirstBlock, int *ilastBlock);
330 
331 
332 
333 //Wizard routines
334 int stbmmProd( Tpltz Nm1, double *V);
335 
336 //=========================================================================
337 #endif /* !TOEPLITZ_H_ */
338 
339