50 #define STRINGIFY(x) STRINGIFY__(x)
51 #define STRINGIFY__(x) #x
56 #if defined(WITHPTHREADS)
57 #define FORMNAME "TFORM"
58 #elif defined(WITHMPI)
59 #define FORMNAME "ParFORM"
61 #define FORMNAME "FORM"
71 #define REPO_VERSION STRINGIFY(REPO_MAJOR_VERSION) "." STRINGIFY(REPO_MINOR_VERSION)
75 #define REPO_DATE __DATE__
78 #define VERSIONSTR FORMNAME " " REPO_VERSION " (" REPO_DATE ", " REPO_REVISION ")"
80 #define VERSIONSTR FORMNAME " " REPO_VERSION " (" REPO_DATE ")"
82 #define MAJORVERSION REPO_MAJOR_VERSION
83 #define MINORVERSION REPO_MINOR_VERSION
90 #define VERSIONSTR__ STRINGIFY(MAJORVERSION) "." STRINGIFY(MINORVERSION) "Beta"
92 #define VERSIONSTR__ STRINGIFY(MAJORVERSION) "." STRINGIFY(MINORVERSION)
94 #define VERSIONSTR FORMNAME " " VERSIONSTR__ " (" PRODUCTIONDATE ")"
107 static void PrintHeader(
int with_full_info)
110 if ( PF.me == MASTER && !AM.silent ) {
114 char buffer1[250], buffer2[80], *s = buffer1, *t = buffer2;
116 for ( n = 0; n < 250; n++ ) buffer1[n] =
' ';
121 if ( strlen(VERSIONSTR) <= 100 ) {
122 strcpy(s,VERSIONSTR);
123 s += strlen(VERSIONSTR);
130 strncpy(s,VERSIONSTR,97);
138 s += sprintf(s,
" %d-bits",(WORD)(
sizeof(WORD)*16));
142 if ( with_full_info ) {
143 #if defined(WITHPTHREADS) || defined(WITHMPI)
144 #if defined(WITHPTHREADS)
145 int nworkers = AM.totalnumberofthreads-1;
146 #elif defined(WITHMPI)
147 int nworkers = PF.numtasks-1;
149 s += sprintf(s,
" %d worker",nworkers);
152 if ( nworkers != 1 ) {
158 sprintf(t,
"Run: %s",MakeDate());
164 length = (s-buffer1) + (t-buffer2);
165 if ( length+2 <= AC.LineLength ) {
166 for ( n = AC.LineLength-length; n > 0; n-- ) *s++ =
' ';
186 if ( length <= AC.LineLength ) {
187 MesPrint(
"%s",buffer1);
190 WORD oldLineLength = AC.LineLength;
191 AC.LineLength = length;
192 MesPrint(
"%s",buffer1);
193 AC.LineLength = oldLineLength;
211 #ifdef WITHINTERACTION
212 static UBYTE deflogname[] =
"formsession.log";
215 #define TAKEPATH(x) if(s[1]== '=' ){x=s+2;} else{x=*argv++;argc--;}
217 int DoTail(
int argc, UBYTE **argv)
219 int errorflag = 0, onlyversion = 1;
226 AM.HoldFlag = AM.qError = AM.Interact = AM.FileOnlyFlag = 0;
227 AM.InputFileName = AM.LogFileName = AM.IncDir = AM.TempDir = AM.TempSortDir =
228 AM.SetupDir = AM.SetupFile = AM.Path = 0;
233 while ( argc >= 1 ) {
235 if ( *s ==
'-' || ( *s ==
'/' && ( argc > 0 || AM.Interact ) ) ) {
239 AM.qError = 1;
break;
242 t = copy = strDup1(*argv,
"Dotail");
243 while ( *t && *t !=
'=' ) t++;
245 if (
PutPreVar(copy,(UBYTE *)
"1",0,0) < 0 )
return(-1);
249 if (
PutPreVar(copy,t,0,0) < 0 )
return(-1);
252 M_free(copy,
"-d prevar");
253 argv++; argc--;
break;
255 AM.FileOnlyFlag = 1; AM.LogType = 0;
break;
257 AM.FileOnlyFlag = 1; AM.LogType = 1;
break;
259 AM.HoldFlag = 1;
break;
260 #ifdef WITHINTERACTION
262 AM.Interact = 1;
break;
265 TAKEPATH(AM.IncDir) break;
267 if ( s[1] == 'l' ) AM.LogType = 1;
271 AM.LogType = 1; break;
279 while ( *s >= '0' && *s <= '9' )
280 threadnum = 10*threadnum + *s++ - '0';
283 if ( PF.me == MASTER )
285 printf(
"Illegal value for option m or w: %s\n",t);
292 AM.ggWTimeStatsFlag = 1;
299 #ifdef WITHEXTERNALCHANNEL
302 if( (s[2]==
'p')&&(s[3]==
'e')&&(s[4]==
'\0') ){
306 if(initPresetExternalChannels(*argv++,AX.timeout)<1){
308 if ( PF.me == MASTER )
310 printf(
"Error initializing preset external channels\n");
317 if ( PF.me == MASTER )
319 printf(
"Illegal option in call of FORM: %s\n",s);
325 if ( ( s[1]==
'i' ) && ( s[2] ==
'p' ) && (s[3] ==
'e' )
326 && ( s[4] ==
'\0' ) ){
328 if ( PF.me == MASTER )
330 printf(
"Illegal option: Pipes not supported on this system.\n");
334 if ( PF.me == MASTER )
336 printf(
"Illegal option: %s\n",s);
348 AM.silent = 1;
break;
350 AC.CheckpointFlag = -1;
353 if ( ( s[1] ==
'o' ) && ( s[2] ==
'r' ) && ( s[3] ==
't' ) ) {
355 AM.TempSortDir = s+5;
358 AM.TempSortDir = *argv++;
362 else if ( s[1] ==
'i' ) {
366 TAKEPATH(AM.SetupDir)
370 TAKEPATH(AM.SetupFile) break;
375 TAKEPATH(AM.TempSortDir)
382 AM.PrintTotalSize = 1;
break;
386 if ( PF.me == MASTER )
389 if ( onlyversion )
return(1);
392 AP.PreDebug = PREPROONLY;
break;
396 while ( *s >=
'0' && *s <=
'9' )
397 AM.TimeLimit = 10*AM.TimeLimit + *s++ -
'0';
400 AM.ClearStore = 1;
break;
402 if ( FG.cTable[*s] == 1 ) {
403 AM.SkipClears = 0; t = s;
404 while ( FG.cTable[*t] == 1 )
405 AM.SkipClears = 10*AM.SkipClears + *t++ -
'0';
408 if ( PF.me == MASTER )
410 printf(
"Illegal numerical option in call of FORM: %s\n",s);
416 if ( PF.me == MASTER )
418 printf(
"Illegal option in call of FORM: %s\n",s);
424 else if ( argc == 0 && !AM.Interact ) AM.InputFileName = argv[-1];
427 if ( PF.me == MASTER )
429 printf(
"Illegal option in call of FORM: %s\n",s);
433 AM.totalnumberofthreads = threadnum;
434 if ( AM.InputFileName ) {
435 s = AM.InputFileName;
437 if ( s < AM.InputFileName+4 ||
438 s[-4] !=
'.' || s[-3] !=
'f' || s[-2] !=
'r' || s[-1] !=
'm' ) {
439 t = (UBYTE *)Malloc1((s-AM.InputFileName)+5,
"adding .frm");
440 s = AM.InputFileName;
441 AM.InputFileName = t;
442 while ( *s ) *t++ = *s++;
443 *t++ =
'.'; *t++ =
'f'; *t++ =
'r'; *t++ =
'm'; *t = 0;
445 if ( AM.LogType >= 0 ) {
446 AM.LogFileName = strDup1(AM.InputFileName,
"name of logfile");
449 s[-3] =
'l'; s[-2] =
'o'; s[-1] =
'g';
452 #ifdef WITHINTERACTION
453 else if ( AM.Interact ) {
454 if ( AM.LogType >= 0 ) {
459 AM.LogFileName = deflogname;
466 if ( PF.me == MASTER )
468 printf(
"No filename specified in call of FORM\n");
471 if ( AM.Path == 0 ) AM.Path = (UBYTE *)getenv(
"FORMPATH");
477 AM.Path = strDup1(AM.Path,
"DoTail Path");
492 int oldNoShowInput = AC.NoShowInput;
494 if ( !AM.Interact ) {
495 if ( OpenStream(AM.InputFileName,FILESTREAM,0,PRENOACTION) == 0 ) {
496 Error1(
"Cannot open file",AM.InputFileName);
499 if ( AC.CurrentStream->inbuffer <= 0 ) {
500 Error1(
"No input in file",AM.InputFileName);
504 while ( AM.SkipClears > 0 ) {
506 if ( c == ENDOFINPUT ) {
507 Error0(
"Not enough .clear instructions in input file");
511 if ( c == ENDOFINPUT )
512 Error0(
"Not enough .clear instructions in input file");
515 if ( c ==
' ' || c ==
'\t' )
continue;
518 if ( tolower(c) ==
'c' ) {
520 if ( tolower(c) ==
'l' ) {
522 if ( tolower(c) ==
'e' ) {
524 if ( tolower(c) ==
'a' ) {
526 if ( tolower(c) ==
'r' ) {
528 if ( FG.cTable[c] > 2 ) {
536 while ( c !=
'\n' && c !=
'\r' && c != ENDOFINPUT ) {
538 if ( c ==
'\\' ) c = GetInput();
541 else if ( c ==
'\n' || c ==
'\r' )
continue;
543 while ( ( c = GetInput() ) !=
'\n' && c !=
'\r' ) {
544 if ( c == ENDOFINPUT ) {
545 Error0(
"Not enough .clear instructions in input file");
550 AC.NoShowInput = oldNoShowInput;
552 if ( AM.LogFileName ) {
554 if ( PF.me != MASTER ) {
559 extern FILES **filelist;
560 int i = CreateHandle();
561 RWLOCKW(AM.handlelock);
562 filelist[i] = (FILES *)123;
563 UNRWLOCK(AM.handlelock);
568 if ( AC.CheckpointFlag != -1 ) {
569 if ( ( AC.LogHandle = CreateLogFile((
char *)(AM.LogFileName)) ) < 0 ) {
570 Error1(
"Cannot create logfile",AM.LogFileName);
575 if ( ( AC.LogHandle = OpenAddFile((
char *)(AM.LogFileName)) ) < 0 ) {
576 Error1(
"Cannot re-open logfile",AM.LogFileName);
600 UBYTE *emptystring = (UBYTE *)
".";
601 UBYTE *defaulttempfilename = (UBYTE *)
"xformxxx.str";
603 VOID ReserveTempFiles(
int par)
607 UBYTE *s, *t, *tenddir, *tenddir2, c;
610 if ( par == 0 || par == 1 ) {
611 if ( AM.TempDir == 0 ) {
612 sp = GetSetupPar((UBYTE *)
"tempdir");
613 if ( ( sp->flags & USEDFLAG ) != USEDFLAG ) {
614 AM.TempDir = (UBYTE *)getenv(
"FORMTMP");
615 if ( AM.TempDir == 0 ) AM.TempDir = emptystring;
617 else AM.TempDir = (UBYTE *)(sp->value);
619 if ( AM.TempSortDir == 0 ) {
620 if ( AM.havesortdir ) {
621 sp = GetSetupPar((UBYTE *)
"tempsortdir");
622 AM.TempSortDir = (UBYTE *)(sp->value);
625 AM.TempSortDir = (UBYTE *)getenv(
"FORMTMPSORT");
626 if ( AM.TempSortDir == 0 ) AM.TempSortDir = AM.TempDir;
634 s = AM.TempDir; i = 200;
635 while ( *s && *s !=
':' ) {
if ( *s ==
'\\' ) s++; s++; i++; }
637 FG.fname = (
char *)Malloc1(
sizeof(UBYTE)*(i+14),
"name for temporary files");
638 s = AM.TempDir; t = (UBYTE *)FG.fname;
639 while ( *s && *s !=
':' ) {
if ( *s ==
'\\' ) s++; *t++ = *s++; }
640 if ( (
char *)t > FG.fname && t[-1] != SEPARATOR && t[-1] != ALTSEPARATOR )
644 FG.fnamebase = t-(UBYTE *)(FG.fname);
646 s = AM.TempSortDir; i = 200;
647 while ( *s && *s !=
':' ) {
if ( *s ==
'\\' ) s++; s++; i++; }
649 FG.fname2 = (
char *)Malloc1(
sizeof(UBYTE)*(i+14),
"name for sort files");
650 s = AM.TempSortDir; t = (UBYTE *)FG.fname2;
651 while ( *s && *s !=
':' ) {
if ( *s ==
'\\' ) s++; *t++ = *s++; }
652 if ( (
char *)t > FG.fname2 && t[-1] != SEPARATOR && t[-1] != ALTSEPARATOR )
656 FG.fname2base = t-(UBYTE *)(FG.fname2);
659 s = defaulttempfilename;
665 M_free(FG.fname,
"name for temporary files");
670 FG.fname = calloc(128,1);
671 strcpy(FG.fname,
"/formswap/xxxxxxxxxxxxxxxxxxxxx");
673 t = (UBYTE *)FG.fname + 10;
674 FG.fnamebase = t-FG.fname;
679 FG.fname = calloc(128,1);
680 strcpy(FG.fname,
"/formswapx/xxxxxxxxxxxxxxxxxxxxx");
682 FG.fname[9] =
'0' + PF.me;
683 t = (UBYTE *)FG.fname + 11;
684 FG.fnamebase = t-FG.fname;
687 iii = sprintf((
char*)t,
"%d",PF.me);
693 while ( *s ) *t++ = *s++;
705 int num = ((int)GetPID())%100000;
712 t[-5] = (UBYTE)(
'0' + num%10);
713 t[-6] = (UBYTE)(
'0' + (num/10)%10);
714 t[-7] = (UBYTE)(
'0' + (num/100)%10);
715 t[-8] = (UBYTE)(
'0' + (num/1000)%10);
716 t[-9] = (UBYTE)(
'0' + num/10000);
717 if ( ( AC.StoreHandle = CreateFile((
char *)FG.fname) ) < 0 ) {
718 t[-5] =
'x'; t[-6] =
'x'; t[-7] =
'x'; t[-8] =
'x'; t[-9] =
'x';
726 if ( ( AC.StoreHandle = OpenFile((
char *)FG.fname) ) < 0 ) {
727 if ( ( AC.StoreHandle = CreateFile((
char *)FG.fname) ) >= 0 )
break;
729 else CloseFile(AC.StoreHandle);
731 if ( c ==
'x' ) t[-5] =
'0';
732 else if ( c ==
'9' ) {
735 if ( c ==
'x' ) t[-6] =
'0';
736 else if ( c ==
'9' ) {
739 if ( c ==
'x' ) t[-7] =
'0';
740 else if ( c ==
'9' ) {
744 MesPrint(
"Name space for temp files exhausted");
746 MesPrint(
"Please remove files of the type %s or try a different directory"
750 else t[-7] = (UBYTE)(c+1);
752 else t[-6] = (UBYTE)(c+1);
754 else t[-5] = (UBYTE)(c+1);
761 s = tenddir; t = tenddir2;
while ( *s ) *t++ = *s++;
767 AM.S0->file.name = (
char *)Malloc1(
sizeof(
char)*(i+14),
"name for temporary files");
768 s = (UBYTE *)AM.S0->file.name;
769 t = (UBYTE *)FG.fname2;
771 while ( *t ) { *s++ = *t++; i++; }
780 s = (UBYTE *)((
void *)(FG.fname2)); i = 0;
781 while ( *s ) { s++; i++; }
782 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+1),
"name for stage4 file a");
783 AR.FoStage4[1].name = (
char *)s;
784 t = (UBYTE *)FG.fname2;
785 while ( *t ) *s++ = *t++;
786 s[-2] =
'4'; s[-1] =
'a'; *s = 0;
787 s = (UBYTE *)((
void *)(FG.fname)); i = 0;
788 while ( *s ) { s++; i++; }
789 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+1),
"name for stage4 file b");
790 AR.FoStage4[0].name = (
char *)s;
791 t = (UBYTE *)FG.fname;
792 while ( *t ) *s++ = *t++;
793 s[-2] =
'4'; s[-1] =
'b'; *s = 0;
794 for ( j = 0; j < 3; j++ ) {
795 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+1),
"name for scratch file");
796 AR.Fscr[j].name = (
char *)s;
797 t = (UBYTE *)FG.fname;
798 while ( *t ) *s++ = *t++;
799 s[-2] =
'c'; s[-1] = (UBYTE)(
'0'+j); *s = 0;
803 else if ( par == 2 ) {
804 s = (UBYTE *)((
void *)(FG.fname2)); i = 0;
805 while ( *s ) { s++; i++; }
806 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+12),
"name for stage4 file a");
807 sprintf((
char *)s,
"%s.%d",FG.fname2,AT.identity);
808 s[i-2] =
'4'; s[i-1] =
'a';
809 AR.FoStage4[1].name = (
char *)s;
810 s = (UBYTE *)((
void *)(FG.fname)); i = 0;
811 while ( *s ) { s++; i++; }
812 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+12),
"name for stage4 file b");
813 sprintf((
char *)s,
"%s.%d",FG.fname,AT.identity);
814 s[i-2] =
'4'; s[i-1] =
'b';
815 AR.FoStage4[0].name = (
char *)s;
816 if ( AT.identity == 0 ) {
817 for ( j = 0; j < 3; j++ ) {
818 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+1),
"name for scratch file");
819 AR.Fscr[j].name = (
char *)s;
820 t = (UBYTE *)FG.fname;
821 while ( *t ) *s++ = *t++;
822 s[-2] =
'c'; s[-1] = (UBYTE)(
'0'+j); *s = 0;
835 ALLPRIVATES *DummyPointer = 0;
851 AB = (ALLPRIVATES **)&DummyPointer;
857 set_sub(AC.separators,AC.separators,AC.separators);
858 set_set(
',',AC.separators);
859 set_set(
'|',AC.separators);
861 AM.BracketFactors[0] = 8;
862 AM.BracketFactors[1] = SYMBOL;
863 AM.BracketFactors[2] = 4;
864 AM.BracketFactors[3] = FACTORSYMBOL;
865 AM.BracketFactors[4] = 1;
866 AM.BracketFactors[5] = 1;
867 AM.BracketFactors[6] = 1;
868 AM.BracketFactors[7] = 3;
873 AC.OutputSpaces = NORMALFORMAT;
875 AM.gIsFortran90 = AC.IsFortran90 = ISNOTFORTRAN90;
876 AM.gFortran90Kind = AC.Fortran90Kind = 0;
878 AC.exprfillwarning = 0;
881 AM.MaxStreamSize = MAXFILESTREAMSIZE;
882 AP.MaxPreAssignLevel = 4;
883 AC.iBufferSize = 512;
885 AP.MaxPreIfLevel = 10;
886 AP.cComChar = AP.ComChar =
'*';
887 AM.OffsetVector = -2*WILDOFFSET+MINSPEC;
889 AM.hparallelflag = AM.gparallelflag =
890 AC.parallelflag = AC.mparallelflag = PARALLELFLAG;
892 if ( PF.numtasks < 2 ) AM.hparallelflag |= NOPARALLEL_NPROC;
895 AM.resetTimeOnClear = 1;
896 AM.gnumextrasym = AM.ggnumextrasym = 0;
898 AM.SpectatorFiles = 0;
899 AM.NumSpectatorFiles = 0;
900 AM.SizeForSpectatorFiles = 0;
904 AP.ProcList.message =
"procedure";
906 AP.LoopList.message =
"doloop";
907 AP.LoopList.size =
sizeof(
DOLOOP);
908 AP.PreVarList.message =
"PreVariable";
909 AP.PreVarList.size =
sizeof(
PREVAR);
910 AC.SymbolList.message =
"symbol";
911 AC.SymbolList.size =
sizeof(
struct SyMbOl);
912 AC.IndexList.message =
"index";
913 AC.IndexList.size =
sizeof(
struct InDeX);
914 AC.VectorList.message =
"vector";
915 AC.VectorList.size =
sizeof(
struct VeCtOr);
916 AC.FunctionList.message =
"function";
917 AC.FunctionList.size =
sizeof(
struct FuNcTiOn);
918 AC.SetList.message =
"set";
919 AC.SetList.size =
sizeof(
struct SeTs);
920 AC.SetElementList.message =
"set element";
921 AC.SetElementList.size =
sizeof(WORD);
922 AC.ExpressionList.message =
"expression";
923 AC.ExpressionList.size =
sizeof(
struct ExPrEsSiOn);
924 AC.cbufList.message =
"compiler buffer";
925 AC.cbufList.size =
sizeof(
CBUF);
926 AC.ChannelList.message =
"channel buffer";
927 AC.ChannelList.size =
sizeof(
CHANNEL);
928 AP.DollarList.message =
"$-variable";
929 AP.DollarList.size =
sizeof(
struct DoLlArS);
930 AC.DubiousList.message =
"ambiguous variable";
931 AC.DubiousList.size =
sizeof(
struct DuBiOuS);
932 AC.TableBaseList.message =
"list of tablebases";
933 AC.TableBaseList.size =
sizeof(
DBASE);
937 AC.AutoSymbolList.message =
"autosymbol";
938 AC.AutoSymbolList.size =
sizeof(
struct SyMbOl);
939 AC.AutoIndexList.message =
"autoindex";
940 AC.AutoIndexList.size =
sizeof(
struct InDeX);
941 AC.AutoVectorList.message =
"autovector";
942 AC.AutoVectorList.size =
sizeof(
struct VeCtOr);
943 AC.AutoFunctionList.message =
"autofunction";
944 AC.AutoFunctionList.size =
sizeof(
struct FuNcTiOn);
945 AC.PotModDolList.message =
"potentially modified dollar";
946 AC.PotModDolList.size =
sizeof(WORD);
947 AC.ModOptDolList.message =
"moduleoptiondollar";
950 AO.FortDotChar =
'_';
952 AC.firstconstindex = 1;
953 AO.Optimize.mctsconstant.fval = 1.0;
954 AO.Optimize.horner = O_MCTS;
955 AO.Optimize.hornerdirection = O_FORWARDORBACKWARD;
956 AO.Optimize.method = O_GREEDY;
957 AO.Optimize.mctstimelimit = 0;
958 AO.Optimize.mctsnumexpand = 1000;
959 AO.Optimize.mctsnumkeep = 10;
960 AO.Optimize.mctsnumrepeat = 1;
961 AO.Optimize.greedytimelimit = 0;
962 AO.Optimize.greedyminnum = 10;
963 AO.Optimize.greedymaxperc = 5;
964 AO.Optimize.printstats = 0;
965 AO.Optimize.debugflags = 0;
966 AO.OptimizeResult.code = NULL;
974 AC.doloopstacksize = 0;
979 AC.varnames = MakeNameTree();
980 AC.exprnames = MakeNameTree();
981 AC.dollarnames = MakeNameTree();
982 AC.autonames = MakeNameTree();
983 AC.activenames = &(AC.varnames);
1004 CBUF *C = cbuf+AM.zbufnum;
1005 WORD one[5] = {4,1,1,3,0};
1008 AM.zerorhs = C->numrhs;
1009 AddNtoC(AM.zbufnum,1,&zero,17);
1011 AM.onerhs = C->numrhs;
1018 AC.Symbols = &(AC.SymbolList);
1019 AC.Indices = &(AC.IndexList);
1020 AC.Vectors = &(AC.VectorList);
1021 AC.Functions = &(AC.FunctionList);
1024 AddDollar((UBYTE *)
"$",DOLUNDEFINED,0,0);
1026 cbuf[AM.dbufnum].mnumlhs = cbuf[AM.dbufnum].numlhs;
1027 cbuf[AM.dbufnum].mnumrhs = cbuf[AM.dbufnum].numrhs;
1029 AddSymbol((UBYTE *)
"i_",-MAXPOWER,MAXPOWER,VARTYPEIMAGINARY,0);
1030 AddSymbol((UBYTE *)
"pi_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1031 AddSymbol((UBYTE *)
"coeff_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1032 AddSymbol((UBYTE *)
"num_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1033 AddSymbol((UBYTE *)
"den_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1034 AddSymbol((UBYTE *)
"xarg_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1035 AddSymbol((UBYTE *)
"dimension_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1036 AddSymbol((UBYTE *)
"factor_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1037 AddSymbol((UBYTE *)
"sep_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1046 for ( ; i < FIRSTUSERSYMBOL; i++ ) {
1047 sprintf(dumstr,
":%d:",i);
1048 AddSymbol((UBYTE *)dumstr,-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1052 AddIndex((UBYTE *)
"iarg_",4,0);
1053 AddVector((UBYTE *)
"parg_",VARTYPENONE,0);
1055 AM.NumFixedFunctions =
sizeof(fixedfunctions)/
sizeof(
struct fixedfun);
1056 for ( i = 0; i < AM.NumFixedFunctions; i++ ) {
1057 ii = AddFunction((UBYTE *)fixedfunctions[i].
name
1058 ,fixedfunctions[i].commu
1059 ,fixedfunctions[i].tensor
1060 ,fixedfunctions[i].complx
1063 if ( fixedfunctions[i].tensor == GAMMAFUNCTION )
1064 functions[ii].flags |= COULDCOMMUTE;
1073 for ( ; i < FIRSTUSERFUNCTION-FUNCTION; i++ ) {
1074 sprintf(dumstr,
"::%d::",i);
1075 AddFunction((UBYTE *)dumstr,0,0,0,0,0,-1,-1);
1078 AM.NumFixedSets =
sizeof(fixedsets)/
sizeof(
struct fixedset);
1079 for ( i = 0; i < AM.NumFixedSets; i++ ) {
1080 ii = AddSet((UBYTE *)fixedsets[i].
name,fixedsets[i].dimension);
1081 Sets[ii].type = fixedsets[i].type;
1083 AM.RepMax = MAXREPEAT;
1084 #ifndef WITHPTHREADS
1085 AT.RepCount = (
int *)Malloc1((LONG)((AM.RepMax+3)*
sizeof(
int)),
"repeat buffers");
1086 AN.RepPoint = AT.RepCount;
1087 AT.RepTop = AT.RepCount + AM.RepMax;
1088 AN.polysortflag = 0;
1091 AC.NumWildcardNames = 0;
1092 AC.WildcardBufferSize = 50;
1093 AC.WildcardNames = (UBYTE *)Malloc1((LONG)AC.WildcardBufferSize,
"argument list names");
1094 #ifndef WITHPTHREADS
1095 AT.WildArgTaken = (WORD *)Malloc1((LONG)AC.WildcardBufferSize*
sizeof(WORD)/2
1096 ,
"argument list names");
1097 AT.WildcardBufferSize = AC.WildcardBufferSize;
1099 AT.nfac = AT.nBer = 0;
1104 AR.wranfnpair1 = NPAIR1;
1105 AR.wranfnpair2 = NPAIR2;
1109 AM.oldnumextrasymbols = strDup1((UBYTE *)
"OLDNUMEXTRASYMBOLS_",
"oldnumextrasymbols");
1110 PutPreVar((UBYTE *)
"VERSION_",(UBYTE *)STRINGIFY(MAJORVERSION),0,0);
1111 PutPreVar((UBYTE *)
"SUBVERSION_",(UBYTE *)STRINGIFY(MINORVERSION),0,0);
1112 PutPreVar((UBYTE *)
"DATE_",(UBYTE *)MakeDate(),0,0);
1113 PutPreVar((UBYTE *)
"random_",(UBYTE *)
"________",(UBYTE *)
"?a",0);
1114 PutPreVar((UBYTE *)
"optimminvar_",(UBYTE *)(
"0"),0,0);
1115 PutPreVar((UBYTE *)
"optimmaxvar_",(UBYTE *)(
"0"),0,0);
1116 PutPreVar(AM.oldnumextrasymbols,(UBYTE *)(
"0"),0,0);
1117 PutPreVar((UBYTE *)
"optimvalue_",(UBYTE *)(
"0"),0,0);
1118 PutPreVar((UBYTE *)
"optimscheme_",(UBYTE *)(
"0"),0,0);
1119 PutPreVar((UBYTE *)
"tolower_",(UBYTE *)(
"0"),(UBYTE *)(
"?a"),0);
1120 PutPreVar((UBYTE *)
"toupper_",(UBYTE *)(
"0"),(UBYTE *)(
"?a"),0);
1121 PutPreVar((UBYTE *)
"SYSTEMERROR_",(UBYTE *)(
"0"),0,0);
1128 pid = ( PF.me == MASTER ) ? GetPID() : (LONG)0;
1132 PutPreVar((UBYTE *)
"PID_",(UBYTE *)buf,0,0);
1135 AP.MaxPreTypes = 10;
1137 AP.PreTypes = (
int *)Malloc1(
sizeof(
int)*(AP.MaxPreTypes+1),
"preprocessor types");
1138 AP.inside.buffer = 0;
1141 AC.SortType = AC.lSortType = AM.gSortType = SORTLOWFIRST;
1144 AR.SortType = AC.SortType;
1147 AC.SetList.numtemp = AC.SetList.num;
1148 AC.SetElementList.numtemp = AC.SetElementList.num;
1150 GetName(AC.varnames,(UBYTE *)
"exp_",&AM.expnum,NOAUTO);
1151 GetName(AC.varnames,(UBYTE *)
"denom_",&AM.denomnum,NOAUTO);
1152 GetName(AC.varnames,(UBYTE *)
"fac_",&AM.facnum,NOAUTO);
1153 GetName(AC.varnames,(UBYTE *)
"invfac_",&AM.invfacnum,NOAUTO);
1154 GetName(AC.varnames,(UBYTE *)
"sum_",&AM.sumnum,NOAUTO);
1155 GetName(AC.varnames,(UBYTE *)
"sump_",&AM.sumpnum,NOAUTO);
1156 GetName(AC.varnames,(UBYTE *)
"term_",&AM.termfunnum,NOAUTO);
1157 GetName(AC.varnames,(UBYTE *)
"match_",&AM.matchfunnum,NOAUTO);
1158 GetName(AC.varnames,(UBYTE *)
"count_",&AM.countfunnum,NOAUTO);
1159 AM.termfunnum += FUNCTION;
1160 AM.matchfunnum += FUNCTION;
1161 AM.countfunnum += FUNCTION;
1163 AC.ThreadStats = AM.gThreadStats = AM.ggThreadStats = 1;
1164 AC.FinalStats = AM.gFinalStats = AM.ggFinalStats = 1;
1165 AC.StatsFlag = AM.gStatsFlag = AM.ggStatsFlag = 1;
1166 AC.ThreadsFlag = AM.gThreadsFlag = AM.ggThreadsFlag = 1;
1167 AC.ThreadBalancing = AM.gThreadBalancing = AM.ggThreadBalancing = 1;
1168 AC.ThreadSortFileSynch = AM.gThreadSortFileSynch = AM.ggThreadSortFileSynch = 0;
1169 AC.ProcessStats = AM.gProcessStats = AM.ggProcessStats = 1;
1170 AC.OldParallelStats = AM.gOldParallelStats = AM.ggOldParallelStats = 0;
1171 AC.OldFactArgFlag = AM.gOldFactArgFlag = AM.ggOldFactArgFlag = NEWFACTARG;
1172 AC.OldGCDflag = AM.gOldGCDflag = AM.ggOldGCDflag = 1;
1173 AC.WTimeStatsFlag = AM.gWTimeStatsFlag = AM.ggWTimeStatsFlag = 0;
1174 AM.gcNumDollars = AP.DollarList.num;
1175 AC.SizeCommuteInSet = AM.gSizeCommuteInSet = 0;
1176 AC.CommuteInSet = 0;
1178 AM.PrintTotalSize = 0;
1180 AO.NoSpacesInNumbers = AM.gNoSpacesInNumbers = AM.ggNoSpacesInNumbers = 0;
1181 AO.IndentSpace = AM.gIndentSpace = AM.ggIndentSpace = INDENTSPACE;
1183 AO.OptimizationLevel = 0;
1184 PUTZERO(AS.MaxExprSize);
1185 PUTZERO(AC.StoreFileSize);
1188 AC.inputnumbers = 0;
1190 AC.numpfirstnum = AC.sizepfirstnum = 0;
1192 AC.MemDebugFlag = 1;
1194 #ifdef WITHEXTERNALCHANNEL
1195 AX.currentExternalChannel=0;
1196 AX.killSignal=SIGKILL;
1197 AX.killWholeGroup=1;
1201 AX.shellname=strDup1((UBYTE *)
"/bin/sh -c",
"external channel shellname");
1202 AX.stderrname=strDup1((UBYTE *)
"/dev/null",
"external channel stderrname");
1213 #ifdef WITHEXTERNALCHANNEL
1219 initPresetExternalChannels((UBYTE*)getenv(
"FORM_PIPES"),AX.timeout);
1229 sprintf((
char*)buf,
"%d",PF.me);
1230 PutPreVar((UBYTE *)
"PARALLELTASK_",buf,0,0);
1231 sprintf((
char*)buf,
"%d",PF.numtasks);
1232 PutPreVar((UBYTE *)
"NPARALLELTASKS_",buf,0,0);
1235 PutPreVar((UBYTE *)
"PARALLELTASK_",(UBYTE *)
"0",0,0);
1236 PutPreVar((UBYTE *)
"NPARALLELTASKS_",(UBYTE *)
"1",0,0);
1239 PutPreVar((UBYTE *)
"NAME_",AM.InputFileName,0,0);
1256 WORD *fi, i, one = 1;
1257 CBUF *C = cbuf+AC.cbufnum;
1261 sprintf((
char*)buf,
"%d",AM.totalnumberofthreads);
1262 PutPreVar((UBYTE *)
"NTHREADS_",buf,0,1);
1264 PutPreVar((UBYTE *)
"NTHREADS_",(UBYTE *)
"1",0,1);
1269 AR.SortType = AC.SortType = AC.lSortType = AM.gSortType;
1271 AC.OutputSpaces = NORMALFORMAT;
1274 AC.ncmod = AM.gncmod = 0;
1275 AC.modmode = AM.gmodmode = 0;
1276 AC.npowmod = AM.gnpowmod = 0;
1277 AC.halfmod = 0; AC.nhalfmod = 0;
1279 AC.lPolyFun = AM.gPolyFun = 0;
1280 AC.lPolyFunInv = AM.gPolyFunInv = 0;
1281 AC.lPolyFunType = AM.gPolyFunType = 0;
1282 AC.lPolyFunExp = AM.gPolyFunExp = 0;
1283 AC.lPolyFunVar = AM.gPolyFunVar = 0;
1284 AC.lPolyFunPow = AM.gPolyFunPow = 0;
1286 AC.lDefDim = AM.gDefDim = 4;
1287 AC.lDefDim4 = AM.gDefDim4 = 0;
1288 AC.lUnitTrace = AM.gUnitTrace = 4;
1289 AC.NamesFlag = AM.gNamesFlag = 0;
1290 AC.CodesFlag = AM.gCodesFlag = 0;
1291 AC.extrasymbols = AM.gextrasymbols = AM.ggextrasymbols = 0;
1292 AC.extrasym = (UBYTE *)Malloc1(2*
sizeof(UBYTE),
"extrasym");
1293 AM.gextrasym = (UBYTE *)Malloc1(2*
sizeof(UBYTE),
"extrasym");
1294 AM.ggextrasym = (UBYTE *)Malloc1(2*
sizeof(UBYTE),
"extrasym");
1295 AC.extrasym[0] = AM.gextrasym[0] = AM.ggextrasym[0] =
'Z';
1296 AC.extrasym[1] = AM.gextrasym[1] = AM.ggextrasym[1] = 0;
1297 AC.TokensWriteFlag = AM.gTokensWriteFlag = 0;
1299 AC.LineLength = AM.gLineLength = 79;
1303 AC.OutputSpaces = NORMALFORMAT;
1304 AM.gOutputSpaces = NORMALFORMAT;
1305 AC.OutNumberType = RATIONALMODE;
1306 AM.gOutNumberType = RATIONALMODE;
1308 AR.gzipCompress = GZIPDEFAULT;
1309 AR.FoStage4[0].ziobuffer = 0;
1310 AR.FoStage4[1].ziobuffer = 0;
1313 AC.bracketindexflag = 0;
1314 AT.bracketindexflag = 0;
1317 AM.gfunpowers = AC.funpowers = COMFUNPOWERS;
1318 AC.parallelflag = AM.gparallelflag;
1319 AC.properorderflag = AM.gproperorderflag = PROPERORDERFLAG;
1320 AC.ProcessBucketSize = AC.mProcessBucketSize = AM.gProcessBucketSize;
1321 AC.ThreadBucketSize = AM.gThreadBucketSize;
1322 AC.ShortStatsMax = 0;
1323 AM.gShortStatsMax = 0;
1324 AM.ggShortStatsMax = 0;
1326 GlobalSymbols = NumSymbols;
1327 GlobalIndices = NumIndices;
1328 GlobalVectors = NumVectors;
1329 GlobalFunctions = NumFunctions;
1330 GlobalSets = NumSets;
1331 GlobalSetElements = NumSetElements;
1332 AC.modpowers = (UWORD *)0;
1336 if ( i > 0 )
do { *fi++ = one; }
while ( --i >= 0 );
1346 for ( i = 8; i < 15; i++ ) AM.Ordering[i] = i;
1348 AC.lUniTrace[0] = SNUMBER;
1352 AC.lUniTrace[2] = 4;
1354 AC.lUniTrace[3] = 1;
1358 AT.MinVecArg[0] = 7+ARGHEAD;
1359 AT.MinVecArg[ARGHEAD] = 7;
1360 AT.MinVecArg[1+ARGHEAD] = INDEX;
1361 AT.MinVecArg[2+ARGHEAD] = 3;
1362 AT.MinVecArg[3+ARGHEAD] = 0;
1363 AT.MinVecArg[4+ARGHEAD] = 1;
1364 AT.MinVecArg[5+ARGHEAD] = 1;
1365 AT.MinVecArg[6+ARGHEAD] = -3;
1367 *t++ = 4+ARGHEAD+FUNHEAD;
1368 for ( i = 1; i < ARGHEAD; i++ ) *t++ = 0;
1372 for ( i = 2; i < FUNHEAD; i++ ) *t++ = 0;
1373 *t++ = 1; *t++ = 1; *t++ = 3;
1380 AT.comsym[1] = SYMBOL;
1391 AT.comfun[0] = FUNHEAD+4;
1392 AT.comfun[1] = FUNCTION;
1393 AT.comfun[2] = FUNHEAD;
1398 AT.comfun[FUNHEAD+1] = 1;
1399 AT.comfun[FUNHEAD+2] = 1;
1400 AT.comfun[FUNHEAD+3] = 3;
1402 AT.comind[1] = INDEX;
1408 AT.locwildvalue[0] = SUBEXPRESSION;
1409 AT.locwildvalue[1] = SUBEXPSIZE;
1410 for ( i = 2; i < SUBEXPSIZE; i++ ) AT.locwildvalue[i] = 0;
1411 AT.mulpat[0] = TYPEMULT;
1412 AT.mulpat[1] = SUBEXPSIZE+3;
1414 AT.mulpat[3] = SUBEXPRESSION;
1415 AT.mulpat[4] = SUBEXPSIZE;
1418 for ( i = 7; i < SUBEXPSIZE+5; i++ ) AT.mulpat[i] = 0;
1419 AT.proexp[0] = SUBEXPSIZE+4;
1420 AT.proexp[1] = EXPRESSION;
1421 AT.proexp[2] = SUBEXPSIZE;
1424 for ( i = 5; i < SUBEXPSIZE+1; i++ ) AT.proexp[i] = 0;
1425 AT.proexp[SUBEXPSIZE+1] = 1;
1426 AT.proexp[SUBEXPSIZE+2] = 1;
1427 AT.proexp[SUBEXPSIZE+3] = 3;
1428 AT.proexp[SUBEXPSIZE+4] = 0;
1429 AT.dummysubexp[0] = SUBEXPRESSION;
1430 AT.dummysubexp[1] = SUBEXPSIZE+4;
1431 for ( i = 2; i < SUBEXPSIZE; i++ ) AT.dummysubexp[i] = 0;
1432 AT.dummysubexp[SUBEXPSIZE] = WILDDUMMY;
1433 AT.dummysubexp[SUBEXPSIZE+1] = 4;
1434 AT.dummysubexp[SUBEXPSIZE+2] = 0;
1435 AT.dummysubexp[SUBEXPSIZE+3] = 0;
1437 AT.inprimelist = -1;
1438 AT.sizeprimelist = 0;
1440 AT.LeaveNegative = 0;
1442 AN.SplitScratch = 0;
1443 AN.SplitScratchSize = AN.InScratch = 0;
1444 AN.SplitScratch1 = 0;
1445 AN.SplitScratchSize1 = AN.InScratch1 = 0;
1446 AN.idfunctionflag = 0;
1448 AO.OutputLine = AO.OutFill = BufferForOutput;
1453 AP.ComChar = AP.cComChar;
1454 AC.cbufnum = AM.rbufnum;
1456 AP.PreAssignFlag = 0;
1467 static int exitInProgress = 0;
1468 static int trappedTerminate = 0;
1472 #ifdef INTSIGHANDLER
1473 static int onErrSig(
int i)
1475 static VOID onErrSig(
int i)
1478 if (exitInProgress){
1481 #ifdef INTSIGHANDLER
1487 trappedTerminate = 1;
1492 #ifdef INTSIGHANDLER
1493 static VOID setNewSig(
int i,
int (*handler)(
int))
1495 static VOID setNewSig(
int i,
void (*handler)(
int))
1500 if ( signal(i,SIG_IGN) !=SIG_IGN)
1505 VOID setSignalHandlers()
1508 setNewSig(SIGSEGV,onErrSig);
1509 setNewSig(SIGFPE,onErrSig);
1510 setNewSig(SIGILL,onErrSig);
1511 setNewSig(SIGEMT,onErrSig);
1512 setNewSig(SIGSYS,onErrSig);
1513 setNewSig(SIGPIPE,onErrSig);
1514 setNewSig(SIGLOST,onErrSig);
1515 setNewSig(SIGXCPU,onErrSig);
1516 setNewSig(SIGXFSZ,onErrSig);
1519 setNewSig(SIGTERM,onErrSig);
1520 setNewSig(SIGINT,onErrSig);
1521 setNewSig(SIGQUIT,onErrSig);
1522 setNewSig(SIGHUP,onErrSig);
1523 setNewSig(SIGALRM,onErrSig);
1524 setNewSig(SIGVTALRM,onErrSig);
1536 ALLPRIVATES *ABdummy[10];
1539 int main(
int argc,
char **argv)
1542 bzero((VOID *)(&A),
sizeof(A));
1545 setSignalHandlers();
1558 if (
PF_Init(&argc,&argv) ) exit(-1);
1582 if ( ( retval = DoTail(argc,(UBYTE **)argv) ) != 0 ) {
1583 if ( retval > 0 ) Terminate(0);
1586 if ( DoSetups() ) Terminate(-2);
1591 if ( OpenInput() ) Terminate(-3);
1595 if ( TryEnvironment() ) Terminate(-2);
1596 if ( TryFileSetups() ) Terminate(-2);
1597 if ( MakeSetupAllocs() ) Terminate(-2);
1601 if ( AM.totalnumberofthreads == 0 ) AM.totalnumberofthreads = 1;
1602 AS.MultiThreaded = 0;
1604 if ( AM.totalnumberofthreads > 1 ) AS.MultiThreaded = 1;
1605 ReserveTempFiles(1);
1606 StartAllThreads(AM.totalnumberofthreads);
1609 ReserveTempFiles(0);
1615 if ( AM.TimeLimit > 0 ) alarm(AM.TimeLimit);
1633 VOID CleanUp(WORD par)
1640 for ( i = 0; i < 3; i++ ) {
1641 if ( AR.Fscr[i].handle >= 0 ) {
1642 if ( AR.Fscr[i].name ) {
1647 CloseFile(AR.Fscr[i].handle);
1648 remove(AR.Fscr[i].name);
1650 AR.Fscr[i].handle = - 1;
1651 AR.Fscr[i].POfill = 0;
1659 if ( AC.StoreHandle >= 0 && par <= 0 ) {
1661 if ( trappedTerminate ) {
1664 SeekFile(AC.StoreHandle,&pos,SEEK_END);
1665 if ( ISNOTZEROPOS(pos) ) {
1666 CloseFile(AC.StoreHandle);
1670 CloseFile(AC.StoreHandle);
1671 if ( par >= 0 || AR.StoreData.Handle < 0 || AM.ClearStore ) {
1676 CloseFile(AC.StoreHandle);
1677 if ( par >= 0 || AR.StoreData.Handle < 0 || AM.ClearStore > 0 ) {
1683 ClearSpectators(CLEARMODULE);
1693 if ( AC.LogHandle >= 0 && par <= 0 ) {
1694 WORD lh = AC.LogHandle;
1697 if ( PF.me == MASTER )
1708 static int firstterminate = 1;
1710 VOID Terminate(
int errorcode)
1712 if ( errorcode && firstterminate ) {
1715 MesPrint(
"Program terminating in thread %w at &");
1716 #elif defined(WITHMPI)
1717 MesPrint(
"Program terminating in process %w at &");
1719 MesPrint(
"Program terminating at &");
1726 #ifdef WITHEXTERNALCHANNEL
1731 closeAllExternalChannels();
1732 AX.currentExternalChannel=0;
1734 AX.killSignal=SIGKILL;
1735 AX.killWholeGroup=1;
1738 if(AX.currentPrompt){
1739 M_free(AX.currentPrompt,
"external channel prompt");
1744 M_free(AX.shellname,
"external channel shellname");
1748 M_free(AX.stderrname,
"external channel stderrname");
1754 TerminateAllThreads();
1756 if ( AC.FinalStats ) {
1757 if ( AM.PrintTotalSize ) {
1758 MesPrint(
"Max. space for expressions: %19p bytes",&(AS.MaxExprSize));
1763 if ( AM.HoldFlag && PF.me == MASTER ) {
1764 WriteFile(AM.StdOut,(UBYTE *)(
"Hit any key "),12);
1769 if ( AM.HoldFlag ) {
1770 WriteFile(AM.StdOut,(UBYTE *)(
"Hit any key "),12);
1780 P_term(errorcode? 0: 1);
1791 VOID PrintRunningTime()
1793 #if (defined(WITHPTHREADS) && (defined(WITHPOSIXCLOCK) || defined(WINDOWS))) || defined(WITHMPI)
1798 #if defined(WITHPTHREADS)
1800 workertime = GetWorkerTimes();
1803 if ( PF.me == MASTER ) {
1805 mastertime = AM.SumTime +
TimeCPU(1);
1807 totaltime = mastertime+workertime;
1809 MesPrint(
" %l.%2i sec + %l.%2i sec: %l.%2i sec out of %l.%2i sec",
1810 mastertime/1000,(WORD)((mastertime%1000)/10),
1811 workertime/1000,(WORD)((workertime%1000)/10),
1812 totaltime/1000,(WORD)((totaltime%1000)/10),
1813 wallclocktime/100,(WORD)(wallclocktime%100));
1817 LONG mastertime = AM.SumTime +
TimeCPU(1);
1820 MesPrint(
" %l.%2i sec out of %l.%2i sec",
1821 mastertime/1000,(WORD)((mastertime%1000)/10),
1822 wallclocktime/100,(WORD)(wallclocktime%100));
1832 LONG GetRunningTime()
1834 #if defined(WITHPTHREADS) && (defined(WITHPOSIXCLOCK) || defined(WINDOWS))
1843 LONG workertime = GetWorkerTimes();
1844 mastertime = AM.SumTime +
TimeCPU(1);
1845 return(mastertime+workertime);
1851 return(AM.SumTime +
TimeCPU(1));
1853 #elif defined(WITHMPI)
1854 LONG mastertime, t = 0;
1856 if ( PF.me == MASTER ) {
1857 mastertime = AM.SumTime +
TimeCPU(1);
1858 t = mastertime + workertime;
1862 return(AM.SumTime +
TimeCPU(1));
void DeleteRecoveryFile()
int PF_Init(int *argc, char ***argv)
WORD Compare1(WORD *, WORD *, WORD)
int PutPreVar(UBYTE *, UBYTE *, UBYTE *, int)
LONG PF_GetSlaveTimes(void)
LONG PF_BroadcastNumber(LONG x)
int PF_Terminate(int errorcode)
void PF_FlushStdOutBuffer(void)