Passing composite variable to mex file
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Vivek Bhattacharya
il 31 Gen 2022
Commentato: Edric Ellis
il 31 Gen 2022
I am running an spmd, and I am wondering if there is a way to pass a composite variable to a mex file without "aggregating" it first. The following is a (simple) example. Say I have the following code.
parpool(2);
spmd
test = labindex + zeros(1000, 2);
end
result = sum([test{:}], 2);
Suppose I would like to replace the sum function with a C/mex implementation of it. It is possible to do something like the following:
test_cellarray = test(:);
result = sum_function(test_cellarray); % Not a built-in function
where sum_function takes in cell arrays. However, in the above "solution", the first line takes up the vast majority of the time.
Is it possible to pass "test" directly to a mex function and access the parts for different workers through pointers?
Thanks for the help.
2 Commenti
Risposta accettata
Edric Ellis
il 31 Gen 2022
Unfortunately, there is no way to access the elements of a Composite from a MEX file. Is there any way you could run the MEX file directly on the workers? If you need to run it on each element, that would probably be the best way.
2 Commenti
Edric Ellis
il 31 Gen 2022
You might be better off collecting the data on a single worker, and working with it there. Worker-to-worker communication is generally more efficient than worker-to-client. I.e. something like:
spmd
myVal = someComputation();
catDim = 1; % dimension to concatenate results
targetWorker = 1;
allVals = gcat(myVal, catDim, targetWorker);
if labindex == targetWorker
endResult = doStuff(allVals);
end
end
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical 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!