Hi all,
I have this piece of code:
def distribution(number):
"Get distribution of number on all processes"
if not hasattr(distribution, "cpp_module"):
cpp_code = '''
#include <vector>
#include "mpi.h"
#include <dolfin.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/complex.h>
#include <pybind11/functional.h>
#include <pybind11/chrono.h>
typedef unsigned int uint;
namespace py = pybind11;
namespace dolfin {
std::vector<unsigned int> distribution(const MPI_Comm mpi_comm, int number)
{
// Variables to help in synchronization
int num_processes, this_process;
MPI_Comm_size(mpi_comm, &num_processes);
MPI_Comm_rank(mpi_comm, &this_process);
std::vector<uint> distribution(num_processes);
for(int i=0; i<num_processes; i++) {
if(i==this_process) {
distribution[i] = number;
}
MPI_Barrier(mpi_comm);
MPI_Bcast(&distribution[0], distribution.size(), MPI_UNSIGNED, i, mpi_comm);
}
return distribution;
}
}
PYBIND11_MODULE(SIGNATURE, m) {
m.def("distribution", &dolfin::distribution, py::arg("mpi_comm"), py::arg("number"));}
'''
distribution.cpp_module = compile_cpp_code(cpp_code)
cpp_module = distribution.cpp_module
return cpp_module.distribution(MPI.comm_world, number)
Whenever I try an integer let’s say distribution(200) is gives me the following error:
TypeError: distribution(): incompatible function arguments. The following argument types are supported:
1. (mpi_comm: int, number: int) -> List[int]
Invoked with: <mpi4py.MPI.Intracomm object at 0x7f1b07286fa8>, 200
My guess is there is something wrong with the PYBIND11_MODULE part. But I am not good with C++ and have never worked with PYBIND11_MODULE. So anything to help me out here would be much appreciated.
Best,