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