|
3 | 3 | Supported Python Programs |
4 | 4 | ========================= |
5 | 5 |
|
6 | | -The `@hpat.jit` decorator... |
| 6 | +HPAT compiles and parallelizes the functions annotated with the `@hpat.jit` |
| 7 | +decorator. Therefore, file I/O and computations on large datasets should be |
| 8 | +inside the jitted functions. The supported data structures for large datasets |
| 9 | +are `Numpy <http://www.numpy.org/>`_ arrays and |
| 10 | +`Pandas <http://pandas.pydata.org/>`_ dataframes. |
| 11 | + |
| 12 | +Enabling Parallelization |
| 13 | +------------------------ |
| 14 | + |
| 15 | +To enable parallelization, HPAT needs to recognize the large datasets and their |
| 16 | +computation in the program. Hence, only the supported data-parallel operators of |
| 17 | +Numpy and Pandas can be used for large datasets and computations. The sequential |
| 18 | +computation on small data can be any code that |
| 19 | +`Numba supports <http://numba.pydata.org/numba-doc/latest/index.html>`_. |
| 20 | + |
| 21 | +Supported Numpy Functions |
| 22 | +------------------------- |
| 23 | + |
| 24 | +Below is the list of the data-parallel Numpy operators that HPAT supports. |
| 25 | + |
| 26 | +1. Numpy `element-wise` or `point-wise` array operations: |
| 27 | + |
| 28 | + * Unary operators: ``+`` ``-`` ``~`` |
| 29 | + * Binary operators: ``+`` ``-`` ``*`` ``/`` ``/?`` ``%`` ``|`` ``>>`` ``^`` |
| 30 | + ``<<`` ``&`` ``**`` ``//`` |
| 31 | + * Comparison operators: ``==`` ``!=`` ``<`` ``<=`` ``>`` ``>=`` |
| 32 | + * data-parallel math operations: ``add``, ``subtract``, ``multiply``, |
| 33 | + ``divide``, ``logaddexp``, ``logaddexp2``, ``true_divide``, |
| 34 | + ``floor_divide``, ``negative``, ``power``, ``remainder``, |
| 35 | + ``mod``, ``fmod``, ``abs``, ``absolute``, ``fabs``, ``rint``, ``sign``, |
| 36 | + ``conj``, ``exp``, ``exp2``, ``log``, ``log2``, ``log10``, ``expm1``, |
| 37 | + ``log1p``, ``sqrt``, ``square``, ``reciprocal``, ``conjugate`` |
| 38 | + * Trigonometric functions: ``sin``, ``cos``, ``tan``, ``arcsin``, |
| 39 | + ``arccos``, ``arctan``, ``arctan2``, ``hypot``, ``sinh``, ``cosh``, |
| 40 | + ``tanh``, ``arcsinh``, ``arccosh``, ``arctanh``, ``deg2rad``, |
| 41 | + ``rad2deg``, ``degrees``, ``radians`` |
| 42 | + * Bit manipulation functions: ``bitwise_and``, ``bitwise_or``, |
| 43 | + ``bitwise_xor``, ``bitwise_not``, ``invert``, ``left_shift``, |
| 44 | + ``right_shift`` |
| 45 | + |
| 46 | +2. Numpy reduction functions ``sum`` and ``prod``. |
| 47 | + |
| 48 | +3. Numpy array creation functions ``zeros``, ``ones`` |
| 49 | + |
| 50 | +4. Random number generator functions: ``rand``, ``randn``, |
| 51 | + ``ranf``, ``random_sample``, ``sample``, ``random``, |
| 52 | + ``standard_normal``, ``chisquare``, ``weibull``, ``power``, ``geometric``, |
| 53 | + ``exponential``, ``poisson``, ``rayleigh``, ``normal``, ``uniform``, |
| 54 | + ``beta``, ``binomial``, ``f``, ``gamma``, ``lognormal``, ``laplace``, |
| 55 | + ``randint``, ``triangular``. |
| 56 | + |
| 57 | +4. Numpy ``dot`` function between a matrix and a vector, or two vectors. |
| 58 | + |
| 59 | +Optional arguments are not supported unless if explicitly mentioned here. |
| 60 | +For operations on multi-dimensional arrays, automatic broadcast of |
| 61 | +dimensions of size 1 is not supported. |
| 62 | + |
| 63 | + |
| 64 | +Explicit Parallel Loops |
| 65 | +----------------------- |
| 66 | + |
| 67 | +Sometimes a program cannot be written in terms of data-parallel operators easy |
| 68 | +and explicit parallel loops are required. |
| 69 | +In this case, one can use HPAT's ``prange`` instead of ``range`` to specify that a |
| 70 | +loop can be parallelized. The user is required to make sure that the loop does |
| 71 | +not have cross iteration dependencies except the supported reductions. |
| 72 | +Currently, only sum using the ``+=`` operator is supported. |
| 73 | +The example below demonstrates a parallel loop with a |
| 74 | +reduction:: |
| 75 | + |
| 76 | + from HPAT import jit, prange |
| 77 | + @jit |
| 78 | + def prange_test(n): |
| 79 | + A = np.random.ranf(n) |
| 80 | + s = 0 |
| 81 | + for i in prange(len(A)): |
| 82 | + s += A[i] |
| 83 | + return s |
| 84 | + |
| 85 | +Supported Pandas Functions |
| 86 | +-------------------------- |
| 87 | + |
| 88 | +File I/O |
| 89 | +-------- |
| 90 | + |
| 91 | +Currently, HPAT only supports I/O for the `HDF5 <http://www.h5py.org/>`_ format. |
0 commit comments