00001
00005 #include "util.h"
00006 #include "nfft3.h"
00007
00027 #define F(MV, FLT, FLT_TYPE, NAME, ...) void i ## MV ## _ ## NAME(__VA_ARGS__)
00028
00029
00030 #define MACRO_SOLVER_ADJOINT_IMPL(MV, FLT, FLT_TYPE) \
00031 \
00032 F(MV, FLT, FLT_TYPE, init_advanced, i ## MV ## _adjoint_plan *ths, \
00033 MV ## _adjoint_plan *mv, unsigned adjoint ## MV ## _flags) \
00034 { \
00035 ths->mv = mv; \
00036 ths->flags = i ## MV ## _flags; \
00037 \
00038 ths->y_hat = (FLT_TYPE*)fftw_malloc(ths->mv->N_total*sizeof(FLT_TYPE));\
00039 ths->r_hat_iter = (FLT_TYPE*)fftw_malloc(ths->mv->N_total*sizeof(FLT_TYPE));\
00040 ths->f_iter = (FLT_TYPE*)fftw_malloc(ths->mv->M_total*sizeof(FLT_TYPE)); \
00041 ths->p_iter = (FLT_TYPE*)fftw_malloc(ths->mv->M_total*sizeof(FLT_TYPE)); \
00042 \
00043 if(ths->flags & LANDWEBER) \
00044 ths->z_iter = ths->p_iter; \
00045 \
00046 if(ths->flags & STEEPEST_DESCENT) \
00047 { \
00048 ths->z_iter = ths->p_iter; \
00049 ths->v_hat_iter = (FLT_TYPE*)fftw_malloc(ths->mv->N_total* \
00050 sizeof(FLT_TYPE)); \
00051 } \
00052 \
00053 if(ths->flags & CGNR) \
00054 { \
00055 ths->z_iter = (FLT_TYPE*)fftw_malloc(ths->mv->M_total* \
00056 sizeof(FLT_TYPE)); \
00057 ths->v_hat_iter = (FLT_TYPE*)fftw_malloc(ths->mv->N_total* \
00058 sizeof(FLT_TYPE)); \
00059 } \
00060 \
00061 if(ths->flags & CGNE) \
00062 ths->z_iter = ths->p_iter; \
00063 \
00064 if(ths->flags & PRECOMPUTE_WEIGHT) \
00065 \
00066 ths->w = (double*) fftw_malloc(ths->mv->M_total*sizeof(double)); \
00067 \
00068 if(ths->flags & PRECOMPUTE_DAMP) \
00069 ths->w_hat = (double*) fftw_malloc(ths->mv->N_total*sizeof(double)); \
00070 } \
00071 \
00072 \
00073 \
00074 F(MV, FLT, FLT_TYPE, init, i ## MV ## _adjoint_plan *ths, MV ## _plan *mv) \
00075 { \
00076 adjoint ## MV ## _init_advanced(ths, mv, CGNR); \
00077 } \
00078 \
00079 \
00080 F(MV, FLT, FLT_TYPE, before_loop, i ## MV ## _adjoint_plan *ths) \
00081 { \
00082 \
00083 \
00084 nfft_cp_ ## FLT(ths->mv->f, ths->f_iter, ths->mv->M_total); \
00085 \
00086 \
00087 NFFT_SWAP_ ## FLT(ths->r_hat_iter, ths->mv->f_hat); \
00088 MV ## _adjoint(ths->mv); \
00089 NFFT_SWAP_ ## FLT(ths->r_hat_iter, ths->mv->f_hat); \
00090 \
00091 \
00092 nfft_upd_axpy_ ## FLT(ths->r_hat_iter, -1.0, ths->y_hat, ths->mv->N_total);\
00093 \
00094 if((!(ths->flags & LANDWEBER)) || (ths->flags & NORMS_FOR_LANDWEBER)) \
00095 { \
00096 if(ths->flags & PRECOMPUTE_WEIGHT) \
00097 ths->dot_r_hat_iter = \
00098 nfft_dot_w_ ## FLT(ths->r_hat_iter, ths->w, ths->mv->N_total); \
00099 else \
00100 ths->dot_r_hat_iter = nfft_dot_ ## FLT(ths->r_hat_iter, ths->mv->N_total); \
00101 } \
00102 \
00103 \
00104 \
00105 if(ths->flags & PRECOMPUTE_WEIGHT) \
00106 nfft_cp_w_ ## FLT(ths->mv->f_hat, ths->w_hat, ths->r_hat_iter, ths->mv->N_total); \
00107 else \
00108 nfft_cp_ ## FLT(ths->mv->f_hat, ths->r_hat_iter, ths->mv->N_total); \
00109 \
00110 \
00113 \
00114 if((!(ths->flags & LANDWEBER)) || (ths->flags & NORMS_FOR_LANDWEBER)) \
00115 { \
00116 if(ths->flags & PRECOMPUTE_DAMP) \
00117 ths->dot_z_iter = \
00118 nfft_dot_w_ ## FLT(ths->z_iter, ths->w, ths->mv->M_total); \
00119 else \
00120 ths->dot_z_iter = nfft_dot_ ## FLT(ths->z_iter, ths->mv->M_total); \
00121 } \
00122 \
00123 if(ths->flags & CGNE) \
00124 ths->dot_p_iter = ths->dot_z_iter; \
00125 \
00126 if(ths->flags & CGNR) \
00127 nfft_cp_ ## FLT(ths->p_iter, ths->z_iter, ths->mv->M_total); \
00128 } \
00129 \
00130 \
00131 \
00132 \
00133 F(MV, FLT, FLT_TYPE, loop_one_step_cgne, i ## MV ## _adjoint_plan *ths) \
00134 { \
00135 \
00136 ths->alpha_iter = ths->dot_r_hat_iter / ths->dot_p_iter; \
00137 \
00138 \
00139 if(ths->flags & PRECOMPUTE_DAMP) \
00140 nfft_upd_xpawy_ ## FLT(ths->f_iter, ths->alpha_iter, ths->w, \
00141 ths->p_iter, ths->mv->M_total); \
00142 else \
00143 nfft_upd_xpay_ ## FLT(ths->f_ter, ths->alpha_iter, ths->p_iter, \
00144 ths->mv->M_total); \
00145 \
00146 \
00147 if(ths->flags & PRECOMPUTE_DAMP) \
00148 nfft_cp_w_ ## FLT(ths->mv->f, ths->w, ths->p_iter, \
00149 ths->mv->M_total); \
00150 else \
00151 nfft_cp_ ## FLT(ths->mv->f, ths->p_iter, ths->mv->M_total); \
00152 \
00153 \
00154 MV ## _adjoint(ths->mv); \
00155 \
00156 nfft_upd_xpay_ ## FLT(ths->r_hat_iter, -ths->alpha_iter, ths->mv->f_hat, \
00157 ths->mv->N_total); \
00158 \
00159 ths->dot_r_hat_iter_old = ths->dot_r_hat_iter; \
00160 if(ths->flags & PRECOMPUTE_WEIGHT) \
00161 ths->dot_r_hat_iter = nfft_dot_w_ ## FLT(ths->r_hat_iter, ths->w_hat, \
00162 ths->mv->N_total); \
00163 else \
00164 ths->dot_r_hat_iter = nfft_dot_ ## FLT(ths->r_hat_iter, ths->mv->N_total);\
00165 \
00166 \
00167 ths->beta_iter = ths->dot_r_hat_iter / ths->dot_r_hat_iter_old; \
00168 \
00169 \
00170 if(ths->flags & PRECOMPUTE_WEIGHT) \
00171 nfft_cp_w_ ## FLT(ths->mv->f_hat, ths->w_hat, ths->r_hat_iter, ths->mv->N_total); \
00172 else \
00173 nfft_cp_ ## FLT(ths->mv->f_hat, ths->r_hat_iter, ths->mv->N_total); \
00174 \
00175 \
00176 MV ## _trafo(ths->mv); \
00177 \
00178 \
00179 \
00180 \
00181 \
00182 nfft_upd_axpy_ ## FLT(ths->p_iter, ths->beta_iter, ths->mv->f, \
00183 ths->mv->M_total); \
00184 \
00185 if(ths->flags & PRECOMPUTE_DAMP) \
00186 ths->dot_p_hat_iter = \
00187 nfft_dot_w_ ## FLT(ths->p_hat_iter, ths->w_hat, ths->mv->N_total); \
00188 else \
00189 ths->dot_p_hat_iter = nfft_dot_ ## FLT(ths->p_hat_iter, ths->mv->N_total);\
00190 } \
00191 \
00192 \
00193 \
00194 \
00195 \
00196 \
00197 \
00198 F(MV, FLT, FLT_TYPE, adjoint_loop_one_step, i ## MV ## _adjoint_plan *ths) \
00199 { \
00200 \
00211 if(ths->flags & CGNE) \
00212 i ## MV ## _adjoint_loop_one_step_cgne(ths); \
00213 } \
00214 \
00215 \
00216 F(MV, FLT, FLT_TYPE, adjoint_finalize, i ## MV ## _adjoint_plan *ths) \
00217 { \
00218 if(ths->flags & PRECOMPUTE_WEIGHT) \
00219 fftw_free(ths->w); \
00220 \
00221 if(ths->flags & PRECOMPUTE_DAMP) \
00222 fftw_free(ths->w_hat); \
00223 \
00224 if(ths->flags & CGNR) \
00225 { \
00226 fftw_free(ths->v_hatiter); \
00227 fftw_free(ths->z_iter); \
00228 } \
00229 \
00230 if(ths->flags & STEEPEST_DESCENT) \
00231 fftw_free(ths->v_hat_iter); \
00232 \
00233 fftw_free(ths->p_iter); \
00234 fftw_free(ths->f_iter); \
00235 \
00236 fftw_free(ths->r_hat_iter); \
00237 fftw_free(ths->y); \
00238 } \
00239 MACRO_SOLVER_ADJOINT_IMPL(nfsft, complex, double complex)
00240