Share memory or get id of the worker access
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Helper
il 11 Mag 2018
Modificato: Helper
il 11 Mag 2018
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 Commenti
Vedere anche
Categorie
Scopri di più su Parallel for-Loops (parfor) in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!