Chipset

General OpenMP discussion

Chipset

Postby ankit_mait_07 » Tue Jun 24, 2008 8:15 am

Hi...
First i would like to know will OMP code only work on a Dual Core machine??
Is there a simulator which can help it run on a single core machine??
I have a Intel 82915G express chipset which i belive is a dual core system with Hyperthreading but my code runs as if it is a sequential code...

Code: Select all
// test.cpp : main project file.

#include "stdafx.h"
#include <omp.h>
#include<conio.h>
//#include<iostream.h>

using namespace System;
//using namespace st;

int main(array<System::String ^> ^args)
{
   
      double a(0.0), b(0.0);
    #pragma omp parallel for default(shared) schedule(static) reduction(+:a) reduction(+:b)
        for (int i = 100; i >= 0; --i)
      {
          a += (double) i;
          b += 1.0/i;
        if(omp_get_thread_num()==0)
        {
           Console::WriteLine(L"Hello World");
        }
        }
        Console::WriteLine(a);
     getch();
}


it prints "hello world 101 times
however if i change the condition to " if(omp_get_thread_num()==1)" Hello World is not printed...
Help??

Thanks
Regards
Ankit
ankit_mait_07
 
Posts: 14
Joined: Wed Jun 18, 2008 11:20 am

Re: Chipset

Postby ankit_mait_07 » Tue Jun 24, 2008 10:19 am

I don't know why this code is giving an unexpected output...
Code: Select all
#include "stdafx.h"
#include <omp.h>
#include<conio.h>
//#include
<iostream.h>

using namespace System;
//using namespace st;

int main(array<System::String ^> ^args)
{
   
      double a(0.0), b(0.0);
    #pragma omp parllel for default(shared) schedule(static) reduction(+:a) reduction(+:b)
        for (int i = 100; i >= 0; --i)
      {
          a += (double) i;
          b += 1.0/i;
        if(omp_get_thread_num()==1)
        {
           Console::Write(i);
           Console::WriteLine("Hello World");
        }
        }
        Console::WriteLine(a);
     _getch();
}


the output is:

Code: Select all
[code]
5050
[/code]


why???
regards
ankit
ankit_mait_07
 
Posts: 14
Joined: Wed Jun 18, 2008 11:20 am

Re: Chipset

Postby ejd » Tue Jun 24, 2008 5:33 pm

As for your first question, the program is not running in parallel. Do one of the following:
  • put a num_threads(2) clause on the parallel for pragma
  • issue a omp_set_dynamic(0) and then a omp_num_threads(2) call before the parallel region
  • set environment variables OMP_DYNAMIC FALSE and OMP_NUM_THREADS 2
Any one of these should get the program to run in parallel if you have compiled it with the OpenMP flag.

It should run on a hyperthreaded chip just fine, though you will most likely not see a speedup. If you haven't done anything "fancy" (i.e., requiring multiple threads as in synchronization across threads) you can run an OpenMP program on one processor (core). Obviously you will not see a speedup - but it is quite often the way to start debugging a parallel program - by running it on one thread.

As for the second question, your program is wrong - you have "parllel" rather than "parallel". The other part is that the program is not being being run in parallel so "omp_get_thread_num() == 1" is never true and thus the values of "i" and "Hello World" are not being printed. The "5050" is the value of "a" after the loop.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: Chipset

Postby ankit_mait_07 » Wed Jun 25, 2008 10:45 pm

hi.
Thanks a lot..
Ankit
ankit_mait_07
 
Posts: 14
Joined: Wed Jun 18, 2008 11:20 am


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 5 guests