Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cmda3634_materials
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
srigavili
cmda3634_materials
Commits
d0324930
Commit
d0324930
authored
11 months ago
by
Jason R Wilson
Browse files
Options
Downloads
Patches
Plain Diff
files
parent
6f9ce7a7
Branches
Branches containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
PSA02/omp_sum_v1.c
+49
-0
49 additions, 0 deletions
PSA02/omp_sum_v1.c
PSA02/omp_sum_v1.sh
+24
-0
24 additions, 0 deletions
PSA02/omp_sum_v1.sh
PSA02/omp_sum_v2.c
+55
-0
55 additions, 0 deletions
PSA02/omp_sum_v2.c
PSA02/omp_sum_v2.sh
+24
-0
24 additions, 0 deletions
PSA02/omp_sum_v2.sh
with
152 additions
and
0 deletions
PSA02/omp_sum_v1.c
0 → 100644
+
49
−
0
View file @
d0324930
#include
<stdio.h>
#include
<stdlib.h>
#include
<omp.h>
int
main
(
int
argc
,
char
*
argv
[])
{
/* get N and thread_count from command line */
if
(
argc
<
3
)
{
printf
(
"Command usage : %s %s %s
\n
"
,
argv
[
0
],
"N"
,
"thread_count"
);
return
1
;
}
long
long
N
=
atol
(
argv
[
1
]);
int
thread_count
=
atoi
(
argv
[
2
]);
omp_set_num_threads
(
thread_count
);
/* start the timer */
double
start_time
,
end_time
;
start_time
=
omp_get_wtime
();
/* calculate the thread sums in parallel */
long
long
thread_sums
[
thread_count
];
#pragma omp parallel default(none) shared(N,thread_sums)
{
int
thread_num
=
omp_get_thread_num
();
thread_sums
[
thread_num
]
=
0
;
#pragma omp for
for
(
long
long
i
=
1
;
i
<=
N
;
i
++
)
{
thread_sums
[
thread_num
]
+=
i
;
}
}
/* add the results of the thread_sums */
long
long
sum
=
0
;
for
(
int
i
=
0
;
i
<
thread_count
;
i
++
)
{
sum
+=
thread_sums
[
i
];
}
/* stop the timer */
end_time
=
omp_get_wtime
();
/* print results */
printf
(
"thread_count = %d, "
,
thread_count
);
printf
(
"elapsed time = %g
\n
"
,
end_time
-
start_time
);
printf
(
" N = %llu, "
,
N
);
printf
(
"sum = %llu, "
,
sum
);
printf
(
"N*(N+1)/2 = %llu
\n
"
,(
N
/
2
)
*
(
N
+
1
));
}
This diff is collapsed.
Click to expand it.
PSA02/omp_sum_v1.sh
0 → 100644
+
24
−
0
View file @
d0324930
#!/bin/bash
#SBATCH -A cmda3634_rjh
#SBATCH -p normal_q
#SBATCH -t 5
#SBATCH --cpus-per-task=4
#SBATCH -o omp_sum_v1.out
# Go to the directory where the job was submitted
cd
$SLURM_SUBMIT_DIR
# Load the modules
module load matplotlib
# Build the executable
gcc
-o
omp_sum_v1 omp_sum_v1.c
-fopenmp
# OpenMP settings
export
OMP_NUM_THREADS
=
$SLURM_CPUS_PER_TASK
export
OMP_PROC_BIND
=
true
# run omp_sum
./omp_sum_v1 200000000 1
./omp_sum_v1 200000000 2
./omp_sum_v1 200000000 4
This diff is collapsed.
Click to expand it.
PSA02/omp_sum_v2.c
0 → 100644
+
55
−
0
View file @
d0324930
#include
<stdio.h>
#include
<stdlib.h>
#include
<omp.h>
#define PAD_SIZE 128
typedef
struct
thread_sum_s
{
long
long
sum
;
int
pad
[
PAD_SIZE
];
}
thread_sum_type
;
int
main
(
int
argc
,
char
*
argv
[])
{
/* get N and thread_count from command line */
if
(
argc
<
3
)
{
printf
(
"Command usage : %s %s %s
\n
"
,
argv
[
0
],
"N"
,
"thread_count"
);
return
1
;
}
long
long
N
=
atol
(
argv
[
1
]);
int
thread_count
=
atoi
(
argv
[
2
]);
omp_set_num_threads
(
thread_count
);
/* start the timer */
double
start_time
,
end_time
;
start_time
=
omp_get_wtime
();
/* calculate the thread sums in parallel */
thread_sum_type
thread_sums
[
thread_count
];
#pragma omp parallel default(none) shared(N,thread_sums)
{
int
thread_num
=
omp_get_thread_num
();
thread_sums
[
thread_num
].
sum
=
0
;
#pragma omp for
for
(
long
long
i
=
1
;
i
<=
N
;
i
++
)
{
thread_sums
[
thread_num
].
sum
+=
i
;
}
}
/* add the results of the thread_sums */
long
long
sum
=
0
;
for
(
int
i
=
0
;
i
<
thread_count
;
i
++
)
{
sum
+=
thread_sums
[
i
].
sum
;
}
/* stop the timer */
end_time
=
omp_get_wtime
();
/* print results */
printf
(
"thread_count = %d, "
,
thread_count
);
printf
(
"elapsed time = %g
\n
"
,
end_time
-
start_time
);
printf
(
" N = %llu, "
,
N
);
printf
(
"sum = %llu, "
,
sum
);
printf
(
"N*(N+1)/2 = %llu
\n
"
,(
N
/
2
)
*
(
N
+
1
));
}
This diff is collapsed.
Click to expand it.
PSA02/omp_sum_v2.sh
0 → 100644
+
24
−
0
View file @
d0324930
#!/bin/bash
#SBATCH -A cmda3634_rjh
#SBATCH -p normal_q
#SBATCH -t 5
#SBATCH --cpus-per-task=4
#SBATCH -o omp_sum_v2.out
# Go to the directory where the job was submitted
cd
$SLURM_SUBMIT_DIR
# Load the modules
module load matplotlib
# Build the executable
gcc
-o
omp_sum_v2 omp_sum_v2.c
-fopenmp
# OpenMP settings
export
OMP_NUM_THREADS
=
$SLURM_CPUS_PER_TASK
export
OMP_PROC_BIND
=
true
# run omp_sum
./omp_sum_v2 200000000 1
./omp_sum_v2 200000000 2
./omp_sum_v2 200000000 4
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment