-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomp_hello.c
39 lines (32 loc) · 997 Bytes
/
omp_hello.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* File: omp_hello.c
*
* Purpose: A parallel hello, world program that uses OpenMP
*
* Compile: gcc -g -Wall -fopenmp -o omp_hello omp_hello.c
* Run: ./omp_hello <number of threads>
*
* Input: none
* Output: A message from each thread
*
* IPP: Section 5.1 (pp. 211 and ff.)
*/
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
void Hello(void); /* Thread function */
/*--------------------------------------------------------------------*/
int main(int argc, char* argv[]) {
int thread_count = strtol(argv[1], NULL, 10);
# pragma omp parallel num_threads(thread_count)
Hello();
return 0;
} /* main */
/*-------------------------------------------------------------------
* Function: Hello
* Purpose: Thread function that prints message
*/
void Hello(void) {
int my_rank = omp_get_thread_num();
int thread_count = omp_get_num_threads();
printf("Hello from thread %d of %d\n", my_rank, thread_count);
} /* Hello */