Hello,

I just started using parallel programming and I have a couple of questions.

1.Can some one give me an example in c++ of thread executing congruently and threads executing in parallel. When I say congruent and parallel I mean the following:

Concurrency is essentially when two tasks are being performed at the same time. This might mean that one is 'paused' for a short duration, while the other is being worked on

Parallelism requires that at least two processes/tasks are actively being performed at a particular moment in time.

If I use join() (#include <thread>) is it parallel or concurrent.

2. If I have 4 cores how can I calculate the optimal number of threads that I have to create so that I have the best performance? Performance is really important in my case.

3. I'm using Visual Studio Community 2015 on Windows 4 core machine and I noticed something weird when I put a break point before the a start joining the threads and I go through the rest of the code it takes a lot less time that If I put a break point after the last join and I go through the rest of the code. WHY ?

Code:
void task(int i){
//do something
}

int main{
   //do smt
   std::thread t1(task(1));
   // and so on I create 15 threads
   
   t1.join();
   // and so on 
   
   // do something else 
}
5. And my last question if I have a for loop that take 16 seconds and each iteration is independent and I want to do it in parallel. I have 4 cores. What is the best time I can get after parallelising, 4 seconds + a couple of ms for creating the threads ???