MoorDyn Parallel computing (Matlab)

Dear all,

I am currently building a model of the NREL 5 MW offshore wind turbine on Matlab.
To reduce my long computational times I am trying to implement parallel computing.
However, MoorDyn does not seem to work.

My code runs perfectly when using standard “for” loops but when I change these to “Parfor” loops (parallel computing) the console window for MoorDyn appears empty and MoorDyn does not initialize, however, it does not report a failure to initialize.
Any help regarding this would be very much appreciated.
I will attach a similar loop below which represents the issue:

parfor i = 1:3
if libisloaded(‘MoorDyn’)
calllib(‘MoorDyn’,‘LinesClose’);
unloadlibrary MoorDyn;
end

 [notfound,warnings] = loadlibrary('MoorDyn','MoorDyn');     % load MoorDyn DLL
 mooring_status = calllib('MoorDyn','LinesInit',zeros(6,1),zeros(6,1));   % initialize MoorDyn 
 if mooring_status ~= 0
     error('MoorDyn unable to load');
 else
     disp('MoorDyn loaded successfully');
 end
 calllib('MoorDyn','LinesClose');
 unloadlibrary MoorDyn;

end

Hi James,
I haven’t used Matlab in a long time and am not familiar with its parallel computing abilities, but you’re probably experiencing a fundamental limitation of the version of MoorDyn that you’re using. It looks like you’re using a relatively recent version of the C++ one, though I can’t guess exactly how recent from the information you provided. MoorDyn in C++ was previously set up assuming it would only be called once. In the last handful of months, an external developer made some changes that I believe would make it more robust for parallel use. However, that hasn’t been confirmed yet to my knowledge. Also, it’s hard to tell exactly how Matlab handles DLLs and there’s a chance that the issue is actually related to Matlab’s memory handling when working with DLLs in this parallel way. (I’m just guessing - if you have knowledge/experience about that please let me know.)

All this being said, if you are modeling the coupled dynamics of a floating wind turbine in Matlab, I would be very surprised if MoorDyn was your computation time bottleneck. I would bet that running a single instance of MoorDyn would be a much smaller computation expense than most other parts of the code.

Let me know if you’re still working on this and have follow-up questions or observations. I’m hoping that we will be able to make some long-awaited fixes to the C++ version of MoorDyn in the months ahead.

Matt

Hi Matt,

Thanks very much for your response,

You are right that MoorDyn was not the part of the code causing the bottleneck, however MoorDyn was required to be run in parallel to allow the other parts of the code to also run in parallel.

I was using the 2017 version of MoorDyn and have since updated it to the 2021 version.
It seems to have resolved the issue with MoorDyn however there are more issues arising from Dot indexing which has nothing to do with MoorDyn so I’m not sure if it is 100% working.

Thanks very much for your help and I will let you know if I get any further with this.

Kind Regards
James

Dear James,

I got an error when calling MoorDyn,When I use this command “loadlibrary(‘MoorDyn’,‘MoorDyn’)”, it will prompt that the file MoorDyn cannot be found, maybe because I need to get the file MoorDyn.dll first?

Best regards,
Monge.

Dear James,

I have some problems when calling MoorDyn in simulink…When I use the command “loadlibrary(‘MoorDyn’, ‘MoorDyn’)”, it will prompt “The file MoorDyn cannot be found”, and when I use the command “calllib(‘MoorDyn’, ‘LinesClose’)”, it will Prompt “library not found”, I do not know what causes this, I hope you can give me some hints.

Sincere thanks in advance!

Best regards,
Monge.

Hi Monge,

Apologies for my delayed response, potentially Matt might be best equipped to answer your question.

Have you ensured that the required MoorDyn files (.dll and H file) are stored in the same path/folder that your code is stored in?

Kind Regards
James

Dear James,

It’s okay, it’s a pleasure to hear from you.The MoorDyn files (.dll and .h) are stored in the same path. When I change this command to “loadlibrary(‘MoorDyn.dll’, ‘MoorDyn.h’)”, matlab will not prompt this error.
In fact, I am trying to use simpack and simulink for joint simulation, and call MoorDyn in simulink to build a mooring system, but I have encountered many errors, which troubled me very much.

Best regards,
Monge.

Hi Monge,

That’s great the error is not occurring in Matlab, unfortunately, I have no experience in working with MoorDyn in Simulink so I can’t offer any advice on this.

Hopefully someone else here may have a solution for this!

Best of luck
James

Dear James,

Thank you very much.

Best regards,
Monge.