0

Hypothetical Question.

I wrote 1 multithreading code, which used to form 8 threads and process the data on different threads and complete the process. I am also using semaphore in the code. But it is giving me different execution time on different machines. Which is OBVIOUS!!

Execution time for same code:

On Intel(R) Core(TM) i3 CPU Machine: 36 sec

On AMD FX(tm)-8350 Eight-Core Processor Machine : 32 sec

On Intel(R) Core(TM) i5-2400 CPU Machine : 16.5 sec

So, my question is,

Is there any kind of setting/variable/command/switch i am missing which could be enabled in higher machine but not enabled in lower machine, which is making higher machine execution time faster? Or, is it the processor only, because of which the time difference is.

Any kind of help/suggestions/comments will be helpful.

Operating System: Linux (Centos5)

Vishwadeep Singh
  • 1,043
  • 1
  • 13
  • 38
  • And it is obvious that it **BOTHERS** you a lot. – LihO Oct 09 '13 at 10:18
  • yes. kind of. @LihO, actually i had read some where long back about some kind of thread enabling or setting or some thing in operating system. I just want to make sure that i am not missing any thing. – Vishwadeep Singh Oct 09 '13 at 10:20
  • how do you measure the execution time? – MYMNeo Oct 09 '13 at 10:24
  • using gettimeofday sys/time.h @MYMNeo – Vishwadeep Singh Oct 09 '13 at 10:25
  • @Vishwadeep: Just don't take my comment too seriously. It was meant to rather be a joke about the way you emphasized the word "obvious" :) – LihO Oct 09 '13 at 10:28
  • @LihO :)... i had already figured out while i was reading your comment. Even when i was typing my question i too smiled on myself. that is the reason in mentioned on the top.. "Hypothetical Question" :) – Vishwadeep Singh Oct 09 '13 at 10:31
  • I think when you write *"I wrote 1 multithreading code"*, it would be nice if you actually post this code + also the way you were measuring its performance. – LihO Oct 09 '13 at 10:32
  • Quite often, performance issues are created in the _benchmarking method_ rather than the actual code. So without knowing how you got these numbers, there is no way to tell. And of course, the main difference between different computers won't be the CPU, but rather how much crap you have running in the background. Linux is no RTOS. – Lundin Oct 09 '13 at 11:33
  • You can for example create a program which creates 1 single thread, which does nothing but sleep for 30 seconds. Then benchmark that program on the various machines. You should get close to 30 seconds in all 3 cases or the problem is in your benchmarking. – Lundin Oct 09 '13 at 11:34
  • @LihO Actually code is bit long.. but long time back for understanding logic i posted a question related the same scenario... http://stackoverflow.com/questions/18608693/semaphore-vs-condition-variables-in-multithreading – Vishwadeep Singh Oct 10 '13 at 04:07

2 Answers2

1

Multi-threading benchmarks should be performed with significant statistical sampling (ex: around 50 experiments per machines). Furthermore, the "environement" in which the program runs is important too (ex: was firefox running at the same time or not).

Also, depending on resources consumptions, runtimes can vary. In other words, without a more complete portrait of your experimental conditions, it's impossible to answer your question.

Some observations I have made from my personnal experiment:

  • Huge memory consumption can alter the results depending on the swapping settings on the machine.

  • Two "identical" machines with the same OS installed under the same conditions can show different results.

  • When total throughput is small compared to 5 mins, results appear pretty random.

  • etc.

Sebastien
  • 1,439
  • 14
  • 27
0

I used to have a problem about time measure.My problem is the time in multithread is larger than that in single thread. Finally I found the problem is that not to measure the time in each thread and sum them but to measure out of the all thread. For example:

Wrong measure:

int main(void)
{
   //create_thread();
   //join_thread();
   //sum the time
}

void thread(void *)
{
   //measure time in thread
}

Right measure:

int main(void)
{
   //record start time

   //create_thread();
   //join_thread();

   //record end time

   //calculate the diff
}

void thread(void *)
{
   //measure time in thread
}
MYMNeo
  • 818
  • 5
  • 9
  • I got your point. But, at the end there should be a valid reason for the time difference overall. – Vishwadeep Singh Oct 09 '13 at 10:51
  • @Vishwadeep, my time measure used cpu time, so it had problem.There is a question about that, it is http://stackoverflow.com/questions/2962785/c-using-clock-to-measure-time-in-multi-threaded-programs – MYMNeo Oct 10 '13 at 02:35