Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ardhi Putra Pratama
teaching
Commits
17d1e9c6
Commit
17d1e9c6
authored
Jan 26, 2018
by
Ardhi Putra Pratama
Browse files
MPI send-receive-exchange example
parent
153308bd
Changes
1
Hide whitespace changes
Inline
Side-by-side
hpc/hello-world/mpi_sendrc.c
0 → 100644
View file @
17d1e9c6
#include
"mpi.h"
#include
<stdio.h>
int
main
(
int
argc
,
char
**
argv
)
{
int
size
,
rank
,
dest
,
source
,
rc
,
count
;
char
inmsg
,
outmsg
=
'x'
;
MPI_Status
Stat
;
MPI_Init
(
&
argc
,
&
argv
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
size
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
rank
);
if
(
rank
==
0
)
{
dest
=
source
=
1
;
outmsg
=
'x'
;
rc
=
MPI_Send
(
&
outmsg
,
1
,
MPI_CHAR
,
dest
,
1
,
MPI_COMM_WORLD
);
rc
=
MPI_Recv
(
&
inmsg
,
1
,
MPI_CHAR
,
source
,
1
,
MPI_COMM_WORLD
,
&
Stat
);
}
else
if
(
rank
==
1
)
{
dest
=
source
=
0
;
outmsg
=
'y'
;
rc
=
MPI_Recv
(
&
inmsg
,
1
,
MPI_CHAR
,
source
,
1
,
MPI_COMM_WORLD
,
&
Stat
);
rc
=
MPI_Send
(
&
outmsg
,
1
,
MPI_CHAR
,
dest
,
1
,
MPI_COMM_WORLD
);
}
printf
(
"Rank %d: Received char %c from task %d
\n
"
,
rank
,
inmsg
,
Stat
.
MPI_SOURCE
);
MPI_Finalize
();
}
Write
Preview
Supports
Markdown
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