comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: multicore-multithreading benchmarks
Date: Wed, 27 Dec 2006 13:51:43 -0600
Date: 2006-12-27T13:51:43-06:00	[thread overview]
Message-ID: <wPWdnbypY4NSUw_YnZ2dnUVZ_h-3nZ2d@comcast.com> (raw)
In-Reply-To: 4592aabf$1@news.hcs.net

>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;



      parent reply	other threads:[~2006-12-27 19:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-22  2:48 multicore-multithreading benchmarks tmoran
2006-12-22  6:14 ` tmoran
2006-12-22 17:12   ` Colin Paul Gloster
2006-12-23  6:50     ` tmoran
2006-12-26 21:58       ` Chip Orange
2006-12-27  8:57         ` tmoran
2006-12-27 17:53           ` Chip Orange
2006-12-27 18:46             ` Jeffrey Creem
2006-12-27 19:51             ` tmoran [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox