Distributed calculations in your browser (beta)

in #gridcoin6 years ago (edited)

I created new project for distributed computing. It is successor of my previous project, distributed prime searching in browser.

Improvements from my previous project:

  • Larger workunits (workunit size can be changed without stopping project)
  • Using JS threads
  • Different types of workunits are possible
  • Checking workunit results between users

Project in beta now. That means I can reset results when needed (but not your payouts). After some time I create release and move project to external hosting. Currently it hosted on my netbook.

Current project

Twin primes - finding twin primes below 9×1015 (wiki link). Value 9×1015 is upper limit of javascript integer variable. It could be avoided later.

Rewards

Currently 0.0001 GRC per completed workunit. It could be adjusted later. Payroll happens daily.

Future plans

I'm planning to implement next projects here:

  • Amicable checker - check if BOINC amicable numbers didn't miss any amicable numbers.
  • Collatz checker - analog for collatz conjecture.
  • Anybody can add their own function - function format is easy as possible (but there is some limitations, because storage is limited). Also you can run your own instance, project is opensourced.

Checking function

Each project should have checking function in JavaScript. Input is interval: start number and stop number, they are received with message. Function reports progress and results (when done). As I said above it's pretty easy. Sample for prime twins searching:

// Event listener. Listens to message with input parameters
self.addEventListener('message', function(e) {
    var thread_index = e.data[0];
    var workunit_result_uid = e.data[1];
    var start_number = parseInt(e.data[2]);
    var stop_number = parseInt(e.data[3]);
    var version = 1;

    // Check each number and report progress
    function check_number_seq(thread_index, start_number, stop_number) {
        var number;
        var seq_result = [];
        var is_prime;
        var progress = 0;
        progress_report_interval=Math.floor((stop_number-start_number)/100);
        progress_report=start_number;

        if((start_number % 2) == 0) start_number++;

        for(number=start_number; number<=stop_number; number+=2) {
            // Check number
            result = check_number(number);
            if(result !== null) {
                // Add number to results
                seq_result.push(number);
                // Optimization - next 4 numbers can be skipped
                number+=4;
            }
            // Report progress
            if(number > progress_report) {
                progress=(number-start_number)/(stop_number-start_number);
                self.postMessage([thread_index,0,progress]);
                progress_report+=progress_report_interval;
            }
        }
        // Return result
        return seq_result;
    }

    var result = check_number_seq(thread_index, start_number, stop_number);
    // Return result with message to parent thread
    self.postMessage([thread_index, 1, version, workunit_result_uid, result]);
}, false);

// Number checking function
// Returns null if not twin
// Returns first of twins otherwise
function check_number(number) {
        if((number%2)==0) return null;
        if(check_is_prime(number) && check_is_prime(number+2)) return [number,number+2];
        return null;
}

// Check is number prime or not
function check_is_prime(number) {
        number=parseInt(number);
        var i;
        var limit=Math.floor(Math.sqrt(number));
        for(i=2;i<=limit;i++) {
                if((number%i) == 0) return 0;
        }
        return 1;
}

Links

Sort:  

Awesome, I'm imagining right now calculations I'd be interested to put on there.

If you ever decide to try some interesting calculations there I'd be willing to do some crunching :D