source: git/kernel/misc.cc @ 098f98f

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