My Project
Loading...
Searching...
No Matches
tesths.cc File Reference
#include "kernel/mod2.h"
#include "omalloc/omalloc.h"
#include "misc/options.h"
#include "factory/factory.h"
#include "kernel/oswrapper/feread.h"
#include "Singular/fevoices.h"
#include "kernel/oswrapper/timer.h"
#include "kernel/oswrapper/vspace.h"
#include "ipshell.h"
#include "cntrlc.h"
#include "links/silink.h"
#include "ipid.h"
#include "sdb.h"
#include "feOpt.h"
#include "misc/distrib.h"
#include "mmalloc.h"
#include "tok.h"
#include "resources/fegetopt.h"
#include "Singular/countedref.h"
#include "Singular/pyobject_setup.h"
#include <unistd.h>
#include <NTL/config.h>

Go to the source code of this file.

Functions

void siInit (char *)
 
int mmInit (void)
 
int main (int argc, char **argv)
 

Variables

EXTERN_VAR FILE * File_Log
 
EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG
 

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 62 of file tesths.cc.

65{
66 mmInit();
67 // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
68 omInitRet_2_Info(argv[0]);
70
71#ifdef PSINGULAR
72 global_argv0 = argv[0];
73#endif
74 siInit(argv[0]);
76
77 // parse command line options
78 int optc, option_index;
79 const char* errormsg;
80 while((optc = fe_getopt_long(argc, argv,
81 SHORT_OPTS_STRING, feOptSpec, &option_index))
82 != EOF)
83 {
84 if (optc == '?' || optc == 0)
85 {
86 fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
87 exit(1);
88 }
89
90 if (optc != LONG_OPTION_RETURN)
91 option_index = feGetOptIndex(optc);
92
93 assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
94
95 if (fe_optarg == NULL &&
96 (feOptSpec[option_index].type == feOptBool ||
97 feOptSpec[option_index].has_arg == optional_argument))
98 errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
99 else
100 errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
101 // not more than MAX_PROCESS cpus
102
103 if (errormsg)
104 {
105 if (fe_optarg == NULL)
106 fprintf(stderr, "Error: Option '--%s' %s\n",
107 feOptSpec[option_index].name, errormsg);
108 else
109 fprintf(stderr, "Error: Option '--%s=%s' %s\n",
110 feOptSpec[option_index].name, fe_optarg, errormsg);
111 fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
112 exit(1);
113 }
114 if (optc == 'h') exit(0);
115 switch(option_index)
116 {
117 case FE_OPT_DUMP_VERSIONTUPLE:
118 exit(0);
119 break;
120 default: ;
121 }
122 }
123 long cpus=(long)feOptValue(FE_OPT_CPUS);
124 #ifdef HAVE_VSPACE
126 {
128 feSetOptValue(FE_OPT_CPUS,cpus);
129 }
130 #endif
131
132 /* say hello */
133
134 if (TEST_V_QUIET)
135 {
136 (printf)(
137" SINGULAR /"
138#ifndef MAKE_DISTRIBUTION
139" Development"
140#endif
141"\n"
142" A Computer Algebra System for Polynomial Computations / version %s\n"
143" 0<\n"
144" by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann \\ %s\n"
145"FB Mathematik der Universitaet, D-67653 Kaiserslautern \\\n"
146, VERSION, VERSION_DATE);
147 if (feOptValue(FE_OPT_NO_SHELL))
148 {
149 WarnS("running in restricted mode:"
150 " shell invocation and file links are disallowed");
152 }
153 }
154 else
155 {
157 if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
158 dup2(1,2);
159 /* alternative:
160 * memcpy(stderr,stdout,sizeof(FILE));
161 */
162 }
163 if (feOptValue(FE_OPT_LOG)!=NULL)
164 {
165 int pid=getpid();
166 char *buf=(char*)malloc(10+strlen((char*) feOptSpec[FE_OPT_LOG].value));
167 snprintf(buf,10+strlen((char*) feOptSpec[FE_OPT_LOG].value),
168 "%s.%d",(char*) feOptSpec[FE_OPT_LOG].value,pid);
169 File_Log=fopen(buf,"w");
170 }
171
172#ifdef SINGULAR_PYOBJECT_SETUP_H
174#endif
175#ifdef SI_COUNTEDREF_AUTOLOAD
177#endif
178 errorreported = 0;
179
180 // -- example for "static" modules ------
181 //load_builtin("huhu.so",FALSE,(SModulFunc_t)huhu_mod_init);
182 //module_help_main("huhu.so","Help for huhu\nhaha\n");
183 //module_help_proc("huhu.so","p","Help for huhu::p\nhaha\n");
184 setjmp(si_start_jmpbuf);
185
186 // Now, put things on the stack of stuff to do
187 // Last thing to do is to execute given scripts
188 if (fe_optind < argc)
189 {
190 int i = argc - 1;
191 FILE *fd;
192 while (i >= fe_optind)
193 {
194 if ((fd = feFopen(argv[i], "r")) == NULL)
195 {
196 Warn("Can not open %s", argv[i]);
197 }
198 else
199 {
200 fclose(fd);
201 newFile(argv[i]);
202 }
203 i--;
204 }
205 }
206 else
207 {
209 }
210
211 // before scripts, we execute -c, if it was given
212 if (feOptValue(FE_OPT_EXECUTE) != NULL)
213 newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
214
215 // first thing, however, is to load .singularrc from Singularpath
216 // and cwd/$HOME (in that order).
217 if (! feOptValue(FE_OPT_NO_RC))
218 {
219 char buf[MAXPATHLEN];
220 FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
221 if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
222 if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
223
224 if (rc != NULL)
225 {
226 if (BVERBOSE(V_LOAD_LIB))
227 Print("// ** executing %s\n", buf);
228 fclose(rc);
229 newFile(buf);
230 }
231 }
232
233 /* start shell */
235 {
237 char *linkname=(char*) feOptValue(FE_OPT_LINK);
238 if((linkname!=NULL)&&(strcmp(linkname,"ssi")==0))
239 {
240 return ssiBatch((char*) feOptValue(FE_OPT_MPHOST),(char*) feOptValue(FE_OPT_MPPORT));
241 //Print("batch: p:%s, h:%s\n",(char*) feOptValue(FE_OPT_MPPORT),(char*) feOptValue(FE_OPT_MPHOST));
242 //exit(0);
243 }
244 else
245 {
246 Print("** missing arguments: -b requires --link/--MPhost/--MPport\n");
247 return 1;
248 }
249 }
250 setjmp(si_start_jmpbuf);
251 yyparse();
252 m2_end(0);
253 return 0;
254}
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
void On(int sw)
switches
int i
Definition cfEzgcd.cc:132
static const int SW_USE_NTL_SORT
set to 1 to sort factors in a factorization
Definition cf_defs.h:39
VAR jmp_buf si_start_jmpbuf
Definition cntrlc.cc:98
VAR BOOLEAN singular_in_batchmode
Definition cntrlc.cc:62
void init_signals()
init signal handlers and error handling for libraries: NTL, factory
Definition cntrlc.cc:530
void countedref_init()
Definition countedref.h:458
#define MAKE_DISTRIBUTION
Definition distrib.h:1
#define Print
Definition emacs.cc:80
#define Warn
Definition emacs.cc:77
#define WarnS
Definition emacs.cc:78
EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG
Definition extra.cc:170
#define VERSION
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition feFopen.cc:47
VAR short errorreported
Definition feFopen.cc:23
feOptIndex
Definition feOptGen.h:15
@ FE_OPT_UNDEF
Definition feOptGen.h:15
#define LONG_OPTION_RETURN
Definition feOptTab.h:4
const char SHORT_OPTS_STRING[]
Definition feOpt.cc:29
feOptIndex feGetOptIndex(const char *name)
Definition feOpt.cc:104
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition feOpt.cc:154
static void * feOptValue(feOptIndex opt)
Definition feOpt.h:40
EXTERN_VAR struct fe_option feOptSpec[]
Definition feOpt.h:17
VAR char * feArgv0
Definition feResource.cc:19
#define DIR_SEPP
Definition feResource.h:7
int fe_getopt_long(int argc, char *const *argv, const char *options, const struct fe_option *long_options, int *opt_index)
Definition fegetopt.c:664
char * fe_optarg
Definition fegetopt.c:94
int fe_optind
Definition fegetopt.c:109
@ feOptBool
Definition fegetopt.h:77
#define optional_argument
Definition fegetopt.h:101
char * fe_fgets_dummy(const char *, char *, int)
Definition feread.cc:455
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition feread.cc:32
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition fevoices.cc:166
VAR Voice * currentVoice
Definition fevoices.cc:49
VAR FILE * File_Log
Definition fevoices.cc:33
BOOLEAN newFile(char *fname)
Definition fevoices.cc:129
Voice * feInitStdin(Voice *pp)
Definition fevoices.cc:677
@ BT_execute
Definition fevoices.h:23
int yyparse(void)
Definition grammar.cc:2149
#define assume(x)
Definition mod2.h:389
void m2_end(int i)
Definition misc_ip.cc:1102
static const int MAX_PROCESS
Definition vspace.h:1419
#define omStrDup(s)
#define malloc
Definition omAllocFunc.c:12
#define omInitGetBackTrace()
#define NULL
Definition omList.c:12
#define MAXPATHLEN
Definition omRet2Info.c:22
#define BVERBOSE(a)
Definition options.h:35
#define TEST_V_QUIET
Definition options.h:135
#define V_LOAD_LIB
Definition options.h:47
void pyobject_setup()
initialize blackbox support for pyobject; functionilty os autoloaded on demand
int status int fd
Definition si_signals.h:69
int status int void * buf
Definition si_signals.h:69
int name
New type name for int.
void siInit(char *)
Definition misc_ip.cc:1361
int mmInit(void)
Definition tesths.cc:46
#define omInitRet_2_Info(argv0)
Definition xalloc.h:274

