split the data into slices to spread the data equally among threads
432424
function( fn ){
      var self = this;
      var _p = self._private;
      var subsize = self.spreadSize(); // number of pass eles to handle in each thread
      var pass = _p.pass.shift().concat([]); // keep a copy
      var runPs = [];

      for( var i = 0; i < this.length; i++ ){
        var thread = this[i];
        var slice = pass.splice( 0, subsize );

        var runP = thread.pass( slice ).run( fn );

        runPs.push( runP );

        var doneEarly = pass.length === 0;
        if( doneEarly ){ break; }
      }

      return $$.Promise.all( runPs ).then(function( thens ){
        var postpass = new Array();
        var p = 0;

        // fill postpass with the total result joined from all threads
        for( var i = 0; i < thens.length; i++ ){
          var then = thens[i]; // array result from thread i

          for( var j = 0; j < then.length; j++ ){
            var t = then[j]; // array element

            postpass[ p++ ] = t;
          }
        }

        return postpass;
      });
    }
618221
def chunks(data, chunk_size):
    
    for i in xrange(0, len(data), chunk_size):
        yield data[i:i+chunk_size]
1086033
static double run(int num_threads) {

    final double membw[] = new double[num_threads];
    Thread[] threads = new Thread[num_threads];
    for (int t=0;t<num_threads;++t) {
      final int thread_num = t;
      threads[t] = new Thread() {
        public void run() {
          MemoryBandwidth l = new MemoryBandwidth();
          membw[thread_num] = l.run_benchmark();
        }
      };
    }
    for (int t=0;t<num_threads;++t) {
      threads[t].start();
    }
    for (int t=0;t<num_threads;++t) {
      try {
        threads[t].join();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
    return Utils.sum(membw);
  }
1078548
def chunks(data, size):
    
    for i in range(0, len(data), size):
        yield data[i:i + size]
789354
def divide(self, data_source_factory):
        """"""
        data_length = data_source_factory.length()
        data_interval_length = data_length / self.workers_number() + 1

        current_index = 0
        self.responses = []
        while current_index < data_length:
            self.responses.append(0)
            offset = current_index
            limit = min((data_length - current_index, data_interval_length))
            yield data_source_factory.part(limit, offset)
            current_index += limit
1009362
def _parameter_sweep(self, parameter_space, kernel_options, device_options, tuning_options):
        """"""
        results = []

        #randomize parameter space to do pseudo load balancing
        parameter_space = list(parameter_space)
        random.shuffle(parameter_space)

        #split parameter space into chunks
        work_per_thread = int(numpy.ceil(len(parameter_space) / float(self.max_threads)))
        chunks = _chunk_list(parameter_space, work_per_thread)

        for chunk in chunks:

            chunked_result = self._run_chunk(chunk, kernel_options, device_options, tuning_options)

            results.append(lift(chunked_result))

        return gather(*results)
929204
def split(self, bits_count):
		
		result = []
		array = WBinArray(self.__value, self.__size)

		if (len(array) % bits_count) > 0:
			array.resize(len(array) + (bits_count - (len(array) % bits_count)))

		while len(array):
			result.append(WBinArray(array[:bits_count], bits_count))
			array = array[bits_count:]
		return result
1259847
def chunks(lst, size):
    """"""
    for i in xrange(0, len(lst), size):
        yield lst[i:i + size]
403628
def data_chunk(data, chunk, with_overlap=False):
    """"""
    assert isinstance(chunk, tuple)
    if len(chunk) == 2:
        i, j = chunk
    elif len(chunk) == 4:
        if with_overlap:
            i, j = chunk[:2]
        else:
            i, j = chunk[2:]
    else:
        raise ValueError("'chunk' should have 2 or 4 elements, "
                         "not {0:d}".format(len(chunk)))
    return data[i:j, ...]
1230469
def parallel_fill(self, games, threads=8):
        
        games.sort(key=os.path.basename)
        # A couple extra in case parsing fails
        max_games = int(self.max_size / self.sampling_frac / 200) + 480
        if len(games) > max_games:
            games = games[-max_games:]

        with mp.Pool(threads) as pool:
            res = tqdm(pool.imap(self.func, games), total=len(games))
            self.examples.extend(itertools.chain.from_iterable(res))
        print("Got", len(self.examples), "examples")
943220
def split_data(data, squeeze=False):
    
    vdata = np.atleast_2d(data)
    nr_freqs = int(vdata.shape[1] / 2)
    part1 = vdata[:, 0:nr_freqs]
    part2 = vdata[:, nr_freqs:]
    if(squeeze):
        part1 = part1.squeeze()
        part2 = part2.squeeze()
    return part1, part2
1015754
def generate_chunks(data, chunk_size=DEFAULT_CHUNK_SIZE):
    """"""
    iterator = iter(repeated.getvalues(data))

    while True:
        chunk = list(itertools.islice(iterator, chunk_size))
        if not chunk:
            return

        yield chunk
439388
def split(self, data):
		
		line = deepcopy(data)
		line_width = (self.width() - 1)

		lines = []
		while len(line):

			new_line = line[:line_width]

			new_line_pos = new_line.find('\n')
			if new_line_pos >= 0:
				new_line = line[:new_line_pos]
				line = line[(new_line_pos + 1):]
			else:
				line = line[line_width:]

			lines.append(new_line)

		return lines
241517
def split_every(n, iterable):
    """"""
    items = iter(iterable)
    return itertools.takewhile(bool, (list(itertools.islice(items, n)) for _ in itertools.count()))
826175
def split32(data):
    
    all_pieces = []

    for position in range(0, len(data), 32):
        piece = data[position:position + 32]
        all_pieces.append(piece)

    return all_pieces
1062197
def chunks(data, n):
    """"""
    for i in range(0, len(data), n):
        yield data[i:i+n]
36095
def _chunk_data(self, data):
        """"""

        assert data[-2:] == "\r\n", "CRLF"

        if self.gzip_decompressor:
            if not self.gzip_header_seen:
                assert data[:2] == '\x1f\x8b', "gzip header"
                self.gzip_header_seen = True

            self.process_input_buffer += self.gzip_decompressor.decompress(data[:-2])
        else:
            self.process_input_buffer += data[:-2]

        self.got_chunk = True

        if self.process_input_buffer:
            # since we now have data in the buffer, enable write events again
            logger.debug('Got data in buffer, interested in writing to process again')
            self.ioloop.update_handler(self.fd_stdin, self.ioloop.WRITE | self.ioloop.ERROR)

        # do NOT call read_chunks directly. This is to give git a chance to consume input.
        # we don't want to grow the buffer unnecessarily.
        # Additionally, this should mitigate the stack explosion mentioned in read_chunks
        self.ioloop.add_callback(self.read_chunks)