|
@@ -0,0 +1,90 @@
|
|
|
+#include <mpi.h>
|
|
|
+#include <stdio.h>
|
|
|
+#include <signal.h>
|
|
|
+#include <unistd.h>
|
|
|
+#include <stdlib.h>
|
|
|
+
|
|
|
+char buffer[100];
|
|
|
+int writeToFile(const char* text) {
|
|
|
+ FILE *file;
|
|
|
+
|
|
|
+
|
|
|
+ file = fopen("/tmp/output.txt", "a");
|
|
|
+
|
|
|
+
|
|
|
+ if (file == NULL) {
|
|
|
+ perror("Erreur lors de l'ouverture du fichier");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ fprintf(file, "%s", text);
|
|
|
+
|
|
|
+
|
|
|
+ fclose(file);
|
|
|
+
|
|
|
+ printf("Données écrites dans le fichier avec succès.\n");
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void handle_sigterm(int signum) {
|
|
|
+ printf("Received SIGTERM (%d).\n", signum);
|
|
|
+ snprintf(buffer,sizeof(buffer), "Received SIGTERM (%d).\n",signum);
|
|
|
+ writeToFile(buffer);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ exit(EXIT_SUCCESS);
|
|
|
+}
|
|
|
+
|
|
|
+void handle_sigint(int signum) {
|
|
|
+ printf("Received SIGINT (%d).\n", signum);
|
|
|
+ exit(EXIT_SUCCESS);
|
|
|
+}
|
|
|
+
|
|
|
+int main() {
|
|
|
+
|
|
|
+ if (signal(SIGTERM, handle_sigterm) == SIG_ERR) {
|
|
|
+ perror("Erreur lors de l'installation du gestionnaire de signal");
|
|
|
+ return EXIT_FAILURE;
|
|
|
+ }
|
|
|
+ if (signal(SIGINT, handle_sigint) == SIG_ERR) {
|
|
|
+ perror("Erreur lors de l'installation du gestionnaire de signal pour SIGINT");
|
|
|
+ return EXIT_FAILURE;
|
|
|
+ }
|
|
|
+ MPI_Init(NULL, NULL);
|
|
|
+
|
|
|
+
|
|
|
+ int world_size;
|
|
|
+ MPI_Comm_size(MPI_COMM_WORLD, &world_size);
|
|
|
+
|
|
|
+
|
|
|
+ int world_rank;
|
|
|
+ MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
|
|
|
+
|
|
|
+
|
|
|
+ char processor_name[MPI_MAX_PROCESSOR_NAME];
|
|
|
+ int name_len;
|
|
|
+ MPI_Get_processor_name(processor_name, &name_len);
|
|
|
+
|
|
|
+
|
|
|
+ printf("Hello world from processor %s, rank %d out of %d processors\n",
|
|
|
+ processor_name, world_rank, world_size);
|
|
|
+ printf("Le programme est en cours d'exécution. PID: %d\n", getpid());
|
|
|
+
|
|
|
+
|
|
|
+ while (1) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ sleep(1);
|
|
|
+ }
|
|
|
+ MPI_Finalize();
|
|
|
+ return EXIT_SUCCESS;
|
|
|
+}
|
|
|
+
|