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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,41967527237c1aa2 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.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: Thu, 29 Mar 2007 23:03:32 -0500 From: "Steve" Newsgroups: comp.lang.ada References: <1175097196.113031.259000@r56g2000hsd.googlegroups.com> <1175100948.580216.145940@r56g2000hsd.googlegroups.com> <1175104396.231171.125360@e65g2000hsc.googlegroups.com> <1175181454.290582.90280@b75g2000hsg.googlegroups.com> Subject: Re: Fun with Tasking Date: Thu, 29 Mar 2007 21:06:01 -0700 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-RFC2646: Format=Flowed; Original Message-ID: NNTP-Posting-Host: 24.20.111.245 X-Trace: sv3-0KB6t5PQDta8O180wOO12NH4s0flXRVFA/4kkgFdBxWWBwRZ7xdYyesJUeTCc82bi0QRSs9Th5J4nR7!6UxKYMZUEpA5NHKh9roLKoM102UNJkDKiht4j6U6ZGPseaIdgSRs+xYeGjjOvZGktyzKJaBMIyhz!vtguCSAhWe9v9FF8eeDSfrHNc7n3VA== 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.34 Xref: g2news1.google.com comp.lang.ada:14669 Date: 2007-03-29T21:06:01-07:00 List-Id: wrote in message news:1175181454.290582.90280@b75g2000hsg.googlegroups.com... [snip] > > Great help and advice all around, thanks much c.l.a! > > Anyhoo Jeff, I'll try to explain in more detail what my program is > doing and hopefully you can see where I'm going wrong. The program > has a number of packages, each handling what I call a subsystem, to be > verbose: ephemeris, residual, vector, covariance and a few others > (this sort of equates to the "exec" procedure in my sample). Each of > these systems has a number of procedures of interest, like a > differencing of quantities, a statistical analysis, etc. Now each of > these procedures of each of these subsystems can have up to 60 (and > more as we go on) objects - each one I handle as it's own task. I've > found that throwing 60 threads at the OS (W2K in this case) is, while > better then serially and single-threaded on multi-cpu's, not terribly > efficient. For this application, I've found most procedures operate > best if N+1 threads are running, N being the processors available. > The output is all .csv files. For awhile, to show an ensemble of > data, I would do a lot of cut and pasting between .csv's, one day, I > thought, why not have the program do this? So I implemented these > "collating" tasks that all 60 or so threads would send some > information to for some sort of unified processing. Each procedure of > each subsystem/package is slightly different either in the data types > being handled or the manner in which the data is processed so a > "generic" collating task isn't really feasible. > You are still rather heavily interlacing your implementation with what you are looking for, but I think I have at least a partial understanding. Here are some suggestions: Don't use function pointers. Don't use System.Address In the context of your problem description, these are tools that a C programmer uses when writing a C program in Ada. Create an abstract base class (tagged type), and subclass for the specific functionality of the subsystems. Note: Some Ada programmers may get their knickers in a bind by my use of terms like "class" and "method" since these are not Ada keywords and they are keywords in other programming languages, I am not describing syntax, but structure. For example a package defining a base class might be something like: ------------------------------ package Data_Processing is type Data_Processing_Type is abstract tagged null record; type Data_Processing_Acc is access all Data_Processing_Type'class; procedure Process_Data( Data_Set : Data_Processing_Type ) is abstract; end Data_Processing; -------------------------------- Derive a specfic processing type for one of the types of processing that needs to be done, hiding any data to be processed in the private part of the package spec: with Data_Processing; use Data_Processing; package Ephemeris_Processing is type Ephemeris_Processing_Type is new Data_Processing_Type with private; procedure Process_Data( Data_Set : Ephemeris_Processing_Type ); function Create_Ephemeris_Processor( data_value : Natural ) return Data_Processing_Acc; private type Ephemeris_Processing_Type is new Data_Processing_Type with record data_value : Natural; end record; type Ephemeris_Processing_Acc is access all Ephemeris_Processing_Type; end Ephemeris_Processing; -------------------------------- with Ada.Text_IO; with Ada.Integer_Text_IO; package body Ephemeris_Processing is procedure Process_Data( Data_Set : Ephemeris_Processing_Type ) is begin Ada.Text_IO.Put( "Value is:" ); Ada.Integer_Text_IO.Put( Data_Set.data_value ); Ada.Text_IO.New_Line; end Process_Data; function Create_Ephemeris_Processor( data_value : Natural ) return Data_Processing_Acc is ret : Ephemeris_Processing_Acc; begin ret := new Ephemeris_Processing_Type; ret.data_value := data_value; return Data_Processing_Acc(ret); end Create_Ephemeris_Processor; end Ephemeris_Processing; -------------------------------- And then use dynamic dispatching to invoke the processing of the data for the specific processing to be done. with Data_Processing; use Data_Processing; with Ephemeris_Processing; use Ephemeris_Processing; procedure Dispatch_Demo is work : Data_Processing_Acc; begin work := Create_Ephemeris_Processor( 42 ); Process_Data( work.ALL ); end Dispatch_Demo; -------------------------------- You can compile and test the snippets of code above to see the dispatching work. This doesn't really describe how to handle the tasking, but a better way to break down the problem. Derive different classes from Data_Processing_Type for each of the different types of processing you need. Information about each of the derived classes is encapsulated in a separate package for each type of processing. You can then create list of processing to be done and send elements of the list to a task. The task receives an access to a data processing type and calls the Process_Data function. One possible implementation is to put the list of operations to be done in a protected object. Create as many threads as you want and have each thread get a data processing object from the list, process the data, and then go back for more work to do. This approach scales well. I hope this helps, Steve (The Duck)