Numerical Integration in Python

  • Python
  • Thread starter EngWiPy
  • Start date
  • #51
33,094
4,796
I need to evaluate say G(1,1,0), G(2,1,0) .... G(10,1,0). These function are independent of each others. But in for loop these will look something like

Code:
for(int i=1; i <= 10; i++){
cout  <<  G(i, 1,0);
}
which are evaluated sequentially. These can be evaluated in parallel. But how? I am not familiar with multithreading, but I think we can get Kx speed up, where K is the number of cores.
My computer, which I've had for five years, has an Intel Quad Core Duo processor, with each of the four cores having effectively two processors. This means that eight threads can be running. You're not going to have K cores, with K being an arbitrary integer. Your program also can't be using all the cores, as some of them will be used by the OS and other processes.

If I were going to write the code, I wouldn't have it iterate 10 times. Instead, I would iterate 4, or 8, or some power of 2, times, and I wouldn't use a loop. If I had four threads to play with, I would create four thread objects to evaluate G(1, 1.0), G(2, 1.0), G(3, 1.0), and G(4, 1.0). When the last one of these is finished, I would use the threads to evaluate G with a first argument of 5, 6, 7, and 8.

Also, I wouldn't output them in the loop. Instead, I would store the return values from G() in an array, and print them out when the array is full.

I can't say too much more about threads and such, since there's quite a bit more than I have explained. Threads are pretty low level. At a higher level of abstraction are async objects, which are easier to work with.
 

Related Threads for: Numerical Integration in Python

Replies
4
Views
2K
  • Last Post
Replies
3
Views
490
Replies
21
Views
964
  • Last Post
Replies
8
Views
3K
Replies
6
Views
2K
Replies
6
Views
6K
  • Last Post
Replies
6
Views
887
Replies
5
Views
658
Top