Provided by: libparmap-ocaml-dev_1.0~rc7-1_amd64

**NAME**

Parmap - Module Parmap: efficient parallel map, fold and mapfold on lists and arrays on multicores.

**Module**

Module Parmap

**Documentation**

ModuleParmap:sigendModuleParmap: efficient parallel map, fold and mapfold on lists and arrays on multicores. All the primitives allow to control the granularity of the parallelism via an optional parameterchunksize: ifchunksizeis omitted, the input sequence is split evenly among the available cores; ifchunksizeis specified, the input data is split in chunks of sizechunksizeand dispatched to the available cores using an on demand strategy that ensures automatic load balancing. A specific primitivearray_float_parmapis provided for fast operations on float arrays.===Settingandgettingthedefaultvalueforncores===valset_default_ncores:int->unitvalget_default_ncores:unit->int===Sequencetype,subsuminglistsandarrays===type'asequence= | Lof'alist| Aof'aarray===Theparmapfold,parfoldandparmapgenericfunctions,forefficiencyreasons,converttheinputdataintoanarrayinternally,soweprovidethe'asequencetypetoallowpassinganarraydirectlyasinput.Ifyouwanttoperformaparallelmapoperationonanarray,usearray_parmaporarray_float_parmapinstead.======Theparmapfold,parfoldandparmapgenericfunctions,forefficiencyreasons,converttheinputdataintoanarrayinternally,soweprovidethe'asequencetypetoallowpassinganarraydirectlyasinput.Ifyouwanttoperformaparallelmapoperationonanarray,usearray_parmaporarray_float_parmapinstead.======Optionalinitandfinalizefunctions======Theparmapfold,parfoldandparmapgenericfunctions,forefficiencyreasons,converttheinputdataintoanarrayinternally,soweprovidethe'asequencetypetoallowpassinganarraydirectlyasinput.Ifyouwanttoperformaparallelmapoperationonanarray,usearray_parmaporarray_float_parmapinstead.======Optionalinitandfinalizefunctions======Theoptionalinit(resp.finalize)functioniscalledoncebyeachchildprocessjustaftercreation(resp.justbeforeexit).initandfinalizebothdefaulttodoingnothing.inititakesthechildrankiasparameter(firstforkedchildhasrank0,next1,etc.).======Theparmapfold,parfoldandparmapgenericfunctions,forefficiencyreasons,converttheinputdataintoanarrayinternally,soweprovidethe'asequencetypetoallowpassinganarraydirectlyasinput.Ifyouwanttoperformaparallelmapoperationonanarray,usearray_parmaporarray_float_parmapinstead.======Optionalinitandfinalizefunctions======Theoptionalinit(resp.finalize)functioniscalledoncebyeachchildprocessjustaftercreation(resp.justbeforeexit).initandfinalizebothdefaulttodoingnothing.inititakesthechildrankiasparameter(firstforkedchildhasrank0,next1,etc.).======Parallelmapfold===valparmapfold:?init:(int->unit)->?finalize:(unit->unit)->?ncores:int->?chunksize:int->('a->'b)->'asequence->('b->'c->'c)->'c->('c->'c->'c)->'cparmapfold~ncores:nf(Ll)opbconcatcomputesList.fold_rightop(List.mapfl)bby forkingnprocesses on a multicore machine. You need to provide the extraconcatoperator to combine the partial results of the fold computed on each core. If 'b = 'c, thenconcatmay be simplyop. The order of computation in parallel changes w.r.t. sequential execution, so this function is only correct ifopandconcatare associative and commutative. If the optionalchunksizeparameter is specified, the processes compute the result in an on-demand fashion on blocks of sizechunksize.parmapfold~ncores:nf(Aa)opbconcatcomputesArray.fold_rightop(Array.mapfa)b===Parallelfold===valparfold:?init:(int->unit)->?finalize:(unit->unit)->?ncores:int->?chunksize:int->('a->'b->'b)->'asequence->'b->('b->'b->'b)->'bparfold~ncores:nop(Ll)bconcatcomputesList.fold_rightoplbby forkingnprocesses on a multicore machine. You need to provide the extraconcatoperator to combine the partial results of the fold computed on each core. If 'b = 'c, thenconcatmay be simplyop. The order of computation in parallel changes w.r.t. sequential execution, so this function is only correct ifopandconcatare associative and commutative. If the optionalchunksizeparameter is specified, the processes compute the result in an on-demand fashion on blocks of sizechunksize.parfold~ncores:nop(Aa)bconcatsimilarly computesArray.fold_rightopab.===Parallelmap===valparmap:?init:(int->unit)->?finalize:(unit->unit)->?ncores:int->?chunksize:int->('a->'b)->'asequence->'blistparmap~ncores:nf(Ll)computesList.mapflby forkingnprocesses on a multicore machine.parmap~ncores:nf(Aa)computesArray.mapfaby forkingnprocesses on a multicore machine. If the optionalchunksizeparameter is specified, the processes compute the result in an on-demand fashion on blocks of sizechunksize; this provides automatic load balancing for unbalanced computations, but the order of the result is no longer guaranteed to be preserved.===Paralleliteration===valpariter:?init:(int->unit)->?finalize:(unit->unit)->?ncores:int->?chunksize:int->('a->unit)->'asequence->unitpariter~ncores:nf(Ll)computesList.iterflby forkingnprocesses on a multicore machine.parmap~ncores:nf(Aa)computesArray.iterfaby forkingnprocesses on a multicore machine. If the optionalchunksizeparameter is specified, the processes perform the computation in an on-demand fashion on blocks of sizechunksize; this provides automatic load balancing for unbalanced computations.===Parallelmapfold,indexed===valparmapifold:?init:(int->unit)->?finalize:(unit->unit)->?ncores:int->?chunksize:int->(int->'a->'b)->'asequence->('b->'c->'c)->'c->('c->'c->'c)->'cLike parmapfold, but the map function gets as an extra argument the index of the mapped element===Parallelmap,indexed===valparmapi:?init:(int->unit)->?finalize:(unit->unit)->?ncores:int->?chunksize:int->(int->'a->'b)->'asequence->'blistLike parmap, but the map function gets as an extra argument the index of the mapped element===Paralleliteration,indexed===valpariteri:?init:(int->unit)->?finalize:(unit->unit)->?ncores:int->?chunksize:int->(int->'a->unit)->'asequence->unitLike pariter, but the iterated function gets as an extra argument the index of the sequence element===Parallelmaponarrays===valarray_parmap:?init:(int->unit)->?finalize:(unit->unit)->?ncores:int->?chunksize:int->('a->'b)->'aarray->'barrayarray_parmap~ncores:nfacomputesArray.mapfaby forkingnprocesses on a multicore machine. If the optionalchunksizeparameter is specified, the processes compute the result in an on-demand fashion on blochs of sizechunksize; this provides automatic load balancing for unbalanced computations, but the order of the result is no longer guaranteed to be preserved.===Parallelmaponarrays,indexed===valarray_parmapi:?init:(int->unit)->?finalize:(unit->unit)->?ncores:int->?chunksize:int->(int->'a->'b)->'aarray->'barrayLike array_parmap, but the map function gets as an extra argument the index of the mapped element===Parallelmaponfloatarrays===exceptionWrongArraySizetypebufvalinit_shared_buffer:floatarray->bufinit_shared_bufferacreates a new memory mapped shared buffer big enough to hold a float array of the size ofa. This buffer can be reused in a series of calls toarray_float_parmap, avoiding the cost of reallocating it each time.valarray_float_parmap:?init:(int->unit)->?finalize:(unit->unit)->?ncores:int->?chunksize:int->?result:floatarray->?sharedbuffer:buf->('a->float)->'aarray->floatarrayarray_float_parmap~ncores:nfacomputesArray.mapfaby forkingnprocesses on a multicore machine, and preallocating the resulting array as shared memory, which allows significantly more efficient computation than calling the generic array_parmap function. If the optionalchunksizeparameter is specified, the processes compute the result in an on-demand fashion on blochs of sizechunksize; this provides automatic load balancing for unbalanced computations, *and* the order of the result is still guaranteed to be preserved. In case you already have at hand an array where to store the result, you can squeeze out some more cpu cycles by passing it as optional parameterresult: this will avoid the creation of a result array, which can be costly for very large data sets. RaisesWrongArraySizeifresultis too small to hold the data. It is possible to share the same preallocated shared memory space across calls, by initialising the space callinginit_shared_bufferaand passing the result as the optionalsharedbufferparameter to each subsequent call toarray_float_parmap. Raises WrongArraySize ifsharedbufferis too small to hold the input data.===Parallelmaponfloatarrays,indexed===valarray_float_parmapi:?init:(int->unit)->?finalize:(unit->unit)->?ncores:int->?chunksize:int->?result:floatarray->?sharedbuffer:buf->(int->'a->float)->'aarray->floatarray===Likearray_float_parmap,butthemapfunctiongetsasanextraargumenttheindexofthemappedelement======Likearray_float_parmap,butthemapfunctiongetsasanextraargumenttheindexofthemappedelement======Debugging===valdebugging:bool->unit===Enableordisabledebuggingcodeinthelibrary;default:false======Enableordisabledebuggingcodeinthelibrary;default:false======Helperfunctionforredirectionofstdoutandstderr===valredirect:?path:string->id:int->unit===Helperfunctionthatredirectsstdoutandstderrtofileslocatedinthedirectorypath,carryingnamesoftheshapestdout.NNNandstderr.NNNwhereNNNistheidoftheusedcore.Usefulwhenwritinginitialisationfunctionstobepassedasinitargumenttotheparallelcombinators.Thedefaultvalueforpathis/tmp/.parmap.PPPPwithPPPPtheprocessidofthemainprogram.===