daleroberts / pypar

Efficient and scalable parallelism using the message passing interface (MPI) to handle big data and highly computational problems.
GNU General Public License v3.0
69 stars 15 forks source link

Guard pypar.balance() against out-of-range index and also stop importing math #7

Closed congma closed 9 years ago

congma commented 9 years ago

In this two commits, I did some minor revisions on pypar.balance() function.

The 1st one guards the argument p against out-of-bound values, and returns (N, N). This return value is natural because N:N is a valid slice of zero-length, which is expected, and also because this is a natural continuation of the return values from valid input values, and finally, such is already the case when balance(N, P, p) is called when P > N.

In the 2nd commit, from math import floor is no longer used, as with conversions to float. They're not necessary, and are much slower than integer arithmetics. To get the quotient and remainder, Python's built-in operators // and % are enough. This is even faster than divmod().

daleroberts commented 9 years ago

Thanks for that.