Multiprocessing V.S. Multithreading V.S. ??

Hi Everyone,

I’m basically coding some function that I’d like to be called simultaneously by three different objects. I’m currently working on my quad core processor. MY concern is that how do I call this function simultaneously on every processor.

I’ll explain what I mean by this. Suppose I have a class "A" and I have three objects that are instances of class A. Let’s call them "A1", "A2" and "A3". Now suppose that the method called Val in class A returns a double.

So, what I’m basically trying to do is store the value

double maxA = max(A1.Val, A2.Val, A3.Val);

My concern is that each call to function Val in Class A takes some time to do its computations. Calling it on three objects can take more time than desired. (Not to forget that call to max itself will take time as well). I’m wondering if I can make use of the quad core to do simultaneous processing for each object. Can someone please give me a direction of how should I go about coding this? I’d like to shave down as much as I can because once I get a large array of Class A objects computation times can significantly increase.
I don’t know much about multithreading or multiprocessing yet, but I’m willing to take the next step to learn. I just don’t know which direction to choose for this. I was recommended to consider using MPI threads but I’m not sure even if it that’s the best bet... not to mention that I don’t know anything about mpi in C++. I wonder how complicated that gets.

Thanks in advance for your comments.

General purpose OS' won't let you run code on particular processors. The OS scheduler decides what to run where and when.

If you just want to execute some function concurrently and then process some result, threads may be your thing, if the OS supports it.

I've previously posted an example here.
http://www.cplusplus.com/forum/beginner/20372/#msg106339
Topic archived. No new replies allowed.