Author Topic: Integrate OpenMP into GLBasic  (Read 2361 times)

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2554
    • View Profile
Integrate OpenMP into GLBasic
« on: 2012-Jul-03 »
OpenMP (See... http://bisqwit.iki.fi/story/howto/openmp/#IntroductionToOpenmpInC ) has been around for a while now in C++, it allows C code to go multi-threaded with almost none of the usual source complications. I was thinking that this may integrate well with the GLB compiler, after all (in theory :P) you just insert some C++ compiler #pragmas to make a normal single threaded piece of source into a multi-threaded one. No extra C source modifications is are needed to support extra cores in your code.

The way OpenMP works is pretty simple, you mark out some pieces of code(using #pragmas) and then choose what method of threading you want the code to run under. So for example...

Code: GLBasic [Select]
#pragma omp parallel
  {
    // Code inside this region runs in parallel.
    printf("Hello!\n");
  }
 

This would create 4 "Hello!"s on a quad core, or just 2 in a dual core system.

In GLB it may look like something like this...

Code: GLBasic [Select]
THREADPARALLEL(TRUE)
  STDOUT "Hello!\n"
THREADPARALLEL(FALSE)

Or whatever, the point is that the control of the threading model would be completely with the Basic coder. It would allow GLBasic to go completely multi-threaded without the usual complex in-line C++ when not using something like OpenMP.

Just a suggestion.  :)

Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3338
  • Integrated Brain
    • View Profile
Re: Integrate OpenMP into GLBasic
« Reply #1 on: 2012-Jul-03 »
I think it´s very interesting, can use all cores of CPU, and if this works in mobile devices can be very usefull!!!

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4971
  • O Rly?
    • View Profile
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2554
    • View Profile
Re: Integrate OpenMP into GLBasic
« Reply #3 on: 2012-Jul-03 »
the threads-library works very well - have used it for more than a year now.  Having said that, OpenMP offers a lot more than mere threads...
Yes I saw that lib too, OpenMP does offer a lot more and I thought that since it should be in theory only a matter of inserting some pragma codes in the GLB generated C code with some extra compiler command line options, it may be feasible to add it to GLBasics compile chain. It would certainly bring GLB bang up to date with multicore processing IMHO.
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10662
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Integrate OpenMP into GLBasic
« Reply #4 on: 2012-Jul-04 »
but you need a compiler that supports it. :)

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2554
    • View Profile
Re: Integrate OpenMP into GLBasic
« Reply #5 on: 2012-Jul-04 »
GCC support is there and it's built into XCode as a project option too.
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)