1 #ifndef SIGNAL_HANDLER
2 #define SIGNAL_HANDLER
3 /* -----------------------------------------------------
4    sighandler.h
5    handels to following signals:
6    SIGIOT         Input/Output problems
7    SIGFPE         Floating point exceptions
8    SIGBUS         Bus error
9    SIGSEGV        Segmentation fault
10    SIGXCPU        CPU time limit exceeded
11    SIGXFSZ        File size limit exceeded
12    if most of those exception are encountered the system
13    tries to exit gracefully, but with some it dies
14    anyway, but tries to say it why in a way which is
15    for humans better understandable
16    -----------------------------------------------------
17  (c) Peter Beerli 2013
18 
19  Permission is hereby granted, free of charge, to any person obtaining
20  a copy of this software and associated documentation files (the
21  "Software"), to deal in the Software without restriction, including
22  without limitation the rights to use, copy, modify, merge, publish,
23  distribute, sublicense, and/or sell copies of the Software, and to
24  permit persons to whom the Software is furnished to do so, subject
25  to the following conditions:
26 
27  The above copyright notice and this permission notice shall be
28  included in all copies or substantial portions of the Software.
29 
30  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
34  ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
35  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 
38 
39    ----------------------------------------------------- */
40 #ifndef __MWERKS__
41 #include <sys/types.h>
42 #endif
43 #include <stdarg.h>
44 #include <signal.h>
45 #include "definitions.h"
46 #define ON 1L
47 #define OFF 0L
48 extern void signalhandling (long switcher);
49 extern void signalhandler (int sig);
50 extern void warning (char string[], ...);
51 extern void usererror (char string[], ...);
52 #define error(x) sig_error(x, __FILE__,(long) __LINE__)
53 extern void sig_error (char string[], char filename[], long line);
54 
55 extern char myfgets (char *buffer, long bufsize, FILE * infile);
56 extern char myfgetssafe (char **buffer, long *bufsize, FILE * infile);
57 #ifdef ZNZ
58 #include "znzlib.h"
59 extern char myznzfgets (char *buffer, long bufsize, znzFile infile);
60 #endif
61 #ifdef NEXTAPP
62 extern void malloc_error_found (int value);
63 #endif
64 
65 #ifdef MEMDEBUG
66 extern void memdebug_free(void *ptr, const char file[], const long line);
67 #define myfree(a) memdebug_free(a,__FILE__,__LINE__);
68 #else
69 #define myfree(a)  free(a)
70 #endif
71 
72 #ifdef LAMARC_MALLOC
73 extern void *LAMARC_malloc (size_t size, const char file[],
74                                 const long line);
75 extern void *LAMARC_calloc (size_t repeats,
76                                 size_t size, const char file[],
77                                 const long line);
78 extern void *LAMARC_realloc (void *ptr, size_t,
79                                  const char file[], const long line);
80 #define mymalloc(a) LAMARC_malloc((size_t) a,__FILE__,(const long)__LINE__)
81 #define mycalloc(b,a) LAMARC_calloc((size_t) b, (size_t) a,__FILE__,(const long)__LINE__)
82 #define myrealloc(c,a) LAMARC_realloc(c, (size_t) a,__FILE__,(const long) __LINE__)
83 #else
84 #define mymalloc(a) malloc((size_t) a)
85 #define mycalloc(b,a) calloc((size_t) b, (size_t) a)
86 #define myrealloc(c,a) realloc(c, (size_t) a)
87 #endif
88 #ifdef MPI
89 #ifdef DEBUG_MPI
90 #define MYMPISEND(a,b,c,d,e,f) printf("%i>before ssend of %li bytes to %i with tag %i (%s,%i)\n",myID, b* sizeof(c), d, e,__FILE__,__LINE__);fflush(stdout);MPI_Ssend(a,b,c, d,  e,f);printf("%i>after send (%s,%i)\n",myID, __FILE__,__LINE__);fflush(stdout)
91 //#define MYMPIISEND(a,b,c,d,e,f,g) printf("%i>before isend of %li bytes to %i with tag %i in %i (%s,%i)\n",myID, b* sizeof(c), d, e, (int) f, __FILE__,__LINE__);fflush(stdout);MPI_Isend(a,b,c,d,  e,f,g);printf("%i>after send (%s,%i)\n",myID, __FILE__,__LINE__);fflush(stdout)
92 #define MYMPIISEND(a,b,c,d,e,f,g) printf("%i>before isend of %li bytes to %i with tag %i in %i (%s,%i)\n",myID, b* sizeof(c), d, e, (int) f, __FILE__,__LINE__);fflush(stdout);MPI_Send(a,b,c,d,  e,f);printf("%i>after send (%s,%i)\n",myID, __FILE__,__LINE__);fflush(stdout)
93 #define MYMPIRECV(a,b,c,d,e,f,g) printf("%i>before receive of %li bytes from %i with tag %i in %i (%s,%i)\n",myID, b * sizeof(c),d,e, (int) f, __FILE__,__LINE__);fflush(stdout);MPI_Recv(a,b,c,d,e,f,g);printf("%i>after receive (%s,%i)\n",myID, __FILE__,__LINE__);fflush(stdout)
94 #define MYMPIBCAST(a,b,c,d,e) printf("%i>before broadcast of %li bytes (%s,%i)\n",myID, ((long) b) * ((long) sizeof(c)), __FILE__,__LINE__);fflush(stdout);MPI_Bcast(a,b,c,d,e);printf("%i>after broadcast (%s,%i)\n",myID, __FILE__,__LINE__);fflush(stdout)
95 #define MYMPIBARRIER(a) printf("%i>before barrier (%s,%i)\n",myID, __FILE__,__LINE__);fflush(stdout);MPI_Barrier(a);printf("%i>after barrier (%s,%i)\n",myID, __FILE__,__LINE__);fflush(stdout)
96 //#define MYMPIWAITALL(a,b,c) printf("%i>before waitall (%s,%i)\n",myID, __FILE__,__LINE__);fflush(stdout);MPI_Waitall(a,b,c);printf("%i>after waitall (%s,%i)\n",myID, __FILE__,__LINE__);fflush(stdout)
97 #define MYMPIWAITALL(a,b,c) /*do nothing*/
98 #else
99 #define MYMPISEND(a,b,c,d,e,f) MPI_Send(a,b,c,d,e,f)
100 //#define MYMPIISEND(a,b,c,d,e,f,g) MPI_Isend(a,b,c,d,e,f,g)
101 #define MYMPIISEND(a,b,c,d,e,f,g) MPI_Send(a,b,c,d,e,f)
102 #define MYMPIRECV(a,b,c,d,e,f,g) MPI_Recv(a,b,c,d,e,f,g)
103 #define MYMPIBCAST(a,b,c,d,e) MPI_Bcast(a,b,c,d,e)
104 #define MYMPIBARRIER(a) MPI_Barrier(a)
105 //#define MYMPIWAITALL(a,b,c) MPI_Waitall(a,b,c)
106 #define MYMPIWAITALL(a,b,c) /*do nothing*/
107 #endif
108 #endif
109 #endif
110 
111