Pointers for making good use of your processing cores

In the era of multicore processors, one may ask himself “how do I make use of all this processing power on my hands?”. I won’t be writing any in-depth material here, but rather spreading out some interesting pointers.

If you are coding in C/C++, you can give OpenMP a try. I haven’t tried it yet, but I surely want to, as it seems extremely easy: you just add a couple #pragma instructions in your code and it automagically parallelizes it for you! Really, check our their tutorials!

For those that are more Python-oriented, like me, you can try Parallel Python. Not only it can explore the available cores in your computer, but it may also use cores in other computers connected in your local network! I did some testing of this and it worked remarkably well. I plan on doing something fun with this someday.

Last, but not least, if you just have to run the same application several times and would like to use your several cores instead of queueing it all on a single one, then you might want to learn something about xargs… It can do the job for you!

Detailed explanation of the use of xargs is out of the scope of this blog post, so I’ll just point you to the -P switch: it controls how many simultaneous processes it should run at a time. As soon as one terminates, it spawns another one. Great, isn’t it? Credit goes to this blog.

What about you? Any tips for exploring the processing powers of multicore CPUs? Share in the comments!

Advertisements

Easy file sharing with Python

I have previously blogged about On-demand Web Server with Python, which is great to serve files you want people (or even yourself, remotely) to download from your computer. Unfortunately, it is unidirectional: people cannot upload files back to you. Luckily, that’s what we are going to address in this post!

Read the rest of this entry »

On-demand Web Server with Python

A friend of mine has just showed me something that is not only useful but extremely simple to use. I’d say it fits the mind-blowing category.

How many times have you wanted to serve a file on an HTTP server for someone to download it from? Well, just install Apache, you’d say. I used to do that, but it feels like overkill. Maybe Lighttpd? I honestly found it was easier to just host it somewhere else than install and configure any of these in case they’re not already in use.

But here’s another solution: use Python! It is installed by default on most Linux distributions, if not all. It is so widespread right now that, if you’re not using it already – be it for programming or as a dependency for something else you use – you will need it sooner than you think. And not only it should already be installed, it needs zero configuration!

Fire up your terminal and try this:

$ python -m SimpleHTTPServer 8000

Next, point your browser to http://localhost:8000. Voilà! You just got yourself a web server! In case you haven’t tried this yourself yet, a directory listing for the current directory should appear. Close it with Ctrl-C when you’re done with it.

Extra tip: you can create a directory under your home such as webjail, or whatever name suits you, and start your webserver from there. Create symbolic links for stuff you want avaiable so you can keep your other files “secret”. Unlike my previous Apache setups with public_html, symlinks do work, so there is no need for hard copies. The only difference from regular files is that they will show a “@” appended to the filename on the listing, but that’s not really an issue, is it? 😉