Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

mpi_eman.c File Reference

#include <python2.6/Python.h>
#include <math.h>
#include <mpi.h>

Include dependency graph for mpi_eman.c:

Include dependency graph

Go to the source code of this file.

Functions

PyObject * mpi_init (PyObject *self, PyObject *args)
PyObject * mpi_comm_rank (PyObject *self, PyObject *args)
PyObject * mpi_comm_size (PyObject *self, PyObject *args)
PyObject * mpi_send (PyObject *self, PyObject *args)
PyObject * mpi_recv (PyObject *self, PyObject *args)
PyObject * mpi_probe (PyObject *self, PyObject *args)
PyObject * mpi_bcast_send (PyObject *self, PyObject *args)
PyObject * mpi_bcast_recv (PyObject *self, PyObject *args)
PyObject * mpi_barrier (PyObject *self, PyObject *args)
PyObject * mpi_finalize (PyObject *self, PyObject *args)
PyMODINIT_FUNC initmpi_eman_c (void)

Variables

PyMethodDef EmanMpiMethods []


Function Documentation

PyMODINIT_FUNC initmpi_eman_c void   ) 
 

Definition at line 175 of file mpi_eman.c.

References EmanMpiMethods, and PyMODINIT_FUNC.

00175                                     {
00176         (void) Py_InitModule("mpi_eman_c", EmanMpiMethods);
00177 }

PyObject* mpi_barrier PyObject *  self,
PyObject *  args
[static]
 

Definition at line 150 of file mpi_eman.c.

00150                                                              {
00151 
00152         MPI_Barrier(MPI_COMM_WORLD);
00153         Py_RETURN_NONE;
00154 }

PyObject* mpi_bcast_recv PyObject *  self,
PyObject *  args
[static]
 

Definition at line 134 of file mpi_eman.c.

References data.

00134                                                                {
00135         const char * data;
00136         int datalen;
00137         int root;
00138 
00139         PyArg_ParseTuple(args,"ii",&datalen,&root);
00140         data=(const char *)malloc(datalen);
00141         MPI_Bcast((void *)data,datalen,MPI_CHAR,root,MPI_COMM_WORLD);
00142 
00143         PyObject *ret = Py_BuildValue("s#",(void *)data,datalen);
00144         free((void *)data);
00145 
00146         return ret;
00147 }

PyObject* mpi_bcast_send PyObject *  self,
PyObject *  args
[static]
 

Definition at line 115 of file mpi_eman.c.

References data.

00115                                                                {
00116         const char * data;
00117         int datalen;
00118         int myrank;
00119         MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
00120 
00121         PyArg_ParseTuple(args,"s#",&data,&datalen);
00122 //                      printf("Sent: %d\n",datalen);
00123         MPI_Bcast((void *)data,datalen,MPI_CHAR,myrank,MPI_COMM_WORLD);
00124         Py_RETURN_NONE;
00125 }

PyObject* mpi_comm_rank PyObject *  self,
PyObject *  args
[static]
 

Definition at line 24 of file mpi_eman.c.

00024                                                               {
00025 int myrank;
00026 MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
00027 
00028 return Py_BuildValue("i",myrank);
00029 }

PyObject* mpi_comm_size PyObject *  self,
PyObject *  args
[static]
 

Definition at line 31 of file mpi_eman.c.

00031                                                               {
00032 int size;
00033 MPI_Comm_size(MPI_COMM_WORLD, &size);
00034 
00035 return Py_BuildValue("i",size);         
00036 }

PyObject* mpi_finalize PyObject *  self,
PyObject *  args
[static]
 

Definition at line 156 of file mpi_eman.c.

00156                                                               {
00157         MPI_Finalize();
00158         Py_RETURN_NONE;
00159 }

PyObject* mpi_init PyObject *  self,
PyObject *  args
[static]
 

Definition at line 12 of file mpi_eman.c.

00012                                                          {
00013 MPI_Init(NULL,NULL);
00014 
00015 int myrank;
00016 MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
00017 
00018 int size;
00019 MPI_Comm_size (MPI_COMM_WORLD, &size);
00020 
00021 return Py_BuildValue("ii",myrank,size);
00022 }

PyObject* mpi_probe PyObject *  self,
PyObject *  args
[static]
 

Definition at line 90 of file mpi_eman.c.

References status.

