lib/job-manager.js
/*
  * divides the job processes over the specified hosts using round-robin divison
  * @param job {Object}: the job specs
  * @return {Object}: a job distribution plan
 */
divides the job processes over the specified hosts using round-robin divison
@param job {Object}: the job specs
@return {Object}: a job distribution plan
divides the job processes over the specified hosts using round - robin divison @param job { Object } : the job specs @return { Object } : a job distribution plan
function divide(job) {
     var hosts = {};
     for(var host in job.hosts) {
         hosts[host] = {count: 0, max: job.hosts[host].max_procs}
     }
     var hosts_list = Object.keys(hosts);
     var allocated = 0;
     var next = 0;
     var counter = 0;
     var overallocate = false;  
     while(allocated < job.size) {
         var host = hosts[hosts_list[next++ % hosts_list.length]];
         if(host.count != host.max || overallocate) {
             host.count++;
             allocated++;
             if(!overallocate) {
                 counter = 0;
             }
         }
         else {
             counter++;
             overallocate = (counter === hosts_list.length);
         }
     }
     var start_index = 0;
     if(!!hosts["local"]) {
         hosts.local.start = 0;
         start_index += hosts.local.count;
     }
     for(var host in hosts) {
         if(host !== "local") {
             hosts[host].start = start_index;
            start_index += hosts[host].count;
        }
        delete hosts[host]["max"];
     }
     return hosts;
 }
function divide ( job ) { var hosts = { } ; for ( var host in job . hosts ) { hosts [ host ] = { count : 0 , max : job . hosts [ host ] . max_procs } } var hosts_list = Object . keys ( hosts ) ; var allocated = 0 ; var next = 0 ; var counter = 0 ; var overallocate = false ; while ( allocated < job . size ) { var host = hosts [ hosts_list [ next ++ % hosts_list . length ] ] ; if ( host . count != host . max || overallocate ) { host . count ++ ; allocated ++ ; if ( ! overallocate ) { counter = 0 ; } } else { counter ++ ; overallocate = ( counter === hosts_list . length ) ; } } var start_index = 0 ; if ( ! ! hosts [ "local" ] ) { hosts . local . start = 0 ; start_index += hosts . local . count ; } for ( var host in hosts ) { if ( host !== "local" ) { hosts [ host ] . start = start_index ; start_index += hosts [ host ] . count ; } delete hosts [ host ] [ "max" ] ; } return hosts ; }
divides the job processes over the specified hosts using round-robin divison
 @param job {Object}: the job specs
 @return {Object}: a job distribution plan
divides the job processes over the specified hosts using round - robin divison @param job { Object } : the job specs @return { Object } : a job distribution plan
// round-robin over the hosts and allocated processes numbers // if true: hosts will be overallocated with processes to meet job.size // if not in overallocate mode already, reset the counter to indicate allocation // set the overallocate to true if gone through the list without allocation // register the 0 index process to the local host if exists // assign the rest of indecies to the rest of hosts