Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
P
PP-04-MPI
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-04-MPI
Commits
9bffb675
Commit
9bffb675
authored
Nov 29, 2023
by
mohamadbashar.disoki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HelloWorld MPI
parents
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
0 deletions
+75
-0
README.md
README.md
+39
-0
hello_world.c
hello_world.c
+33
-0
mpi_hosts
mpi_hosts
+3
-0
No files found.
README.md
0 → 100644
View file @
9bffb675
# MPI LAB
## Prepare your User
To establish ssh connection between master and slaves without prompt required password we copy
public id on slave machines as following
```
$ ssh-keygen (dont use any passphrase)
$ ssh-copy-id mpiuser@slave1
$ ssh-copy-id mpiuser@slave2
```
## Running MPI programs
if you want to compile your own code, the name of which let’s say is
*mpi_sample.c*
, you will compile it
the way given below, to generate an executable
*mpi_sample*
.
```
mpicc -o mpi_sample mpi_sample.c
```
**Note**
: compile your code within the
**/nfs**
shared directory
To run it only in your machine (with 2 processes), you do
```
mpirun -np 2 ./mpi_sample
```
Now, to run it within a cluster (add the hostname of the cluster's node you want to use),
```
mpirun -np 5 -hosts master,localhost ./mpi_sample
```
Or specify the same in a hostfile
```
mpirun -np 3 -f mpi_hosts ./mpi_sampl
```
hello_world.c
0 → 100644
View file @
9bffb675
// An intro MPI hello world program that uses MPI_Init, MPI_Comm_size,
// MPI_Comm_rank, MPI_Finalize, and MPI_Get_processor_name.
//
#include <mpi.h>
#include <stdio.h>
int
main
(
int
argc
,
char
**
argv
)
{
// Initialize the MPI environment. The two arguments to MPI Init are not
// currently used by MPI implementations, but are there in case future
// implementations might need the arguments.
MPI_Init
(
NULL
,
NULL
);
// Get the number of processes
int
world_size
;
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
world_size
);
// Get the rank of the process
int
world_rank
;
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
world_rank
);
// Get the name of the processor
char
processor_name
[
MPI_MAX_PROCESSOR_NAME
];
int
name_len
;
MPI_Get_processor_name
(
processor_name
,
&
name_len
);
// Print off a hello world message
printf
(
"Hello world from processor %s, rank %d out of %d processors
\n
"
,
processor_name
,
world_rank
,
world_size
);
// Finalize the MPI environment. No more MPI calls can be made after this
MPI_Finalize
();
}
\ No newline at end of file
mpi_hosts
0 → 100644
View file @
9bffb675
master
slave1
slave2
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