Nedela
parent
5db4ee1eaa
commit
26cd2c9ae1
|
@ -15,4 +15,4 @@ push:
|
||||||
|
|
||||||
run_remote:
|
run_remote:
|
||||||
ssh nsc 'cd $(DESTINATION); make clean;module load OpenMPI/4.0.5-GCC-10.2.0; make server;'
|
ssh nsc 'cd $(DESTINATION); make clean;module load OpenMPI/4.0.5-GCC-10.2.0; make server;'
|
||||||
ssh nsc 'srun --mpi=pmix --reservation=fri -n2 $(DESTINATION)/server'
|
ssh nsc 'module load OpenMPI/4.0.5-GCC-10.2.0; mpirun -N 2 $(DESTINATION)/server'
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <mpi.h>
|
||||||
|
|
||||||
|
#define buffsize 650
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
int taskid, ntasks;
|
||||||
|
int *buff;
|
||||||
|
double inittime, totaltime;
|
||||||
|
|
||||||
|
MPI_Init(&argc, &argv);
|
||||||
|
|
||||||
|
MPI_Comm_rank(MPI_COMM_WORLD, &taskid);
|
||||||
|
MPI_Comm_size(MPI_COMM_WORLD, &ntasks);
|
||||||
|
|
||||||
|
buff = (int *)malloc(sizeof(int)*buffsize);
|
||||||
|
for (int i=0; i<buffsize; i++)
|
||||||
|
buff[i] = i;
|
||||||
|
MPI_Barrier(MPI_COMM_WORLD);
|
||||||
|
|
||||||
|
printf("Task %d has started, ntasks = %d\n", taskid, ntasks);
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
inittime = MPI_Wtime();
|
||||||
|
|
||||||
|
if(taskid == 0) {
|
||||||
|
buff[0] = 0;
|
||||||
|
buff[1] = -1;
|
||||||
|
printf("Task %d has started sending message, ntasks = %d\n", taskid, ntasks);
|
||||||
|
fflush(stdout);
|
||||||
|
MPI_Send(buff, buffsize, MPI_INT, 1, 0, MPI_COMM_WORLD);
|
||||||
|
}
|
||||||
|
|
||||||
|
MPI_Recv(buff, buffsize, MPI_INT, taskid, 0, MPI_COMM_WORLD, NULL);
|
||||||
|
printf("Task %d has recieved the message, ntasks = %d\n", taskid, ntasks);
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
if (taskid != 0) {
|
||||||
|
for (int j = 0; j < buffsize; j++) {
|
||||||
|
if(buff[j] == -1) {
|
||||||
|
buff[j] = taskid;
|
||||||
|
buff[j + 1] = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taskid != ntasks - 1) {
|
||||||
|
MPI_Send(buff, buffsize, MPI_INT, 0, 0, MPI_COMM_WORLD);
|
||||||
|
}
|
||||||
|
MPI_Send(buff, buffsize, MPI_INT, taskid + 1, 0, MPI_COMM_WORLD);
|
||||||
|
}
|
||||||
|
|
||||||
|
totaltime = MPI_Wtime() - inittime;
|
||||||
|
|
||||||
|
if (taskid == 0) {
|
||||||
|
printf("Cas prenosa: %f s, buffsize: %ld\n", totaltime, sizeof(int)*buffsize);
|
||||||
|
for(int i = 0; i < buffsize; i++) {
|
||||||
|
if(buff[i] == -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
printf("%d ", buff[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(buff);
|
||||||
|
MPI_Finalize();
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -1,95 +0,0 @@
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <mpi.h>
|
|
||||||
|
|
||||||
#define buffsize 650
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
int taskid, ntasks;
|
|
||||||
int i;
|
|
||||||
int *buff;
|
|
||||||
double inittime, totaltime;
|
|
||||||
MPI_Request sendrequest, recvrequest;
|
|
||||||
int done;
|
|
||||||
|
|
||||||
MPI_Init(&argc, &argv);
|
|
||||||
|
|
||||||
MPI_Comm_rank(MPI_COMM_WORLD, &taskid);
|
|
||||||
MPI_Comm_size(MPI_COMM_WORLD, &ntasks);
|
|
||||||
|
|
||||||
|
|
||||||
buff = (int *)malloc(sizeof(int)*buffsize);
|
|
||||||
for (i=0; i<buffsize; i++)
|
|
||||||
buff[i] = i;
|
|
||||||
MPI_Barrier(MPI_COMM_WORLD);
|
|
||||||
|
|
||||||
printf("Task %d has started, ntasks = %d\n", taskid, ntasks);
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
inittime = MPI_Wtime();
|
|
||||||
|
|
||||||
int size;
|
|
||||||
|
|
||||||
if(taskid == 0) {
|
|
||||||
buff[0] = 0;
|
|
||||||
buff[1] = -1;
|
|
||||||
printf("Sending master\n");
|
|
||||||
MPI_Isend(buff, buffsize, MPI_INT, 1, 0, MPI_COMM_WORLD, &sendrequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 1; i < ntasks; i++)
|
|
||||||
{
|
|
||||||
if(taskid == i)
|
|
||||||
{
|
|
||||||
printf("Recieving %d\n", taskid);
|
|
||||||
fflush(stdout);
|
|
||||||
MPI_Irecv(buff, buffsize, MPI_INT, 0, 0, MPI_COMM_WORLD,&recvrequest);
|
|
||||||
MPI_Wait(&sendrequest, MPI_STATUS_IGNORE);
|
|
||||||
MPI_Wait(&recvrequest, MPI_STATUS_IGNORE);
|
|
||||||
printf("Recieved\n");
|
|
||||||
fflush(stdout);
|
|
||||||
for (int j = 0; j < buffsize; j++)
|
|
||||||
{
|
|
||||||
if(buff[j] == -1)
|
|
||||||
{
|
|
||||||
buff[j] = taskid;
|
|
||||||
buff[j + 1] = -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("Sending\n");
|
|
||||||
fflush(stdout);
|
|
||||||
MPI_Send(buff, buffsize, MPI_INT, i+1, 0, MPI_COMM_WORLD);
|
|
||||||
printf("Sent\n");
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(taskid == 0) {
|
|
||||||
printf("Done rec");
|
|
||||||
fflush(stdout);
|
|
||||||
MPI_Recv(buff, buffsize, MPI_INT, ntasks, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
|
||||||
printf("Done rec1");
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
totaltime = MPI_Wtime() - inittime;
|
|
||||||
|
|
||||||
if (taskid == 0) {
|
|
||||||
printf("Cas prenosa: %f s, buffsize: %ld\n", totaltime, sizeof(int)*buffsize);
|
|
||||||
for(int i = 0; i < buffsize; i++) {
|
|
||||||
if(buff[i] == -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
printf("%d ", buff[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(buff);
|
|
||||||
|
|
||||||
MPI_Finalize();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Reference in New Issue