00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 template<class T>
00017 void mdp_field<T>::update(int np, int d, int ncomp) {
00018 T *dynamic_buffer=0;
00019 T *where_to=0;
00020 mpi.comm_time-=mpi.time();
00021 mdp_request request;
00022 long start_to_send,dp,process,length,idx;
00023 int k, ni, nf;
00024 if(d==-1) {d=0; ncomp=field_components;}
00025 if((ncomp==field_components) && (d!=0))
00026 error("update(): packet is too big");
00027 if(np<2) ni=nf=np;
00028 else {ni=0; nf=1; }
00029 for(dp=1; dp<Nproc; dp++) {
00030 process=(ME+dp) % Nproc;
00031 if(np<2) {
00032 length=lattice().len_to_send[process][np];
00033 } else {
00034 length=lattice().len_to_send[process][0]+lattice().len_to_send[process][1];
00035 }
00036 if(np==1) start_to_send=lattice().len_to_send[process][0];
00037 else start_to_send=0;
00038 if(length>0) {
00039 dynamic_buffer=new T[length*ncomp];
00040 for(idx=0; idx<length; idx++)
00041 for(k=0; k<ncomp; k++)
00042 dynamic_buffer[idx*ncomp+k]=
00043 *(m+lattice().to_send[process][start_to_send+idx]*
00044 field_components+d*ncomp+k);
00045 mpi.put(dynamic_buffer, length*ncomp, process, request);
00046 cout.flush();
00047 } else {
00048 dynamic_buffer=0;
00049 }
00050
00051 process=(ME-dp+Nproc) % Nproc;
00052 length=lattice().stop[process][nf]-lattice().start[process][ni];
00053 if(length>0) {
00054 if(ncomp==field_components) {
00055 where_to=m+lattice().start[process][ni]*field_components;
00056 mpi.get(where_to, length*field_components, process);
00057 where_to=0;
00058 } else {
00059 where_to=new T[length*ncomp];
00060 mpi.get(where_to, length*ncomp, process);
00061 for(idx=0; idx<length; idx++)
00062 for(k=0; k<ncomp; k++)
00063 *(m+(lattice().start[process][ni]+idx)*field_components+
00064 d*ncomp+k)=where_to[idx*ncomp+k];
00065 delete[] where_to;
00066 }
00067 }
00068
00069 process=(ME+dp) % Nproc;
00070 if(dynamic_buffer!=0) {
00071 mpi.wait(request);
00072 delete[] dynamic_buffer;
00073 }
00074 }
00075 mpi.comm_time+=mpi.time();
00076 }