00090                                                           {
00091 MPI_Status status;
00092 int datalen,src,tag;
00093 
00094 // Get a string argument
00095 if (!PyArg_ParseTuple(args,"ii",&src,&tag)) return NULL;
00096 
00097 if (src<0) src=MPI_ANY_SOURCE;
00098 if (tag<0) tag=MPI_ANY_TAG;
00099 
00100 MPI_Probe(src,tag,MPI_COMM_WORLD,&status);
00101 MPI_Get_count(&status,MPI_CHAR,&datalen);
00102 
00103 PyObject *ret = Py_BuildValue("iii",datalen,status.MPI_SOURCE,status.MPI_TAG);
00104 
00105 return ret;
00106 }

PyObject* mpi_recv PyObject *  self,
PyObject *  args
[static]
 

Definition at line 60 of file mpi_eman.c.

References data, and status.

00060                                                          {
00061 MPI_Status status;
00062 const char * data;
00063 int datalen,src,tag;
00064 
00065 // Get a string argument
00066 if (!PyArg_ParseTuple(args,"ii",&src,&tag)) return NULL;
00067 
00068 if (src<0) src=MPI_ANY_SOURCE;
00069 if (tag<0) tag=MPI_ANY_TAG;
00070 
00071 MPI_Probe(src,tag,MPI_COMM_WORLD,&status);
00072 
00073 MPI_Get_count(&status,MPI_CHAR,&datalen);
00074 data=(const char *)malloc(datalen);
00075 MPI_Recv((void *)data,datalen,MPI_CHAR,src,tag,MPI_COMM_WORLD,&status);
00076 
00077 PyObject *ret = Py_BuildValue("s#ii",(void *)data,datalen,status.MPI_SOURCE,status.MPI_TAG);
00078 free((void *)data);
00079 
00080 return ret;
00081 }

PyObject* mpi_send PyObject *  self,
PyObject *  args
[static]
 

Definition at line 42 of file mpi_eman.c.

References data.

00042                                                          {
00043 const char * data;
00044 int datalen,dest,tag;
00045 
00046 // Get a string argument
00047 if (!PyArg_ParseTuple(args,"s#ii",&data,&datalen,&dest,&tag)) return NULL;
00048 
00049 MPI_Send((void *)data,datalen,MPI_CHAR,dest,tag,MPI_COMM_WORLD);
00050 
00051         Py_RETURN_NONE;
00052 
00053 }


Variable Documentation

PyMethodDef EmanMpiMethods[] [static]
 

Initial value:

 {
        {"mpi_init",mpi_init,METH_VARARGS,"MPI_Init command. No arguments. Returns the rank id and process count to each node."},
        {"mpi_comm_rank",mpi_comm_rank,METH_VARARGS,"This will return the rank id, same as returned by mpi_init."},
        {"mpi_comm_size",mpi_comm_size,METH_VARARGS,"This will return the number of processes, same as returned by mpi_init."},
        {"mpi_send",mpi_send,METH_VARARGS,"MPI_Send(string,destination rank,tag)"},
        {"mpi_recv",mpi_recv,METH_VARARGS,"MPI_Recv(source rank,tag). If either is negative, arbitrary values accepted. Returns (data,src,tag)."},
        {"mpi_probe",mpi_probe,METH_VARARGS,"MPI_Probe(source rank,tag). If either is negative, arbitrary values accepted. Returns (len,src,tag)."},
        {"mpi_bcast_send",mpi_bcast_send,METH_VARARGS,"MPI_Bcast(string). Provide a string to broadcast to other nodes"},
        {"mpi_bcast_recv",mpi_bcast_recv,METH_VARARGS,"MPI_Bcast(data_length,source). Receives a broadcast of length data_length from source and returns a string."},
        {"mpi_barrier",mpi_barrier,METH_VARARGS,"MPI_Barrier(). No arguments or return. Blocks until all nodes call it."},
        {"mpi_finalize",mpi_finalize,METH_VARARGS,"MPI_Finalize(). No arguments or return. Call before exiting an MPI Python program exactly once."},
        {NULL,NULL,0,NULL}
}

Definition at line 161 of file mpi_eman.c.

Referenced by initmpi_eman_c().


Generated on Thu Dec 9 13:46:34 2010 for EMAN2 by  doxygen 1.3.9.1