manpage.pl 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  1. #!/usr/bin/env perl
  2. # Hey, EMACS: -*- cperl -*-
  3. # manpage.pl - script to generate mlucas(1) man page from embedded Pod
  4. # Copyright (C) 2015-2019 Alex Vong <alexvong1995@gmail.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program; if not, write to the Free Software Foundation, Inc.,
  18. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. #
  20. # First parameter, NAME, should be all caps
  21. # Second parameter, SECTION, should be 1-8, maybe w/ subsection
  22. # other parameters are allowed: see man(7), man(1)
  23. #
  24. # Some roff macros, for reference:
  25. # .nh disable hyphenation
  26. # .hy enable hyphenation
  27. # .ad l left justify
  28. # .ad b justify to both left and right margins
  29. # .nf disable filling
  30. # .fi enable filling
  31. # .br insert line break
  32. # .sp <n> insert n+1 empty lines
  33. # for manpage-specific macros, see man(7)
  34. # for reference for writing man pages, see man-page(7).
  35. # for Perl Pod format, see perlpod(1).
  36. use strict;
  37. use warnings;
  38. use Pod::Man;
  39. # my global variables
  40. my $ERR_USAGE = 67;
  41. my $PROG_NAME = "MLUCAS";
  42. my $PROG_VER = "Mlucas 17.1";
  43. my $SECTION_NAME = "User Commands";
  44. my $SECTION_NUM = "1";
  45. my $LAST_UPDATE = "2019-01-26";
  46. my $ERR_HANDLING = "die";
  47. chomp(my $USAGE = <<EOF);
  48. Usage: $0 [-h | --help]
  49. -h, --help show this message
  50. EOF
  51. chomp(my $GREET = <<'EOF');
  52. .\" Hey, EMACS: -*- nroff -*-
  53. EOF
  54. chomp(my $INTRO = <<'EOF');
  55. .\" mlucas.1 - man page of mlucas written for Debian GNU/Linux
  56. .\" Copyright (C) 2015, 2017 Alex Vong <alexvong1995@gmail.com>,
  57. .\"
  58. .\" This program is free software; you can redistribute it and/or modify
  59. .\" it under the terms of the GNU General Public License as published by
  60. .\" the Free Software Foundation; either version 2 of the License, or
  61. .\" (at your option) any later version.
  62. .\"
  63. .\" This program is distributed in the hope that it will be useful,
  64. .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
  65. .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  66. .\" GNU General Public License for more details.
  67. .\"
  68. .\" You should have received a copy of the GNU General Public License along
  69. .\" with this program; if not, write to the Free Software Foundation, Inc.,
  70. .\" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  71. .\"
  72. .\" First parameter, NAME, should be all caps
  73. .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
  74. .\" other parameters are allowed: see man(7), man(1)
  75. .\"
  76. .\" Some roff macros, for reference:
  77. .\" .nh disable hyphenation
  78. .\" .hy enable hyphenation
  79. .\" .ad l left justify
  80. .\" .ad b justify to both left and right margins
  81. .\" .nf disable filling
  82. .\" .fi enable filling
  83. .\" .br insert line break
  84. .\" .sp <n> insert n+1 empty lines
  85. .\" for manpage-specific macros, see man(7)
  86. .\" for reference for writing man pages, see man-page(7).
  87. .\" for Perl Pod format, see perlpod(1).
  88. EOF
  89. # preprocess embedded Pod in this script using M4
  90. sub preprocess
  91. {
  92. return <<`EOF`;
  93. printf '%s' "change""quote(\\\`[+', \\\`+]')" | cat - "$0" | m4
  94. EOF
  95. }
  96. # convert Pod to Man using Pod::Man
  97. sub pod2man
  98. {
  99. my $output;
  100. my $parser = Pod::Man->new
  101. (
  102. center => "$SECTION_NAME",
  103. date => "$LAST_UPDATE",
  104. errors => "$ERR_HANDLING",
  105. name => "$PROG_NAME",
  106. release => "$PROG_VER",
  107. section => "$SECTION_NUM",
  108. );
  109. $parser->output_string(\$output);
  110. $parser->parse_lines(@_);
  111. return split "$/", "$output";
  112. }
  113. # add greeting and intorduction in the beginning
  114. sub add_greeting_intro
  115. {
  116. my $header = shift;
  117. my $blank_line = shift;
  118. unshift @_, "$GREET", "$header", "$blank_line", "$INTRO", "$blank_line";
  119. return @_;
  120. }
  121. # postprocess Man using perlre
  122. sub postprocess
  123. {
  124. foreach (@_)
  125. {
  126. # convert .IP macro to .TP macro
  127. s/^\.(el|ie\sn)\s\.IP\s"([^"]+)"\s(\d+)
  128. /.$1 \\{\\PERL_NEWLINE.TP $3PERL_NEWLINE$2\\}/gx;
  129. s/^\.IP\s"([^"]+)"\s(\d+)
  130. /.TP $2PERL_NEWLINE$1/gx;
  131. # convert `\fBfunction\fR()' to `.BR function ()'
  132. # convert `\fBfunction\fR(section)' to `.BR function (section)'
  133. s/\\fB([^\\]+)\\fR\((\d?)\)([[:punct:]]?)\s*(\.?[^\s[:punct:]]+)
  134. /PERL_NEWLINE.BR $1 ($2)$3PERL_NEWLINE$4/gx;
  135. s/\\fB([^\\]+)\\fR\((\d?)\)([[:punct:]]?)\s*
  136. /PERL_NEWLINE.BR $1 ($2)$3/gx;
  137. # remove \& followed by newline
  138. s/\\&PERL_NEWLINE//g;
  139. # convert dummy newline to real one in order to avoid a bug
  140. # where newline `\n' fail to render
  141. # when being placed between a comma `,' and a dot `.'
  142. s/PERL_NEWLINE/\n/g;
  143. print;
  144. }
  145. }
  146. # main
  147. $\ = "$/";
  148. foreach (@ARGV)
  149. {
  150. if ($_ eq "-h" or $_ eq "--help")
  151. {
  152. print "$USAGE";
  153. exit;
  154. }
  155. else
  156. {
  157. print STDERR "invalid option: `$_'";
  158. print STDERR "$USAGE";
  159. exit "$ERR_USAGE";
  160. }
  161. }
  162. postprocess(add_greeting_intro(pod2man(preprocess)));
  163. exit;
  164. =pod
  165. =for comment
  166. [+start removing blank lines+]
  167. dnl
  168. define([+_START_NO_BLANK_LINES+],
  169. [+=for man .PD 0
  170. =begin man
  171. .de Sp
  172. .br
  173. ..
  174. =end man+])dnl
  175. =for comment
  176. [+stop removing blank lines+]
  177. dnl
  178. define([+_END_NO_BLANK_LINES+],
  179. [+=for man .PD
  180. =begin man
  181. .de Sp
  182. .if t .sp .5v
  183. .if n .sp
  184. ..
  185. =end man+])dnl
  186. =for comment
  187. [+front end to invoke _INDENT_BLOCK_NORMAL and _INDENT_BLOCK_HACKISH
  188. _INDENT_BLOCK_NORMAL is used
  189. if no function or manpage references are present+]
  190. dnl
  191. define([+_INDENT_BLOCK+],
  192. [+ifelse(regexp([+$1+],[+B<[^<]+>([012345678]?)+]),
  193. [+-1+],
  194. [+_INDENT_BLOCK_NORMAL([+$1+], [+$2+])+],
  195. [+_INDENT_BLOCK_HACKISH([+$1+], [+$2+])+])+])dnl
  196. =for comment
  197. [+primary way to start indentation of text block
  198. a text block is a piece of text without blank lines+]
  199. dnl
  200. define([+_INDENT_BLOCK_NORMAL+],
  201. [+=over 4
  202. =item [+$1+]
  203. =for man .Sp
  204. _START_NO_BLANK_LINES
  205. [+$2+]
  206. _END_NO_BLANK_LINES
  207. =back+])dnl
  208. =for comment
  209. [+secondary way to start indentation of text block+]
  210. dnl
  211. define([+_INDENT_BLOCK_HACKISH+],
  212. [+=for man .RE
  213. =for man .RS 7
  214. [+$1+]
  215. =for man .RS 4
  216. [+$2+]
  217. =for man .RE+])dnl
  218. =for comment
  219. [+join strings together (e.g., `_JOIN([+a+], [+b+], [+c+])' => `abc')+]
  220. dnl
  221. define([+_JOIN+],
  222. [+ifelse([+$#+],
  223. [+1+],
  224. [+$1+],
  225. [+[+$1+]_JOIN(shift($@))+])+])dnl
  226. =head1 NAME
  227. mlucas - program to perform Lucas-Lehmer test on a Mersenne number,
  228. 2 ^ p - 1
  229. =head1 SYNOPSIS
  230. _START_NO_BLANK_LINES
  231. B<mlucas>
  232. B<mlucas -h>
  233. B<mlucas> B<-s> B<tiny> | B<t> | B<small> | B<s> | B<medium> | B<m> |
  234. B<large> | B<l> | B<huge> | B<h> | B<all> | B<a>
  235. [B<-iters> B<100> | B<1000> | B<10000> [B<-nthread> I<threads>]]
  236. B<mlucas> B<-m> I<exponent> | B<-f> I<exponent>
  237. [B<-iters> B<100> | B<1000> | B<10000> [B<-nthread> I<threads>]]
  238. B<mlucas> B<-fftlen> I<fft_length>
  239. [B<-radset> I<radix_set>]
  240. [B<-m> I<exponent> | B<-f> I<exponent>]
  241. B<-iters> B<100> | B<1000> | B<10000>
  242. [B<-nthread> I<threads>]
  243. _END_NO_BLANK_LINES
  244. =head1 DESCRIPTION
  245. This manual page documents briefly the B<mlucas> command.
  246. B<mlucas> is an open-source (and free/libre) program
  247. for performing Lucas-Lehmer test on prime-exponent Mersenne numbers,
  248. that is, integers of the form 2 ^ p - 1, with prime exponent p.
  249. In short, everything you need to search for world-record Mersenne primes!
  250. It has been used in the verification of various Mersenne primes,
  251. including the 45th, 46th and 48th found Mersenne prime.
  252. You may use it to test any suitable number as you wish,
  253. but it is preferable that you do so in a coordinated fashion,
  254. as part of the B<Great Internet Mersenne Prime Search> (B<GIMPS>).
  255. For more information on B<GIMPS>,
  256. see the B<Great Internet Mersenne Prime Search> subsection
  257. within the B<NOTES> section and B<SEE ALSO> section.
  258. Note that B<mlucas> is not (yet) as efficient as the main B<GIMPS> client,
  259. George Woltman's B<Prime95> program
  260. (a.k.a. B<mprime> for the (gnu/)linux version),
  261. but that program is not truly open-source (and free/libre), since
  262. it requires the user to abide by the prize-sharing rules set by its author
  263. (incompatible with I<freedom to run the program as you wish,
  264. for any purpose>),
  265. should a user be lucky enough to find a new prime eligible for
  266. one of the monetary prizes offered by the Electronic Freedom Foundation
  267. (see L<EFF Cooperative Computing Awards|https://www.eff.org/awards/coop>
  268. for details).
  269. B<mlucas> reads the exponents from the F<$MLUCAS_PATH/worktodo.ini> file.
  270. Results are written to the F<$MLUCAS_PATH/results.txt> file
  271. and the exponent-specific F<$MLUCAS_PATH/*.stat> file
  272. (see section B<FILES> for details).
  273. Error messages are written to I<stderr>
  274. and the F<$MLUCAS_PATH/*.stat> file.
  275. Exponents can also be passed as command-line arguments
  276. but this is mainly used for debugging (see section B<OPTIONS> for details).
  277. In addition, B<mlucas> can perform the Pe'pin primality test
  278. on Fermat numbers 2 ^ (2 ^ n) + 1,
  279. using an exponent-optimized fast-transform length
  280. much like that used for testing Mersenne numbers.
  281. New users are urged to jump straight to the B<EXAMPLE> section
  282. and follow the examples and pointers to other sections.
  283. Users with little time for in-depth reading
  284. should at least read the B<NOTES>, B<BUGS> and B<EXAMPLE> sections
  285. for a brief introduction to the B<Great Internet Mersenne Prime Search>,
  286. undesirable restrictions and common usages.
  287. B<FILES> section is also highly recommended
  288. since it describes the B<mlucas> configuration files
  289. used for host-specific optimization and other B<mlucas>-generated files.
  290. Advanced users should also peruse the B<OPTIONS> section
  291. since it introduces less-commonly-used advanced options.
  292. Experienced users who find this manual inadequate
  293. should consult the B<SEE ALSO> section for further information.
  294. Lastly, the F<Mlucas README>, available both online and offline,
  295. is highly recommended
  296. since it is written and maintained by the author of B<mlucas>
  297. and should be considered the final authority.
  298. =head1 OPTIONS
  299. B<mlucas> follows the traditional POSIX (see B<standards>(7) for details)
  300. command line syntax,
  301. with short options starting with one dashes (`I<->').
  302. A summary of options is included below.
  303. A complete description is in the B<SEE ALSO> section.
  304. =over 7
  305. =item B<-h>
  306. Show version of program and summary of options.
  307. =item B<-s t, -s tiny>
  308. Run 100-iteration self-test on a set of 32 Mersenne exponents,
  309. ranging from 173431 to 2455003.
  310. This will take around 1 minute on a fast (pre-2010) CPU.
  311. =item B<-s s, -s small>
  312. Run 100-iteration self-test on a set of 24 Mersenne exponents,
  313. ranging from 173431 to 1245877.
  314. This will take around 10 minutes on a fast (pre-2010) CPU.
  315. =item B<-s m, -s medium>
  316. Run 100-iteration self-test on a set of 24 Mersenne exponents,
  317. ranging from 1327099 to 9530803.
  318. This will take around an hour on a fast (pre-2010) CPU.
  319. =item B<-s l, -s large>
  320. Run 100-iteration self-test on a set of 24 Mersenne exponents,
  321. ranging from 10151971 to 72851621.
  322. This will take around an hour on a fast (pre-2010) CPU.
  323. =item B<-s h, -s huge>
  324. Run 100-iteration self-test on a set of 16 Mersenne exponents,
  325. ranging from 77597293 to 282508657.
  326. This will take a couple of hours on a fast (pre-2010) CPU.
  327. =item B<-s a, -s all>
  328. Run 100-iteration self-test on all Mersenne exponents
  329. and all FFT radix sets.
  330. This will take several hours on a fast (pre-2010) CPU.
  331. =item B<-fftlen> I<fft_length>
  332. This allows the user to specify the length of the fast-transform (FFT)
  333. used to effect the large-integer modular multiply
  334. which is at the heart of all such nonfactorial primality tests.
  335. The length unit here is in terms of the number of double-precision
  336. machine words used in the multiword-integer encoding
  337. of the primality test residue
  338. which is both input and result of each of said multiplies.
  339. Because mlucas is intended for testing numbers with many millions of bits,
  340. we generally speak of these FFT lengths in terms of kilodoubles
  341. (= 2 ^ 10 or 1024 doubles).
  342. If I<fft_length> is one of the available FFT lengths (in kilodoubles),
  343. run all available FFT radices available at that length,
  344. unless the I<-radset> flag is also invoked (see below for details).
  345. If I<-fftlen> is invoked with either the I<-m> or I<-f> flag,
  346. the self-tests will perform the first 100 iterations
  347. of a Lucas-Lehmer test (I<-m>) or Pe'pin test (I<-f>)
  348. on the user-specified Mersenne or Fermat number.
  349. If no user-set exponent is invoked,
  350. do 100 Lucas-Lehmer test iterations using
  351. the default self-test Mersenne or Fermat exponent for that FFT length.
  352. The program uses this to find the optimal radix set for a given FFT length
  353. on your hardware.
  354. =item B<-iters> B<100> | B<1000> | B<10000>
  355. Do I<100>, I<1000> or I<10000> self-test iterations of the type determined
  356. by the modulus-related options
  357. (I<-s> / I<-m> = Lucas-Lehmer test iterations with initial seed 4,
  358. I<-f> = Pe'pin test squarings with initial seed 3).
  359. Default is I<100> iterations.
  360. =item B<-radset> I<radix_set>
  361. Specify index of a set of complex FFT radices to use,
  362. based on the big selection table in the function B<get_fft_radices>().
  363. This requires a supported value of I<-fftlen> to be specified,
  364. meaning (for an FFT length supported by the program)
  365. an index B<0>, B<1>, B<2>, ... and so on.
  366. B<0> is always a valid radix set index;
  367. how high one can go in the enumeration depends on the FFT length.
  368. As soon as the user tries an index out of range of the current FFT length,
  369. the program will error-exit with an informational message to that effect,
  370. which also notes the maximum allowable radix set index for that FFT length.
  371. =item B<-nthread> I<threads>
  372. For multithread-enabled (default) build,
  373. perform the test in parallel mode with this many threads.
  374. =item B<-m> I<exponent>
  375. Perform a Lucas-Lehmer primality test of the Mersenne number
  376. M(I<exponent>) = 2 ^ I<exponent> - 1,
  377. where I<exponent> must be an odd prime.
  378. If I<-iters> is also invoked, this indicates a timing test.
  379. This requires suitable added arguments
  380. (I<-fftlen> and, optionally, I<-radset>) to be supplied.
  381. If the I<-fftlen> option (and optionally I<-radset>) is also invoked
  382. but I<-iters> is not,
  383. the program first checks
  384. the first line of the F<$MLUCAS_PATH/worktodo.ini> file to see
  385. if the assignment specified there is a Lucas-Lehmer test
  386. with the same exponent as specified via the I<-m> argument.
  387. If so, the I<-fftlen> argument is treated as a user override
  388. of the default FFT length for the exponent.
  389. If I<-radset> is also invoked, this is similarly treated as
  390. a user-specified radix set for the user-set FFT length;
  391. otherwise the program will use the F<$MLUCAS_PATH/mlucas.cfg> file
  392. to select the radix set to be used for the user-forced FFT length.
  393. If the F<$MLUCAS_PATH/worktodo.ini> file entry
  394. does not match the I<-m> value,
  395. a set of timing self-tests is run on the user-specified Mersenne number
  396. using all sets of FFT radices available at the specified FFT length.
  397. If the I<-fftlen> option is not invoked,
  398. the tests use all sets of FFT radices
  399. available at that exponent's default FFT length.
  400. Use this to find the optimal radix set
  401. for a single given Mersenne exponent on your hardware,
  402. similarly to the I<-fftlen> option.
  403. Perform 100 iterations, or as many as specified via the I<-iters> flag.
  404. =item B<-f> I<exponent>
  405. Perform a base-3 Pe'pin test on the Fermat number
  406. F(I<exponent>) = 2 ^ (2 ^ I<exponent>) + 1.
  407. If desired this can be invoked together with the I<-fftlen> option
  408. as for the Mersenne-number self-tests (see above notes on the I<-m> flag;
  409. note that not all FFT lengths supported for I<-m> are available for I<-f>:
  410. I<-m> permits FFT lengths of form I<odd> * 2 ^ n
  411. with I<odd> = any of B<1>, B<3>, B<5>, B<7>, B<9>, B<11>, B<13>, B<15>;
  412. I<-f> allows odd = B<1>, B<7>, B<15> and B<63>)
  413. Optimal radix sets and timings
  414. are written to the F<$MLUCAS_PATH/fermat.cfg> file.
  415. Perform 100 iterations, or as many as specified via the I<-iters> flag.
  416. =back
  417. =head1 EXIT STATUS
  418. _INDENT_BLOCK(
  419. [+The list of exit status values is limited.
  420. It is not possible to determine the cause of failure
  421. from the exit status value alone.
  422. However, B<mlucas> make use of I<stderr> to print error messages
  423. as well as saving them to the F<$MLUCAS_PATH/*.stat> file,
  424. where I<*> is in the form+],
  425. [+pI<exponent>+])
  426. _INDENT_BLOCK(
  427. [+for Mersenne number 2 ^ I<exponent> - 1 or+],
  428. [+fI<exponent>+])
  429. for Fermat number 2 ^ (2 ^ I<exponent>) + 1.
  430. (see B<FILES> section for details).
  431. =over 7
  432. =item B<0>
  433. Exit successfully.
  434. =item B<1>
  435. _START_NO_BLANK_LINES
  436. Assertion failure.
  437. Cannot determine the number of CPUs.
  438. Unknown fetal error.
  439. Radix set index not available for given FFT length.
  440. _END_NO_BLANK_LINES
  441. =item B<255>
  442. _START_NO_BLANK_LINES
  443. B<thread_policy_set>() failure.
  444. B<malloc>(3), B<calloc>(3) or B<realloc>(3) failure.
  445. B<pthread_create>(3) or B<pthread_join>(3) failure.
  446. _END_NO_BLANK_LINES
  447. =back
  448. =head1 ENVIRONMENT
  449. B<mlucas> honors the following environment variables, if they exist:
  450. =over 7
  451. =item B<MLUCAS_PATH>
  452. The path to read B<mlucas> configuration files
  453. and to write B<mlucas> generated files (see B<FILES> section for details).
  454. B<MLUCAS_PATH> must end with a slash (e.g., I</home/foolish/bar/>.
  455. If B<MLUCAS_PATH> is not set,
  456. then B<MLUCAS_PATH> defaults to I<$HOME/.mlucas.d/>,
  457. where the environmental variable I<$HOME> will be expanded
  458. in the environment where B<mlucas> is invoked.
  459. B<mlucas> will attept to make the directory with parents
  460. pointed by B<MLUCAS_PATH> using the B<mkdir>(1) command.
  461. The effect is similar to executing I<mkdir -p $MLUCAS_PATH> in the shell
  462. provided that the I<-p> flag is honored.
  463. =back
  464. =head1 FILES
  465. This section details B<mlucas> configuration files
  466. and B<mlucas> generated files.
  467. As noted in the B<ENVIRONMENT> section,
  468. B<$MLUCAS_PATH> defaults to I<$HOME/mlucas.d/> but this can be
  469. overridden at run-time by setting the B<MLUCAS_PATH> environment variable.
  470. =over 7
  471. =item B<$MLUCAS_PATH/*.stat>
  472. _INDENT_BLOCK(
  473. [+The filename-prefix wildcard I<*>
  474. is as described in the EXIT STATUS section;
  475. for the primality test of the Mersenne number 2 ^ I<exponent> - 1
  476. it is of the form+],
  477. [+pI<exponent>+])
  478. _INDENT_BLOCK(
  479. [+All important events, per-10000-iteration residues
  480. (or per-100000-iteration if more than 4 threads are used for the test)
  481. and the final residue during Lucas-Lehmer test of I<exponent>
  482. are recorded in this file.
  483. It can be seen as an I<exponent>-specific detailed
  484. F<$MLUCAS_PATH/results.txt>
  485. (see F<$MLUCAS_PATH/results.txt> below for details).
  486. This file is useful for debugging purposes.
  487. Its format looks like:+],
  488. [+B<INFO>: I<event>
  489. ...
  490. B<M>I<exponent>: B<using FFT length> I<fft_length>B<K>
  491. B<=> I<fft_length * 1024> B<8-byte floats.>
  492. Bz<this gives an average> I<bits> B<bits per digit>
  493. B<Using complex FFT radices> I<radix_set>
  494. (product of all elements of radix_set = fft_length / 2)
  495. ...
  496. B<[>I<date_and_time>B<]>
  497. B<M>I<exponent>
  498. B<Iter#> B<=> I<iterations>
  499. B<clocks> B<=> I<time_taken_per_10000_iterations>
  500. B<[>I< time_taken_per_iteration> B<sec/iter>B<]>
  501. B<Res64:> I<residue>B<.>
  502. B<AvgMaxErr> B<=> I<roe_avg>B<.>
  503. B<MaxErr> B<=> I<roe_max>
  504. ...
  505. [B<Restarting> B<M>I<exponent> B<at iteration> B<=> I<iteration>B<.>
  506. B<Res64:> I<residue>
  507. B<M>I<exponent>: B<using FFT length> I<fft_length>B<K>
  508. B<=> I<fft_length * 1024> B<8-byte floats.>
  509. B<this gives an average> I<bits> B<bits per digit>
  510. B<Using complex FFT radices> I<radix_set>]
  511. (product of all elements of radix_set = fft_length / 2)
  512. ...
  513. B<M>I<exponent> B<is not prime.>
  514. B<Res64:> I<residue>B<.>
  515. B<Program: E17.1>
  516. B<M>I<exponent> B<mod 2^36> B<=> I<remainder_1>
  517. B<M>I<exponent> B<mod 2^35 - 1> B<=> I<remainder_2>
  518. B<M>I<exponent> B<mod 2^36 - 1> B<=> I<remainder_3>+])
  519. =item B<$MLUCAS_PATH/fermat.cfg>
  520. The format of this file is exactly the same as
  521. the format of F<$MLUCAS_PATH/mlucas.cfg>
  522. (see F<$MLUCAS_PATH/mlucas.cfg> below for details).
  523. =item B<$MLUCAS_PATH/mlucas.cfg>
  524. _INDENT_BLOCK(
  525. [+This file stores the radix set with best timing for each FFT length.
  526. Its format looks like:+],
  527. [+B<17.1>
  528. I<fft_length> B<msec/iter> B<=> I<timing>
  529. B<ROE[avg,max]> B<=> B<[>I<roe_avg>B<,> I<roe_max>B<]>
  530. B<radices> B<=> I<radix_set>
  531. ...+])
  532. _END_NO_BLANK_LINES
  533. Normally, the I<timing> entry for each line should be monotonic
  534. from above to below since larger FFT length should take longer to test.
  535. But it is OK for a given I<fft_length> to have a higher I<timing> than
  536. the one after it since B<mlucas> checks the timings listed in this file
  537. for all FFT lengths >= the default FFT length for the number being tested,
  538. and uses the FFT length having the smallest listed timing.
  539. However, if you notice that this file has any entries such that
  540. a given I<fft_length> has a timing 5% or more greater than the next-larger
  541. FFT length, or higher timing than two or more larger FFT lengths,
  542. please contact the author (see B<BUGS> section for details).
  543. =item B<$MLUCAS_PATH/nthreads.ini>
  544. This file sets the number of threads used.
  545. It should only contain a positive integer
  546. since the content of this file is read by
  547. B<sscanf(>I<in_line>, I<"%d">B<,> I<&NTHREADS>B<);>
  548. where the variable I<in_line>
  549. contains the content of the F<$MLUCAS_PATH/nthreads.ini> file.
  550. If this file is not present,
  551. B<mlucas> will use as many threads as the number of CPUs detected.
  552. The number of threads used set by this file
  553. can be overridden by setting I<-nthread> flag at run-time.
  554. This file is for those who want to set the number of threads
  555. to be greater or less than the number of CPUs detected.
  556. This can be useful since some users reported up to 10% performance gain
  557. when using more threads than the number of CPUs detected.
  558. =item B<$MLUCAS_PATH/results.txt>
  559. _INDENT_BLOCK(
  560. [+Important events which occurred during Lucas-Lehmer test
  561. and the final residue obtained are recorded in this file.
  562. This file summarizes important information
  563. in all F<$MLUCAS_PATH/*.stat> files
  564. (see F<$MLUCAS_PATH/*.stat> above for details) into a single file.
  565. This file (more specifically, any results
  566. which were added to it since your last checkin from)
  567. should be submitted to the PrimeNet server (see subsection
  568. B<Great Internet Mersenne Prime Search> in section B<NOTES> for details)
  569. since the Lucas-Lehmer test exponents are obtained from the PrimeNet server
  570. (see F<$MLUCAS_PATH/worktodo.ini> below for details).
  571. Its format looks like:+],
  572. [+B<INFO:> I<event>
  573. ...
  574. [B<M>I<exponent> B<Roundoff warning on iteration> I<iteration>B<,>
  575. B<maxerr> B<=> I<roundoff_error>
  576. B< Retrying iteration interval to see if roundoff error is reproducible.>
  577. [B<Retry of iteration interval with fatal roundoff error was successful.>]]
  578. ...
  579. B<M>I<exponent>B< is not prime.>
  580. B<Res64:> I<residue>B<.>
  581. B<Program: E17.1>
  582. B<M>I<exponent> B<mod 2^36> B<=> I<remainder_1>
  583. B<M>I<exponent> B<mod 2^35 - 1> B<=> I<remainder_2>
  584. B<M>I<exponent> B<mod 2^36 - 1> B<=> I<remainder_3>
  585. ...+])
  586. =item B<$MLUCAS_PATH/worktodo.ini>
  587. _INDENT_BLOCK(
  588. [+This file contains Lucas-Lehmer test assignments to be tested.
  589. Its format looks like:+],
  590. [+I<assignment>B<=>I<ID>B<,>I<exponent>B<,>I<trial
  591. factored up to>B<,>I<has P-1 factoring>
  592. ...+])
  593. The I<assignment> field contains B<Test>
  594. if the assignment is a first-time Lucas-Lehmer test,
  595. or B<DoubleCheck> if the assignment is a double-check Lucas-Lehmer test.
  596. (The program handles both cases the same way.)
  597. _START_NO_BLANK_LINES
  598. I<ID> is a unique 32-digit hex number.
  599. I<exponent> specifies the Mersenne number
  600. (of the form 2 ^ I<exponent> - 1) to be tested.
  601. I<trial factored up to> is the number of bit this Mersenne number
  602. has been trial factored up to without finding a factor.
  603. I<has P-1 factoring> B<=> B<0> if no prior P-1 factoring has been done,
  604. B<=> B<1> if P-1 factoring (without finding a factor) has been done.
  605. Since mlucas currently has no P-1 factoring capability
  606. it simply discards these data,
  607. but users should prefer B<=> B<1> here
  608. since such an assignment is slightly more likely (5-10%) to yield a prime.
  609. _END_NO_BLANK_LINES
  610. To do Lucas-Lehmer test,
  611. you should reserve exponents from the PrimeNet server
  612. and copy lines in the above format into the
  613. F<$MLUCAS_PATH/worktodo.ini> file (see subsection
  614. B<Great Internet Mersenne Prime Search> in section B<NOTES> for details).
  615. You may need to create the F<$MLUCAS_PATH/worktodo.ini> file
  616. if it does not exist.
  617. =item B<Save files in $MLUCAS_PATH>
  618. All files matching the following extended regular expression
  619. (see B<regex>(7) for details)
  620. in I<$MLUCAS_PATH> directory are save files:
  621. ^[fpq][0123456789]+([.][0123456789]+0M)?$
  622. For both of the supported test types,
  623. duplicate pairs of savefiles are written at each checkpoint,
  624. to guard against corruption of the on-disk savefiles.
  625. Lucas-Lehmer test savefile-pair names start with <p> and <q>, respectively,
  626. while Pe'pin test savefile-pair names start with <f> and <q>, respectively.
  627. They should not be modified but backups may be made by the user.
  628. By default, the program will save a persistent backup of the primary
  629. (B<p> or B<f>) save file every 10 millionth iteration,
  630. for examples upon completion of the Lucas-Lehmer test of M57885161
  631. the user will find the following exponent-associated files
  632. in the I<$MLUCAS_PATH> directory:
  633. p57885161.stat
  634. p57885161.10M
  635. p57885161.20M
  636. p57885161.30M
  637. p57885161.40M
  638. p57885161.50M
  639. =back
  640. =head1 NOTES
  641. =head2 Great Internet Mersenne Prime Search
  642. This subsection needs to be compeleted...
  643. =head1 BUGS
  644. The argument parser is buggy.
  645. The relative position of arguments is relevant to B<mlucas>,
  646. the order of arguments in B<SYNOPSIS>
  647. should be followed to avoid confusing the parser.
  648. Only I<100>, I<1000> and I<10000> are supported for I<-iters> flag.
  649. However, the parser will not reject unsupported arguments.
  650. Using unsupported arguments for I<-iters> flag
  651. may trigger strange behaviour.
  652. Sometimes there is more than one applicable exit status values
  653. (see B<EXIT STATUS> section for details).
  654. In such case, there is no guarantee which will be returned.
  655. For example,
  656. if B<malloc>(3) failure triggers an assertion failure.
  657. It is possible that B<mlucas> returns I<1>
  658. instead of I<255> as exit status value.
  659. For problems regarding the program B<mlucas>,
  660. please contact the author Ernst W. Mayer <ewmayer@aol.com>.
  661. For installation and documentation related problems
  662. regarding the Debian package and this manual,
  663. please use B<reportbug>(1) to contact Alex Vong <alexvong1995@gmail.com>.
  664. =head1 EXAMPLE
  665. There are 3 common cases where you will want to run this program.
  666. Normally, you should do a spot-check first to quick-test your build,
  667. followed by the self-test range for `medium' exponents.
  668. Finally, full-blown Lucas-Lehmer testing
  669. which is the main purpose of this program.
  670. =over 7
  671. =item B<mlucas -fftlen 192 -iters 100 -radset 0 -nthread 2>
  672. Perform spot-check to see if B<mlucas> works
  673. and fill-in a bug report if it does not.
  674. The spot check should produce residues
  675. matching the internal tabulated ones.
  676. If the residues does not match,
  677. B<mlucas> should emit a verbose error message.
  678. =item B<mlucas -s m>
  679. Perform timing self-test for `medium' exponents
  680. to tune code parameters for your platform.
  681. Ordinary users are recommended to do this self-test only.
  682. For best results,
  683. run any self-tests under zero- or constant-load conditions.
  684. The self-tests append
  685. (or create if F<$MLUCAS_PATH/mlucas.cfg> does not exist)
  686. new timing data to the F<$MLUCAS_PATH/mlucas.cfg>
  687. (see B<FILES> section for details).
  688. Before doing any self-tests,
  689. you should first check if there is an existing
  690. F<$MLUCAS_PATH/mlucas.cfg> file
  691. and either delete it or do a backup-via-rename to
  692. to prevent mixing old and new timing data.
  693. F<$MLUCAS_PATH/mlucas.cfg> normally locates at
  694. I<$HOME/.mlucas.d/> directory
  695. although this can be overridden at run-time
  696. by settingthe B<MLUCAS_PATH> environment variable
  697. (see B<ENVIRONMENT> section for details).
  698. =item B<mlucas &>
  699. _INDENT_BLOCK(
  700. [+Perform Lucas-Lehmer test on Mersenne numbers
  701. by running B<mlucas> as a background job
  702. (see B<JOB CONTROL> section in B<bash>(1)
  703. and B<Builtins> subsection in B<dash>(1) for details).
  704. To perform Lucas-Lehmer test on a given Mersenne number,
  705. you must first perform a self-test
  706. for `medium' exponents mentioned above,
  707. or if you only desire to test a single selected Mersenne number,
  708. a self-test for the default FFT length for that number:+],
  709. [+mlucas -m I<exponent> -iters 100+])
  710. In the case of multi-exponent "production testing",
  711. you should reserve exponent from the PrimeNet server
  712. and add them into F<$MLUCAS_PATH/worktodo.ini>
  713. (see the subsection B<Great Internet Mersenne Prime Search>
  714. within the section B<NOTES> and B<FILES> section for details).
  715. =back
  716. =head2 Advanced Usage Tips
  717. To start B<mlucas> in terminal 1,
  718. add the following lines to your login shell initialization file,
  719. such as I<$HOME/.profile>
  720. (see B<INVOCATION> section in B<bash>(1)
  721. and B<Invocation> subsection B<dash>(1) for details).
  722. # Test if we are in tty1
  723. if test `tty` = '/dev/tty1'
  724. then
  725. # turn on job control
  726. set -m
  727. # start mlucas
  728. nice mlucas > /dev/null 2>&1 &
  729. fi
  730. =head1 SEE ALSO
  731. B<bash>(1), B<dash>(1), B<reportbug>(1)
  732. L<https://www.mersenneforum.org/mayer/README.html>,
  733. F</usr/share/doc/mlucas/html/README.html>
  734. B<mlucas> is documented fully by F<Mlucas README>,
  735. available both online and offline as shown above.
  736. L<F<Great Internet Mersenne Prime Search>|https://www.mersenne.org/>
  737. L<F<Mersenne Forum>|https://www.mersenneforum.org/>
  738. _JOIN([+L<F<Chris Caldwell's web page on Mersenne numbers>|+],
  739. [+https://primes.utm.edu/mersenne/index.html>+])
  740. _JOIN([+L<F<Richard Crandall and Barry Fagin, +],
  741. [+Discrete Weighted Transforms and Large-Integer Arithmetic.>|+],
  742. [+https://pdfs.semanticscholar.org/07c0/+],
  743. [+fae878fe9d6a117de08282802fb7b892bf2d.pdf>+])
  744. _JOIN([+L<F<Richard E. Crandall, Ernst W. Mayer, +],
  745. [+and Jason S. Papadopoulos, +],
  746. [+The Twenty-Fourth Fermat Number is Composite.>|+],
  747. [+https://www.mersenneforum.org/mayer/F24.pdf>+])
  748. =cut