Integrate OpenMP into GLBasic

Previous topic - Next topic

bigsofty

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)

mentalthink

I think it´s very interesting, can use all cores of CPU, and if this works in mobile devices can be very usefull!!!

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

bigsofty

Quote from: Ocean 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)

Kitty Hello

but you need a compiler that supports it. :)

bigsofty

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)