Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
HPC
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexandru Dura
HPC
Commits
c1e5abb7
Commit
c1e5abb7
authored
Mar 03, 2020
by
Alexandru Dura
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ring communication
parent
abd12736
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
0 deletions
+107
-0
exercise_06/nbcomm/Makefile
exercise_06/nbcomm/Makefile
+24
-0
exercise_06/nbcomm/nbcomm.c
exercise_06/nbcomm/nbcomm.c
+83
-0
No files found.
exercise_06/nbcomm/Makefile
0 → 100644
View file @
c1e5abb7
CFLAGS
=
-O3
-march
=
native
-Wall
-std
=
c99
LDFLAGS
=
-lm
SOURCES
=
$(
wildcard
*
.c
)
TARGETS
=
TARGETS
:=
$(
patsubst
%.c,%.run,
$(SOURCES)
)
$(TARGETS)
DEPS
=
$(
wildcard
*
.h
)
CC
=
mpicc
all
:
$(TARGETS)
time
:
$(patsubst %.run
,
%.time
,
$(TARGETS))
%.run
:
%.c $(DEPS)
$(CC)
$(CFLAGS)
-DSCHEDULE
=
static
-o
$@
$<
$(LDFLAGS)
%.time
:
%.run
@
echo
$<
@
time
-f
"
\t
%e real"
./
$<
>
/dev/null
clean
:
rm
-f
*
.o
rm
-f
*
.run
exercise_06/nbcomm/nbcomm.c
0 → 100644
View file @
c1e5abb7
#include <mpi.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#define DEFAULT_COMM MPI_COMM_WORLD
#define EAGER_PROTO 1
#if EAGER_PROTO
// using rendez-vous protocol
#define SEND MPI_Issend
#define RECV MPI_Recv
#else
// defaults
#define SEND MPI_Ssend
#define RECV MPI_Recv
#endif
int
main
(
int
argc
,
char
**
argv
)
{
MPI_Init
(
NULL
,
NULL
);
int
nsize
,
rank
;
MPI_Comm_size
(
DEFAULT_COMM
,
&
nsize
);
MPI_Comm_rank
(
DEFAULT_COMM
,
&
rank
);
int
upneighbour
=
(
rank
+
1
)
%
nsize
;
int
dnneighbour
=
(
rank
+
nsize
-
1
)
%
nsize
;
int
*
startdata
=
malloc
(
nsize
*
sizeof
(
int
));
for
(
int
i
=
0
;
i
<
nsize
;
++
i
)
startdata
[
i
]
=
rank
;
int
*
dnsend
=
malloc
(
nsize
*
sizeof
(
int
));
for
(
int
i
=
0
;
i
<
nsize
;
++
i
)
dnsend
[
i
]
=
startdata
[
i
]
*
1000
;
int
*
upsend
=
malloc
(
nsize
*
sizeof
(
int
));
for
(
int
i
=
0
;
i
<
nsize
;
++
i
)
upsend
[
i
]
=
startdata
[
i
];
int
*
uprecv
=
malloc
(
nsize
*
sizeof
(
int
));
int
*
dnrecv
=
malloc
(
nsize
*
sizeof
(
int
));
for
(
int
i
=
0
;
i
<
nsize
;
++
i
)
{
MPI_Request
request_up
,
request_dn
;
MPI_Isend
(
upsend
,
nsize
,
MPI_INT
,
upneighbour
,
0
,
DEFAULT_COMM
,
&
request_up
);
MPI_Isend
(
dnsend
,
nsize
,
MPI_INT
,
dnneighbour
,
0
,
DEFAULT_COMM
,
&
request_dn
);
MPI_Recv
(
uprecv
,
nsize
,
MPI_INT
,
upneighbour
,
0
,
DEFAULT_COMM
,
MPI_STATUS_IGNORE
);
MPI_Recv
(
dnrecv
,
nsize
,
MPI_INT
,
dnneighbour
,
0
,
DEFAULT_COMM
,
MPI_STATUS_IGNORE
);
MPI_Wait
(
&
request_up
,
MPI_STATUS_IGNORE
);
MPI_Wait
(
&
request_dn
,
MPI_STATUS_IGNORE
);
memcpy
(
dnsend
,
uprecv
,
nsize
*
sizeof
(
int
));
memcpy
(
upsend
,
dnrecv
,
nsize
*
sizeof
(
int
));
}
for
(
int
i
=
0
;
i
<
nsize
;
++
i
)
{
MPI_Barrier
(
DEFAULT_COMM
);
if
(
i
==
rank
)
{
printf
(
"Process %d/%d
\n
"
,
rank
,
nsize
);
for
(
int
i
=
0
;
i
<
nsize
;
++
i
)
{
printf
(
"%d "
,
uprecv
[
i
]);
}
printf
(
"
\n
"
);
for
(
int
i
=
0
;
i
<
nsize
;
++
i
)
{
printf
(
"%d "
,
dnrecv
[
i
]);
}
printf
(
"
\n
"
);
}
}
MPI_Finalize
();
return
0
;
}
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