1

I have written an mpi app in c that sorts n positive random integers. I would like to put a graphical front end on it and wonder if there is a way to use Python's graphics library via SWIG to do this. I suppose I could resort to TCP or UDP sockets. I have no experience with SWIG or sockets but have a sense that sockets are fairly complex and do know Python.

I'd appreciate some help in going down this path, in terms of code examples and/or learning materials or just some written comments from readers of this list.

Thanks, Scott

  • What does a graphics library have to do with networking? – Adam Jun 05 '14 at 02:53
  • I want to plot the random integers on a gui somehow, to give others a sense what is happening as the values are sorted from a set of random points all over the graph to some kind of smooth curve. – user3583629 Jun 05 '14 at 17:14
  • http://stackoverflow.com/a/9042139/168175 might be what you're looking for. – Flexo Jun 05 '14 at 21:03

1 Answers1

2

Your question is extremely ambiguous, but I'm assuming you have a C program and you want to do some plotting using a Python library.

It looks like you just need to embed the Python interpreter. There is an official guide on embedding.

It's pretty straight forward:

#include <Python.h>

int
main(int argc, char *argv[])
{
  Py_SetProgramName(argv[0]);  /* optional but recommended */
  Py_Initialize();
  PyRun_SimpleString("from time import time,ctime\n"
                     "print 'Today is',ctime(time())\n");
  Py_Finalize();
  return 0;
}

Just enter your plotting script there. MPI makes no difference.

Adam
  • 16,808
  • 7
  • 52
  • 98
  • So, when you say enter it 'there', do you mean between the Py_Initialize() and the Py_Finalize()? And, just to check my understanding, this segment exposes Python to my C code? I can place my C code in this code and it will allow the C code to call Python GUI code to plot my internal values? – user3583629 Jun 05 '14 at 17:19
  • The python code is the argument to `PyRun_SimpleString`. – Adam Jun 05 '14 at 17:32
  • I see. So, I ought to place all my Python code into functions, which I can wrap with PyRun_SimpleString()? – user3583629 Jun 05 '14 at 22:25