SortingAlgorithm

This commit is contained in:
edoardocoli
2024-03-03 23:03:44 +00:00
parent 62d7568c80
commit 4ce77085f7
376 changed files with 1612 additions and 9635 deletions
+19
View File
@@ -0,0 +1,19 @@
MPICC = mpicc #The wrapper for the compiler
CFLAGS += -g #Useful for debug symbols
all: helloworld hamlet easysendrecv nonblockingsendrecv
helloworld: helloworld.c
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
hamlet: hamlet.c
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
easysendrecv: easysendrecv.c
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
nonblockingsendrecv: nonblockingsendrecv.c
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
clean:
rm -f helloworld hamlet easysendrecv nonblockingsendrecv
BIN
View File
Binary file not shown.
+29
View File
@@ -0,0 +1,29 @@
#include "mpi.h"
#include <string.h>
#include <stdio.h>
int main( int argc, char **argv){
char message[20];
char messaggio[20];
int myrank;
MPI_Status status1;
MPI_Status status2;
MPI_Init( &argc, &argv );
MPI_Comm_rank( MPI_COMM_WORLD, &myrank );
if (myrank == 0){ /* code for process zero */
strcpy(message,"Hello, there");
strcpy(messaggio,"Hello, there");
MPI_Send(message, strlen(message)+1, MPI_CHAR, 1, 99, MPI_COMM_WORLD);
MPI_Send(messaggio, strlen(message)+1, MPI_CHAR, 2, 98, MPI_COMM_WORLD);
}
else if (myrank == 1){ /* code for process one */
MPI_Recv(message, 20, MPI_CHAR, 0, 99, MPI_COMM_WORLD, &status1);
printf("(1)received :\"%s\"\n", message);
}
else if (myrank == 5){ /* code for process one */
MPI_Recv(messaggio, 20, MPI_CHAR, 0, 98, MPI_COMM_WORLD, &status2);
printf("(2)received :\"%s\"\n", messaggio);
}
MPI_Finalize();
return 0;
}
+17
View File
@@ -0,0 +1,17 @@
#include "mpi.h"
#include <stdio.h>
int main( int argc, char **argv ){
int rank, size;
MPI_Init( &argc, &argv );
MPI_Comm_rank( MPI_COMM_WORLD, &rank );
MPI_Comm_size( MPI_COMM_WORLD, &size );
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name,&name_len);
printf( "Hello world form %s, rank %d out of %d proc\n",processor_name,rank, size );
MPI_Finalize();
return 0;
}
+10
View File
@@ -0,0 +1,10 @@
#include "mpi.h"
#include <stdio.h>
int main(int argc, char **argv){
MPI_Init( &argc, &argv);
printf("Hello, world!\n");
MPI_Finalize();
return 0;
}
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
#SBATCH --job-name=helloworld
#SBATCH --nodes=1
#SBATCH --ntasks=10
#SBATCH --time=00:05:00
#SBATCH -o ./%x.%j.out
#SBATCH -e ./%x.%j.err
mpirun easysendrecv
+30
View File
@@ -0,0 +1,30 @@
#include <stdio.h>
#include <mpi.h>
int main(int argc, char **argv) {
int a, b;
int size, rank;
int tag = 0;
MPI_Status status;
MPI_Request send_request, recv_request;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0) {
a = 314159;
MPI_Isend(&a, 1, MPI_INT, 1, tag, MPI_COMM_WORLD, &send_request);
MPI_Irecv (&b, 1, MPI_INT, 1, tag, MPI_COMM_WORLD, &recv_request);
MPI_Wait(&send_request, &status);
MPI_Wait(&recv_request, &status);
printf ("Process %d received value %d\n", rank, b);
} else {
a = 667;
MPI_Isend (&a, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &send_request);
MPI_Irecv (&b, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &recv_request);
MPI_Wait(&send_request, &status);
MPI_Wait(&recv_request, &status);
printf ("Process %d received value %d\n", rank, b);
}
MPI_Finalize();
return 0;
}