Low-Level API in MATLAB

53 views
Skip to first unread message

Daniel Boman

unread,
May 23, 2022, 8:14:30 PM5/23/22
to coolprop-users
I am attempting to implement the low-level API in MATLAB R2022a for reasons of speed (need to evaluate millions of function calls, and the overhead associated with doing so through Python via MATLAB is much too slow). However, I am running into two issues. First, the file structure on my computer seems to be substantially different than that in the example. I am using Windows 10, and there doesn't seem to be a libs directory in the install directory for CoolProp (AppData/Roaming). Second, even though I have installed the MinGW add-on for MATLAB, when I try to use loadlibrary on CoolPropLib.h, I get the error that a supported compiler is not detected. I have verified in the MATLAB examples that the compiler does work on the example file.

Can you please advise on how to address these challenges?

Thank you in advance for your help!

Ian Bell

unread,
May 24, 2022, 9:41:06 AM5/24/22
to coolpro...@googlegroups.com
For sure you need to change paths as appropriate for your machine. If you really care about speed,  consider c++, Julia or Matlab

I don't think mingw plays nicely with Matlab, check the docs.  There are multiple flavors of mingw as well,  which further complicates things. 

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coolprop-users/05fdc3de-19d4-4155-97e3-7cd55bfc9dcan%40googlegroups.com.

Daniel Boman

unread,
May 24, 2022, 11:44:27 AM5/24/22
to coolprop-users
Thanks for the quick response. Maybe I'm asking the wrong question. The example script on the CoolProp site has a path_to_lib variable that gets added to the path and never seems to get used again. What is the purpose of adding this directory to the path? What files would be in this directory on a non-Windows system?

My confusion with MinGW is that it is the compiler that MATLAB recommends using. In fact, MATLAB has supported it as an add-on since R2017a. Is there a reason that it wouldn't work with CoolProp?

Ian Bell

unread,
May 24, 2022, 7:16:32 PM5/24/22
to coolpro...@googlegroups.com
Yeah, I think you can get away without that.

There was a time that mingw and MATLAB didn't get along, maybe that is no longer the case.  Make sure you use their mingw though, to have the greatest chance of success.

Are you already using the low-level interface? Another user complained about the speed of the python interface in MATLAB, but with a bit of work, we got it to be only two times slower than in python, which is about as good as you can expect.

Michael LaPresti

unread,
May 26, 2022, 2:48:05 PM5/26/22
to coolprop-users
I have recently implemented the low-level API in Matlab R2022A. I built a light handle class to abstract the calls to the low level API. Speed is very good.

If you have any specific questions about implementation, configuration, etc., I'd be happy to look into my own environment and let you know what I've done. 

Daniel Boman

unread,
May 26, 2022, 3:22:13 PM5/26/22
to coolprop-users
Hi Michael,

I would appreciate any help you're willing to give on getting the low-level API set up. I can't seem to get MATLAB to even import the functions from the DLL, so clearly I'm doing something wrong. Can you please let me know what the trick is to access the API?

Michael LaPresti

unread,
May 26, 2022, 3:32:34 PM5/26/22
to coolpro...@googlegroups.com
Sure. As a start, can you share your code so far. An easy test might be for me to try running it and compare the response/errors. 

On May 26, 2022, at 3:22 PM, Daniel Boman <dbo...@gradientcomfort.com> wrote:

Hi Michael,

Daniel Boman

unread,
May 26, 2022, 3:42:32 PM5/26/22
to coolprop-users
At this point, I'm using the code posted as an example at http://www.coolprop.org/dev/coolprop/wrappers/MATLAB/index.html#id3 with the following modified code at the beginning:

path_to_lib = '/work/CoolProp/libs/shared'; %specify path to coolprop shared library
path_to_include= 'C:\Users\Daniel Boman\AppData\Roaming\CoolProp'; %specify path to coolprop's include folder
% Loading shared library
if ~libisloaded('coolprop') %checking whether library is already loaded
       %addpath(path_to_lib)
        addpath(path_to_include)

path_to_lib doesn't seem to be used later. I'm working on a Windows machine, and it doesn't seem to have separate directories for the shared library and the include folder. I have confirmed that both the DLL and CoolPropLib.h are in the target folder. I have installed the MinGW add-on for MATLAB through their add-on interface. When I run the code, I get the error "Supported compiler not detected"

Reply all
Reply to author
Forward
0 new messages