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
a1ba171c
Commit
a1ba171c
authored
11 months ago
by
Jason R Wilson
Browse files
Options
Downloads
Patches
Plain Diff
files for lecture 21
parent
195fd256
Branches
Branches containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
L21/mpi_reduce.c
+58
-0
58 additions, 0 deletions
L21/mpi_reduce.c
L21/mpi_reduce.sh
+20
-0
20 additions, 0 deletions
L21/mpi_reduce.sh
L21/mpi_reduce_64_1.out
+7
-0
7 additions, 0 deletions
L21/mpi_reduce_64_1.out
with
85 additions
and
0 deletions
L21/mpi_reduce.c
0 → 100644
+
58
−
0
View file @
a1ba171c
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<mpi.h>
int
main
(
int
argc
,
char
*
argv
[])
{
MPI_Init
(
&
argc
,
&
argv
);
// MPI_COMM_WORLD is the default communicator that contains all ranks
int
rank
,
size
;
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
rank
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
size
);
char
node_name
[
MPI_MAX_PROCESSOR_NAME
];
int
node_name_len
;
MPI_Get_processor_name
(
node_name
,
&
node_name_len
);
// make sure we are not running on a login node!
if
((
strcmp
(
node_name
,
"tinkercliffs1"
)
==
0
)
||
(
strcmp
(
node_name
,
"tinkercliffs2"
)
==
0
))
{
printf
(
"error : running on login node %s!
\n
"
,
node_name
);
return
1
;
}
// get the number of rounds from command line
if
(
argc
<
3
)
{
printf
(
"Command usage : %s %s
\n
"
,
argv
[
0
],
"rounds"
,
"seed"
);
return
1
;
}
int
rounds
=
atoi
(
argv
[
1
]);
int
seed
=
atoi
(
argv
[
2
]);
srandom
(
seed
+
rank
);
// start the timer
double
start_time
,
end_time
;
start_time
=
MPI_Wtime
();
// random sum
int
total_sum
=
0
;
for
(
int
round
=
0
;
round
<
rounds
;
round
++
)
{
int
round_sum
=
random
()
%
5
;
int
number
=
round_sum
;
MPI_Reduce
(
&
number
,
&
round_sum
,
1
,
MPI_INT
,
MPI_SUM
,
0
,
MPI_COMM_WORLD
);
total_sum
+=
round_sum
;
}
// stop the timer
end_time
=
MPI_Wtime
();
// print results
if
(
rank
==
0
)
{
printf
(
"elapsed time = %.4f seconds
\n
"
,
end_time
-
start_time
);
printf
(
"rounds = %d, seed = %d, sum = %d
\n
"
,
rounds
,
seed
,
total_sum
);
}
MPI_Finalize
();
}
This diff is collapsed.
Click to expand it.
L21/mpi_reduce.sh
0 → 100644
+
20
−
0
View file @
a1ba171c
#!/bin/bash
#SBATCH -A cmda3634_rjh
#SBATCH -p normal_q
#SBATCH -t 5
#SBATCH --nodes=64
#SBATCH --ntasks-per-node=1
#SBATCH -o mpi_reduce.out
# Go to the directory where the job was submitted
cd
$SLURM_SUBMIT_DIR
# Load the modules we need for MPI
module load matplotlib
# Build the executable
mpicc
-o
mpi_reduce mpi_reduce.c
# Run mpi_reduce
mpiexec
-n
$SLURM_NTASKS
--map-by
ppr:
$SLURM_NTASKS_PER_NODE
:node ./mpi_reduce
$1
$2
This diff is collapsed.
Click to expand it.
L21/mpi_reduce_64_1.out
0 → 100644
+
7
−
0
View file @
a1ba171c
[jasonwil@tinkercliffs2 L21]$ sbatch mpi_reduce.sh 500000 1234
[jasonwil@tinkercliffs2 L21]$ squeue -u jasonwil
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
2300544 normal_q mpi_redu jasonwil R 0:02 64 tc[003-004,006,009-010,012-013,015-016,018,020,022,024-027,032,035,037,046,049-053,056,059,061,066-067,070-071,075,079-087,089-090,095,099-101,104,133-134,179-181,196-201,239-240,253-254]
[jasonwil@tinkercliffs2 L21]$ cat mpi_reduce.out
elapsed time = 1.1595 seconds
rounds = 500000, seed = 1234, sum = 64020814
\ No newline at end of file
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