Introduction: Hello World of Parallel Programming in Ubuntu With OpenMP


Hope you are having a nice day and continue so. In my second instructables, I would like to share a little titbits i had learned in ubuntu. I would like to share about basic of parallel programming in ubuntu.. Any comments or feedbacks throughout this instructable is appreciated. Stay tuned and follow this instructable..LET'S GO!!!

Step 1: Open Terminal

Let's get started, shall we?.First and foremost, we must open the terminal in ubuntu. as shown in image

Step 2: Open a Text Editor

There are many text editors in ubuntu. I prefer using pico.. to open your text editor simply type sudo "text editor name" for an example, when i want to open pico, i type this in my terminal:

sudo pico

user password will be asked, enter your password and you are in the text editor..Easy right? now let's go to the third step..

Step 3: Write,save and Compile the Code

We are going to write the code in C language. Writing the hello world code in C is the same everywhere. There are only minor differences in the code. Example of the code:


int main( int ac, char **av)


#pragma omp parallel // specify the code between the curly brackets is part of an OpenMP parallel section.


printf("Hello World!!!\n");


return 0;


Now, save the code as anyname.c and exit the text editor . Now lets compile the code first to see if there is any mistake.

To compile your code, simply type this in the terminal

gcc anyname.c -o anyname.out

if there is any problem in the code, you must fix it and compile again.Now to next step.

Step 4: Number of Threads and Running in OpenMp

Now that the code is correct when compiled, we can run it parallel form using OpenMp. firstly we determine number of threads we are going to use. type this in your terminal:


you can try changing the number of threads into numbers you like.

Then, we are going to compile it using the OpenMP. It is similar to normal compiling but with addition of a few words. The format is like this:

gcc -fopenmp anyname.c -o anyname.out

after that, you can run the program. To run the program, type this into your terminal:


you will find out that the hello world prints out as many times as your thread number. Well, test with more numbers and see what happens!! That's all for now, I will try to share with all of you whatever knowledge i have next time. Happy PROGRAMMING!!


Nostoc (author)2015-04-08

Why do you run pico as root?

halim930112 (author)Nostoc2015-04-08

Well, i am a bit more familiar using pico.. i tried using vim but i got confused :( can also use gedit text editor and many others but basic principle is the same

neliason (author)halim9301122015-04-09

I think the question is not why you are running pico, but rather why you are running it as root. Why are you running it as root?

Usually there is no need to use sudo (running a program as root) to start your text editor, as long as you aren't editing system files. Just write pico (or whatever editor you use). You should not run programs as root unless you really have to. And most often not even then

halim930112 (author)neliason2015-04-09

I am sorry for my lack of knowledge.. I guess I did not study smart enough.. I will make sure that these mistakes would not occur next time. Thank you very much for the comments and knowledge. With your explanation, I will try to improve myself and my instructables. ;)

neliason (author)halim9301122015-04-10

No worries mate! I hope I didn't come across as hostile. English is not my native language =) Common enough newbie mistake, the sudo-thingie, though. Best to help it not spread ;) Keep up the good work!

About This Instructable




More by halim930112:Arduino Systems: Simple Bluetooth Door LockVoice To Arduino: Control LEDs using MIT Speech RecognizerExperiment for Fun: Morse Code Encrypter Using Arduino and Smartphone!!!!
Add instructable to: