Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

comparing execution time ( multithreaded vs serial )

Hi All,
I wrote a program in C for this and I saw that multithreaded program was taking more time than its serial counterpart on some machine.

1. On an AIX machine specially designed for threads the threaded program shows less execution time but on linux 3.0 machine the serial program takes lesser time that should not.
2. A multithreaded program takes more time than a serial counterpart but if we increase the amount of computation than also it gives justifiable results.
3. For some I/O operations like opening and closing of a file and doing some R/W on it the time increases but again on a machine linux 4.0 with 4 processors which has the maximum thread spawn limit as 16384 it gives opposite results ie multithreaded program is taking more time than serial.

Please justify it and solve my problem.

Comments

  • JonathanJonathan Member Posts: 2,914
    : I wrote a program in C for this and I saw that multithreaded program
    : was taking more time than its serial counterpart on some machine.
    :
    It's be interesting to know about the hardware that you're using for these tests, since that makes a difference. Note that if you only have one single-core CPU and are testing intensive computation then you're not going to get any win - you'll likely just do worse. Unless there's hyperthreading, but that's a minimal win if there's little I/O and you have good locality of reference.

    : 1. On an AIX machine specially designed for threads the threaded
    : program shows less execution time but on linux 3.0 machine the serial
    : program takes lesser time that should not.
    There's a Linux 3.0?! But if this is some early version of Linux then it may be doing user space threading, not kernel threading, which means you lose some of the benefits of threading and don't get such good performance. See if you're using pthreads - that's user space threading. It's hard to know without more details for sure though.

    : 2. A multithreaded program takes more time than a serial counterpart
    : but if we increase the amount of computation than also it gives
    : justifiable results.
    This one I can answer more confidently than the other two. Thread creation/destruction isn't free. Switching between running threads isn't free either. This overhead is probably mitigating the benefit you get from concurrent execution.

    : 3. For some I/O operations like opening and closing of a file and doing some R/W on it the time increases but again on a machine linux 4.0 with 4 processors which has the maximum thread spawn limit as 16384 it gives opposite results ie multithreaded program is taking more time than serial.
    :
    Again, not sure what you mean by Linux 4.0. But this is possibly thread creation and switching overhead biting you again. You don't mention how many threads you are creating...

    : Please justify it and solve my problem.
    :
    Hopefully this helps a bit. But the issues like this tend to revolve around the differences between kernel and user space threading, overhead for creation/switching/destruction of threads and, often the big one, locking. Using threads well can be tricky.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • sandeept_24sandeept_24 Member Posts: 8
    Hi Jonathan Thanks for your reply,now I would like to clear some issues.

    Firstly by Linux 3.0 and 4.0 I meant to say RedHat Enterprise Linux Version 3.0 single core Pentium 4 and EL 4.0 on a 4 processor Intel Itanium Multiprocessor environment (hyperthreading) respectivelly.

    You are absolutely correct that on a single core machine I am not able to get the benifit. The AIX I mentioned which gives good results is a dual core machine.

    Moreover again you are correct that i am using pthreads ie user space threading.

    I created only three threads just to test. And probably File I/O can not be a reliable means to test because of various File system issues like locking.

    Probably the situation is more clearer to you now. Bye

    Sandeep

    : : I wrote a program in C for this and I saw that multithreaded program
    : : was taking more time than its serial counterpart on some machine.
    : :
    : It's be interesting to know about the hardware that you're using for these tests, since that makes a difference. Note that if you only have one single-core CPU and are testing intensive computation then you're not going to get any win - you'll likely just do worse. Unless there's hyperthreading, but that's a minimal win if there's little I/O and you have good locality of reference.
    :
    : : 1. On an AIX machine specially designed for threads the threaded
    : : program shows less execution time but on linux 3.0 machine the serial
    : : program takes lesser time that should not.
    : There's a Linux 3.0?! But if this is some early version of Linux then it may be doing user space threading, not kernel threading, which means you lose some of the benefits of threading and don't get such good performance. See if you're using pthreads - that's user space threading. It's hard to know without more details for sure though.
    :
    : : 2. A multithreaded program takes more time than a serial counterpart
    : : but if we increase the amount of computation than also it gives
    : : justifiable results.
    : This one I can answer more confidently than the other two. Thread creation/destruction isn't free. Switching between running threads isn't free either. This overhead is probably mitigating the benefit you get from concurrent execution.
    :
    : : 3. For some I/O operations like opening and closing of a file and doing some R/W on it the time increases but again on a machine linux 4.0 with 4 processors which has the maximum thread spawn limit as 16384 it gives opposite results ie multithreaded program is taking more time than serial.
    : :
    : Again, not sure what you mean by Linux 4.0. But this is possibly thread creation and switching overhead biting you again. You don't mention how many threads you are creating...
    :
    : : Please justify it and solve my problem.
    : :
    : Hopefully this helps a bit. But the issues like this tend to revolve around the differences between kernel and user space threading, overhead for creation/switching/destruction of threads and, often the big one, locking. Using threads well can be tricky.
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

Sign In or Register to comment.