TABLE OF CONTENTS


::pwtk::tpool::constructor

SYNOPSIS

    constructor {args} {

USAGE

   set tp [::pwtk::tpool new -h HOSTLIST ?-rdir DIRECTORY? ?-rpwtk FILE?]
 or
   set tp [::pwtk::tpool new -b NUM ?-r?]
 or
   set tp [::pwtk::tpool new -t NUM ?-r?]

DESCRIPTION

A constructor for creating a thread-pool. There are three types of thread-pools, named "bgl, "thread", and "remote".

The "bg" and "thread" type thread-pools are local thread-pools and create workers on the current computer. For example:

      set tp [::pwtk::tpool new -b NUM]

creates NUM ::pwtk::bg workers on the current computer, whereas the "-t" option creates the ::pwtk::thread workers.

The "remote" thread-pool creates ::pwtk::remote workers on the specified remote computers. For example:

      set tp [::pwtk::tpool new -h {machine1 machine2 machine3}]

or

      set tp [::pwtk::tpool new -h {user@machine1 user@machine2 user@machine3}]

creates three workers, one on each specified host. To create several workers on a given computer, specify that computer multiple times in the hosts list. For example:

      set tp [::pwtk::tpool new -h {machine1 machine1 machine2}]

creates two workers on machine1 and one worker on machine2.

OPTIONS

SOURCE

        set options {
            {h.arg {}   "list of hosts where to run jobs"}
            {b.arg {}   "number of ::pwtk::bg workers to run in parallel on localhost"}
            {t.arg {}   "number of ::pwtk::thread workers to run in parallel on localhost"}
            {r          "redirect the stdout of each jobs to a separate log file"}
            {rdir.arg   {}   "directory on the remote host where jobs will be run (default = mirror of the current working directory but on the remote hosts)"}
            {rpwtk.arg  pwtk "full pathname of the PWTK launcher on remote hosts"}
        }        
        set narg 0
        set usage "-h HOSTLIST ?-rdir DIRECTORY?  ?-rpwtk FILE?\nor\n-b NUM ?-r?\nor\n -t NUM ?-r?"
        ::pwtk::parseOpt_
        ::pwtk::checkOType_ -nworkers $opt(b) {number posint} "positive integer"        
        ::pwtk::checkOType_ -nworkers $opt(t) {number posint} "positive integer"        

        set tt 0
        ::pwtk::ifnotempty opt(h) { incr tt }
        ::pwtk::ifnotempty opt(b) { incr tt }
        ::pwtk::ifnotempty opt(t) { incr tt }
        if { $tt > 1 } {
            ::pwtk::error "mutually exclusive -h, -b, or -t options specified" 1
        } elseif { $tt == 0 } {
            ::pwtk::error "none of -h, -b, or -t options specified; exectly one of these options must be specified" 1
        }
        
        set opts {}
        foreach o {rdir rpwtk} {
            if { $opt($o) ne {} } { lappend opts -$o $opt($o) }
        }
        if { $opt(r) } {
            lappend opts -r
        } 
        
        ::pwtk::print TPOOL "Initializing a new thread-pool ...\n"
        ::pwtk::thread_init
        
        set hostText {}
        if { $opt(h) ne {} } {
            #
            # remote
            #
            set type remote
            set hosts $opt(h)
            set nworkers [llength $opt(h)]
            set hostText "\nworker hosts      :  [join $hosts { }]"
            
            # check that each host is alive
            foreach host $hosts {
                if { ! [pwtk::host_is_up $host] } {
                    ::pwtk::error "cannot communicate with '$host'\n\n$::errorInfo" 1
                }
            }
        } elseif { $opt(b) ne {} } {
            #
            # bg
            #
            set type bg
            set nworkers $opt(b)
        } else {
            #
            # thread
            #
            set type thread
            set nworkers $opt(t)
        }

        # create thread-pool

        #set tpid [tpool::create -minworkers $nworkers -maxworkers $nworkers -initcmd $::pwtk::thread(initcmd)]
        set tpid [tpool::create \
                      -minworkers $nworkers \
                      -maxworkers $nworkers \
                      -initcmd [::pwtk::thread_initscript_]]
        set count 0
        set jobList {}

        ::pwtk::print "thread-pool type  :  $type
number of workers :  ${nworkers}$hostText
thread-pool ID    :  $tpid\n"
    }