50 #if defined(WITHPTHREADS) 51 #define FORMNAME "TFORM" 52 #elif defined(WITHMPI) 53 #define FORMNAME "ParFORM" 55 #define FORMNAME "FORM" 62 #define VERSIONSTR VERSION"Beta" 64 #define VERSIONSTR VERSION 70 #define STRINGIFY(x) STRINGIFY__(x) 71 #define STRINGIFY__(x) #x 86 #ifdef WITHINTERACTION 87 static UBYTE deflogname[] =
"formsession.log";
90 #define TAKEPATH(x) if(s[1]== '=' ){x=s+2;} else{x=*argv++;argc--;} 92 int DoTail(
int argc, UBYTE **argv)
94 int errorflag = 0, onlyversion = 1;
99 AM.HoldFlag = AM.qError = AM.Interact = AM.FileOnlyFlag = 0;
100 AM.InputFileName = AM.LogFileName = AM.IncDir = AM.TempDir = AM.TempSortDir =
102 AM.SetupDir = AM.SetupFile = 0;
104 AM.SetupDir = AM.SetupFile = AM.Path = 0;
110 while ( argc >= 1 ) {
112 if ( *s ==
'-' || ( *s ==
'/' && ( argc > 0 || AM.Interact ) ) ) {
116 AM.qError = 1;
break;
119 t = copy = strDup1(*argv,
"Dotail");
120 while ( *t && *t !=
'=' ) t++;
122 if (
PutPreVar(copy,(UBYTE *)
"1",0,0) < 0 )
return(-1);
126 if (
PutPreVar(copy,t,0,0) < 0 )
return(-1);
129 M_free(copy,
"-d prevar");
130 argv++; argc--;
break;
132 AM.FileOnlyFlag = 1; AM.LogType = 0;
break;
134 AM.FileOnlyFlag = 1; AM.LogType = 1;
break;
136 AM.HoldFlag = 1;
break;
137 #ifdef WITHINTERACTION 139 AM.Interact = 1;
break;
142 TAKEPATH(AM.IncDir) break;
144 if ( s[1] == 'l' ) AM.LogType = 1;
148 AM.LogType = 1; break;
156 while ( *s >= '0' && *s <= '9' )
157 threadnum = 10*threadnum + *s++ - '0';
160 if ( PF.me == MASTER )
162 printf(
"Illegal value for option m or w: %s\n",t);
173 #ifdef WITHEXTERNALCHANNEL 176 if( (s[2]==
'p')&&(s[3]==
'e')&&(s[4]==
'\0') ){
180 if(initPresetExternalChannels(*argv++,AX.timeout)<1){
182 if ( PF.me == MASTER )
184 printf(
"Error initializing preset external channels\n");
191 if ( PF.me == MASTER )
193 printf(
"Illegal option in call of FORM: %s\n",s);
199 if ( ( s[1]==
'i' ) && ( s[2] ==
'p' ) && (s[3] ==
'e' )
200 && ( s[4] ==
'\0' ) ){
202 if ( PF.me == MASTER )
204 printf(
"Illegal option: Pipes not supported on this system.\n");
208 if ( PF.me == MASTER )
210 printf(
"Illegal option: %s\n",s);
222 AM.silent = 1;
break;
224 AC.CheckpointFlag = -1;
227 if ( ( s[1] ==
'o' ) && ( s[2] ==
'r' ) && ( s[3] ==
't' ) ) {
229 AM.TempSortDir = s+5;
232 AM.TempSortDir = *argv++;
236 else if ( s[1] ==
'i' ) {
240 TAKEPATH(AM.SetupDir)
244 TAKEPATH(AM.SetupFile) break;
246 TAKEPATH(AM.TempDir) break;
248 AM.PrintTotalSize = 1; break;
252 if ( PF.me == MASTER )
255 char buffer[100], *s = buffer;
256 sprintf(s,
"%s %s (%s)",FORMNAME,VERSIONSTR,PRODUCTIONDATE);
258 sprintf(s,
" %d-bits",(WORD)(
sizeof(WORD)*16));
260 printf(
"%s\n",buffer);
262 if ( onlyversion )
return(1);
265 AP.PreDebug = PREPROONLY;
break;
267 if ( FG.cTable[*s] == 1 ) {
268 AM.SkipClears = 0; t = s;
269 while ( FG.cTable[*t] == 1 )
270 AM.SkipClears = 10*AM.SkipClears + *t++ -
'0';
273 if ( PF.me == MASTER )
275 printf(
"Illegal numerical option in call of FORM: %s\n",s);
281 if ( PF.me == MASTER )
283 printf(
"Illegal option in call of FORM: %s\n",s);
289 else if ( argc == 0 && !AM.Interact ) AM.InputFileName = argv[-1];
292 if ( PF.me == MASTER )
294 printf(
"Illegal option in call of FORM: %s\n",s);
298 AM.totalnumberofthreads = threadnum;
299 if ( AM.InputFileName ) {
300 s = AM.InputFileName;
302 if ( s < AM.InputFileName+4 ||
303 s[-4] !=
'.' || s[-3] !=
'f' || s[-2] !=
'r' || s[-1] !=
'm' ) {
304 t = (UBYTE *)Malloc1((s-AM.InputFileName)+5,
"adding .frm");
305 s = AM.InputFileName;
306 AM.InputFileName = t;
307 while ( *s ) *t++ = *s++;
308 *t++ =
'.'; *t++ =
'f'; *t++ =
'r'; *t++ =
'm'; *t = 0;
310 if ( AM.LogType >= 0 ) {
311 AM.LogFileName = strDup1(AM.InputFileName,
"name of logfile");
314 s[-3] =
'l'; s[-2] =
'o'; s[-1] =
'g';
317 #ifdef WITHINTERACTION 318 else if ( AM.Interact ) {
319 if ( AM.LogType >= 0 ) {
324 AM.LogFileName = deflogname;
331 if ( PF.me == MASTER )
333 printf(
"No filename specified in call of FORM\n");
336 if ( AM.Path == 0 ) AM.Path = (UBYTE *)getenv(
"FORMPATH");
350 int oldNoShowInput = AC.NoShowInput;
352 if ( !AM.Interact ) {
353 if ( OpenStream(AM.InputFileName,FILESTREAM,0,PRENOACTION) == 0 ) {
354 Error1(
"Cannot open file",AM.InputFileName);
357 if ( AC.CurrentStream->inbuffer <= 0 ) {
358 Error1(
"No input in file",AM.InputFileName);
362 while ( AM.SkipClears > 0 ) {
364 if ( c == ENDOFINPUT ) {
365 Error0(
"Not enough .clear instructions in input file");
369 if ( c == ENDOFINPUT )
370 Error0(
"Not enough .clear instructions in input file");
373 if ( c ==
' ' || c ==
'\t' )
continue;
376 if ( tolower(c) ==
'c' ) {
378 if ( tolower(c) ==
'l' ) {
380 if ( tolower(c) ==
'e' ) {
382 if ( tolower(c) ==
'a' ) {
384 if ( tolower(c) ==
'r' ) {
386 if ( FG.cTable[c] > 2 ) {
394 while ( c !=
'\n' && c !=
'\r' && c != ENDOFINPUT ) {
396 if ( c ==
'\\' ) c = GetInput();
399 else if ( c ==
'\n' || c ==
'\r' )
continue;
401 while ( ( c = GetInput() ) !=
'\n' && c !=
'\r' ) {
402 if ( c == ENDOFINPUT ) {
403 Error0(
"Not enough .clear instructions in input file");
408 AC.NoShowInput = oldNoShowInput;
410 if ( AM.LogFileName ) {
412 if ( PF.me != MASTER ) {
417 extern FILES **filelist;
418 int i = CreateHandle();
419 RWLOCKW(AM.handlelock);
420 filelist[i] = (FILES *)123;
421 UNRWLOCK(AM.handlelock);
426 if ( AC.CheckpointFlag != -1 ) {
427 if ( ( AC.LogHandle = CreateLogFile((
char *)(AM.LogFileName)) ) < 0 ) {
428 Error1(
"Cannot create logfile",AM.LogFileName);
433 if ( ( AC.LogHandle = OpenAddFile((
char *)(AM.LogFileName)) ) < 0 ) {
434 Error1(
"Cannot re-open logfile",AM.LogFileName);
458 UBYTE *emptystring = (UBYTE *)
".";
459 UBYTE *defaulttempfilename = (UBYTE *)
"xformxxx.str";
461 VOID ReserveTempFiles(
int par)
468 if ( par == 0 || par == 1 ) {
469 if ( AM.TempDir == 0 ) {
470 sp = GetSetupPar((UBYTE *)
"tempdir");
471 if ( ( sp->flags & USEDFLAG ) != USEDFLAG ) {
472 AM.TempDir = (UBYTE *)getenv(
"FORMTMP");
473 if ( AM.TempDir == 0 ) AM.TempDir = emptystring;
475 else AM.TempDir = (UBYTE *)(sp->value);
482 s = AM.TempDir; i = 200;
483 while ( *s && *s !=
':' ) {
if ( *s ==
'\\' ) s++; s++; i++; }
485 FG.fname = (
char *)Malloc1(
sizeof(UBYTE)*(i+10),
"name for temporary files");
486 s = AM.TempDir; t = (UBYTE *)FG.fname;
487 while ( *s && *s !=
':' ) {
if ( *s ==
'\\' ) s++; *t++ = *s++; }
488 if ( (
char *)t > FG.fname && t[-1] != SEPARATOR && t[-1] != ALTSEPARATOR )
490 s = defaulttempfilename;
496 M_free(FG.fname,
"name for temporary files");
501 FG.fname = calloc(128,1);
502 strcpy(FG.fname,
"/formswap/xxxxxxxxxxxxxxxxxxxxx");
504 t = (UBYTE *)FG.fname + 10;
509 FG.fname = calloc(128,1);
510 strcpy(FG.fname,
"/formswapx/xxxxxxxxxxxxxxxxxxxxx");
512 FG.fname[9] =
'0' + PF.me;
513 t = (UBYTE *)FG.fname + 11;
516 iii = sprintf((
char*)t,
"%d",PF.me);
522 while ( *s ) *t++ = *s++;
536 int num = ((int)pp)%100000;
543 t[-5] = (UBYTE)(
'0' + num%10);
544 t[-6] = (UBYTE)(
'0' + (num/10)%10);
545 t[-7] = (UBYTE)(
'0' + (num/100)%10);
546 t[-8] = (UBYTE)(
'0' + (num/1000)%10);
547 t[-9] = (UBYTE)(
'0' + num/10000);
548 if ( ( AC.StoreHandle = CreateFile((
char *)FG.fname) ) < 0 ) {
549 t[-5] =
'x'; t[-6] =
'x'; t[-7] =
'x'; t[-8] =
'x'; t[-9] =
'x';
560 if ( ( AC.StoreHandle = OpenFile((
char *)FG.fname) ) < 0 ) {
561 if ( ( AC.StoreHandle = CreateFile((
char *)FG.fname) ) >= 0 )
break;
563 else CloseFile(AC.StoreHandle);
565 if ( c ==
'x' ) t[-5] =
'0';
566 else if ( c ==
'9' ) {
569 if ( c ==
'x' ) t[-6] =
'0';
570 else if ( c ==
'9' ) {
573 if ( c ==
'x' ) t[-7] =
'0';
574 else if ( c ==
'9' ) {
578 MesPrint(
"Name space for temp files exhausted");
580 MesPrint(
"Please remove files of the type %s or try a different directory" 584 else t[-7] = (UBYTE)(c+1);
586 else t[-6] = (UBYTE)(c+1);
588 else t[-5] = (UBYTE)(c+1);
594 AM.S0->file.name = (
char *)Malloc1(
sizeof(
char)*i,
"name for temporary files");
595 s = (UBYTE *)AM.S0->file.name;
596 t = (UBYTE *)FG.fname;
598 while ( *t ) { *s++ = *t++; i++; }
607 s = (UBYTE *)Malloc1(
sizeof(
char)*i,
"name for stage4 file a");
608 AR.FoStage4[0].name = (
char *)s;
609 t = (UBYTE *)FG.fname;
610 while ( *t ) *s++ = *t++;
611 s[-2] =
'4'; s[-1] =
'a'; *s = 0;
612 s = (UBYTE *)Malloc1(
sizeof(
char)*i,
"name for stage4 file b");
613 AR.FoStage4[1].name = (
char *)s;
614 t = (UBYTE *)FG.fname;
615 while ( *t ) *s++ = *t++;
616 s[-2] =
'4'; s[-1] =
'b'; *s = 0;
617 for ( j = 0; j < 3; j++ ) {
618 s = (UBYTE *)Malloc1(
sizeof(
char)*i,
"name for scratch file");
619 AR.Fscr[j].name = (
char *)s;
620 t = (UBYTE *)FG.fname;
621 while ( *t ) *s++ = *t++;
622 s[-2] =
'c'; s[-1] = (UBYTE)(
'0'+j); *s = 0;
626 else if ( par == 2 ) {
627 s = (UBYTE *)((
void *)(FG.fname)); i = 0;
628 while ( *s ) { s++; i++; }
629 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+12),
"name for stage4 file a");
630 sprintf((
char *)s,
"%s.%d",FG.fname,AT.identity);
631 s[i-2] =
'4'; s[i-1] =
'a';
632 AR.FoStage4[0].name = (
char *)s;
633 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+12),
"name for stage4 file b");
634 sprintf((
char *)s,
"%s.%d",FG.fname,AT.identity);
635 s[i-2] =
'4'; s[i-1] =
'b';
636 AR.FoStage4[1].name = (
char *)s;
637 if ( AT.identity == 0 ) {
638 for ( j = 0; j < 3; j++ ) {
639 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+1),
"name for scratch file");
640 AR.Fscr[j].name = (
char *)s;
641 t = (UBYTE *)FG.fname;
642 while ( *t ) *s++ = *t++;
643 s[-2] =
'c'; s[-1] = (UBYTE)(
'0'+j); *s = 0;
656 ALLPRIVATES *DummyPointer = 0;
672 AB = (ALLPRIVATES **)&DummyPointer;
678 set_sub(AC.separators,AC.separators,AC.separators);
679 set_set(
',',AC.separators);
680 set_set(
'|',AC.separators);
682 AM.BracketFactors[0] = 8;
683 AM.BracketFactors[1] = SYMBOL;
684 AM.BracketFactors[2] = 4;
685 AM.BracketFactors[3] = FACTORSYMBOL;
686 AM.BracketFactors[4] = 1;
687 AM.BracketFactors[5] = 1;
688 AM.BracketFactors[6] = 1;
689 AM.BracketFactors[7] = 3;
694 AC.OutputSpaces = NORMALFORMAT;
696 AM.gIsFortran90 = AC.IsFortran90 = ISNOTFORTRAN90;
697 AM.gFortran90Kind = AC.Fortran90Kind = 0;
699 AC.exprfillwarning = 0;
702 AM.MaxStreamSize = 1024;
703 AC.iBufferSize = 512;
705 AP.MaxPreIfLevel = 10;
706 AP.cComChar = AP.ComChar =
'*';
707 AM.OffsetVector = -2*WILDOFFSET+MINSPEC;
709 AM.hparallelflag = AM.gparallelflag =
710 AC.parallelflag = AC.mparallelflag = PARALLELFLAG;
712 if ( PF.numtasks < 2 ) AM.hparallelflag |= NOPARALLEL_NPROC;
715 AM.resetTimeOnClear = 1;
720 AP.ProcList.message =
"procedure";
722 AP.LoopList.message =
"doloop";
723 AP.LoopList.size =
sizeof(
DOLOOP);
724 AP.PreVarList.message =
"PreVariable";
725 AP.PreVarList.size =
sizeof(
PREVAR);
726 AC.SymbolList.message =
"symbol";
727 AC.SymbolList.size =
sizeof(
struct SyMbOl);
728 AC.IndexList.message =
"index";
729 AC.IndexList.size =
sizeof(
struct InDeX);
730 AC.VectorList.message =
"vector";
731 AC.VectorList.size =
sizeof(
struct VeCtOr);
732 AC.FunctionList.message =
"function";
733 AC.FunctionList.size =
sizeof(
struct FuNcTiOn);
734 AC.SetList.message =
"set";
735 AC.SetList.size =
sizeof(
struct SeTs);
736 AC.SetElementList.message =
"set element";
737 AC.SetElementList.size =
sizeof(WORD);
738 AC.ExpressionList.message =
"expression";
739 AC.ExpressionList.size =
sizeof(
struct ExPrEsSiOn);
740 AC.cbufList.message =
"compiler buffer";
741 AC.cbufList.size =
sizeof(
CBUF);
742 AC.ChannelList.message =
"channel buffer";
743 AC.ChannelList.size =
sizeof(
CHANNEL);
744 AP.DollarList.message =
"$-variable";
745 AP.DollarList.size =
sizeof(
struct DoLlArS);
746 AC.DubiousList.message =
"ambiguous variable";
747 AC.DubiousList.size =
sizeof(
struct DuBiOuS);
748 AC.TableBaseList.message =
"list of tablebases";
749 AC.TableBaseList.size =
sizeof(
DBASE);
751 AC.AutoSymbolList.message =
"autosymbol";
752 AC.AutoSymbolList.size =
sizeof(
struct SyMbOl);
753 AC.AutoIndexList.message =
"autoindex";
754 AC.AutoIndexList.size =
sizeof(
struct InDeX);
755 AC.AutoVectorList.message =
"autovector";
756 AC.AutoVectorList.size =
sizeof(
struct VeCtOr);
757 AC.AutoFunctionList.message =
"autofunction";
758 AC.AutoFunctionList.size =
sizeof(
struct FuNcTiOn);
759 AC.PotModDolList.message =
"potentially modified dollar";
760 AC.PotModDolList.size =
sizeof(WORD);
761 AC.ModOptDolList.message =
"moduleoptiondollar";
764 AO.FortDotChar =
'_';
766 AC.firstconstindex = 1;
767 AO.Optimize.mctsconstant.fval = 1.0;
768 AO.Optimize.horner = O_MCTS;
769 AO.Optimize.hornerdirection = O_FORWARDORBACKWARD;
770 AO.Optimize.method = O_GREEDY;
771 AO.Optimize.mctstimelimit = 0;
772 AO.Optimize.mctsnumexpand = 1000;
773 AO.Optimize.mctsnumkeep = 10;
774 AO.Optimize.mctsnumrepeat = 1;
775 AO.Optimize.greedytimelimit = 0;
776 AO.Optimize.greedyminnum = 10;
777 AO.Optimize.greedymaxperc = 5;
778 AO.Optimize.printstats = 0;
779 AO.Optimize.debugflags = 0;
780 AO.OptimizeResult.code = NULL;
788 AC.doloopstacksize = 0;
793 AC.varnames = MakeNameTree();
794 AC.exprnames = MakeNameTree();
795 AC.dollarnames = MakeNameTree();
796 AC.autonames = MakeNameTree();
797 AC.activenames = &(AC.varnames);
803 AM.rbufnum = inicbufs();
805 AT.ebufnum = inicbufs();
806 AT.fbufnum = inicbufs();
810 AM.dbufnum = inicbufs();
811 AM.sbufnum = inicbufs();
812 AC.ffbufnum = inicbufs();
813 AM.zbufnum = inicbufs();
815 CBUF *C = cbuf+AM.zbufnum;
817 AddRHS(AM.zbufnum,1);
818 AM.zerorhs = C->numrhs;
819 AddNtoC(AM.zbufnum,1,&zero);
821 AP.inside.inscbuf = inicbufs();
825 AC.Symbols = &(AC.SymbolList);
826 AC.Indices = &(AC.IndexList);
827 AC.Vectors = &(AC.VectorList);
828 AC.Functions = &(AC.FunctionList);
831 AddDollar((UBYTE *)
"$",DOLUNDEFINED,0,0);
833 cbuf[AM.dbufnum].mnumlhs = cbuf[AM.dbufnum].numlhs;
834 cbuf[AM.dbufnum].mnumrhs = cbuf[AM.dbufnum].numrhs;
836 AddSymbol((UBYTE *)
"i_",-MAXPOWER,MAXPOWER,VARTYPEIMAGINARY,0);
837 AddSymbol((UBYTE *)
"pi_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
838 AddSymbol((UBYTE *)
"coeff_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
839 AddSymbol((UBYTE *)
"num_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
840 AddSymbol((UBYTE *)
"den_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
841 AddSymbol((UBYTE *)
"xarg_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
842 AddSymbol((UBYTE *)
"dimension_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
843 AddSymbol((UBYTE *)
"factor_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
844 AddSymbol((UBYTE *)
"sep_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
853 for ( ; i < FIRSTUSERSYMBOL; i++ ) {
854 sprintf(dumstr,
":%d:",i);
855 AddSymbol((UBYTE *)dumstr,-MAXPOWER,MAXPOWER,VARTYPENONE,0);
859 AddIndex((UBYTE *)
"iarg_",4,0);
860 AddVector((UBYTE *)
"parg_",VARTYPENONE,0);
862 AM.NumFixedFunctions =
sizeof(fixedfunctions)/
sizeof(
struct fixedfun);
863 for ( i = 0; i < AM.NumFixedFunctions; i++ )
864 AddFunction((UBYTE *)fixedfunctions[i].name
865 ,fixedfunctions[i].commu
866 ,fixedfunctions[i].tensor
867 ,fixedfunctions[i].complx
868 ,fixedfunctions[i].symmetric
877 for ( ; i < FIRSTUSERFUNCTION-FUNCTION; i++ ) {
878 sprintf(dumstr,
"::%d::",i);
879 AddFunction((UBYTE *)dumstr,0,0,0,0,0,-1,-1);
882 AM.NumFixedSets =
sizeof(fixedsets)/
sizeof(
struct fixedset);
883 for ( i = 0; i < AM.NumFixedSets; i++ ) {
884 ii = AddSet((UBYTE *)fixedsets[i].
name,fixedsets[i].dimension);
885 Sets[ii].type = fixedsets[i].type;
887 AM.RepMax = MAXREPEAT;
889 AT.RepCount = (
int *)Malloc1((LONG)((AM.RepMax+3)*
sizeof(
int)),
"repeat buffers");
890 AN.RepPoint = AT.RepCount;
891 AT.RepTop = AT.RepCount + AM.RepMax;
895 AC.NumWildcardNames = 0;
896 AC.WildcardBufferSize = 50;
897 AC.WildcardNames = (UBYTE *)Malloc1((LONG)AC.WildcardBufferSize,
"argument list names");
899 AT.WildArgTaken = (WORD *)Malloc1((LONG)AC.WildcardBufferSize*
sizeof(WORD)/2
900 ,
"argument list names");
901 AT.WildcardBufferSize = AC.WildcardBufferSize;
903 AT.nfac = AT.nBer = 0;
908 AR.wranfnpair1 = NPAIR1;
909 AR.wranfnpair2 = NPAIR2;
913 AM.oldnumextrasymbols = strDup1((UBYTE *)
"OLDNUMEXTRASYMBOLS_",
"oldnumextrasymbols");
914 PutPreVar((UBYTE *)
"VERSION_",(UBYTE *)STRINGIFY(MAJORVERSION),0,0);
915 PutPreVar((UBYTE *)
"SUBVERSION_",(UBYTE *)STRINGIFY(MINORVERSION),0,0);
916 PutPreVar((UBYTE *)
"DATE_",(UBYTE *)MakeDate(),0,0);
917 PutPreVar((UBYTE *)
"random_",(UBYTE *)
"________",(UBYTE *)
"?a",0);
918 PutPreVar((UBYTE *)
"optimminvar_",(UBYTE *)(
"0"),0,0);
919 PutPreVar((UBYTE *)
"optimmaxvar_",(UBYTE *)(
"0"),0,0);
920 PutPreVar(AM.oldnumextrasymbols,(UBYTE *)(
"0"),0,0);
924 AP.PreTypes = (
int *)Malloc1(
sizeof(
int)*(AP.MaxPreTypes+1),
"preprocessor types");
925 AP.inside.buffer = 0;
928 AC.SortType = AC.lSortType = AM.gSortType = SORTLOWFIRST;
931 AR.SortType = AC.SortType;
934 AC.SetList.numtemp = AC.SetList.num;
935 AC.SetElementList.numtemp = AC.SetElementList.num;
937 GetName(AC.varnames,(UBYTE *)
"exp_",&AM.expnum,NOAUTO);
938 GetName(AC.varnames,(UBYTE *)
"denom_",&AM.denomnum,NOAUTO);
939 GetName(AC.varnames,(UBYTE *)
"fac_",&AM.facnum,NOAUTO);
940 GetName(AC.varnames,(UBYTE *)
"invfac_",&AM.invfacnum,NOAUTO);
941 GetName(AC.varnames,(UBYTE *)
"sum_",&AM.sumnum,NOAUTO);
942 GetName(AC.varnames,(UBYTE *)
"sump_",&AM.sumpnum,NOAUTO);
943 GetName(AC.varnames,(UBYTE *)
"term_",&AM.termfunnum,NOAUTO);
944 GetName(AC.varnames,(UBYTE *)
"match_",&AM.matchfunnum,NOAUTO);
945 GetName(AC.varnames,(UBYTE *)
"count_",&AM.countfunnum,NOAUTO);
946 AM.termfunnum += FUNCTION;
947 AM.matchfunnum += FUNCTION;
948 AM.countfunnum += FUNCTION;
950 AC.ThreadStats = AM.gThreadStats = AM.ggThreadStats = 1;
951 AC.FinalStats = AM.gFinalStats = AM.ggFinalStats = 1;
952 AC.StatsFlag = AM.gStatsFlag = AM.ggStatsFlag = 1;
953 AC.ThreadsFlag = AM.gThreadsFlag = AM.ggThreadsFlag = 1;
954 AC.ThreadBalancing = AM.gThreadBalancing = AM.ggThreadBalancing = 1;
955 AC.ThreadSortFileSynch = AM.gThreadSortFileSynch = AM.ggThreadSortFileSynch = 0;
956 AC.ProcessStats = AM.gProcessStats = AM.ggProcessStats = 1;
957 AC.OldParallelStats = AM.gOldParallelStats = AM.ggOldParallelStats = 0;
958 AC.OldFactArgFlag = AM.gOldFactArgFlag = AM.ggOldFactArgFlag = NEWFACTARG;
959 AM.gcNumDollars = AP.DollarList.num;
961 AM.PrintTotalSize = 0;
963 AO.NoSpacesInNumbers = AM.gNoSpacesInNumbers = AM.ggNoSpacesInNumbers = 0;
964 AO.IndentSpace = AM.gIndentSpace = AM.ggIndentSpace = INDENTSPACE;
966 AO.OptimizationLevel = 0;
967 PUTZERO(AS.MaxExprSize);
968 PUTZERO(AC.StoreFileSize);
973 AC.numpfirstnum = AC.sizepfirstnum = 0;
977 #ifdef WITHEXTERNALCHANNEL 978 AX.currentExternalChannel=0;
979 AX.killSignal=SIGKILL;
984 AX.shellname=strDup1((UBYTE *)
"/bin/sh -c",
"external channel shellname");
985 AX.stderrname=strDup1((UBYTE *)
"/dev/null",
"external channel stderrname");
996 #ifdef WITHEXTERNALCHANNEL 1002 initPresetExternalChannels((UBYTE*)getenv(
"FORM_PIPES"),AX.timeout);
1012 sprintf((
char*)buf,
"%d",PF.me);
1013 PutPreVar((UBYTE *)
"PARALLELTASK_",buf,0,0);
1014 sprintf((
char*)buf,
"%d",PF.numtasks);
1015 PutPreVar((UBYTE *)
"NPARALLELTASKS_",buf,0,0);
1018 PutPreVar((UBYTE *)
"PARALLELTASK_",(UBYTE *)
"0",0,0);
1019 PutPreVar((UBYTE *)
"NPARALLELTASKS_",(UBYTE *)
"1",0,0);
1022 PutPreVar((UBYTE *)
"NAME_",AM.InputFileName,0,0);
1037 if ( PF.me == MASTER && !AM.silent ) {
1041 char buffer[100], *s = buffer;
1042 sprintf(s,
"%s %s (%s)",FORMNAME,VERSIONSTR,PRODUCTIONDATE);
1044 sprintf(s,
" %d-bits",(WORD)(
sizeof(WORD)*16));
1046 #if defined(WITHPTHREADS) 1047 sprintf(s,
" %d worker",AM.totalnumberofthreads-1);
1049 if ( AM.totalnumberofthreads != 2 ) *s++ =
's';
1051 #elif defined(WITHMPI) 1052 sprintf(s,
" %d worker",PF.numtasks-1);
1054 if ( PF.numtasks != 2 ) *s++ =
's';
1060 while ( s-buffer < 48 ) *s++ =
' ';
1061 sprintf(s,
" Run: %s",MakeDate());
1062 MesPrint(
"%s",buffer);
1069 if ( PF.me == MASTER && !AM.silent ) {
1073 MesPrint(FORMNAME
" by J.Vermaseren %s(%s) Run at: %s",
1074 VERSIONSTR,PRODUCTIONDATE,MakeDate());
1093 WORD *fi, i, one = 1;
1094 CBUF *C = cbuf+AC.cbufnum;
1097 sprintf((
char*)buf,
"%d",AM.totalnumberofthreads);
1098 PutPreVar((UBYTE *)
"NTHREADS_",buf,0,0);
1102 AR.SortType = AC.SortType = AC.lSortType = AM.gSortType;
1104 AC.OutputSpaces = NORMALFORMAT;
1107 AC.ncmod = AM.gncmod = 0;
1108 AC.modmode = AM.gmodmode = 0;
1109 AC.npowmod = AM.gnpowmod = 0;
1110 AC.halfmod = 0; AC.nhalfmod = 0;
1112 AC.lPolyFun = AM.gPolyFun = 0;
1113 AC.lPolyFunType = AM.gPolyFunType = 0;
1115 AC.lDefDim = AM.gDefDim = 4;
1116 AC.lDefDim4 = AM.gDefDim4 = 0;
1117 AC.lUnitTrace = AM.gUnitTrace = 4;
1118 AC.NamesFlag = AM.gNamesFlag = 0;
1119 AC.CodesFlag = AM.gCodesFlag = 0;
1120 AC.extrasymbols = AM.gextrasymbols = AM.ggextrasymbols = 0;
1121 AC.extrasym = (UBYTE *)Malloc1(2*
sizeof(UBYTE),
"extrasym");
1122 AM.gextrasym = (UBYTE *)Malloc1(2*
sizeof(UBYTE),
"extrasym");
1123 AM.ggextrasym = (UBYTE *)Malloc1(2*
sizeof(UBYTE),
"extrasym");
1124 AC.extrasym[0] = AM.gextrasym[0] = AM.ggextrasym[0] =
'Z';
1125 AC.extrasym[1] = AM.gextrasym[1] = AM.ggextrasym[1] = 0;
1126 AC.TokensWriteFlag = AM.gTokensWriteFlag = 0;
1128 AC.LineLength = AM.gLineLength = 79;
1132 AC.OutputSpaces = NORMALFORMAT;
1133 AM.gOutputSpaces = NORMALFORMAT;
1134 AC.OutNumberType = RATIONALMODE;
1135 AM.gOutNumberType = RATIONALMODE;
1137 AR.gzipCompress = 0;
1140 AC.bracketindexflag = 0;
1141 AT.bracketindexflag = 0;
1144 AM.gfunpowers = AC.funpowers = COMFUNPOWERS;
1145 AC.parallelflag = AM.gparallelflag;
1146 AC.properorderflag = AM.gproperorderflag = PROPERORDERFLAG;
1147 AC.ProcessBucketSize = AC.mProcessBucketSize = AM.gProcessBucketSize;
1148 AC.ThreadBucketSize = AM.gThreadBucketSize;
1149 AC.ShortStatsMax = 0;
1150 AM.gShortStatsMax = 0;
1151 AM.ggShortStatsMax = 0;
1153 GlobalSymbols = NumSymbols;
1154 GlobalIndices = NumIndices;
1155 GlobalVectors = NumVectors;
1156 GlobalFunctions = NumFunctions;
1157 GlobalSets = NumSets;
1158 GlobalSetElements = NumSetElements;
1159 AC.modpowers = (UWORD *)0;
1163 if ( i > 0 )
do { *fi++ = one; }
while ( --i >= 0 );
1173 for ( i = 8; i < 15; i++ ) AM.Ordering[i] = i;
1175 AC.lUniTrace[0] = SNUMBER;
1179 AC.lUniTrace[2] = 4;
1181 AC.lUniTrace[3] = 1;
1185 AT.MinVecArg[0] = 7+ARGHEAD;
1186 AT.MinVecArg[ARGHEAD] = 7;
1187 AT.MinVecArg[1+ARGHEAD] = INDEX;
1188 AT.MinVecArg[2+ARGHEAD] = 3;
1189 AT.MinVecArg[3+ARGHEAD] = 0;
1190 AT.MinVecArg[4+ARGHEAD] = 1;
1191 AT.MinVecArg[5+ARGHEAD] = 1;
1192 AT.MinVecArg[6+ARGHEAD] = -3;
1194 *t++ = 4+ARGHEAD+FUNHEAD;
1195 for ( i = 1; i < ARGHEAD; i++ ) *t++ = 0;
1199 for ( i = 2; i < FUNHEAD; i++ ) *t++ = 0;
1200 *t++ = 1; *t++ = 1; *t++ = 3;
1207 AT.comsym[1] = SYMBOL;
1218 AT.comfun[0] = FUNHEAD+4;
1219 AT.comfun[1] = FUNCTION;
1220 AT.comfun[2] = FUNHEAD;
1225 AT.comfun[FUNHEAD+1] = 1;
1226 AT.comfun[FUNHEAD+2] = 1;
1227 AT.comfun[FUNHEAD+3] = 3;
1229 AT.comind[1] = INDEX;
1235 AT.locwildvalue[0] = SUBEXPRESSION;
1236 AT.locwildvalue[1] = SUBEXPSIZE;
1237 for ( i = 2; i < SUBEXPSIZE; i++ ) AT.locwildvalue[i] = 0;
1238 AT.mulpat[0] = TYPEMULT;
1239 AT.mulpat[1] = SUBEXPSIZE+3;
1241 AT.mulpat[3] = SUBEXPRESSION;
1242 AT.mulpat[4] = SUBEXPSIZE;
1245 for ( i = 7; i < SUBEXPSIZE+5; i++ ) AT.mulpat[i] = 0;
1246 AT.proexp[0] = SUBEXPSIZE+4;
1247 AT.proexp[1] = EXPRESSION;
1248 AT.proexp[2] = SUBEXPSIZE;
1251 for ( i = 5; i < SUBEXPSIZE+1; i++ ) AT.proexp[i] = 0;
1252 AT.proexp[SUBEXPSIZE+1] = 1;
1253 AT.proexp[SUBEXPSIZE+2] = 1;
1254 AT.proexp[SUBEXPSIZE+3] = 3;
1255 AT.proexp[SUBEXPSIZE+4] = 0;
1256 AT.dummysubexp[0] = SUBEXPRESSION;
1257 AT.dummysubexp[1] = SUBEXPSIZE+4;
1258 for ( i = 2; i < SUBEXPSIZE; i++ ) AT.dummysubexp[i] = 0;
1259 AT.dummysubexp[SUBEXPSIZE] = WILDDUMMY;
1260 AT.dummysubexp[SUBEXPSIZE+1] = 4;
1261 AT.dummysubexp[SUBEXPSIZE+2] = 0;
1262 AT.dummysubexp[SUBEXPSIZE+3] = 0;
1264 AT.inprimelist = -1;
1265 AT.sizeprimelist = 0;
1267 AN.SplitScratch = 0;
1268 AN.SplitScratchSize = AN.InScratch = 0;
1269 AN.SplitScratch1 = 0;
1270 AN.SplitScratchSize1 = AN.InScratch1 = 0;
1272 AO.OutputLine = AO.OutFill = BufferForOutput;
1277 AP.ComChar = AP.cComChar;
1278 AC.cbufnum = AM.rbufnum;
1280 AP.PreAssignFlag = 0;
1291 static int exitInProgress = 0;
1292 static int trappedTerminate = 0;
1296 #ifdef INTSIGHANDLER 1297 static int onErrSig(
int i)
1299 static VOID onErrSig(
int i)
1302 if (exitInProgress){
1305 #ifdef INTSIGHANDLER 1311 trappedTerminate = 1;
1316 #ifdef INTSIGHANDLER 1317 static VOID setNewSig(
int i,
int (*handler)(
int))
1319 static VOID setNewSig(
int i,
void (*handler)(
int))
1324 if ( signal(i,SIG_IGN) !=SIG_IGN)
1329 VOID setSignalHandlers()
1332 setNewSig(SIGSEGV,onErrSig);
1333 setNewSig(SIGFPE,onErrSig);
1334 setNewSig(SIGILL,onErrSig);
1335 setNewSig(SIGEMT,onErrSig);
1336 setNewSig(SIGSYS,onErrSig);
1337 setNewSig(SIGPIPE,onErrSig);
1338 setNewSig(SIGLOST,onErrSig);
1339 setNewSig(SIGXCPU,onErrSig);
1340 setNewSig(SIGXFSZ,onErrSig);
1343 setNewSig(SIGTERM,onErrSig);
1344 setNewSig(SIGINT,onErrSig);
1345 setNewSig(SIGQUIT,onErrSig);
1346 setNewSig(SIGHUP,onErrSig);
1347 setNewSig(SIGALRM,onErrSig);
1348 setNewSig(SIGVTALRM,onErrSig);
1349 setNewSig(SIGPROF,onErrSig);
1360 ALLPRIVATES *ABdummy[10];
1363 int main(
int argc,
char **argv)
1366 bzero((VOID *)(&A),
sizeof(A));
1369 setSignalHandlers();
1377 AM.SumTime = TimeCPU(0);
1382 if (
PF_Init(&argc,&argv) ) exit(-1);
1406 if ( ( retval = DoTail(argc,(UBYTE **)argv) ) != 0 ) {
1407 if ( retval > 0 ) Terminate(0);
1410 if ( DoSetups() ) Terminate(-2);
1415 if ( OpenInput() ) Terminate(-3);
1419 if ( TryEnvironment() ) Terminate(-2);
1420 if ( TryFileSetups() ) Terminate(-2);
1421 if ( MakeSetupAllocs() ) Terminate(-2);
1425 if ( AM.totalnumberofthreads == 0 ) AM.totalnumberofthreads = 1;
1426 AS.MultiThreaded = 0;
1428 if ( AM.totalnumberofthreads > 1 ) AS.MultiThreaded = 1;
1429 ReserveTempFiles(1);
1430 StartAllThreads(AM.totalnumberofthreads);
1433 ReserveTempFiles(0);
1456 VOID CleanUp(WORD par)
1463 for ( i = 0; i < 2; i++ ) {
1464 if ( AR.Fscr[i].handle >= 0 ) {
1465 if ( AR.Fscr[i].name ) {
1470 CloseFile(AR.Fscr[i].handle);
1471 remove(AR.Fscr[i].name);
1473 AR.Fscr[i].handle = - 1;
1474 AR.Fscr[i].POfill = 0;
1482 if ( AC.StoreHandle >= 0 && par <= 0 ) {
1484 if ( trappedTerminate ) {
1487 SeekFile(AC.StoreHandle,&pos,SEEK_END);
1488 if ( ISNOTZEROPOS(pos) ) {
1489 CloseFile(AC.StoreHandle);
1493 CloseFile(AC.StoreHandle);
1494 if ( par >= 0 || AR.StoreData.Handle < 0 ) {
1499 CloseFile(AC.StoreHandle);
1500 if ( par >= 0 || AR.StoreData.Handle < 0 ) {
1515 if ( AC.LogHandle >= 0 && par <= 0 ) {
1516 WORD lh = AC.LogHandle;
1519 if ( PF.me == MASTER )
1530 static int firstterminate = 1;
1532 VOID Terminate(
int errorcode)
1534 if ( errorcode && firstterminate ) {
1537 MesPrint(
"Program terminating in thread %w at &");
1538 #elif defined(WITHMPI) 1539 MesPrint(
"Program terminating in process %w at &");
1541 MesPrint(
"Program terminating at &");
1548 #ifdef WITHEXTERNALCHANNEL 1553 closeAllExternalChannels();
1554 AX.currentExternalChannel=0;
1556 AX.killSignal=SIGKILL;
1557 AX.killWholeGroup=1;
1560 if(AX.currentPrompt){
1561 M_free(AX.currentPrompt,
"external channel prompt");
1566 M_free(AX.shellname,
"external channel shellname");
1570 M_free(AX.stderrname,
"external channel stderrname");
1576 TerminateAllThreads();
1578 if ( AC.FinalStats ) {
1579 if ( AM.PrintTotalSize ) {
1580 MesPrint(
"Max. space for expressions: %19p bytes",&(AS.MaxExprSize));
1585 if ( AM.HoldFlag && PF.me == MASTER ) {
1586 WriteFile(AM.StdOut,(UBYTE *)(
"Hit any key "),12);
1591 if ( AM.HoldFlag ) {
1592 WriteFile(AM.StdOut,(UBYTE *)(
"Hit any key "),12);
1602 P_term(errorcode? 0: 1);
1613 VOID PrintRunningTime()
1615 #if (defined(WITHPTHREADS) && (defined(WITHPOSIXCLOCK) || defined(WINDOWS))) || defined(WITHMPI) 1620 #if defined(WITHPTHREADS) 1622 workertime = GetWorkerTimes();
1625 if ( PF.me == MASTER ) {
1627 mastertime = AM.SumTime + TimeCPU(1);
1628 wallclocktime = TimeWallClock(1);
1629 totaltime = mastertime+workertime;
1630 MesPrint(
" %l.%2i sec + %l.%2i sec: %l.%2i sec out of %l.%2i sec",
1631 mastertime/1000,(WORD)((mastertime%1000)/10),
1632 workertime/1000,(WORD)((workertime%1000)/10),
1633 totaltime/1000,(WORD)((totaltime%1000)/10),
1634 wallclocktime/100,(WORD)(wallclocktime%100));
1637 LONG mastertime = AM.SumTime + TimeCPU(1);
1638 LONG wallclocktime = TimeWallClock(1);
1639 MesPrint(
" %l.%2i sec out of %l.%2i sec",
1640 mastertime/1000,(WORD)((mastertime%1000)/10),
1641 wallclocktime/100,(WORD)(wallclocktime%100));
1650 LONG GetRunningTime()
1652 #if defined(WITHPTHREADS) && (defined(WITHPOSIXCLOCK) || defined(WINDOWS)) 1656 workertime = GetWorkerTimes();
1657 mastertime = AM.SumTime + TimeCPU(1);
1658 return(mastertime+workertime);
1661 return(AM.SumTime + TimeCPU(1));
1663 #elif defined(WITHMPI) 1664 LONG mastertime, t = 0;
1666 if ( PF.me == MASTER ) {
1667 mastertime = AM.SumTime + TimeCPU(1);
1668 t = mastertime + workertime;
1672 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)