Faster numerical integration for vector functions

10 views (last 30 days)
Dear all,
I have an algorithm that has a for loop which contains double numerical integartion.
Matlab provides integarl2 with its iterated and tiled methods and the ability to reduce the precision of the integration to make it faster. Unfortunately, integarl2 does not support the functionality 'ArrayValued',true. Which means if I have a vector function I need to write the integral2 evaluations inside a for loop to evaluate each vector element alone.
My problem is that I need to run my algorithm for a large-size vector, and I have checked the execution time, and it looks that this will make my algorithm super slow due to the numerical integartion.
My questions are:
  • Does Matlab provide any alternatives to speed up the operation.
  • The computer, that I'm running my simulation on, has two beast GPUs GeForce RTX 2080 Ti. Is there anyway to use their power to evaluate the numerical integration (I'm sure it will be faster) without modifying all my Matlab code.
Please reply. Regards,
  1 Comment
Walter Roberson
Walter Roberson on 28 Jul 2019

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 28 Jul 2019
First, why does integral2 not allow arrayvalued integration? I can only conjecture, but I think this is reasonable - integral2 is an adaptive routine. If your various kernels (all stuffed into one vector) are different enough that the adaptive rule would make different choices for each, then it has a problem. As such they decided not to allow that option.
So where does that leave you?
You can use GPU tools to do the work, which requires the parallel processing toolbox, and NVIDIA GPUs. (They make GeForce, so I assume you are ok there.) Can you do that without modifying any code at all? Probably not, since you will need to invoke those GPUs for this specific operation.
Perhps better, is to use parfor. You need the parallel toolbox anyway to use the GPUs. But integral2 will surely not be using multiple cores effectively, as that is NOT the sort of thing that is easily accelerated automatically. However, a simple parfor loop around the call to integral2 will allow you to use all the cores on your machine, at once.
Other options? Without knowing the nature of your integration kernels, I might wonder if you could break the multiple integration up, doing one of them using a direct Gaussian integration of some sort. Of course, that would significantly change your code, and I cannot even guess if it is an option. But it would speed things up.
  1 Comment
Hussein Ammar
Hussein Ammar on 28 Jul 2019
Thank you all for your help. It seems using the GPU to do the numerical integration will require to modfiy the definition for all my used arrays and functions. My simulation code is very large, so I would leave this option as a last resort.
Regarding parfor, I'm already using it to do the numerical integration for each element in the function vector being integrated. But, my computer can run only 10 parallel workers, so I still need to do many loops to do the integration for all the vector function elements.
But, I have noticed that intregral2 tiled method is much faster than the iterated one. For one numerical integration using 'AbsTol',1e-10,'RelTol',1e-4; it needs 0.809117 seconds of execution time, while the iterated method needs 4.015269 seconds.

Sign in to comment.

More Answers (0)


Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by