Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
supercomputer_lab
Project
Project
Details
Activity
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
Gaurav Kukreja
supercomputer_lab
Commits
ababf07b
Commit
ababf07b
authored
May 16, 2012
by
Gaurav Kukreja
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ping-pong.c for Latency
Working Code - Umbreen Signed-off-by:
Gaurav Kukreja
<
mailme.gaurav@gmail.com
>
parent
fd2df844
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
28 deletions
+41
-28
ping-pong.c
mpi-assign3/ping-pong.c
+34
-23
result.c
mpi-assign3/result.c
+3
-3
result.h
mpi-assign3/result.h
+4
-2
No files found.
mpi-assign3/ping-pong.c
View file @
ababf07b
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include "result.h"
#define FNAME_CMDARG 1
extern
char
*
filename
;
struct
data_latency
data_l
;
char
*
filename
;
int
main
(
int
argc
,
char
**
argv
)
{
int
my_
proc
,
other_proc
,
i
,
j
,
nprocs
;
int
PING_PONG_LIMIT
=
5
;
int
my_
rank
,
partner_rank
,
i
,
j
,
nprocs
;
int
tag
=
10
;
char
a
,
b
;
double
tstart
,
tend
;
...
...
@@ -21,40 +22,50 @@ int main (int argc, char **argv)
MPI_Init
(
&
argc
,
&
argv
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
nprocs
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
my_
proc
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
my_
rank
);
for
(
i
=
1
;
i
<
nprocs
;
i
++
)
{
other_proc
=
i
;
MPI_Barrier
(
MPI_COMM_WORLD
);
int
ping_pong_count
=
0
;
if
(
my_proc
==
0
)
{
MPI_Barrier
(
MPI_COMM_WORLD
);
if
(
my_rank
==
0
)
{
partner_rank
=
i
;
tstart
=
MPI_Wtime
();
for
(
j
=
0
;
j
<
5
;
j
++
)
{
MPI_Send
(
&
a
,
0
,
MPI_DOUBLE
,
other_proc
,
10
,
MPI_COMM_WORLD
);
MPI_Recv
(
&
b
,
0
,
MPI_DOUBLE
,
other_proc
,
10
,
MPI_COMM_WORLD
,
&
status
);
while
(
ping_pong_count
<
PING_PONG_LIMIT
)
{
// Increment the ping pong count before you send it
ping_pong_count
++
;
MPI_Send
(
&
ping_pong_count
,
1
,
MPI_INT
,
partner_rank
,
10
,
MPI_COMM_WORLD
);
//printf("%d sent and incremented ping_pong_count %d to %d\n",my_rank, ping_pong_count, partner_rank);
MPI_Recv
(
&
ping_pong_count
,
1
,
MPI_INT
,
partner_rank
,
10
,
MPI_COMM_WORLD
,
&
status
);
//printf("%d received ping_pong_count %d from %d\n", my_rank, ping_pong_count, partner_rank);
}
tend
=
MPI_Wtime
();
}
else
{
for
(
j
=
0
;
j
<
5
;
j
++
)
{
MPI_Recv
(
&
b
,
0
,
MPI_DOUBLE
,
0
,
10
,
MPI_COMM_WORLD
,
&
status
);
MPI_Send
(
&
b
,
0
,
MPI_DOUBLE
,
0
,
10
,
MPI_COMM_WORLD
);
}
else
if
(
my_rank
==
i
)
{
while
(
ping_pong_count
<
PING_PONG_LIMIT
)
{
MPI_Recv
(
&
ping_pong_count
,
1
,
MPI_INT
,
0
,
10
,
MPI_COMM_WORLD
,
&
status
);
//printf("%d received ping_pong_count %d from %d\n",my_rank, ping_pong_count, 0);
// Increment the ping pong count before you send it
ping_pong_count
++
;
MPI_Send
(
&
ping_pong_count
,
1
,
MPI_INT
,
0
,
10
,
MPI_COMM_WORLD
);
//printf("%d sent and incremented ping_pong_count %d to %d\n",my_rank, ping_pong_count, 0);
}
}
MPI_Barrier
(
MPI_COMM_WORLD
);
data_l
.
source_thread
=
0
;
data_l
.
dest_thread
=
other_proc
;
data_l
.
latency
=
(
tend
-
tstart
)
/
10
;
submit_latency_data
(
data_l
);
printf
(
"Latency for process %d = %lf
\n
"
,
other_proc
,
tend
-
tstart
);
if
(
my_rank
==
0
){
data_l
.
source_thread
=
0
;
data_l
.
dest_thread
=
partner_rank
;
data_l
.
latency
=
(
tend
-
tstart
)
/
10
;
submit_latency_data
(
data_l
);
printf
(
"Latency for process %d = %lf
\n
"
,
partner_rank
,
(
tend
-
tstart
)
/
10
);
}
}
MPI_Finalize
();
return
0
;
}
mpi-assign3/result.c
View file @
ababf07b
#include <stdio.h>
#include "result.h"
char
*
filename
;
extern
char
*
filename
;
int
submit_bandwidth_data
(
struct
data_bandwidth
data_b
)
{
FILE
*
fp
;
fp
=
fopen
(
filename
,
"a"
);
fprintf
(
fp
,
"%d
/t%d/t%d/t%lf/t%lf/
n"
,
data_b
.
source_thread
,
fprintf
(
fp
,
"%d
\t
%d
\t
%d
\t
%lf
\t
%lf
\
n
"
,
data_b
.
source_thread
,
data_b
.
dest_thread
,
data_b
.
log_size
,
data_b
.
time
,
data_b
.
bandwidth
);
...
...
@@ -21,7 +21,7 @@ int submit_latency_data(struct data_latency data_l)
FILE
*
fp
;
fp
=
fopen
(
filename
,
"a"
);
fprintf
(
fp
,
"%d
/t%d/t%lf/
n"
,
data_l
.
source_thread
,
fprintf
(
fp
,
"%d
\t
%d
\t
%lf
\
n
"
,
data_l
.
source_thread
,
data_l
.
dest_thread
,
data_l
.
latency
);
fclose
(
fp
);
...
...
mpi-assign3/result.h
View file @
ababf07b
...
...
@@ -15,8 +15,10 @@ struct data_bandwidth {
double
bandwidth
;
};
int
submit_latency_data
(
struct
data_latency
);
int
submit_latency_data
(
struct
data_latency
data_l
);
int
submit_bandwidth_data
(
struct
data_bandwidth
);
int
submit_bandwidth_data
(
struct
data_bandwidth
data_b
);
int
write_hello
();
#endif
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