Faster numerical integration for vector functions
16 views (last 30 days)
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,
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.