- To avoid repeated transfers, you can make the matrix a “global” variable; however, this must be used sparingly and specific to the application. Refer to the documentation of “global” : https://www.mathworks.com/help/matlab/ref/global.html
- You can also use “persistent” storage to preserve a variable inside a function between repeated function calls. To use “persistent” efficiently, refer to the documentation of “persistent”: https://www.mathworks.com/help/matlab/ref/persistent.html
- To store matrix efficiently, you must ensure the correct datatype to use which can save space since storing a double is costlier compared to “int32” data type, if entries are single precision, then use “int32” or “single” instead of “double”.
- You must use optimized function like “A*a” for efficient matrix vector multiplication to boost up speed as the internal implementations are highly optimized for performance.
How to reduce the overall cost(Storage as well as communication) of transfer a dense matrix in nested functions
2 ビュー (過去 30 日間)
古いコメントを表示
Suppose I have a dense matrix in the very first stage of my code and I need to tranfer that matrix into the function again and again and just need a matrix vector multiplication inside the function as shown below
clc
Matrix A= 100000×100000 (dense)
Program starts
{
Function1
{
Function2
{
Here I need Matrix multiplication with some vector (M.a = b)....... [a,b = vectors]
}
}
}
How can I tranfer this matrix efficiently in the code and get matrix-vector multiplication and How can I store it efficiently?
0 件のコメント
回答 (1 件)
Arjun
2024 年 10 月 10 日
I understand that you want to efficiently store and transfer dense matrices in your programs.
Here are some suggestions which might help you:
You can try implementing the above suggestions to the problem.
I hope this will help!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with Optimization Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!