当前位置: 首页>>代码示例>>C++>>正文


C++ Communicator::Sum方法代码示例

本文整理汇总了C++中Communicator::Sum方法的典型用法代码示例。如果您正苦于以下问题:C++ Communicator::Sum方法的具体用法?C++ Communicator::Sum怎么用?C++ Communicator::Sum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Communicator的用法示例。


在下文中一共展示了Communicator::Sum方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: calculateAllDistances

void MultiReferenceBase::calculateAllDistances( const Pbc& pbc, const std::vector<Value*> & vals, Communicator& comm, Matrix<double>& distances, const bool& squared ) {
  distances=0.0;
  unsigned k=0, size=comm.Get_size(), rank=comm.Get_rank();
  for(unsigned i=1; i<frames.size(); ++i) {
    for(unsigned j=0; j<i; ++j) {
      if( (k++)%size!=rank ) continue;
      distances(i,j) = distances(j,i) = distance( pbc, vals, frames[i], frames[j], squared );
    }
  }
  comm.Sum( distances );
}
开发者ID:epfl-cosmo,项目名称:plumed2,代码行数:11,代码来源:MultiReferenceBase.cpp

示例2: small_test_mpi

// short test to see if MPI surrogate function do what they should
void small_test_mpi() {
  Communicator comm;
  Vector x0(1,2,3),x=x0;
  Vector y0(4,5,6),y=y0;
  
  plumed_assert(x[0]==x0[0] && x[1]==x0[1] && x[2]==x0[2]);
  plumed_assert(y[0]==y0[0] && y[1]==y0[1] && y[2]==y0[2]);
  comm.Sum(x);
  plumed_assert(x[0]==x0[0] && x[1]==x0[1] && x[2]==x0[2]);
  plumed_assert(y[0]==y0[0] && y[1]==y0[1] && y[2]==y0[2]);
  comm.Allgather(x,y);
  plumed_assert(x[0]==x0[0] && x[1]==x0[1] && x[2]==x0[2]);
  plumed_assert(y[0]==x0[0] && y[1]==x0[1] && y[2]==x0[2]);
  std::vector<int> count(1,3);
  std::vector<int> displ(1,0);
  x=x0;
  y=y0;
  comm.Allgatherv(y,x,count.data(),displ.data());
  plumed_assert(x[0]==y0[0] && x[1]==y0[1] && x[2]==y0[2]);
  plumed_assert(y[0]==y0[0] && y[1]==y0[1] && y[2]==y0[2]);
}
开发者ID:GiovanniBussi,项目名称:test-travis-ci,代码行数:22,代码来源:main.cpp

示例3: dumpforces


//.........这里部分代码省略.........
         } else plumed_error();
         if(!debug_pd || ( i>=pd_start && i<pd_start+pd_nlocal) ){
           coordinates[3*i]=real(cc[0]);
           coordinates[3*i+1]=real(cc[1]);
           coordinates[3*i+2]=real(cc[2]);
         }
       }
       if(trajectory_fmt=="gro"){
         if(!Tools::getline(fp,line)) error("premature end of trajectory file");
         std::vector<string> words=Tools::getWords(line);
         if(words.size()<3) error("cannot understand box format");
         Tools::convert(words[0],cell[0]);
         Tools::convert(words[1],cell[4]);
         Tools::convert(words[2],cell[8]);
         if(words.size()>3) Tools::convert(words[3],cell[1]);
         if(words.size()>4) Tools::convert(words[4],cell[2]);
         if(words.size()>5) Tools::convert(words[5],cell[3]);
         if(words.size()>6) Tools::convert(words[6],cell[5]);
         if(words.size()>7) Tools::convert(words[7],cell[6]);
         if(words.size()>8) Tools::convert(words[8],cell[7]);
       }

       if(debug_dd){
         for(int i=0;i<dd_nlocal;++i){
           int kk=dd_gatindex[i];
           dd_coordinates[3*i+0]=coordinates[3*kk+0];
           dd_coordinates[3*i+1]=coordinates[3*kk+1];
           dd_coordinates[3*i+2]=coordinates[3*kk+2];
         }
         p.cmd("setForces",&dd_forces[0]);
         p.cmd("setPositions",&dd_coordinates[0]);
         p.cmd("setMasses",&dd_masses[0]);
         p.cmd("setCharges",&dd_charges[0]);
       } else {
         p.cmd("setForces",&forces[3*pd_start]);
         p.cmd("setPositions",&coordinates[3*pd_start]);
         p.cmd("setMasses",&masses[pd_start]);
         p.cmd("setCharges",&charges[pd_start]);
       }
       p.cmd("setBox",&cell[0]);
       p.cmd("setVirial",&virial[0]);
   }
   p.cmd("calc");

// this is necessary as only processor zero is adding to the virial:
   intracomm.Bcast(virial,0);
   if(debug_pd) intracomm.Sum(forces);
   if(debug_dd){
     for(int i=0;i<dd_nlocal;i++){
       forces[3*dd_gatindex[i]+0]=dd_forces[3*i+0];
       forces[3*dd_gatindex[i]+1]=dd_forces[3*i+1];
       forces[3*dd_gatindex[i]+2]=dd_forces[3*i+2];
     }
     dd_forces.assign(3*natoms,0.0);
     intracomm.Sum(forces);
   }
   if(debug_grex &&step%grex_stride==0){
     p.cmd("GREX savePositions");
     if(intracomm.Get_rank()>0){
       p.cmd("GREX prepare");
     } else {
       int r=intercomm.Get_rank();
       int n=intercomm.Get_size();
       int partner=r+(2*((r+step/grex_stride)%2))-1;
       if(partner<0)partner=0;
       if(partner>=n) partner=n-1;
       p.cmd("GREX setPartner",&partner);
       p.cmd("GREX calculate");
       p.cmd("GREX shareAllDeltaBias");
       for(int i=0;i<n;i++){
         string s; Tools::convert(i,s);
         real a; s="GREX getDeltaBias "+s; p.cmd(s.c_str(),&a);
         if(grex_log) fprintf(grex_log," %f",a);
       }
       if(grex_log) fprintf(grex_log,"\n");
     }
   }


   if(fp_forces){
     fprintf(fp_forces,"%d\n",natoms);
     string fmt=dumpforcesFmt+" "+dumpforcesFmt+" "+dumpforcesFmt+"\n";
     fprintf(fp_forces,fmt.c_str(),virial[0],virial[4],virial[8]);
     fmt="X "+fmt;
     for(int i=0;i<natoms;i++)
       fprintf(fp_forces,fmt.c_str(),forces[3*i],forces[3*i+1],forces[3*i+2]);
   }

    if(noatoms && plumedStopCondition) break;

    step+=stride;
  }
  p.cmd("runFinalJobs");

  if(fp_forces) fclose(fp_forces);
  if(fp && fp!=in)fclose(fp);
  if(grex_log) fclose(grex_log);
  
  return 0;
}
开发者ID:apoma,项目名称:plumed2,代码行数:101,代码来源:Driver.cpp


注:本文中的Communicator::Sum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。