Parallel Computing Toolbox very Slow After Compilation

1 次查看(过去 30 天)
Hi There Matlab team,
I have a code using parfor (PCT). It runs very efficiently when ran from within matlab (each thread uses 20% of cpu) but very slow when ran after compilation using matlab compiler (each thread uses 1% of cpu)
any ideas what might be the problem
thanks in advance yaniv

回答(1 个)

Prateekshya
Prateekshya 2024-10-9
编辑:Prateekshya 2024-10-9
Hello Yaniv,
The issue you are experiencing with the compiled MATLAB code using parfor (Parallel Computing Toolbox) and MATLAB Compiler might be due to several factors. Here are some potential causes and solutions to consider:
  • Parallel Pool Configuration: When running in MATLAB, the parallel pool is automatically managed. However, in a compiled application, you need to ensure that the parallel pool is correctly configured and started. Check if the compiled application is starting the parallel pool with the desired number of workers. You can explicitly specify the number of workers using parpool.
if isempty(gcp('nocreate'))
parpool('local', numWorkers); % Specify the number of workers
end
  • MATLAB Runtime Environment: Ensure that the MATLAB Runtime (MCR) is correctly installed and configured on the machine where you are running the compiled application. The MCR must match the version used for compilation.
  • Data Transfer Overhead: In a compiled application, there might be additional overhead in data transfer between the client and workers, especially if large data sets are involved. Ensure that data is efficiently partitioned and transferred.
  • Resource Allocation: Check if the compiled application has sufficient system resources (CPU, memory) allocated. The behavior might differ from the MATLAB environment, where resource allocation is typically more straightforward.
  • Code Optimization: Review your code for any operations that might behave differently or less efficiently in a compiled environment. Ensure that the code inside the parfor loop is optimized for parallel execution.
  • Licensing Issues: Verify that the necessary licenses for Parallel Computing Toolbox and MATLAB Compiler are available and correctly configured on the deployment machine.
  • Profiling and Debugging: Use MATLAB’s profiling tools to identify bottlenecks in the compiled code. You can also add logging to understand where the slowdown occurs.
  • Environment Variables: Check if there are any environment variables or system settings that might affect performance, such as thread affinity or power management settings on the deployment machine.
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Parallel Computing Fundamentals 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by