Skip to content

Commit 053e292

Browse files
committed
Added some changes
1 parent 7d39ebd commit 053e292

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/libminiomp.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ init_miniomp(void) {
1717
parse_env();
1818
// Initialize Pthread data structures
1919
// Initialize Pthread thread-specific data, useful for example to store the OpenMP thread identifier
20-
pthread_key_create(&miniomp_specifickey, NULL);
2120
// Initialize OpenMP default lock and default barrier
2221
// Initialize OpenMP workdescriptors for for and single
2322
// Initialize OpenMP task queue for task and taskloop

src/parallel.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,28 @@ miniomp_thread_t *miniomp_threads;
99
miniomp_parallel_t *miniomp_parallel;
1010

1111
// Declaration of per-thread specific key
12-
pthread_key_t miniomp_specifickey;
12+
extern pthread_key_t miniomp_specifickey;
1313

1414
void miniomp_thread_init(miniomp_thread_t * thread, unsigned int id, void (*fn) (void *), miniomp_parallel_t *region){
1515
thread->id = id;
1616
thread->region = region;
17-
pthread_setspecific(miniomp_specifickey, thread);
1817
pthread_create(&(thread->pthread), NULL, fn, thread);
1918
}
2019

2120

2221
// This is the prototype for the Pthreads starting function
2322
void worker(void *args) {
23+
pthread_key_create(&miniomp_specifickey, NULL);
2424
miniomp_thread_t *thread = args;
25+
pthread_setspecific(miniomp_specifickey, thread);
2526
miniomp_parallel_t *parallel = thread->region;
2627
int id = thread->id;
2728
printf("Thread %d initialized\n", id);
2829
void (*fn) (void *) = parallel->fn;
2930
void * data = parallel->fn_data;
30-
//printf("Thread %d fn and data done\n", id);
31+
printf("Thread %d fn and data done\n", id);
3132
fn(data);
32-
//printf("Executed fn in thread %d", id);
33-
// insert all necessary code here for:
34-
// 1) save thread-specific data
35-
// 2) invoke the per-threads instance of function encapsulating the parallel region
36-
// 3) exit the function
33+
printf("Executed fn in thread %d\n", id);
3734
}
3835

3936
void
@@ -50,6 +47,7 @@ GOMP_parallel (void (*fn) (void *), void *data, unsigned num_threads, unsigned i
5047
miniomp_thread_init(&miniomp_threads[i], i, worker, miniomp_parallel);
5148
}
5249
for (int i=0; i < num_threads; i++){
50+
printf("Thread %i arrived to join\n", i);
5351
pthread_join(miniomp_threads[i].pthread, NULL);
5452
}
5553
free(miniomp_threads);

0 commit comments

Comments
 (0)