Thread: How to write actually good multithreaded code?

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You will get a slowdown. The "number of elements" is decided by the command line parameter.
    It simply divides work on N threads, where N is decided by the number of processors in your system.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Oh, you're right. My bad, I read the output from 'time' wrong XD

    Edit :

    I hope this doesn't sound too brown nosey, Elysia, but looking at your code is kind of a privilege to me. You're really good at C++. Like shoot, you're really good. I'm learning so much by looking at your code, thank you.
    Last edited by MutantJohn; 11-26-2013 at 11:44 AM.

  3. #18
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    - You don't have control over cache (the hardware manages it, period)
    We do have a little bit of control over cache, with prefetching instructions, as well as instructions that instruct the CPU to read from memory, but don't cache it (because you know it will only be needed one time), or only cache it in higher levels (because you know by the time it's needed again, it would have been flushed from L1 anyways even if you cached it there, etc, but still want it cached in L2).

    GCC supports them through __builtin_prefetch, where the programmer would give "hints" on how much locality the data fetched has (will it be needed again later, etc), and GCC decides how to support that on the target.

    Data Prefetch Support - GNU Project - Free Software Foundation (FSF)

  4. #19
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    For X86 processors, it appears that those data prefetch options only apply to SSE / MMX instructions, not general purpose instructions that involve memory accesses.

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by MutantJohn View Post
    I hope this doesn't sound too brown nosey, Elysia, but looking at your code is kind of a privilege to me. You're really good at C++. Like shoot, you're really good. I'm learning so much by looking at your code, thank you.
    You're welcome. Any time.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    For X86 processors, it appears that those data prefetch options only apply to SSE / MMX instructions, not general purpose instructions that involve memory accesses.
    The prefetch instructions are part of SSE / MMX, but the data prefetched can be used by any instruction.

  7. #22
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    Quote Originally Posted by MutantJohn View Post

    I hope this doesn't sound too brown nosey, Elysia, but looking at your code is kind of a privilege to me. You're really good at C++. Like shoot, you're really good. I'm learning so much by looking at your code, thank you.
    You have done quite some damage there. This will be going in his/her signature for a long long time.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  8. #23
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Quote Originally Posted by cyberfish View Post
    The prefetch instructions are part of SSE / MMX, but the data prefetched can be used by any instruction.
    OK, it wasn't clear to me that those settings affected all data accesses. There's still the issue of the translation look aside buffer / cache used to map virtual addresses into physical addresses for fetching data values that are not in one of the data caches.

  9. #24
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Another issue is that a simple search may be memory bandwidth limited, regardless of the cache usage. In this case, sequential or near sequential accesses of RAM will be faster because of the RAS / CAS delay counts, and parallel but different access points into RAM would trigger the longer delay counts.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What are you using to write your code?
    By Sjvlsdsd in forum General Discussions
    Replies: 21
    Last Post: 07-23-2011, 07:20 AM
  2. MultiThreaded GUI.
    By execute in forum Windows Programming
    Replies: 6
    Last Post: 05-18-2006, 01:00 PM
  3. How to write a program as good as possible?
    By jinhao in forum C++ Programming
    Replies: 9
    Last Post: 06-15-2005, 12:59 PM
  4. any good way to write sprite/animation classes for a game?
    By compjinx in forum Game Programming
    Replies: 2
    Last Post: 03-28-2002, 01:22 AM