Permalink
Browse files

[6model/c] use OpenMP for threading if available

  • Loading branch information...
1 parent 5fa7d52 commit 24a54a48cb9deca0e52266c5785b73b470fac85d @mberends mberends committed Aug 10, 2011
Showing with 133 additions and 127 deletions.
  1. +22 −23 c/Configure.bat
  2. +3 −5 c/Configure.sh
  3. +12 −2 c/src/threads.c
  4. +9 −9 c/t/01-toolchain/01a-cc.c
  5. +1 −1 c/t/01-toolchain/01b-timing.c
  6. +12 −7 c/t/Test.h
  7. +74 −80 c/tools/build/Configure.c
View
@@ -7,31 +7,30 @@
:: - Add a --help option and provide for more options in general
@echo off
-:: Determine whether the C compiler is MSVC or GCC, by attempting to use
-:: them in that order.
+:: Determine whether the C compiler is cl (Microsoft C) or mingw32-gcc,
+:: by attempting to use each one on a very small C program.
echo int main(int argc, char * argv[]) { return 0; } >tools\build\temp.c
cl -nologo -Fotools\build\temp.obj -Fetools\build\temp.exe tools\build\temp.c >nul 2>nul
-if not errorlevel 1 goto :msvc
-gcc -otools\build\temp.exe tools\build\temp.c
-if not errorlevel 1 goto :gcc
-cc tools\build\temp.c
-if not errorlevel 1 goto :cc
-echo Sorry! Cannot compile with eith cl, gcc or cc. Please fix.
+if not errorlevel 1 goto cl
+mingw32-gcc -otools\build\temp.exe tools\build\temp.c
+if not errorlevel 1 goto mingw32-gcc
+echo Sorry! Cannot compile with either cl or mingw32-gcc. Please fix.
if exist tools\build\temp.exe del tools\build\temp.exe
if exist tools\build\temp.obj del tools\build\temp.obj
if exist tools\build\temp.c del tools\build\temp.c
goto :end_of_script
-:msvc
+
+:cl
echo Detected Microsoft Visual C/C++ (cl.exe)
del tools\build\temp.obj tools\build\temp.exe tools\build\temp.c
-set COMPILER=MSVC
+set COMPILER=cl
goto :got_compiler
-:gcc
-echo Detected GNU Compiler Collection (gcc.exe)
+
+:mingw32-gcc
+echo Detected MinGW GCC (mingw32-gcc.exe)
del tools\build\temp.exe tools\build\temp.c
-set COMPILER=GCC
+set COMPILER=mingw32-gcc
goto :got_compiler
-:cc
:got_compiler
echo Compiling tools\build\Configure.c to tools\build\Configure.exe
@@ -47,10 +46,10 @@ echo Compiling tools\build\Configure.c to tools\build\Configure.exe
:: are not blessed with strcpy_s and so on, this project opts to
:: continue using the "older, less secure functions" and disable the
:: warnings with -D_CRT_SECURE_NO_WARNINGS
-set opts_msvc=-nologo -Wall -DCC=MSVC -D_CRT_SECURE_NO_WARNINGS -wd4820 -wd4668 -wd4255
-set opts_gcc=-Wall -DCC=GCC
-if "%COMPILER%"=="MSVC" cl %opts_msvc% -Fotools\build\Configure.obj -Fetools\build\Configure.exe tools\build\Configure.c
-if "%COMPILER%"=="GCC" gcc %opts_gcc% -otools\build\Configure.exe tools\build\Configure.c
+set opts_msc=-nologo -Wall -openmp -D_CRT_SECURE_NO_WARNINGS -wd4820 -wd4668 -wd4255
+set opts_gcc=-Wall -fopenmp
+if "%COMPILER%"=="cl" cl %opts_msvc% -Fotools\build\Configure.obj -Fetools\build\Configure.exe tools\build\Configure.c
+if "%COMPILER%"=="mingw32-gcc" mingw32-gcc %opts_gcc% -otools\build\Configure.exe tools\build\Configure.c
if errorlevel 1 goto :end_of_script
if exist tools\build\Configure.obj del tools\build\Configure.obj
:: echo Run tools\build\Configure.exe to create Makefile
@@ -61,9 +60,9 @@ tools\build\Configure.exe tools\build\Makefile.in Makefile
:: Notes
:: Configure.bat or Configure.cmd?
-:: There is almost no difference between the two file types (just something
-:: subtle about errorlevel), and in 6model/c they work the same. So on user
-:: friendliness grounds, .bat reassures the reader that the script will do
-:: only "simple" things.
-:: You could argue it the other way - we use cmd.exe, not command.com, so we
+:: Windows XP and later handle the two file types in almost exactly the
+:: same way (there is a minor detail about errorlevel). In 6model/c
+:: either file type would work the same. So for user friendliness, .bat
+:: reassures the user that the script does only simple things. There is
+:: the opposite rationale, that it needs cmd.exe not command.com, and
:: should use the extension that command.com cannot handle. Dunno...
View
@@ -1,7 +1,5 @@
#!/bin/sh
-# TODO
-# - Add a --help option and provide for more options in general
-export COMPILER=GCC
-set opts_gcc=-Wall -DCC=$COMPILER
-cc $opts_gcc -o tools/build/Configure tools/build/Configure.c
+# TODO: Add a --help option and provide for more options in general
+OPTS_GCC='-Wall -fopenmp'
+gcc $OPTS_GCC -o tools/build/Configure tools/build/Configure.c
tools/build/Configure tools/build/Makefile.in Makefile
View
@@ -5,6 +5,7 @@
/* is a very thin wrapper on Posix systems, and does a lightweight */
/* emulation elsewhere. */
+
#include "threads.h" /* thread_create */
@@ -38,9 +39,18 @@ thread_join(struct thread_info * info)
}
+/* Caution - do not underestimate the overheads of creating and */
+/* synchronizing threads. See for example the HPL-2004-209 report */
+/* below, stating that some of the machine code instructions took */
+/* over 100 machine cycles on a Pentium 4. More detailed and recent */
+/* performance figures would be very welcome. */
+
/* See also: */
/* Lawrence Livermore National Laboratory tutorials: */
-/* pthreads https://computing.llnl.gov/tutorials/pthreads/ */
-/* OpenMP https://computing.llnl.gov/tutorials/openMP/ */
+/* pthreads https://computing.llnl.gov/tutorials/pthreads/ */
+/* OpenMP https://computing.llnl.gov/tutorials/openMP/ */
+/* Threads Cannot be Implemented as a Library (may now be outdated): */
+/* http://www.hpl.hp.com/techreports/2004/HPL-2004-209.html */
+/* http://en.wikipedia.org/wiki/Lock-free_and_wait-free_algorithms */
/* end of threads.c */
@@ -20,7 +20,7 @@
#include <stdio.h> /* fclose fopen fprintf perror printf */
#include <stdlib.h> /* system */
-#ifdef _WIN32
+#if defined( _WIN32 )
#include <windows.h>
#define pclose _pclose
#define popen _popen
@@ -66,7 +66,7 @@ create_exe()
printf("ok 1 - create testexe.c\n");
/* test 2: compile the source file to an executable */
- #ifdef MSVC
+ #if defined( _MSC_VER )
status = system("cl -WX -Fetestexe.exe -nologo testexe.c >nul");
if (status==0)
status = unlink("testexe" EXT_OBJ);
@@ -88,7 +88,7 @@ run_exe()
int status, c;
FILE * childfile;
char inputbuffer[80], * pbuffer, * pbufferend, * testcommand;
- #ifdef _WIN32
+ #if defined( _WIN32 )
testcommand = ".\\testexe foo bar";
#else
testcommand = "./testexe foo bar";
@@ -103,7 +103,7 @@ run_exe()
/* test 4: read the output of the child process into inputbuffer */
pbuffer = inputbuffer; pbufferend = inputbuffer + 80 - 1;
- while ((c=getc(childfile))!=EOF) {
+ while ((c=getc(childfile)) != EOF) {
* pbuffer = c;
if (++pbuffer >= pbufferend) {
fprintf(stderr,"not ok 4 - buffer overflow\n");
@@ -172,7 +172,7 @@ create_lib()
"}\n"
);
fclose(testlib_sourcefile);
- #ifdef _WIN32
+ #if defined( _WIN32 )
#ifdef _MSC_VER
status = system("cl -LD -WX -nologo testlib.c >nul"); /* Visual C++ */
#else
@@ -203,7 +203,7 @@ load_lib()
char * error;
int result;
/* test 9: load the library */
- #ifdef _WIN32
+ #if defined( _WIN32 )
FARPROC pfunction;
testlib = LoadLibrary("./testlib.dll");
if (testlib==NULL) {
@@ -220,7 +220,7 @@ load_lib()
#endif
printf("ok 9 - load testlib" EXT_DYNLIB "\n");
- #ifdef _WIN32
+ #if defined( _WIN32 )
pfunction = GetProcAddress(testlib, "testfunction");
#else
dlerror(); /* clear any possible error */
@@ -240,7 +240,7 @@ load_lib()
printf("ok 12 - testfunction result\n");
else
printf("not ok 12 - testfunction result\n");
- #ifdef _WIN32
+ #if defined( _WIN32 )
result = ! FreeLibrary(testlib); /* returns 0 for failure! */
#else
result = dlclose(testlib);
@@ -264,7 +264,7 @@ remove_lib()
exit(14);
}
printf("ok 14 - remove testlib.c\n");
- #ifdef _MSC_VER
+ #if defined( _MSC_VER )
status = unlink("testlib" EXT_OBJ);
if (status) {
perror("01a-cc error 15:");
@@ -46,7 +46,7 @@ seconds_microseconds_sleep()
/* test 1 - time1 is nonzero */
sprintf(message, "clock returned %lld seconds and %d microseconds",
seconds1, microseconds1);
- ok(seconds1 > 0L && microseconds1 > 0, message);
+ ok(seconds1 > 0L, message);
/* test 2 - time2 >= time1 */
sprintf(message, "clock returned %lld seconds and %d microseconds",
View
@@ -2,25 +2,30 @@
/* Lightweight TAP (Test Anything Protocol) emitter in C macros. */
-/* Example usage:
-
-#include <string.h>
+/* SYNOPSIS
#include "../Test.h"
int
main(int argc, char * argv[])
{
- char s[7];
plan(1);
ok(1==1, "1 is equal to 1");
- is_ii(1+1, 2, "1 plus 1 is equal to 2");
- strcpy(s, "foo"); strcat(s, "bar");
- is_ss(s, "foobar", "strcpy and strcat");
+ is_ii(2 + 2, 4, "2 plus 2 equals 4");
return 0;
}
+*/
+/* DEFINITIONS
+plan(i);
+diag(s);
+is_ii(i1, i2, "integers match");
+is_ss(s1, s2, "strings match");
+ok(b, "any boolean expression");
+TODO: is_pp(p1, p2, "pointers match");
+TODO: done_testing();
*/
+
#include <stdio.h> /* printf */
int _test_number=0; /* yes, namespace pollution. patches welcome ;-) */
Oops, something went wrong.

0 comments on commit 24a54a4

Please sign in to comment.