pmap.scrbl (2059B)
1 #lang scribble/manual 2 3 4 @require[@for-label[pmap 5 racket/base 6 racket/future 7 racket/place 8 ]] 9 10 @title{pmap} 11 @author{APOS80} 12 13 @defmodule[pmap] 14 15 @section{pmapf} 16 17 pmapf works as map but applies the function to every item in the list/lists in parallel using futures. 18 It's restrictions is the same as for futures and map in general in Racket. 19 20 21 @racketblock[ 22 ;Example: 23 24 >(pmapf + '(1 2 3) '(1 2 3)) 25 >'(2 4 6) 26 ] 27 28 If the function applied is to simple pmap might perform worse than map because of the 29 overhead a future generate. 30 31 32 @section{pmapp} 33 34 pmapp works almost as map and applies the function to every item in the list/lists in parallel using places. 35 Places has some restrictions and that impacts on the implementation in several ways, READ ON! 36 37 First: 38 On creation of a place a rkt file is loaded into the new place, that means the uses of the place 39 is determined of the file and cant be changed by anyone else then the creator. For now it includes racket base, flonum and fixnum. 40 41 Second: 42 A procedure can NOT be passed to a place! Then how do you pass a function, as a list! 43 44 pmapp shows it strength in heavyer calcullations like mandelbrot, see the comparison section! 45 46 @racketblock[ 47 ;Example: 48 49 >(pmapp '(lambda (x y)(+ x y) ) '(1 2 3) '(1 2 3)) 50 >'(2 4 6) 51 52 >(pmapp '(lambda (x y)(fl+ x y) ) '(1.0 2.0 3.0) '(1.0 2.0 3.0)) 53 >'(2.0 4.0 6.0) 54 ] 55 56 The place file has racket/base, racket/fixnum and math required. 57 58 @section{Comparison} 59 60 An comparison calcullating two mandelbrot's: 61 @racketblock[ 62 "(10000001 10000001) (4976.39990234375 ms)" ;map 63 "(10000001 10000001) (4196.400146484375 ms)";pmapf 64 "(10000001 10000001) (1840.7998046875 ms)" ;pmapp 65 ] 66 67 An comparison calcullating four mandelbrot's, with flonum: 68 @racketblock[ 69 "(10000001 10000001 10000001 10000001) (9752.256591796875 ms)";map 70 "(10000001 10000001 10000001 10000001) (8613.47607421875 ms)" ;pmapf 71 "(10000001 10000001 10000001 10000001) (1887.66064453125 ms)" ;pmapp 72 ]