Share memory or get id of the worker access
3 次查看(过去 30 天)
显示 更早的评论
Hello, I am new to the parallel computing toolbox and having the following issue when using parfor.
Aim: I want to assemble a matrix using multi-threading for Finite Element discretizations.
Possible Way: 1. I was planning to use parafor to get the local assemblies and then sum up all the local assemblies. (The local assemblies mean the task for one thread.) The issue is I need to associate the local entries to the global entries and need an access of the global variables in each thread. I try the following which does not work.
nnz = 2000;
Threads =4;
loop = nnz/Threads;
A = zeros(nnz,1);
parfor i = 1:4
b = i;
A((i-1)*loop+1:loop*i) = b;
end
2. Another way, was to get to manually create all the data structures for each thread. Do the global assembly in each thread. And then add them up. But for this I need the thread id access. I do not know if this possible.
Other ways can be suggested. Thanks in advance.
0 个评论
回答(1 个)
Helper
2018-5-11
编辑:Helper
2018-5-11
The reason for why the first way does not work is the "A" variable is not a valid sliced variable. Variables within "parfor" have different meanings. Please refer to the following documentation links for more information:
There is another way to do this, which is using "spmd". So we could have:
spmd
A((labindex-1)*loop+1:loop*labindex) = labindex;
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Distributed Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!