Pages

Monday, June 27, 2011

Arbitrary Precision using Python Mpmath

Mpmath is great, powerful and easy to use to calculating equation that involve floating point.
I found several article that could be used to find minimal setting for arbitrary precision, enough the chat, let my code do the talk..

Software that used:
  • python ver 2.6.5 in ubuntu 10.04 64 bit
  • python EPD(Enthought Python Distribution) ver 7.0-2 32 bit in windows 7 64 bit, no default mpmath installation under python epd, but its available via sympy(included ver 0.14 mpmath)
  • python mpmath ver 0.17, http://code.google.com/p/mpmath/
  • gmpy -> python binding for GMP
  • sage version 4.7 64bit for ubuntu10.04  http://www.sagemath.org/

Below are 2 equations that could be used for searching significant setting for mpmath arbitrary precision.
1. Interval Arithmetic: Python Implementation and Applications by Stefano Taschini in SciPy2008_proceedings.pdf
GMPY Backend

SAGE Backend


Python Backend


2. Why and how to use arbitrary precision by Kaveh R. Ghazi, Vincent Lefèvre, Philippe Théveny, Paul Zimmermann in cise.pdf
GMPY Backend




SAGE Backend


Python Backend



Conclusion
  • different BACKEND in mpmath did not effect in result and mpmath.mp context(setting for arbitrary precision), just gives an performance effect(sage faster, than gmpy, last python) 
  • mpmath prec value that could be gives most precision is not less than 128 bit (mpmath.mp.prec=128)
  • creating a mpf object is better to converted into string data type first( mp.mpf('0.1') or mp.mpf(str(0.1)))
  • better doing a arithmetic rational operation when possible see first code that solved using sympy

Tuesday, June 21, 2011

Install OpenCL and PyOpenCL in Ubuntu 10.04 LTS Lucid Lynx 64 bit

After playing with Scientific Linux 6 with OpenCL and PyOpenCL, I decided to bring it into my primary OS, and yes it is Ubuntu 10.04 LTS Lucid Lynx 64 bit.

Searching through the net, I found two ways to install OpenCL

Because my previous experience in SL6 is worked, so i liked to doing so within my ubuntu.

Things that needed by my system for OpenCL(testing that it works by executing 'make all' in your $AMDAPPSDKROOT -> i put it on "/home/user/AMD-APP-SDK-v2.4-lnx64/", this will built samples application that included in samples folder)
  • read the guide AMD_APP_SDK_Installation_Notes.pdf (it just extract and put a conf in /etc dir)
  • install libglu1-mesa-dev (in my case the package(header files) that missing is only this, so might be different on your system!), this needed when build a OpenCL samples
  • also add a AMDAPPSDK in your $PATH in .bashrc file like this
Below are some screenshoot to test sample applications under AMD-APP-SDK-v2.4-lnx64/samples/opencl/bin/x86_64/ directory if the installation of AMDAPPSDK and is working:
test using HelloCL
test using GlobalMemoryBandwidth




and notice if running an OpenCL program using all processor thread(because i didn't have a GPU capable for OpenCL

And now for PyOpenCL(made by Andreas Klöckner at http://mathema.tician.de/software/pyopencl )
To install correctly please enable the internet connectivity its needed to install required python dependency module.

In my system is need to install libboost1.40-all-dev, python-numpy and python-libxslt. (Both are available from ubuntu repository). Using command from terminal -> sudo apt-get install libboost1.40-all-dev python-numpy python-libxslt

Installing PyOpenCl:
  • download PyOpenCL from PyOpenCL
  • Notice when execute configure.py : python configure.py   --cl-inc-dir=$AMDAPPSDKROOT/include   --cl-lib-dir=$AMDAPPSDKROOT/lib/x86_64   --cl-libname=OpenCL
  • then -> python setup.py build
  • finnally -> sudo python setup.py install
test PyOpenCL using examples benchmark-all.py

BTW  I'm just noticed that python in ubuntu is faster than in Scientific Linux 6, and it same 64 bit, same laptop.