Sunday, January 17, 2016

Multi-threading in JavaScript with ParallelJS


Parallel.js is a simple library for parallel computing in Javascript (in node.js or in the modern web browsers). Paralleljs takes advantage of Web Workers for the web, and child processes for Node.

What is web workers

Web Workers are a mechanism by which a script operation can be made to run in a background thread separate from the main execution thread of a web application. The advantage of this is that laborious processing can be performed in a separate thread, allowing the main (usually the UI) thread to run without being blocked/slowed down.
- https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API 


Multi-Threading in JavaScript

JavaScript is executed in a single thread by an event loop. With the Worker interface, a solution to this single-thread limitation problem has been found. With web workers Messages Api is used to communicate.

Note that, multi-threaded programming is parallel, but parallel programming is not necessarily multi-threaded. Unless the multi-threading occurs on a single core, in which case it is only concurrent.

Parallel.js

ParallelJS  provides a great easy to useAPI for web workers with many helpers. A sample usage :

var p = new Parallel([1, 2, 3, 4, 5]);console.log(p.data)


The instance p contains a set of helper methods, for example spawn, map, reduce.
Here is a simple example of map function usage. It returns a Promise with the result. This is not the right solution for multi-threading with parallel.js but only a simple example. 

p.map(function (number) {
 return number * number;
}).then(function (data) {
 console.log(data);
});

Tuesday, January 12, 2016

Install Caffe with GPU support without pain

This is my cheatsheet to install caffe with gpu support on an ubuntu machine.
https://gist.github.com/hasantayyar/1023dbdb01647b0c9559


apt-get update && apt-get install -q -y \
  wget \
  build-essential \
  module-init-tools

cd /opt && \
  wget http://developer.download.nvidia.com/compute/cuda/7_0/Prod/local_installers/cuda_7.0.28_linux.run && \
  chmod +x *.run && \
  mkdir nvidia_installers && \
  ./cuda_7.0.28_linux.run -extract=`pwd`/nvidia_installers && \
  cd nvidia_installers && \
  ./NVIDIA-Linux-x86_64-346.46.run -s -N --no-kernel-module && \
  ./cuda-linux64-rel-7.0.28-19326674.run -noprompt

#ENV LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-7.0/lib64

#ENV PYTHONPATH=/opt/caffe/python

#ENV PATH $PATH:/opt/caffe/.build_release/tools

apt-get update && apt-get install -y \
  bc cmake curl git
  gcc-4.6 g++-4.6 gcc-4.6-multilib g++-4.6-multilib \
  gfortran unzip wget \
  libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev \
  libboost-all-dev \
  libhdf5-serial-dev \
  liblmdb-dev libjpeg62 libfreeimage-dev libatlas-base-dev \
  pkgconf protobuf-compiler \
  python-dev python-pip python-yaml python-numpy

# you may not need to change your gcc version
# update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-4.6 30 && \
  update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-4.6 30 && \
  update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 30 && \
  update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 30

# Allow it to find CUDA libs
echo "/usr/local/cuda/lib64" > /etc/ld.so.conf.d/cuda.conf && \
ldconfig
# Clone caffe
cd /opt && git clone https://github.com/BVLC/caffe.git

# you may not need to install glog. but caffe will log warnings until you've glog installed.
cd /opt && wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz && \
  tar zxvf glog-0.3.3.tar.gz && \
  cd /opt/glog-0.3.3 && \
  ./configure && \
  make && \
  make install

ldconfig

cd /opt && \
  wget https://github.com/schuhschuh/gflags/archive/master.zip && \
  unzip master.zip && \
  cd /opt/gflags-master && \
  mkdir build && \
  cd /opt/gflags-master/build && \
  export CXXFLAGS="-fPIC" && \
  cmake .. && \
  make VERBOSE=1 && make && make install

cd /opt/caffe && \
  cp Makefile.config.example Makefile.config

# echo "CXX := /usr/bin/g++-4.6" >> Makefile.config && sed -i 's/CXX :=/CXX ?=/' Makefile && \
make all -j8

# link caffe-ld-so.conf under /etc/ld.so.conf.d/

ldconfig

# you can install pillow from apt python-pil
easy_install pillow 

# You can find apt alternatives for these python deps.
cd /opt/caffe/python ; \
      for req in $(cat requirements.txt); do pip install $req; done

cd /opt/caffe && make py

# Done

Monday, January 11, 2016

If You are Dealing with Data, You will Like Anaconda

With Python at its core, Anaconda is a platform for connecting your expertise and curiosity with data to explore and deploy innovative analytic apps that solve challenging problems with ease and agility. Processing multi-workload data analytics – from batch through interactive to real-time – the platform is used for both ad hoc and production deployments. Anaconda is tuned to take advantage of modern computing environments – everything from multi-core servers, to Spark and Hadoop, to GPUs – delivering flexibility and allowing you to maximize your infrastructure investment. All of this plus the key capabilities required of an open source modern analytics platform – spanning advanced analytics, interactive visualizations, governance, security and operational support.


 https://www.continuum.io/



    Anaconda Stack

    APP

  • Notebooks 
  • Embeddable Dashboards 
  • Data Services 
  • Visual Apps 
  • VIZ 
  • Plots
  • Interactive Viz
  • Big Data
  • Maps & GIS
  • 3D
  • Streaming
  • Graphs 

      STORYBOARD

  • Notebooks
  • Interactive Exploration
  • Visual Programming
  • Data IDEs 

      ANALYTICS

  • DataPrep
  • Stats
  • ML & Ensembles
  • Deep Learning
  • Simulation & Optimization
  • Geospatial
  • Text & NLP
  • Video/Image/Audio Mining
  • Graph & Network 

      DATA

  • Hadoop & Hive
  • Spark
  • NoSQL
  • DW & SOL
  • Files & Web Services

      HARDWARE

  • Servers
  • Clusters
  • GPUs & High End Workstations