[35aab3] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
| 4 | /* |
---|
| 5 | * ABSTRACT: |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include <string.h> |
---|
| 9 | #include <unistd.h> |
---|
| 10 | #include <stdio.h> |
---|
| 11 | #include <stddef.h> |
---|
| 12 | #include <stdlib.h> |
---|
| 13 | #include <time.h> |
---|
| 14 | |
---|
| 15 | #include "mod2.h" |
---|
| 16 | #include <mylimits.h> |
---|
| 17 | #include "omalloc.h" |
---|
| 18 | #include "structs.h" |
---|
| 19 | #include "febase.h" |
---|
| 20 | //#include "cntrlc.h" |
---|
| 21 | #include "kstd1.h" |
---|
| 22 | #include "timer.h" |
---|
| 23 | #include "intvec.h" |
---|
| 24 | #include "ring.h" |
---|
| 25 | #include "omSingularConfig.h" |
---|
| 26 | #include "p_Procs.h" |
---|
[6160abe] | 27 | #include "kversion.h" |
---|
[35aab3] | 28 | |
---|
| 29 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
| 30 | |
---|
| 31 | //#ifdef HAVE_LIBPARSER |
---|
| 32 | //# include "libparse.h" |
---|
| 33 | //#endif /* HAVE_LIBPARSER */ |
---|
| 34 | |
---|
| 35 | #ifdef HAVE_FACTORY |
---|
| 36 | #include <factory.h> |
---|
| 37 | #endif |
---|
| 38 | |
---|
| 39 | /* version strings */ |
---|
| 40 | #ifdef HAVE_LIBFAC_P |
---|
| 41 | extern const char * libfac_version; |
---|
| 42 | extern const char * libfac_date; |
---|
| 43 | #endif |
---|
| 44 | extern "C" { |
---|
| 45 | #include <gmp.h> |
---|
| 46 | } |
---|
| 47 | #ifdef HAVE_MPSR |
---|
| 48 | #include <MP_Config.h> |
---|
| 49 | #endif |
---|
| 50 | |
---|
| 51 | /* init bins from structs.h */ |
---|
| 52 | |
---|
| 53 | omBin MP_INT_bin = omGetSpecBin(sizeof(MP_INT)); |
---|
| 54 | omBin char_ptr_bin = omGetSpecBin(sizeof(char_ptr)); |
---|
| 55 | omBin ideal_bin = omGetSpecBin(sizeof(ideal)); |
---|
| 56 | omBin int_bin = omGetSpecBin(sizeof(int)); |
---|
| 57 | omBin poly_bin = omGetSpecBin(sizeof(poly)); |
---|
| 58 | omBin void_ptr_bin = omGetSpecBin(sizeof(void_ptr)); |
---|
| 59 | omBin indlist_bin = omGetSpecBin(sizeof(indlist)); |
---|
| 60 | omBin naIdeal_bin = omGetSpecBin(sizeof(naIdeal)); |
---|
| 61 | omBin snaIdeal_bin = omGetSpecBin(sizeof(snaIdeal)); |
---|
| 62 | omBin sm_prec_bin = omGetSpecBin(sizeof(sm_prec)); |
---|
| 63 | omBin smprec_bin = omGetSpecBin(sizeof(smprec)); |
---|
| 64 | omBin sip_sideal_bin = omGetSpecBin(sizeof(sip_sideal)); |
---|
| 65 | omBin sip_smap_bin = omGetSpecBin(sizeof(sip_smap)); |
---|
| 66 | omBin sip_sring_bin = omGetSpecBin(sizeof(sip_sring)); |
---|
| 67 | omBin ip_sideal_bin = omGetSpecBin(sizeof(ip_sideal)); |
---|
| 68 | omBin ip_smap_bin = omGetSpecBin(sizeof(ip_smap)); |
---|
| 69 | omBin ip_sring_bin = omGetSpecBin(sizeof(ip_sring)); |
---|
| 70 | |
---|
| 71 | /*0 implementation*/ |
---|
| 72 | |
---|
| 73 | /*2 |
---|
| 74 | * the global exit routine of Singular |
---|
| 75 | */ |
---|
| 76 | extern "C" { |
---|
[a3760d] | 77 | void m2_end(int i) |
---|
[35aab3] | 78 | { |
---|
| 79 | fe_reset_input_mode(); |
---|
| 80 | #ifdef PAGE_TEST |
---|
| 81 | mmEndStat(); |
---|
| 82 | #endif |
---|
| 83 | #ifdef HAVE_TCL |
---|
| 84 | if (tclmode) |
---|
| 85 | { |
---|
| 86 | PrintTCL('Q',0,NULL); |
---|
| 87 | } |
---|
| 88 | #endif |
---|
| 89 | fe_reset_input_mode(); |
---|
| 90 | if (i<=0) |
---|
| 91 | { |
---|
| 92 | #ifdef HAVE_TCL |
---|
| 93 | if (!tclmode) |
---|
| 94 | #endif |
---|
| 95 | if (BVERBOSE(0)) |
---|
| 96 | { |
---|
| 97 | if (i==0) |
---|
| 98 | printf("Auf Wiedersehen.\n"); |
---|
| 99 | else |
---|
| 100 | printf("\n$Bye.\n"); |
---|
| 101 | } |
---|
[212aaf] | 102 | //#ifdef sun |
---|
| 103 | // #ifndef __svr4__ |
---|
| 104 | // _cleanup(); |
---|
| 105 | // _exit(0); |
---|
| 106 | // #endif |
---|
| 107 | //#endif |
---|
[35aab3] | 108 | exit(0); |
---|
| 109 | } |
---|
| 110 | else |
---|
| 111 | { |
---|
| 112 | #ifdef HAVE_TCL |
---|
| 113 | if (!tclmode) |
---|
| 114 | #endif |
---|
| 115 | printf("\nhalt %d\n",i); |
---|
| 116 | } |
---|
| 117 | exit(i); |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | /*2 |
---|
| 122 | * the renice routine for very large jobs |
---|
| 123 | * works only on unix machines, |
---|
| 124 | * testet on : linux, HP 9.0 |
---|
| 125 | * |
---|
| 126 | *#ifndef MSDOS |
---|
| 127 | *#include <sys/times.h> |
---|
| 128 | *#include <sys/resource.h> |
---|
| 129 | *extern "C" int setpriority(int,int,int); |
---|
| 130 | *void very_nice() |
---|
| 131 | *{ |
---|
| 132 | *#ifndef NO_SETPRIORITY |
---|
| 133 | * setpriority(PRIO_PROCESS,0,19); |
---|
| 134 | *#endif |
---|
| 135 | * sleep(10); |
---|
| 136 | *} |
---|
| 137 | *#else |
---|
| 138 | *void very_nice(){} |
---|
| 139 | *#endif |
---|
| 140 | */ |
---|
| 141 | |
---|
| 142 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
| 143 | #ifdef buildin_rand |
---|
| 144 | /* |
---|
| 145 | * |
---|
| 146 | * A prime modulus multiplicative linear congruential |
---|
| 147 | * generator (PMMLCG), or "Lehmer generator". |
---|
| 148 | * Implementation directly derived from the article: |
---|
| 149 | * |
---|
| 150 | * S. K. Park and K. W. Miller |
---|
| 151 | * Random Number Generators: Good Ones are Hard to Find |
---|
| 152 | * CACM vol 31, #10. Oct. 1988. pp 1192-1201. |
---|
| 153 | * |
---|
| 154 | * Using the following multiplier and modulus, we obtain a |
---|
| 155 | * generator which: |
---|
| 156 | * |
---|
| 157 | * 1) Has a full period: 1 to 2^31 - 2. |
---|
| 158 | * 2) Is testably "random" (see the article). |
---|
| 159 | * 3) Has a known implementation by E. L. Schrage. |
---|
| 160 | */ |
---|
| 161 | |
---|
| 162 | |
---|
[63105e5] | 163 | #define A 16807 /* A "good" multiplier */ |
---|
| 164 | #define M 2147483647 /* Modulus: 2^31 - 1 */ |
---|
| 165 | #define Q 127773 /* M / A */ |
---|
| 166 | #define R 2836 /* M % A */ |
---|
[35aab3] | 167 | |
---|
| 168 | |
---|
| 169 | int siSeed = 1L; |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | int siRand() |
---|
| 173 | { |
---|
| 174 | siSeed = A * (siSeed % Q) - R * (siSeed / Q); |
---|
| 175 | |
---|
| 176 | if ( siSeed < 0 ) |
---|
| 177 | siSeed += M; |
---|
| 178 | |
---|
| 179 | return( siSeed ); |
---|
| 180 | } |
---|
| 181 | #endif |
---|
| 182 | |
---|