*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
Commit a7eee754 authored by Blaas-Schenner, Claudia's avatar Blaas-Schenner, Claudia
Browse files

tmp2 02_pingpong

parent c553023c
No related branches found
No related tags found
No related merge requests found
Showing
with 439 additions and 0 deletions
#include <stdio.h>
#include <mpi.h>
int main(int argc, char *argv[])
{
int i, rank;
float buffer[1];
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
printf("I am %i before send ping \n", rank);
printf("I am %i after recv ping \n", rank);
MPI_Finalize();
}
#include <stdio.h>
#include <mpi.h>
int main(int argc, char *argv[])
{
int i, rank;
float buffer[1];
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0)
{
printf("I am %i before send ping \n", rank);
MPI_Send(buffer, 1, MPI_FLOAT, 1, 17, MPI_COMM_WORLD);
}
else if (rank == 1)
{
MPI_Recv(buffer, 1, MPI_FLOAT, 0, 17, MPI_COMM_WORLD, &status);
printf("I am %i after recv ping \n", rank);
}
MPI_Finalize();
}
#include <stdio.h>
#include <mpi.h>
#define number_of_messages 50
int main(int argc, char *argv[])
{
int i, rank;
float buffer[1];
// ??? start, finish, msg_transfer_time;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0)
{
MPI_Send(buffer, 1, MPI_FLOAT, 1, 17, MPI_COMM_WORLD);
MPI_Recv(buffer, 1, MPI_FLOAT, 1, 23, MPI_COMM_WORLD, &status);
}
else if (rank == 1)
{
MPI_Recv(buffer, 1, MPI_FLOAT, 0, 17, MPI_COMM_WORLD, &status);
MPI_Send(buffer, 1, MPI_FLOAT, 0, 23, MPI_COMM_WORLD);
}
if (rank == 0)
{
// msg_transfer_time = ((finish - start) / (2 * number_of_messages)) * 1e6 ; // in microsec
// printf("Time for one messsage: %f micro seconds.\n", msg_transfer_time);
}
MPI_Finalize();
}
#include <stdio.h>
#include <mpi.h>
#define number_of_messages 50
int main(int argc, char *argv[])
{
int i, rank;
float buffer[1];
double start, finish, msg_transfer_time;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
start = MPI_Wtime();
for (i = 1; i <= number_of_messages; i++)
{
if (rank == 0)
{
MPI_Send(buffer, 1, MPI_FLOAT, 1, 17, MPI_COMM_WORLD);
MPI_Recv(buffer, 1, MPI_FLOAT, 1, 23, MPI_COMM_WORLD, &status);
}
else if (rank == 1)
{
MPI_Recv(buffer, 1, MPI_FLOAT, 0, 17, MPI_COMM_WORLD, &status);
MPI_Send(buffer, 1, MPI_FLOAT, 0, 23, MPI_COMM_WORLD);
}
}
finish = MPI_Wtime();
if (rank == 0)
{
msg_transfer_time = ((finish - start) / (2 * number_of_messages)) * 1e6 ; // in microsec
printf("Time for one messsage: %f micro seconds.\n", msg_transfer_time);
}
MPI_Finalize();
}
#include <stdio.h>
#include <mpi.h>
#define number_of_messages 50
int main(int argc, char *argv[])
{
int i, rank;
float buffer[1];
double start, finish, msg_transfer_time;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0)
{
MPI_Send(buffer, 1, MPI_FLOAT, 1, 17, MPI_COMM_WORLD);
MPI_Recv(buffer, 1, MPI_FLOAT, 1, 23, MPI_COMM_WORLD, &status);
}
else if (rank == 1)
{
MPI_Recv(buffer, 1, MPI_FLOAT, 0, 17, MPI_COMM_WORLD, &status);
MPI_Send(buffer, 1, MPI_FLOAT, 0, 23, MPI_COMM_WORLD);
}
start = MPI_Wtime();
for (i = 1; i <= number_of_messages; i++)
{
if (rank == 0)
{
MPI_Send(buffer, 1, MPI_FLOAT, 1, 17, MPI_COMM_WORLD);
MPI_Recv(buffer, 1, MPI_FLOAT, 1, 23, MPI_COMM_WORLD, &status);
}
else if (rank == 1)
{
MPI_Recv(buffer, 1, MPI_FLOAT, 0, 17, MPI_COMM_WORLD, &status);
MPI_Send(buffer, 1, MPI_FLOAT, 0, 23, MPI_COMM_WORLD);
}
}
finish = MPI_Wtime();
if (rank == 0)
{
msg_transfer_time = ((finish - start) / (2 * number_of_messages)) * 1e6 ; // in microsec
printf("Time for one messsage: %f micro seconds.\n", msg_transfer_time);
}
MPI_Finalize();
}
#include <stdio.h>
#include <mpi.h>
#define number_of_messages 50
int main(int argc, char *argv[])
{
int i, rank;
float buffer[1];
double start, finish, msg_transfer_time;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
start = MPI_Wtime();
for (i = 1; i <= number_of_messages; i++)
{
if (rank == 0)
{
MPI_Send(buffer, 1, MPI_FLOAT, 1, 17, MPI_COMM_WORLD);
MPI_Recv(buffer, 1, MPI_FLOAT, 1, 23, MPI_COMM_WORLD, &status);
}
else if (rank == 1)
{
MPI_Recv(buffer, 1, MPI_FLOAT, 0, 17, MPI_COMM_WORLD, &status);
MPI_Send(buffer, 1, MPI_FLOAT, 0, 23, MPI_COMM_WORLD);
}
}
finish = MPI_Wtime();
if (rank == 0)
{
msg_transfer_time = ((finish - start) / (2 * number_of_messages)) * 1e6 ; // in microsec
printf("Time for one messsage: %f micro seconds.\n", msg_transfer_time);
}
MPI_Finalize();
}
#include <stdio.h>
#include <mpi.h>
int main(int argc, char *argv[])
{
int i, rank;
float buffer[1];
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0)
{
printf("I am %i before send ping \n", rank);
MPI_Send(buffer, 1, MPI_FLOAT, 1, 17, MPI_COMM_WORLD);
printf("I WILL BE / am %i after recv ping \n", rank);
}
else if (rank == 1)
{
MPI_Recv(buffer, 1, MPI_FLOAT, 0, 17, MPI_COMM_WORLD, &status);
printf("I am %i after recv ping \n", rank);
printf("I WILL BE / am %i before send pong \n", rank);
}
MPI_Finalize();
}
#include <stdio.h>
#include <mpi.h>
int main(int argc, char *argv[])
{
int i, rank;
float buffer[1];
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0)
{
printf("I am %i before send ping \n", rank);
MPI_Send(buffer, 1, MPI_FLOAT, 1, 17, MPI_COMM_WORLD);
MPI_Recv(buffer, 1, MPI_FLOAT, 1, 23, MPI_COMM_WORLD, &status);
printf("I am %i after recv pong \n", rank);
}
else if (rank == 1)
{
MPI_Recv(buffer, 1, MPI_FLOAT, 0, 17, MPI_COMM_WORLD, &status);
printf("I am %i after recv ping \n", rank);
printf("I am %i before send pong \n", rank);
MPI_Send(buffer, 1, MPI_FLOAT, 0, 23, MPI_COMM_WORLD);
}
MPI_Finalize();
}
program ping
use mpi_f08
implicit none
type(MPI_Status) :: status
real :: buffer(1)
integer :: i, rank
call MPI_Init()
call MPI_Comm_rank(MPI_COMM_WORLD, rank)
write(*,*) 'I am ', rank, ' before send ping'
write(*,*) 'I am ', rank, ' after recv ping'
call MPI_Finalize()
end program
program ping
use mpi_f08
implicit none
type(MPI_Status) :: status
real :: buffer(1)
integer :: i, rank
call MPI_Init()
call MPI_Comm_rank(MPI_COMM_WORLD, rank)
if (rank .eq. 0) then
write(*,*) 'I am ', rank, ' before send ping'
call MPI_Send(buffer, 1, MPI_REAL, 1, 17, MPI_COMM_WORLD)
else if (rank .eq. 1) then
call MPI_Recv(buffer, 1, MPI_REAL, 0, 17, MPI_COMM_WORLD, status)
write(*,*) 'I am ', rank, ' after recv ping'
end if
call MPI_Finalize()
end program
program pingpong-bench
use mpi_f08
implicit none
integer :: number_of_messages
parameter (number_of_messages=50)
! ??? :: start, finish, msg_transfer_time
type(MPI_Status) :: status
real :: buffer(1)
integer :: i, rank
call MPI_Init()
call MPI_Comm_rank(MPI_COMM_WORLD, rank)
if (rank .eq. 0) then
call MPI_Send(buffer, 1, MPI_REAL, 1, 17, MPI_COMM_WORLD)
call MPI_Recv(buffer, 1, MPI_REAL, 1, 23, MPI_COMM_WORLD, status)
else if (rank .eq. 1) then
call MPI_Recv(buffer, 1, MPI_REAL, 0, 17, MPI_COMM_WORLD, status)
call MPI_Send(buffer, 1, MPI_REAL, 0, 23, MPI_COMM_WORLD)
end if
if (rank .eq. 0) then
msg_transfer_time = ((finish - start) / (2 * number_of_messages)) * 1e6 ! in microsec
WRITE(*,*) 'Time for one message:', msg_transfer_time, ' micro seconds'
end if
call MPI_Finalize()
end program
program pingpong_bench
use mpi_f08
implicit none
integer :: number_of_messages
parameter (number_of_messages=50)
double precision :: start, finish, msg_transfer_time
type(MPI_Status) :: status
real :: buffer(1)
integer :: i, rank
call MPI_Init()
call MPI_Comm_rank(MPI_COMM_WORLD, rank)
start = MPI_Wtime()
do i = 1, number_of_messages
if (rank .eq. 0) then
call MPI_Send(buffer, 1, MPI_REAL, 1, 17, MPI_COMM_WORLD)
call MPI_Recv(buffer, 1, MPI_REAL, 1, 23, MPI_COMM_WORLD, status)
else if (rank .eq. 1) then
call MPI_Recv(buffer, 1, MPI_REAL, 0, 17, MPI_COMM_WORLD, status)
call MPI_Send(buffer, 1, MPI_REAL, 0, 23, MPI_COMM_WORLD)
end if
end do
finish = MPI_Wtime()
if (rank .eq. 0) then
msg_transfer_time = ((finish - start) / (2 * number_of_messages)) * 1e6 ! in microsec
WRITE(*,*) 'Time for one message:', msg_transfer_time, ' micro seconds'
end if
call MPI_Finalize()
end program
program pingpong
use mpi_f08
implicit none
type(MPI_Status) :: status
real :: buffer(1)
integer :: i, rank
call MPI_Init()
call MPI_Comm_rank(MPI_COMM_WORLD, rank)
if (rank .eq. 0) then
write(*,*) 'I am ', rank, ' before send ping'
call MPI_Send(buffer, 1, MPI_REAL, 1, 17, MPI_COMM_WORLD)
! write(*,*) 'I am ', rank, ' after recv pong'
else if (rank .eq. 1) then
call MPI_Recv(buffer, 1, MPI_REAL, 0, 17, MPI_COMM_WORLD, status)
write(*,*) 'I am ', rank, ' after recv ping'
! write(*,*) 'I am ', rank, ' before send pong'
end if
call MPI_Finalize()
end program
program pingpong
use mpi_f08
implicit none
type(MPI_Status) :: status
real :: buffer(1)
integer :: i, rank
call MPI_Init()
call MPI_Comm_rank(MPI_COMM_WORLD, rank)
if (rank .eq. 0) then
write(*,*) 'I am ', rank, ' before send ping'
call MPI_Send(buffer, 1, MPI_REAL, 1, 17, MPI_COMM_WORLD)
call MPI_Recv(buffer, 1, MPI_REAL, 1, 23, MPI_COMM_WORLD, status)
write(*,*) 'I am ', rank, ' after recv pong'
else if (rank .eq. 1) then
call MPI_Recv(buffer, 1, MPI_REAL, 0, 17, MPI_COMM_WORLD, status)
write(*,*) 'I am ', rank, ' after recv ping'
write(*,*) 'I am ', rank, ' before send pong'
call MPI_Send(buffer, 1, MPI_REAL, 0, 23, MPI_COMM_WORLD)
end if
call MPI_Finalize()
end program
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment