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;
224 AM.HoldFlag = AM.qError = AM.Interact = AM.FileOnlyFlag = 0;
225 AM.InputFileName = AM.LogFileName = AM.IncDir = AM.TempDir = AM.TempSortDir =
226 AM.SetupDir = AM.SetupFile = AM.Path = 0;
231 while ( argc >= 1 ) {
233 if ( *s ==
'-' || ( *s ==
'/' && ( argc > 0 || AM.Interact ) ) ) {
237 AM.qError = 1;
break;
240 t = copy = strDup1(*argv,
"Dotail");
241 while ( *t && *t !=
'=' ) t++;
243 if (
PutPreVar(copy,(UBYTE *)
"1",0,0) < 0 )
return(-1);
247 if (
PutPreVar(copy,t,0,0) < 0 )
return(-1);
250 M_free(copy,
"-d prevar");
251 argv++; argc--;
break;
253 AM.FileOnlyFlag = 1; AM.LogType = 0;
break;
255 AM.FileOnlyFlag = 1; AM.LogType = 1;
break;
257 AM.HoldFlag = 1;
break;
258 #ifdef WITHINTERACTION 260 AM.Interact = 1;
break;
263 TAKEPATH(AM.IncDir) break;
265 if ( s[1] == 'l' ) AM.LogType = 1;
269 AM.LogType = 1; break;
277 while ( *s >= '0' && *s <= '9' )
278 threadnum = 10*threadnum + *s++ - '0';
281 if ( PF.me == MASTER )
283 printf(
"Illegal value for option m or w: %s\n",t);
290 AM.ggWTimeStatsFlag = 1;
297 #ifdef WITHEXTERNALCHANNEL 300 if( (s[2]==
'p')&&(s[3]==
'e')&&(s[4]==
'\0') ){
304 if(initPresetExternalChannels(*argv++,AX.timeout)<1){
306 if ( PF.me == MASTER )
308 printf(
"Error initializing preset external channels\n");
315 if ( PF.me == MASTER )
317 printf(
"Illegal option in call of FORM: %s\n",s);
323 if ( ( s[1]==
'i' ) && ( s[2] ==
'p' ) && (s[3] ==
'e' )
324 && ( s[4] ==
'\0' ) ){
326 if ( PF.me == MASTER )
328 printf(
"Illegal option: Pipes not supported on this system.\n");
332 if ( PF.me == MASTER )
334 printf(
"Illegal option: %s\n",s);
346 AM.silent = 1;
break;
348 AC.CheckpointFlag = -1;
351 if ( ( s[1] ==
'o' ) && ( s[2] ==
'r' ) && ( s[3] ==
't' ) ) {
353 AM.TempSortDir = s+5;
356 AM.TempSortDir = *argv++;
360 else if ( s[1] ==
'i' ) {
364 TAKEPATH(AM.SetupDir)
368 TAKEPATH(AM.SetupFile) break;
373 TAKEPATH(AM.TempSortDir)
380 AM.PrintTotalSize = 1;
break;
384 if ( PF.me == MASTER )
387 if ( onlyversion )
return(1);
390 AP.PreDebug = PREPROONLY;
break;
392 if ( FG.cTable[*s] == 1 ) {
393 AM.SkipClears = 0; t = s;
394 while ( FG.cTable[*t] == 1 )
395 AM.SkipClears = 10*AM.SkipClears + *t++ -
'0';
398 if ( PF.me == MASTER )
400 printf(
"Illegal numerical option in call of FORM: %s\n",s);
406 if ( PF.me == MASTER )
408 printf(
"Illegal option in call of FORM: %s\n",s);
414 else if ( argc == 0 && !AM.Interact ) AM.InputFileName = argv[-1];
417 if ( PF.me == MASTER )
419 printf(
"Illegal option in call of FORM: %s\n",s);
423 AM.totalnumberofthreads = threadnum;
424 if ( AM.InputFileName ) {
425 s = AM.InputFileName;
427 if ( s < AM.InputFileName+4 ||
428 s[-4] !=
'.' || s[-3] !=
'f' || s[-2] !=
'r' || s[-1] !=
'm' ) {
429 t = (UBYTE *)Malloc1((s-AM.InputFileName)+5,
"adding .frm");
430 s = AM.InputFileName;
431 AM.InputFileName = t;
432 while ( *s ) *t++ = *s++;
433 *t++ =
'.'; *t++ =
'f'; *t++ =
'r'; *t++ =
'm'; *t = 0;
435 if ( AM.LogType >= 0 ) {
436 AM.LogFileName = strDup1(AM.InputFileName,
"name of logfile");
439 s[-3] =
'l'; s[-2] =
'o'; s[-1] =
'g';
442 #ifdef WITHINTERACTION 443 else if ( AM.Interact ) {
444 if ( AM.LogType >= 0 ) {
449 AM.LogFileName = deflogname;
456 if ( PF.me == MASTER )
458 printf(
"No filename specified in call of FORM\n");
461 if ( AM.Path == 0 ) AM.Path = (UBYTE *)getenv(
"FORMPATH");
467 AM.Path = strDup1(AM.Path,
"DoTail Path");
482 int oldNoShowInput = AC.NoShowInput;
484 if ( !AM.Interact ) {
485 if ( OpenStream(AM.InputFileName,FILESTREAM,0,PRENOACTION) == 0 ) {
486 Error1(
"Cannot open file",AM.InputFileName);
489 if ( AC.CurrentStream->inbuffer <= 0 ) {
490 Error1(
"No input in file",AM.InputFileName);
494 while ( AM.SkipClears > 0 ) {
496 if ( c == ENDOFINPUT ) {
497 Error0(
"Not enough .clear instructions in input file");
501 if ( c == ENDOFINPUT )
502 Error0(
"Not enough .clear instructions in input file");
505 if ( c ==
' ' || c ==
'\t' )
continue;
508 if ( tolower(c) ==
'c' ) {
510 if ( tolower(c) ==
'l' ) {
512 if ( tolower(c) ==
'e' ) {
514 if ( tolower(c) ==
'a' ) {
516 if ( tolower(c) ==
'r' ) {
518 if ( FG.cTable[c] > 2 ) {
526 while ( c !=
'\n' && c !=
'\r' && c != ENDOFINPUT ) {
528 if ( c ==
'\\' ) c = GetInput();
531 else if ( c ==
'\n' || c ==
'\r' )
continue;
533 while ( ( c = GetInput() ) !=
'\n' && c !=
'\r' ) {
534 if ( c == ENDOFINPUT ) {
535 Error0(
"Not enough .clear instructions in input file");
540 AC.NoShowInput = oldNoShowInput;
542 if ( AM.LogFileName ) {
544 if ( PF.me != MASTER ) {
549 extern FILES **filelist;
550 int i = CreateHandle();
551 RWLOCKW(AM.handlelock);
552 filelist[i] = (FILES *)123;
553 UNRWLOCK(AM.handlelock);
558 if ( AC.CheckpointFlag != -1 ) {
559 if ( ( AC.LogHandle = CreateLogFile((
char *)(AM.LogFileName)) ) < 0 ) {
560 Error1(
"Cannot create logfile",AM.LogFileName);
565 if ( ( AC.LogHandle = OpenAddFile((
char *)(AM.LogFileName)) ) < 0 ) {
566 Error1(
"Cannot re-open logfile",AM.LogFileName);
590 UBYTE *emptystring = (UBYTE *)
".";
591 UBYTE *defaulttempfilename = (UBYTE *)
"xformxxx.str";
593 VOID ReserveTempFiles(
int par)
597 UBYTE *s, *t, *tenddir, *tenddir2, c;
600 if ( par == 0 || par == 1 ) {
601 if ( AM.TempDir == 0 ) {
602 sp = GetSetupPar((UBYTE *)
"tempdir");
603 if ( ( sp->flags & USEDFLAG ) != USEDFLAG ) {
604 AM.TempDir = (UBYTE *)getenv(
"FORMTMP");
605 if ( AM.TempDir == 0 ) AM.TempDir = emptystring;
607 else AM.TempDir = (UBYTE *)(sp->value);
609 if ( AM.TempSortDir == 0 ) {
610 if ( AM.havesortdir ) {
611 sp = GetSetupPar((UBYTE *)
"tempsortdir");
612 AM.TempSortDir = (UBYTE *)(sp->value);
615 AM.TempSortDir = (UBYTE *)getenv(
"FORMTMPSORT");
616 if ( AM.TempSortDir == 0 ) AM.TempSortDir = AM.TempDir;
624 s = AM.TempDir; i = 200;
625 while ( *s && *s !=
':' ) {
if ( *s ==
'\\' ) s++; s++; i++; }
627 FG.fname = (
char *)Malloc1(
sizeof(UBYTE)*(i+14),
"name for temporary files");
628 s = AM.TempDir; t = (UBYTE *)FG.fname;
629 while ( *s && *s !=
':' ) {
if ( *s ==
'\\' ) s++; *t++ = *s++; }
630 if ( (
char *)t > FG.fname && t[-1] != SEPARATOR && t[-1] != ALTSEPARATOR )
634 FG.fnamebase = t-(UBYTE *)(FG.fname);
636 s = AM.TempSortDir; i = 200;
637 while ( *s && *s !=
':' ) {
if ( *s ==
'\\' ) s++; s++; i++; }
639 FG.fname2 = (
char *)Malloc1(
sizeof(UBYTE)*(i+14),
"name for sort files");
640 s = AM.TempSortDir; t = (UBYTE *)FG.fname2;
641 while ( *s && *s !=
':' ) {
if ( *s ==
'\\' ) s++; *t++ = *s++; }
642 if ( (
char *)t > FG.fname2 && t[-1] != SEPARATOR && t[-1] != ALTSEPARATOR )
646 FG.fname2base = t-(UBYTE *)(FG.fname2);
649 s = defaulttempfilename;
655 M_free(FG.fname,
"name for temporary files");
660 FG.fname = calloc(128,1);
661 strcpy(FG.fname,
"/formswap/xxxxxxxxxxxxxxxxxxxxx");
663 t = (UBYTE *)FG.fname + 10;
664 FG.fnamebase = t-FG.fname;
669 FG.fname = calloc(128,1);
670 strcpy(FG.fname,
"/formswapx/xxxxxxxxxxxxxxxxxxxxx");
672 FG.fname[9] =
'0' + PF.me;
673 t = (UBYTE *)FG.fname + 11;
674 FG.fnamebase = t-FG.fname;
677 iii = sprintf((
char*)t,
"%d",PF.me);
683 while ( *s ) *t++ = *s++;
695 int num = ((int)GetPID())%100000;
702 t[-5] = (UBYTE)(
'0' + num%10);
703 t[-6] = (UBYTE)(
'0' + (num/10)%10);
704 t[-7] = (UBYTE)(
'0' + (num/100)%10);
705 t[-8] = (UBYTE)(
'0' + (num/1000)%10);
706 t[-9] = (UBYTE)(
'0' + num/10000);
707 if ( ( AC.StoreHandle = CreateFile((
char *)FG.fname) ) < 0 ) {
708 t[-5] =
'x'; t[-6] =
'x'; t[-7] =
'x'; t[-8] =
'x'; t[-9] =
'x';
716 if ( ( AC.StoreHandle = OpenFile((
char *)FG.fname) ) < 0 ) {
717 if ( ( AC.StoreHandle = CreateFile((
char *)FG.fname) ) >= 0 )
break;
719 else CloseFile(AC.StoreHandle);
721 if ( c ==
'x' ) t[-5] =
'0';
722 else if ( c ==
'9' ) {
725 if ( c ==
'x' ) t[-6] =
'0';
726 else if ( c ==
'9' ) {
729 if ( c ==
'x' ) t[-7] =
'0';
730 else if ( c ==
'9' ) {
734 MesPrint(
"Name space for temp files exhausted");
736 MesPrint(
"Please remove files of the type %s or try a different directory" 740 else t[-7] = (UBYTE)(c+1);
742 else t[-6] = (UBYTE)(c+1);
744 else t[-5] = (UBYTE)(c+1);
751 s = tenddir; t = tenddir2;
while ( *s ) *t++ = *s++;
757 AM.S0->file.name = (
char *)Malloc1(
sizeof(
char)*(i+14),
"name for temporary files");
758 s = (UBYTE *)AM.S0->file.name;
759 t = (UBYTE *)FG.fname2;
761 while ( *t ) { *s++ = *t++; i++; }
770 s = (UBYTE *)((
void *)(FG.fname2)); i = 0;
771 while ( *s ) { s++; i++; }
772 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+1),
"name for stage4 file a");
773 AR.FoStage4[1].name = (
char *)s;
774 t = (UBYTE *)FG.fname2;
775 while ( *t ) *s++ = *t++;
776 s[-2] =
'4'; s[-1] =
'a'; *s = 0;
777 s = (UBYTE *)((
void *)(FG.fname)); i = 0;
778 while ( *s ) { s++; i++; }
779 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+1),
"name for stage4 file b");
780 AR.FoStage4[0].name = (
char *)s;
781 t = (UBYTE *)FG.fname;
782 while ( *t ) *s++ = *t++;
783 s[-2] =
'4'; s[-1] =
'b'; *s = 0;
784 for ( j = 0; j < 3; j++ ) {
785 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+1),
"name for scratch file");
786 AR.Fscr[j].name = (
char *)s;
787 t = (UBYTE *)FG.fname;
788 while ( *t ) *s++ = *t++;
789 s[-2] =
'c'; s[-1] = (UBYTE)(
'0'+j); *s = 0;
793 else if ( par == 2 ) {
794 s = (UBYTE *)((
void *)(FG.fname2)); i = 0;
795 while ( *s ) { s++; i++; }
796 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+12),
"name for stage4 file a");
797 sprintf((
char *)s,
"%s.%d",FG.fname2,AT.identity);
798 s[i-2] =
'4'; s[i-1] =
'a';
799 AR.FoStage4[1].name = (
char *)s;
800 s = (UBYTE *)((
void *)(FG.fname)); i = 0;
801 while ( *s ) { s++; i++; }
802 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+12),
"name for stage4 file b");
803 sprintf((
char *)s,
"%s.%d",FG.fname,AT.identity);
804 s[i-2] =
'4'; s[i-1] =
'b';
805 AR.FoStage4[0].name = (
char *)s;
806 if ( AT.identity == 0 ) {
807 for ( j = 0; j < 3; j++ ) {
808 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+1),
"name for scratch file");
809 AR.Fscr[j].name = (
char *)s;
810 t = (UBYTE *)FG.fname;
811 while ( *t ) *s++ = *t++;
812 s[-2] =
'c'; s[-1] = (UBYTE)(
'0'+j); *s = 0;
825 ALLPRIVATES *DummyPointer = 0;
841 AB = (ALLPRIVATES **)&DummyPointer;
847 set_sub(AC.separators,AC.separators,AC.separators);
848 set_set(
',',AC.separators);
849 set_set(
'|',AC.separators);
851 AM.BracketFactors[0] = 8;
852 AM.BracketFactors[1] = SYMBOL;
853 AM.BracketFactors[2] = 4;
854 AM.BracketFactors[3] = FACTORSYMBOL;
855 AM.BracketFactors[4] = 1;
856 AM.BracketFactors[5] = 1;
857 AM.BracketFactors[6] = 1;
858 AM.BracketFactors[7] = 3;
863 AC.OutputSpaces = NORMALFORMAT;
865 AM.gIsFortran90 = AC.IsFortran90 = ISNOTFORTRAN90;
866 AM.gFortran90Kind = AC.Fortran90Kind = 0;
868 AC.exprfillwarning = 0;
871 AM.MaxStreamSize = MAXFILESTREAMSIZE;
872 AP.MaxPreAssignLevel = 4;
873 AC.iBufferSize = 512;
875 AP.MaxPreIfLevel = 10;
876 AP.cComChar = AP.ComChar =
'*';
877 AM.OffsetVector = -2*WILDOFFSET+MINSPEC;
879 AM.hparallelflag = AM.gparallelflag =
880 AC.parallelflag = AC.mparallelflag = PARALLELFLAG;
882 if ( PF.numtasks < 2 ) AM.hparallelflag |= NOPARALLEL_NPROC;
885 AM.resetTimeOnClear = 1;
886 AM.gnumextrasym = AM.ggnumextrasym = 0;
888 AM.SpectatorFiles = 0;
889 AM.NumSpectatorFiles = 0;
890 AM.SizeForSpectatorFiles = 0;
894 AP.ProcList.message =
"procedure";
896 AP.LoopList.message =
"doloop";
897 AP.LoopList.size =
sizeof(
DOLOOP);
898 AP.PreVarList.message =
"PreVariable";
899 AP.PreVarList.size =
sizeof(
PREVAR);
900 AC.SymbolList.message =
"symbol";
901 AC.SymbolList.size =
sizeof(
struct SyMbOl);
902 AC.IndexList.message =
"index";
903 AC.IndexList.size =
sizeof(
struct InDeX);
904 AC.VectorList.message =
"vector";
905 AC.VectorList.size =
sizeof(
struct VeCtOr);
906 AC.FunctionList.message =
"function";
907 AC.FunctionList.size =
sizeof(
struct FuNcTiOn);
908 AC.SetList.message =
"set";
909 AC.SetList.size =
sizeof(
struct SeTs);
910 AC.SetElementList.message =
"set element";
911 AC.SetElementList.size =
sizeof(WORD);
912 AC.ExpressionList.message =
"expression";
913 AC.ExpressionList.size =
sizeof(
struct ExPrEsSiOn);
914 AC.cbufList.message =
"compiler buffer";
915 AC.cbufList.size =
sizeof(
CBUF);
916 AC.ChannelList.message =
"channel buffer";
917 AC.ChannelList.size =
sizeof(
CHANNEL);
918 AP.DollarList.message =
"$-variable";
919 AP.DollarList.size =
sizeof(
struct DoLlArS);
920 AC.DubiousList.message =
"ambiguous variable";
921 AC.DubiousList.size =
sizeof(
struct DuBiOuS);
922 AC.TableBaseList.message =
"list of tablebases";
923 AC.TableBaseList.size =
sizeof(
DBASE);
927 AC.AutoSymbolList.message =
"autosymbol";
928 AC.AutoSymbolList.size =
sizeof(
struct SyMbOl);
929 AC.AutoIndexList.message =
"autoindex";
930 AC.AutoIndexList.size =
sizeof(
struct InDeX);
931 AC.AutoVectorList.message =
"autovector";
932 AC.AutoVectorList.size =
sizeof(
struct VeCtOr);
933 AC.AutoFunctionList.message =
"autofunction";
934 AC.AutoFunctionList.size =
sizeof(
struct FuNcTiOn);
935 AC.PotModDolList.message =
"potentially modified dollar";
936 AC.PotModDolList.size =
sizeof(WORD);
937 AC.ModOptDolList.message =
"moduleoptiondollar";
940 AO.FortDotChar =
'_';
942 AC.firstconstindex = 1;
943 AO.Optimize.mctsconstant.fval = 1.0;
944 AO.Optimize.horner = O_MCTS;
945 AO.Optimize.hornerdirection = O_FORWARDORBACKWARD;
946 AO.Optimize.method = O_GREEDY;
947 AO.Optimize.mctstimelimit = 0;
948 AO.Optimize.mctsnumexpand = 1000;
949 AO.Optimize.mctsnumkeep = 10;
950 AO.Optimize.mctsnumrepeat = 1;
951 AO.Optimize.greedytimelimit = 0;
952 AO.Optimize.greedyminnum = 10;
953 AO.Optimize.greedymaxperc = 5;
954 AO.Optimize.printstats = 0;
955 AO.Optimize.debugflags = 0;
956 AO.OptimizeResult.code = NULL;
964 AC.doloopstacksize = 0;
969 AC.varnames = MakeNameTree();
970 AC.exprnames = MakeNameTree();
971 AC.dollarnames = MakeNameTree();
972 AC.autonames = MakeNameTree();
973 AC.activenames = &(AC.varnames);
994 CBUF *C = cbuf+AM.zbufnum;
995 WORD one[5] = {4,1,1,3,0};
998 AM.zerorhs = C->numrhs;
999 AddNtoC(AM.zbufnum,1,&zero,17);
1001 AM.onerhs = C->numrhs;
1008 AC.Symbols = &(AC.SymbolList);
1009 AC.Indices = &(AC.IndexList);
1010 AC.Vectors = &(AC.VectorList);
1011 AC.Functions = &(AC.FunctionList);
1014 AddDollar((UBYTE *)
"$",DOLUNDEFINED,0,0);
1016 cbuf[AM.dbufnum].mnumlhs = cbuf[AM.dbufnum].numlhs;
1017 cbuf[AM.dbufnum].mnumrhs = cbuf[AM.dbufnum].numrhs;
1019 AddSymbol((UBYTE *)
"i_",-MAXPOWER,MAXPOWER,VARTYPEIMAGINARY,0);
1020 AddSymbol((UBYTE *)
"pi_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1021 AddSymbol((UBYTE *)
"coeff_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1022 AddSymbol((UBYTE *)
"num_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1023 AddSymbol((UBYTE *)
"den_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1024 AddSymbol((UBYTE *)
"xarg_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1025 AddSymbol((UBYTE *)
"dimension_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1026 AddSymbol((UBYTE *)
"factor_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1027 AddSymbol((UBYTE *)
"sep_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1036 for ( ; i < FIRSTUSERSYMBOL; i++ ) {
1037 sprintf(dumstr,
":%d:",i);
1038 AddSymbol((UBYTE *)dumstr,-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1042 AddIndex((UBYTE *)
"iarg_",4,0);
1043 AddVector((UBYTE *)
"parg_",VARTYPENONE,0);
1045 AM.NumFixedFunctions =
sizeof(fixedfunctions)/
sizeof(
struct fixedfun);
1046 for ( i = 0; i < AM.NumFixedFunctions; i++ ) {
1047 ii = AddFunction((UBYTE *)fixedfunctions[i].
name 1048 ,fixedfunctions[i].commu
1049 ,fixedfunctions[i].tensor
1050 ,fixedfunctions[i].complx
1053 if ( fixedfunctions[i].tensor == GAMMAFUNCTION )
1054 functions[ii].flags |= COULDCOMMUTE;
1063 for ( ; i < FIRSTUSERFUNCTION-FUNCTION; i++ ) {
1064 sprintf(dumstr,
"::%d::",i);
1065 AddFunction((UBYTE *)dumstr,0,0,0,0,0,-1,-1);
1068 AM.NumFixedSets =
sizeof(fixedsets)/
sizeof(
struct fixedset);
1069 for ( i = 0; i < AM.NumFixedSets; i++ ) {
1070 ii = AddSet((UBYTE *)fixedsets[i].
name,fixedsets[i].dimension);
1071 Sets[ii].type = fixedsets[i].type;
1073 AM.RepMax = MAXREPEAT;
1074 #ifndef WITHPTHREADS 1075 AT.RepCount = (
int *)Malloc1((LONG)((AM.RepMax+3)*
sizeof(
int)),
"repeat buffers");
1076 AN.RepPoint = AT.RepCount;
1077 AT.RepTop = AT.RepCount + AM.RepMax;
1078 AN.polysortflag = 0;
1081 AC.NumWildcardNames = 0;
1082 AC.WildcardBufferSize = 50;
1083 AC.WildcardNames = (UBYTE *)Malloc1((LONG)AC.WildcardBufferSize,
"argument list names");
1084 #ifndef WITHPTHREADS 1085 AT.WildArgTaken = (WORD *)Malloc1((LONG)AC.WildcardBufferSize*
sizeof(WORD)/2
1086 ,
"argument list names");
1087 AT.WildcardBufferSize = AC.WildcardBufferSize;
1089 AT.nfac = AT.nBer = 0;
1094 AR.wranfnpair1 = NPAIR1;
1095 AR.wranfnpair2 = NPAIR2;
1099 AM.oldnumextrasymbols = strDup1((UBYTE *)
"OLDNUMEXTRASYMBOLS_",
"oldnumextrasymbols");
1100 PutPreVar((UBYTE *)
"VERSION_",(UBYTE *)STRINGIFY(MAJORVERSION),0,0);
1101 PutPreVar((UBYTE *)
"SUBVERSION_",(UBYTE *)STRINGIFY(MINORVERSION),0,0);
1102 PutPreVar((UBYTE *)
"DATE_",(UBYTE *)MakeDate(),0,0);
1103 PutPreVar((UBYTE *)
"random_",(UBYTE *)
"________",(UBYTE *)
"?a",0);
1104 PutPreVar((UBYTE *)
"optimminvar_",(UBYTE *)(
"0"),0,0);
1105 PutPreVar((UBYTE *)
"optimmaxvar_",(UBYTE *)(
"0"),0,0);
1106 PutPreVar(AM.oldnumextrasymbols,(UBYTE *)(
"0"),0,0);
1107 PutPreVar((UBYTE *)
"optimvalue_",(UBYTE *)(
"0"),0,0);
1108 PutPreVar((UBYTE *)
"optimscheme_",(UBYTE *)(
"0"),0,0);
1109 PutPreVar((UBYTE *)
"tolower_",(UBYTE *)(
"0"),(UBYTE *)(
"?a"),0);
1110 PutPreVar((UBYTE *)
"toupper_",(UBYTE *)(
"0"),(UBYTE *)(
"?a"),0);
1117 pid = ( PF.me == MASTER ) ? GetPID() : (LONG)0;
1121 PutPreVar((UBYTE *)
"PID_",(UBYTE *)buf,0,0);
1124 AP.MaxPreTypes = 10;
1126 AP.PreTypes = (
int *)Malloc1(
sizeof(
int)*(AP.MaxPreTypes+1),
"preprocessor types");
1127 AP.inside.buffer = 0;
1130 AC.SortType = AC.lSortType = AM.gSortType = SORTLOWFIRST;
1133 AR.SortType = AC.SortType;
1136 AC.SetList.numtemp = AC.SetList.num;
1137 AC.SetElementList.numtemp = AC.SetElementList.num;
1139 GetName(AC.varnames,(UBYTE *)
"exp_",&AM.expnum,NOAUTO);
1140 GetName(AC.varnames,(UBYTE *)
"denom_",&AM.denomnum,NOAUTO);
1141 GetName(AC.varnames,(UBYTE *)
"fac_",&AM.facnum,NOAUTO);
1142 GetName(AC.varnames,(UBYTE *)
"invfac_",&AM.invfacnum,NOAUTO);
1143 GetName(AC.varnames,(UBYTE *)
"sum_",&AM.sumnum,NOAUTO);
1144 GetName(AC.varnames,(UBYTE *)
"sump_",&AM.sumpnum,NOAUTO);
1145 GetName(AC.varnames,(UBYTE *)
"term_",&AM.termfunnum,NOAUTO);
1146 GetName(AC.varnames,(UBYTE *)
"match_",&AM.matchfunnum,NOAUTO);
1147 GetName(AC.varnames,(UBYTE *)
"count_",&AM.countfunnum,NOAUTO);
1148 AM.termfunnum += FUNCTION;
1149 AM.matchfunnum += FUNCTION;
1150 AM.countfunnum += FUNCTION;
1152 AC.ThreadStats = AM.gThreadStats = AM.ggThreadStats = 1;
1153 AC.FinalStats = AM.gFinalStats = AM.ggFinalStats = 1;
1154 AC.StatsFlag = AM.gStatsFlag = AM.ggStatsFlag = 1;
1155 AC.ThreadsFlag = AM.gThreadsFlag = AM.ggThreadsFlag = 1;
1156 AC.ThreadBalancing = AM.gThreadBalancing = AM.ggThreadBalancing = 1;
1157 AC.ThreadSortFileSynch = AM.gThreadSortFileSynch = AM.ggThreadSortFileSynch = 0;
1158 AC.ProcessStats = AM.gProcessStats = AM.ggProcessStats = 1;
1159 AC.OldParallelStats = AM.gOldParallelStats = AM.ggOldParallelStats = 0;
1160 AC.OldFactArgFlag = AM.gOldFactArgFlag = AM.ggOldFactArgFlag = NEWFACTARG;
1161 AC.OldGCDflag = AM.gOldGCDflag = AM.ggOldGCDflag = 1;
1162 AC.WTimeStatsFlag = AM.gWTimeStatsFlag = AM.ggWTimeStatsFlag = 0;
1163 AM.gcNumDollars = AP.DollarList.num;
1164 AC.SizeCommuteInSet = AM.gSizeCommuteInSet = 0;
1165 AC.CommuteInSet = 0;
1167 AM.PrintTotalSize = 0;
1169 AO.NoSpacesInNumbers = AM.gNoSpacesInNumbers = AM.ggNoSpacesInNumbers = 0;
1170 AO.IndentSpace = AM.gIndentSpace = AM.ggIndentSpace = INDENTSPACE;
1172 AO.OptimizationLevel = 0;
1173 PUTZERO(AS.MaxExprSize);
1174 PUTZERO(AC.StoreFileSize);
1177 AC.inputnumbers = 0;
1179 AC.numpfirstnum = AC.sizepfirstnum = 0;
1181 AC.MemDebugFlag = 1;
1183 #ifdef WITHEXTERNALCHANNEL 1184 AX.currentExternalChannel=0;
1185 AX.killSignal=SIGKILL;
1186 AX.killWholeGroup=1;
1190 AX.shellname=strDup1((UBYTE *)
"/bin/sh -c",
"external channel shellname");
1191 AX.stderrname=strDup1((UBYTE *)
"/dev/null",
"external channel stderrname");
1202 #ifdef WITHEXTERNALCHANNEL 1208 initPresetExternalChannels((UBYTE*)getenv(
"FORM_PIPES"),AX.timeout);
1218 sprintf((
char*)buf,
"%d",PF.me);
1219 PutPreVar((UBYTE *)
"PARALLELTASK_",buf,0,0);
1220 sprintf((
char*)buf,
"%d",PF.numtasks);
1221 PutPreVar((UBYTE *)
"NPARALLELTASKS_",buf,0,0);
1224 PutPreVar((UBYTE *)
"PARALLELTASK_",(UBYTE *)
"0",0,0);
1225 PutPreVar((UBYTE *)
"NPARALLELTASKS_",(UBYTE *)
"1",0,0);
1228 PutPreVar((UBYTE *)
"NAME_",AM.InputFileName,0,0);
1245 WORD *fi, i, one = 1;
1246 CBUF *C = cbuf+AC.cbufnum;
1250 sprintf((
char*)buf,
"%d",AM.totalnumberofthreads);
1251 PutPreVar((UBYTE *)
"NTHREADS_",buf,0,1);
1253 PutPreVar((UBYTE *)
"NTHREADS_",(UBYTE *)
"1",0,1);
1258 AR.SortType = AC.SortType = AC.lSortType = AM.gSortType;
1260 AC.OutputSpaces = NORMALFORMAT;
1263 AC.ncmod = AM.gncmod = 0;
1264 AC.modmode = AM.gmodmode = 0;
1265 AC.npowmod = AM.gnpowmod = 0;
1266 AC.halfmod = 0; AC.nhalfmod = 0;
1268 AC.lPolyFun = AM.gPolyFun = 0;
1269 AC.lPolyFunInv = AM.gPolyFunInv = 0;
1270 AC.lPolyFunType = AM.gPolyFunType = 0;
1271 AC.lPolyFunExp = AM.gPolyFunExp = 0;
1272 AC.lPolyFunVar = AM.gPolyFunVar = 0;
1273 AC.lPolyFunPow = AM.gPolyFunPow = 0;
1275 AC.lDefDim = AM.gDefDim = 4;
1276 AC.lDefDim4 = AM.gDefDim4 = 0;
1277 AC.lUnitTrace = AM.gUnitTrace = 4;
1278 AC.NamesFlag = AM.gNamesFlag = 0;
1279 AC.CodesFlag = AM.gCodesFlag = 0;
1280 AC.extrasymbols = AM.gextrasymbols = AM.ggextrasymbols = 0;
1281 AC.extrasym = (UBYTE *)Malloc1(2*
sizeof(UBYTE),
"extrasym");
1282 AM.gextrasym = (UBYTE *)Malloc1(2*
sizeof(UBYTE),
"extrasym");
1283 AM.ggextrasym = (UBYTE *)Malloc1(2*
sizeof(UBYTE),
"extrasym");
1284 AC.extrasym[0] = AM.gextrasym[0] = AM.ggextrasym[0] =
'Z';
1285 AC.extrasym[1] = AM.gextrasym[1] = AM.ggextrasym[1] = 0;
1286 AC.TokensWriteFlag = AM.gTokensWriteFlag = 0;
1288 AC.LineLength = AM.gLineLength = 79;
1292 AC.OutputSpaces = NORMALFORMAT;
1293 AM.gOutputSpaces = NORMALFORMAT;
1294 AC.OutNumberType = RATIONALMODE;
1295 AM.gOutNumberType = RATIONALMODE;
1297 AR.gzipCompress = GZIPDEFAULT;
1300 AC.bracketindexflag = 0;
1301 AT.bracketindexflag = 0;
1304 AM.gfunpowers = AC.funpowers = COMFUNPOWERS;
1305 AC.parallelflag = AM.gparallelflag;
1306 AC.properorderflag = AM.gproperorderflag = PROPERORDERFLAG;
1307 AC.ProcessBucketSize = AC.mProcessBucketSize = AM.gProcessBucketSize;
1308 AC.ThreadBucketSize = AM.gThreadBucketSize;
1309 AC.ShortStatsMax = 0;
1310 AM.gShortStatsMax = 0;
1311 AM.ggShortStatsMax = 0;
1313 GlobalSymbols = NumSymbols;
1314 GlobalIndices = NumIndices;
1315 GlobalVectors = NumVectors;
1316 GlobalFunctions = NumFunctions;
1317 GlobalSets = NumSets;
1318 GlobalSetElements = NumSetElements;
1319 AC.modpowers = (UWORD *)0;
1323 if ( i > 0 )
do { *fi++ = one; }
while ( --i >= 0 );
1333 for ( i = 8; i < 15; i++ ) AM.Ordering[i] = i;
1335 AC.lUniTrace[0] = SNUMBER;
1339 AC.lUniTrace[2] = 4;
1341 AC.lUniTrace[3] = 1;
1345 AT.MinVecArg[0] = 7+ARGHEAD;
1346 AT.MinVecArg[ARGHEAD] = 7;
1347 AT.MinVecArg[1+ARGHEAD] = INDEX;
1348 AT.MinVecArg[2+ARGHEAD] = 3;
1349 AT.MinVecArg[3+ARGHEAD] = 0;
1350 AT.MinVecArg[4+ARGHEAD] = 1;
1351 AT.MinVecArg[5+ARGHEAD] = 1;
1352 AT.MinVecArg[6+ARGHEAD] = -3;
1354 *t++ = 4+ARGHEAD+FUNHEAD;
1355 for ( i = 1; i < ARGHEAD; i++ ) *t++ = 0;
1359 for ( i = 2; i < FUNHEAD; i++ ) *t++ = 0;
1360 *t++ = 1; *t++ = 1; *t++ = 3;
1367 AT.comsym[1] = SYMBOL;
1378 AT.comfun[0] = FUNHEAD+4;
1379 AT.comfun[1] = FUNCTION;
1380 AT.comfun[2] = FUNHEAD;
1385 AT.comfun[FUNHEAD+1] = 1;
1386 AT.comfun[FUNHEAD+2] = 1;
1387 AT.comfun[FUNHEAD+3] = 3;
1389 AT.comind[1] = INDEX;
1395 AT.locwildvalue[0] = SUBEXPRESSION;
1396 AT.locwildvalue[1] = SUBEXPSIZE;
1397 for ( i = 2; i < SUBEXPSIZE; i++ ) AT.locwildvalue[i] = 0;
1398 AT.mulpat[0] = TYPEMULT;
1399 AT.mulpat[1] = SUBEXPSIZE+3;
1401 AT.mulpat[3] = SUBEXPRESSION;
1402 AT.mulpat[4] = SUBEXPSIZE;
1405 for ( i = 7; i < SUBEXPSIZE+5; i++ ) AT.mulpat[i] = 0;
1406 AT.proexp[0] = SUBEXPSIZE+4;
1407 AT.proexp[1] = EXPRESSION;
1408 AT.proexp[2] = SUBEXPSIZE;
1411 for ( i = 5; i < SUBEXPSIZE+1; i++ ) AT.proexp[i] = 0;
1412 AT.proexp[SUBEXPSIZE+1] = 1;
1413 AT.proexp[SUBEXPSIZE+2] = 1;
1414 AT.proexp[SUBEXPSIZE+3] = 3;
1415 AT.proexp[SUBEXPSIZE+4] = 0;
1416 AT.dummysubexp[0] = SUBEXPRESSION;
1417 AT.dummysubexp[1] = SUBEXPSIZE+4;
1418 for ( i = 2; i < SUBEXPSIZE; i++ ) AT.dummysubexp[i] = 0;
1419 AT.dummysubexp[SUBEXPSIZE] = WILDDUMMY;
1420 AT.dummysubexp[SUBEXPSIZE+1] = 4;
1421 AT.dummysubexp[SUBEXPSIZE+2] = 0;
1422 AT.dummysubexp[SUBEXPSIZE+3] = 0;
1424 AT.inprimelist = -1;
1425 AT.sizeprimelist = 0;
1427 AT.LeaveNegative = 0;
1429 AN.SplitScratch = 0;
1430 AN.SplitScratchSize = AN.InScratch = 0;
1431 AN.SplitScratch1 = 0;
1432 AN.SplitScratchSize1 = AN.InScratch1 = 0;
1433 AN.idfunctionflag = 0;
1435 AO.OutputLine = AO.OutFill = BufferForOutput;
1440 AP.ComChar = AP.cComChar;
1441 AC.cbufnum = AM.rbufnum;
1443 AP.PreAssignFlag = 0;
1454 static int exitInProgress = 0;
1455 static int trappedTerminate = 0;
1459 #ifdef INTSIGHANDLER 1460 static int onErrSig(
int i)
1462 static VOID onErrSig(
int i)
1465 if (exitInProgress){
1468 #ifdef INTSIGHANDLER 1474 trappedTerminate = 1;
1479 #ifdef INTSIGHANDLER 1480 static VOID setNewSig(
int i,
int (*handler)(
int))
1482 static VOID setNewSig(
int i,
void (*handler)(
int))
1487 if ( signal(i,SIG_IGN) !=SIG_IGN)
1492 VOID setSignalHandlers()
1495 setNewSig(SIGSEGV,onErrSig);
1496 setNewSig(SIGFPE,onErrSig);
1497 setNewSig(SIGILL,onErrSig);
1498 setNewSig(SIGEMT,onErrSig);
1499 setNewSig(SIGSYS,onErrSig);
1500 setNewSig(SIGPIPE,onErrSig);
1501 setNewSig(SIGLOST,onErrSig);
1502 setNewSig(SIGXCPU,onErrSig);
1503 setNewSig(SIGXFSZ,onErrSig);
1506 setNewSig(SIGTERM,onErrSig);
1507 setNewSig(SIGINT,onErrSig);
1508 setNewSig(SIGQUIT,onErrSig);
1509 setNewSig(SIGHUP,onErrSig);
1510 setNewSig(SIGALRM,onErrSig);
1511 setNewSig(SIGVTALRM,onErrSig);
1523 ALLPRIVATES *ABdummy[10];
1526 int main(
int argc,
char **argv)
1529 bzero((VOID *)(&A),
sizeof(A));
1532 setSignalHandlers();
1545 if (
PF_Init(&argc,&argv) ) exit(-1);
1569 if ( ( retval = DoTail(argc,(UBYTE **)argv) ) != 0 ) {
1570 if ( retval > 0 ) Terminate(0);
1573 if ( DoSetups() ) Terminate(-2);
1578 if ( OpenInput() ) Terminate(-3);
1582 if ( TryEnvironment() ) Terminate(-2);
1583 if ( TryFileSetups() ) Terminate(-2);
1584 if ( MakeSetupAllocs() ) Terminate(-2);
1588 if ( AM.totalnumberofthreads == 0 ) AM.totalnumberofthreads = 1;
1589 AS.MultiThreaded = 0;
1591 if ( AM.totalnumberofthreads > 1 ) AS.MultiThreaded = 1;
1592 ReserveTempFiles(1);
1593 StartAllThreads(AM.totalnumberofthreads);
1596 ReserveTempFiles(0);
1619 VOID CleanUp(WORD par)
1626 for ( i = 0; i < 3; i++ ) {
1627 if ( AR.Fscr[i].handle >= 0 ) {
1628 if ( AR.Fscr[i].name ) {
1633 CloseFile(AR.Fscr[i].handle);
1634 remove(AR.Fscr[i].name);
1636 AR.Fscr[i].handle = - 1;
1637 AR.Fscr[i].POfill = 0;
1645 if ( AC.StoreHandle >= 0 && par <= 0 ) {
1647 if ( trappedTerminate ) {
1650 SeekFile(AC.StoreHandle,&pos,SEEK_END);
1651 if ( ISNOTZEROPOS(pos) ) {
1652 CloseFile(AC.StoreHandle);
1656 CloseFile(AC.StoreHandle);
1657 if ( par >= 0 || AR.StoreData.Handle < 0 ) {
1662 CloseFile(AC.StoreHandle);
1663 if ( par >= 0 || AR.StoreData.Handle < 0 ) {
1669 ClearSpectators(CLEARMODULE);
1679 if ( AC.LogHandle >= 0 && par <= 0 ) {
1680 WORD lh = AC.LogHandle;
1683 if ( PF.me == MASTER )
1694 static int firstterminate = 1;
1696 VOID Terminate(
int errorcode)
1698 if ( errorcode && firstterminate ) {
1701 MesPrint(
"Program terminating in thread %w at &");
1702 #elif defined(WITHMPI) 1703 MesPrint(
"Program terminating in process %w at &");
1705 MesPrint(
"Program terminating at &");
1712 #ifdef WITHEXTERNALCHANNEL 1717 closeAllExternalChannels();
1718 AX.currentExternalChannel=0;
1720 AX.killSignal=SIGKILL;
1721 AX.killWholeGroup=1;
1724 if(AX.currentPrompt){
1725 M_free(AX.currentPrompt,
"external channel prompt");
1730 M_free(AX.shellname,
"external channel shellname");
1734 M_free(AX.stderrname,
"external channel stderrname");
1740 TerminateAllThreads();
1742 if ( AC.FinalStats ) {
1743 if ( AM.PrintTotalSize ) {
1744 MesPrint(
"Max. space for expressions: %19p bytes",&(AS.MaxExprSize));
1749 if ( AM.HoldFlag && PF.me == MASTER ) {
1750 WriteFile(AM.StdOut,(UBYTE *)(
"Hit any key "),12);
1755 if ( AM.HoldFlag ) {
1756 WriteFile(AM.StdOut,(UBYTE *)(
"Hit any key "),12);
1766 P_term(errorcode? 0: 1);
1777 VOID PrintRunningTime()
1779 #if (defined(WITHPTHREADS) && (defined(WITHPOSIXCLOCK) || defined(WINDOWS))) || defined(WITHMPI) 1784 #if defined(WITHPTHREADS) 1786 workertime = GetWorkerTimes();
1789 if ( PF.me == MASTER ) {
1791 mastertime = AM.SumTime +
TimeCPU(1);
1793 totaltime = mastertime+workertime;
1795 MesPrint(
" %l.%2i sec + %l.%2i sec: %l.%2i sec out of %l.%2i sec",
1796 mastertime/1000,(WORD)((mastertime%1000)/10),
1797 workertime/1000,(WORD)((workertime%1000)/10),
1798 totaltime/1000,(WORD)((totaltime%1000)/10),
1799 wallclocktime/100,(WORD)(wallclocktime%100));
1803 LONG mastertime = AM.SumTime +
TimeCPU(1);
1806 MesPrint(
" %l.%2i sec out of %l.%2i sec",
1807 mastertime/1000,(WORD)((mastertime%1000)/10),
1808 wallclocktime/100,(WORD)(wallclocktime%100));
1818 LONG GetRunningTime()
1820 #if defined(WITHPTHREADS) && (defined(WITHPOSIXCLOCK) || defined(WINDOWS)) 1829 LONG workertime = GetWorkerTimes();
1830 mastertime = AM.SumTime +
TimeCPU(1);
1831 return(mastertime+workertime);
1837 return(AM.SumTime +
TimeCPU(1));
1839 #elif defined(WITHMPI) 1840 LONG mastertime, t = 0;
1842 if ( PF.me == MASTER ) {
1843 mastertime = AM.SumTime +
TimeCPU(1);
1844 t = mastertime + workertime;
1848 return(AM.SumTime +
TimeCPU(1));
void DeleteRecoveryFile()
int PF_Init(int *argc, char ***argv)
int PutPreVar(UBYTE *, UBYTE *, UBYTE *, int)
LONG PF_GetSlaveTimes(void)
LONG PF_BroadcastNumber(LONG x)
WORD Compare1(PHEAD WORD *, WORD *, WORD)
int PF_Terminate(int errorcode)
void PF_FlushStdOutBuffer(void)