From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,59c52143b2a1463b X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nntp.club.cc.cmu.edu!feeder.erje.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!gegeweb.org!aioe.org!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: How many hardware threads? Date: Mon, 12 Jul 2010 02:38:45 +0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: <4c3a65d7$0$2405$4d3efbfe@news.sover.net> NNTP-Posting-Host: J4HSNf9Eqj44wTz1J3b8lQ.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Tom's custom newsreader Xref: g2news1.google.com comp.lang.ada:12331 Date: 2010-07-12T02:38:45+00:00 List-Id: > I'm about to write a simple program that decomposes into parallel, > compute-bound tasks quite nicely. How many such tasks should I create? I > could ask the user to provide the number as a command line argument or > in a configuration file. Yet it seems like the program should just be > able to figure it out. Does Ada have a standard way of doing that? In MS Windows you can call GetProcessAffinityMask and count the ones in your process's mask. But just knowing how many CPUs there are is just the beginning. Are there other programs running on the machine and should you leave some CPUs for them, or grab them all for your program? What about cache? It tends to be small and if you (or your program plus any others running on the system) actually try to use all the CPUs simultaneously you may thrash. Thread overhead goes up with thread count. The best algorithm may not be the most straightforward. In the early days of virtual memory some people thought "I have a giant memory, which I can access as I wish". They soon found they needed to consider access patterns or their program could thrash horribly. Similarly for multi-core CPUs.