mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2022-01-17, 21:16   #12
hunson
 
Feb 2020
Germany

2·52 Posts
Default

Thanks for looking into my code.


I was already writing a reply where I explained that I do not understand the problem and I could not figure it out when I decided to have a look if someone else answered after henryzz :)

I even had it running with the
Code:
primes = malloc(sizeof(int) * sieve_depth);
in 'debug' but not in 'release', something was very strange.



I corrected the corresponding lines and the code works! Thanks.

I tried to save some memory, so I used a char variable to store the information from the sieve. Worked out great for me...


Now I can try out my 'efficient' program to generate prime candidates
hunson is offline   Reply With Quote
Old 2022-01-17, 21:23   #13
bsquared
 
bsquared's Avatar
 
"Ben"
Feb 2007

3,617 Posts
Default

Speaking of efficiency, it is much better to flip the order of the loops. Exponentiation and the other operations on big numbers are a lot more expensive than division by a single limb, so do the loop over 'e' first. Then after you've computed each candidate 'n', loop over the primes and trial divide, breaking out if mod==0.

Last fiddled with by bsquared on 2022-01-17 at 21:24
bsquared is offline   Reply With Quote
Old 2022-01-18, 20:50   #14
hunson
 
Feb 2020
Germany

2×52 Posts
Default

Thanks for the bug finding! The program works as expected now.
@bsquared: I wrote the program with flipped for-loops in the beginning. Then I switched to see what the performance might be, encountered the bug and forgot to change it back :/


*now* I can use my efficient program (I actually find it quite alright for a novice)



regards
hunson is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
P-1 memory ET_ Software 4 2018-05-14 13:55
error failled to reallocate cardmaker Msieve 10 2016-07-05 13:09
"Hybrid Memory Cube" offers 1 Tb/s memory bandwith at just 1.4 mW/Gb/s ixfd64 Hardware 4 2011-12-14 21:24
Memory available to P-1 lycorn Software 23 2010-05-09 22:15
available memory Unregistered Information & Answers 2 2008-04-11 07:40

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


Tue May 24 06:34:48 UTC 2022 up 40 days, 4:36, 0 users, load averages: 1.39, 1.54, 1.69

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

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

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

≠ ± ∓ ÷ × · − √ ‰ ⊗ ⊕ ⊖ ⊘ ⊙ ≤ ≥ ≦ ≧ ≨ ≩ ≺ ≻ ≼ ≽ ⊏ ⊐ ⊑ ⊒ ² ³ °
∠ ∟ ° ≅ ~ ‖ ⟂ ⫛
≡ ≜ ≈ ∝ ∞ ≪ ≫ ⌊⌋ ⌈⌉ ∘ ∏ ∐ ∑ ∧ ∨ ∩ ∪ ⨀ ⊕ ⊗ 𝖕 𝖖 𝖗 ⊲ ⊳
∅ ∖ ∁ ↦ ↣ ∩ ∪ ⊆ ⊂ ⊄ ⊊ ⊇ ⊃ ⊅ ⊋ ⊖ ∈ ∉ ∋ ∌ ℕ ℤ ℚ ℝ ℂ ℵ ℶ ℷ ℸ 𝓟
¬ ∨ ∧ ⊕ → ← ⇒ ⇐ ⇔ ∀ ∃ ∄ ∴ ∵ ⊤ ⊥ ⊢ ⊨ ⫤ ⊣ … ⋯ ⋮ ⋰ ⋱
∫ ∬ ∭ ∮ ∯ ∰ ∇ ∆ δ ∂ ℱ ℒ ℓ
𝛢𝛼 𝛣𝛽 𝛤𝛾 𝛥𝛿 𝛦𝜀𝜖 𝛧𝜁 𝛨𝜂 𝛩𝜃𝜗 𝛪𝜄 𝛫𝜅 𝛬𝜆 𝛭𝜇 𝛮𝜈 𝛯𝜉 𝛰𝜊 𝛱𝜋 𝛲𝜌 𝛴𝜎𝜍 𝛵𝜏 𝛶𝜐 𝛷𝜙𝜑 𝛸𝜒 𝛹𝜓 𝛺𝜔