• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Global headerfile of the OpenMP Testsuite */
2 
3 #ifndef OMP_TESTSUITE_H
4 #define OMP_TESTSUITE_H
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <omp.h>
9 
10 /* General                                                */
11 /**********************************************************/
12 #define LOOPCOUNT 1000 /* Number of iterations to slit amongst threads */
13 #define REPETITIONS 10 /* Number of times to run each test */
14 
15 /* following times are in seconds */
16 #define SLEEPTIME 1
17 
18 /* Definitions for tasks                                  */
19 /**********************************************************/
20 #define NUM_TASKS 25
21 #define MAX_TASKS_PER_THREAD 5
22 
23 #ifdef  _WIN32
24 // Windows versions of pthread_create() and pthread_join()
25 # include <windows.h>
26 typedef HANDLE pthread_t;
27 
28 // encapsulates the information about a pthread-callable function
29 struct thread_func_info_t {
30   void* (*start_routine)(void*);
31   void* arg;
32 };
33 
34 // call the void* start_routine(void*);
__thread_func_wrapper(LPVOID lpParameter)35 static DWORD __thread_func_wrapper(LPVOID lpParameter) {
36   struct thread_func_info_t* function_information;
37   function_information = (struct thread_func_info_t*)lpParameter;
38   function_information->start_routine(function_information->arg);
39   free(function_information);
40   return 0;
41 }
42 
43 // attr is ignored
pthread_create(pthread_t * thread,void * attr,void * (* start_routine)(void *),void * arg)44 static int pthread_create(pthread_t *thread, void *attr,
45                           void *(*start_routine) (void *), void *arg) {
46   pthread_t pthread;
47   struct thread_func_info_t* info;
48   info = (struct thread_func_info_t*)malloc(sizeof(struct thread_func_info_t));
49   info->start_routine = start_routine;
50   info->arg = arg;
51   pthread = CreateThread(NULL, 0, __thread_func_wrapper, info, 0, NULL);
52   if (pthread == NULL) {
53     fprintf(stderr, "CreateThread() failed: Error #%u.\n", GetLastError());
54     exit(1);
55   }
56   *thread = pthread;
57   return 0;
58 }
59 // retval is ignored for now
pthread_join(pthread_t thread,void ** retval)60 static int pthread_join(pthread_t thread, void **retval) {
61   int rc;
62   rc = WaitForSingleObject(thread, INFINITE);
63   if (rc == WAIT_FAILED) {
64     fprintf(stderr, "WaitForSingleObject() failed: Error #%u.\n",
65             GetLastError());
66     exit(1);
67   }
68   rc = CloseHandle(thread);
69   if (rc == 0) {
70     fprintf(stderr, "CloseHandle() failed: Error #%u.\n", GetLastError());
71     exit(1);
72   }
73   return 0;
74 }
75 #else
76 # include <pthread.h>
77 #endif
78 
79 #endif
80