OptPmeXPencil Class Reference

#include <fftlib.h>

Inheritance diagram for OptPmeXPencil:

OptPmePencil< CBase_OptPmeXPencil > CBase_OptPmeXPencil List of all members.

Public Member Functions

OptPmeXPencil_SDAG_CODE OptPmeXPencil ()
 OptPmeXPencil (CkMigrateMessage *)
void fft_init ()
void recv_trans (const OptPmeFFTMsg *)
void many_to_many_recv_trans ()
void forward_fft ()
void pme_kspace ()
void backward_fft ()
void send_untrans ()
void many_to_many_send_untrans ()
void submit_evir ()
void initialize_manytomany ()

Public Attributes

fftw_plan forward_plan
fftw_plan backward_plan
int ny
int nz
PmeKSpacemyKSpace
CkCallbackWrapper cbw_recvtrans
bool constant_pressure
SubmitReductionreduction

Detailed Description

Definition at line 172 of file fftlib.h.


Constructor & Destructor Documentation

OptPmeXPencil_SDAG_CODE OptPmeXPencil::OptPmeXPencil (  )  [inline]

Definition at line 175 of file fftlib.h.

References myKSpace.

00175 { __sdag_init();  myKSpace = 0; setMigratable(false); }

OptPmeXPencil::OptPmeXPencil ( CkMigrateMessage *   )  [inline]

Definition at line 176 of file fftlib.h.

00176 { __sdag_init(); }


Member Function Documentation

void OptPmeXPencil::backward_fft (  ) 

Definition at line 508 of file fftlib.C.

References backward_plan, OptPmePencil< CBase_OptPmeXPencil >::data, ny, nz, and OptPmePencil< CBase_OptPmeXPencil >::work.

00508                                  {
00509 #ifdef NAMD_FFTW
00510 #ifdef NAMD_FFTW_3
00511   fftwf_execute(backward_plan);
00512 #else
00513 
00514   fftw(backward_plan, ny*nz,
00515        ((fftw_complex *) data), ny*nz, 1, (fftw_complex *) work, 1, 0);
00516 #endif
00517 #endif
00518 }

void OptPmeXPencil::fft_init (  ) 

Definition at line 182 of file fftlib.C.

References backward_plan, PmeGrid::block2, PmeGrid::block3, OptPmePencilInitMsgData::constant_pressure, constant_pressure, OptPmePencil< CBase_OptPmeXPencil >::data, PmeGrid::dim3, fftw_plan_lock, forward_plan, OptPmePencilInitMsgData::grid, OptPmePencil< CBase_OptPmeXPencil >::handle, OptPmePencil< CBase_OptPmeXPencil >::initdata, initialize_manytomany(), PmeGrid::K1, PmeGrid::K2, OptPmePencil< CBase_OptPmeXPencil >::lattice, OptPmePencil< CBase_OptPmeXPencil >::many_to_many_data, OptPmePencil< CBase_OptPmeXPencil >::many_to_many_nb, myKSpace, NAMD_die(), ny, nz, ReductionMgr::Object(), OptPmePencil< CBase_OptPmeXPencil >::order_init(), reduction, REDUCTIONS_BASIC, Node::simParameters, simParams, ReductionMgr::willSubmit(), OptPmePencil< CBase_OptPmeXPencil >::work, and OptPmePencilInitMsgData::xBlocks.

