I am trying to use mutlithreaded database updates in Simulink using the update function inside parfor My code is something like this:
parfor i = 1:numLoad
updateQuery = strcat("{""$set"":", jsonencode(document(i)), "}");
findQuery = strcat("{""name"": """, document(i).name, """}");
temp_conn = dbConnections{i};
update(temp_conn, "collection", findQuery, updateQuery);
end
where dBConnections is initialised like this:
for i = 1:5
dbConnections{i} = mongoc("localhost",27017,"database");
end
However, this crashes.
It will not crash if I either (1) change parfor to for, or (2) remove the update function.
Is the mongoc connection just not usable in parfor?
The error messages are:
Warning: A worker aborted during execution of the parfor loop. The parfor loop will now run again on the remaining workers. > In distcomp/remoteparfor/handleIntervalErrorResult (line 246) In distcomp/remoteparfor/getCompleteIntervals (line 396) In parallel_function>distributed_execution (line 746) In parallel_function (line 578) In my_model>Outputs (line 118)
An error occurred while running the simulation and the simulation was terminated
Caused by:
- Error evaluating registered method 'Outputs' of MATLAB S-Function 'my_model' in 'my_model/Level-2 S-Function For MongoDB'. The following is the MATLAB call stack (file names and line numbers) that produced this error: ['C:\Program Files\MATLAB\R2022b\toolbox\parallel\distcomp\+distcomp\remoteparfor.m'] [195] ['C:\Program Files\MATLAB\R2022b\toolbox\parallel\distcomp\+distcomp\remoteparfor.m'] [259] ['C:\Program Files\MATLAB\R2022b\toolbox\parallel\distcomp\+distcomp\remoteparfor.m'] [396] ['C:\Users\me\MATLAB\Projects\learning_simulink\work\my_model.m'] [118]
- All workers aborted during execution of the parfor loop
Any ideas for what the issue is?