Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
P
PP-06-OpenMP-CUDA
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohamadbashar.disoki
PP-06-OpenMP-CUDA
Commits
90a9f070
Commit
90a9f070
authored
Jan 25, 2024
by
mohamadbashar.disoki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update OpenMP
parent
4104e57c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
129 additions
and
14 deletions
+129
-14
out
OpenMP/out
+0
-0
parallelFor.c
OpenMP/parallelFor.c
+35
-0
raceCondition.c
OpenMP/raceCondition.c
+3
-9
reduction.c
OpenMP/reduction.c
+13
-3
sync_Barrier_ordered.c
OpenMP/sync_Barrier_ordered.c
+33
-0
sync_lock.c
OpenMP/sync_lock.c
+2
-2
waitCondition.c
OpenMP/waitCondition.c
+43
-0
No files found.
OpenMP/out
deleted
100755 → 0
View file @
4104e57c
File deleted
OpenMP/parallelFor.c
0 → 100644
View file @
90a9f070
#include "omp.h"
#include "stdlib.h"
#include "stdio.h"
void
simpleParalleloop
(
int
n
,
float
*
a
,
float
*
b
,
float
*
res
)
{
int
index
;
#pragma omp parallel for num_threads(4)
for
(
index
=
1
;
index
<
n
;
index
++
)
/* index is private by default */
{
res
[
index
]
=
(
a
[
index
]
+
b
[
index
]);
}
}
void
main
(
int
count
,
char
*
arg
[])
{
int
n
=
count
>
1
?
atoi
(
arg
[
1
])
:
10
;
float
a
[
n
],
b
[
n
],
res
[
n
];
//set array a values
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
a
[
i
]
=
i
*
i
;
b
[
i
]
=
i
;
}
simpleParalleloop
(
n
,
a
,
b
,
res
);
printf
(
"
\n
The Result Is:
\r\n
"
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
printf
(
"%f, "
,
res
[
i
]);
printf
(
"
\n
"
);
}
\ No newline at end of file
OpenMP/raceCondition.c
View file @
90a9f070
...
@@ -6,24 +6,18 @@
...
@@ -6,24 +6,18 @@
void
start
()
void
start
()
{
{
int
x
=
2
;
int
x
=
2
;
#pragma omp parallel num_threads(
20
)
#pragma omp parallel num_threads(
6
)
{
{
int
threadId
=
omp_get_thread_num
();
int
threadId
=
omp_get_thread_num
();
if
(
threadId
==
5
)
if
(
threadId
==
0
)
x
=
5
;
x
=
5
;
else
else
printf
(
"I am Thread %d and for me x=%d
\n
"
,
threadId
,
x
);
printf
(
"I am Thread %d and for me x=%d
\n
"
,
threadId
,
x
);
#pragma omp barrier
printf
(
"After barrier => I'am thread %d and x=%d
\n
"
,
threadId
,
x
);
}
}
}
}
void
main
(
int
count
,
char
*
arg
[])
void
main
(
int
count
,
char
*
arg
[])
{
{
start
();
start
();
}
}
\ No newline at end of file
OpenMP/reduction.c
View file @
90a9f070
...
@@ -5,6 +5,10 @@
...
@@ -5,6 +5,10 @@
//simple example to demonstrate race condition in parallel programs and barrier
//simple example to demonstrate race condition in parallel programs and barrier
void
start
()
void
start
()
{
{
#pragma omp parallel num_threads(12)
{
int
threadId
=
omp_get_thread_num
();
int
i
=
0
,
length
=
10
;
int
i
=
0
,
length
=
10
;
int
array
[
length
];
int
array
[
length
];
for
(
i
=
0
;
i
<
length
;
i
++
)
for
(
i
=
0
;
i
<
length
;
i
++
)
...
@@ -18,11 +22,17 @@ void start()
...
@@ -18,11 +22,17 @@ void start()
sum
+=
array
[
index
];
sum
+=
array
[
index
];
//calculate average
//calculate average
avg
=
sum
/
(
double
)
length
;
#pragma omp barrier
#pragma omp single
{
avg
=
sum
/
(
double
)
length
;
printf
(
"Average is avg = %f
\n
"
,
avg
);
printf
(
"Average is avg = %f
\n
"
,
avg
);
}
}
}
}
void
main
(
int
count
,
char
*
arg
[])
void
main
(
int
count
,
char
*
arg
[])
{
{
start
();
start
();
}
}
\ No newline at end of file
OpenMP/sync_Barrier_ordered.c
0 → 100644
View file @
90a9f070
#include <stdio.h>
#include <omp.h>
//simple example to demonstrate race condition in parallel programs and barrier
void
start
()
{
int
x
=
2
;
#pragma omp parallel num_threads(6)
{
int
threadId
=
omp_get_thread_num
();
if
(
threadId
==
0
)
x
=
5
;
else
printf
(
"I am Thread %d and for me x=%d
\n
"
,
threadId
,
x
);
#pragma omp barrier
{
#pragma ordered
printf
(
"After Barrier => I am Thread %d and for me x=%d
\n
"
,
threadId
,
x
);
#pragma ordered
printf
(
"After Order => I am Thread %d and for me x=%d
\n
"
,
threadId
,
x
);
}
}
}
void
main
(
int
count
,
char
*
arg
[])
{
start
();
}
\ No newline at end of file
OpenMP/sync_lock.c
View file @
90a9f070
...
@@ -29,11 +29,11 @@ void start()
...
@@ -29,11 +29,11 @@ void start()
}
}
omp_destroy_lock
(
&
lock
);
}
}
}
}
void
main
(
int
count
,
char
*
arg
[])
void
main
(
int
count
,
char
*
arg
[])
{
{
start
();
start
();
}
}
\ No newline at end of file
OpenMP/waitCondition.c
0 → 100644
View file @
90a9f070
#include <omp.h>
#include <stdio.h>
void
main
(
int
count
,
char
*
arg
[])
{
int
flag
=
0
;
#pragma omp parallel num_threads(3)
{
int
threadId
=
omp_get_thread_num
();
if
(
threadId
==
0
)
{
/* Set flag to release thread 1 */
#pragma omp atomic update
flag
++
;
/* Flush of flag is implied by the atomic directive */
}
else
if
(
threadId
==
1
)
{
/* Loop until we see that flag reaches 1*/
#pragma omp flush(flag)
while
(
flag
<
1
)
{
#pragma omp flush(flag)
}
printf
(
"Thread 1 awoken
\n
"
);
/* Set flag to release thread 2 */
#pragma omp atomic update
flag
++
;
/* Flush of flag is implied by the atomic directive */
}
else
if
(
threadId
==
2
)
{
/* Loop until we see that flag reaches 2 */
#pragma omp flush(flag)
while
(
flag
<
2
)
{
#pragma omp flush(flag)
}
printf
(
"Thread 2 awoken
\n
"
);
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment