⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parallel.hpp

📁 dysii是一款非常出色的滤波函数库
💻 HPP
字号:
#ifndef INDII_ML_AUX_PARALLEL_HPP#define INDII_ML_AUX_PARALLEL_HPP#include "vector.hpp"#include "matrix.hpp"#include "boost/mpi.hpp"#include <functional>namespace boost {  namespace mpi {    /* Omit these from documentation */    /// @cond COMMUTATIVE    template<>    struct is_commutative<std::plus<unsigned int>, unsigned int> : mpl::true_ {      //    };    template<>    struct is_commutative<std::plus<double>, double> : mpl::true_ {      //    };    template<>    struct is_commutative<std::plus<indii::ml::aux::vector>,        indii::ml::aux::vector> : mpl::true_ {      //    };    template<>    struct is_commutative<std::plus<indii::ml::aux::matrix>,        indii::ml::aux::matrix> : mpl::true_ {      //    };    template<>    struct is_commutative<std::plus<indii::ml::aux::symmetric_matrix>,        indii::ml::aux::symmetric_matrix> : mpl::true_ {      //    };    template<>    struct is_commutative<std::plus<indii::ml::aux::lower_triangular_matrix>,        indii::ml::aux::lower_triangular_matrix> : mpl::true_ {      //    };    template<>    struct is_commutative<std::plus<indii::ml::aux::upper_triangular_matrix>,        indii::ml::aux::upper_triangular_matrix> : mpl::true_ {      //    };    template<>    struct is_commutative<std::plus<indii::ml::aux::identity_matrix>,        indii::ml::aux::identity_matrix> : mpl::true_ {      //    };    template<>    struct is_commutative<std::plus<indii::ml::aux::zero_matrix>,        indii::ml::aux::zero_matrix> : mpl::true_ {      //    };    template<>    struct is_commutative<std::plus<indii::ml::aux::scalar_matrix>,        indii::ml::aux::scalar_matrix> : mpl::true_ {      //    };    template<>    struct is_commutative<std::plus<indii::ml::aux::sparse_matrix>,        indii::ml::aux::sparse_matrix> : mpl::true_ {      //    };    /// @endcond  }}namespace indii {  namespace ml {    namespace aux {  /**   * Rotate variable values between all nodes. For \f$N\f$ nodes, node   * \f$i\f$ sends its value to node \f$i+N-1\pmod{N}\f$ and receives   * the value of node \f$i+1\pmod{N}\f$. This facilitates   * calculations involving data stored across multiple nodes without   * gathering all the data onto one node.   *   * @param x Value to send. Contains value received on return.   */  template <class T>  void rotate(T& x);    }  }}template <class T>void indii::ml::aux::rotate(T& x) {  boost::mpi::communicator world;  boost::mpi::request reqSend, reqRecv;  const int rank = world.rank();  const int size = world.size();  T send(x);  if (size > 1) {    reqSend = world.isend((rank+size-1) % size, 0, send);    reqRecv = world.irecv((rank+1) % size, 0, x);    reqRecv.wait();    reqSend.wait();  }}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -