jueves, 23 de febrero de 2012

Examples with CUDA

The first example that we will see is a vectors sum using CUDA, where we have two lists of numbers where we sum the elements from each list and store the result in a third list.

Now we have the source code where we are using CPU.

As you saw in the comments that program is just simple we add always the library "book.h" which we need to use all the features of CUDA, and I took a screenshot of the results.

[Image of results]

Now we have the source code where we are using GPU.


miércoles, 22 de febrero de 2012

Running programs in parallel using Parallel Python

Parallel Python is a python module which provides mechanism for parallel execution of python code on SMP(systems with multiple processors or cores) and clusters(computers connected via network).

Parallel Python has good features as you can see below:
  • Parallel execution of python code on SMP and clusters.
  • Easy to understand and implement job-based parallelization technique (easy to convert serial application in parallel).
  • Automatic detection of the optimal configuration (by default the number of worker processes is set to the number of effective processors).
  • Dynamic processors allocation (number of worker processes can be changed at runtime).
  • Low overhead for subsequent jobs with the same function (transparent caching is implemented to decrease the overhead).
  • Dynamic load balancing (jobs are distributed between processors at runtime).
  • Fault-tolerance (if one of the nodes fails tasks are rescheduled on others).
  • Auto-discovery of computational resources.
  • Dynamic allocation of computational resources (consequence of auto-discovery and fault-tolerance).
  • SHA based authentication for network connections.
  • Cross-platform portability and interoperability (Windows, Linux, Unix, Mac OS X).
  • Cross-architecture portability and interoperability (x86, x86-64, etc.).
  • Open source.

The first thing what we need to do is just download a module of Parallel Python, as you see below I leave one link where you can find it, download whichever you want.

Decompress it, and open the directory created, then type the following:

sudo setup.py install

We tested an example called sum_primes.py using two netbooks with Atom processor and a MacBookPro with i5 processor, before to see results I take some screenshots using just the MacBookPro.

 And now the results adding the two netbooks.

As you saw in the second one we have less time considerable than the first one, another thing that we saw is the warning that said statistics provided adove is not accuarte due to job rescheduling, it may occurs because they work with a little porcentage of time.

I took screenshots from my activity monitor to prove that the processor is using the top.



jueves, 16 de febrero de 2012

My report #3

I can't install CUDA in my Ubuntu and I crashed it, now I can't start with de GUI and I couldn't try those things that I learned.

What I think to do?

The first thing that I need to do is fix my Ubuntu, then install CUDA again, and after all try for some examples those I was following in a good book about CUDA programming step by step.Then I'll find some examples in POSIX.

Who is the highest contributor in this week?

Well, I think that is Cecilia Urbina, because She did a good job in some programs those I saw, and I understand some things where I had issues.

jueves, 9 de febrero de 2012

My second contribution

To my second contribution I read a book called CUDA by Example: An Introduction to General-Purpose GPU Programming you can find it in amazon as you can see bellow I leave the link to check out that book.

I'll do some examples about CUDA programming because we need an introduction to this kind of programming environment.

lunes, 6 de febrero de 2012

Example Producer-Consumer with Python

Well let's start with this simple example about the Producer-Consumer problem as you may saw it in the last semester, if you didn't, don't worry about it I'm gonna explain it.

The producer-consumer problem illustrates the need for synchronization in systems where many processes share a resource, in this problem, two processes share a fixed-size buffer.One process produces information and puts it in the buffer, while the other process consumes information from the buffer.These processes do not take turns accessing the buffer, they both work concurrently.Instead processes, we're gonna use threads to solve that problem.

Now that we have defined the problem, we're gonna program using threads and a module called Condition, with Condition we can handle the behavoir from each thread, we need to handle one thread called Producer and another called Consumer without any kind of conflict.
from threading import Thread, Condition
import time, random

class Productor(Thread):
    def __init__(self, lista, condicion):
        self.lista = lista
        self.condicion = condicion
    def run(self):
        while True:
            lista = random.randint(0,10)
            print 'Condicion adquirida por %s' % self.name
            print '%d agregado a la lista por %s' %(lista, self.name)
            print 'Condicion notificada por %s'%self.name
            print 'Condicion liberada por %s'% self.name

class Consumidor(Thread):
    def __init__(self,lista,condicion):
        self.condicion = condicion
    def run(self):
        while True:
            print'condicion adquirida por %s'%self.name
            while True:
                if self.lista:
                    lista = self.lista.pop()
                    print '%d removido de la lista por %s' % (lista, self.name)
                print'Condicion espera por %s' % self.name
            print'condicion liberada por %s' % self.name

def main():
    lista = []
    condicion = Condition()
    hilo1 = Productor(lista, condicion)
    hilo2 = Consumidor(lista, condicion)


You'll see something like the picture below.
http://chuwiki.chuidiang.org/index.php?title=Hilos_en_python#Condition http://code.google.com/p/chuidiang-ejemplos/source/browse/trunk/python-hilos/src/threading_hilo_condition.py

jueves, 2 de febrero de 2012