00182                              {
00183   CProxy_Node nd(CkpvAccess(BOCclass_group).node);
00184   Node *node = nd.ckLocalBranch();
00185   SimParameters *simParams = node->simParameters;
00186 
00187   //  printf ("Initialize xpencil [%d,%d], on pd %d\n", thisIndex.x, thisIndex.y, CkMyPe());
00188 
00189   lattice = simParams->lattice;
00190 
00191   int K1 = initdata.grid.K1;
00192   int K2 = initdata.grid.K2;
00193   int dim3 = initdata.grid.dim3;
00194   int block2 = initdata.grid.block2;
00195   int block3 = initdata.grid.block3;
00196 
00197   ny = block2;
00198   if ( (thisIndex.y + 1) * block2 > K2 ) ny = K2 - thisIndex.y * block2;
00199   nz = block3;
00200   if ( (thisIndex.z+1)*block3 > dim3/2 ) nz = dim3/2 - thisIndex.z*block3;
00201 
00202   data = new float[K1*block2*block3*2];
00203   many_to_many_data = new float[K1*block2*block3*2];
00204   many_to_many_nb = new int [initdata.xBlocks];
00205   work = new float[2*K1];
00206 
00207   memset(many_to_many_data, 0, sizeof(float) * K1*block2*block3*2);
00208 
00209   order_init(initdata.xBlocks);
00210 
00211 #ifdef NAMD_FFTW
00212   CmiLock(fftw_plan_lock);
00213 #ifdef NAMD_FFTW_3
00214   /* need array of sizes for the how many */
00215   int numLines=ny*nz;
00216   int planLineSizes[1];
00217   planLineSizes[0]=K1;
00218   forward_plan = fftwf_plan_many_dft(1, planLineSizes, numLines,
00219                                      (fftwf_complex *) data, NULL, K1, 1,
00220                                      (fftwf_complex *) data, NULL, 1, 0,
00221                                    FFTW_FORWARD,
00222                                    ( simParams->FFTWEstimate ? FFTW_ESTIMATE 
00223                                      : FFTW_MEASURE ));
00224   backward_plan = fftwf_plan_many_dft(1, planLineSizes, numLines,
00225                                      (fftwf_complex *) data, NULL, K1, 1,
00226                                      (fftwf_complex *) data, NULL, 1, 0,
00227                                    FFTW_BACKWARD,
00228                                    ( simParams->FFTWEstimate ? FFTW_ESTIMATE 
00229                                      : FFTW_MEASURE ));
00230 #else
00231 
00232   forward_plan = fftw_create_plan_specific(K1, FFTW_FORWARD,
00233         ( simParams->FFTWEstimate ? FFTW_ESTIMATE : FFTW_MEASURE )
00234         | FFTW_IN_PLACE | FFTW_USE_WISDOM, (fftw_complex *) data,
00235         ny*nz, (fftw_complex *) work, 1);
00236   backward_plan = fftw_create_plan_specific(K1, FFTW_BACKWARD,
00237         ( simParams->FFTWEstimate ? FFTW_ESTIMATE : FFTW_MEASURE )
00238         | FFTW_IN_PLACE | FFTW_USE_WISDOM, (fftw_complex *) data,
00239         ny*nz, (fftw_complex *) work, 1);
00240 
00241   CmiUnlock(fftw_plan_lock);
00242 #endif
00243 #else
00244   NAMD_die("Sorry, FFTW must be compiled in to use PME.");
00245 #endif
00246 
00247   myKSpace = new PmeKSpace(initdata.grid,
00248                 thisIndex.y*block2, thisIndex.y*block2 + ny,
00249                 thisIndex.z*block3, thisIndex.z*block3 + nz);
00250 
00251   handle = CmiDirect_manytomany_allocate_handle();
00252   initialize_manytomany();
00253 
00254   constant_pressure = initdata.constant_pressure;
00255 
00256   reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC);
00257 }

void OptPmeXPencil::forward_fft (  ) 

Definition at line 462 of file fftlib.C.

References OptPmePencil< CBase_OptPmeXPencil >::data, forward_plan, ny, nz, and OptPmePencil< CBase_OptPmeXPencil >::work.

00462                                 {
00463 #ifdef NAMD_FFTW
00464 #ifdef NAMD_FFTW_3
00465   fftwf_execute(forward_plan);
00466 #else
00467 
00468   fftw(forward_plan, ny*nz,
00469        ((fftw_complex *) data), ny*nz, 1, (fftw_complex *) work, 1, 0);
00470 #endif
00471 #endif
00472 }

void OptPmeXPencil::initialize_manytomany (  ) 

Definition at line 1151 of file fftlib.C.

References CkCallbackWrapper::array, PmeGrid::block1, call_ck_cb_recv_trans_x(), CkCallbackWrapper::cb, cbw_recvtrans, global_map_y, OptPmePencilInitMsgData::grid, OptPmePencil< CBase_OptPmeXPencil >::initdata, PmeGrid::K1, OptPmePencil< CBase_OptPmeXPencil >::many_to_many_data, OptPmePencil< CBase_OptPmeXPencil >::many_to_many_nb, CkCallbackWrapper::msg, ny, nz, PHASE_XF, PHASE_YB, PRIORITY_SIZE, OptPmePencil< CBase_OptPmeXPencil >::single_pencil, and OptPmePencilInitMsgData::xBlocks.

Referenced by fft_init().

