Most efficient matrix multiplication in C using fork() and IPC

半城伤御伤魂 提交于 2019-12-24 16:46:35

问题


I need to implement concurrent matrix multiplication in C using multiple processes. I understand that because each process has its own private address space, I will have to use some form of interprocess communication (IPC). I did some looking around and couldn't find many implementations that didn't use threads. I was wondering if anyone knew the most best way to go about this, either using shared memory, message passing, or pipes? I am not asking for a solution, but rather, if anyone knows, which of these methods will be more efficient with matrix multiplication. Or if there is a common standard way to do this with multiple processes?


回答1:


The most efficient way of concurrently processing matrix multiplications would be shared memory. In this way, you don't have to serialize your matrix through a pipe/message and you can directly apply your multiplications on your shared memory space.




回答2:


Shared memory will be a good solution for this problem, I think. The processes can compute their solutions and share one memory to take the solutions together.

#include <sys/ipc.h>
#include <sys/shm.h>
int shmget(key_t key, int size, int shmflg);

Is one of the C functions for shared memory (you'll need shmat() and maybe shmdt() and shmctl() too).

Also you have to care about synchronization so that the processes does not manipulate the computation from each other.

I would use semaphores for that: see Semaphores in C and Semaphore Wikipedia



来源:https://stackoverflow.com/questions/12569785/most-efficient-matrix-multiplication-in-c-using-fork-and-ipc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!