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,cd86d70d109cd9b1 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 27 Dec 2006 13:51:42 -0600 From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: multicore-multithreading benchmarks References: <4592aabf$1@news.hcs.net> X-Newsreader: Tom's custom newsreader Message-ID: Date: Wed, 27 Dec 2006 13:51:43 -0600 NNTP-Posting-Host: 67.164.83.70 X-Trace: sv3-i7Ezvo0R9aHtwx5FyjkO8wA6ugu37AyUJ1zsfVlVbfzW4do0GGm1ssRVwKra/33fjjlOrOmA70RTDAN!sjWe2lhfW5AbesKwYcdr2yeBJBfAS6BDn42nnOOHRu0uKz3R37qN/T7SDcOgegHa7TnAzoKA8GvI!3TC07TfqvX7Zdw== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news2.google.com comp.lang.ada:8028 Date: 2006-12-27T13:51:43-06:00 List-Id: >there's no "standard" way in Ada to handle any of this? Does this seem like >a lack in Ada to you as it does to me, or am I missing some bigger picture? This is clearly very OS dependent. See below for an Ada program that gets the "affinity masks" on Windows. >With multicore/cpus being readily available, wouldn't you think any >programmer should be rewriting his applications to take advantage of this, >and so, would need this type of information to do so? Or should we, as a >general rule, just break all programming tasks into threads, assuming that >the OS will handle load balancing better than we could? Well, on dual-core, one of the cores can run the anti-virus while the other does useful work. ;) Seriously, if the OS knows more than you do about the demands on the machine, it can, potentially, do a better job of allocating resources. If you know more about the requirements than it does, then you should be able to do the better job. Also, most of today's machines are still single CPU, and tomorrow they may have a thousand CPUs, so it's hard to design a program that's optimized for all situations. (Note that Windows' "affinity mask" is limited to a max of 32 CPUs.) Judicious allocation of CPU resources with limited fore-knowledge is part of the program designer's job. Remember also that multi-tasking is not merely a speed-up technique, but is also a design tool. Some programs are more naturally written if you use multiple tasks, even if they run on single CPUs. with Ada.Text_IO, Interfaces.C; procedure Showaff is use type Interfaces.C.Unsigned; type Process_Handles is new Interfaces.C.Unsigned; type Masks is new Interfaces.C.Unsigned; type Bool is new Interfaces.C.Unsigned; package Hex_IO is new Ada.Text_IO.Modular_IO(Masks); function Get_Current_Process return Process_Handles; pragma Import(Stdcall, Get_Current_Process, "GetCurrentProcess"); function Get_Process_Affinity_Mask(Process : Process_Handles; Process_Mask, System_Mask: access Masks) return Bool; pragma Import(Stdcall, Get_Process_Affinity_Mask, "GetProcessAffinityMask"); Me : constant Process_Handles := Get_Current_Process; My_Mask, System_Mask: aliased Masks; begin if Get_Process_Affinity_Mask(Me, My_Mask'access, System_Mask'access) = 0 then Ada.Text_IO.Put_Line("GetProcessAffinityMask failed!"); else Ada.Text_IO.Put("my mask="); Hex_IO.Put(My_Mask, Base => 16); Ada.Text_IO.Put(" system mask="); Hex_IO.Put(System_Mask, Base => 16); Ada.Text_IO.New_Line; end if; end Showaff;