예제 #1
0
bool PythonSignal::open(boost::python::list macAddress) {
  BOOST_VERIFY(mpSignal != 0);
  uint8_t mac[6] = {0,0,0,0,0,0};  
  if(boost::python::extract<size_t>(macAddress.attr("__len__")()) >= 6) {
    for (int i = 5; i >= 0; i--) {
      mac[i] = boost::python::extract<uint8_t>(macAddress.pop());
    }
  }
  return mpSignal->open(mac);
}
예제 #2
0
bool mpi_init(boost::python::list python_argv)
{
  using boost::python::extract;
  using boost::python::object;

  // If already initialized, do nothing but note that initialization
  // is done.
  int flag = 0;
  int result = MPI_Initialized(&flag);
  assert(result == MPI_SUCCESS);
  if (flag) return false;

  // Convert Python argv into C-style argc/argv. Ewwwww!
  int my_argc = extract<int>(python_argv.attr("__len__")());
  char** my_argv = new char*[my_argc];
  for (int arg = 0; arg < my_argc; ++arg)
    my_argv[arg] = strdup(extract<const char*>(python_argv[arg]));

  // Initialize MPI
  int mpi_argc = my_argc;
  char** mpi_argv = my_argv;
  result = MPI_Init(&mpi_argc, &mpi_argv);
  assert(result == MPI_SUCCESS);

  // If anything changed, convert C-style argc/argv into Python argv
  if (mpi_argv != my_argv) {
    // Tear down Python argv
    while (int(extract<int>(python_argv.attr("__len__")())) > 0)
      python_argv.pop();

    // Build up new Python argv
    for (int arg = 0; arg < mpi_argc; ++arg)
      python_argv.append(object(mpi_argv[arg]));
  }

  for (int arg = 0; arg < my_argc; ++arg)
    free(my_argv[arg]);
  delete [] my_argv;

  return true;
}