◆ mmInit()

int mmInit ( void )

Definition at line 46 of file tesths.cc.

47{
48#ifndef X_OMALLOC
49#if defined(OMALLOC_USES_MALLOC)
50 /* in mmstd.c, for some architectures freeSize() unconditionally uses the *system* free() */
51 /* sage ticket 5344: http://trac.sagemath.org/sage_trac/ticket/5344 */
52 /* do not rely on the default in Singular as libsingular may be different */
53 mp_set_memory_functions(omMallocFunc,omReallocSizeFunc,omFreeSizeFunc);
54#else
55 mp_set_memory_functions(malloc,reallocSize,freeSize);
56#endif
57#endif
58 return 1;
59}
#define freeSize
Definition omAllocFunc.c:15
#define reallocSize
Definition omAllocFunc.c:17
#define omFreeSizeFunc
Definition xalloc.h:285
#define omReallocSizeFunc
Definition xalloc.h:286
#define omMallocFunc
Definition xalloc.h:284

◆ siInit()

void siInit ( char * name)
extern

Definition at line 1361 of file misc_ip.cc.

1362{
1363// memory initialization: -----------------------------------------------
1364 om_Opts.OutOfMemoryFunc = omSingOutOfMemoryFunc;
1365#ifndef OM_NDEBUG
1366#ifndef __OPTIMIZE__
1367 om_Opts.ErrorHook = dErrorBreak;
1368#else
1369 om_Opts.Keep = 0; /* !OM_NDEBUG, __OPTIMIZE__*/
1370#endif
1371#else
1372 om_Opts.Keep = 0; /* OM_NDEBUG */
1373#endif
1374 omInitInfo();
1375// factory
1376#ifndef HAVE_NTL
1377 extern void initPT();
1378 initPT();
1379#endif
1380// options ---------------------------------------------------------------
1381 si_opt_1=0;
1382// interpreter tables etc.: -----------------------------------------------
1383 memset(&sLastPrinted,0,sizeof(sleftv));
1384 sLastPrinted.rtyp=NONE;
1385
1386 extern int iiInitArithmetic(); iiInitArithmetic(); // iparith.cc
1387
1388 basePack=(package)omAlloc0(sizeof(*basePack));
1390 idhdl h;
1391 h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, FALSE);
1393 IDPACKAGE(h)->language = LANG_TOP;
1394 currPackHdl=h;
1395 basePackHdl=h;
1396
1397 coeffs_BIGINT = nInitChar(n_Q,(void*)1);
1398
1399#if 1
1400 // def HAVE_POLYEXTENSIONS
1401 if(TRUE)
1402 {
1403 n_coeffType type;
1404 #ifdef SINGULAR_4_2
1406 assume(type == n_polyExt);
1407 #endif
1408
1409 type = nRegister(n_algExt, naInitChar);
1410 assume(type == n_algExt);
1411
1413 assume(type == n_transExt);
1414
1415 (void)type;
1416 }
1417#endif
1418
1419// random generator: -----------------------------------------------
1420 {
1421 int t=startTimer();
1422 if (t==0) t=1;
1423 initRTimer();
1424 siSeed=t;
1425 factoryseed(t);
1426 siRandomStart=t;
1427 feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart);
1428 }
1429
1430// ressource table: ----------------------------------------------------
1431 // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
1432 // hack such that all shared' libs in the bindir are loaded correctly
1434
1435// singular links: --------------------------------------------------
1437 myynest=0;
1438// how many processes ? -----------------------------------------------------
1439 {
1440 int cpus=2;
1441 int cpu_n;
1442 #ifdef _SC_NPROCESSORS_ONLN
1443 if ((cpu_n=sysconf(_SC_NPROCESSORS_ONLN))>cpus) cpus=cpu_n;
1444 #elif defined(_SC_NPROCESSORS_CONF)
1445 if ((cpu_n=sysconf(_SC_NPROCESSORS_CONF))>cpus) cpus=cpu_n;
1446 #endif
1448 char *env_cpu=getenv("SINGULAR_CPUS");
1449 if (env_cpu!=NULL)
1450 {
1451 int t=atoi(env_cpu);
1452 if ((t>=0)&&(t<cpus)) cpus=t;
1453 }
1454 feSetOptValue(FE_OPT_CPUS, cpus);
1455// how many threads ? -----------------------------------------------------
1456 feSetOptValue(FE_OPT_THREADS, cpus);
1457 }
1458
1459// default coeffs
1460 {
1461 idhdl h;
1462 h=enterid("QQ",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1463 IDDATA(h)=(char*)nInitChar(n_Q,NULL);
1464 h=enterid("ZZ",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1465 IDDATA(h)=(char*)nInitChar(n_Z,NULL);
1467 iiAddCproc("kernel","crossprod",FALSE,iiCrossProd);
1468 iiAddCproc("kernel","Float",FALSE,iiFloat);
1469 //h=enterid("RR",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1470 //IDDATA(h)=(char*)nInitChar(n_R,NULL);
1471 //h=enterid("CC",0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1472 //IDDATA(h)=(char*)nInitChar(n_long_C,NULL);
1473 }
1474// setting routines for PLURAL QRINGS:
1475// allowing to use libpolys without libSingular(kStd)
1476#ifdef HAVE_PLURAL
1477 nc_NF=k_NF;
1483#endif
1484// loading standard.lib -----------------------------------------------
1485 if (! feOptValue(FE_OPT_NO_STDLIB))
1486 {
1487 BITSET save1,save2;
1488 SI_SAVE_OPT(save1,save2);
1490 iiLibCmd("standard.lib", TRUE,TRUE,TRUE);
1491 SI_RESTORE_OPT(save1,save2);
1492 }
1493 // interpreter error handling
1494 #ifndef __CYGWIN__
1495 factoryError=callWerrorS; // to honour later changes of variable WerrorS
1496 #endif
1497 errorreported = 0;
1498}
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition algext.cc:1386
BOOLEAN n2pInitChar(coeffs cf, void *infoStruct)
Definition algext.cc:1640
#define BITSET
Definition auxiliary.h:85
void initPT()
void factoryseed(int s)
random seed initializer
Definition cf_random.cc:189
VAR void(* factoryError)(const char *s)
Definition cf_util.cc:80
Class used for (list of) interpreter objects.
Definition subexpr.h:83
VAR int siRandomStart
Definition cntrlc.cc:99
n_coeffType
Definition coeffs.h:27
@ n_polyExt
used to represent polys as coefficients
Definition coeffs.h:34
@ n_Q
rational (GMP) numbers
Definition coeffs.h:30
@ n_algExt
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic
Definition coeffs.h:35
@ n_Zn
only used if HAVE_RINGS is defined
Definition coeffs.h:44
@ n_transExt
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition coeffs.h:38
@ n_Z
only used if HAVE_RINGS is defined
Definition coeffs.h:43
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition numbers.cc:406
void feInitResources(const char *argv0)
VAR int myynest
Definition febase.cc:41
char * getenv()
EXTERN_VAR BBA_Proc gnc_gr_bba
Definition gb_hack.h:10
EXTERN_VAR BBA_Proc gnc_gr_mora
Definition gb_hack.h:10
EXTERN_VAR BBA_Proc sca_gr_bba
Definition gb_hack.h:10
EXTERN_VAR NF_Proc nc_NF
Definition gb_hack.h:9
EXTERN_VAR BBA_Proc sca_mora
Definition gb_hack.h:10
EXTERN_VAR BBA_Proc sca_bba
Definition gb_hack.h:10
ideal k_gnc_gr_bba(const ideal F, const ideal Q, const intvec *, const bigintmat *, kStrategy strat, const ring _currRing)
Definition gr_kstd2.cc:1030
ideal k_gnc_gr_mora(const ideal F, const ideal Q, const intvec *, const bigintmat *, kStrategy strat, const ring _currRing)
Definition gr_kstd2.cc:1283
int iiInitArithmetic()
initialisation of arithmetic structured data
Definition iparith.cc:9953
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition ipid.cc:256
VAR package basePack
Definition ipid.cc:56
VAR package currPack
Definition ipid.cc:55
VAR idhdl currPackHdl
Definition ipid.cc:53
VAR idhdl basePackHdl
Definition ipid.cc:54
#define IDDATA(a)
Definition ipid.h:126
#define IDROOT
Definition ipid.h:19
#define IDPACKAGE(a)
Definition ipid.h:139
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition iplib.cc:1073
BOOLEAN iiLibCmd(const char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition iplib.cc:894
STATIC_VAR Poly * h
Definition janet.cc:971
ideal k_sca_bba(const ideal F, const ideal Q, const intvec *, const bigintmat *, kStrategy strat, const ring _currRing)
Modified modern Sinuglar Buchberger's algorithm.
Definition sca.cc:368
ideal k_sca_gr_bba(const ideal F, const ideal Q, const intvec *, const bigintmat *, kStrategy strat, const ring _currRing)
Modified Plural's Buchberger's algorithmus.
Definition sca.cc:95
ideal k_sca_mora(const ideal F, const ideal Q, const intvec *, const bigintmat *, kStrategy strat, const ring _currRing)
Modified modern Sinuglar Mora's algorithm.
Definition sca.cc:885
poly k_NF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce, const ring _currRing)
NOTE: this is just a wrapper which sets currRing for the actual kNF call.
Definition kstd1.cc:3438
static BOOLEAN iiCrossProd(leftv res, leftv args)
Definition misc_ip.cc:1326
void omSingOutOfMemoryFunc()
Definition misc_ip.cc:1199
static BOOLEAN iiFloat(leftv res, leftv pnn)
Definition misc_ip.cc:1297
static void callWerrorS(const char *s)
Definition misc_ip.cc:1360
void dErrorBreak(void)
void nRegisterCfByName(cfInitCfByNameProc p, n_coeffType n)
Definition numbers.cc:624
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
Definition numbers.cc:583
#define omAlloc0(size)
omOpts_t om_Opts
Definition omOpts.c:13
VAR unsigned si_opt_2
Definition options.c:6
VAR unsigned si_opt_1
Definition options.c:5
#define SI_SAVE_OPT(A, B)
Definition options.h:20
#define Sy_bit(x)
Definition options.h:31
#define SI_RESTORE_OPT(A, B)
Definition options.h:23
VAR coeffs coeffs_BIGINT
Definition polys.cc:14
idrec * idhdl
Definition ring.h:22
coeffs nrnInitCfByName(char *s, n_coeffType)
Definition rmodulon.cc:33
#define SIPC_MAX_SEMAPHORES
Definition simpleipc.h:10
VAR int siSeed
Definition sirandom.c:30
ip_package * package
Definition structs.h:39
INST_VAR sleftv sLastPrinted
Definition subexpr.cc:46
@ LANG_TOP
Definition subexpr.h:22
int startTimer()
Definition timer.cc:66
void initRTimer()
Definition timer.cc:136
@ CRING_CMD
Definition tok.h:56
@ PACKAGE_CMD
Definition tok.h:150
#define NONE
Definition tok.h:223
BOOLEAN ntInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition transext.cc:2636
#define omInitInfo()
Definition xalloc.h:228

Variable Documentation

◆ FE_OPT_NO_SHELL_FLAG

EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG

Definition at line 44 of file tesths.cc.

◆ File_Log

EXTERN_VAR FILE* File_Log

Definition at line 43 of file tesths.cc.