mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2010-08-24, 15:08   #1
Andi47
 
Andi47's Avatar
 
Oct 2004
Austria

9B216 Posts
Default pearl question: multiple threads of ECM

I am attempting to code a pearl script which launches multiple threads of ECM.exe: (configured to use 7 threads of my i7 here, as the 8th thread is busy with an msieve poly select)

Code:
use Math::BigInt;
use Math::BigFloat;

$NUM_CPUS=7;
$NUM_THREADS=$NUM_CPUS;

$ECHO_CMDLINE=1;

### ECM parameters ###

$B1=43000000;
$NUM_CURVES=777; #total number of curves 
$MAXMEM=900; #max. memory used per thread

$INPUTFILE="alq10212.2315.txt";
$ECM_OUTPUTNAME="alq10212.2315_43e6.out";


############# nothing configurable below here! #######################

$CNUM=int($NUM_CURVES)/$NUM_THREADS; #note: this will cause rounding errors if $NUM_CURVES is not divisible by $NUM_THREADS

if ($NUM_THREADS != 1) {
  use Config; 
  if (!($Config{usethreads})) { 
    printf "This version of Perl doesn't support multiple threads.  Only using 1 thread.";
    $NUM_THREADS=1; 
  }
  else {
    use Thread qw(async);
  }
}

# statements below copied from factmsieve.pl and modified for running ecm

  if ($NUM_THREADS==1) {
    # It's very important to call like this, so that if the user CTRL-C's,
    # or otherwise kills the process, we see it and terminate as well.
    unlink($ECM_OUTPUTNAME);
    $cmd="ecm -nn -maxmem $MAXMEM -c $CNUM <$INPUTFILE $B1 >>$ECM_OUTPUTNAME";
    print "=>$cmd\n" if($ECHO_CMDLINE);
    $res=system($cmd);
  }
  else {
    @thd = (1 .. $NUM_THREADS);
    for ($j=1;$j<=$NUM_THREADS;$j++) {
      unlink("$ECM_OUTPUTNAME.T$j");
      $cmd="ECM -nn -maxmem $MAXMEM -c $CNUM <$INPUTFILE $B1 >>$ECM_OUTPUTNAME.T$j";
      print "=>$cmd\n" if($ECHO_CMDLINE);
      $thd[$j]=async{system($cmd)};
    }
#    $res=0;
#    for ($j=1;$j<=$NUM_THREADS;$j++) {
#      $res+=eval{$thd[$j]->join()};
#    }
#    for ($j=1;$j<=$NUM_THREADS;$j++) {
#      if ($LATSIEVE_SIDE) {
#        unlink <$JOBNAME.T$j.afb.1> if ($sieverRL == ($Q0-1));
#      }
#      else {
#        unlink <$JOBNAME.T$j.afb.0> if ($sieverAL == ($Q0-1));
#      }
#      $cmd="\"$CAT\" $SIEVER_OUTPUTNAME.T$j >> $SIEVER_OUTPUTNAME";
#      print "=>$cmd\n" if($ECHO_CMDLINE);
#      concat("$SIEVER_OUTPUTNAME.T$j", ">>", "$SIEVER_OUTPUTNAME");
#      unlink "$SIEVER_OUTPUTNAME.T$j";
#    }
  }
When I run this script (command line window under Win 7 professional, 64 bit), I get this screen output:

Code:
=>ECM -nn -maxmem 900 -c 111 <alq10212.2315.txt 43000000 >>alq10212.2315_43e6.out.T1
=>ECM -nn -maxmem 900 -c 111 <alq10212.2315.txt 43000000 >>alq10212.2315_43e6.out.T2
=>ECM -nn -maxmem 900 -c 111 <alq10212.2315.txt 43000000 >>alq10212.2315_43e6.out.T3
=>ECM -nn -maxmem 900 -c 111 <alq10212.2315.txt 43000000 >>alq10212.2315_43e6.out.T4
=>ECM -nn -maxmem 900 -c 111 <alq10212.2315.txt 43000000 >>alq10212.2315_43e6.out.T5
=>ECM -nn -maxmem 900 -c 111 <alq10212.2315.txt 43000000 >>alq10212.2315_43e6.out.T6
=>ECM -nn -maxmem 900 -c 111 <alq10212.2315.txt 43000000 >>alq10212.2315_43e6.out.T7
Perl exited with active threads:
        7 running and unjoined
        0 finished and unjoined
        0 running and detached