01151                                             {  
01152   int xBlocks = initdata.xBlocks;
01153   int block1 = initdata.grid.block1;
01154   int K1 = initdata.grid.K1;
01155   
01156   CmiDirect_manytomany_initialize_sendbase (handle, PHASE_YB, NULL, NULL, (char *)many_to_many_data, xBlocks, thisIndex.y);
01157   CkArrayIndex3D idx (thisIndex.x, thisIndex.y, thisIndex.z);
01158   cbw_recvtrans.cb = CkCallback(CkIndex_OptPmeXPencil::many_to_manyRecvTrans(NULL), idx, thisProxy.ckGetArrayID());
01159   cbw_recvtrans.msg    = new (PRIORITY_SIZE) OptPmeDummyMsg;
01160   cbw_recvtrans.array  = this;
01161   CmiDirect_manytomany_initialize_recvbase (handle, PHASE_XF, 
01162                                             call_ck_cb_recv_trans_x, 
01163                                             &cbw_recvtrans,  
01164                                             (char *)many_to_many_data, 
01165                                             initdata.xBlocks, -1);
01166 
01167   single_pencil = false;
01168   if (ny == 1 && nz == 1 && xBlocks <= K1 && block1==1)
01169     single_pencil = true;
01170 
01171   for ( int ib=0; ib<xBlocks; ++ib ) {
01172     int nx = block1;
01173     if ( (ib+1)*block1 > K1 ) {
01174       single_pencil = false;
01175       nx = K1 - ib*block1;
01176     }
01177     
01178     CkArrayIndex3D index (ib,0,thisIndex.z);
01179     CProxy_OptPmePencilMapY yproxy (global_map_y);
01180     int pe = yproxy.ckLocalBranch()->procNum(0, index);
01181     CmiDirect_manytomany_initialize_send (handle, PHASE_YB, ib, 2*block1*ny*nz*ib*sizeof(float), 2*nx*ny*nz*sizeof(float), pe);
01182     
01183     CmiDirect_manytomany_initialize_recv (handle, PHASE_XF, ib, ib*block1*ny*nz*2*sizeof(float), nx*ny*nz*2*sizeof(float), pe);
01184     many_to_many_nb [ib] = nx;
01185   }
01186 }

void OptPmeXPencil::many_to_many_recv_trans (  ) 

Definition at line 860 of file fftlib.C.

References PmeGrid::block1, OptPmePencil< CBase_OptPmeXPencil >::data, OptPmePencilInitMsgData::grid, OptPmePencil< CBase_OptPmeXPencil >::initdata, j, PmeGrid::K1, OptPmePencil< CBase_OptPmeXPencil >::many_to_many_data, OptPmePencil< CBase_OptPmeXPencil >::many_to_many_nb, ny, nz, OptPmePencil< CBase_OptPmeXPencil >::single_pencil, and OptPmePencilInitMsgData::xBlocks.

00860                                              {
00861   
00862   int block1 = initdata.grid.block1;
00863   int K1 = initdata.grid.K1;
00864   
00865   const float *md = many_to_many_data;
00866   if (single_pencil) {
00867     for (int ib =0; ib < initdata.xBlocks; ib++ ) {
00868       data[2*ib]   = *(md++);
00869       data[2*ib+1] = *(md++);
00870     }
00871   }
00872   else {
00873     for (int ib =0; ib < initdata.xBlocks; ib++ ) {
00874       int nx = many_to_many_nb[ib];    
00875       for ( int i=ib*block1; i<(ib*block1+nx); ++i ) {
00876         float *d = data + i*ny*nz*2;
00877         for ( int j=0; j<ny; ++j, d += nz*2 ) {
00878           for ( int k=0; k<nz; ++k ) {
00879             d[2*k] = *(md++);
00880             d[2*k+1] = *(md++);
00881           }
00882         }
00883       }
00884     }
00885   }
00886 }

void OptPmeXPencil::many_to_many_send_untrans (  ) 

Definition at line 888 of file fftlib.C.

References PmeGrid::block1, OptPmePencil< CBase_OptPmeXPencil >::data, OptPmePencilInitMsgData::grid, OptPmePencil< CBase_OptPmeXPencil >::handle, OptPmePencil< CBase_OptPmeXPencil >::initdata, j, PmeGrid::K1, OptPmePencil< CBase_OptPmeXPencil >::many_to_many_data, ny, nz, PHASE_YB, OptPmePencil< CBase_OptPmeXPencil >::single_pencil, and OptPmePencilInitMsgData::xBlocks.

