mersenneforum.org  

Go Back   mersenneforum.org > Great Internet Mersenne Prime Search > PrimeNet

Reply
 
Thread Tools
Old 2014-10-31, 12:18   #1
Rincewind
 
Rincewind's Avatar
 
Oct 2006

103 Posts
Default convert files from srsieve/srfile into worktodo.txt

Hi,

is there a way to convert the output from srsieve/srfile (.abcd .prp .pfgw) automaticaly into a worktodo.txt for mprime/prime95?
Rincewind is offline   Reply With Quote
Old 2014-10-31, 14:00   #2
Mini-Geek
Account Deleted
 
Mini-Geek's Avatar
 
"Tim Sorbera"
Aug 2006
San Antonio, TX USA

17·251 Posts
Default

If doing a little bit of manual work, you can use a text editor: In any decent text editor (e.g. Notepad++), use regex to find/replace, e.g.
Code:
^(\d+) (\d+)$
replace with
Code:
PRP=\1,2,\2,-1
will transform

Code:
some header line
456 789456
789 456987
to

Code:
some header line
PRP=456,2,789456,-1
PRP=789,2,456987,-1
If you need it to be an automated script, you might do something like this pseudo-Python:
Code:
for line in read(input_file):
    # if it's an actual line and not a header
    k, n = split(line)
    print('PRP={},2,{},-1', k, n)
Mini-Geek is offline   Reply With Quote
Old 2014-10-31, 15:13   #3
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3×2,399 Posts
Default

Code:
import re
in_file = 'blah.abcd'
out = []
with open(in_file) as f:
    for line in f.readlines():
        if re.match(r'^(\d+) (\d+)$', line):
            k, n = line.split()
            out.append('PRP={},2,{},-1'.format(k, n))
out_file = 'worktodo.txt'
with open(out_file, 'w') as f:
    f.write('\n'.join(out) + '\n')
The loop could be written as an ultra-extended list comprehension:

Code:
out = ['PRP={},2,{},-1'.format(*line.split()) for line in f.readlines() if re.match(r'^(\d+) (\d+)$', line)]

Last fiddled with by Dubslow on 2014-10-31 at 15:15
Dubslow is offline   Reply With Quote
Old 2014-10-31, 17:18   #4
Rincewind
 
Rincewind's Avatar
 
Oct 2006

10310 Posts
Default

That's great!

I thought about using 'sed' but regex and I are not the best friends ; )
Thank you both!
Rincewind is offline   Reply With Quote
Old 2014-10-31, 17:46   #5
Batalov
 
Batalov's Avatar
 
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2

22·2,281 Posts
Default

awk

For example
awk '{print "PRP="$1",2,"$2",-1"}' infile > outfile
and then take care of the 1st line (the header) in an editor
Batalov is offline   Reply With Quote
Old 2014-10-31, 19:07   #6
Mark Rose
 
Mark Rose's Avatar
 
"/X\(‘-‘)/X\"
Jan 2013

54708 Posts
Default

Quote:
Originally Posted by Batalov View Post
awk

For example
awk '{print "PRP="$1",2,"$2",-1"}' infile > outfile
and then take care of the 1st line (the header) in an editor
awk '{if(NR==1){print;}else{print "PRP="$1",2,"$2",-1"}' infile >outfile

:)
Mark Rose is offline   Reply With Quote
Old 2014-10-31, 19:19   #7
Batalov
 
Batalov's Avatar
 
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2

23A416 Posts
Default

Perfectionism notwithstanding, there's no limit what can be further beautified :)

If you have 400 lines in input and 8 cores for Prime95 to follow,

awk '{if(NR%50==1){print "[Worker #"int(NR/50)+1"]"} if(NR>1){print "PRP="$1",2,"$2",-1"}}' infile >outfile
Batalov is offline   Reply With Quote
Old 2014-10-31, 22:33   #8
Rincewind
 
Rincewind's Avatar
 
Oct 2006

103 Posts
Default

This is very helpful!

Is there a way to use sed or awk to create a file for n-cores where every nth-candidate is moved to a certain worker:

for example 4 cores:
Code:
candidate      - >            assigned worker
1                                   1
2                                   2
3                                   3
4                                   4
5                                   1
6                                   2
7                                   3
8                                   4
...
This would mean that there are no (or only small) gaps between the n-values from the workers.
Rincewind is offline   Reply With Quote
Old 2014-10-31, 23:04   #9
Batalov
 
Batalov's Avatar
 
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2

22×2,281 Posts
Default

Here you will need a bit of perl (probably can be done in awk, but when you get out of one-line volume of code in awk you want to switch to perl). This takes one parameter (or 4 by default) and text on stdin, like this: ./split.pl 6 < aa.npg > worktodo.txt
Code:
#!/usr/bin/perl -w

$N = (shift || 4);

@A = <>;

for($i=1;$i<=$N;$i++) {
    print "[Worker #", $i, "]\n";
    for($k=$i;$k<@A;$k+=$N) {
        $A[$k] =~ /(\d+) (\d+)/;
        print "PRP=$1,2,$2,-1\n";
    }
}
Note: this, of course, assumes that the input if an .npg file or a .pfgw file and the first line of it is to be thrown away. Don't forget it or else you will lose the first line with a candidate (if you actually already stripped the header).

Last fiddled with by Batalov on 2014-10-31 at 23:08 Reason: (P.S.)
Batalov is offline   Reply With Quote
Old 2014-11-01, 11:47   #10
Rincewind
 
Rincewind's Avatar
 
Oct 2006

103 Posts
Thumbs up

Again: Thank you!
This will do it for me.
Rincewind is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bug in srfile 1.0.6 pepi37 Software 6 2017-05-25 17:51
where is prime95 keeping my prime, local, worktodo files? almostfrugal Information & Answers 4 2012-09-19 03:51
Regenerating the worktodo files from PrimeNet? LaurV PrimeNet 3 2012-03-28 17:40
srfile justinsane Software 2 2009-07-20 16:27
P-1 and srfile henryzz Factoring 7 2008-11-04 17:01

All times are UTC. The time now is 00:36.

Fri Oct 23 00:36:35 UTC 2020 up 42 days, 21:47, 0 users, load averages: 0.96, 1.41, 1.54

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, 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.