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_seq.c
Go to the documentation of this file.
1 
49 #include "toeplitz.h"
50 
51 //r1.1 - Frederic Dauvergne (APC)
52 //This is the sequential version of the mpi routines for the API.
53 //The stbmm and gstbmm are the same as the mpi_stbmm and mpi_gstbmm but without
54 //any communication. stmm is a simplifed call of the sequential product including
55 //initialization and cleaning.
56 
57 
58 //=========================================================================
60 
72 int stmm(double **V, int n, int m, double *T, int lambda, Flag flag_stgy)
73 {
74 
75 //fftw variables
76  fftw_complex *V_fft, *T_fft;
77  double *V_rfft;
78  fftw_plan plan_f, plan_b;
79 
80 //product parameters
81  int nfft, blocksize;
82 
83  FILE *file;
84  file = stdout;
85 
86 
87  tpltz_init(n, lambda, &nfft, &blocksize, &T_fft, T, &V_fft, &V_rfft, &plan_f, &plan_b, flag_stgy);
88 
89  //Toeplitz computation
90  if(VERBOSE)
91  fprintf(file, "Before stmm_main call : nfft = %d, blocksize = %d\n", nfft, blocksize);
92  stmm_main(V, n, m, 0, n*m, T, T_fft, lambda, V_fft, V_rfft, plan_f, plan_b, blocksize, nfft, flag_stgy);
93 
94  tpltz_cleanup(&T_fft, &V_fft, &V_rfft, &plan_f, &plan_b);
95 
96 
97  return 0;
98 }
99 
100 
101 //=========================================================================
103 
121 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)
122 {
123 
124 
125  int nb_blocks_local=nb_blocks;
126  int nb_blocks_all=nb_blocks;
127  // int idp=0;
128  // int local_V_size=nrow;
129  //MPI_Comm comm=NULL;
130 
131  mpi_stbmm(V, nrow, m_cw, m_rw, tpltzblocks, nb_blocks, nb_blocks, idp, local_V_size, flag_stgy, NULL);
132 
133 
134 
135  return 0;
136 }
137 
138 
139 //====================================================================
140 
142 // This matrix V contains defined gaps which represents the useless data for the comutation. The gaps indexes are defined in the global time space as the generized toeplitz matrix,
143 // meaning the row dimension. Each of his diagonal blocks is a symmetric, band-diagonal Toeplitz matrix, which can be different for each block.
170 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)
171 {
172  int nb_blocks_local=nb_blocks;
173  int nb_blocks_all=nb_blocks;
174  // int idp=0;
175  // int local_V_size=nrow;
176  //MPI_Comm comm=NULL;
177 
178  mpi_gstbmm(V, nrow, m_cw, m_rw, tpltzblocks, nb_blocks, nb_blocks, idp, local_V_size, id0gap, lgap, ngap, flag_stgy, NULL);
179 
180 
181 
182  return 0;
183 }
184 
185 
186 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)
187 {
188 
189  int rank=0;
190  int i,j,k; //some indexes
191 
192  int flag_skip_build_gappy_blocks = flag_stgy.flag_skip_build_gappy_blocks;
193 
194  FILE *file;
195  file = stdout;
196  PRINT_RANK=rank ;
197 
198 //put zeros at the gaps location
199  reset_gaps( V, id0p, local_V_size, m, nrow, m_rowwise, id0gap, lgap, ngap);
200 
201 
202 //allocation for the gappy structure of the diagonal block Toeplitz matrix
203  int nb_blocks_gappy;
204  int nb_blockgappy_max;
205  int Tgappysize_max;
206 
207  Block *tpltzblocks_gappy;
208 
209 //some computation usefull to determine the max size possible for the gappy variables
210  int Tsize=0;
211  int lambdamax=0;
212 
213 if (VERBOSE)
214  fprintf(file, "[%d] flag_skip_build_gappy_blocks=%d\n", rank, flag_skip_build_gappy_blocks);
215 
216  if (flag_skip_build_gappy_blocks==1) { //no build gappy blocks strategy, just put zeros at gaps location
217 
218  //compute the product using only the input Toeplitz blocks structure with zeros at the gaps location
219 //to remake stbmm(V, nrow, m, m_rowwise, tpltzblocks, nb_blocks_local, nb_blocks_all, id0p, local_V_size, flag_stgy);
220 
221  }
222  else { //build gappy blocks strategy
223 
224  for(Tsize=i=0;i<nb_blocks_local;i++)
225  Tsize += tpltzblocks[i].lambda;
226 
227  for(i=0;i<nb_blocks_local;i++) {
228  if (tpltzblocks[i].lambda>lambdamax)
229  lambdamax = tpltzblocks[i].lambda;
230  }
231 
232 //compute max size possible for the gappy variables
233  nb_blockgappy_max = nb_blocks_local+ngap;
234  Tgappysize_max = Tsize + lambdamax*ngap;
235 
236 //allocation of the gappy variables with max size possible
237  tpltzblocks_gappy = (Block *) calloc(nb_blockgappy_max,sizeof(Block));
238 
239 
240 //build gappy Toeplitz block structure considering significant gaps locations, meaning we skip
241 //the gaps lower than the minimum correlation distance. You can also use the flag_param_distmin_fixed
242 //parameter which allows you to skip the gap lower than these value. Indeed, sometimes it's
243 //better to just put somes zeros than to consider two separates blocks.
244 //ps: This criteria could be dependant of the local lambda in futur impovements.
245  int flag_param_distmin_fixed = flag_stgy.flag_param_distmin_fixed;
246  build_gappy_blocks(nrow, m, tpltzblocks, nb_blocks_local, nb_blocks_all, id0gap, lgap, ngap, tpltzblocks_gappy, &nb_blocks_gappy, flag_param_distmin_fixed);
247 
248 
249 if (VERBOSE) {
250  fprintf(file, "[%d] nb_blocks_gappy=%d\n", rank, nb_blocks_gappy);
251  for(i=0;i<nb_blocks_gappy;i++)
252  fprintf(file, "[%d] idvgappy[%d]=%d ; ngappy[%d]=%d\n", rank, i, tpltzblocks_gappy[i].idv, i, tpltzblocks_gappy[i].n );
253 }
254 //ps: we could reallocate the gappy variables to their real size. Not sure it's worth it.
255 
256 //compute the product using the freshly created gappy Toeplitz blocks structure
257 //to remake stbmm(V, nrow, m, m_rowwise, tpltzblocks_gappy, nb_blocks_local, nb_blocks_all, id0p, local_V_size, flag_stgy);
258 
259  } //end flag_skip_build_gappy_blocks==1
260 
261 
262 //put zeros on V for the gaps location again. Indeed, some gaps are just replaced by zeros
263 //in input, it's created some fakes results we need to clear after the computation.
264  reset_gaps( V, id0p, local_V_size, m, nrow, m_rowwise, id0gap, lgap, ngap);
265 
266 
267  return 0;
268 }
269