Using .Net Assembly Methods in parfor Parallel loops.
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to use methods from a .Net Assembly class inside a parfor loop in MATLAB 2017a. Here is the relevant section of code, omitting the section where the method inputs are generated. I run the addAssembly command on all workers (which posts a lot of unnecessary info to the window, but I can deal with that):
gcp;
pctRunOnAll NET.addAssembly('SinapsXNet');
pctRunOnAll SP = SinapsXNet.SindaPlotting;
parfor i = 1:NumRecords
SP.getAllAtRecord('T',RecordNumbers(i));
TemperatureOut(i,:) = double(getXArray(SP));
end
And this creates the error "Warning: Unable to load .NET object. Saving (serializing) .NET objects into a MAT-file is not supported." This function works without an issue if constructed with a basic 'for' instead of 'parfor'. Is there a workaround for this error?
0 Kommentare
Antworten (1)
Edric Ellis
am 13 Nov. 2017
In your example, the variable SP is being transferred to the workers, and that uses the same machinery as save and load (despite your use of pctRunOnAll, the body of your parfor loop is using the SP instance transferred from the client). I don't have the necessary code to try this out, but perhaps it might work to do the following:
gcp;
pctRunOnAll NET.addAssembly('SinapsXNet');
SP_c = parallel.pool.Constant(@SinapsXNet.SindaPlotting);
parfor i = 1:NumRecords
SP = SP_c.Value;
SP.getAllAtRecord('T',RecordNumbers(i));
TemperatureOut(i,:) = double(getXArray(SP));
end
This avoids the problem by using parallel.pool.Constant with a function handle to build the .NET object directly on the workers.
3 Kommentare
Edric Ellis
am 20 Nov. 2017
That looks like a loop output is somehow a .NET object (that last warning is being thrown at the client when trying to interpret results from the workers). Does the parallel.pool.Constant appear to do the right thing at all? I.e. can you access the .Value field on the workers (using parfor or even spmd), and does it appear to contain the correct object? I.e.
spmd
disp(SP_c.Value)
end
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!