简体   繁体   English

C语言中的矩阵乘法多进程

[英]Matrix Multiplication multiprocess in C

I want to do matrix multiplication using multiple processes via fork and using shared memory with each of the process computing one row for small sized matrix but with higher sized matrices it is not possible to create a process for each row . 我想通过fork使用多个进程并使用共享内存来进行矩阵乘法,其中每个进程针对小型矩阵计算一行,但是对于大型矩阵,不可能为每一行创建一个进程。 So It should compute a block of rows determined by the size. 因此,它应该计算由大小决定的一行行。 For example upto 10 rows it should calculate one row per process and after that say for 20 rows one process should calculate 4 rows each. 例如,最多10行,每个进程应计算一行,然后说20行,每个进程应计算4行。 I am unable to program it as I can take row number as number of processes. 我无法对其编程,因为我可以将行号作为进程数。 Suppose I take number of processes constant say 8 then each block would have N/8 rows.But then size of matrix should be multiple of 8, and number of processes should be variable.Suppose it has 6 CPUs , Can I take number of processes to be constant ie 6 .What can be the right approach ? 假设我将进程数定为8,则每个块将有N / 8行。但是矩阵的大小应为8的倍数,并且进程数应该是可变的。假设它有6个CPU,我可以取进程数吗?保持不变,即6。正确的方法是什么? How should I write it ? 我应该怎么写?

Here's some example code which demonstrates matrix mult. 这是一些示例代码,演示了矩阵乘法。 in pthreads. 在pthreads中。 I found it almost instantly in a search engine. 我几乎在搜索引擎中立即发现了它。 It shows a method for doing what you describe. 它显示了一种执行您描述的方法的方法。
http://www.cs.arizona.edu/classes/cs422/spring13/examples/matmult-dyn.c http://www.cs.arizona.edu/classes/cs422/spring13/examples/matmult-dyn.c

You'll probably need to do some fine tuning of it to determine what is the best approach. 您可能需要对其进行一些微调,以确定什么是最佳方法。

You probably should also read this article: http://aristeia.com/TalkNotes/PDXCodeCamp2010.pdf 您可能还应该阅读这篇文章: http : //aristeia.com/TalkNotes/PDXCodeCamp2010.pdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM