psmile_attach.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include <stdio.h>
00007 #include <stddef.h>
00008 #include <stdlib.h>
00009 #include <string.h>
00010 #include <time.h>
00011 #include <sys/types.h>
00012 #include <unistd.h>
00013
00014 #include "PSMILe_f2c.h"
00015
00016 #define VOLATILE volatile
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef ANSI_C
00027
00028 void psmile_attach (INTEGER *psmile_rank);
00029
00030 #else
00031
00032 void psmile_attach (psmile_rank)
00033
00034 INTEGER *psmile_rank;
00035
00036 #endif
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 {
00078 char *env = getenv ("PSMILE_ATTACH");
00079 int rank;
00080
00081 if (env == NULL) return;
00082
00083
00084
00085 rank = strtol (env, (char **) NULL, 10);
00086
00087 if (rank == *psmile_rank) {
00088 time_t t_start, t_end;
00089 VOLATILE int attached = 0;
00090
00091 fprintf (stderr, "[%d] PSMILe_attach: ### Wait for user attach; pid %d\n",
00092 *psmile_rank, getpid ());
00093 fflush (stderr);
00094 t_start = time(NULL);
00095
00096 while (attached == 0) {
00097 t_end = time(NULL);
00098
00099 if (t_end - t_start > 30 || t_end < t_start) {
00100 fprintf (stderr, "[%d] PSMILe_attach: ### Wait aborted since time limit exceeded\n",
00101 *psmile_rank);
00102 break;
00103 }
00104 }
00105 }
00106 }