21#define MAX_TASKS_PER_THREAD 5
39 #pragma omp parallel num_threads(nthreads)
48 #pragma omp parallel proc_bind(spread)
57 #pragma omp parallel proc_bind(close)
66 #pragma omp parallel proc_bind(master)
74 return ((
g_counter__ == -1) ? EXIT_FAILURE : EXIT_SUCCESS);
80typedef HANDLE pthread_t;
83struct thread_func_info_t {
84 void* (*start_routine)(
void*);
89static DWORD WINAPI __thread_func_wrapper(LPVOID lpParameter) {
90 struct thread_func_info_t* function_information;
91 function_information = (
struct thread_func_info_t*)lpParameter;
92 function_information->start_routine(function_information->arg);
93 free(function_information);
98static int pthread_create(pthread_t *thread,
void *attr,
99 void *(*start_routine) (
void *),
void *arg) {
101 struct thread_func_info_t* info;
102 info = (
struct thread_func_info_t*)malloc(
sizeof(
struct thread_func_info_t));
103 info->start_routine = start_routine;
105 pthread = CreateThread(NULL, 0, __thread_func_wrapper, info, 0, NULL);
106 if (pthread == NULL) {
107 fprintf(stderr,
"CreateThread() failed: Error #%u.\n",
108 (
unsigned) GetLastError());
115static int pthread_join(pthread_t thread,
void **retval) {
117 rc = WaitForSingleObject(thread, INFINITE);
118 if (rc == WAIT_FAILED) {
119 fprintf(stderr,
"WaitForSingleObject() failed: Error #%u.\n",
120 (
unsigned) GetLastError());
123 rc = CloseHandle(thread);
125 fprintf(stderr,
"CloseHandle() failed: Error #%u.\n",
126 (
unsigned) GetLastError());
static void go_parallel()
static void go_parallel_nthreads(int nthreads)
static void go_parallel_master()
static void go_parallel_spread()
static void go_parallel_close()
static int get_exit_value()