Add this blog to Del.icio.us, Digg or Furl | Create Watchlist for this blog

Archive for the ‘C/C++’ Category

Intel C++ 10, OpenMP & OpenSuSE Linux

Friday, August 31st, 2007

OpenMP on Linux with Intel iccAs promised yesterday, I’ll try the OpenMP features of Intel C++ 10.0 for Linux today. Cause I’m lazy, I use a wide spread “Hello World” for OpenMP example, it is very simple and it’s only purpose is to demonstrate the basics of how to parallelize a code with OpenMP.

/***********************************************************
* FILE: omp_hello.c
* DESCRIPTION:
*   OpenMP Example - Hello World - C/C++ Version
*   In this simple example, the master thread
*   forks a parallel region. All threads in the team obtain
*   their unique thread number and print it. The master
*   thread only prints the total number of threads.  Two OpenMP
*   library routines are used to obtain the number of threads
*   and each thread's number.
* AUTHOR: Blaise Barney  5/99
* LAST REVISED: 04/06/05
************************************************************/
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>

int main (int argc, char **argv) {

int nthreads, tid;

/* Fork a team of threads giving them their own copies of variables */
#pragma omp parallel private(nthreads, tid)
  {

  /* Obtain thread number */
  tid = omp_get_thread_num();
  printf("Hello World from thread = %dn", tid);

  /* Only master thread does this */
  if (tid == 0)
    {
    nthreads = omp_get_num_threads();
    printf("Number of threads = %dn", nthreads);
    }

  }  /* All threads join master thread and disband */

}

To compile this example with icc you need the OpenMP switch turned on:

rainer@novotop:/tmp> icc -openmp omp_hello.c
omp_hello.c(22): (col. 1) remark: OpenMP DEFINED REGION
WAS PARALLELIZED.
rainer@novotop:/tmp> ./a.out
Hello World from thread = 0
Number of threads = 2
Hello World from thread = 1

Ok, that’s pretty cool. We saw how to parallelize a region and giving private variables to it. By the way, you can specify the number of threads OpenMP starts with the OMP_NUM_THREADS environment variable (export OMP_NUM_THREADS=4, then start a.out -> you get four thread outputs).
Next post will handle mutexes, semaphores, thread shared memory etc. in more depth.

About installing Intel C++ 10.0 on OpenSuSE 10.2
A good tutorial

Intel C++ 10.0 for linux

Thursday, August 30th, 2007

Get the most out of it

I like gcc very much but now I have a Intel Core 2 Duo notebook, and I think it’s time to get the most out of it. That’s why I go for the Intel C++ 10.0 compiler today.

Intel provides a “free for non-commercial usage” download, that’s pretty nice and one more reason to give’em a try!

The other thing I am really interested in is the openMP integration. If you had troubles with pthreads you know why!

Start of my report

Go to the download page, confirm non-commercial agreement, register with email address, then start downloading the 45 MB package (in the IA32 version).

Untar the package and as root type
./install.sh

The installation went smooth, had to agree to several license agreements, answer some question (always took the default). Until suddenly:


Your platform :
architecture = i686
kernel = 2.6.18
glibc = glibc-2.5-25
operating system = unknown

This product is supported for use with the following combinations :

Machine Type Kernel glibc

IA-32/Intel(R) 64 2.4.x 2.2.5
IA-32/Intel(R) 64 2.4.x 2.2.93
IA-32/Intel(R) 64 2.4.x 2.3.2
IA-32/Intel(R) 64 2.6.x 2.3.x
IA-32/Intel(R) 64 2.6.x 2.4.x
IA-32/Intel(R) 64 2.6.x 2.5.x

Would you like to perform an unsupported install of this product [yes/no] (no) ? :

At this point I face my fear but typed YES.
After some other questions (always answer with default) I finally got the “successful” message:


Successfully installed:

Substitute Headers for Intel(R) C++ Compiler for applications running on IA-32, Version 10.0 (10.0.023)
intel-isubh100023-10.0.023-1.i386.rpm

Intel(R) C++ Compiler for applications running on IA-32, Version 10.0 (10.0.023)
intel-icc100023-10.0.023-1.i386.rpm

Intel(R) Debugger for applications running on IA-32, Version 10.0 (10.0.023)
intel-iidb100023-10.0.023-1.i386.rpm

Intel(R) C++ Compiler features and plugins for integration into Eclipse* CDT development environment, Version 10.0 (10.0.023)
intel-icc_ide100023-10.0.023-1.i386.rpm

Intel(R) Debugger features and plugins for integration into Eclipse* CDT development environment, Version 10.0 (10.0.023)
intel-idb_ide100023-10.0.023-1.i386.rpm

First compilation

My first compilation will be a “Hello World” as it is good tradition in the C business:

#include <stdio.h>

int main(int argc, char **argv)
{
        fprintf(stdout, "Hello ICC Worldn");

        return 0;
}

To get the icc environment up, Intel delivers a Shell-Script. Source it then compile like this:
source /opt/intel/cc/10.0.023/bin/iccvars.sh
icc hello.c

Then run the result:
./a.out
Watch the output and be happy :-)
Hello ICC World

This is so great! Tomorrow I’ll report on first experiences with openMP!
See you soon!