According to the output files which have appeared in my ecm directory, only threads T1, T2, T3, T4 and T6 have been spawned, but not T5 and T7. Any ideas why?

Last fiddled with by Andi47 on 2010-08-24 at 15:08
Andi47 is offline   Reply With Quote
Old 2010-08-27, 05:31   #2
Andi47
 
Andi47's Avatar
 
Oct 2004
Austria

2·17·73 Posts
Default

Quote:
Originally Posted by Andi47 View Post
According to the output files which have appeared in my ecm directory, only threads T1, T2, T3, T4 and T6 have been spawned, but not T5 and T7. Any ideas why?
Hmmm... I think I found out why the threads have been left unjoined and two of them had died immediately: I accidently commented out these lines:

Code:
    $res=0;
    for ($j=1;$j<=$NUM_THREADS;$j++) {
      $res+=eval{$thd[$j]->join()};
    }
Andi47 is offline   Reply With Quote
Old 2010-09-25, 06:34   #3
Andi47
 
Andi47's Avatar
 
Oct 2004
Austria

2·17·73 Posts
Default

Current version (with the line mentioned in post #2 NOT commented out):

Code:
use Math::BigInt;
use Math::BigFloat;
# Bah, this causes a fatal error if GMP BigInt is not available.
# use Math::BigInt lib => 'GMP';

$NUM_CPUS=7;
$NUM_THREADS=$NUM_CPUS;

$ECHO_CMDLINE=1;

### ECM parameters ###

$B1=26e7;
$NUM_CURVES=91; #total number of curves 
$MAXMEM=900; #max. memory used per thread

#$INPUTFILE="alq10212.2351.txt";
#$ECM_OUTPUTNAME="alq10212.2351_3e6.out";

$INPUTFILE="alq4788.2549.txt";
$ECM_OUTPUTNAME="alq4788.2549_h_26e7.out";



############# nothing configurable below here! #######################

$CNUM=int($NUM_CURVES)/$NUM_THREADS; #note: this will cause rounding errors if $NUM_CURVES is not divisible by $NUM_THREADS

if ($NUM_THREADS != 1) {
  use Config; 
  if (!($Config{usethreads})) { 
    printf "This version of Perl doesn't support multiple threads.  Only using 1 thread.";
    $NUM_THREADS=1; 
  }
  else {
    use Thread qw(async);
  }
}


  if ($NUM_THREADS==1) {
    # It's very important to call like this, so that if the user CTRL-C's,
    # or otherwise kills the process, we see it and terminate as well.
    unlink($ECM_OUTPUTNAME);
    $cmd="ecm -nn -maxmem $MAXMEM -c $CNUM <$INPUTFILE $B1 >>$ECM_OUTPUTNAME";
    print "=>$cmd\n" if($ECHO_CMDLINE);
    $res=system($cmd);
  }
  else {
    @thd = (1 .. $NUM_THREADS);
    for ($j=1;$j<=$NUM_THREADS;$j++) {
      unlink("$ECM_OUTPUTNAME.T$j");
      $cmd="ECM -nn -maxmem $MAXMEM -c $CNUM <$INPUTFILE $B1 >>$ECM_OUTPUTNAME.T$j";
      print "=>$cmd\n" if($ECHO_CMDLINE);
      $thd[$j]=async{system($cmd)};
    }
    $res=0;
    for ($j=1;$j<=$NUM_THREADS;$j++) {
      $res+=eval{$thd[$j]->join()};
    }
  }
Andi47 is offline   Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple threads per assignment? f0rteOC Hardware 3 2016-02-29 06:08
using multiple threads on an LL assignment tha Software 4 2016-02-02 13:49
Question: Multiple sequences in NewPGen format Xentar Conjectures 'R Us 3 2008-01-20 15:56
Multiple threads efficiency... Xyzzy Linux 1 2004-12-31 21:03
multiple computer question yankeesmarc923 Software 13 2003-12-13 20:39

All times are UTC. The time now is 06:56.


Sat Jul 17 06:56:19 UTC 2021 up 50 days, 4:43, 1 user, load averages: 1.84, 2.00, 1.78

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.