按照标题,我正在寻找方法,所以我可以使用线程或其他可以加速我的八度计算。
谁有任何想法,功能或包装?请帮我。 和我在使用Windows 7。
答案 0 :(得分:0)
Octave通过多线程库支持Linux上的多线程。请参阅Get GNU Octave to work with a multicore processor. (Multithreading) Atlas通过Cyqwin支持Windows http://math-atlas.sourceforge.net/faq.html#where我在Gentoo Linux上使用了这些库,并在运行单个进程时提高了速度。库自动在多个处理器之间划分一些操作。当然,这不是最佳解决方案,因为它在处理非常大的矩阵时才有效。它也可能很难在Windows上运行。我知道我在Linux上遇到了一些问题。调整库时,不要使用多个作业进行编译(请参阅编译器文档)。每次尝试都失败了。
更好的解决方案是,如果您可以将问题划分为彼此独立的较小问题,那么它们的执行顺序无关紧要。我编写了一个小的Perl脚本来解决对Octave的多次调用,因为Octave没有创建线程的本地方法。由于您使用的是Windows,除非您使用Cyqwin,否则需要进行一些调整。
#!/usr/bin/perl -wT
$ENV{PATH} = "/bin:/usr/bin:/usr/local/bin";
use strict;
use POSIX qw(setsid :sys_wait_h);
use Time::Piece;
use Time::Local;
#------------------- GLOBALS -----------------------
my $go_me = 0;
my $kid = 0;
my $kid_pid = 0;
my $num_children = 0;
#------------- SUBROUTINES ----------------------
sub Interrupt
{ $go_me = 0; }
sub Interrupt_Die
{
$go_me = 0;
print localtime . " > $$ - Dieing: @_ $!\n";
exit(0);
}
sub Child_Is_Done
{ $num_children++; }
#------------------ PROCESS OVERHEAD -------------------------
if($#ARGV != 1)
{
print "Usage: octbatch /path/filename [concurrency number]\n";
exit(0);
}
my $stdout_file = "";
if($ENV{HOME} =~ m/^(\/home\/\w+)$/)
{
$stdout_file = "$1" . '/octbatch.log';
}
else
{
print "Invalid value for $ENV{HOME}\nDon't run as root.\n";
exit(0);
}
open STDIN,'/dev/null' or die "Can't read /dev/null: $!";
open STDOUT,'>',$stdout_file or die "Can't write to $stdout_file: $!";
open(STDERR, ">&STDOUT") or die "Can't write to $stdout_file: $!";
defined(my $pid = fork) or die "Can't fork: $!";
exit if $pid;
setsid or die "Can't start a new session: $!";
my $parent = "$$";
print "Parent process is: $parent\n";
$go_me = 1;
print localtime . " > $$ - Starting.\n";
#----------------------- MAIN CYCLE ---------------------------------
my $filename = $ARGV[0];
unless(open(COMMANDFILE, "<$filename"))
{ die "Could not open $filename $!\n"; }
$num_children = $ARGV[1];
$SIG{'CHLD'} = 'Child_Is_Done';
while($go_me and my $line = <COMMANDFILE>)
{
if($num_children <= 0 and $kid_pid)
{
my $child_pid = -1;
$child_pid = wait();
if(WIFEXITED($?))
{ print localtime . " > $$ - Process $child_pid exited\n"; }
}
chomp($line);
print localtime . " > $$ - Running $line\n";
$num_children--;
Interrupt_Die("Can't fork!") unless defined($kid_pid = fork());
if($kid_pid)
{
print localtime . " > $$ - I am the parent.\n";
$SIG{'CHLD'} = 'Child_Is_Done';
}
else
{
print localtime . " > $$ - I am the child.\n";
$go_me = 0;
$kid = 1;
print localtime . " > $$ - Running $line\n";
if($line =~ m/^(octave ([^;\n\r]+))$/)
{
$line = "$1";
system("$line");
}
else
{
print localtime . " > $$ - Invalid line. Skipping.\n";
}
}
}
if($kid)
{
print localtime . " > $$ - Process $$ exited\n";
exit(0);
}
else
{
my $child_pid = -1;
do
{
$child_pid = waitpid(-1,0);
if(WIFEXITED($?))
{ print localtime . " > $$ - Process $child_pid exited\n"; }
} while($child_pid > 0);
print localtime . " > $$ - Stopping: $!\n";
exit(0);
}
答案 1 :(得分:0)