manpage.pl 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  1. #!/usr/bin/perl
  2. # Hey, EMACS: -*- cperl -*-
  3. # manpage.pl - script to generate mlucas(1) man page from embedded Pod
  4. # Copyright (C) 2015-2021 Alex Vong <alexvong1995 AT protonmail DOT 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 20.1.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-2021 Alex Vong <alexvong1995 AT protonmail DOT 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. [B<FIXME:> This man page is potentially outdated, please see the
  246. L<online documentation|https://www.mersenneforum.org/mayer/README.html>
  247. or the help text located in F</usr/share/doc/mlucas/help.txt.gz>
  248. for up-to-date information.]
  249. This manual page documents briefly the B<mlucas> command.
  250. B<mlucas> is an open-source (and free/libre) program
  251. for performing Lucas-Lehmer test on prime-exponent Mersenne numbers,
  252. that is, integers of the form 2 ^ p - 1, with prime exponent p.
  253. In short, everything you need to search for world-record Mersenne primes!
  254. It has been used in the verification of various Mersenne primes,
  255. including the 45th, 46th and 48th found Mersenne prime.
  256. You may use it to test any suitable number as you wish,
  257. but it is preferable that you do so in a coordinated fashion,
  258. as part of the B<Great Internet Mersenne Prime Search> (B<GIMPS>).
  259. For more information on B<GIMPS>,
  260. see the B<Great Internet Mersenne Prime Search> subsection
  261. within the B<NOTES> section and B<SEE ALSO> section.
  262. Note that B<mlucas> is not (yet) as efficient as the main B<GIMPS> client,
  263. George Woltman's B<Prime95> program
  264. (a.k.a. B<mprime> for the (gnu/)linux version),
  265. but that program is not truly open-source (and free/libre), since
  266. it requires the user to abide by the prize-sharing rules set by its author
  267. (incompatible with I<freedom to run the program as you wish,
  268. for any purpose>),
  269. should a user be lucky enough to find a new prime eligible for
  270. one of the monetary prizes offered by the Electronic Freedom Foundation
  271. (see L<EFF Cooperative Computing Awards|https://www.eff.org/awards/coop>
  272. for details).
  273. B<mlucas> reads the exponents from the F<$MLUCAS_PATH/worktodo.ini> file.
  274. Results are written to the F<$MLUCAS_PATH/results.txt> file
  275. and the exponent-specific F<$MLUCAS_PATH/*.stat> file
  276. (see section B<FILES> for details).
  277. Error messages are written to I<stderr>
  278. and the F<$MLUCAS_PATH/*.stat> file.
  279. Exponents can also be passed as command-line arguments
  280. but this is mainly used for debugging (see section B<OPTIONS> for details).
  281. In addition, B<mlucas> can perform the Pe'pin primality test
  282. on Fermat numbers 2 ^ (2 ^ n) + 1,
  283. using an exponent-optimized fast-transform length
  284. much like that used for testing Mersenne numbers.
  285. New users are urged to jump straight to the B<EXAMPLE> section
  286. and follow the examples and pointers to other sections.
  287. Users with little time for in-depth reading
  288. should at least read the B<NOTES>, B<BUGS> and B<EXAMPLE> sections
  289. for a brief introduction to the B<Great Internet Mersenne Prime Search>,
  290. undesirable restrictions and common usages.
  291. B<FILES> section is also highly recommended
  292. since it describes the B<mlucas> configuration files
  293. used for host-specific optimization and other B<mlucas>-generated files.
  294. Advanced users should also peruse the B<OPTIONS> section
  295. since it introduces less-commonly-used advanced options.
  296. Experienced users who find this manual inadequate
  297. should consult the B<SEE ALSO> section for further information.
  298. Lastly, the F<Mlucas README>, available both online and offline,
  299. is highly recommended
  300. since it is written and maintained by the author of B<mlucas>
  301. and should be considered the final authority.
  302. =head1 OPTIONS
  303. B<mlucas> follows the traditional POSIX (see B<standards>(7) for details)
  304. command line syntax,
  305. with short options starting with one dashes (`I<->').
  306. A summary of options is included below.
  307. A complete description is in the B<SEE ALSO> section.
  308. =over 7
  309. =item B<-h>
  310. Show version of program and summary of options.
  311. =item B<-s t, -s tiny>
  312. Run 100-iteration self-test on a set of 32 Mersenne exponents,
  313. ranging from 173431 to 2455003.
  314. This will take around 1 minute on a fast (pre-2010) CPU.
  315. =item B<-s s, -s small>
  316. Run 100-iteration self-test on a set of 24 Mersenne exponents,
  317. ranging from 173431 to 1245877.
  318. This will take around 10 minutes on a fast (pre-2010) CPU.
  319. =item B<-s m, -s medium>
  320. Run 100-iteration self-test on a set of 24 Mersenne exponents,
  321. ranging from 1327099 to 9530803.
  322. This will take around an hour on a fast (pre-2010) CPU.
  323. =item B<-s l, -s large>
  324. Run 100-iteration self-test on a set of 24 Mersenne exponents,
  325. ranging from 10151971 to 72851621.
  326. This will take around an hour on a fast (pre-2010) CPU.
  327. =item B<-s h, -s huge>
  328. Run 100-iteration self-test on a set of 16 Mersenne exponents,
  329. ranging from 77597293 to 282508657.
  330. This will take a couple of hours on a fast (pre-2010) CPU.
  331. =item B<-s a, -s all>
  332. Run 100-iteration self-test on all Mersenne exponents
  333. and all FFT radix sets.
  334. This will take several hours on a fast (pre-2010) CPU.
  335. =item B<-fftlen> I<fft_length>
  336. This allows the user to specify the length of the fast-transform (FFT)
  337. used to effect the large-integer modular multiply
  338. which is at the heart of all such nonfactorial primality tests.
  339. The length unit here is in terms of the number of double-precision
  340. machine words used in the multiword-integer encoding
  341. of the primality test residue
  342. which is both input and result of each of said multiplies.
  343. Because mlucas is intended for testing numbers with many millions of bits,
  344. we generally speak of these FFT lengths in terms of kilodoubles
  345. (= 2 ^ 10 or 1024 doubles).
  346. If I<fft_length> is one of the available FFT lengths (in kilodoubles),
  347. run all available FFT radices available at that length,
  348. unless the I<-radset> flag is also invoked (see below for details).
  349. If I<-fftlen> is invoked with either the I<-m> or I<-f> flag,
  350. the self-tests will perform the first 100 iterations
  351. of a Lucas-Lehmer test (I<-m>) or Pe'pin test (I<-f>)
  352. on the user-specified Mersenne or Fermat number.
  353. If no user-set exponent is invoked,
  354. do 100 Lucas-Lehmer test iterations using
  355. the default self-test Mersenne or Fermat exponent for that FFT length.
  356. The program uses this to find the optimal radix set for a given FFT length
  357. on your hardware.
  358. =item B<-iters> B<100> | B<1000> | B<10000>
  359. Do I<100>, I<1000> or I<10000> self-test iterations of the type determined
  360. by the modulus-related options
  361. (I<-s> / I<-m> = Lucas-Lehmer test iterations with initial seed 4,
  362. I<-f> = Pe'pin test squarings with initial seed 3).
  363. Default is I<100> iterations.
  364. =item B<-radset> I<radix_set>
  365. Specify index of a set of complex FFT radices to use,
  366. based on the big selection table in the function B<get_fft_radices>().
  367. This requires a supported value of I<-fftlen> to be specified,
  368. meaning (for an FFT length supported by the program)
  369. an index B<0>, B<1>, B<2>, ... and so on.
  370. B<0> is always a valid radix set index;
  371. how high one can go in the enumeration depends on the FFT length.
  372. As soon as the user tries an index out of range of the current FFT length,
  373. the program will error-exit with an informational message to that effect,
  374. which also notes the maximum allowable radix set index for that FFT length.
  375. =item B<-nthread> I<threads>
  376. For multithread-enabled (default) build,
  377. perform the test in parallel mode with this many threads.
  378. =item B<-m> I<exponent>
  379. Perform a Lucas-Lehmer primality test of the Mersenne number
  380. M(I<exponent>) = 2 ^ I<exponent> - 1,
  381. where I<exponent> must be an odd prime.
  382. If I<-iters> is also invoked, this indicates a timing test.
  383. This requires suitable added arguments
  384. (I<-fftlen> and, optionally, I<-radset>) to be supplied.
  385. If the I<-fftlen> option (and optionally I<-radset>) is also invoked
  386. but I<-iters> is not,
  387. the program first checks
  388. the first line of the F<$MLUCAS_PATH/worktodo.ini> file to see
  389. if the assignment specified there is a Lucas-Lehmer test
  390. with the same exponent as specified via the I<-m> argument.
  391. If so, the I<-fftlen> argument is treated as a user override
  392. of the default FFT length for the exponent.
  393. If I<-radset> is also invoked, this is similarly treated as
  394. a user-specified radix set for the user-set FFT length;
  395. otherwise the program will use the F<$MLUCAS_PATH/mlucas.cfg> file
  396. to select the radix set to be used for the user-forced FFT length.
  397. If the F<$MLUCAS_PATH/worktodo.ini> file entry
  398. does not match the I<-m> value,
  399. a set of timing self-tests is run on the user-specified Mersenne number
  400. using all sets of FFT radices available at the specified FFT length.
  401. If the I<-fftlen> option is not invoked,
  402. the tests use all sets of FFT radices
  403. available at that exponent's default FFT length.
  404. Use this to find the optimal radix set
  405. for a single given Mersenne exponent on your hardware,
  406. similarly to the I<-fftlen> option.
  407. Perform 100 iterations, or as many as specified via the I<-iters> flag.
  408. =item B<-f> I<exponent>
  409. Perform a base-3 Pe'pin test on the Fermat number
  410. F(I<exponent>) = 2 ^ (2 ^ I<exponent>) + 1.
  411. If desired this can be invoked together with the I<-fftlen> option
  412. as for the Mersenne-number self-tests (see above notes on the I<-m> flag;
  413. note that not all FFT lengths supported for I<-m> are available for I<-f>:
  414. I<-m> permits FFT lengths of form I<odd> * 2 ^ n
  415. with I<odd> = any of B<1>, B<3>, B<5>, B<7>, B<9>, B<11>, B<13>, B<15>;
  416. I<-f> allows odd = B<1>, B<7>, B<15> and B<63>)
  417. Optimal radix sets and timings
  418. are written to the F<$MLUCAS_PATH/fermat.cfg> file.
  419. Perform 100 iterations, or as many as specified via the I<-iters> flag.
  420. =back
  421. =head1 EXIT STATUS
  422. _INDENT_BLOCK(
  423. [+The list of exit status values is limited.
  424. It is not possible to determine the cause of failure
  425. from the exit status value alone.
  426. However, B<mlucas> make use of I<stderr> to print error messages
  427. as well as saving them to the F<$MLUCAS_PATH/*.stat> file,
  428. where I<*> is in the form+],
  429. [+pI<exponent>+])
  430. _INDENT_BLOCK(
  431. [+for Mersenne number 2 ^ I<exponent> - 1 or+],
  432. [+fI<exponent>+])
  433. for Fermat number 2 ^ (2 ^ I<exponent>) + 1.
  434. (see B<FILES> section for details).
  435. =over 7
  436. =item B<0>
  437. Exit successfully.
  438. =item B<1>
  439. _START_NO_BLANK_LINES
  440. Assertion failure.
  441. Cannot determine the number of CPUs.
  442. Unknown fetal error.
  443. Radix set index not available for given FFT length.
  444. _END_NO_BLANK_LINES
  445. =item B<255>
  446. _START_NO_BLANK_LINES
  447. B<thread_policy_set>() failure.
  448. B<malloc>(3), B<calloc>(3) or B<realloc>(3) failure.
  449. B<pthread_create>(3) or B<pthread_join>(3) failure.
  450. _END_NO_BLANK_LINES
  451. =back
  452. =head1 ENVIRONMENT
  453. B<mlucas> honors the following environment variables, if they exist:
  454. =over 7
  455. =item B<MLUCAS_PATH>
  456. The path to read B<mlucas> configuration files
  457. and to write B<mlucas> generated files (see B<FILES> section for details).
  458. B<MLUCAS_PATH> must end with a slash (e.g., I</home/foolish/bar/>.
  459. If B<MLUCAS_PATH> is not set,
  460. then B<MLUCAS_PATH> defaults to I<$HOME/.mlucas.d/>,
  461. where the environmental variable I<$HOME> will be expanded
  462. in the environment where B<mlucas> is invoked.
  463. B<mlucas> will attept to make the directory with parents
  464. pointed by B<MLUCAS_PATH> using the B<mkdir>(1) command.
  465. The effect is similar to executing I<mkdir -p $MLUCAS_PATH> in the shell
  466. provided that the I<-p> flag is honored.
  467. =back
  468. =head1 FILES
  469. This section details B<mlucas> configuration files
  470. and B<mlucas> generated files.
  471. As noted in the B<ENVIRONMENT> section,
  472. B<$MLUCAS_PATH> defaults to I<$HOME/mlucas.d/> but this can be
  473. overridden at run-time by setting the B<MLUCAS_PATH> environment variable.
  474. =over 7
  475. =item B<$MLUCAS_PATH/*.stat>
  476. _INDENT_BLOCK(
  477. [+The filename-prefix wildcard I<*>
  478. is as described in the EXIT STATUS section;
  479. for the primality test of the Mersenne number 2 ^ I<exponent> - 1
  480. it is of the form+],
  481. [+pI<exponent>+])
  482. _INDENT_BLOCK(
  483. [+All important events, per-10000-iteration residues
  484. (or per-100000-iteration if more than 4 threads are used for the test)
  485. and the final residue during Lucas-Lehmer test of I<exponent>
  486. are recorded in this file.
  487. It can be seen as an I<exponent>-specific detailed
  488. F<$MLUCAS_PATH/results.txt>
  489. (see F<$MLUCAS_PATH/results.txt> below for details).
  490. This file is useful for debugging purposes.
  491. Its format looks like:+],
  492. [+B<INFO>: I<event>
  493. ...
  494. B<M>I<exponent>: B<using FFT length> I<fft_length>B<K>
  495. B<=> I<fft_length * 1024> B<8-byte floats.>
  496. Bz<this gives an average> I<bits> B<bits per digit>
  497. B<Using complex FFT radices> I<radix_set>
  498. (product of all elements of radix_set = fft_length / 2)
  499. ...
  500. B<[>I<date_and_time>B<]>
  501. B<M>I<exponent>
  502. B<Iter#> B<=> I<iterations>
  503. B<clocks> B<=> I<time_taken_per_10000_iterations>
  504. B<[>I< time_taken_per_iteration> B<sec/iter>B<]>
  505. B<Res64:> I<residue>B<.>
  506. B<AvgMaxErr> B<=> I<roe_avg>B<.>
  507. B<MaxErr> B<=> I<roe_max>
  508. ...
  509. [B<Restarting> B<M>I<exponent> B<at iteration> B<=> I<iteration>B<.>
  510. B<Res64:> I<residue>
  511. B<M>I<exponent>: B<using FFT length> I<fft_length>B<K>
  512. B<=> I<fft_length * 1024> B<8-byte floats.>
  513. B<this gives an average> I<bits> B<bits per digit>
  514. B<Using complex FFT radices> I<radix_set>]
  515. (product of all elements of radix_set = fft_length / 2)
  516. ...
  517. B<M>I<exponent> B<is not prime.>
  518. B<Res64:> I<residue>B<.>
  519. B<Program: E17.1>
  520. B<M>I<exponent> B<mod 2^36> B<=> I<remainder_1>
  521. B<M>I<exponent> B<mod 2^35 - 1> B<=> I<remainder_2>
  522. B<M>I<exponent> B<mod 2^36 - 1> B<=> I<remainder_3>+])
  523. =item B<$MLUCAS_PATH/fermat.cfg>
  524. The format of this file is exactly the same as
  525. the format of F<$MLUCAS_PATH/mlucas.cfg>
  526. (see F<$MLUCAS_PATH/mlucas.cfg> below for details).
  527. =item B<$MLUCAS_PATH/mlucas.cfg>
  528. _INDENT_BLOCK(
  529. [+This file stores the radix set with best timing for each FFT length.
  530. Its format looks like:+],
  531. [+B<17.1>
  532. I<fft_length> B<msec/iter> B<=> I<timing>
  533. B<ROE[avg,max]> B<=> B<[>I<roe_avg>B<,> I<roe_max>B<]>
  534. B<radices> B<=> I<radix_set>
  535. ...+])
  536. _END_NO_BLANK_LINES
  537. Normally, the I<timing> entry for each line should be monotonic
  538. from above to below since larger FFT length should take longer to test.
  539. But it is OK for a given I<fft_length> to have a higher I<timing> than
  540. the one after it since B<mlucas> checks the timings listed in this file
  541. for all FFT lengths >= the default FFT length for the number being tested,
  542. and uses the FFT length having the smallest listed timing.
  543. However, if you notice that this file has any entries such that
  544. a given I<fft_length> has a timing 5% or more greater than the next-larger
  545. FFT length, or higher timing than two or more larger FFT lengths,
  546. please contact the author (see B<BUGS> section for details).
  547. =item B<$MLUCAS_PATH/nthreads.ini>
  548. This file sets the number of threads used.
  549. It should only contain a positive integer
  550. since the content of this file is read by
  551. B<sscanf(>I<in_line>, I<"%d">B<,> I<&NTHREADS>B<);>
  552. where the variable I<in_line>
  553. contains the content of the F<$MLUCAS_PATH/nthreads.ini> file.
  554. If this file is not present,
  555. B<mlucas> will use as many threads as the number of CPUs detected.
  556. The number of threads used set by this file
  557. can be overridden by setting I<-nthread> flag at run-time.
  558. This file is for those who want to set the number of threads
  559. to be greater or less than the number of CPUs detected.
  560. This can be useful since some users reported up to 10% performance gain
  561. when using more threads than the number of CPUs detected.
  562. =item B<$MLUCAS_PATH/results.txt>
  563. _INDENT_BLOCK(
  564. [+Important events which occurred during Lucas-Lehmer test
  565. and the final residue obtained are recorded in this file.
  566. This file summarizes important information
  567. in all F<$MLUCAS_PATH/*.stat> files
  568. (see F<$MLUCAS_PATH/*.stat> above for details) into a single file.
  569. This file (more specifically, any results
  570. which were added to it since your last checkin from)
  571. should be submitted to the PrimeNet server (see subsection
  572. B<Great Internet Mersenne Prime Search> in section B<NOTES> for details)
  573. since the Lucas-Lehmer test exponents are obtained from the PrimeNet server
  574. (see F<$MLUCAS_PATH/worktodo.ini> below for details).
  575. Its format looks like:+],
  576. [+B<INFO:> I<event>
  577. ...
  578. [B<M>I<exponent> B<Roundoff warning on iteration> I<iteration>B<,>
  579. B<maxerr> B<=> I<roundoff_error>
  580. B< Retrying iteration interval to see if roundoff error is reproducible.>
  581. [B<Retry of iteration interval with fatal roundoff error was successful.>]]
  582. ...
  583. B<M>I<exponent>B< is not prime.>
  584. B<Res64:> I<residue>B<.>
  585. B<Program: E17.1>
  586. B<M>I<exponent> B<mod 2^36> B<=> I<remainder_1>
  587. B<M>I<exponent> B<mod 2^35 - 1> B<=> I<remainder_2>
  588. B<M>I<exponent> B<mod 2^36 - 1> B<=> I<remainder_3>
  589. ...+])
  590. =item B<$MLUCAS_PATH/worktodo.ini>
  591. _INDENT_BLOCK(
  592. [+This file contains Lucas-Lehmer test assignments to be tested.
  593. Its format looks like:+],
  594. [+I<assignment>B<=>I<ID>B<,>I<exponent>B<,>I<trial
  595. factored up to>B<,>I<has P-1 factoring>
  596. ...+])
  597. The I<assignment> field contains B<Test>
  598. if the assignment is a first-time Lucas-Lehmer test,
  599. or B<DoubleCheck> if the assignment is a double-check Lucas-Lehmer test.
  600. (The program handles both cases the same way.)
  601. _START_NO_BLANK_LINES
  602. I<ID> is a unique 32-digit hex number.
  603. I<exponent> specifies the Mersenne number
  604. (of the form 2 ^ I<exponent> - 1) to be tested.
  605. I<trial factored up to> is the number of bit this Mersenne number
  606. has been trial factored up to without finding a factor.
  607. I<has P-1 factoring> B<=> B<0> if no prior P-1 factoring has been done,
  608. B<=> B<1> if P-1 factoring (without finding a factor) has been done.
  609. Since mlucas currently has no P-1 factoring capability
  610. it simply discards these data,
  611. but users should prefer B<=> B<1> here
  612. since such an assignment is slightly more likely (5-10%) to yield a prime.
  613. _END_NO_BLANK_LINES
  614. To do Lucas-Lehmer test,
  615. you should reserve exponents from the PrimeNet server
  616. and copy lines in the above format into the
  617. F<$MLUCAS_PATH/worktodo.ini> file (see subsection
  618. B<Great Internet Mersenne Prime Search> in section B<NOTES> for details).
  619. You may need to create the F<$MLUCAS_PATH/worktodo.ini> file
  620. if it does not exist.
  621. =item B<Save files in $MLUCAS_PATH>
  622. All files matching the following extended regular expression
  623. (see B<regex>(7) for details)
  624. in I<$MLUCAS_PATH> directory are save files:
  625. ^[fpq][0123456789]+([.][0123456789]+0M)?$
  626. For both of the supported test types,
  627. duplicate pairs of savefiles are written at each checkpoint,
  628. to guard against corruption of the on-disk savefiles.
  629. Lucas-Lehmer test savefile-pair names start with <p> and <q>, respectively,
  630. while Pe'pin test savefile-pair names start with <f> and <q>, respectively.
  631. They should not be modified but backups may be made by the user.
  632. By default, the program will save a persistent backup of the primary
  633. (B<p> or B<f>) save file every 10 millionth iteration,
  634. for examples upon completion of the Lucas-Lehmer test of M57885161
  635. the user will find the following exponent-associated files
  636. in the I<$MLUCAS_PATH> directory:
  637. p57885161.stat
  638. p57885161.10M
  639. p57885161.20M
  640. p57885161.30M
  641. p57885161.40M
  642. p57885161.50M
  643. =back
  644. =head1 NOTES
  645. =head2 Great Internet Mersenne Prime Search
  646. This subsection needs to be compeleted...
  647. =head1 BUGS
  648. The argument parser is buggy.
  649. The relative position of arguments is relevant to B<mlucas>,
  650. the order of arguments in B<SYNOPSIS>
  651. should be followed to avoid confusing the parser.
  652. Only I<100>, I<1000> and I<10000> are supported for I<-iters> flag.
  653. However, the parser will not reject unsupported arguments.
  654. Using unsupported arguments for I<-iters> flag
  655. may trigger strange behaviour.
  656. Sometimes there is more than one applicable exit status values
  657. (see B<EXIT STATUS> section for details).
  658. In such case, there is no guarantee which will be returned.
  659. For example,
  660. if B<malloc>(3) failure triggers an assertion failure.
  661. It is possible that B<mlucas> returns I<1>
  662. instead of I<255> as exit status value.
  663. For problems regarding the program B<mlucas>,
  664. please contact the author Ernst W. Mayer <ewmayer AT aol DOT com>.
  665. For installation and documentation related problems
  666. regarding the Debian package and this manual,
  667. please use B<reportbug>(1) to
  668. contact Alex Vong <alexvong1995 AT protonmail DOT com>.
  669. =head1 EXAMPLE
  670. There are 3 common cases where you will want to run this program.
  671. Normally, you should do a spot-check first to quick-test your build,
  672. followed by the self-test range for `medium' exponents.
  673. Finally, full-blown Lucas-Lehmer testing
  674. which is the main purpose of this program.
  675. =over 7
  676. =item B<mlucas -fftlen 192 -iters 100 -radset 0 -nthread 2>
  677. Perform spot-check to see if B<mlucas> works
  678. and fill-in a bug report if it does not.
  679. The spot check should produce residues
  680. matching the internal tabulated ones.
  681. If the residues does not match,
  682. B<mlucas> should emit a verbose error message.
  683. =item B<mlucas -s m>
  684. Perform timing self-test for `medium' exponents
  685. to tune code parameters for your platform.
  686. Ordinary users are recommended to do this self-test only.
  687. For best results,
  688. run any self-tests under zero- or constant-load conditions.
  689. The self-tests append
  690. (or create if F<$MLUCAS_PATH/mlucas.cfg> does not exist)
  691. new timing data to the F<$MLUCAS_PATH/mlucas.cfg>
  692. (see B<FILES> section for details).
  693. Before doing any self-tests,
  694. you should first check if there is an existing
  695. F<$MLUCAS_PATH/mlucas.cfg> file
  696. and either delete it or do a backup-via-rename to
  697. to prevent mixing old and new timing data.
  698. F<$MLUCAS_PATH/mlucas.cfg> normally locates at
  699. I<$HOME/.mlucas.d/> directory
  700. although this can be overridden at run-time
  701. by settingthe B<MLUCAS_PATH> environment variable
  702. (see B<ENVIRONMENT> section for details).
  703. =item B<mlucas &>
  704. _INDENT_BLOCK(
  705. [+Perform Lucas-Lehmer test on Mersenne numbers
  706. by running B<mlucas> as a background job
  707. (see B<JOB CONTROL> section in B<bash>(1)
  708. and B<Builtins> subsection in B<dash>(1) for details).
  709. To perform Lucas-Lehmer test on a given Mersenne number,
  710. you must first perform a self-test
  711. for `medium' exponents mentioned above,
  712. or if you only desire to test a single selected Mersenne number,
  713. a self-test for the default FFT length for that number:+],
  714. [+mlucas -m I<exponent> -iters 100+])
  715. In the case of multi-exponent "production testing",
  716. you should reserve exponent from the PrimeNet server
  717. and add them into F<$MLUCAS_PATH/worktodo.ini>
  718. (see the subsection B<Great Internet Mersenne Prime Search>
  719. within the section B<NOTES> and B<FILES> section for details).
  720. =back
  721. =head2 Advanced Usage Tips
  722. To start B<mlucas> in terminal 1,
  723. add the following lines to your login shell initialization file,
  724. such as I<$HOME/.profile>
  725. (see B<INVOCATION> section in B<bash>(1)
  726. and B<Invocation> subsection B<dash>(1) for details).
  727. # Test if we are in tty1
  728. if test `tty` = '/dev/tty1'
  729. then
  730. # turn on job control
  731. set -m
  732. # start mlucas
  733. nice mlucas > /dev/null 2>&1 &
  734. fi
  735. =head1 SEE ALSO
  736. B<bash>(1), B<dash>(1), B<reportbug>(1)
  737. L<https://www.mersenneforum.org/mayer/README.html>,
  738. F</usr/share/doc/mlucas/html/README.html>
  739. B<mlucas> is documented fully by F<Mlucas README>,
  740. available both online and offline as shown above.
  741. L<F<Great Internet Mersenne Prime Search>|https://www.mersenne.org/>
  742. L<F<Mersenne Forum>|https://www.mersenneforum.org/>
  743. _JOIN([+L<F<Chris Caldwell's web page on Mersenne numbers>|+],
  744. [+https://primes.utm.edu/mersenne/index.html>+])
  745. _JOIN([+L<F<Richard Crandall and Barry Fagin, +],
  746. [+Discrete Weighted Transforms and Large-Integer Arithmetic.>|+],
  747. [+https://pdfs.semanticscholar.org/07c0/+],
  748. [+fae878fe9d6a117de08282802fb7b892bf2d.pdf>+])
  749. _JOIN([+L<F<Richard E. Crandall, Ernst W. Mayer, +],
  750. [+and Jason S. Papadopoulos, +],
  751. [+The Twenty-Fourth Fermat Number is Composite.>|+],
  752. [+https://www.mersenneforum.org/mayer/F24.pdf>+])
  753. =cut