NAME
Math::Matlab::Pool - Interface to a pool of Matlab processes.
SYNOPSIS
use Math::Matlab::Pool;
$matlab = Math::Matlab::Pool->new(
members => [ $matlab1, $matlab2, $matlab3 ],
sync_file => '/path/to/sync/file'
);
my $code = q/fprintf( 'Hello world!\n' );/
if ( $matlab->execute($code) ) {
print $matlab->fetch_result;
} else {
print $matlab->err_msg;
}
DESCRIPTION
Math::Matlab::Pool implements an interface to a pool of Matlab processes. It consists of a simple list of other Matlab objects (Local, Remote or Pool). Each call to execute() is simply passed on to one of the other objects in the list as determined by the next_index() method.
In this base class, the next_index() method uses a counter in a text file to store the index of the currently selected member of the list. Each time execute is called the value is incremented and the new index is used to determine which member to pass the execute call to. File locking is used to ensure multiple processes running with identical Pool's will distribute execute calls in round robin style to each member of the pool sequentially.
Attributes
- members
-
An arrayref of Math::Matlab objects used for execution.
- sync_file
-
A string containing the name of the file to be used for the counter.
METHODS
Public Class Methods
- new
-
$matlab = Math::Matlab::Pool->new; $matlab = Math::Matlab::Pool->new( { members => [ $matlab1, $matlab2, $matlab3 ], sync_file => '/path/to/sync/file' } )
Constructor: creates an object which can run Matlab programs and return the output. Attributes 'members' and 'sync_file' can be initialized via a hashref argument to new(). Defaults for these values are taken from the package variables $MEMBERS and $SYNC_FILE, respectively. The members arrayref of the initialization hash may contain either Math::Matlab objects, which are put in the list directly, or hashrefs with 'class' and 'args' keys. The value of 'class' must be the name of the Math::Matlab class to use to construct this memmber, and the args should be a hashref of args to pass to the new method.
This allows one to construct a Pool and all of its members with a single call to the Pool's new() method.
E.g. $matlab = Math::Matlab::Pool->new({ sync_file => '/tmp/matlab-pool-sync.txt', members => [ { class => 'Math::Matlab::Remote', uri => 'http://server1.mydomain.com' }, { class => 'Math::Matlab::Remote', uri => 'http://server2.mydomain.com' }, { class => 'Math::Matlab::Remote', uri => 'http://server3.mydomain.com' } ] } )
Public Object Methods
- execute
-
$TorF = $matlab->execute($code, @args)
Takes a string containing Matlab code and optional extra arguments and passes them to the execute method of the Math::Matlab object in the 'members' list, selected by the next_index() method.
- next_index
-
$index = $matlab->next_index
Returns the index of the next member of the 'members' list. This method can be overridden in sub-classes to use alternative rules for selection. In this class it increments a counter in a file and uses the new counter value as the index into the list. The counter wraps around to zero when it reaches the end of the list.
- members
-
$members = $matlab->members $members = $matlab->members($members)
Get or set the members attribute.
- sync_file
-
$sync_file = $matlab->sync_file $sync_file = $matlab->sync_file($sync_file)
Get or set the sync_file attribute.
CHANGE HISTORY
10/16/02 - (RZ) Created.
COPYRIGHT
Copyright (c) 2002 PSERC. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
Ray Zimmerman, <rz10@cornell.edu>
SEE ALSO
perl(1), Math::Matlab