COM interfaces in task parallel

1 view (last 30 days)
Kevin Dupraz
Kevin Dupraz on 26 Nov 2015
I'm using a COM interface to run calculation in separate software (Code V). I load the software and prepare it for calculation (create geometry, type of calculation etc). As the calculation is long I'm trying to do it in separate thread using Task. But when I run the Task it say:
Warning: Unable to calculate the dependencies of the
and then it crashed with:
Invoke Error, Dispatch Exception:
Source: CodeV.Command.107_SR1
Description: CodeV has not been opened. StartCodeV must be called before trying to execute a command.
It seems that the COM interface is not transmit through the Task. How can I pass through this limitation ? I don't want to set up my geometry during the task because it's a long procedure and I reuse the same geometry many times in the local session.
This is a simplification of my code I used:
%%%create the COM server for Code V calculation
CV_server = actxserver('CODEV.Command'); % open COM with last version of Code V by defaut
invoke(CV_server,'SetCommandTimeout',500000); % timeout for synchronous commands
invoke(CV_server,'SetMaxTextBufferSize',300000); % Buffer size in characters
invoke(CV_server,'SetStartingDirectory',pwd); % set starting directory
invoke(CV_server,'StartCodeV') ; % start Code V
generate_geometry(CV_server); % create the geometry in Code V through invoke(CV_server,'Command',[...]) command
%%%Create the Task to run the calculation
profileName = parallel.defaultClusterProfile();
clust = parcluster(profileName);
job = createJob(clust);
task = createTask(job, @(x)invoke(x,'Command','SA ?'), 1, {CV_server}); % here we only ask for listing the geometry components
%%%wait for job (or do some other calculation)
out = fetchOutputs(job);
Here the function generate_geometry(), creates geometry components in Code V application using the invoke command. For the example I only ask to list the geometry components during the task (usually I run the calculation in Code V application instead). I test my code and it works when I do not used parallel task.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!