Secifically, in `~/nim-0.18.0/compiler/vmdef.nim` set `MaxLoopIterations* =
1_000_000_000` (1 Billion)
then rebuild sysem: `./koch boot -d:release`
: No such file or directory
clang-6.0: error: linker command failed with exit code 1 (use -v to see
invocation)
Error: execution of an external program failed: 'clang -o
/home/jzakiya/nim/twinprimes_test4a
/home/jzakiya/nim/nimcache/twinprimes_test4a.o
/home/jzakiya/nim/nimcache
> So you DID inspect C code differences and also checked another compiler, but
> you still blame Nim, not gcc, for that time difference? Even to the point of
> calling it a security issue?
Excuse me @Udiknedormin, maybe you aren't fluent in English? I have not
_blamed_ Nim or gcc. I have asked
` is consistent
with any combination of kernel, and gcc or clang, on VB based systems for
64-bit Linux distros.
Here are the gists of the tested code:
The difference between the code is line 239 in `twins_sieve`.
`twinprimes_test.nim`
[https://gist.github.com/jzakiya
I looked at the generated C code for both versions. They have exactly the same
structure (reference names are different) and exactly the same number of total
lines-of-code (loc).
Here's the C code generated for the different Nim versions snippets.
while (1) {
if
Oh by the way, the compiled code for `a[k] = 1` was 95 bytes bigger, using gcc
4.9.2
Hey @dataman, thanks for info on `intsets`
FYI, `intsets` has a problem compiling the `card|len` method on `0.17.2` but
not on `0.18.0`. Also, while `intsets` indeed will take the correct number of
set members, it's at least 3x slower than using `sets`, across the board. So
for this case,
Hey @dataman can you show how to use this to replace using `sets`.
Below is a code prototype using `sets`, what would be the equivalent with
`IntSet`.
proc example(a, b, c) =
var aset: set[uint16]
while n < max
aset = {}
So @miran and @Stefan_Salewski I used a `set` to replace a `seq`, and it is
pretty fast for this case, as I don't have to worry about `deduplicating` the
array, which was vey slow as the array size increased. `Sets` did create a
much better logical inplace replacement for this case. The
Hey SolitudeSF thanks for the tip.
Hey Miran, this is `Open Source Software` so you can modify it as much as you
want. I think all you have to do is comment out the line that puts out the
enter number message to get what you want.
But as I said in the initial post, people should feel free to
updated version 2018/04/07.
[https://gist.github.com/jzakiya/6c7e1868bd749a6b1add62e3e3b2341e](https://gist.github.com/jzakiya/6c7e1868bd749a6b1add62e3e3b2341e)
I was hoping a few people would be curious enough to run the code and post (or
send me via email) their results on their systems. If you
than `version
2018/04/03`.
[https://gist.github.com/jzakiya/6c7e1868bd749a6b1add62e3e3b2341e](https://gist.github.com/jzakiya/6c7e1868bd749a6b1add62e3e3b2341e)
Biggest change was compiling source in VB (Virtual Box) image of base OS
distros which has `gcc 7.3.0`. Compiled source in it to create
I have this code where I'm setting all the bytes in `seg` to `0`.
for b in s_row..s_row+KB-1: seg[b] = 0
Can I do something like: `seg[a..b] = 0`
Then I have this code that counts all the `0` in `seg`
for k in 0..Kn-1: (if seg[s_row+k] == 0: sum += 1)
Is
Hey @miran, thanks. I'll look at your code when I get some time today.
It would be really helpful if people could run the code on different (Intel
cpus, AMD, ARM, etc) platforms with different number of threads, cache size,
etc, and if possible a|b it against `primesieve` on their systems, and
GC. Also, the
information you provided on using OpenMP is way over my head. Do you feel like
trying to do an OpenMP implementation in Nim?
Anyway, here's the updated gist file, and source code:
[https://gist.github.com/jzakiya/6c7e1868bd749a6b1add62e3e3b2341e](https://gist.github.com/jzakiya
ake the code faster. Whoever
knows how to do that, go for it!
Below is the code and its gist (it's 317 loc, with ~60 separate loc of
comments, compare that to `primesieve`'s code size):
[https://gist.github.com/jzakiya/6c7e1868bd749a6b1add62e3e3b2341e](https://gist.github.com/jzak
OK, so core Nim doesn't have an arbitrary precision math capability. Is it
something planned for in the roadmap to 1.0?
I have Ruby/Crystal code that uses arbitrary precision integer numbers (really
BIG numbers). Looking at Nim's math libraries they don't appear to be arbitrary
precision.
> @jzakiya: The limit is at one billion now.
+1!!
OK, I set `MaxLoopIterations* = 1_000_000_000` (1 Billion) in
`~/nim-0.18.0/compiler/vmdef.nim` and rebuilt doing `./koch boot -d:release`
and was able to compile P17.
I think this value is way more reasonable, because as stated previously, on
modern machines (or really any system with
Here's a gist of the code.
[https://gist.github.com/jzakiya/b096b92c181ed343dab8c130c88f1d39](https://gist.github.com/jzakiya/b096b92c181ed343dab8c130c88f1d39)
Back in the day I had that book, when I wore a younger man's clothes, and also
**Applied Cryptography**. I wonder what happened to them
[https://www.goodreads.com/book/show/351301.Applied_Cryptography](https://www.goodreads.com/book/show/351301.Applied_Cryptography)
On the Ruby issue tracker replacing Euclid's gcd algorithm with Steins (binary)
algorithm came up.
[https://bugs.ruby-lang.org/issues/13503](https://bugs.ruby-lang.org/issues/13503)
Here's the wikipedia article on it.
Compiling again for P17, with 0.18.0 and 0.17.2, the error messages point to
`gcd` function in both cases:
# 0.18.0 error message
generating parameters for P17
stack trace: (most recent call last)
twinprimes_ssozp17par5d3.nim(87)
twinprimes_ssozp17par5d3.nim(65)
One (last?) trick to reduce the number of iterations.
I changed this:
var residues: seq[int] = @[]
var pc = 1
while pc < modpg: (pc += 2; if gcd(modpg, pc) == 1: residues.add(pc))
let rescnt = residues.len
to this:
var residues:
OK, **I finally got it to compile with the original iteration count** , but
man, did I have to jump through hoops to do it.
To reduce the number of loops, instead of doing `brute force trial-and-error`
to test each residue against the others to find its inverse, I found the code
here
I started changing the `MaxLoopIterations* = 1500_000 # max iterations of all
loops` line in `compiler/vmdef.nim` in increments of 1 million, until it was
20M, recompiling after each change, and still got error. Then I went up in 100M
increments until 1 trillion, and still got error.
Do I need
I could use Ruby to create all the parameters and dump them into a file too,
which would be easier.
**I Don 't want to jump through extra HOOPs because the Nim compiler is
deficient!!**
I don't have to do this in C++.
The compiler should work for the human, not the other way around.
I raised this issue regarding 0.17.2 but it still persists in 0.18.0.
I want to generate some system constants at compile time.
I need to generate some constant arrays of numbers for a (selectable) prime
generator (PG).
When the array size gets past some (?) value the compiler quits with this
Thanks! Where in the docs are these methods?
I've looked through the docs but haven't found the answer to this.
I have an array of integers (prime numbers) and I want to: 1) determine if some
number is included in the array and 2) return the index value of the number in
the array.
In Ruby/Crystal I can do the following. What are the
Stafan_Salewski, yes, thanks for reminding about that again.
The twinprimes code is old (almost a year, using 0.17.x), when I was just
getting seriously into converting C++ code into Nim. Using the original
construct for that loop worked, because I always compiled with `gc` on. Then I
started
led binary went from ~ 112K bytes to ~85K bytes. So I guess I'm
sticking with 0.17.2 for awhile.
Below are the source files:
**twinprimes_ssozp5a2.nim** \- sieve as single process
[https://gist.github.com/jzakiya/8f7f4f0dc8c9efd70870a1b3449c60cc](https://gist.github.com/jzak
So I'm compiling some new code in 0.18.0.
This code code compiles and runs correctly as one process with no problems.
proc segsieve(Kn: int) = # for Kn resgroups|bytes in segment
...
for indx in 0..5: # for nextp row indexes,
var r =
Ruby is a fully OOP language but doesn't have multiple inheritance either.
Every class is open though (you can add/change methods in them), and you can
create the equivalence of multiple inheritance by using **modules** and
**mixins** where you **include** them in **classes** to extend them.
Looking thru the Ruby Weekly newsletter
[https://rubyweekly.com](https://rubyweekly.com)/ there was these:
**Top five reasons for Rubyist to use Crystal**
It appears most of the comments made to my original post are not addressing the
issue I raised, which is increasing the exposure of Nim. In fact, some
commentators seem to be suggesting they don't see a high need to increase Nim's
exposure. I think this is a very insular view and attitude of
Having access to various Ruby article feeder sites I recently came across this
[https://hacklines.com](https://hacklines.com)/
[https://hacklines.com/en?ucc=rubyflow=Ruby%2CRails%2CSinatra](https://hacklines.com/en?ucc=rubyflow=Ruby%2CRails%2CSinatra)
which is multilingual. It lists articles
I have some working code and **I'm experimenting** with using pointers and
slices to achieve the same results.
Here's what I conceptually want to do.
parallel:
for bytn in 0..bprg-1:
.
var seg_r: seq[uint8] = seg[bytn*Ks..byt*Ks+Ks-1]
Matz's (Ruby's creator) Keynote Address at RubyConf 2017 provides very good
guidance for language (any project really) development. It's really worth the
TL;DR time.
This code works as desired in parallel. Thanks for the instructions.
proc column_load(prime, j, k, r: int) {.gcsafe.} =
{.gcsafe.}:
for ri in residues: # for each prime|residue pair
let prod = r * ri # compute res
I'm trying to understand what you are suggesting with your response, especially
because what I ultimately want to do in this instance I will want to do with
other bigger generators.
What I assume you are saying is `helper` is some Nim source program that will
produce the output that
The code below works, but when I try to run it using P17 the compiler throws an
error about the `gcd` proc. Using P17 causes `gcd` to be called on the order of
250,000 times, as `modpg = 510510`
Here's the code.
# Create constant parameters for chosen PG at compile time
proc
When Nim starts having conferences it would be nice for them to feel like those
for Ruby.
[https://avdi.codes/rubyconf-2017/?utm_source=rubyweekly_medium=email](https://avdi.codes/rubyconf-2017/?utm_source=rubyweekly_medium=email)
@dom96 if you want people to voluntarily, out of their concern for the project,
and goodness of their own `heart`, contribute to Nim, first you need to `check
your attitude`, and learn how not to chase people away.
**Araq you need to chill out!**
I took the time to document for you unexpected, deficient, and incorrect
behavior of your documentation and you are not even `humble` enough to thank me
for it.
So why should I bother to keep using your `work in progress` language that you
can't even take
Upon thinking about it, I think the case for `echo num.formatFloat(ffDecimial,
0)` is incorrect, and should be changed to be consistent with the intent of the
function.
The `0` option should produce a value (currently it would be `rounded`) with no
digits displayed.
`echo
@bluenote, also for `formatFloat`, it should also explain that it seems to
using `rounding` of the digits its displays and not truncation. If a user wants
to just truncate the displayed digits what function does that, or can this one
perform that too. It may be an option to include into this
@bluenote I could kiss you!
Now just do that for at least everything in that module and that will be a
significant start, and benefit to all of us users.
Hey guys, stop being defensive. If I didn't think Nim is a worthy project, and
has great potential, I would have never bothered to take the time to tell you
how to improve your project, and it would be in your interest to take comments
as mine as `positive critical feedback`.
As further
Actually, `the only limits of what you can provide in documentation are self
imposed`.
`Writing documentation is an attitude!` Either you care about doing it (to
benefit/help users) or you don't.
Nim has to compete against lots of other languages, and like cars, smartphones,
etc, having the
Thanks a whole lot!
The Docs really need to get better by showing clear examples like this for just
about everything. It took way too long for me to search and not even find this,
and had to resort to asking how to do this here. I also agree the semantics for
doing this has to become a lot
let num = 10.123456789
echo( formatFloat(num) )
Could I get a little help here to make this work.
let num = 10
const x = 9
echo(num + x)
let num = 10.int
const x = 9
echo(num + x)
let num = 10.uint
const x = 9
echo(num + x)
That seems to be the case because you have to explicitly cast `let` s (or the
compiler assumes a default cast).
I compute a floating point number `x`. How do I use `echo|write.stdout` to
output it with just 4 decimal digits showing?
I don't know if this is currently possible, but it would be nice to have.
It seems I could theoretically speed the execution of this code.
proc segsieve(Kmax: uint, KB: int) = # for Kn resgroups|bytes in segment
let Ks = KB# make default seg size
What I was trying to get at is how to make the generated constant values behave
like coding specific numerical numbers.
Apparent for numerical constants, when you do this: `const modpg = 2310` the
compiler will convert it to whatever is required to make math operations work
(at least it did so
Hey thanks for the help!
Here's what I had to do to get it to compile/work fully (using Nim 0.17.2).
proc genPGparameters(prime: int): (int, int, int, seq[int]) =
echo("generating parameters for P", prime)
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23]
var
I do `import math` to get `gcd` in my program, that's why you got that error.
I still can't get the output from `getPGparameters` assigned to constants of
the same names, to be used later in the program. I thought you could do
assignments like:
const (a, b, c) = tuple(x, y, z)
I want to execute the code below at compile time to initialize the global
variables shown - modpg, rescnt, residues, ep.
proc genPGparameters(prime: int): tuple =
echo("generating parameters for P", prime)
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23]
var modpg = 1
Yes, that is what I meant, the `threads` that are available per system (all cpu
cores), which you can see using commands such as `lscpu` or `htop`.
Thanks, will do.
Yes, that returns the number of available threads, though its doc says
processors/cores.
How do you get the number of available system threads inside a Nim proggram?
OK. Could you provide the url for doing it.
The Unix `time` command
[https://en.wikipedia.org/wiki/Time_%28Unix%29](https://en.wikipedia.org/wiki/Time_%28Unix%29)
[https://www.lifewire.com/command-return-time-command-4054237](https://www.lifewire.com/command-return-time-command-4054237)
returns three (3) variants: `real`, `usr`, `sys`.
Yes, that did it.
This is a good use case example to distinguish in `time` docs between the use
of `cpuTime()` and `epochTime()`. The given example for `cpuTime()` assumes
single threaded use and not the effect of multi processor/threads use.
The `cnt +=` operation in parallel is ripe for creating a `reduction` like
option for Nim that's in `OpenMP`.
[https://stackoverflow.com/questions/13290245/reduction-with-openmp#13290673](https://stackoverflow.com/questions/13290245/reduction-with-openmp#13290673)
OK, I had to clean it up a little to make it work, but here is the code that
gets it to compile.
var cnt: array[rescnt, uint]
parallel:
for i in 0..rescnt-1:
cnt[i] = spawn segcount(i*KB, Kn)
sync()
for i in 0..rescnt-1:
primecnt +=
The error messages keep saying the issue is a mismatch with FlowVar[T]. In
Chapter 6 of **Nim in Action** here is what it says they are.
`FlowVar[T] can be thought of as a container similar to the Future[T] type,
which you used in chapter 3. At first, the container has nothing inside it.
When
In the previous snippet I forgot the `spawn`. The code below compiles, but is
slower.
var cnt = 0# count for the primes, the '1' bytes
for i in 0..
After reading the **Nim in Action** book I got it to compile by placing a `^`
before `spawn`, but it makes the program slower. The problem has to do with
`segcount` returning a `FlowVar[T]` mismatch. And when I use `parallel:` it
won't compile, and shows even more errors. Doing more research.
I've done it both with/out `parallel:` as shown below, but get the same
compiler output.
parallel:
var cnt = 0 # count for the segment primes '1'
bytes
for i in 0..
OK, I've racked my brain enough and need help. Using 0.17.2 on Linux, I have
this `proc` below.
proc segcount(row, Kn: int): int =
var cnt = 0
for k in 0..
>From looking at the xxx.c file in the `nimcache` directory I ultimately
>figured out which source code version the executable was created from.
The intent of the post was to provide information **from a user's perspective**
with real world code on how to make Nim better _from the user's perspective_.
Why did you make the assumption I didn't compile my code with `--d:release`? I
did. What I hoped you appreciated was that using fixed
I want to be able to do true parallel processing of highly numerical
algorithms, and currently I don't know if Nim can do this, and if so, I can't
find many coding examples of more than rudimentary examples. So I was wondering
since Nim compiles to C/C++ whether it currently can work with
**1)** In **nextp_init** in the line below, **i** can start from eithre '0' or
'1'.
for i in 0|1..
Actually I'm not a C/C++ programmer, I'm (mostly now) a Ruby programmer who is
functional in C++, and haven't really done anything in C of any note.
I've been looking to see how to view the C/C++ that Nim is generating but I
don't know how to do that. Can you show me how to do that?
Remember,
I have identified a very subtle memory management error that took me weeks to
characterize.
I'm directly translating a working C++ program to Nim. The problem seems to be
that the Nim code erroneously addresses the **seg** array beyonds its bounds,
because the **k** values used to update the
ed, then just opened a terminal
and ran the timing tests.
[jzakiya@localhost nim]$ time ./ssozp5
Enter integer number: 1_000_000_000
segment has 262144 bytes and 262144 residues groups
prime candidates = 26665; resgroups = 3334
create nextp[8x3398] array
p
these times, running on a noisy system (multiple browsers, et al, open)
for the sequential version of SSoZ using P5 prime generator.
[jzakiya@jabari-pc nim]$ time ./ssozp
Enter integer number: 1_000_000_000
segment has 262144 bytes and 262144 residues groups
prime
ritten in Nim
[https://gist.github.com/jzakiya/94670e6144735eb0041919f633d6011c](https://gist.github.com/jzakiya/94670e6144735eb0041919f633d6011c)
**twinprimes_ssozp5.nim**
Find Twin Primes <= N, using sequential Segmented Sieve of Zakiya (SSoZ) with
P5 prime generator, written in Ni
The error was observed in the pdf version but doesn't exist in the ePub version.
Is there an errata page for the book on the website, or somewhere.
I found a few typos|errors in the book for correction, e.g. the data in Table
2.2 on page 27.
The ranges for uint[8|16|32] have a mistaken '0' on the end of the 'range'
numbers for those types.
That's what I assumed, when I got combo 2).
I assumed the pBook was the printed book, and didn't know the difference
between an eBook and pdf|ePub|kindle, so I made sure I got the pdf and ePub
versions, since I have various readers for them.
When I went to the Manning website it offered two combo deals.
1) $49.99 -- pBook + eBook + liveBook
2) $39.99 -- pdf + ePub + kindle + liveBook
Using the 50% off discount code gave: 1) $49.99 - $25.00 = $24.99; 2) $39.99 -
$20.00 = $19.99
I assumed the pBook in combo 1) was for the print
As I stated, Nim was not installed via these distros, and was being installed
per the process given on Nim's website.
Putting in the suggested PATH did solve the problem though, so thanks.
$ export PATH=~/nim-0.17.0/bin:$PATH
However, this just highlights the inadequacies of
The problem with installing seems to have to do with executables not in correct
bins.
I can go through the install process off the website, and compile the
executables in the **nim-0.17.0** directory, created by untarring the tarball.
Notes about installation from source
ial implementation of SSoZ with P5 prime
generator.
[https://gist.github.com/jzakiya/94670e6144735eb0041919f633d6011c](https://gist.github.com/jzakiya/94670e6144735eb0041919f633d6011c)
**nthprime_ssozp5.nim**
Find nth primes, using sequential implementation of SSoZ with P5 prime
generator.
[ht
I mostly use the KDE Kate and Atom editors for code writing and notice they
don't seem to have Nim profiles for **.nim** files. Do you know editors that
do, and have editor profiles been something the devs have on their todo list?
Is there an available list of all the current Nim methods, functions, etc,
similar to what Ruby provides, as below?
[https://ruby-doc.org/core-2.4.1](https://ruby-doc.org/core-2.4.1)/
I cleaned up the code and added more commments. It should be much easier now to
uderstand what/why the code is doing after reading my paper.
Here is the gist location of the source code for this version.
[https://gist.github.com/jzakiya/94670e6144735eb0041919f633d6011c](https://gist.github.com
Compiling with **\--threadAnalysis:off** did allow the program to compile and
run with no segfaults, and it produces the correct results, but it's 2x slower
than the serial version.
In the code snippet, the **next**, **seg**, and **primes** arrays (seqs), and
the constant **rescnt** are global
Using Nim 0.17.
Afer reading the Nim manual on Parallel programming, and how to use **spawn**
and **parallel** I can't get the following code to compile.
proc residue_sieve(r: int, Kn: int) =
let row = r * pcnt# set address to ith row in next[]
let
this code is free subject to acknowledgment of copyright.
Copyright (c) 2017 Jabari Zakiya -- jzakiya at gmail dot com
Version Date: 2017/08/21
This code is provided under the terms of the
GNU General Public License Version 3, GPLv3, or greater.
License copy/terms are he
Whoops, sorry, forgot to run the executable (probably should go to bed now)
[jzakiya@jabari-pc nim]$ ./inputtest
Enter integer number: 34422
You inputed 34422 with type BiggestUInt
[jzakiya@jabari-pc nim]$
Made the same mistake on target program, but it works now
t
echo "You inputed ", val, " with type ", val.type.name
Here are the compile and runtime results
[jzakiya@jabari-pc nim]$ nim c --cc:clang --d:release inputtest.nim
Hint: used config file '/etc/nim.cfg' [Conf]
Hint: system [Processing]
Hint: i
These don't work.
When the program displays
Enter number value:
it should stay there until I type a number and hit and then proceed.
For both cases shown the program just falls through.
[jzakiya@jabari-pc nim]$ ./myprogram
Enter number value:
Error
1 - 100 of 107 matches
Mail list logo