[英]Creating parallel threads using Win 32 API
Here is the problem: I have two sparse matrices described as vector of triplets. 问题是:我有两个稀疏矩阵,被描述为三元组的向量。 The task is to write multiplication function for them using parallel processing with Win 32 API.
任务是使用Win 32 API的并行处理为其编写乘法函数。 So I need to know how do I:
所以我需要知道如何:
1) Create a thread in Win 32 API 1)在Win 32 API中创建线程
2) Pass input parameters for it 2)传递输入参数
3) Get return value. 3)获取返回值。
Thanks in advance! 提前致谢!
Edit: "Process" changed for "Thread" 编辑:“进程”更改为“线程”
Well, the answer to your question is CreateProcess
and GetExitCodeProcess
. 好吧,您问题的答案是
CreateProcess
和GetExitCodeProcess
。
But the solution to your problem isn't another process at all, it's more threads. 但是解决您的问题的方法根本不是另一个过程,而是更多的线程。 And probably OpenMP is a much more suitable mechanism than creating your own threads.
可能OpenMP是比创建自己的线程更合适的机制。
If you have to use the Win32 API directly for threads, the process is something like: 如果必须将Win32 API直接用于线程,则过程类似于:
CreateThread
and pass the address of the work item descriptor. CreateThread
并传递工作项描述符的地址。 WaitForMultipleObjects
to join with the worker threads. WaitForMultipleObjects
以与辅助线程一起加入。 For even greater efficiency, you can use the Windows thread pool and call QueueUserWorkItem
. 为了获得更高的效率,可以使用Windows线程池并调用
QueueUserWorkItem
。 But while you won't have to create threads yourself, you'd then need event handles to join tasks back to the main thread. 但是,尽管您不必自己创建线程,但是您将需要事件句柄将任务连接回主线程。 It's about the same amount of code I suspect.
这与我怀疑的代码量差不多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.