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
5a04e194
Commit
5a04e194
authored
Nov 29, 2023
by
mohamadbashar.disoki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Send Recv Example
parent
9bffb675
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
2 deletions
+45
-2
mpi_hosts
mpi_hosts
+2
-2
send_recv.c
send_recv.c
+43
-0
No files found.
mpi_hosts
View file @
5a04e194
master
slave1
slave2
slave1
user=mpiuser
slave2
user=mpiuser
send_recv.c
0 → 100644
View file @
5a04e194
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
int
main
(
int
argc
,
char
**
argv
)
{
// Initialize the MPI environment
MPI_Init
(
NULL
,
NULL
);
// Find out rank, size
int
world_rank
;
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
world_rank
);
int
world_size
;
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
world_size
);
// We are assuming at least 2 processes for this task
if
(
world_size
<
2
)
{
fprintf
(
stderr
,
"World size must be greater than 1 for %s
\n
"
,
argv
[
0
]);
MPI_Abort
(
MPI_COMM_WORLD
,
1
);
}
int
number
;
if
(
world_rank
==
0
)
{
// If we are rank 0, set the number to -1 and send it to process 1
number
=
-
1
;
MPI_Send
(
/* data = */
&
number
,
/* count = */
1
,
/* datatype = */
MPI_INT
,
/* destination = */
1
,
/* tag = */
0
,
/* communicator = */
MPI_COMM_WORLD
);
}
else
if
(
world_rank
==
1
)
{
MPI_Recv
(
/* data = */
&
number
,
/* count = */
1
,
/* datatype = */
MPI_INT
,
/* source = */
0
,
/* tag = */
0
,
/* communicator = */
MPI_COMM_WORLD
,
/* status = */
MPI_STATUS_IGNORE
);
printf
(
"Process 1 received number %d from process 0
\n
"
,
number
);
}
MPI_Finalize
();
}
\ 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