【问题标题】:boost.mpi.world Communicator did not match C++ signature: boost::mpi::communicatorboost.mpi.world Communicator 与 C++ 签名不匹配:boost::mpi::communicator
【发布时间】:2016-05-20 00:47:15
【问题描述】:

我正在尽力将 C++ 模块链接到 python 绑定。我正在努力实现增强 mpi 通信。我将boost.mpi.world 对象发送到C++,它期待boost::mpi::communicator 对象。当我从 python 调用我的 C++ 函数时,它会引发不匹配的签名错误。

myModule.myfunc(Communicator, NoneType, NoneType, _ExcInfo) did not match C++ signature:
myfunc(boost::mpi::communicator {lvalue}, char*, char*, boost::python::api::object)

我不明白 - 看起来它们确实是同一个对象,因此应该具有相同的 C++ 签名。

我是否正确使用了 boost mpi?什么可能导致此问题?

尝试一个可重复的例子

为了重新创建它,我制作了一个 setup.py 文件和一个包含我的函数的 wrapper.cpp 文件:

包装器.cpp:

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python/numeric.hpp>
#include <boost/mpi.hpp>

#ifdef WINDOWS
#include <windows.h>
#endif

namespace bp = boost::python;
namespace bpn = boost::python::numeric;

int run_mod_mpi(boost::mpi::communicator &_mpi)

{
  return 111;
}

#include <boost/python.hpp>
using namespace boost::python;
BOOST_PYTHON_MODULE(myMod)
{
  using namespace bpn;

  def("run_my_mpi_mod", run_mod_mpi, "run my module with mpi");
}

setup.py:

from setuptools import setup
from setuptools.extension import Extension
import os

include_dirs = ['/nopt/nrel/apps/boost/1.55.0-openmpi-gcc_140415/include']
library_dirs = ['/nopt/nrel/apps/boost/1.55.0-openmpi-gcc_140415/lib']

EXTRA_LIBS = ['gfortran']

sources = ['wrapper.cpp']

external_libs = [
    'boost_regex', 'boost_filesystem', 'boost_serialization', 'boost_system',
    'boost_signals', 'boost_python']#, 'lapack', 'blas']

external_libs.append('boost_mpi')
os.environ['CC'] = 'mpicxx'


libraries = external_libs + EXTRA_LIBS

myMod = Extension(name='myMod',
                     sources=sources,
                     include_dirs=include_dirs,
                     library_dirs=library_dirs,
                     libraries=libraries,
                     language='c++')

setup(name='myMod',
      description='a module I made',
      py_modules=['dakota', 'test_dakota'],
      ext_modules=[myMod],
      zip_safe=False,
      )

问题:

$ python setup.py build
$ cd build/lib.linux-x86_64-2.7
$ ipython

In [1]: import myMod
In [2]: from boost.mpi import world
In [3]: myMod.run_my_mpi_mod(world)
Out[3]: 111

所以,我误诊了我的问题。

【问题讨论】:

    标签: python c++ boost mpi boost-python


    【解决方案1】:

    您应该将**char*, char*** 作为第二个参数,但您将两个 NoneType 对象放在那里。

    【讨论】:

      猜你喜欢
      • 2017-09-08
      • 1970-01-01
      • 2019-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-14
      • 1970-01-01
      • 2012-06-18
      相关资源
      最近更新 更多