source: git/kernel/misc.cc @ 8c35ba

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