How to speed up my code?

4 ビュー (過去 30 日間)
Canberk Suat Gurel
Canberk Suat Gurel 2018 年 3 月 5 日
回答済み: vijaya lakshmi 2018 年 3 月 21 日
Hi all,
I have written a BFS (path planning) algorithm and although it works perfectly fine with small grids (e.g. 20x20) when the grid gets larger (e.g. 150x250) due to the matrix representation I have used, the size of the adjacency matrix* becomes enormous (37901x37901) which as expected takes forever (over 10 hours) to find the path from initial node to goal node. I am using MATLAB 2016a and it is running on Nvidia GeForce 840M.
Question 1: Could it be quicker if I run it on my Intel Processor (Intel Core i7-4510U CPU@ 2.00GHz, 2601MHz, 2 Cores, 4 Logical Processors)?
Question 2: As C++ is a more efficient language, if I generate a C++ from my MATLAB code using MATLAB Coder, whould it speed up the process? If yes, by how much (approximately)?
*Adjacency matrix is the matrix that stores the connection information between nodes.
Thanks!

採用された回答

vijaya lakshmi
vijaya lakshmi 2018 年 3 月 21 日
Hi Canberk,
The following provides information on tools within MATLAB that can help you optimize the performance of your code.
1.The first step is to analyze the performance of your MATLAB code in its current state. Click here to view the documentation regarding this topic
In particular, the MATLAB Profiler measures where a program spends time and generates a summary. By using the Profiler, you can determine which commands and which lines of code are taking the longest to execute, and therefore determine where you can focus most of your optimization efforts. To read about how to use the MATLAB Profiler to improve performance, please see the following link
2. There is a section in the documentation that discusses best practices for writing highly efficient code, including when and how to vectorize, how to preallocate memory for arrays, http://www.mathworks.com/help/matlab/matlab_prog/techniques-for-improving-performance.html
3.Multithreading comes default enabled in the most recent version of MATLAB. Common mathematical operations are programmed to make use of multithreading.
To find out if the Parallel Computing Toolbox can help make best use of a multiple core desktop or a computing cluster, navigate to the following link
Hope this information helps you to speed up your code.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeExecution Speed についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by