1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162(**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the "hack" directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*)(****************************************************************************)(* Moduling Making buckets.
* When we parallelize, we need to create "buckets" of tasks for the
* workers.
* Given a list of files, we want to split it up into buckets such that
* every worker is busy long enough. If the bucket is too big, it hurts
* load balancing, if it is too small, the overhead in synchronization time
* hurts *)(****************************************************************************)type'abucket=|Jobof'a|Wait|Donetype'anext=unit->'abucketletmake_bucket_sizejobs=leti=ref0infun()->letbucket_size=min(Array.lengthjobs-!i)bucket_sizeinletresult=Array.subjobs!ibucket_sizeini:=bucket_size+!i;Array.to_listresultletmake_list~num_workersjobs=letjobs=Array.of_listjobsinletbucket_size=max1(1+((Array.lengthjobs)/num_workers))inmake_bucket_sizejobsletof_list=function|[]->Done|wl->Jobwlletmake~num_workersjobs=letmaker=make_list~num_workersjobsinfun()->of_list(maker())type'aof_n={work:'a;bucket:int;total:int}letmake_n_buckets~buckets~split=letnext_bucket=ref0infun()->letcurrent=!next_bucketinincrnext_bucket;if(current<buckets)thenJob{work=split~bucket:current;bucket=current;total=buckets}elseDone