
224 CHAPTER 10. SORTING
# ( cou l d a l s o use q u a n t i l e ( ) he re )
k <− f l oor ( nsamp / n c o r e s )
i f (me > 1) mylo <− samp [ ( me−1) ∗ k + 1 ]
i f (me < n c or e s ) myhi <− samp [ me ∗ k ]
i f (me == 1) myx <− x [ x <= myhi ] else
i f (me == nco r e s ) myx <− x [ x > mylo ] e l s e
myx <− x [ x > mylo & x <= myhi ]
# t h i s th r e a d now s o r t s i t s as s i g n e d group
sort (myx)
}
r e s <− mclapply ( 1 : ncor e s , dowork , mc. c o r e s=nc o r es )
# s t r i n g th e r e s u l t s t o g e t h e r
c ( u n l ist ( r e s ) )
}
t e s t <− function ( n , n co r e s ) {
x <− runif ( n )
mcbsort ( x , n c or e s=n cores , nsamp=1000)
}
This ...