Git Product home page Git Product logo

primenumbers-metal's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

pudepiedj

primenumbers-metal's Issues

GPU and CPU generate different numbers of primes

Alex, I found your interesting Metal implementation of prime number generation through Reddit.

I've cloned and run it and it works well until the number of primes gets large when the test you have included to compare CPU and GPU prime-generation generates an error.

The first error is for a false prime generated by the GPU (the false primes are all generated by the GPU). This is the claim that 17884441 is prime when in fact it it 4229^2. Subsequently all numbers that are the squares of primes are falsely identified as primes.

The problem comes from the upper bound at about line 33 in your gpuTest/computePrimeNumbers.metal file where the last number is not tested; hence when the only divisor of a number is its prime square-root, it seems to be a prime but isn't.

This fixes it just by adding 2 to force the top number to be tested:

for (UIntType i = 3; i <= sqrt((FloatType)num) + 2; i+=2)

I notice that you also use a different Type in the CPU version with Double rather than FloatType so maybe that would also work but I haven't checked.

Hope this is helpful.

Incidentally, my MacBook generates primes up to 1,000,000,000 on its AMD Radeon 5500M GPU in about 10 secs; the CPU takes forever (or maybe hangs) and I haven't run it to completion with that many primes.

The code doesn't seem to exit smoothly, but that's another matter.

pudepiedj

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.