MIDAPACK - MIcrowave Data Analysis PACKage  1.1b
Parallel software tools for high performance CMB DA analysis
toeplitz_seq.c
Go to the documentation of this file.
1 
61 #include "toeplitz.h"
62 
63 // r1.1 - Frederic Dauvergne (APC)
64 // This is the sequential version of the mpi routines for the API.
65 // The stbmm and gstbmm are the same as the mpi_stbmm and mpi_gstbmm but without
66 // any communication. stmm is a simplifed call of the sequential product
67 // including initialization and cleaning.
68 
69 
70 //=========================================================================
73 
85 int stmm(double **V, int n, int m, double *T, int lambda, Flag flag_stgy) {
86 
87  // fftw variables
88  fftw_complex *V_fft, *T_fft;
89  double *V_rfft;
90  fftw_plan plan_f, plan_b;
91 
92  // product parameters
93  int nfft, blocksize;
94 
95  FILE *file;
96  file = stdout;
97 
98 
99  tpltz_init(n, lambda, &nfft, &blocksize, &T_fft, T, &V_fft, &V_rfft,
100  &plan_f, &plan_b, flag_stgy);
101 
102  // Toeplitz computation
103  if (VERBOSE)
104  fprintf(file, "Before stmm_main call : nfft = %d, blocksize = %d\n",
105  nfft, blocksize);
106  stmm_main(V, n, m, 0, n * m, T, T_fft, lambda, V_fft, V_rfft, plan_f,
107  plan_b, blocksize, nfft, flag_stgy);
108 
109  tpltz_cleanup(&T_fft, &V_fft, &V_rfft, &plan_f, &plan_b);
110 
111 
112  return 0;
113 }
114 
115 
116 //===================================================\=====================
120 
136 int stbmm(double **V, int nrow, int m_cw, int m_rw, Block *tpltzblocks,
137  int nb_blocks, int64_t idp, int local_V_size, Flag flag_stgy) {
138 
139 
140  int nb_blocks_local = nb_blocks;
141  int nb_blocks_all = nb_blocks;
142  // int idp=0;
143  // int local_V_size=nrow;
144  MPI_Comm comm = MPI_COMM_NULL;
145 
146  mpi_stbmm(V, nrow, m_cw, m_rw, tpltzblocks, nb_blocks, nb_blocks, idp,
147  local_V_size, flag_stgy, comm);
148 
149 
150  return 0;
151 }
152 
153 
154 //====================================================================
155 
158 // This matrix V contains defined gaps which represents the useless data for the
159 // comutation. The gaps indexes are defined in the global time space as the
160 // generized toeplitz matrix, meaning the row dimension. Each of his diagonal
161 // blocks is a symmetric, band-diagonal Toeplitz matrix, which can be different
162 // for each block.
189 int gstbmm(double **V, int nrow, int m_cw, int m_rw, Block *tpltzblocks,
190  int nb_blocks, int64_t idp, int local_V_size, int64_t *id0gap,
191  int *lgap, int ngap, Flag flag_stgy) {
192  int nb_blocks_local = nb_blocks;
193  int nb_blocks_all = nb_blocks;
194  // int idp=0;
195  // int local_V_size=nrow;
196  MPI_Comm comm = MPI_COMM_NULL;
197 
198  mpi_gstbmm(V, nrow, m_cw, m_rw, tpltzblocks, nb_blocks, nb_blocks, idp,
199  local_V_size, id0gap, lgap, ngap, flag_stgy, comm);
200 
201 
202  return 0;
203 }
204 
205 
206 int gstbmm0(double **V, int nrow, int m, int m_rowwise, Block *tpltzblocks,
207  int nb_blocks_local, int nb_blocks_all, int id0p, int local_V_size,
208  int64_t *id0gap, int *lgap, int ngap, Flag flag_stgy) {
209 
210  int rank = 0;
211  int i, j, k; // some indexes
212 
213  int flag_skip_build_gappy_blocks = flag_stgy.flag_skip_build_gappy_blocks;
214 
215  FILE *file;
216  file = stdout;
217  PRINT_RANK = rank;
218 
219  // put zeros at the gaps location
220  reset_gaps(V, id0p, local_V_size, m, nrow, m_rowwise, id0gap, lgap, ngap);
221 
222 
223  // allocation for the gappy structure of the diagonal block Toeplitz matrix
224  int nb_blocks_gappy;
225  int nb_blockgappy_max;
226  int Tgappysize_max;
227 
228  Block *tpltzblocks_gappy;
229 
230  // some computation usefull to determine the max size possible for the gappy
231  // variables
232  int Tsize = 0;
233  int lambdamax = 0;
234 
235  if (VERBOSE)
236  fprintf(file, "[%d] flag_skip_build_gappy_blocks=%d\n", rank,
237  flag_skip_build_gappy_blocks);
238 
239  if (flag_skip_build_gappy_blocks == 1) { // no build gappy blocks strategy,
240  // just put zeros at gaps location
241 
242  // compute the product using only the input Toeplitz blocks structure
243  // with zeros at the gaps location
244  // to remake stbmm(V, nrow, m, m_rowwise, tpltzblocks, nb_blocks_local,
245  // nb_blocks_all, id0p, local_V_size, flag_stgy);
246 
247  } else { // build gappy blocks strategy
248 
249  for (Tsize = i = 0; i < nb_blocks_local; i++)
250  Tsize += tpltzblocks[i].lambda;
251 
252  for (i = 0; i < nb_blocks_local; i++) {
253  if (tpltzblocks[i].lambda > lambdamax)
254  lambdamax = tpltzblocks[i].lambda;
255  }
256 
257  // compute max size possible for the gappy variables
258  nb_blockgappy_max = nb_blocks_local + ngap;
259  Tgappysize_max = Tsize + lambdamax * ngap;
260 
261  // allocation of the gappy variables with max size possible
262  tpltzblocks_gappy = (Block *) calloc(nb_blockgappy_max, sizeof(Block));
263 
264 
265  // build gappy Toeplitz block structure considering significant gaps
266  // locations, meaning we skip the gaps lower than the minimum
267  // correlation distance. You can also use the flag_param_distmin_fixed
268  // parameter which allows you to skip the gap lower than these value.
269  // Indeed, sometimes it's better to just put somes zeros than to
270  // consider two separates blocks. ps: This criteria could be dependant
271  // of the local lambda in futur impovements.
272  int flag_param_distmin_fixed = flag_stgy.flag_param_distmin_fixed;
273  build_gappy_blocks(nrow, m, tpltzblocks, nb_blocks_local, nb_blocks_all,
274  id0gap, lgap, ngap, tpltzblocks_gappy,
275  &nb_blocks_gappy, flag_param_distmin_fixed);
276 
277 
278  if (VERBOSE) {
279  fprintf(file, "[%d] nb_blocks_gappy=%d\n", rank, nb_blocks_gappy);
280  for (i = 0; i < nb_blocks_gappy; i++)
281  fprintf(file, "[%d] idvgappy[%d]=%ld ; ngappy[%d]=%d\n", rank,
282  i, tpltzblocks_gappy[i].idv, i, tpltzblocks_gappy[i].n);
283  }
284  // ps: we could reallocate the gappy variables to their real size. Not
285  // sure it's worth it.
286 
287  // compute the product using the freshly created gappy Toeplitz blocks
288  // structure to remake stbmm(V, nrow, m, m_rowwise, tpltzblocks_gappy,
289  // nb_blocks_local, nb_blocks_all, id0p, local_V_size, flag_stgy);
290 
291  } // end flag_skip_build_gappy_blocks==1
292 
293 
294  // put zeros on V for the gaps location again. Indeed, some gaps are just
295  // replaced by zeros in input, it's created some fakes results we need to
296  // clear after the computation.
297  reset_gaps(V, id0p, local_V_size, m, nrow, m_rowwise, id0gap, lgap, ngap);
298 
299 
300  return 0;
301 }
int PRINT_RANK
Definition: toeplitz.c:117
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)
Definition: toeplitz.c:298
int VERBOSE
Verbose mode.
Definition: toeplitz.c:113
int tpltz_cleanup(fftw_complex **T_fft, fftw_complex **V_fft, double **V_rfft, fftw_plan *plan_f, fftw_plan *plan_b)
Definition: toeplitz.c:485
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)
Definition: toeplitz.c:888
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)
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)
int reset_gaps(double **V, int id0, int local_V_size, int m, int nrow, int m_rowwise, const int64_t *id0gap, const int *lgap, int ngap)
Set the data to zeros at the gaps location.
int build_gappy_blocks(int nrow, int m, Block *tpltzblocks, int nb_blocks_local, int nb_blocks_all, const int64_t *id0gap, const int *lgap, int ngap, Block *tpltzblocks_gappy, int *nb_blocks_gappy_final, int flag_param_distmin_fixed)
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)
Definition: toeplitz_seq.c:189
int gstbmm0(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)
Definition: toeplitz_seq.c:206
int stmm(double **V, int n, int m, double *T, int lambda, Flag flag_stgy)
Definition: toeplitz_seq.c:85
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)
Definition: toeplitz_seq.c:136