Running cantera in parallel - matlab

400 views
Skip to first unread message

jamie kee

unread,
Jul 8, 2015, 2:35:46 PM7/8/15
to canter...@googlegroups.com
Hi all,

I've been interested in running cantera in parallel using matlab's parfor structure. Some previous posts mentioned creating separate cantera objects for each worker. However, when I try that, matlab complains that the class constructors are not set up to its liking.

pool = gcp('nocreate');

if isempty(pool)

   pool = parpool;

end

poolsize = pool.NumWorkers;


gases
= cell(poolsize,1);

for n = 1:poolsize
    gases
{n} = air;
end

parfor j
= 1:poolsize
    gas
= gases{j};
%   density(gas)
end


This segment provides the following warning messages:


Warning: Element(s) of class 'Solution' do not match the current constructor definition.  The element(s) have been converted to structures.
Warning: Element(s) of class 'Kinetics' do not match the current constructor definition.  The element(s) have been converted to structures.
Warning: Element(s) of class 'ThermoPhase' do not match the current constructor definition.  The element(s) have been converted to structures.
Warning: Element(s) of class 'Transport' do not match the current constructor definition.  The element(s) have been converted to structures.


Modifying the class structures a bit allowed me to get the parfor running without warnings and without converting to structures. However if I tried calling, for example density(gas), the correct thermo_id is being passed in the matlab but that item no longer exists in the thermo cabinet on the cpp side. I may have changed the class structure incorrectly though.


Another suggestion I tried was remaking the object each time


parfor j = 1:poolsize      
    gas
= importPhase('example.xml','gas');
    density
(gas)
end
cleanup


This seems to work. Cleanup needs to be called, otherwise the number of objects begin to build up quickly.

All that considered, is there a recommended way to run parallel in matlab? Or should I stick to recreating the object each iteration?


Thanks, any suggestions are appreciated,

Jamie


If important: I'm on a mac running Cantera 2.2.0

lixx...@umn.edu

unread,
Feb 17, 2016, 1:57:35 PM2/17/16
to Cantera Users' Group
Dear Jamie,

I am also working on a similar problem and may I ask how to modify the class structures? I will try repeat your procedures and see if the thermo_id issue could be fixed.

Best regards, 

rbat...@gmail.com

unread,
Apr 11, 2016, 5:29:22 PM4/11/16
to Cantera Users' Group
I'm running into a similar problem when trying to run Cantera in MATLAB in parallel.

 I noticed that it helps to pre-specify structures that are created:


I realize this probably doesn't exactly solve your problem but I figured I'd throw in this suggestion anyway. 

Best,

Richard 

Running Cantera 2.02 64bit  on Windows 

David Couch

unread,
Nov 29, 2021, 10:11:53 PM11/29/21
to Cantera Users' Group
I would love for someone to figure out this problem. I would also like to run some chemical kinetics simulation in parallel.

Note that importPhase() has been replaced with Solution() since this thread started. The new function seems to work the same way as the old, except it requires .yaml files and does not work with .cti files.

Somewhere in the MATLAB documentation on parallel computing, I found that class constructors must work with no inputs. So I tried adding a section to the ThermoPhase, Kinetics, and Solution classes to handle no inputs without throwing an error (by pointing to the default water.yaml file), but I still have all the same problems. Apparently this was not the "element of class 'Solution' [that does] not match the current constructor definition."

I think I am giving up for now on making a parallel version.
Best,
David
Running Cantera 2.5.1, MATLAB 2019b, Windows 10

Steven DeCaluwe

unread,
Nov 30, 2021, 2:05:53 AM11/30/21
to Cantera Users' Group
Hi David,

I don’t remember that Jamie ever got this working to a point where he used it much.  He has since graduated and is a postdoc at Wash. St. now (he’ll still likely get this email - hi, Jamie).

One thought that occurs to me: would a SolutionArray be useful for this?  Searching the docs, it loos like this is a Python-only method, but I wonder if you could create an implementation in the Matlab toolbox? 

Separately, a re-design of the Matlab interface is currently underway.  I wonder if this might also help address the hang-ups, here.

Sorry that I’m not too much help, here, but just a few thoughts.

Steven



--
You received this message because you are subscribed to the Google Groups "Cantera Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cantera-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cantera-users/23044275-f71d-4d2d-9d4b-1d3b433b343cn%40googlegroups.com.

jamie

unread,
Dec 10, 2021, 2:18:38 PM12/10/21
to Cantera Users' Group
Hi all and Steven!

Looks like I never replied to this thread 6 years ago...  

That's correct that I never fully used the matlab parallel processing with Cantera. As you mentioned one of the initial hangups is that there is no null constructor for the classes, so matlab has an issue initializing the structures in a parfor loop. You can manually add in null constructors and recompile cantera. Based on my initial message it looks like that partially solves some of the initialization errors, but apparently incorrectly links the thermo/kinetic/transport classes. 

My guess is that Solutions cannot be initialized, then linked to a cti (or thermo/kinetic/transport classes) after. Rather they need to be created at the same time from matlab. But the matlab parfor wants an initialization event first. So I think looking into the constructors for solution/thermo/kinetic/transport classes is the best bet, then making sure they can be linked to each other after the initialization event. However, I think access to this on the matlab side is limited. 

Hopefully this helps anyone who is interested in investigating further, but my knowledge on this may be dated...

Jamie
Reply all
Reply to author
Forward
0 new messages