I’m trying to write a program using MPI and I have a question that would help me a lot. Is it possible in MPI to send a pointer to another process in any way? What I want is to just send the pointer, not to copy the memory from one process to the other.
If that doesn’t apply is it possible to represent a pointer as a string for example and then send it so that the receiving process can again cast it to pointer and have access to the memory pointed?
Thanks in advance.
Short answer: No, you cannot do that.
The explanation is that MPI processes are not guaranteed to share memory in any way. In fact most MPI implementations map MPI processes to actual OS processes, so that they don’t share the same memory adress space. Plus you might want to run MPI applications on a cluster, in which case MPI processes are not even on the same hardware.
EDIT:
MPI2 introduces window operations (see e.g.
MPI_WIN_CREATE), which mimic shared memory access. Your implementation might decide that if all processes are running on the same node, such window operations can be implemented using shared memory. But as always with MPI, you never have any guarantee how an operation will be implemented