00888                                               {
00889   int xBlocks = initdata.xBlocks;
00890   int block1 = initdata.grid.block1;
00891   int K1 = initdata.grid.K1;
00892   
00893   int     nx = block1;
00894   float * md = many_to_many_data;
00895   if (single_pencil) {
00896     float *d = data;
00897     for ( int ib=0; ib<xBlocks; ++ib ) {
00898       *(md++) = d[2*ib];
00899       *(md++) = d[2*ib+1];
00900     }
00901   }
00902   else {
00903     for ( int ib=0; ib<xBlocks; ++ib ) {
00904       nx = block1;
00905       if ( (ib+1)*block1 > K1 ) nx = K1 - ib*block1;
00906       
00907       for ( int i=ib*block1; i<(ib*block1+nx); ++i ) {
00908         float *d = data + i*ny*nz*2;
00909         for ( int j=0; j<ny; ++j, d += nz*2 ) {
00910           for ( int k=0; k<nz; ++k ) {
00911             *(md++) = d[2*k];
00912             *(md++) = d[2*k+1];
00913           }
00914         }
00915       }
00916     }
00917   }
00918   CmiDirect_manytomany_start (handle, PHASE_YB);
00919 }

void OptPmeXPencil::pme_kspace (  ) 

Definition at line 474 of file fftlib.C.

References PmeKSpace::compute_energy(), OptPmePencil< CBase_OptPmeXPencil >::data, OptPmePencil< CBase_OptPmeXPencil >::evir, ComputeNonbondedUtil::ewaldcof, OptPmePencil< CBase_OptPmeXPencil >::lattice, and myKSpace.

00474                                {
00475   evir = 0.;  //set evir to 0
00476 
00477 #ifdef FFTCHECK
00478   return;
00479 #endif
00480 
00481   BigReal ewaldcof = ComputeNonbondedUtil::ewaldcof;
00482   evir[0] = myKSpace->compute_energy(data,
00483                                      lattice, ewaldcof, &(evir[1]), 0);
00484 
00485   //contribute (7*sizeof(double), evir.begin(), CkReduction::sum_double, initdata.cb_energy);
00486 }

void OptPmeXPencil::recv_trans ( const OptPmeFFTMsg  ) 

Definition at line 442 of file fftlib.C.

References PmeGrid::block1, OptPmePencil< CBase_OptPmeXPencil >::data, OptPmePencilInitMsgData::grid, OptPmePencil< CBase_OptPmeXPencil >::initdata, j, PmeGrid::K1, OptPmeFFTMsg::nx, ny, nz, OptPmeFFTMsg::qgrid, and OptPmeFFTMsg::sourceNode.

00442                                                       {
00443 
00444   int block1 = initdata.grid.block1;
00445   int K1 = initdata.grid.K1;
00446   int ib = msg->sourceNode;
00447   int nx = msg->nx;
00448   const float *md = msg->qgrid;
00449   for ( int i=ib*block1; i<(ib*block1+nx); ++i ) {
00450     float *d = data + i*ny*nz*2;
00451     for ( int j=0; j<ny; ++j, d += nz*2 ) {
00452       for ( int k=0; k<nz; ++k ) {
00453         d[2*k] = *(md++);
00454         d[2*k+1] = *(md++);
00455       }
00456     }
00457   }
00458 }

void OptPmeXPencil::send_untrans (  ) 

Definition at line 520 of file fftlib.C.

References PmeGrid::block1, OptPmePencil< CBase_OptPmeXPencil >::data, OptPmePencilInitMsgData::grid, OptPmePencil< CBase_OptPmeXPencil >::initdata, j, PmeGrid::K1, OptPmeFFTMsg::nx, ny, nz, PRIORITY_SIZE, OptPmeFFTMsg::qgrid, OptPmePencil< CBase_OptPmeXPencil >::send_order, OptPmeFFTMsg::sourceNode, OptPmePencilInitMsgData::xBlocks, and OptPmePencilInitMsgData::yPencil.

