Community
cancel
Showing results for 
Search instead for 
Did you mean: 
balteo
Beginner
101 Views

Monte carlo simulation

Jump to solution
Hello,

I am new to TBB and I am trying to build a monte carlo program that will run N simulations independent of each other and use the results of that N simulations in order to carry on working.

I am not sure whether to use parallel_for, parallel_reduce or parallel_do or some other function. Can anyone please advise?

Thanks in advance,

Julien Martin.


0 Kudos
1 Solution
robert-reed
Valued Contributor II
101 Views

Well, learning C++ by writing a parallel program will certainly give you a challenge. Threading Building Blocks uses C++ very deeply.

Can you describe the inputs for your N simulations in the form of an indexed array? You might start looking at the TBB parallel for to divide that list of simulations among the available threads, letting each take on as much work as they can accomplish. Since the simulations are completely independent of each other, there should be no interference between the threads. If some of the simulations take longer than others, the natural load balancing provided by task stealing within TBB should allow the workers to help each other finish the set.

You might try focusing on these ideas and let them guide your reading of the documentation.

View solution in original post

6 Replies
smasherprog
Beginner
101 Views
balteo
Beginner
101 Views
Thank you smasherprog,
I already had a look at the documentation. What I need to start with is basic guidance as to what to look for in the documentation bearing in mind the need I have.
I am completely new to TBB and rather novice in C++...
Thanks,
J.
robert-reed
Valued Contributor II
102 Views

Well, learning C++ by writing a parallel program will certainly give you a challenge. Threading Building Blocks uses C++ very deeply.

Can you describe the inputs for your N simulations in the form of an indexed array? You might start looking at the TBB parallel for to divide that list of simulations among the available threads, letting each take on as much work as they can accomplish. Since the simulations are completely independent of each other, there should be no interference between the threads. If some of the simulations take longer than others, the natural load balancing provided by task stealing within TBB should allow the workers to help each other finish the set.

You might try focusing on these ideas and let them guide your reading of the documentation.

View solution in original post

balteo
Beginner
101 Views
Thanks Robert,
This API/library looks new and exciting to me.
Can anyone please tell me what these mean in c++ (see //HERE and //HERE below).
I cannot seem to be able to figure out what the ":my_a(a){}" mean and it gives me a compilation error...
Any help?
Julien.

#include "tbb/tbb.h"
using namespace tbb;
class ApplyFoo {
float *const my_a;
public:
void operator()( const blocked_range& r ) const {
float *a = my_a;
for( size_t i=r.begin(); i!=r.end(); ++i )
Foo(a);
}
ApplyFoo( float a[] ) : //HERE
my_a(a) //HERE
{}
};


robert-reed
Valued Contributor II
101 Views
Your "//HERE" markers coincide witha C++ class constructor that uses an initializer (the ": my_a(a)" initializes the class variable my_a from the constructor parameter a). I didn't look at it closely enough to determine what error you might have encountered. Time to go back to your C++ training materials.
balteo
Beginner
101 Views
Thanks a lot.
J.
Reply