Shared memory access control mechanism for process

2019-02-15 23:47发布

I have a shared memory used by multiple processes, these processes are created using MPI.

Now I need a mechanism to control the access of this shared memory.

I know that named semaphore and flock mechanisms can be used to do this but just wanted to know if MPI provides any special locking mechanism for shared memory usage ?

I am working on C under Linux.

2条回答
做自己的国王
2楼-- · 2019-02-16 00:07

No, MPI doesn't provide any support for shared memory. In fact, MPI would not want to support shared memory. The reason is that a program written with MPI is supposed to scale to a large number of processors, and a large number of processors never have shared memory.

However, it may happen, and often does, that groups of small number of processors (in that set of large number of processors) do have shared memory. To utilize that shared memory however, OpenMP is used.

OpenMP is very simple. I strongly suggest you learn it.

查看更多
成全新的幸福
3楼-- · 2019-02-16 00:10

MPI actually does provide support for shared memory now (as of version 3.0). You might try looking at the One-sided communication chapter (http://www.mpi-forum.org/docs/mpi-3.0/mpi30-report.pdf) starting with MPI_WIN_ALLOCATE_SHARED (11.2.3). To use this, you'll have to make sure you have an implementation that supports it. I know that the most recent versions of both MPICH and Open MPI work.

查看更多
登录 后发表回答