Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F96572011
isend_recv.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Dec 28, 08:07
Size
789 B
Mime Type
text/x-c
Expires
Mon, Dec 30, 08:07 (1 d, 8 h)
Engine
blob
Format
Raw Data
Handle
23209047
Attached To
R11821 phys-743-lecture
isend_recv.cc
View Options
#include <assert.h>
#include <iostream>
#include <mpi.h>
#include <vector>
void
fill_buffer
(
std
::
vector
<
int
>
&
buf
)
{
for
(
auto
&
v
:
buf
)
{
v
=
0
;
}
}
int
main
()
{
int
rank
,
size
;
std
::
vector
<
int
>
buf
(
100
);
MPI_Init
(
NULL
,
NULL
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
rank
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
size
);
assert
(
size
==
2
&&
"Works only with 2 procs"
);
MPI_Request
request
;
if
(
rank
==
0
)
{
fill_buffer
(
buf
);
MPI_Isend
(
buf
.
data
(),
buf
.
size
(),
MPI_INT
,
1
,
0
,
MPI_COMM_WORLD
,
&
request
);
}
else
if
(
rank
==
1
)
{
MPI_Recv
(
buf
.
data
(),
buf
.
size
(),
MPI_INT
,
0
,
0
,
MPI_COMM_WORLD
,
MPI_STATUS_IGNORE
);
}
// here I can do computation as long as buf is not modified
MPI_Wait
(
&
request
,
MPI_STATUS_IGNORE
);
MPI_Finalize
();
return
0
;
}
Event Timeline
Log In to Comment