63int PF_RawSend(
int dest,
void *buf, LONG l,
int tag);
64LONG
PF_RawRecv(
int *src,
void *buf,LONG thesize,
int *tag);
69static int PF_WaitAllSlaves(
void);
71static void PF_PackRedefinedPreVars(
void);
72static void PF_UnpackRedefinedPreVars(
void);
74static int PF_Wait4MasterIP(
int tag);
75static int PF_DoOneExpr(
void);
76static int PF_ReadMaster(
void);
77static int PF_Slave2MasterIP(
int src);
78static int PF_Master2SlaveIP(
int dest, EXPRESSIONS e);
79static int PF_WalkThrough(WORD *t, LONG l, LONG chunk, LONG *count);
80static int PF_SendChunkIP(
FILEHANDLE *curfile, POSITION *position,
int to, LONG thesize);
81static int PF_RecvChunkIP(
FILEHANDLE *curfile,
int from, LONG thesize);
83static void PF_ReceiveErrorMessage(
int src,
int tag);
84static void PF_CatchErrorMessages(
int *src,
int *tag);
85static void PF_CatchErrorMessagesForAll(
void);
86static int PF_ProbeWithCatchingErrorMessages(
int *src);
95static LONG PF_goutterms;
96static POSITION PF_exprsize;
103#ifdef PF_WITH_SCHED_YIELD
108 #define PRINTFBUF(TEXT,TERM,SIZE) { UBYTE lbuf[24]; if(PF.log){ WORD iii;\
109 NumToStr(lbuf,AC.CModule); \
110 fprintf(stderr,"[%d|%s] %s : ",PF.me,lbuf,(char*)TEXT);\
111 if(TERM){ fprintf(stderr,"[%d] ",(int)(*TERM));\
112 if((SIZE)<500 && (SIZE)>0) for(iii=1;iii<(SIZE);iii++)\
113 fprintf(stderr,"%d ",TERM[iii]); }\
114 fprintf(stderr,"\n");\
117 #define PRINTFBUF(TEXT,TERM,SIZE) {}
126 char swap_tmp__[sizeof(x) == sizeof(y) ? (int)sizeof(x) : -1]; \
127 memcpy(swap_tmp__, &y, sizeof(x)); \
128 memcpy(&y, &x, sizeof(x)); \
129 memcpy(&x, swap_tmp__, sizeof(x)); \
135#define PACK_LONG(p, n) \
137 *(p)++ = (UWORD)((ULONG)(n) & (ULONG)WORDMASK); \
138 *(p)++ = (UWORD)(((ULONG)(n) >> BITSINWORD) & (ULONG)WORDMASK); \
144#define UNPACK_LONG(p, n) \
146 (n) = (LONG)((((ULONG)(p)[1] & (ULONG)WORDMASK) << BITSINWORD) | ((ULONG)(p)[0] & (ULONG)WORDMASK)); \
153#define CHECK(condition) _CHECK(condition, __FILE__, __LINE__)
154#define _CHECK(condition, file, line) __CHECK(condition, file, line)
155#define __CHECK(condition, file, line) \
157 if ( !(condition) ) { \
158 Error0("Fatal error at " file ":" #line); \
166#define DBGOUT(lv1, lv2, a) do { if ( lv1 >= lv2 ) { printf a; fflush(stdout); } } while (0)
169#define DBGOUT_NINTERMS(lv, a)
177static LONG PF_linterms;
178#define PF_STATS_SIZE 5
179static LONG **PF_stats = NULL;
180static LONG PF_laststat;
181static LONG PF_statsinterval;
195static int PF_Statistics(LONG **stats,
int proc)
202 if ( AT.SS == AM.S0 && PF.me == MASTER ) {
203 real =
PF_RealTime(PF_TIME); rpart = (WORD)(real%100); real /= 100;
205 if ( PF_stats == NULL ) {
206 PF_stats = (LONG**)Malloc1(PF.numtasks*
sizeof(LONG*),
"PF_stats 1");
207 for ( i = 0; i < PF.numtasks; i++ ) {
208 PF_stats[i] = (LONG*)Malloc1(PF_STATS_SIZE*
sizeof(LONG),
"PF_stats 2");
209 for ( j = 0; j < PF_STATS_SIZE; j++ ) PF_stats[i][j] = 0;
212 if ( proc > 0 )
for ( i = 0; i < PF_STATS_SIZE; i++ ) PF_stats[proc][i] = stats[0][i];
214 if ( real >= PF_laststat + PF_statsinterval || proc == 0 ) {
215 LONG sum[PF_STATS_SIZE];
217 for ( i = 0; i < PF_STATS_SIZE; i++ ) sum[i] = 0;
219 cpart = (WORD)(cpu%1000);
222 if ( AC.OldParallelStats ) MesPrint(
"");
223 if ( proc > 0 && AC.StatsFlag && AC.OldParallelStats ) {
224 MesPrint(
"proc CPU in gen left byte");
225 MesPrint(
"%3d : %7l.%2i %10l",0,cpu,cpart,AN.ninterms);
227 else if ( AC.StatsFlag && AC.OldParallelStats ) {
228 MesPrint(
"proc CPU in gen out byte");
229 MesPrint(
"%3d : %7l.%2i %10l %10l %10l",0,cpu,cpart,AN.ninterms,0,PF_goutterms);
232 for ( i = 1; i < PF.numtasks; i++ ) {
233 cpart = (WORD)(PF_stats[i][0]%1000);
234 cpu = PF_stats[i][0] / 1000;
236 if ( AC.StatsFlag && AC.OldParallelStats )
237 MesPrint(
"%3d : %7l.%2i %10l %10l %10l",i,cpu,cpart,
238 PF_stats[i][2],PF_stats[i][3],PF_stats[i][4]);
239 for ( j = 0; j < PF_STATS_SIZE; j++ ) sum[j] += PF_stats[i][j];
241 cpart = (WORD)(sum[0]%1000);
244 if ( AC.StatsFlag && AC.OldParallelStats ) {
245 MesPrint(
"Sum = %7l.%2i %10l %10l %10l",cpu,cpart,sum[2],sum[3],sum[4]);
246 MesPrint(
"Real = %7l.%2i %20s (%l) %16s",
247 real,rpart,AC.Commercial,AC.CModule,EXPRNAME(AR.CurExpr));
279static WORD **PF_term;
280static WORD **PF_newcpos;
281static WORD *PF_newclen;
287static WORD *PF_WorkSpace;
288static UWORD *PF_ScratchSpace;
311static PF_BUFFER *PF_AllocBuf(
int nbufs, LONG bsize, WORD free)
319 (LONG)(
sizeof(
PF_BUFFER) + 4*nbufs*
sizeof(WORD*) + (nbufs-free)*bsize);
322 (LONG)( nbufs * ( 2 *
sizeof(MPI_Status)
323 +
sizeof(MPI_Request)
324 +
sizeof(MPI_Datatype)
326 allocsize += (LONG)( nbufs * 3 *
sizeof(
int) );
328 if ( ( buf = (
PF_BUFFER*)Malloc1(allocsize,
"PF_AllocBuf") ) == NULL )
return(NULL);
331 stop = ((UBYTE *)buf) + allocsize;
333 buf->numbufs = nbufs;
336 buf->buff = (WORD**)p; p += buf->numbufs*
sizeof(WORD*);
337 buf->fill = (WORD**)p; p += buf->numbufs*
sizeof(WORD*);
338 buf->full = (WORD**)p; p += buf->numbufs*
sizeof(WORD*);
339 buf->stop = (WORD**)p; p += buf->numbufs*
sizeof(WORD*);
340 buf->status = (MPI_Status *)p; p += buf->numbufs*
sizeof(MPI_Status);
341 buf->retstat = (MPI_Status *)p; p += buf->numbufs*
sizeof(MPI_Status);
342 buf->request = (MPI_Request *)p; p += buf->numbufs*
sizeof(MPI_Request);
343 buf->type = (MPI_Datatype *)p; p += buf->numbufs*
sizeof(MPI_Datatype);
344 buf->index = (
int *)p; p += buf->numbufs*
sizeof(int);
346 for ( i = 0; i < buf->numbufs; i++ ) buf->request[i] = MPI_REQUEST_NULL;
347 buf->tag = (
int *)p; p += buf->numbufs*
sizeof(int);
348 buf->from = (
int *)p; p += buf->numbufs*
sizeof(int);
352 for ( i = free; i < buf->numbufs; i++ ) {
353 buf->buff[i] = (WORD*)p; p += bsize;
354 buf->stop[i] = (WORD*)p;
355 buf->fill[i] = buf->full[i] = buf->buff[i];
358 MesPrint(
"Error in PF_AllocBuf p = %x stop = %x\n",p,stop);
380static int PF_InitTree(
void)
385 int numrbufs,numtasks = PF.numtasks;
386 int i, j, src, numnodes;
387 int numslaves = numtasks - 1;
393 if ( PF_term == NULL ) {
394 size = 2*numtasks*
sizeof(WORD*) +
sizeof(WORD)*
395 ( numtasks*(1 + AM.MaxTal) + (AM.MaxTer/
sizeof(WORD)+1) + 2*(AM.MaxTal+2));
397 PF_term = (WORD **)Malloc1(size,
"PF_term");
398 stop = ((UBYTE*)PF_term) + size;
399 p = ((UBYTE*)PF_term) + numtasks*
sizeof(WORD*);
401 PF_newcpos = (WORD **)p; p +=
sizeof(WORD*) * numtasks;
402 PF_newclen = (WORD *)p; p +=
sizeof(WORD) * numtasks;
403 for ( i = 0; i < numtasks; i++ ) {
404 PF_newcpos[i] = (WORD *)p; p +=
sizeof(WORD)*AM.MaxTal;
407 PF_WorkSpace = (WORD *)p; p += AM.MaxTer+
sizeof(WORD);
408 PF_ScratchSpace = (UWORD*)p; p += 2*(AM.MaxTal+2)*
sizeof(UWORD);
410 if ( p != stop ) { MesPrint(
"error in PF_InitTree");
return(-1); }
416 numrbufs = PF.numrbufs;
420 size = (AT.SS->sTop2 - AT.SS->lBuffer - 1)/(PF.numtasks - 1);
422 if ( rbuf == NULL ) {
423 if ( ( rbuf = (
PF_BUFFER**)Malloc1(numtasks*
sizeof(
PF_BUFFER*),
"Master: rbufs") ) == NULL )
return(-1);
424 if ( (rbuf[0] = PF_AllocBuf(1,0,1) ) == NULL )
return(-1);
425 for ( i = 1; i < numtasks; i++ ) {
426 if (!(rbuf[i] = PF_AllocBuf(numrbufs,
sizeof(WORD)*size,1)))
return(-1);
429 rbuf[0]->buff[0] = AT.SS->lBuffer;
430 rbuf[0]->full[0] = rbuf[0]->fill[0] = rbuf[0]->buff[0];
431 rbuf[0]->stop[0] = rbuf[1]->buff[0] = rbuf[0]->buff[0] + 1;
432 rbuf[1]->full[0] = rbuf[1]->fill[0] = rbuf[1]->buff[0];
433 for ( i = 2; i < numtasks; i++ ) {
434 rbuf[i-1]->stop[0] = rbuf[i]->buff[0] = rbuf[i-1]->buff[0] + size;
435 rbuf[i]->full[0] = rbuf[i]->fill[0] = rbuf[i]->buff[0];
437 rbuf[numtasks-1]->stop[0] = rbuf[numtasks-1]->buff[0] + size;
439 for ( i = 1; i < numtasks; i++ ) {
440 for ( j = 0; j < rbuf[i]->numbufs; j++ ) {
441 rbuf[i]->full[j] = rbuf[i]->fill[j] = rbuf[i]->buff[j] + AM.MaxTer/
sizeof(WORD) + 2;
443 PF_term[i] = rbuf[i]->fill[rbuf[i]->active];
448 PF_term[0] = rbuf[0]->buff[0];
457 if ( numslaves < 3 ) numnodes = 1;
460 while ( numnodes < numslaves ) numnodes *= 2;
464 if ( PF_root == NULL )
465 if ( ( PF_root = (NODE*)Malloc1(
sizeof(NODE)*numnodes,
"nodes in mergtree") ) == NULL )
471 for ( i = 0; i < numnodes; i++ ) {
472 if ( 2*(i+1) <= numnodes ) {
473 PF_root[i].left = &(PF_root[2*(i+1)-1]);
478 if ( src < numtasks ) PF_root[i].lsrc = src++;
479 else PF_root[i].lsrc = 0;
481 PF_root[i].lloser = 0;
483 for ( i = 0; i < numnodes; i++ ) {
484 if ( 2*(i+1)+1 <= numnodes ) {
485 PF_root[i].rght = &(PF_root[2*(i+1)]);
490 if (src<numtasks) PF_root[i].rsrc = src++;
491 else PF_root[i].rsrc = 0;
493 PF_root[i].rloser = 0;
524static WORD *PF_PutIn(
int src)
531 int a = rbuf->active;
532 int next = a+1 >= rbuf->numbufs ? 0 : a+1 ;
533 WORD *lastterm = PF_term[src];
534 WORD *term = rbuf->fill[a];
536 if ( src <= 0 )
return(PF_term[0]);
538 if ( rbuf->full[a] == rbuf->buff[a] + AM.MaxTer/
sizeof(WORD) + 2 ) {
543 rbuf->full[a] += size;
544 if ( tag == PF_ENDBUFFER_MSGTAG ) *rbuf->full[a]++ = 0;
545 else if ( rbuf->numbufs > 1 ) {
549 rbuf->full[next] = rbuf->buff[next] + AM.MaxTer/
sizeof(WORD) + 2;
550 size = (LONG)(rbuf->stop[next] - rbuf->full[next]);
554 if ( *term == 0 && term != rbuf->full[a] )
return(PF_term[0]);
558 if ( term + *term > rbuf->full[a] || term + 1 >= rbuf->full[a] ) {
560 m1 = rbuf->buff[next] + AM.MaxTer/
sizeof(WORD) + 1;
561 if ( *term < 0 || term == rbuf->full[a] ) {
565 m2 = rbuf->full[a] - 1;
566 while ( m2 >= term ) *m1-- = *m2--;
567 rbuf->fill[next] = term = m1 + 1;
568 m2 = lastterm + *lastterm - 1;
569 while ( m2 >= lastterm ) *m1-- = *m2--;
576 m2 = rbuf->full[a] - 1;
577 while ( m2 >= term ) *m1-- = *m2--;
578 rbuf->fill[next] = term = m1 + 1;
580 if ( rbuf->numbufs == 1 ) {
581 rbuf->full[a] = rbuf->buff[a] + AM.MaxTer/
sizeof(WORD) + 2;
582 size = (LONG)(rbuf->stop[a] - rbuf->full[a]);
588 rbuf->full[next] = rbuf->buff[next] + AM.MaxTer/
sizeof(WORD) + 2;
590 rbuf->full[next] += size;
591 if ( tag == PF_ENDBUFFER_MSGTAG ) {
592 *rbuf->full[next]++ = 0;
594 else if ( rbuf->numbufs > 1 ) {
598 rbuf->full[a] = rbuf->buff[a] + AM.MaxTer/
sizeof(WORD) + 2;
599 size = (LONG)(rbuf->stop[a] - rbuf->full[a]);
605 a = rbuf->active = next;
613 r = term[1] - im + 1;
615 m2 = lastterm - im + 1;
616 while ( ++im <= 0 ) *--m1 = *--m2;
618 rbuf->fill[a] = term = m1;
619 if ( term + *term > rbuf->full[a] )
goto newterms;
621 rbuf->fill[a] += *term;
648static int PF_GetLoser(NODE *n)
653 if ( PF_loser == 0 ) {
657 if ( n->left ) n->lloser = PF_GetLoser(n->left);
660 if ( *(PF_term[n->lsrc] = PF_PutIn(n->lsrc)) == 0) n->lloser = 0;
663 if ( n->rght ) n->rloser = PF_GetLoser(n->rght);
666 if ( *(PF_term[n->rsrc] = PF_PutIn(n->rsrc)) == 0 ) n->rloser = 0;
670 else if ( PF_loser == n->lloser ) {
671 if ( n->left ) n->lloser = PF_GetLoser(n->left);
674 if ( *(PF_term[n->lsrc] = PF_PutIn(n->lsrc)) == 0 ) n->lloser = 0;
677 else if ( PF_loser == n->rloser ) {
679 if ( n->rght ) n->rloser = PF_GetLoser(n->rght);
682 if ( *(PF_term[n->rsrc] = PF_PutIn(n->rsrc)) == 0 ) n->rloser = 0;
685 if ( n->lloser > 0 && n->rloser > 0 ) {
686 comp = CompareTerms(PF_term[n->lloser],PF_term[n->rloser],(WORD)0);
687 if ( comp > 0 )
return(n->lloser);
688 else if (comp < 0 )
return(n->rloser);
695 WORD lclen, rclen, newclen, newnlen;
704 WORD *ml = PF_term[n->lloser];
705 WORD *mr = PF_term[n->rloser];
707 if ( ( r1 = (
int)*PF_term[n->lloser] ) <= 0 ) r1 = 20;
708 if ( ( r2 = (
int)*PF_term[n->rloser] ) <= 0 ) r2 = 20;
712 if ( S->PolyFlag == 2 ) {
714 if ( *tt1 + w[1] - ml[1] > AM.MaxTer/((LONG)
sizeof(WORD)) ) {
715 MesPrint(
"Term too complex in PolyRatFun addition. MaxTermSize of %10l is too small",AM.MaxTer);
722 if ( w + ml[1] + mr[1] > AT.WorkTop ) {
723 MesPrint(
"A WorkSpace of %10l is too small",AM.WorkSize);
729 if ( r1 <= FUNHEAD || ( w[FUNHEAD] == -SNUMBER && w[FUNHEAD+1] == 0 ) ) {
735 else if ( r1 < ml[1] ) {
739 while ( --r1 >= 0 ) *--ml = *--mr;
742 while ( --r1 >= 0 ) *--ml = *--mr;
744 PF_term[n->lloser] = ml;
748 if ( r2 > 2*AM.MaxTal )
749 MesPrint(
"warning: new term in polyfun is large");
754 PF_term[n->lloser] = mr;
759 PF_newclen[n->rloser] = 0;
760 PF_loser = n->rloser;
766 if ( ( lclen = PF_newclen[n->lloser] ) != 0 ) lcpos = PF_newcpos[n->lloser];
768 lcpos = PF_term[n->lloser];
769 lclen = *(lcpos += *lcpos - 1);
770 lcpos -= ABS(lclen) - 1;
772 if ( ( rclen = PF_newclen[n->rloser] ) != 0 ) rcpos = PF_newcpos[n->rloser];
774 rcpos = PF_term[n->rloser];
775 rclen = *(rcpos += *rcpos - 1);
776 rcpos -= ABS(rclen) -1;
778 lclen = ( (lclen > 0) ? (lclen-1) : (lclen+1) ) >> 1;
779 rclen = ( (rclen > 0) ? (rclen-1) : (rclen+1) ) >> 1;
780 newcpos = PF_ScratchSpace;
781 if ( AddRat(BHEAD (UWORD *)lcpos,lclen,(UWORD *)rcpos,rclen,newcpos,&newnlen) )
return(-1);
782 if ( AN.ncmod != 0 ) {
783 if ( ( AC.modmode & POSNEG ) != 0 ) {
786 if ( BigLong(newcpos,newnlen,(UWORD *)AC.cmod,ABS(AN.ncmod)) >=0 ) {
788 SubPLon(newcpos,newnlen,(UWORD *)AC.cmod,ABS(AN.ncmod),newcpos,&newnlen);
789 newcpos[newnlen] = 1;
790 for ( ii = 1; ii < newnlen; ii++ ) newcpos[newnlen+ii] = 0;
793 if ( newnlen == 0 ) {
798 PF_loser = n->lloser;
799 PF_newclen[n->lloser] = 0;
800 if ( n->left ) n->lloser = PF_GetLoser(n->left);
803 if ( *(PF_term[n->lsrc] = PF_PutIn(n->lsrc)) == 0 ) n->lloser = 0;
805 PF_loser = n->rloser;
806 PF_newclen[n->rloser] = 0;
814 newclen = ( newnlen > 0 ) ? ( newnlen + 1 ) : ( newnlen - 1 );
815 if ( newnlen < 0 ) newnlen = -newnlen;
816 PF_newclen[n->lloser] = newclen;
817 lcpos = PF_newcpos[n->lloser];
818 if ( newclen < 0 ) newclen = -newclen;
819 while ( newclen-- ) *lcpos++ = *newcpos++;
820 PF_loser = n->rloser;
821 PF_newclen[n->rloser] = 0;
829 if (n->lloser > 0)
return(n->lloser);
830 if (n->rloser > 0)
return(n->rloser);
871 LONG size, noutterms;
872 POSITION position, oldposition;
876 if ( AT.SS != AT.S0 || !PF.parallel )
return 0;
878 if ( PF.me != MASTER ) {
886 size = (S->sTop2 - S->lBuffer - 1)/(PF.numtasks - 1);
887 size -= (AM.MaxTer/
sizeof(WORD) + 2);
888 if ( fout->POsize < (LONG)(size*
sizeof(WORD)) ) size = fout->POsize/
sizeof(WORD);
889 if ( sbuf == NULL ) {
890 if ( (sbuf = PF_AllocBuf(PF.numsbufs, size*
sizeof(WORD), 1)) == NULL )
return -1;
894 sbuf->buff[0] = fout->PObuffer;
895 sbuf->stop[0] = fout->PObuffer+size;
896 if ( sbuf->stop[0] > fout->POstop )
return -1;
897 for ( i = 0; i < PF.numsbufs; i++ )
898 sbuf->fill[i] = sbuf->full[i] = sbuf->buff[i];
900 fout->PObuffer = sbuf->buff[sbuf->active];
901 fout->POstop = sbuf->stop[sbuf->active];
902 fout->POsize = size*
sizeof(WORD);
903 fout->POfill = fout->POfull = fout->PObuffer;
919 if ( AR.PolyFun == 0 ) { S->PolyFlag = 0; }
920 else if ( AR.PolyFunType == 1 ) { S->PolyFlag = 1; }
921 else if ( AR.PolyFunType == 2 ) {
922 if ( AR.PolyFunExp == 2
923 || AR.PolyFunExp == 3 ) S->PolyFlag = 1;
924 else S->PolyFlag = 2;
926 *AR.CompressPointer = 0;
927 SeekScratch(fout, &position);
928 oldposition = position;
929 oldgzipCompress = AR.gzipCompress;
934 while ( PF_loser >= 0 ) {
935 if ( (PF_loser = PF_GetLoser(PF_root)) == 0 )
break;
936 outterm = PF_term[PF_loser];
939 if ( PF_newclen[PF_loser] != 0 ) {
943 outterm = PF_WorkSpace;
944 pp = PF_term[PF_loser];
946 while ( cc-- ) *outterm++ = *pp++;
947 outterm = (outterm[-1] > 0) ? outterm-outterm[-1] : outterm+outterm[-1];
948 if ( PF_newclen[PF_loser] > 0 ) cc = (WORD)PF_newclen[PF_loser] - 1;
949 else cc = -(WORD)PF_newclen[PF_loser] - 1;
950 pp = PF_newcpos[PF_loser];
951 while ( cc-- ) *outterm++ = *pp++;
952 *outterm++ = PF_newclen[PF_loser];
953 *PF_WorkSpace = outterm - PF_WorkSpace;
954 outterm = PF_WorkSpace;
955 *PF_newcpos[PF_loser] = 0;
956 PF_newclen[PF_loser] = 0;
961 PRINTFBUF(
"PF_EndSort to PutOut: ",outterm,*outterm);
962 PutOut(BHEAD outterm,&position,fout,1);
965 AR.gzipCompress = oldgzipCompress;
968 S->TermsLeft = PF_goutterms = noutterms;
969 DIFPOS(PF_exprsize, position, oldposition);
970 AR.gzipCompress = oldgzipCompress;
981static WORD *PF_CurrentBracket;
1006static WORD PF_GetTerm(WORD *term)
1009 FILEHANDLE *fi = AC.RhsExprInModuleFlag && PF.rhsInParallel ? &PF.slavebuf : AR.infile;
1011 WORD *next, *np, *last, *lp = 0, *nextstop, *tp=term;
1015 AN.deferskipped = 0;
1016 if ( fi->POfill >= fi->POfull || fi->POfull == fi->PObuffer ) {
1022 int src = MASTER, tag;
1024 LONG size,cpu,space = 0;
1027 fprintf(stderr,
"[%d] Starting to send to Master\n",PF.me);
1035 PF_Pack(&PF_linterms ,1,PF_LONG);
1036 PF_Pack(&(AM.S0->GenTerms) ,1,PF_LONG);
1037 PF_Pack(&(AM.S0->TermsLeft),1,PF_LONG);
1041 fprintf(stderr,
"[%d] Now sending with tag = %d\n",PF.me,PF_READY_MSGTAG);
1045 PF_Send(MASTER, PF_READY_MSGTAG);
1048 fprintf(stderr,
"[%d] returning from send\n",PF.me);
1052 size = fi->POstop - fi->PObuffer - 1;
1053#ifdef AbsolutelyExtra
1056 if ( tag == PF_TERM_MSGTAG ) {
1058 if ( PF_Put_target(src) == 0 ) {
1059 printf(
"PF_Put_target error ...\n");
1071 fi->POfill = fi->PObuffer;
1076 if ( fi->POfill < fi->POfull ) {
1077 DBGOUT_NINTERMS(2, (
"PF.me=%d AN.ninterms=%d PF_linterms=%d ninterms=%d GET\n", (
int)PF.me, (
int)AN.ninterms, (
int)PF_linterms, (
int)ninterms));
1078 AN.ninterms = ninterms - 1;
1080 DBGOUT_NINTERMS(2, (
"PF.me=%d AN.ninterms=%d PF_linterms=%d ninterms=%d GETEND\n", (
int)PF.me, (
int)AN.ninterms, (
int)PF_linterms, (
int)ninterms));
1083 fi->POfull = fi->PObuffer + size;
1084 if ( tag == PF_ENDSORT_MSGTAG ) *fi->POfull++ = 0;
1089 if ( PF_CurrentBracket ) *PF_CurrentBracket = 0;
1091 if ( *fi->POfill == 0 ) {
1092 fi->POfill = fi->POfull = fi->PObuffer;
1096 if ( AR.DeferFlag ) {
1097 if ( !PF_CurrentBracket ) {
1102 (WORD*)Malloc1(AM.MaxTer,
"PF_CurrentBracket");
1103 *PF_CurrentBracket = 0;
1108 while ( *PF_CurrentBracket ) {
1113 nextstop = next + *next; nextstop -= ABS(nextstop[-1]);
1115 last = PF_CurrentBracket+1;
1116 while ( next < nextstop ) {
1120 if ( *last == HAAKJE && *next == HAAKJE ) {
1124 PRINTFBUF(
"PF_GetTerm skips",fi->POfill,*fi->POfill);
1130 np = next; next += next[1];
1131 lp = last; last += last[1];
1132 while ( np < next )
if ( *lp++ != *np++ )
goto strip;
1137 fi->POfill += *fi->POfill;
1142 if ( fi->POfill >= fi->POfull || fi->POfull == fi->PObuffer )
1144 if ( *fi->POfill == 0 ) {
1145 fi->POfill = fi->POfull = fi->PObuffer;
1161 nextstop = next + *next; nextstop -= ABS(nextstop[-1]);
1164 lp = PF_CurrentBracket + 1;
1165 while ( next < nextstop ) {
1166 if ( *next == HAAKJE ) {
1167 fi->POfill += *fi->POfill;
1168 while ( next < fi->POfill ) *lp++ = *next++;
1169 *PF_CurrentBracket = lp - PF_CurrentBracket;
1174 *term = WORDDIF(tp,term);
1175 PRINTFBUF(
"PF_GetTerm new brack",PF_CurrentBracket,*PF_CurrentBracket);
1176 PRINTFBUF(
"PF_GetTerm POfill",fi->POfill,*fi->POfill);
1179 np = next; next += next[1];
1180 while ( np < next ) *tp++ = *lp++ = *np++;
1189 while ( i-- ) *tp++ = *fi->POfill++;
1191 PRINTFBUF(
"PF_GetTerm returns",term,*term);
1213 FILEHANDLE *fi = AC.RhsExprInModuleFlag && PF.rhsInParallel ? &PF.slavebuf : AR.infile;
1214 WORD *next = fi->POfill;
1215 WORD *termout = AT.WorkPointer;
1216 WORD *oldwork = AT.WorkPointer;
1218 AT.WorkPointer = (WORD *)((UBYTE *)(AT.WorkPointer) + AM.MaxTer);
1221 PRINTFBUF(
"PF_Deferred (Term) ",term,*term);
1222 PRINTFBUF(
"PF_Deferred (Bracket)",PF_CurrentBracket,*PF_CurrentBracket);
1224 bra = bstop = PF_CurrentBracket;
1227 bstop -= ABS(bstop[-1]);
1230 while ( *bra != HAAKJE && bra < bstop ) bra += bra[1];
1231 if ( bra >= bstop ) {
1232 AT.WorkPointer = term + *term;
1233 if (
Generator(BHEAD term,level) )
goto DefCall;
1235 AT.WorkPointer = oldwork;
1239 tstart = bra + bra[1];
1240 bra = PF_CurrentBracket;
1242 *tstart = bra + *bra - tstart;
1251 if (
InsertTerm(BHEAD term,0,AM.rbufnum,tstart,termout,0) < 0 ) {
1257 AT.WorkPointer = termout + *termout;
1258 if (
Generator(BHEAD termout,level) )
goto DefCall;
1259 AT.WorkPointer = termout;
1261 if ( tstart >= fi->POfull )
goto ThatsIt;
1266 while ( bra <= bstop ) {
1267 if ( *bra != *tstart )
goto ThatsIt;
1274 if ( *bra != HAAKJE || *tstart != HAAKJE )
goto ThatsIt;
1275 tstart += tstart[1];
1277 *tstart = next - tstart;
1278 bra = PF_CurrentBracket + 1;
1288 MesCall(
"PF_Deferred");
1297static LONG **PF_W4Sstats = 0;
1305static int PF_Wait4Slave(
int src)
1309 tag = PF_ANY_MSGTAG;
1310 PF_CatchErrorMessages(&src, &tag);
1313 if ( tag != PF_READY_MSGTAG ) {
1314 MesPrint(
"[%d] PF_Wait4Slave: received MSGTAG %d",(WORD)PF.me,(WORD)tag);
1317 if ( PF_W4Sstats == 0 ) {
1318 PF_W4Sstats = (LONG**)Malloc1(
sizeof(LONG*),
"");
1319 PF_W4Sstats[0] = (LONG*)Malloc1(PF_STATS_SIZE*
sizeof(LONG),
"");
1321 PF_Unpack(PF_W4Sstats[0],PF_STATS_SIZE,PF_LONG);
1322 PF_Statistics(PF_W4Sstats,next);
1343static WORD *partodoexr=NULL;
1352static int PF_Wait4SlaveIP(
int *src)
1356 tag = PF_ANY_MSGTAG;
1357 PF_CatchErrorMessages(src, &tag);
1360 if ( PF_W4Sstats == 0 ) {
1361 PF_W4Sstats = (LONG**)Malloc1(
sizeof(LONG*),
"");
1362 PF_W4Sstats[0] = (LONG*)Malloc1(PF_STATS_SIZE*
sizeof(LONG),
"");
1365 PF_Unpack(PF_W4Sstats[0],PF_STATS_SIZE,PF_LONG);
1366 if ( tag == PF_DATA_MSGTAG )
1367 AR.CurExpr = partodoexr[next];
1368 PF_Statistics(PF_W4Sstats,next);
1391static int PF_WaitAllSlaves(
void)
1393 int i, readySlaves, tag, next = PF_ANY_SOURCE;
1394 UBYTE *has_sent = 0;
1396 has_sent = (UBYTE*)Malloc1(
sizeof(UBYTE)*(PF.numtasks + 1),
"PF_WaitAllSlaves");
1397 for ( i = 0; i < PF.numtasks; i++ ) has_sent[i] = 0;
1399 for ( readySlaves = 1; readySlaves < PF.numtasks; ) {
1400 if ( next != PF_ANY_SOURCE) {
1402 if ( ++next >= PF.numtasks ) next = 1;
1403 }
while ( has_sent[next] == 1 );
1408 tag = PF_ProbeWithCatchingErrorMessages(&next);
1413 case PF_BUFFER_MSGTAG:
1414 case PF_ENDBUFFER_MSGTAG:
1418 if ( has_sent[next] == 0 ) {
1423 fprintf(stderr,
"ERROR next=%d tag=%d\n",next,tag);
1437#ifdef PF_WITH_SCHED_YIELD
1444 case PF_DATA_MSGTAG:
1446 next=PF_Wait4SlaveIP(&tag);
1450 PF_Statistics(PF_stats,0);
1451 PF_Slave2MasterIP(next);
1452 PF_Master2SlaveIP(next,NULL);
1453 if ( has_sent[next] == 0 ) {
1458 fprintf(stderr,
"ERROR next=%d tag=%d\n",next,tag);
1461 case PF_EMPTY_MSGTAG:
1463 next=PF_Wait4SlaveIP(&tag);
1467 PF_Master2SlaveIP(next,NULL);
1468 if ( has_sent[next] == 0 ) {
1473 fprintf(stderr,
"ERROR next=%d tag=%d\n",next,tag);
1476 case PF_READY_MSGTAG:
1481 next = PF_Wait4Slave(next);
1482 if ( next == -1 )
return(next);
1483 if ( has_sent[0] == 0 ) {
1484 PF.sbuf->active = 0;
1492 PACK_LONG(PF.sbuf->fill[next], AN.ninterms);
1496 *(PF.sbuf->fill[next])++ = 0;
1497 PF.sbuf->active = next;
1509 MesPrint(
"!!!Unexpected MPI message src=%d tag=%d.", next, tag);
1510 readySlaves = PF.numtasks+1;
1515 if ( has_sent ) M_free(has_sent,
"PF_WaitAllSlaves");
1520 return(PF.numtasks-readySlaves);
1543 WORD *term = AT.WorkPointer;
1553 if ( PF_shared_buff == NULL ) {
1554 if ( PF_SMWin_Init() == 0 ) {
1555 MesPrint(
"PF_SMWin_Init error");
1561 if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer ) ) > AT.WorkTop )
return(MesWork());
1564 if ( AC.numpfirstnum > 0 ) {
1565 for ( j = 0; j < AC.numpfirstnum; j++ ) {
1566 AC.inputnumbers[j] = -1;
1570 if ( AC.mparallelflag != PARALLELFLAG )
return(0);
1572 if ( PF.me == MASTER ) {
1577 WORD oldBracketOn = AR.BracketOn;
1578 WORD *oldBrackBuf = AT.BrackBuf;
1579 WORD oldbracketindexflag = AT.bracketindexflag;
1584 LONG ProcessBucketSize = AC.mProcessBucketSize;
1586 if ( PF.log && AC.CModule >= PF.log )
1587 MesPrint(
"[%d] working on expression %s in module %l",PF.me,EXPRNAME(i),AC.CModule);
1588 if ( GetTerm(BHEAD term) <= 0 ) {
1589 MesPrint(
"[%d] Expression %d has problems in scratchfile",PF.me,i);
1593 if ( AR.outtohide ) {
1594 SeekScratch(AR.hidefile,&position);
1595 e->onfile = position;
1596 if (
PutOut(BHEAD term,&position,AR.hidefile,0) < 0 )
return(-1);
1599 SeekScratch(AR.outfile,&position);
1600 e->onfile = position;
1601 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
return(-1);
1605 if ( ( e->vflags & ISFACTORIZED ) != 0 ) {
1607 AT.BrackBuf = AM.BracketFactors;
1608 AT.bracketindexflag = 1;
1610 if ( AT.bracketindexflag > 0 ) OpenBracketIndex(i);
1621 if ( sb == 0 || sb->buff[0] != AT.SS->lBuffer ) {
1622 size = (LONG)((AT.SS->sTop2 - AT.SS->lBuffer)/(PF.numtasks));
1623 if ( size > (LONG)(AR.infile->POsize/
sizeof(WORD) - 1) )
1624 size = AR.infile->POsize/
sizeof(WORD) - 1;
1626 if ( ( sb = PF_AllocBuf(PF.numtasks,size*
sizeof(WORD),PF.numtasks) ) == NULL )
1629 sb->buff[0] = AT.SS->lBuffer;
1630 sb->full[0] = sb->fill[0] = sb->buff[0];
1631 for ( j = 1; j < PF.numtasks; j++ ) {
1632 sb->stop[j-1] = sb->buff[j] = sb->buff[j-1] + size;
1634 sb->stop[PF.numtasks-1] = sb->buff[PF.numtasks-1] + size;
1637 for ( j = 0; j < PF.numtasks; j++ ) {
1638 sb->full[j] = sb->fill[j] = sb->buff[j];
1650 maxinterms = ProcessBucketSize / 100;
1651 if ( maxinterms > e->counter / (PF.numtasks - 1) / 4 )
1652 maxinterms = e->counter / (PF.numtasks - 1) / 4;
1653 if ( maxinterms < 1 ) maxinterms = 1;
1664 while ( GetTerm(BHEAD term) ) {
1665 AN.ninterms++; dd = AN.deferskipped;
1666 if ( AC.CollectFun && *term <= (LONG)(AM.MaxTer/(2*
sizeof(WORD))) ) {
1667 if ( GetMoreTerms(term) < 0 ) {
1671 PRINTFBUF(
"PF_Processor gets",term,*term);
1672 if ( termsinbucket >= maxinterms || sb->fill[0] + *term >= sb->stop[0] ) {
1673 next = PF_Wait4Slave(PF_ANY_SOURCE);
1675 sb->fill[next] = sb->fill[0];
1676 sb->full[next] = sb->full[0];
1677 SWAP(sb->stop[next], sb->stop[0]);
1678 SWAP(sb->buff[next], sb->buff[0]);
1679 sb->fill[0] = sb->full[0] = sb->buff[0];
1683 if ( PF_Put_origin(next) == 0 ) {
1684 printf(
"PF_Put_origin error...\n");
1696 if ( cmaxinterms >= PF.numtasks - 2 ) {
1698 if ( maxinterms >= ProcessBucketSize ) {
1700 maxinterms = ProcessBucketSize;
1703 else if ( cmaxinterms >= 0 ) {
1708 NCOPY(sb->fill[0], s, j);
1718 if ( LastExpression ) {
1720 if ( AR.infile->handle >= 0 ) {
1721 CloseFile(AR.infile->handle);
1722 AR.infile->handle = -1;
1723 remove(AR.infile->name);
1724 PUTZERO(AR.infile->POposition);
1726 AR.infile->POfill = AR.infile->POfull = AR.infile->PObuffer;
1728 if ( AR.outtohide ) AR.outfile = AR.hidefile;
1730 if (
EndSort(BHEAD AM.S0->sBuffer,0) < 0 )
return(-1);
1732 if ( AR.outtohide ) {
1733 AR.outfile = oldoutfile;
1734 AR.hidefile->POfull = AR.hidefile->POfill;
1737 AR.BracketOn = oldBracketOn;
1738 AT.BrackBuf = oldBrackBuf;
1739 if ( ( e->vflags & TOBEFACTORED ) != 0 )
1741 else if ( ( ( e->vflags & TOBEUNFACTORED ) != 0 )
1742 && ( ( e->vflags & ISFACTORIZED ) != 0 ) )
1744 AT.bracketindexflag = oldbracketindexflag;
1755 DBGOUT_NINTERMS(1, (
"PF.me=%d AN.ninterms=%d ENDSORT\n", (
int)PF.me, (
int)AN.ninterms));
1756 PF_CatchErrorMessagesForAll();
1758 for ( k = 1; k < PF.numtasks; k++ ) {
1762 WORD numdummies, expchanged;
1765 if ( e->numdummies < numdummies ) e->numdummies = numdummies;
1766 AR.expchanged |= expchanged;
1769 if ( AC.numpfirstnum > 0 ) PF_UnpackRedefinedPreVars();
1771 if ( ! AC.OldParallelStats ) {
1774 for ( k = 1; k < PF.numtasks; k++ ) {
1775 genterms += PF_stats[k][3];
1777 AT.SS->GenTerms = genterms;
1779 Expressions[AR.CurExpr].size = PF_exprsize;
1781 PF_Statistics(PF_stats,0);
1786 if ( AM.S0->TermsLeft ) e->vflags &= ~ISZERO;
1787 else e->vflags |= ISZERO;
1788 if ( AR.expchanged == 0 ) e->vflags |= ISUNMODIFIED;
1789 if ( AM.S0->TermsLeft ) AR.expflags |= ISZERO;
1790 if ( AR.expchanged ) AR.expflags |= ISUNMODIFIED;
1806 WORD oldBracketOn = AR.BracketOn;
1807 WORD *oldBrackBuf = AT.BrackBuf;
1808 WORD oldbracketindexflag = AT.bracketindexflag;
1811 if ( AC.numpfirstnum > 0 ) {
1812 for ( j = 0; j < AC.numpfirstnum; j++ ) {
1813 AC.inputnumbers[j] = -1;
1817 SeekScratch(AR.outfile,&position);
1818 e->onfile = position;
1819 AR.DeferFlag = AC.ComDefer;
1821 if ( ( e->vflags & ISFACTORIZED ) != 0 ) {
1823 AT.BrackBuf = AM.BracketFactors;
1824 AT.bracketindexflag = 1;
1827 AR.MaxDum = AM.IndDum;
1832 AR.infile->POfull = AR.infile->POfill = AR.infile->PObuffer = PF_shared_buff;
1835 FILEHANDLE *fi = AC.RhsExprInModuleFlag && PF.rhsInParallel ? &PF.slavebuf : AR.infile;
1836 fi->POfull = fi->POfill = fi->PObuffer;
1840 while ( PF_GetTerm(term) ) {
1841 PF_linterms++; AN.ninterms++; dd = AN.deferskipped;
1842 AT.WorkPointer = term + *term;
1843 AN.RepPoint = AT.RepCount + 1;
1844 if ( ( e->vflags & ISFACTORIZED ) != 0 && term[1] == HAAKJE ) {
1848 if ( AR.DeferFlag ) {
1849 AR.CurDum = AN.IndDum = Expressions[AR.CurExpr].numdummies + AM.IndDum;
1852 AN.IndDum = AM.IndDum;
1853 AR.CurDum = ReNumber(BHEAD term);
1855 if ( AC.SymChangeFlag ) MarkDirty(term,DIRTYSYMFLAG);
1857 if ( ( AC.modmode & ALSOFUNARGS ) != 0 ) MarkDirty(term,DIRTYFLAG);
1858 else if ( AR.PolyFun ) PolyFunDirty(BHEAD term);
1860 else if ( AC.PolyRatFunChanged ) PolyFunDirty(BHEAD term);
1861 if ( ( AR.PolyFunType == 2 ) && ( AC.PolyRatFunChanged == 0 )
1862 && ( e->status == LOCALEXPRESSION || e->status == GLOBALEXPRESSION ) ) {
1863 PolyFunClean(BHEAD term);
1866 MesPrint(
"[%d] PF_Processor: Error in Generator",PF.me);
1869 PF_linterms += dd; AN.ninterms += dd;
1871 PF_linterms += dd; AN.ninterms += dd;
1887 WORD *oldbuff = fout->PObuffer;
1888 WORD *oldstop = fout->POstop;
1889 LONG oldsize = fout->POsize;
1890 if (
EndSort(BHEAD AM.S0->sBuffer, 0) < 0 )
return -1;
1891 fout->PObuffer = oldbuff;
1892 fout->POstop = oldstop;
1893 fout->POsize = oldsize;
1894 fout->POfill = fout->POfull = fout->PObuffer;
1896 AR.BracketOn = oldBracketOn;
1897 AT.BrackBuf = oldBrackBuf;
1898 AT.bracketindexflag = oldbracketindexflag;
1903 DBGOUT_NINTERMS(1, (
"PF.me=%d AN.ninterms=%d PF_linterms=%d ENDSORT\n", (
int)PF.me, (
int)AN.ninterms, (
int)PF_linterms));
1913 WORD numdummies = AR.MaxDum - AM.IndDum;
1918 if ( AC.numpfirstnum > 0 ) PF_PackRedefinedPreVars();
1930 NumToStr(lbuf,AC.CModule);
1931 fprintf(stderr,
"[%d|%s] Endsort,Collect,Broadcast done\n",PF.me,lbuf);
1958 PF_CurrentBracket = 0;
1969 PF_statsinterval = 10;
1971 PF.exprbufsize=4096;
1974 if ( PF.me == MASTER ) {
1979 if ( ( c = getenv(
"PF_LOG") ) != 0 ) {
1980 if ( *c ) PF.log = (int)atoi(c);
1982 fprintf(stderr,
"[%d] changing PF.log to %d\n",PF.me,PF.log);
1985 if ( ( c = (
char*)getenv(
"PF_RBUFS") ) != 0 ) {
1986 PF.numrbufs = (int)atoi(c);
1987 fprintf(stderr,
"[%d] changing numrbufs to: %d\n",PF.me,PF.numrbufs);
1990 if ( ( c = (
char*)getenv(
"PF_SBUFS") ) != 0 ) {
1991 PF.numsbufs = (int)atoi(c);
1992 fprintf(stderr,
"[%d] changing numsbufs to: %d\n",PF.me,PF.numsbufs);
1995 if ( PF.numsbufs > 10 ) PF.numsbufs = 10;
1996 if ( PF.numsbufs < 1 ) PF.numsbufs = 1;
1997 if ( PF.numrbufs > 2 ) PF.numrbufs = 2;
1998 if ( PF.numrbufs < 1 ) PF.numrbufs = 1;
2000 if ( ( c = getenv(
"PF_STATS") ) ) {
2002 PF_statsinterval = (int)atoi(c);
2003 NumToStr(lbuf,PF_statsinterval);
2004 fprintf(stderr,
"[%d] changing PF_statsinterval to %s\n",PF.me,lbuf);
2006 if ( PF_statsinterval < 1 ) PF_statsinterval = 10;
2013 if ( PF.me == MASTER ) {
2016 PF_Pack(&PF.numrbufs,1,PF_WORD);
2017 PF_Pack(&PF.numsbufs,1,PF_WORD);
2020 if ( PF.me != MASTER ) {
2025 fprintf(stderr,
"[%d] log=%d rbufs=%d sbufs=%d\n",
2026 PF.me, PF.log, PF.numrbufs, PF.numsbufs);
2065 LONG slavetimes = 0;
2066 LONG t = PF.me == MASTER ? 0 : AM.SumTime +
TimeCPU(1);
2067 MPI_Reduce(&t, &slavetimes, 1, PF_LONG, MPI_SUM, MASTER, PF_COMM);
2085#ifdef PF_DEBUG_BCAST_LONG
2086 if ( PF.me == MASTER ) {
2087 MesPrint(
">> Broadcast LONG: %l", x);
2114#ifdef PF_DEBUG_BCAST_BUF
2115 if ( PF.me == MASTER ) {
2116 MesPrint(
">> Broadcast Buffer: length=%l", *length);
2120 if ( PF.me != MASTER ) {
2125 if ( *length <= 0 )
return;
2127 if ( PF.me != MASTER ) {
2128 *buffer = (WORD *)Malloc1(*length *
sizeof(WORD),
"PF_BroadcastBuffer");
2133 while ( rest > 0 ) {
2134 int l = rest < (LONG)PF.exprbufsize ? (
int)rest : PF.exprbufsize;
2167 if ( MASTER == PF.me ) {
2176 if ( MASTER != PF.me ) {
2183 }
while ( cstr[clength-1] !=
'\0' );
2215 if ( MASTER == PF.me ) {
2221 LONG n = ((*newsize)+1)/PF_maxDollarChunkSize;
2233 WORD *thechunk = *dbuffer;
2236 err |=
PF_Pack(numterms,1,PF_INT);
2237 err |=
PF_Pack(newsize,1,PF_LONG);
2242 for ( i = 0; i < n; i++ ) {
2243 err |=
PF_Pack(thechunk,PF_maxDollarChunkSize,PF_WORD);
2245 thechunk +=PF_maxDollarChunkSize;
2251 if ( ( n = ( (*newsize)+1)%PF_maxDollarChunkSize ) != 0 ) {
2252 err |=
PF_Pack(thechunk,n,PF_WORD);
2255#ifdef PF_DEBUG_BCAST_PREDOLLAR
2256 MesPrint(
">> Broadcast PreDollar: newsize=%d numterms=%d", (
int)*newsize, *numterms);
2259 if ( MASTER != PF.me ) {
2261 LONG n, therest, thesize;
2268 thesize = (*newsize)+1;
2273 n = (thesize/PF_maxDollarChunkSize) - 1;
2277 therest = thesize % PF_maxDollarChunkSize;
2278 thechunk = *dbuffer =
2279 (WORD*)Malloc1( thesize *
sizeof(WORD),
"$-buffer slave");
2280 if ( thechunk == NULL )
return(err|4);
2285 for ( i = 0; i < n; i++ ) {
2286 err |=
PF_Unpack(thechunk,PF_maxDollarChunkSize,PF_WORD);
2287 thechunk += PF_maxDollarChunkSize;
2294 err |=
PF_Unpack(thechunk,PF_maxDollarChunkSize,PF_WORD);
2295 thechunk += PF_maxDollarChunkSize;
2301 if ( therest != 0 ) err |=
PF_Unpack(thechunk,therest,PF_WORD);
2316static inline LONG dollarlen(
const WORD *terms)
2318 const WORD *p = terms;
2319 while ( *p ) p += *p;
2332static inline WORD dollar_mod_type(WORD index)
2335 for ( i = 0; i < NumModOptdollars; i++ )
2336 if ( ModOptdollars[i].number == index )
break;
2337 if ( i >= NumModOptdollars )
return -1;
2338 return ModOptdollars[i].type;
2356static inline int dollar_to_be_collected(WORD index)
2358 switch ( dollar_mod_type(index) ) {
2377static inline void copy_dollar(WORD index, WORD type,
const WORD *where, LONG size)
2379 DOLLARS d = Dollars + index;
2381 CleanDollarFactors(d);
2383 if ( type != DOLZERO && where != NULL && where != &AM.dollarzero && where[0] != 0 && size > 0 ) {
2384 if ( size > d->size || size < d->size / 4 ) {
2385 if ( d->where && d->where != &AM.dollarzero )
2386 M_free(d->where,
"old content of dollar");
2387 d->where = Malloc1(
sizeof(WORD) * size,
"copy buffer to dollar");
2391 WCOPY(d->where, where, size);
2394 if ( d->where && d->where != &AM.dollarzero )
2395 M_free(d->where,
"old content of dollar");
2397 d->where = &AM.dollarzero;
2411static inline int compare_two_expressions(
const WORD *e1,
const WORD *e2)
2430 else if ( e2[e2[0]] == 0 && e2[0] == ABS(e2[e2[0] - 1]) + 1 ) {
2431 if ( e2[e2[0] - 1] > 0 )
2437 else if ( e1[e1[0]] == 0 && e1[0] == ABS(e1[e1[0] - 1]) + 1 ) {
2439 if ( e1[e1[0] - 1] > 0 )
2444 else if ( e2[e2[0]] == 0 && e2[0] == ABS(e2[e2[0] - 1]) + 1 ) {
2445 return(
CompCoef((WORD *)e1, (WORD *)e2));
2449 while ( e1[0] && e2[0] ) {
2450 int c = CompareTerms((WORD *)e1, (WORD *)e2, 1);
2458 if ( e1[0] )
return(+1);
2459 if ( e2[0] )
return(-1);
2472 PADPOINTER(1,0,1,0);
2502 if ( AC.mparallelflag != PARALLELFLAG && !AC.partodoflag )
return 0;
2508 for ( i = 0; i < NumPotModdollars; i++ ) {
2509 WORD index = PotModdollars[i];
2510 if ( dollar_to_be_collected(index) ) ndollars++;
2512 if ( ndollars == 0 )
return 0;
2514 if ( PF.me == MASTER ) {
2520 int nbufs = ndollars * (PF.numtasks - 1);
2522 for ( i =
VectorSize(dollar_slave_bufs); i < nbufs; i++ ) {
2527 for ( nslaves = 1; nslaves < PF.numtasks; nslaves++ ) {
2531 for ( i = 0; i < NumPotModdollars; i++ ) {
2532 WORD index = PotModdollars[i];
2534 if ( !dollar_to_be_collected(index) )
continue;
2535 b = &
VectorPtr(dollar_slave_bufs)[(PF.numtasks - 1) * nvars + (src - 1)];
2537 if ( b->type != DOLZERO ) {
2563 for ( i = 0; i < NumPotModdollars; i++ ) {
2564 WORD index = PotModdollars[i];
2568 if ( !dollar_to_be_collected(index) )
continue;
2569 d = Dollars + index;
2570 b = &
VectorPtr(dollar_slave_bufs)[(PF.numtasks - 1) * nvars];
2571 dtype = dollar_mod_type(index);
2579 for ( j = 1; j < PF.numtasks - 1; j++ ) {
2581 if ( (dtype == MODMAX && c > 0) || (dtype == MODMIN && c < 0) )
2585 copy_dollar(index, b->type,
VectorPtr(b->buf), b->size);
2598 CBUF *C = cbuf + AM.rbufnum;
2599 WORD *oldwork = AT.WorkPointer, *oldcterm = AN.cTerm;
2600 WORD olddefer = AR.DeferFlag, oldnumlhs = AR.Cnumlhs, oldnumrhs = C->numrhs;
2608 if ( ((WORD *)((UBYTE *)AT.WorkPointer + AM.MaxTer)) > AT.WorkTop ) {
2629 for ( j = 0; j < PF.numtasks; j++ ) {
2631 for ( r = j == 0 ? Dollars[index].where :
VectorPtr(b[j - 1].buf); *r; r += *r ) {
2632 WCOPY(AT.WorkPointer, r, *r);
2633 AT.WorkPointer += *r;
2640 AT.WorkPointer = oldwork;
2644 size =
EndSort(BHEAD (WORD *)&dbuf, 2);
2654 if ( dbuf[0] == 0 ) {
2657 else if ( dbuf[dbuf[0]] == 0 ) {
2658 const WORD *t = dbuf, *w;
2662 if ( nsize < 0 ) nsize = -nsize;
2663 if ( nsize == n - 1 ) {
2664 nsize = (nsize - 1) / 2;
2667 w++;
while ( w < t + n - 1 ) {
if ( *w )
break; w++; }
2668 if ( w >= t + n - 1 ) type = DOLNUMBER;
2670 else if ( n == 7 && t[6] == 3 && t[5] == 1 && t[4] == 1 && t[1] == INDEX && t[2] == 3 ) {
2676 copy_dollar(index, type, dbuf, dollarlen(dbuf) + 1);
2677 M_free(dbuf,
"temporary dollar buffer");
2679 AR.Cnumlhs = oldnumlhs;
2680 C->numrhs = oldnumrhs;
2681 AR.DeferFlag = olddefer;
2682 AN.cTerm = oldcterm;
2683 AT.WorkPointer = oldwork;
2685 if ( err )
return err;
2692 if ( d->type == DOLTERMS )
2693 cbuf[AM.dbufnum].CanCommu[index] = numcommute(d->where, &cbuf[AM.dbufnum].NumTerms[index]);
2694 cbuf[AM.dbufnum].rhs[index] = d->where;
2696#ifdef PF_DEBUG_REDUCE_DOLLAR
2697 MesPrint(
"<< Reduce $-var: %s", AC.dollarnames->namebuffer + d->name);
2710 for ( i = 0; i < NumPotModdollars; i++ ) {
2711 WORD index = PotModdollars[i];
2713 if ( !dollar_to_be_collected(index) )
continue;
2714 d = Dollars + index;
2716 if ( d->type != DOLZERO ) {
2721 LONG size = dollarlen(d->where);
2748static inline int dollar_to_be_broadcast(WORD index)
2750 switch ( dollar_mod_type(index) ) {
2782 for ( i = 0; i < NumPotModdollars; i++ ) {
2783 WORD index = PotModdollars[i];
2784 if ( dollar_to_be_broadcast(index) ) ndollars++;
2786 if ( ndollars == 0 )
return 0;
2788 if ( PF.me == MASTER ) {
2794 for ( i = 0; i < NumPotModdollars; i++ ) {
2795 WORD index = PotModdollars[i];
2797 if ( !dollar_to_be_broadcast(index) )
continue;
2798 d = Dollars + index;
2799 PF_LongMultiPack(&d->type, 1, PF_WORD);
2800 if ( d->type != DOLZERO ) {
2805 LONG size = dollarlen(d->where);
2806 PF_LongMultiPack(&size, 1, PF_LONG);
2807 PF_LongMultiPack(d->where, size, PF_WORD);
2809 PF_LongMultiPack(&d->nfactors, 1, PF_WORD);
2810 if ( d->nfactors > 1 ) {
2811 for ( j = 0; j < d->nfactors; j++ ) {
2812 FACDOLLAR *f = &d->factors[j];
2813 PF_LongMultiPack(&f->type, 1, PF_WORD);
2814 PF_LongMultiPack(&f->size, 1, PF_LONG);
2816 PF_LongMultiPack(f->where, f->size, PF_WORD);
2818 PF_LongMultiPack(&f->value, 1, PF_WORD);
2822#ifdef PF_DEBUG_BCAST_DOLLAR
2823 MesPrint(
">> Broadcast $-var: %s", AC.dollarnames->namebuffer + d->name);
2831 if ( PF.me != MASTER ) {
2835 for ( i = 0; i < NumPotModdollars; i++ ) {
2836 WORD index = PotModdollars[i];
2838 if ( !dollar_to_be_broadcast(index) )
continue;
2839 d = Dollars + index;
2841 if ( d->where && d->where != &AM.dollarzero )
2842 M_free(d->where,
"old content of dollar");
2843 d->where = &AM.dollarzero;
2845 CleanDollarFactors(d);
2847 PF_LongMultiUnpack(&d->type, 1, PF_WORD);
2848 if ( d->type != DOLZERO ) {
2850 PF_LongMultiUnpack(&size, 1, PF_LONG);
2852 d->where = (WORD *)Malloc1(
sizeof(WORD) * d->size,
"dollar content");
2853 PF_LongMultiUnpack(d->where, size, PF_WORD);
2856 PF_LongMultiUnpack(&d->nfactors, 1, PF_WORD);
2857 if ( d->nfactors > 1 ) {
2858 d->factors = (FACDOLLAR *)Malloc1(
sizeof(FACDOLLAR) * d->nfactors,
"dollar factored stuff");
2859 for ( j = 0; j < d->nfactors; j++ ) {
2860 FACDOLLAR *f = &d->factors[j];
2861 PF_LongMultiUnpack(&f->type, 1, PF_WORD);
2862 PF_LongMultiUnpack(&f->size, 1, PF_LONG);
2863 if ( f->size > 0 ) {
2864 f->where = (WORD *)Malloc1(
sizeof(WORD) * (f->size + 1),
"dollar factor content");
2865 PF_LongMultiUnpack(f->where, f->size, PF_WORD);
2866 f->where[f->size] = 0;
2871 PF_LongMultiUnpack(&f->value, 1, PF_WORD);
2876 if ( d->type == DOLTERMS )
2877 cbuf[AM.dbufnum].CanCommu[index] = numcommute(d->where, &cbuf[AM.dbufnum].NumTerms[index]);
2878 cbuf[AM.dbufnum].rhs[index] = d->where;
2895static Vector(UBYTE, prevarbuf);
2910static void PF_PackRedefinedPreVars(
void)
2915 for ( i = 0; i < AC.numpfirstnum; i++ )
2916 if ( AC.inputnumbers[i] >= 0 ) nredefs++;
2919 for ( i = 0; i < AC.numpfirstnum; i++ )
2920 if ( AC.inputnumbers[i] >= 0) {
2921 WORD index = AC.pfirstnum[i];
2922 UBYTE *value = PreVar[index].value;
2923 int bytes = strlen((
char *)value);
2945static void PF_UnpackRedefinedPreVars(
void)
2951 if ( nredefs > 0 ) {
2953 for ( i = 0; i < nredefs; i++ ) {
2963 value[bytes] =
'\0';
2966 for ( j = 0; j < AC.numpfirstnum; j++ )
2967 if ( AC.pfirstnum[j] == index )
break;
2968 if ( AC.inputnumbers[j] < inputnumber ) {
2969 AC.inputnumbers[j] = inputnumber;
2970 PutPreVar(PreVar[index].name, value, NULL, 1);
2998 if ( PF.me == MASTER ) {
3006 for ( i = 0; i < AC.numpfirstnum; i++ )
3007 if ( AC.inputnumbers[i] >= 0 ) nredefs++;
3008 PF_LongMultiPack(&nredefs, 1, PF_INT);
3010 for ( i = 0; i < AC.numpfirstnum; i++ )
3011 if ( AC.inputnumbers[i] >= 0) {
3012 WORD index = AC.pfirstnum[i];
3013 UBYTE *value = PreVar[index].value;
3014 int bytes = strlen((
char *)value);
3015 PF_LongMultiPack(&index, 1, PF_WORD);
3016 PF_LongMultiPack(&bytes, 1, PF_INT);
3017 PF_LongMultiPack(value, bytes, PF_BYTE);
3018#ifdef PF_DEBUG_BCAST_PREVAR
3019 MesPrint(
">> Broadcast PreVar: %s = \"%s\"", PreVar[index].name, value);
3027 if ( PF.me != MASTER ) {
3033 PF_LongMultiUnpack(&nredefs, 1, PF_INT);
3034 if ( nredefs > 0 ) {
3036 for ( i = 0; i < nredefs; i++ ) {
3040 PF_LongMultiUnpack(&index, 1, PF_WORD);
3041 PF_LongMultiUnpack(&bytes, 1, PF_INT);
3044 PF_LongMultiUnpack(value, bytes, PF_BYTE);
3045 value[bytes] =
'\0';
3046 PutPreVar(PreVar[index].name, value, NULL, 1);
3064static WORD oldRhsExprInModuleFlag;
3065static Vector(WORD, oldPotModdollars);
3066static Vector(WORD, oldpfirstnum);
3081int PF_StoreInsideInfo(
void)
3084 oldRhsExprInModuleFlag = AC.RhsExprInModuleFlag;
3086 for ( i = 0; i < NumPotModdollars; i++ )
3089 for ( i = 0; i < AC.numpfirstnum; i++ )
3107int PF_RestoreInsideInfo(
void)
3110 AC.RhsExprInModuleFlag = oldRhsExprInModuleFlag;
3111 NumPotModdollars =
VectorSize(oldPotModdollars);
3112 for ( i = 0; i < NumPotModdollars; i++ )
3113 PotModdollars[i] =
VectorPtr(oldPotModdollars)[i];
3115 for ( i = 0; i < AC.numpfirstnum; i++ )
3116 AC.pfirstnum[i] =
VectorPtr(oldpfirstnum)[i];
3135 CBUF *C = cbuf + bufnum;
3138 if ( PF.me == MASTER ) {
3144 PF_LongMultiPack(&C->
BufferSize, 1, PF_LONG);
3145 PF_LongMultiPack(&C->numlhs, 1, PF_INT);
3146 PF_LongMultiPack(&C->numrhs, 1, PF_INT);
3147 PF_LongMultiPack(&C->maxlhs, 1, PF_INT);
3148 PF_LongMultiPack(&C->maxrhs, 1, PF_INT);
3149 PF_LongMultiPack(&C->mnumlhs, 1, PF_INT);
3150 PF_LongMultiPack(&C->mnumrhs, 1, PF_INT);
3151 PF_LongMultiPack(&C->numtree, 1, PF_INT);
3152 PF_LongMultiPack(&C->rootnum, 1, PF_INT);
3153 PF_LongMultiPack(&C->MaxTreeSize, 1, PF_INT);
3156 PF_LongMultiPack(&l, 1, PF_LONG);
3157 PF_LongMultiPack(C->
Buffer, l, PF_WORD);
3158 for ( i = 0; i < C->numlhs + 1; i++ ) {
3160 PF_LongMultiPack(&l, 1, PF_LONG);
3162 for ( i = 0; i < C->numrhs + 1; i++ ) {
3164 PF_LongMultiPack(&l, 1, PF_LONG);
3166 PF_LongMultiPack(C->
CanCommu, C->numrhs + 1, PF_LONG);
3167 PF_LongMultiPack(C->
NumTerms, C->numrhs + 1, PF_LONG);
3168 PF_LongMultiPack(C->
numdum, C->numrhs + 1, PF_WORD);
3169 PF_LongMultiPack(C->
dimension, C->numrhs + 1, PF_WORD);
3170 if ( C->MaxTreeSize > 0 )
3171 PF_LongMultiPack(C->
boomlijst, (C->numtree + 1) * (
sizeof(
COMPTREE) /
sizeof(
int)), PF_INT);
3172#ifdef PF_DEBUG_BCAST_CBUF
3173 MesPrint(
">> Broadcast CBuf %d", bufnum);
3180 if ( PF.me != MASTER ) {
3187 PF_LongMultiUnpack(&C->
BufferSize, 1, PF_LONG);
3188 PF_LongMultiUnpack(&C->numlhs, 1, PF_INT);
3189 PF_LongMultiUnpack(&C->numrhs, 1, PF_INT);
3190 PF_LongMultiUnpack(&C->maxlhs, 1, PF_INT);
3191 PF_LongMultiUnpack(&C->maxrhs, 1, PF_INT);
3192 PF_LongMultiUnpack(&C->mnumlhs, 1, PF_INT);
3193 PF_LongMultiUnpack(&C->mnumrhs, 1, PF_INT);
3194 PF_LongMultiUnpack(&C->numtree, 1, PF_INT);
3195 PF_LongMultiUnpack(&C->rootnum, 1, PF_INT);
3196 PF_LongMultiUnpack(&C->MaxTreeSize, 1, PF_INT);
3198 C->
Buffer = (WORD *)Malloc1(C->
BufferSize *
sizeof(WORD),
"compiler buffer");
3200 C->
lhs = (WORD **)Malloc1(C->maxlhs *
sizeof(WORD *),
"compiler buffer");
3201 C->
rhs = (WORD **)Malloc1(C->maxrhs * (
sizeof(WORD *) + 2 *
sizeof(LONG) + 2 *
sizeof(WORD)),
"compiler buffer");
3206 if ( C->MaxTreeSize > 0 )
3209 PF_LongMultiUnpack(&l, 1, PF_LONG);
3210 PF_LongMultiUnpack(C->
Buffer, l, PF_WORD);
3212 for ( i = 0; i < C->numlhs + 1; i++ ) {
3213 PF_LongMultiUnpack(&l, 1, PF_LONG);
3216 for ( i = 0; i < C->numrhs + 1; i++ ) {
3217 PF_LongMultiUnpack(&l, 1, PF_LONG);
3220 PF_LongMultiUnpack(C->
CanCommu, C->numrhs + 1, PF_LONG);
3221 PF_LongMultiUnpack(C->
NumTerms, C->numrhs + 1, PF_LONG);
3222 PF_LongMultiUnpack(C->
numdum, C->numrhs + 1, PF_WORD);
3223 PF_LongMultiUnpack(C->
dimension, C->numrhs + 1, PF_WORD);
3224 if ( C->MaxTreeSize > 0 )
3225 PF_LongMultiUnpack(C->
boomlijst, (C->numtree + 1) * (
sizeof(
COMPTREE) /
sizeof(
int)), PF_INT);
3248 if ( PF.me == MASTER ) {
3253 PF_LongMultiPack(&AR.expflags, 1, PF_WORD);
3254 for ( i = 0; i < NumExpressions; i++ ) {
3255 e = &Expressions[i];
3256 PF_LongMultiPack(&e->counter, 1, PF_WORD);
3257 PF_LongMultiPack(&e->vflags, 1, PF_WORD);
3258 PF_LongMultiPack(&e->numdummies, 1, PF_WORD);
3259 PF_LongMultiPack(&e->numfactors, 1, PF_WORD);
3260#ifdef PF_DEBUG_BCAST_EXPRFLAGS
3261 MesPrint(
">> Broadcast ExprFlags: %s", AC.exprnames->namebuffer + e->name);
3269 if ( PF.me != MASTER ) {
3273 PF_LongMultiUnpack(&AR.expflags, 1, PF_WORD);
3274 for ( i = 0; i < NumExpressions; i++ ) {
3275 e = &Expressions[i];
3276 PF_LongMultiUnpack(&e->counter, 1, PF_WORD);
3277 PF_LongMultiUnpack(&e->vflags, 1, PF_WORD);
3278 PF_LongMultiUnpack(&e->numdummies, 1, PF_WORD);
3279 PF_LongMultiUnpack(&e->numfactors, 1, PF_WORD);
3299static void PF_SetScratch(
FILEHANDLE *f,POSITION *position)
3302 ( f->
handle >= 0) && ISGEPOS(*position,f->POposition) &&
3303 ( ISGEPOSINC(*position,f->POposition,(f->POfull-f->PObuffer)*
sizeof(WORD)) ==0 )
3305 f->POfull=f->PObuffer;
3306 SetScratch(f,position);
3325 if ( ( RetCode = CreateFile(f->name) ) >= 0 ) {
3326 f->
handle = (WORD)RetCode;
3327 PUTZERO(f->filesize);
3328 PUTZERO(f->POposition);
3331 MesPrint(
"Cannot create scratch file %s",f->name);
3335 size = (f->POfill-f->PObuffer)*
sizeof(WORD);
3337 SeekFile(f->
handle,&(f->POposition),SEEK_SET);
3338 if ( WriteFile(f->
handle,(UBYTE *)(f->PObuffer),size) != size ){
3339 MesPrint(
"Error while writing to disk. Disk full?");
3342 ADDPOS(f->filesize,size);
3343 ADDPOS(f->POposition,size);
3344 f->POfill = f->POfull=f->PObuffer;
3356static int PF_WalkThroughExprMaster(
FILEHANDLE *curfile,
int dl)
3360 if(curfile->POfull-curfile->POfill < dl){
3362 SeekScratch(curfile,&pos);
3363 PF_SetScratch(curfile,&pos);
3365 curfile->POfill+=dl;
3367 if( l >= PF.exprbufsize){
3368 if( l == PF.exprbufsize){
3369 if( *(curfile->POfill) == 0)
3377 dl=*(curfile->POfill);
3379 return l-PF.exprbufsize;
3382 if(curfile->POfull-curfile->POfill < 1){
3384 SeekScratch(curfile,&pos);
3385 PF_SetScratch(curfile,&pos);
3387 dl=*(curfile->POfill+1)+2;
3398static int PF_WalkThroughExprSlave(
FILEHANDLE *curfile, LONG *counter,
int dl)
3402 if(curfile->POstop-curfile->POfill < dl){
3403 if(PF_pushScratch(curfile))
3404 return(-PF.exprbufsize-1);
3406 curfile->POfill+=dl;
3407 curfile->POfull=curfile->POfill;
3409 if( l >= PF.exprbufsize){
3410 if( l == PF.exprbufsize){
3415 if( *(curfile->POfill) == 0)
3420 curfile->POfull=curfile->POfill;
3424 dl=*(curfile->POfill);
3426 return l-PF.exprbufsize;
3429 if(curfile->POstop-curfile->POfill < 1){
3430 if(PF_pushScratch(curfile))
3431 return(-PF.exprbufsize-1);
3437 dl=*(curfile->POfill+1)+2;
3454static int PF_rhsBCastMaster(
FILEHANDLE *curfile, EXPRESSIONS e)
3457 SetScratch(curfile,&(e->onfile));
3464 if ( curfile->POfull - curfile->POfill < PF.exprbufsize + 1 ) {
3466 SeekScratch(curfile,&pos);
3467 PF_SetScratch(curfile,&pos);
3469 if (
PF_Bcast(curfile->POfill, (PF.exprbufsize + 1) *
sizeof(WORD)) )
3471 l=PF_WalkThroughExprMaster(curfile,l-1);
3491static int PF_rhsBCastSlave(
FILEHANDLE *curfile, EXPRESSIONS e)
3501 if ( curfile->POstop - curfile->POfill < PF.exprbufsize + 1 ) {
3502 if(PF_pushScratch(curfile))
3505 if (
PF_Bcast(curfile->POfill, (PF.exprbufsize + 1) *
sizeof(WORD)) )
3507 l = PF_WalkThroughExprSlave(curfile, &counter, l - 1);
3510 if(l<-PF.exprbufsize)
3514 if ( curfile->
handle >= 0 ) {
3515 if ( PF_pushScratch(curfile) )
return -1;
3517 curfile->POfull=curfile->POfill;
3518 if ( curfile != AR.hidefile ) AR.InInBuf = curfile->POfull-curfile->PObuffer;
3519 else AR.InHiBuf = curfile->POfull-curfile->PObuffer;
3520 CHECK(counter == e->counter + 1);
3538 if ( PF.me == MASTER ) {
3539 if ( PF_rhsBCastMaster(file, e) )
return -1;
3540#ifdef PF_DEBUG_BCAST_RHSEXPR
3541 MesPrint(
">> Broadcast RhsExpr: %s", AC.exprnames->namebuffer + e->name);
3546 SetEndHScratch(file, &pos);
3548 if ( PF_rhsBCastSlave(file, e) )
return -1;
3567 for ( i = 0; i < NumExpressions; i++ ) {
3568 EXPRESSIONS e = &Expressions[i];
3569 if ( !(e->vflags & ISINRHS) )
continue;
3570 switch ( e->status ) {
3571 case LOCALEXPRESSION:
3572 case SKIPLEXPRESSION:
3573 case DROPLEXPRESSION:
3574 case GLOBALEXPRESSION:
3575 case SKIPGEXPRESSION:
3576 case DROPGEXPRESSION:
3577 case HIDELEXPRESSION:
3578 case HIDEGEXPRESSION:
3579 case INTOHIDELEXPRESSION:
3580 case INTOHIDEGEXPRESSION:
3583 case HIDDENLEXPRESSION:
3584 case HIDDENGEXPRESSION:
3585 case DROPHLEXPRESSION:
3586 case DROPHGEXPRESSION:
3587 case UNHIDELEXPRESSION:
3588 case UNHIDEGEXPRESSION:
3593 if ( PF.me != MASTER )
3620 if ( PF.numtasks >= 3 ) {
3621 for ( i = 0; i < NumExpressions; i++ ) {
3622 e = Expressions + i;
3623 if ( e->partodo > 0 && e->counter == 0 ) {
3628 if(PF.me == MASTER){
3629 if ( PF.numtasks >= 3 ) {
3630 partodoexr = (WORD*)Malloc1(
sizeof(WORD)*(PF.numtasks+1),
"PF_InParallelProcessor");
3631 for ( i = 0; i < NumExpressions; i++ ) {
3633 if ( e->partodo <= 0 )
continue;
3635 case LOCALEXPRESSION:
3636 case GLOBALEXPRESSION:
3637 case UNHIDELEXPRESSION:
3638 case UNHIDEGEXPRESSION:
3639 case INTOHIDELEXPRESSION:
3640 case INTOHIDEGEXPRESSION:
3642 next=PF_Wait4SlaveIP(&tag);
3645 if(tag == PF_DATA_MSGTAG){
3646 PF_Statistics(PF_stats,0);
3647 if(PF_Slave2MasterIP(next))
3650 if(PF_Master2SlaveIP(next,e))
3663 if(PF_WaitAllSlaves())
3666 if ( AC.CollectFun ) AR.DeferFlag = 0;
3668 M_free(partodoexr,
"PF_InParallelProcessor");
3673 for ( i = 0; i < NumExpressions; i++ ) {
3674 Expressions[i].partodo = 0;
3680 if(PF_Wait4MasterIP(PF_EMPTY_MSGTAG))
3684 WORD *oldwork= AT.WorkPointer;
3685 tag=PF_ReadMaster();
3688 if(tag == PF_DATA_MSGTAG){
3689 oldwork = AT.WorkPointer;
3692 if ( AC.numpfirstnum > 0 ) {
3694 for ( j = 0; j < AC.numpfirstnum; j++ ) {
3695 AC.inputnumbers[j] = -1;
3701 if(PF_Wait4MasterIP(PF_DATA_MSGTAG))
3703 if(PF_Slave2MasterIP(PF.me))
3705 AT.WorkPointer=oldwork;
3707 }
while(tag!=PF_EMPTY_MSGTAG);
3717static int PF_Wait4MasterIP(
int tag)
3723 fprintf(stderr,
"[%d] Starting to send to Master\n",PF.me);
3731 PF_Pack(&PF_linterms ,1,PF_LONG);
3732 PF_Pack(&(AM.S0->GenTerms) ,1,PF_LONG);
3733 PF_Pack(&(AM.S0->TermsLeft),1,PF_LONG);
3737 fprintf(stderr,
"[%d] Now sending with tag = %d\n",PF.me,tag);
3744 fprintf(stderr,
"[%d] returning from send\n",PF.me);
3761static int PF_DoOneExpr(
void)
3767 POSITION position, outposition;
3770 WORD oldBracketOn = AR.BracketOn;
3771 WORD *oldBrackBuf = AT.BrackBuf;
3772 WORD oldbracketindexflag = AT.bracketindexflag;
3773 e = Expressions + PF.exprtodo;
3776 AR.SortType = AC.SortType;
3778 if ( ( e->vflags & ISFACTORIZED ) != 0 ) {
3780 AT.BrackBuf = AM.BracketFactors;
3781 AT.bracketindexflag = 1;
3784 position = AS.OldOnFile[i];
3785 if ( e->status == HIDDENLEXPRESSION || e->status == HIDDENGEXPRESSION ) {
3786 AR.GetFile = 2; fi = AR.hidefile;
3789 AR.GetFile = 0; fi = AR.infile;
3797 SetScratch(fi,&position);
3798 term = AT.WorkPointer;
3799 AR.CompressPointer = AR.CompressBuffer;
3800 AR.CompressPointer[0] = 0;
3802 if ( GetTerm(BHEAD term) <= 0 ) {
3803 MesPrint(
"Expression %d has problems in scratchfile",i);
3806 if ( AT.bracketindexflag > 0 ) OpenBracketIndex(i);
3808 PUTZERO(outposition);
3810 fout->POfill = fout->POfull = fout->PObuffer;
3811 fout->POposition = outposition;
3812 if ( fout->
handle >= 0 ) {
3813 fout->POposition = outposition;
3825 if (
PutOut(BHEAD term,&outposition,fout,0) < 0 )
return -1;
3827 AR.DeferFlag = AC.ComDefer;
3830 term = AT.WorkPointer;
3832 AR.MaxDum = AM.IndDum;
3834 while ( GetTerm(BHEAD term) ) {
3835 SeekScratch(fi,&position);
3836 AN.ninterms++; dd = AN.deferskipped;
3837 if ( ( e->vflags & ISFACTORIZED ) != 0 && term[1] == HAAKJE ) {
3841 if ( AC.CollectFun && *term <= (AM.MaxTer/(2*(LONG)
sizeof(WORD))) ) {
3842 if ( GetMoreTerms(term) < 0 ) {
3845 SeekScratch(fi,&position);
3847 AT.WorkPointer = term + *term;
3848 AN.RepPoint = AT.RepCount + 1;
3849 if ( AR.DeferFlag ) {
3850 AR.CurDum = AN.IndDum = Expressions[PF.exprtodo].numdummies;
3853 AN.IndDum = AM.IndDum;
3854 AR.CurDum = ReNumber(BHEAD term);
3856 if ( AC.SymChangeFlag ) MarkDirty(term,DIRTYSYMFLAG);
3858 if ( ( AC.modmode & ALSOFUNARGS ) != 0 ) MarkDirty(term,DIRTYFLAG);
3859 else if ( AR.PolyFun ) PolyFunDirty(BHEAD term);
3861 else if ( AC.PolyRatFunChanged ) PolyFunDirty(BHEAD term);
3862 if ( ( AR.PolyFunType == 2 ) && ( AC.PolyRatFunChanged == 0 )
3863 && ( e->status == LOCALEXPRESSION || e->status == GLOBALEXPRESSION ) ) {
3864 PolyFunClean(BHEAD term);
3871 SetScratch(fi,&position);
3872 if ( fi == AR.hidefile ) {
3873 AR.InHiBuf = (fi->POfull-fi->PObuffer)
3874 -DIFBASE(position,fi->POposition)/
sizeof(WORD);
3877 AR.InInBuf = (fi->POfull-fi->PObuffer)
3878 -DIFBASE(position,fi->POposition)/
sizeof(WORD);
3882 if (
EndSort(BHEAD AM.S0->sBuffer,0) < 0 )
return(-1);
3883 e->numdummies = AR.MaxDum - AM.IndDum;
3884 AR.BracketOn = oldBracketOn;
3885 AT.BrackBuf = oldBrackBuf;
3886 if ( ( e->vflags & TOBEFACTORED ) != 0 )
3888 else if ( ( ( e->vflags & TOBEUNFACTORED ) != 0 )
3889 && ( ( e->vflags & ISFACTORIZED ) != 0 ) )
3891 if ( AM.S0->TermsLeft ) e->vflags &= ~ISZERO;
3892 else e->vflags |= ISZERO;
3893 if ( AR.expchanged == 0 ) e->vflags |= ISUNMODIFIED;
3897 AT.bracketindexflag = oldbracketindexflag;
3899 fout->POfull = fout->POfill;
3913static int PF_Slave2MasterIP(
int src)
3916 bufIPstruct_t exprData;
3923 if(PF.me != MASTER){
3924 e = Expressions + PF.exprtodo;
3926 memcpy(&(exprData.e), e,
sizeof(
struct ExPrEsSiOn));
3927 SeekScratch(fout,&pos);
3928 exprData.i=BASEPOSITION(pos);
3930 if(
PF_RawSend(MASTER,&exprData,
sizeof(bufIPstruct_t),0))
3933 SETBASEPOSITION(pos,0);
3935 int blen=PF.exprbufsize*
sizeof(WORD);
3938 l=PF_SendChunkIP(fout,&pos, MASTER, blen);
3945 if ( fout->
handle >= 0 ) {
3949 PUTZERO(fout->POposition);
3950 PUTZERO(fout->filesize);
3951 fout->POfill = fout->POfull = fout->PObuffer;
3954 if ( AC.numpfirstnum > 0 ) {
3956 PF_PackRedefinedPreVars();
3963 e = Expressions +partodoexr[src];
3965 if (
PF_RawRecv(&src, &exprData,
sizeof(bufIPstruct_t),&i)!=
sizeof(bufIPstruct_t))
3969 e->counter = exprData.e.counter;
3970 e->vflags = exprData.e.vflags;
3971 e->numdummies = exprData.e.numdummies;
3972 e->numfactors = exprData.e.numfactors;
3973 if ( !(e->vflags & ISZERO) ) AR.expflags |= ISZERO;
3974 if ( !(e->vflags & ISUNMODIFIED) ) AR.expflags |= ISUNMODIFIED;
3975 SeekScratch(fout,&pos);
3979 int blen=PF.exprbufsize*
sizeof(WORD);
3982 l=PF_RecvChunkIP(fout,src,blen);
3989 if ( AC.numpfirstnum > 0 ) {
3991 PF_UnpackRedefinedPreVars();
4001static int PF_Master2SlaveIP(
int dest, EXPRESSIONS e)
4003 bufIPstruct_t exprData;
4010 if(
PF_RawSend(dest,&exprData,
sizeof(bufIPstruct_t),PF_EMPTY_MSGTAG))
4014 memcpy(&(exprData.e), e,
sizeof(
struct ExPrEsSiOn));
4015 exprData.i=e-Expressions;
4016 if ( AC.StatsFlag && AC.OldParallelStats ) {
4018 MesPrint(
" Sending expression %s to slave %d",EXPRNAME(exprData.i),dest);
4020 if(
PF_RawSend(dest,&exprData,
sizeof(bufIPstruct_t),PF_DATA_MSGTAG))
4022 if ( e->status == HIDDENLEXPRESSION || e->status == HIDDENGEXPRESSION )
4027 SetScratch(fi,&pos);
4029 l=PF_SendChunkIP(fi, &pos, dest, PF.exprbufsize*
sizeof(WORD));
4032 t=fi->PObuffer+ (DIFBASE(pos,fi->POposition))/
sizeof(WORD);
4033 ll=PF_WalkThrough(t,ll,l/
sizeof(WORD),&count);
4044static int PF_ReadMaster(
void)
4046 bufIPstruct_t exprData;
4056 if (
PF_RawRecv(&m, &exprData,
sizeof(bufIPstruct_t),&tag)!=
sizeof(bufIPstruct_t))
4059 if(tag == PF_EMPTY_MSGTAG)
4063 PF.exprtodo=exprData.i;
4064 e=Expressions + PF.exprtodo;
4067 if ( e->status == HIDDENLEXPRESSION || e->status == HIDDENGEXPRESSION )
4071 SetEndHScratch(fi,&pos);
4072 e->onfile=AS.OldOnFile[PF.exprtodo]=pos;
4075 l=PF_RecvChunkIP(fi,MASTER,PF.exprbufsize*
sizeof(WORD));
4078 t=fi->POfull-l/
sizeof(WORD);
4079 ll=PF_WalkThrough(t,ll,l/
sizeof(WORD),&count);
4083 fi->POfill=fi->POfull;
4084 return(PF_DATA_MSGTAG);
4093static int PF_SendChunkIP(
FILEHANDLE *curfile, POSITION *position,
int to, LONG thesize)
4097 ISLESSPOS(*position,curfile->POposition) ||
4098 ISGEPOSINC(*position,curfile->POposition,
4099 ((curfile->POfull-curfile->PObuffer)*
sizeof(WORD)-thesize) )
4102 l=(curfile->POfull-curfile->PObuffer)*
sizeof(WORD) - (LONG)(position->p1);
4104 PF_SetScratch(curfile,position);
4106 ISGEPOSINC(*position,curfile->POposition,
4107 ((curfile->POfull-curfile->PObuffer)*
sizeof(WORD)-thesize) )
4109 l=(curfile->POfull-curfile->PObuffer)*
sizeof(WORD) - (LONG)position->p1;
4114 if(
PF_RawSend(to,curfile->PObuffer+ (DIFBASE(*position,curfile->POposition))/
sizeof(WORD),l,0))
4125static int PF_RecvChunkIP(
FILEHANDLE *curfile,
int from, LONG thesize)
4129 if( (LONG)((curfile->POstop - curfile->POfull)*
sizeof(WORD)) < thesize )
4130 if(PF_pushScratch(curfile))
4135 receivedBytes=
PF_RawRecv(&from,curfile->POfull,thesize,&tag);
4137 if(receivedBytes >= 0 ){
4138 curfile->POfull+=receivedBytes/
sizeof(WORD);
4139 curfile->POfill=curfile->POfull;
4141 return(receivedBytes);
4157static int PF_WalkThrough(WORD *t, LONG l, LONG chunk, LONG *count)
4198#define PF_SNDFILEBUFSIZE 4096
4211 if(
PF_RawSend(to,&to,
sizeof(
int),PF_EMPTY_MSGTAG))
4216 char buf[PF_SNDFILEBUFSIZE];
4218 l=fread(buf, 1, PF_SNDFILEBUFSIZE, fd);
4220 if(l==PF_SNDFILEBUFSIZE){
4221 if(
PF_RawSend(to,buf,PF_SNDFILEBUFSIZE,PF_BUFFER_MSGTAG))
4250 char buf[PF_SNDFILEBUFSIZE];
4252 l=
PF_RawRecv(&from,buf,PF_SNDFILEBUFSIZE,&tag);
4255 if(tag == PF_EMPTY_MSGTAG)
4258 if( fwrite(buf,l,1,fd)!=1 )
4261 }
while(tag!=PF_ENDBUFFER_MSGTAG);
4303static int errorMessageLock = 0;
4304static Vector(UBYTE, stdoutBuffer);
4305static Vector(UBYTE, logBuffer);
4306#define recvBuffer logBuffer
4312#ifndef PF_ENABLE_STDOUT_BUFFERING
4314#define PF_ENABLE_STDOUT_BUFFERING
4329 if ( errorMessageLock++ > 0 )
return;
4345 if ( --errorMessageLock > 0 )
return;
4373 if ( PF.me != MASTER && errorMessageLock > 0 ) {
4374 if ( handle == AM.StdOut ) {
4378 else if ( handle == AC.LogHandle ) {
4383#ifdef PF_ENABLE_STDOUT_BUFFERING
4429 if ( PF.me == MASTER && handle == AM.StdOut ) {
4432 if ( (size > 0 && buffer[size - 1] != LINEFEED) || (size == 1 && buffer[0] == LINEFEED) ) {
4436 if ( (oldsize =
VectorSize(stdoutBuffer)) > 0 ) {
4444 else if ( ret < (LONG)oldsize ) {
4448 return ret - (LONG)oldsize;
4453 return WriteFileToFile(handle, buffer, size);
4467#ifdef PF_ENABLE_STDOUT_BUFFERING
4468 if ( PF.me == MASTER &&
VectorSize(stdoutBuffer) > 0 ) {
4488static void PF_ReceiveErrorMessage(
int src,
int tag)
4495 case PF_STDOUT_MSGTAG:
4501 int handle = (tag == PF_STDOUT_MSGTAG) ? AM.StdOut : AC.LogHandle;
4502#ifdef PF_ENABLE_STDOUT_BUFFERING
4506 WriteFileToFile(handle,
VectorPtr(recvBuffer), size);
4525static void PF_CatchErrorMessages(
int *src,
int *tag)
4533 if ( atag == PF_STDOUT_MSGTAG || atag == PF_LOG_MSGTAG ) {
4534 PF_ReceiveErrorMessage(asrc, atag);
4552static void PF_CatchErrorMessagesForAll(
void)
4556 for ( i = 1; i < PF.numtasks; i++ ) {
4558 int tag = PF_ANY_MSGTAG;
4559 PF_CatchErrorMessages(&src, &tag);
4577static int PF_ProbeWithCatchingErrorMessages(
int *src)
4582 if ( tag == PF_STDOUT_MSGTAG || tag == PF_LOG_MSGTAG ) {
4583 PF_ReceiveErrorMessage(newsrc, tag);
4586 if ( tag > 0 ) *src = newsrc;
WORD * poly_ratfun_add(PHEAD WORD *, WORD *)
int poly_unfactorize_expression(EXPRESSIONS)
WORD CompCoef(WORD *, WORD *)
VOID WriteStats(POSITION *, WORD)
WORD PutOut(PHEAD WORD *, POSITION *, FILEHANDLE *, WORD)
LONG EndSort(PHEAD WORD *, int)
WORD InsertTerm(PHEAD WORD *, WORD, WORD, WORD *, WORD *, WORD)
WORD Generator(PHEAD WORD *, WORD)
WORD StoreTerm(PHEAD WORD *)
int poly_factorize_expression(EXPRESSIONS)
VOID AddArgs(PHEAD WORD *, WORD *, WORD *)
int NormalModulus(UWORD *, WORD *)
WORD FlushOut(POSITION *, FILEHANDLE *, int)
int PutPreVar(UBYTE *, UBYTE *, UBYTE *, int)
int PF_LongSingleReceive(int src, int tag, int *psrc, int *ptag)
int PF_PackString(const UBYTE *str)
int PF_LongSingleSend(int to, int tag)
int PF_PrepareLongSinglePack(void)
int PF_Unpack(void *buffer, size_t count, MPI_Datatype type)
int PF_Receive(int src, int tag, int *psrc, int *ptag)
int PF_Send(int to, int tag)
int PF_LongSingleUnpack(void *buffer, size_t count, MPI_Datatype type)
int PF_Pack(const void *buffer, size_t count, MPI_Datatype type)
int PF_PrepareLongMultiPack(void)
int PF_LongMultiBroadcast(void)
int PF_UnpackString(UBYTE *str)
int PF_LongSinglePack(const void *buffer, size_t count, MPI_Datatype type)
int PF_Bcast(void *buffer, int count)
int PF_ISendSbuf(int to, int tag)
int PF_WaitRbuf(PF_BUFFER *, int, LONG *)
void PF_FreeErrorMessageBuffers(void)
WORD PF_Deferred(WORD *term, WORD level)
int PF_BroadcastRedefinedPreVars(void)
int PF_Init(int *argc, char ***argv)
int PF_BroadcastRHS(void)
LONG PF_GetSlaveTimes(void)
int PF_BroadcastExpFlags(void)
int PF_BroadcastPreDollar(WORD **dbuffer, LONG *newsize, int *numterms)
int PF_BroadcastModifiedDollars(void)
int PF_RecvWbuf(WORD *, LONG *, int *)
int PF_BroadcastCBuf(int bufnum)
void PF_BroadcastBuffer(WORD **buffer, LONG *length)
LONG PF_RawRecv(int *src, void *buf, LONG thesize, int *tag)
int PF_CollectModifiedDollars(void)
LONG PF_WriteFileToFile(int handle, UBYTE *buffer, LONG size)
int PF_RawProbe(int *src, int *tag, int *bytesize)
int PF_RecvFile(int from, FILE *fd)
int PF_IRecvRbuf(PF_BUFFER *, int, int)
int PF_BroadcastString(UBYTE *str)
int PF_Terminate(int errorcode)
void PF_FlushStdOutBuffer(void)
int PF_RawSend(int dest, void *buf, LONG l, int tag)
LONG PF_BroadcastNumber(LONG x)
int PF_LibInit(int *, char ***)
int PF_SendFile(int to, FILE *fd)
int PF_Processor(EXPRESSIONS e, WORD i, WORD LastExpression)
int PF_BroadcastExpr(EXPRESSIONS e, FILEHANDLE *file)
#define UNPACK_LONG(p, n)
int PF_InParallelProcessor(void)
#define VectorReserve(X, newcapacity)
#define VectorPushBack(X, x)
#define VectorPushBacks(X, src, n)