00520                                  {
00521   int xBlocks = initdata.xBlocks;
00522   int block1 = initdata.grid.block1;
00523   int K1 = initdata.grid.K1;
00524 
00525   for ( int isend=0; isend<xBlocks; ++isend ) {
00526     int ib = send_order[isend];
00527     int nx = block1;
00528     if ( (ib+1)*block1 > K1 ) nx = K1 - ib*block1;
00529     OptPmeFFTMsg *msg = new (nx*ny*nz*2,PRIORITY_SIZE) OptPmeFFTMsg;    
00530     msg->sourceNode = thisIndex.y;
00531     msg->nx = ny;
00532     float *md = msg->qgrid;
00533     for ( int i=ib*block1; i<(ib*block1+nx); ++i ) {
00534       float *d = data + i*ny*nz*2;
00535       for ( int j=0; j<ny; ++j, d += nz*2 ) {
00536         for ( int k=0; k<nz; ++k ) {
00537           *(md++) = d[2*k];
00538           *(md++) = d[2*k+1];
00539         }
00540       }
00541     }
00542     
00543     //printf ("%d, %d: Xpencil Sending untrans to %d, %d\n", thisIndex.y, thisIndex.z, ib, thisIndex.z);
00544     initdata.yPencil(ib,0,thisIndex.z).recvUntrans(msg);
00545   }
00546 }

void OptPmeXPencil::submit_evir (  ) 

Definition at line 488 of file fftlib.C.

References Array< Elem, Size >::begin(), OptPmePencil< CBase_OptPmeXPencil >::evir, SubmitReduction::item(), Node::Object(), reduction, REDUCTION_ELECT_ENERGY_SLOW, Node::simParameters, simParams, and SubmitReduction::submit().

00488                                 {
00489   double * cdata = (double *) evir.begin();
00490   reduction->item(REDUCTION_ELECT_ENERGY_SLOW) += cdata[0];
00491   reduction->item(REDUCTION_VIRIAL_SLOW_XX) += cdata[1];
00492   reduction->item(REDUCTION_VIRIAL_SLOW_XY) += cdata[2];
00493   reduction->item(REDUCTION_VIRIAL_SLOW_XZ) += cdata[3];
00494   reduction->item(REDUCTION_VIRIAL_SLOW_YX) += cdata[2];
00495   reduction->item(REDUCTION_VIRIAL_SLOW_YY) += cdata[4];
00496   reduction->item(REDUCTION_VIRIAL_SLOW_YZ) += cdata[5];
00497   reduction->item(REDUCTION_VIRIAL_SLOW_ZX) += cdata[3];
00498   reduction->item(REDUCTION_VIRIAL_SLOW_ZY) += cdata[5];
00499   reduction->item(REDUCTION_VIRIAL_SLOW_ZZ) += cdata[6];   
00500 
00501   SimParameters *simParams = Node::Object()->simParameters;
00502   int fef = simParams->fullElectFrequency;
00503   for (int i = 0; i < fef; i++) {
00504     reduction->submit();
00505   }
00506 }


Member Data Documentation

fftw_plan OptPmeXPencil::backward_plan

Definition at line 190 of file fftlib.h.

Referenced by backward_fft(), and fft_init().

CkCallbackWrapper OptPmeXPencil::cbw_recvtrans

Definition at line 195 of file fftlib.h.

Referenced by initialize_manytomany().

bool OptPmeXPencil::constant_pressure

Definition at line 196 of file fftlib.h.

Referenced by fft_init().

fftw_plan OptPmeXPencil::forward_plan

Definition at line 190 of file fftlib.h.

Referenced by fft_init(), and forward_fft().

PmeKSpace* OptPmeXPencil::myKSpace

Definition at line 194 of file fftlib.h.

Referenced by fft_init(), OptPmeXPencil(), and pme_kspace().

int OptPmeXPencil::ny

Definition at line 193 of file fftlib.h.

Referenced by backward_fft(), fft_init(), forward_fft(), initialize_manytomany(), many_to_many_recv_trans(), many_to_many_send_untrans(), recv_trans(), and send_untrans().

int OptPmeXPencil::nz

Definition at line 193 of file fftlib.h.

Referenced by backward_fft(), fft_init(), forward_fft(), initialize_manytomany(), many_to_many_recv_trans(), many_to_many_send_untrans(), recv_trans(), and send_untrans().

SubmitReduction* OptPmeXPencil::reduction

Definition at line 198 of file fftlib.h.

Referenced by fft_init(), and submit_evir().


The documentation for this class was generated from the following files:
Generated on Mon Sep 25 01:17:19 2017 for NAMD by  doxygen 1.4.7