Showing posts with label belajar pemrograman. Show all posts
Showing posts with label belajar pemrograman. Show all posts

Friday, March 25, 2016

Parallel programming pada Bash shell

Sejak tahun 2005, perkembangan processor komputer telah berganti paradigma, dari peningkatan clock CPU menjadi peningkatan jumlah core (Cek Wikipedia: Intel CPU Trends). Namun, pemrograman komputer yang banyak dipakai sekarang masih serial yang hanya mengandalkan single core. Artinya, kita belum banyak mengeksplorasi kemampuan komputer yang memiliki banyak core tersebut. Sebagai contoh, laptop saya memikil 4 physical core, jika saya hanya mengandalkan pemrograman serial, maka tiga core lainnya tak terpakai. Bagaimana cara memprogram secara parallel? Materi berikut saya peroleh dari workshop computational infrastructure dan scientific computing.

Screenshot workload 4 CPU (hyperthread) saat running parallel programming, keempat CPU menunjukkan beban kerja yang hampir 100% (baik pada "top" maupun system setting CPU history)

Instalasi

Cara termudah untuk parallel programming adalah dengan dengan menggunakan OS berbasis Linux. Saya menggunakan Ubuntu OS dengan library openmpi. Cara menginstallnya adalah sebagai berikut:
 sudo apt-get install openmpi-bin
Untuk mengeceknya, silakan ketik di terminal "mpirun" dan enter, Jika ada keterangan dan pesan "Report bugs to http://www.open-mpi.org/community/help/" berarti library openmpi sudah terinstall di Ubuntu.

Program Pertama

Program pertama yang bisa kita tes dengan mpirun adalah sebagai berikut,
 mpirun -np 12 /bin/hostname 
Program diatas artinya mencetak nama hostname (nama komputer) kita melalui 12 processor (-np 12). Meski jumlah processor kita hanya 4, namun kita bisa memerintahkan pada PC untuk me-run lebih dari jumlah CPU/processor. Sisa process (12-4=8) akan diluar setelah 4 process pertama, namun karena program diatas sangat ringan maka duabelas outputnya pun dapat ditampilkan bebarengan. Jika anda mendapat ouput 12 nama hostname, itu adalah hasil pemrograman parallel pertama anda. Hello world!

Thursday, March 17, 2016

Learn Python the Hardway : The work flow

Really, I want to say; I hate python programming. But, when I said something bad, the bad will come to me again and again. So, let's to to stop it. Python is interpreter language or scripted language. It doesn't need to compile like C or C++. It seems the easiest (programming) language to learn. How to learn it? How to master it? what is the hard way to learn as fast as possible? Here the work flow:

Tutorial:
  1. Do all exercise in Learn Python The Hardway by hand (type, not copy paste), from Exercise 1 to Exercise 39.
  2. Solve the Project Euler Problem, Problem number 1, 2, 3, 14, 17, 57, 79 and 102 with Python.
  3. Learn the basic concept of python and advanced it with python object oriented programming. 
  4. Learn Tutorial-python.
  5. Learn from software carpentry python lesson.
Free online MOOC (interactive coding, RECOMMENDED):
  1. Datacamp's intro to Python for Data Science
  2. EdX Intro to Python for Data Science (Connected to DataCamp)
  3. EdX introdution to Programming Using Python
  4. MITx 6.00.1x Introduction to Computer Science and Prorgramming Using Python
  5. EdX Using Python for Research

That's all, do it. You'll master the python on the hard way method. That is one of the most important thing that I got from the workshop of scientific computing.