63 int PF_RawSend(
int dest,
void *buf, LONG l,
int tag);
64 LONG
PF_RawRecv(
int *src,
void *buf,LONG thesize,
int *tag);
69 static int PF_WaitAllSlaves(
void);
71 static void PF_PackRedefinedPreVars(
void);
72 static void PF_UnpackRedefinedPreVars(
void);
74 static int PF_Wait4MasterIP(
int tag);
75 static int PF_DoOneExpr(
void);
76 static int PF_ReadMaster(
void);
77 static int PF_Slave2MasterIP(
int src);
78 static int PF_Master2SlaveIP(
int dest,
EXPRESSIONS e);
79 static int PF_WalkThrough(WORD *t, LONG l, LONG chunk, LONG *count);
80 static int PF_SendChunkIP(
FILEHANDLE *curfile,
POSITION *position,
int to, LONG thesize);
81 static int PF_RecvChunkIP(
FILEHANDLE *curfile,
int from, LONG thesize);
83 static void PF_ReceiveErrorMessage(
int src,
int tag);
84 static void PF_CatchErrorMessages(
int *src,
int *tag);
85 static void PF_CatchErrorMessagesForAll(
void);
86 static int PF_ProbeWithCatchingErrorMessages(
int *src);
95 static LONG PF_goutterms;
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) 177 static LONG PF_linterms;
178 #define PF_STATS_SIZE 5 179 static LONG **PF_stats = NULL;
180 static LONG PF_laststat;
181 static LONG PF_statsinterval;
195 static 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;
218 sum[0] = cpu = TimeCPU(1);
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));
277 static NODE *PF_root;
278 static WORD PF_loser;
279 static WORD **PF_term;
280 static WORD **PF_newcpos;
281 static WORD *PF_newclen;
287 static WORD *PF_WorkSpace;
288 static UWORD *PF_ScratchSpace;
311 static 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);
380 static 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;
524 static 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;
648 static 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(BHEAD 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 ) {
713 w = poly_ratfun_add(BHEAD ml,mr);
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;
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 S->PolyFlag = AR.PolyFun ? AR.PolyFunType : 0;
920 *AR.CompressPointer = 0;
921 SeekScratch(fout, &position);
922 oldposition = position;
923 oldgzipCompress = AR.gzipCompress;
928 while ( PF_loser >= 0 ) {
929 if ( (PF_loser = PF_GetLoser(PF_root)) == 0 )
break;
930 outterm = PF_term[PF_loser];
933 if ( PF_newclen[PF_loser] != 0 ) {
937 outterm = PF_WorkSpace;
938 pp = PF_term[PF_loser];
940 while ( cc-- ) *outterm++ = *pp++;
941 outterm = (outterm[-1] > 0) ? outterm-outterm[-1] : outterm+outterm[-1];
942 if ( PF_newclen[PF_loser] > 0 ) cc = (WORD)PF_newclen[PF_loser] - 1;
943 else cc = -(WORD)PF_newclen[PF_loser] - 1;
944 pp = PF_newcpos[PF_loser];
945 while ( cc-- ) *outterm++ = *pp++;
946 *outterm++ = PF_newclen[PF_loser];
947 *PF_WorkSpace = outterm - PF_WorkSpace;
948 outterm = PF_WorkSpace;
949 *PF_newcpos[PF_loser] = 0;
950 PF_newclen[PF_loser] = 0;
955 PRINTFBUF(
"PF_EndSort to PutOut: ",outterm,*outterm);
956 PutOut(BHEAD outterm,&position,fout,1);
959 AR.gzipCompress = oldgzipCompress;
962 S->TermsLeft = PF_goutterms = noutterms;
963 DIFPOS(PF_exprsize, position, oldposition);
964 AR.gzipCompress = oldgzipCompress;
975 static WORD *PF_CurrentBracket;
1000 static WORD PF_GetTerm(WORD *term)
1003 FILEHANDLE *fi = AC.RhsExprInModuleFlag && PF.rhsInParallel ? &PF.slavebuf : AR.infile;
1005 WORD *next, *np, *last, *lp = 0, *nextstop, *tp=term;
1009 AN.deferskipped = 0;
1010 if ( fi->POfill >= fi->POfull || fi->POfull == fi->PObuffer ) {
1016 int src = MASTER, tag;
1018 LONG size,cpu,space = 0;
1021 fprintf(stderr,
"[%d] Starting to send to Master\n",PF.me);
1029 PF_Pack(&PF_linterms ,1,PF_LONG);
1030 PF_Pack(&(AM.S0->GenTerms) ,1,PF_LONG);
1031 PF_Pack(&(AM.S0->TermsLeft),1,PF_LONG);
1035 fprintf(stderr,
"[%d] Now sending with tag = %d\n",PF.me,PF_READY_MSGTAG);
1039 PF_Send(MASTER, PF_READY_MSGTAG);
1042 fprintf(stderr,
"[%d] returning from send\n",PF.me);
1046 size = fi->POstop - fi->PObuffer - 1;
1047 #ifdef AbsolutelyExtra 1050 if ( tag == PF_TERM_MSGTAG ) {
1052 if ( PF_Put_target(src) == 0 ) {
1053 printf(
"PF_Put_target error ...\n");
1065 fi->POfill = fi->PObuffer;
1070 if ( *fi->POfill ) {
1071 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));
1072 AN.ninterms = ninterms - 1;
1074 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));
1077 fi->POfull = fi->PObuffer + size;
1078 if ( tag == PF_ENDSORT_MSGTAG ) *fi->POfull++ = 0;
1083 if ( PF_CurrentBracket ) *PF_CurrentBracket = 0;
1085 if ( *fi->POfill == 0 ) {
1086 fi->POfill = fi->POfull = fi->PObuffer;
1090 if ( AR.DeferFlag ) {
1091 if ( !PF_CurrentBracket ) {
1096 (WORD*)Malloc1(AM.MaxTer,
"PF_CurrentBracket");
1097 *PF_CurrentBracket = 0;
1102 while ( *PF_CurrentBracket ) {
1107 nextstop = next + *next; nextstop -= ABS(nextstop[-1]);
1109 last = PF_CurrentBracket+1;
1110 while ( next < nextstop ) {
1114 if ( *last == HAAKJE && *next == HAAKJE ) {
1118 PRINTFBUF(
"PF_GetTerm skips",fi->POfill,*fi->POfill);
1124 np = next; next += next[1];
1125 lp = last; last += last[1];
1126 while ( np < next )
if ( *lp++ != *np++ )
goto strip;
1131 fi->POfill += *fi->POfill;
1136 if ( fi->POfill >= fi->POfull || fi->POfull == fi->PObuffer )
1138 if ( *fi->POfill == 0 ) {
1139 fi->POfill = fi->POfull = fi->PObuffer;
1155 nextstop = next + *next; nextstop -= ABS(nextstop[-1]);
1158 lp = PF_CurrentBracket + 1;
1159 while ( next < nextstop ) {
1160 if ( *next == HAAKJE ) {
1161 fi->POfill += *fi->POfill;
1162 while ( next < fi->POfill ) *lp++ = *next++;
1163 *PF_CurrentBracket = lp - PF_CurrentBracket;
1168 *term = WORDDIF(tp,term);
1169 PRINTFBUF(
"PF_GetTerm new brack",PF_CurrentBracket,*PF_CurrentBracket);
1170 PRINTFBUF(
"PF_GetTerm POfill",fi->POfill,*fi->POfill);
1173 np = next; next += next[1];
1174 while ( np < next ) *tp++ = *lp++ = *np++;
1183 while ( i-- ) *tp++ = *fi->POfill++;
1185 PRINTFBUF(
"PF_GetTerm returns",term,*term);
1207 FILEHANDLE *fi = AC.RhsExprInModuleFlag && PF.rhsInParallel ? &PF.slavebuf : AR.infile;
1208 WORD *next = fi->POfill;
1209 WORD *termout = AT.WorkPointer;
1210 WORD *oldwork = AT.WorkPointer;
1212 AT.WorkPointer = (WORD *)((UBYTE *)(AT.WorkPointer) + AM.MaxTer);
1215 PRINTFBUF(
"PF_Deferred (Term) ",term,*term);
1216 PRINTFBUF(
"PF_Deferred (Bracket)",PF_CurrentBracket,*PF_CurrentBracket);
1218 bra = bstop = PF_CurrentBracket;
1221 bstop -= ABS(bstop[-1]);
1224 while ( *bra != HAAKJE && bra < bstop ) bra += bra[1];
1225 if ( bra >= bstop ) {
1226 AT.WorkPointer = term + *term;
1227 if (
Generator(BHEAD term,level) )
goto DefCall;
1229 AT.WorkPointer = oldwork;
1233 tstart = bra + bra[1];
1234 bra = PF_CurrentBracket;
1236 *tstart = bra + *bra - tstart;
1245 if (
InsertTerm(BHEAD term,0,AM.rbufnum,tstart,termout,0) < 0 ) {
1251 AT.WorkPointer = termout + *termout;
1252 if (
Generator(BHEAD termout,level) )
goto DefCall;
1253 AT.WorkPointer = termout;
1255 if ( tstart >= fi->POfull )
goto ThatsIt;
1260 while ( bra <= bstop ) {
1261 if ( *bra != *tstart )
goto ThatsIt;
1268 if ( *bra != HAAKJE || *tstart != HAAKJE )
goto ThatsIt;
1269 tstart += tstart[1];
1271 *tstart = next - tstart;
1272 bra = PF_CurrentBracket + 1;
1282 MesCall(
"PF_Deferred");
1291 static LONG **PF_W4Sstats = 0;
1299 static int PF_Wait4Slave(
int src)
1303 tag = PF_ANY_MSGTAG;
1304 PF_CatchErrorMessages(&src, &tag);
1307 if ( tag != PF_READY_MSGTAG ) {
1308 MesPrint(
"[%d] PF_Wait4Slave: received MSGTAG %d",(WORD)PF.me,(WORD)tag);
1311 if ( PF_W4Sstats == 0 ) {
1312 PF_W4Sstats = (LONG**)Malloc1(
sizeof(LONG*),
"");
1313 PF_W4Sstats[0] = (LONG*)Malloc1(PF_STATS_SIZE*
sizeof(LONG),
"");
1315 PF_Unpack(PF_W4Sstats[0],PF_STATS_SIZE,PF_LONG);
1316 PF_Statistics(PF_W4Sstats,next);
1337 static WORD *partodoexr=NULL;
1346 static int PF_Wait4SlaveIP(
int *src)
1350 tag = PF_ANY_MSGTAG;
1351 PF_CatchErrorMessages(src, &tag);
1354 if ( PF_W4Sstats == 0 ) {
1355 PF_W4Sstats = (LONG**)Malloc1(
sizeof(LONG*),
"");
1356 PF_W4Sstats[0] = (LONG*)Malloc1(PF_STATS_SIZE*
sizeof(LONG),
"");
1359 PF_Unpack(PF_W4Sstats[0],PF_STATS_SIZE,PF_LONG);
1360 if ( tag == PF_DATA_MSGTAG )
1361 AR.CurExpr = partodoexr[next];
1362 PF_Statistics(PF_W4Sstats,next);
1385 static int PF_WaitAllSlaves(
void)
1387 int i, readySlaves, tag, next = PF_ANY_SOURCE;
1388 UBYTE *has_sent = 0;
1390 has_sent = (UBYTE*)Malloc1(
sizeof(UBYTE)*(PF.numtasks + 1),
"PF_WaitAllSlaves");
1391 for ( i = 0; i < PF.numtasks; i++ ) has_sent[i] = 0;
1393 for ( readySlaves = 1; readySlaves < PF.numtasks; ) {
1394 if ( next != PF_ANY_SOURCE) {
1396 if ( ++next >= PF.numtasks ) next = 1;
1397 }
while ( has_sent[next] == 1 );
1402 tag = PF_ProbeWithCatchingErrorMessages(&next);
1407 case PF_BUFFER_MSGTAG:
1408 case PF_ENDBUFFER_MSGTAG:
1412 if ( has_sent[next] == 0 ) {
1417 fprintf(stderr,
"ERROR next=%d tag=%d\n",next,tag);
1431 #ifdef PF_WITH_SCHED_YIELD 1438 case PF_DATA_MSGTAG:
1440 next=PF_Wait4SlaveIP(&tag);
1444 PF_Statistics(PF_stats,0);
1445 PF_Slave2MasterIP(next);
1446 PF_Master2SlaveIP(next,NULL);
1447 if ( has_sent[next] == 0 ) {
1452 fprintf(stderr,
"ERROR next=%d tag=%d\n",next,tag);
1455 case PF_EMPTY_MSGTAG:
1457 next=PF_Wait4SlaveIP(&tag);
1461 PF_Master2SlaveIP(next,NULL);
1462 if ( has_sent[next] == 0 ) {
1467 fprintf(stderr,
"ERROR next=%d tag=%d\n",next,tag);
1470 case PF_READY_MSGTAG:
1475 next = PF_Wait4Slave(next);
1476 if ( next == -1 )
return(next);
1477 if ( has_sent[0] == 0 ) {
1478 PF.sbuf->active = 0;
1486 PACK_LONG(PF.sbuf->fill[next], AN.ninterms);
1490 *(PF.sbuf->fill[next])++ = 0;
1491 PF.sbuf->active = next;
1503 MesPrint(
"!!!Unexpected MPI message src=%d tag=%d.", next, tag);
1504 readySlaves = PF.numtasks+1;
1509 if ( has_sent ) M_free(has_sent,
"PF_WaitAllSlaves");
1514 return(PF.numtasks-readySlaves);
1537 WORD *term = AT.WorkPointer;
1547 if ( PF_shared_buff == NULL ) {
1548 if ( PF_SMWin_Init() == 0 ) {
1549 MesPrint(
"PF_SMWin_Init error");
1555 if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer ) ) > AT.WorkTop )
return(MesWork());
1558 if ( AC.numpfirstnum > 0 ) {
1559 for ( j = 0; j < AC.numpfirstnum; j++ ) {
1560 AC.inputnumbers[j] = -1;
1564 if ( AC.mparallelflag != PARALLELFLAG )
return(0);
1566 if ( PF.me == MASTER ) {
1571 WORD oldBracketOn = AR.BracketOn;
1572 WORD *oldBrackBuf = AT.BrackBuf;
1573 WORD oldbracketindexflag = AT.bracketindexflag;
1578 LONG ProcessBucketSize = AC.mProcessBucketSize;
1580 if ( PF.log && AC.CModule >= PF.log )
1581 MesPrint(
"[%d] working on expression %s in module %l",PF.me,EXPRNAME(i),AC.CModule);
1582 if ( GetTerm(BHEAD term) <= 0 ) {
1583 MesPrint(
"[%d] Expression %d has problems in scratchfile",PF.me,i);
1587 if ( AR.outtohide ) {
1588 SeekScratch(AR.hidefile,&position);
1589 e->onfile = position;
1590 if (
PutOut(BHEAD term,&position,AR.hidefile,0) < 0 )
return(-1);
1593 SeekScratch(AR.outfile,&position);
1594 e->onfile = position;
1595 if (
PutOut(BHEAD term,&position,AR.outfile,0) < 0 )
return(-1);
1599 if ( ( e->vflags & ISFACTORIZED ) != 0 ) {
1601 AT.BrackBuf = AM.BracketFactors;
1602 AT.bracketindexflag = 1;
1604 if ( AT.bracketindexflag > 0 ) OpenBracketIndex(i);
1615 if ( sb == 0 || sb->buff[0] != AT.SS->lBuffer ) {
1616 size = (LONG)((AT.SS->sTop2 - AT.SS->lBuffer)/(PF.numtasks));
1617 if ( size > (LONG)(AR.infile->POsize/
sizeof(WORD) - 1) )
1618 size = AR.infile->POsize/
sizeof(WORD) - 1;
1620 if ( ( sb = PF_AllocBuf(PF.numtasks,size*
sizeof(WORD),PF.numtasks) ) == NULL )
1623 sb->buff[0] = AT.SS->lBuffer;
1624 sb->full[0] = sb->fill[0] = sb->buff[0];
1625 for ( j = 1; j < PF.numtasks; j++ ) {
1626 sb->stop[j-1] = sb->buff[j] = sb->buff[j-1] + size;
1628 sb->stop[PF.numtasks-1] = sb->buff[PF.numtasks-1] + size;
1631 for ( j = 0; j < PF.numtasks; j++ ) {
1632 sb->full[j] = sb->fill[j] = sb->buff[j];
1644 maxinterms = ProcessBucketSize / 100;
1645 if ( maxinterms > e->counter / (PF.numtasks - 1) / 4 )
1646 maxinterms = e->counter / (PF.numtasks - 1) / 4;
1647 if ( maxinterms < 1 ) maxinterms = 1;
1658 while ( GetTerm(BHEAD term) ) {
1659 AN.ninterms++; dd = AN.deferskipped;
1660 if ( AC.CollectFun && *term <= (LONG)(AM.MaxTer/(2*
sizeof(WORD))) ) {
1661 if ( GetMoreTerms(term) < 0 ) {
1665 PRINTFBUF(
"PF_Processor gets",term,*term);
1666 if ( termsinbucket >= maxinterms || sb->fill[0] + *term >= sb->stop[0] ) {
1667 next = PF_Wait4Slave(PF_ANY_SOURCE);
1669 sb->fill[next] = sb->fill[0];
1670 sb->full[next] = sb->full[0];
1671 SWAP(sb->stop[next], sb->stop[0]);
1672 SWAP(sb->buff[next], sb->buff[0]);
1673 sb->fill[0] = sb->full[0] = sb->buff[0];
1677 if ( PF_Put_origin(next) == 0 ) {
1678 printf(
"PF_Put_origin error...\n");
1690 if ( cmaxinterms >= PF.numtasks - 2 ) {
1692 if ( maxinterms >= ProcessBucketSize ) {
1694 maxinterms = ProcessBucketSize;
1697 else if ( cmaxinterms >= 0 ) {
1702 NCOPY(sb->fill[0], s, j);
1712 if ( LastExpression ) {
1714 if ( AR.infile->handle >= 0 ) {
1715 CloseFile(AR.infile->handle);
1716 AR.infile->handle = -1;
1717 remove(AR.infile->name);
1718 PUTZERO(AR.infile->POposition);
1720 AR.infile->POfill = AR.infile->POfull = AR.infile->PObuffer;
1722 if ( AR.outtohide ) AR.outfile = AR.hidefile;
1724 if (
EndSort(BHEAD AM.S0->sBuffer,0) < 0 )
return(-1);
1726 if ( AR.outtohide ) {
1727 AR.outfile = oldoutfile;
1728 AR.hidefile->POfull = AR.hidefile->POfill;
1731 AR.BracketOn = oldBracketOn;
1732 AT.BrackBuf = oldBrackBuf;
1733 if ( ( e->vflags & TOBEFACTORED ) != 0 )
1734 poly_factorize_expression(e);
1735 else if ( ( ( e->vflags & TOBEUNFACTORED ) != 0 )
1736 && ( ( e->vflags & ISFACTORIZED ) != 0 ) )
1737 poly_unfactorize_expression(e);
1738 AT.bracketindexflag = oldbracketindexflag;
1749 DBGOUT_NINTERMS(1, (
"PF.me=%d AN.ninterms=%d ENDSORT\n", (
int)PF.me, (
int)AN.ninterms));
1750 PF_CatchErrorMessagesForAll();
1752 for ( k = 1; k < PF.numtasks; k++ ) {
1756 WORD numdummies, expchanged;
1759 if ( e->numdummies < numdummies ) e->numdummies = numdummies;
1760 AR.expchanged |= expchanged;
1763 if ( AC.numpfirstnum > 0 ) PF_UnpackRedefinedPreVars();
1765 if ( ! AC.OldParallelStats ) {
1768 for ( k = 1; k < PF.numtasks; k++ ) {
1769 genterms += PF_stats[k][3];
1771 AT.SS->GenTerms = genterms;
1774 PF_Statistics(PF_stats,0);
1779 if ( AM.S0->TermsLeft ) e->vflags &= ~ISZERO;
1780 else e->vflags |= ISZERO;
1781 if ( AR.expchanged == 0 ) e->vflags |= ISUNMODIFIED;
1782 if ( AM.S0->TermsLeft ) AR.expflags |= ISZERO;
1783 if ( AR.expchanged ) AR.expflags |= ISUNMODIFIED;
1799 WORD oldBracketOn = AR.BracketOn;
1800 WORD *oldBrackBuf = AT.BrackBuf;
1801 WORD oldbracketindexflag = AT.bracketindexflag;
1804 if ( AC.numpfirstnum > 0 ) {
1805 for ( j = 0; j < AC.numpfirstnum; j++ ) {
1806 AC.inputnumbers[j] = -1;
1810 SeekScratch(AR.outfile,&position);
1811 e->onfile = position;
1812 AR.DeferFlag = AC.ComDefer;
1814 if ( ( e->vflags & ISFACTORIZED ) != 0 ) {
1816 AT.BrackBuf = AM.BracketFactors;
1817 AT.bracketindexflag = 1;
1820 AR.MaxDum = AM.IndDum;
1825 AR.infile->POfull = AR.infile->POfill = AR.infile->PObuffer = PF_shared_buff;
1828 FILEHANDLE *fi = AC.RhsExprInModuleFlag && PF.rhsInParallel ? &PF.slavebuf : AR.infile;
1829 fi->POfull = fi->POfill = fi->PObuffer;
1833 while ( PF_GetTerm(term) ) {
1834 PF_linterms++; AN.ninterms++; dd = AN.deferskipped;
1835 AT.WorkPointer = term + *term;
1836 AN.RepPoint = AT.RepCount + 1;
1837 if ( ( e->vflags & ISFACTORIZED ) != 0 && term[1] == HAAKJE ) {
1841 if ( AR.DeferFlag ) {
1842 AR.CurDum = AN.IndDum = Expressions[AR.CurExpr].numdummies + AM.IndDum;
1845 AN.IndDum = AM.IndDum;
1846 AR.CurDum = ReNumber(BHEAD term);
1848 if ( AC.SymChangeFlag ) MarkDirty(term,DIRTYSYMFLAG);
1850 if ( ( AC.modmode & ALSOFUNARGS ) != 0 ) MarkDirty(term,DIRTYFLAG);
1851 else if ( AR.PolyFun ) PolyFunDirty(BHEAD term);
1853 if ( ( AR.PolyFunType == 2 ) && ( AC.PolyRatFunChanged == 0 )
1854 && ( e->status == LOCALEXPRESSION || e->status == GLOBALEXPRESSION ) ) {
1855 PolyFunClean(BHEAD term);
1858 MesPrint(
"[%d] PF_Processor: Error in Generator",PF.me);
1861 PF_linterms += dd; AN.ninterms += dd;
1863 PF_linterms += dd; AN.ninterms += dd;
1879 WORD *oldbuff = fout->PObuffer;
1880 WORD *oldstop = fout->POstop;
1881 LONG oldsize = fout->POsize;
1882 if (
EndSort(BHEAD AM.S0->sBuffer, 0) < 0 )
return -1;
1883 fout->PObuffer = oldbuff;
1884 fout->POstop = oldstop;
1885 fout->POsize = oldsize;
1886 fout->POfill = fout->POfull = fout->PObuffer;
1888 AR.BracketOn = oldBracketOn;
1889 AT.BrackBuf = oldBrackBuf;
1890 AT.bracketindexflag = oldbracketindexflag;
1895 DBGOUT_NINTERMS(1, (
"PF.me=%d AN.ninterms=%d PF_linterms=%d ENDSORT\n", (
int)PF.me, (
int)AN.ninterms, (
int)PF_linterms));
1905 WORD numdummies = AR.MaxDum - AM.IndDum;
1910 if ( AC.numpfirstnum > 0 ) PF_PackRedefinedPreVars();
1922 NumToStr(lbuf,AC.CModule);
1923 fprintf(stderr,
"[%d|%s] Endsort,Collect,Broadcast done\n",PF.me,lbuf);
1953 PF_CurrentBracket = 0;
1964 PF_statsinterval = 10;
1966 PF.exprbufsize=4096;
1968 if ( PF.me == MASTER ) {
1969 #ifdef PF_WITHGETENV 1973 if ( ( c = getenv(
"PF_LOG") ) != 0 ) {
1974 if ( *c ) PF.log = (int)atoi(c);
1976 fprintf(stderr,
"[%d] changing PF.log to %d\n",PF.me,PF.log);
1979 if ( ( c = (
char*)getenv(
"PF_RBUFS") ) != 0 ) {
1980 PF.numrbufs = (int)atoi(c);
1981 fprintf(stderr,
"[%d] changing numrbufs to: %d\n",PF.me,PF.numrbufs);
1984 if ( ( c = (
char*)getenv(
"PF_SBUFS") ) != 0 ) {
1985 PF.numsbufs = (int)atoi(c);
1986 fprintf(stderr,
"[%d] changing numsbufs to: %d\n",PF.me,PF.numsbufs);
1989 if ( PF.numsbufs > 10 ) PF.numsbufs = 10;
1990 if ( PF.numsbufs < 1 ) PF.numsbufs = 1;
1991 if ( PF.numrbufs > 2 ) PF.numrbufs = 2;
1992 if ( PF.numrbufs < 1 ) PF.numrbufs = 1;
1994 if ( ( c = getenv(
"PF_STATS") ) ) {
1996 PF_statsinterval = (int)atoi(c);
1997 NumToStr(lbuf,PF_statsinterval);
1998 fprintf(stderr,
"[%d] changing PF_statsinterval to %s\n",PF.me,lbuf);
2000 if ( PF_statsinterval < 1 ) PF_statsinterval = 10;
2002 fp = (UBYTE*)getenv(
"FORMPATH");
2005 while ( *ubp++ ) fpsize++;
2006 if ( AC.OldParallelStats ) {
2007 fprintf(stderr,
"[%d] changing Path to %s\n",PF.me,fp);
2021 if ( PF.me == MASTER ) {
2024 PF_Pack(&PF.numrbufs,1,PF_WORD);
2025 PF_Pack(&PF.numsbufs,1,PF_WORD);
2030 if ( PF.me != MASTER ) {
2035 AM.Path = (UBYTE*)Malloc1(fpsize*
sizeof(UBYTE),
"Path");
2038 fprintf(stderr,
"[%d] log=%d rbufs=%d sbufs=%d path=%s\n",
2039 PF.me, PF.log, PF.numrbufs, PF.numsbufs, AM.Path);
2078 LONG slavetimes = 0;
2079 LONG t = PF.me == MASTER ? 0 : AM.SumTime + TimeCPU(1);
2080 MPI_Reduce(&t, &slavetimes, 1, PF_LONG, MPI_SUM, MASTER, PF_COMM);
2098 #ifdef PF_DEBUG_BCAST_LONG 2099 if ( PF.me == MASTER ) {
2100 MesPrint(
">> Broadcast LONG: %l", x);
2127 #ifdef PF_DEBUG_BCAST_BUF 2128 if ( PF.me == MASTER ) {
2129 MesPrint(
">> Broadcast Buffer: length=%l", *length);
2133 if ( PF.me != MASTER ) {
2138 if ( *length <= 0 )
return;
2140 if ( PF.me != MASTER ) {
2141 *buffer = (WORD *)Malloc1(*length *
sizeof(WORD),
"PF_BroadcastBuffer");
2146 while ( rest > 0 ) {
2147 int l = rest < (LONG)PF.exprbufsize ? (
int)rest : PF.exprbufsize;
2180 if ( MASTER == PF.me ) {
2189 if ( MASTER != PF.me ) {
2196 }
while ( cstr[clength-1] !=
'\0' );
2228 if ( MASTER == PF.me ) {
2234 LONG n = ((*newsize)+1)/PF_maxDollarChunkSize;
2246 WORD *thechunk = *dbuffer;
2249 err |=
PF_Pack(numterms,1,PF_INT);
2250 err |=
PF_Pack(newsize,1,PF_LONG);
2255 for ( i = 0; i < n; i++ ) {
2256 err |=
PF_Pack(thechunk,PF_maxDollarChunkSize,PF_WORD);
2258 thechunk +=PF_maxDollarChunkSize;
2264 if ( ( n = ( (*newsize)+1)%PF_maxDollarChunkSize ) != 0 ) {
2265 err |=
PF_Pack(thechunk,n,PF_WORD);
2268 #ifdef PF_DEBUG_BCAST_PREDOLLAR 2269 MesPrint(
">> Broadcast PreDollar: newsize=%d numterms=%d", (
int)*newsize, *numterms);
2272 if ( MASTER != PF.me ) {
2274 LONG n, therest, thesize;
2281 thesize = (*newsize)+1;
2286 n = (thesize/PF_maxDollarChunkSize) - 1;
2290 therest = thesize % PF_maxDollarChunkSize;
2291 thechunk = *dbuffer =
2292 (WORD*)Malloc1( thesize *
sizeof(WORD),
"$-buffer slave");
2293 if ( thechunk == NULL )
return(err|4);
2298 for ( i = 0; i < n; i++ ) {
2299 err |=
PF_Unpack(thechunk,PF_maxDollarChunkSize,PF_WORD);
2300 thechunk += PF_maxDollarChunkSize;
2307 err |=
PF_Unpack(thechunk,PF_maxDollarChunkSize,PF_WORD);
2308 thechunk += PF_maxDollarChunkSize;
2314 if ( therest != 0 ) err |=
PF_Unpack(thechunk,therest,PF_WORD);
2329 static inline LONG dollarlen(
const WORD *terms)
2331 const WORD *p = terms;
2332 while ( *p ) p += *p;
2345 static inline WORD dollar_mod_type(WORD index)
2348 for ( i = 0; i < NumModOptdollars; i++ )
2349 if ( ModOptdollars[i].number == index )
break;
2350 if ( i >= NumModOptdollars )
return -1;
2351 return ModOptdollars[i].type;
2369 static inline int dollar_to_be_collected(WORD index)
2371 switch ( dollar_mod_type(index) ) {
2390 static inline void copy_dollar(WORD index, WORD type,
const WORD *where, LONG size)
2394 CleanDollarFactors(d);
2396 if ( type != DOLZERO && where != NULL && where != &AM.dollarzero && where[0] != 0 && size > 0 ) {
2397 if ( size > d->size || size < d->size / 4 ) {
2398 if ( d->where && d->where != &AM.dollarzero )
2399 M_free(d->where,
"old content of dollar");
2400 d->where = Malloc1(
sizeof(WORD) * size,
"copy buffer to dollar");
2404 WCOPY(d->where, where, size);
2407 if ( d->where && d->where != &AM.dollarzero )
2408 M_free(d->where,
"old content of dollar");
2410 d->where = &AM.dollarzero;
2424 static inline int compare_two_expressions(
const WORD *e1,
const WORD *e2)
2443 else if ( e2[e2[0]] == 0 && e2[0] == ABS(e2[e2[0] - 1]) + 1 ) {
2444 if ( e2[e2[0] - 1] > 0 )
2450 else if ( e1[e1[0]] == 0 && e1[0] == ABS(e1[e1[0] - 1]) + 1 ) {
2452 if ( e1[e1[0] - 1] > 0 )
2457 else if ( e2[e2[0]] == 0 && e2[0] == ABS(e2[e2[0] - 1]) + 1 ) {
2458 return(
CompCoef((WORD *)e1, (WORD *)e2));
2462 while ( e1[0] && e2[0] ) {
2463 int c = CompareTerms(BHEAD (WORD *)e1, (WORD *)e2, 1);
2471 if ( e1[0] )
return(+1);
2472 if ( e2[0] )
return(-1);
2485 PADPOINTER(1,0,1,0);
2515 if ( AC.mparallelflag != PARALLELFLAG )
return 0;
2521 for ( i = 0; i < NumPotModdollars; i++ ) {
2522 WORD index = PotModdollars[i];
2523 if ( dollar_to_be_collected(index) ) ndollars++;
2525 if ( ndollars == 0 )
return 0;
2527 if ( PF.me == MASTER ) {
2533 int nbufs = ndollars * (PF.numtasks - 1);
2535 for ( i =
VectorSize(dollar_slave_bufs); i < nbufs; i++ ) {
2540 for ( nslaves = 1; nslaves < PF.numtasks; nslaves++ ) {
2544 for ( i = 0; i < NumPotModdollars; i++ ) {
2545 WORD index = PotModdollars[i];
2547 if ( !dollar_to_be_collected(index) )
continue;
2548 b = &
VectorPtr(dollar_slave_bufs)[(PF.numtasks - 1) * nvars + (src - 1)];
2550 if ( b->type != DOLZERO ) {
2576 for ( i = 0; i < NumPotModdollars; i++ ) {
2577 WORD index = PotModdollars[i];
2581 if ( !dollar_to_be_collected(index) )
continue;
2582 d = Dollars + index;
2583 b = &
VectorPtr(dollar_slave_bufs)[(PF.numtasks - 1) * nvars];
2584 dtype = dollar_mod_type(index);
2592 for ( j = 1; j < PF.numtasks - 1; j++ ) {
2594 if ( (dtype == MODMAX && c > 0) || (dtype == MODMIN && c < 0) )
2598 copy_dollar(index, b->type,
VectorPtr(b->buf), b->size);
2611 CBUF *C = cbuf + AM.rbufnum;
2612 WORD *oldwork = AT.WorkPointer, *oldcterm = AN.cTerm;
2613 WORD olddefer = AR.DeferFlag, oldnumlhs = AR.Cnumlhs, oldnumrhs = C->numrhs;
2621 if ( ((WORD *)((UBYTE *)AT.WorkPointer + AM.MaxTer)) > AT.WorkTop ) {
2642 for ( j = 0; j < PF.numtasks; j++ ) {
2644 for ( r = j == 0 ? Dollars[index].where :
VectorPtr(b[j - 1].buf); *r; r += *r ) {
2645 WCOPY(AT.WorkPointer, r, *r);
2646 AT.WorkPointer += *r;
2653 AT.WorkPointer = oldwork;
2657 size =
EndSort(BHEAD (WORD *)&dbuf, 2);
2667 if ( dbuf[0] == 0 ) {
2670 else if ( dbuf[dbuf[0]] == 0 ) {
2671 const WORD *t = dbuf, *w;
2675 if ( nsize < 0 ) nsize = -nsize;
2676 if ( nsize == n - 1 ) {
2677 nsize = (nsize - 1) / 2;
2680 w++;
while ( w < t + n - 1 ) {
if ( *w )
break; w++; }
2681 if ( w >= t + n - 1 ) type = DOLNUMBER;
2683 else if ( n == 7 && t[6] == 3 && t[5] == 1 && t[4] == 1 && t[1] == INDEX && t[2] == 3 ) {
2689 copy_dollar(index, type, dbuf, dollarlen(dbuf) + 1);
2690 M_free(dbuf,
"temporary dollar buffer");
2692 AR.Cnumlhs = oldnumlhs;
2693 C->numrhs = oldnumrhs;
2694 AR.DeferFlag = olddefer;
2695 AN.cTerm = oldcterm;
2696 AT.WorkPointer = oldwork;
2698 if ( err )
return err;
2705 if ( d->type == DOLTERMS )
2706 cbuf[AM.dbufnum].CanCommu[index] = numcommute(d->where, &cbuf[AM.dbufnum].NumTerms[index]);
2707 cbuf[AM.dbufnum].rhs[index] = d->where;
2709 #ifdef PF_DEBUG_REDUCE_DOLLAR 2710 MesPrint(
"<< Reduce $-var: %s", AC.dollarnames->namebuffer + d->name);
2723 for ( i = 0; i < NumPotModdollars; i++ ) {
2724 WORD index = PotModdollars[i];
2726 if ( !dollar_to_be_collected(index) )
continue;
2727 d = Dollars + index;
2729 if ( d->type != DOLZERO ) {
2734 LONG size = dollarlen(d->where);
2761 static inline int dollar_to_be_broadcast(WORD index)
2763 switch ( dollar_mod_type(index) ) {
2795 for ( i = 0; i < NumPotModdollars; i++ ) {
2796 WORD index = PotModdollars[i];
2797 if ( dollar_to_be_broadcast(index) ) ndollars++;
2799 if ( ndollars == 0 )
return 0;
2801 if ( PF.me == MASTER ) {
2807 for ( i = 0; i < NumPotModdollars; i++ ) {
2808 WORD index = PotModdollars[i];
2810 if ( !dollar_to_be_broadcast(index) )
continue;
2811 d = Dollars + index;
2812 PF_LongMultiPack(&d->type, 1, PF_WORD);
2813 if ( d->type != DOLZERO ) {
2818 LONG size = dollarlen(d->where);
2819 PF_LongMultiPack(&size, 1, PF_LONG);
2820 PF_LongMultiPack(d->where, size, PF_WORD);
2822 PF_LongMultiPack(&d->nfactors, 1, PF_WORD);
2823 if ( d->nfactors > 1 ) {
2824 for ( j = 0; j < d->nfactors; j++ ) {
2826 PF_LongMultiPack(&f->type, 1, PF_WORD);
2827 PF_LongMultiPack(&f->size, 1, PF_LONG);
2829 PF_LongMultiPack(f->where, f->size, PF_WORD);
2831 PF_LongMultiPack(&f->value, 1, PF_WORD);
2835 #ifdef PF_DEBUG_BCAST_DOLLAR 2836 MesPrint(
">> Broadcast $-var: %s", AC.dollarnames->namebuffer + d->name);
2844 if ( PF.me != MASTER ) {
2848 for ( i = 0; i < NumPotModdollars; i++ ) {
2849 WORD index = PotModdollars[i];
2851 if ( !dollar_to_be_broadcast(index) )
continue;
2852 d = Dollars + index;
2854 if ( d->where && d->where != &AM.dollarzero )
2855 M_free(d->where,
"old content of dollar");
2856 d->where = &AM.dollarzero;
2858 CleanDollarFactors(d);
2860 PF_LongMultiUnpack(&d->type, 1, PF_WORD);
2861 if ( d->type != DOLZERO ) {
2863 PF_LongMultiUnpack(&size, 1, PF_LONG);
2865 d->where = (WORD *)Malloc1(
sizeof(WORD) * d->size,
"dollar content");
2866 PF_LongMultiUnpack(d->where, size, PF_WORD);
2869 PF_LongMultiUnpack(&d->nfactors, 1, PF_WORD);
2870 if ( d->nfactors > 1 ) {
2871 d->factors = (
FACDOLLAR *)Malloc1(
sizeof(
FACDOLLAR) * d->nfactors,
"dollar factored stuff");
2872 for ( j = 0; j < d->nfactors; j++ ) {
2874 PF_LongMultiUnpack(&f->type, 1, PF_WORD);
2875 PF_LongMultiUnpack(&f->size, 1, PF_LONG);
2876 if ( f->size > 0 ) {
2877 f->where = (WORD *)Malloc1(
sizeof(WORD) * (f->size + 1),
"dollar factor content");
2878 PF_LongMultiUnpack(f->where, f->size, PF_WORD);
2879 f->where[f->size] = 0;
2884 PF_LongMultiUnpack(&f->value, 1, PF_WORD);
2889 if ( d->type == DOLTERMS )
2890 cbuf[AM.dbufnum].CanCommu[index] = numcommute(d->where, &cbuf[AM.dbufnum].NumTerms[index]);
2891 cbuf[AM.dbufnum].rhs[index] = d->where;
2908 static Vector(UBYTE, prevarbuf);
2923 static void PF_PackRedefinedPreVars(
void)
2928 for ( i = 0; i < AC.numpfirstnum; i++ )
2929 if ( AC.inputnumbers[i] >= 0 ) nredefs++;
2932 for ( i = 0; i < AC.numpfirstnum; i++ )
2933 if ( AC.inputnumbers[i] >= 0) {
2934 WORD index = AC.pfirstnum[i];
2935 UBYTE *value = PreVar[index].value;
2936 int bytes = strlen((
char *)value);
2958 static void PF_UnpackRedefinedPreVars(
void)
2964 if ( nredefs > 0 ) {
2966 for ( i = 0; i < nredefs; i++ ) {
2976 value[bytes] =
'\0';
2979 for ( j = 0; j < AC.numpfirstnum; j++ )
2980 if ( AC.pfirstnum[j] == index )
break;
2981 if ( AC.inputnumbers[j] < inputnumber ) {
2982 AC.inputnumbers[j] = inputnumber;
2983 PutPreVar(PreVar[index].name, value, NULL, 1);
3011 if ( PF.me == MASTER ) {
3019 for ( i = 0; i < AC.numpfirstnum; i++ )
3020 if ( AC.inputnumbers[i] >= 0 ) nredefs++;
3021 PF_LongMultiPack(&nredefs, 1, PF_INT);
3023 for ( i = 0; i < AC.numpfirstnum; i++ )
3024 if ( AC.inputnumbers[i] >= 0) {
3025 WORD index = AC.pfirstnum[i];
3026 UBYTE *value = PreVar[index].value;
3027 int bytes = strlen((
char *)value);
3028 PF_LongMultiPack(&index, 1, PF_WORD);
3029 PF_LongMultiPack(&bytes, 1, PF_INT);
3030 PF_LongMultiPack(value, bytes, PF_BYTE);
3031 #ifdef PF_DEBUG_BCAST_PREVAR 3032 MesPrint(
">> Broadcast PreVar: %s = \"%s\"", PreVar[index].name, value);
3040 if ( PF.me != MASTER ) {
3046 PF_LongMultiUnpack(&nredefs, 1, PF_INT);
3047 if ( nredefs > 0 ) {
3049 for ( i = 0; i < nredefs; i++ ) {
3053 PF_LongMultiUnpack(&index, 1, PF_WORD);
3054 PF_LongMultiUnpack(&bytes, 1, PF_INT);
3057 PF_LongMultiUnpack(value, bytes, PF_BYTE);
3058 value[bytes] =
'\0';
3059 PutPreVar(PreVar[index].name, value, NULL, 1);
3077 static WORD oldRhsExprInModuleFlag;
3078 static Vector(WORD, oldPotModdollars);
3079 static Vector(WORD, oldpfirstnum);
3094 int PF_StoreInsideInfo(
void)
3097 oldRhsExprInModuleFlag = AC.RhsExprInModuleFlag;
3099 for ( i = 0; i < NumPotModdollars; i++ )
3102 for ( i = 0; i < AC.numpfirstnum; i++ )
3120 int PF_RestoreInsideInfo(
void)
3123 AC.RhsExprInModuleFlag = oldRhsExprInModuleFlag;
3124 NumPotModdollars =
VectorSize(oldPotModdollars);
3125 for ( i = 0; i < NumPotModdollars; i++ )
3126 PotModdollars[i] =
VectorPtr(oldPotModdollars)[i];
3128 for ( i = 0; i < AC.numpfirstnum; i++ )
3129 AC.pfirstnum[i] =
VectorPtr(oldpfirstnum)[i];
3148 CBUF *C = cbuf + bufnum;
3151 if ( PF.me == MASTER ) {
3157 PF_LongMultiPack(&C->
BufferSize, 1, PF_LONG);
3158 PF_LongMultiPack(&C->numlhs, 1, PF_INT);
3159 PF_LongMultiPack(&C->numrhs, 1, PF_INT);
3160 PF_LongMultiPack(&C->maxlhs, 1, PF_INT);
3161 PF_LongMultiPack(&C->maxrhs, 1, PF_INT);
3162 PF_LongMultiPack(&C->mnumlhs, 1, PF_INT);
3163 PF_LongMultiPack(&C->mnumrhs, 1, PF_INT);
3164 PF_LongMultiPack(&C->numtree, 1, PF_INT);
3165 PF_LongMultiPack(&C->rootnum, 1, PF_INT);
3166 PF_LongMultiPack(&C->MaxTreeSize, 1, PF_INT);
3169 PF_LongMultiPack(&l, 1, PF_LONG);
3170 PF_LongMultiPack(C->
Buffer, l, PF_WORD);
3171 for ( i = 0; i < C->numlhs + 1; i++ ) {
3173 PF_LongMultiPack(&l, 1, PF_LONG);
3175 for ( i = 0; i < C->numrhs + 1; i++ ) {
3177 PF_LongMultiPack(&l, 1, PF_LONG);
3179 PF_LongMultiPack(C->
CanCommu, C->maxrhs + 1, PF_LONG);
3180 PF_LongMultiPack(C->
NumTerms, C->maxrhs + 1, PF_LONG);
3181 PF_LongMultiPack(C->
numdum, C->maxrhs + 1, PF_WORD);
3182 PF_LongMultiPack(C->
dimension, C->maxrhs + 1, PF_WORD);
3183 if ( C->MaxTreeSize > 0 )
3184 PF_LongMultiPack(C->
boomlijst, (C->numtree + 1) * (
sizeof(
COMPTREE) /
sizeof(
int)), PF_INT);
3185 #ifdef PF_DEBUG_BCAST_CBUF 3186 MesPrint(
">> Broadcast CBuf %d", bufnum);
3193 if ( PF.me != MASTER ) {
3200 PF_LongMultiUnpack(&C->
BufferSize, 1, PF_LONG);
3201 PF_LongMultiUnpack(&C->numlhs, 1, PF_INT);
3202 PF_LongMultiUnpack(&C->numrhs, 1, PF_INT);
3203 PF_LongMultiUnpack(&C->maxlhs, 1, PF_INT);
3204 PF_LongMultiUnpack(&C->maxrhs, 1, PF_INT);
3205 PF_LongMultiUnpack(&C->mnumlhs, 1, PF_INT);
3206 PF_LongMultiUnpack(&C->mnumrhs, 1, PF_INT);
3207 PF_LongMultiUnpack(&C->numtree, 1, PF_INT);
3208 PF_LongMultiUnpack(&C->rootnum, 1, PF_INT);
3209 PF_LongMultiUnpack(&C->MaxTreeSize, 1, PF_INT);
3211 C->
Buffer = (WORD *)Malloc1(C->
BufferSize *
sizeof(WORD),
"compiler buffer");
3213 C->
lhs = (WORD **)Malloc1(C->maxlhs *
sizeof(WORD *),
"compiler buffer");
3214 C->
rhs = (WORD **)Malloc1(C->maxrhs * (
sizeof(WORD *) + 2 *
sizeof(LONG) + 2 *
sizeof(WORD)),
"compiler buffer");
3219 if ( C->MaxTreeSize > 0 )
3222 PF_LongMultiUnpack(&l, 1, PF_LONG);
3223 PF_LongMultiUnpack(C->
Buffer, l, PF_WORD);
3225 for ( i = 0; i < C->numlhs + 1; i++ ) {
3226 PF_LongMultiUnpack(&l, 1, PF_LONG);
3229 for ( i = 0; i < C->numrhs + 1; i++ ) {
3230 PF_LongMultiUnpack(&l, 1, PF_LONG);
3233 PF_LongMultiUnpack(C->
CanCommu, C->maxrhs + 1, PF_LONG);
3234 PF_LongMultiUnpack(C->
NumTerms, C->maxrhs + 1, PF_LONG);
3235 PF_LongMultiUnpack(C->
numdum, C->maxrhs + 1, PF_WORD);
3236 PF_LongMultiUnpack(C->
dimension, C->maxrhs + 1, PF_WORD);
3237 if ( C->MaxTreeSize > 0 )
3238 PF_LongMultiUnpack(C->
boomlijst, (C->numtree + 1) * (
sizeof(
COMPTREE) /
sizeof(
int)), PF_INT);
3261 if ( PF.me == MASTER ) {
3266 PF_LongMultiPack(&AR.expflags, 1, PF_WORD);
3267 for ( i = 0; i < NumExpressions; i++ ) {
3268 e = &Expressions[i];
3269 PF_LongMultiPack(&e->counter, 1, PF_WORD);
3270 PF_LongMultiPack(&e->vflags, 1, PF_WORD);
3271 PF_LongMultiPack(&e->numdummies, 1, PF_WORD);
3272 PF_LongMultiPack(&e->numfactors, 1, PF_WORD);
3273 #ifdef PF_DEBUG_BCAST_EXPRFLAGS 3274 MesPrint(
">> Broadcast ExprFlags: %s", AC.exprnames->namebuffer + e->name);
3282 if ( PF.me != MASTER ) {
3286 PF_LongMultiUnpack(&AR.expflags, 1, PF_WORD);
3287 for ( i = 0; i < NumExpressions; i++ ) {
3288 e = &Expressions[i];
3289 PF_LongMultiUnpack(&e->counter, 1, PF_WORD);
3290 PF_LongMultiUnpack(&e->vflags, 1, PF_WORD);
3291 PF_LongMultiUnpack(&e->numdummies, 1, PF_WORD);
3292 PF_LongMultiUnpack(&e->numfactors, 1, PF_WORD);
3315 ( f->
handle >= 0) && ISGEPOS(*position,f->POposition) &&
3316 ( ISGEPOSINC(*position,f->POposition,(f->POfull-f->PObuffer)*
sizeof(WORD)) ==0 )
3318 f->POfull=f->PObuffer;
3319 SetScratch(f,position);
3338 if ( ( RetCode = CreateFile(f->name) ) >= 0 ) {
3339 f->
handle = (WORD)RetCode;
3340 PUTZERO(f->filesize);
3341 PUTZERO(f->POposition);
3344 MesPrint(
"Cannot create scratch file %s",f->name);
3348 size = (f->POfill-f->PObuffer)*
sizeof(WORD);
3350 SeekFile(f->
handle,&(f->POposition),SEEK_SET);
3351 if ( WriteFile(f->
handle,(UBYTE *)(f->PObuffer),size) != size ){
3352 MesPrint(
"Error while writing to disk. Disk full?");
3355 ADDPOS(f->filesize,size);
3356 ADDPOS(f->POposition,size);
3357 f->POfill = f->POfull=f->PObuffer;
3369 static int PF_WalkThroughExprMaster(
FILEHANDLE *curfile,
int dl)
3373 if(curfile->POfull-curfile->POfill < dl){
3375 SeekScratch(curfile,&pos);
3376 PF_SetScratch(curfile,&pos);
3378 curfile->POfill+=dl;
3380 if( l >= PF.exprbufsize){
3381 if( l == PF.exprbufsize){
3382 if( *(curfile->POfill) == 0)
3390 dl=*(curfile->POfill);
3392 return l-PF.exprbufsize;
3395 if(curfile->POfull-curfile->POfill < 1){
3397 SeekScratch(curfile,&pos);
3398 PF_SetScratch(curfile,&pos);
3400 dl=*(curfile->POfill+1)+2;
3411 static int PF_WalkThroughExprSlave(
FILEHANDLE *curfile, LONG *counter,
int dl)
3415 if(curfile->POstop-curfile->POfill < dl){
3416 if(PF_pushScratch(curfile))
3417 return(-PF.exprbufsize-1);
3419 curfile->POfill+=dl;
3420 curfile->POfull=curfile->POfill;
3422 if( l >= PF.exprbufsize){
3423 if( l == PF.exprbufsize){
3428 if( *(curfile->POfill) == 0)
3433 curfile->POfull=curfile->POfill;
3437 dl=*(curfile->POfill);
3439 return l-PF.exprbufsize;
3442 if(curfile->POstop-curfile->POfill < 1){
3443 if(PF_pushScratch(curfile))
3444 return(-PF.exprbufsize-1);
3450 dl=*(curfile->POfill+1)+2;
3470 SetScratch(curfile,&(e->onfile));
3477 if ( curfile->POfull - curfile->POfill < PF.exprbufsize + 1 ) {
3479 SeekScratch(curfile,&pos);
3480 PF_SetScratch(curfile,&pos);
3482 if (
PF_Bcast(curfile->POfill, (PF.exprbufsize + 1) *
sizeof(WORD)) )
3484 l=PF_WalkThroughExprMaster(curfile,l-1);
3514 if ( curfile->POstop - curfile->POfill < PF.exprbufsize + 1 ) {
3515 if(PF_pushScratch(curfile))
3518 if (
PF_Bcast(curfile->POfill, (PF.exprbufsize + 1) *
sizeof(WORD)) )
3520 l = PF_WalkThroughExprSlave(curfile, &counter, l - 1);
3523 if(l<-PF.exprbufsize)
3527 if ( curfile->
handle >= 0 ) {
3528 if ( PF_pushScratch(curfile) )
return -1;
3530 curfile->POfull=curfile->POfill;
3531 if ( curfile != AR.hidefile ) AR.InInBuf = curfile->POfull-curfile->PObuffer;
3532 else AR.InHiBuf = curfile->POfull-curfile->PObuffer;
3533 CHECK(counter == e->counter + 1);
3551 if ( PF.me == MASTER ) {
3552 if ( PF_rhsBCastMaster(file, e) )
return -1;
3553 #ifdef PF_DEBUG_BCAST_RHSEXPR 3554 MesPrint(
">> Broadcast RhsExpr: %s", AC.exprnames->namebuffer + e->name);
3559 SetEndHScratch(file, &pos);
3561 if ( PF_rhsBCastSlave(file, e) )
return -1;
3580 for ( i = 0; i < NumExpressions; i++ ) {
3582 if ( !(e->vflags & ISINRHS) )
continue;
3583 switch ( e->status ) {
3584 case LOCALEXPRESSION:
3585 case SKIPLEXPRESSION:
3586 case DROPLEXPRESSION:
3587 case GLOBALEXPRESSION:
3588 case SKIPGEXPRESSION:
3589 case DROPGEXPRESSION:
3590 case HIDELEXPRESSION:
3591 case HIDEGEXPRESSION:
3592 case INTOHIDELEXPRESSION:
3593 case INTOHIDEGEXPRESSION:
3596 case HIDDENLEXPRESSION:
3597 case HIDDENGEXPRESSION:
3598 case DROPHLEXPRESSION:
3599 case DROPHGEXPRESSION:
3600 case UNHIDELEXPRESSION:
3601 case UNHIDEGEXPRESSION:
3606 if ( PF.me != MASTER )
3629 if(PF.me == MASTER){
3630 if ( PF.numtasks >= 3 ) {
3631 partodoexr = (WORD*)Malloc1(
sizeof(WORD)*(PF.numtasks+1),
"PF_InParallelProcessor");
3632 for ( i = 0; i < NumExpressions; i++ ) {
3634 if ( e->partodo <= 0 )
continue;
3635 if ( e->counter == 0 ) {
3640 case LOCALEXPRESSION:
3641 case GLOBALEXPRESSION:
3642 case UNHIDELEXPRESSION:
3643 case UNHIDEGEXPRESSION:
3644 case INTOHIDELEXPRESSION:
3645 case INTOHIDEGEXPRESSION:
3647 next=PF_Wait4SlaveIP(&tag);
3650 if(tag == PF_DATA_MSGTAG){
3651 PF_Statistics(PF_stats,0);
3652 if(PF_Slave2MasterIP(next))
3655 if(PF_Master2SlaveIP(next,e))
3668 if(PF_WaitAllSlaves())
3671 if ( AC.CollectFun ) AR.DeferFlag = 0;
3673 M_free(partodoexr,
"PF_InParallelProcessor");
3678 for ( i = 0; i < NumExpressions; i++ ) {
3679 Expressions[i].partodo = 0;
3685 if(PF_Wait4MasterIP(PF_EMPTY_MSGTAG))
3689 WORD *oldwork= AT.WorkPointer;
3690 tag=PF_ReadMaster();
3693 if(tag == PF_DATA_MSGTAG){
3694 oldwork = AT.WorkPointer;
3697 if ( AC.numpfirstnum > 0 ) {
3699 for ( j = 0; j < AC.numpfirstnum; j++ ) {
3700 AC.inputnumbers[j] = -1;
3706 if(PF_Wait4MasterIP(PF_DATA_MSGTAG))
3708 if(PF_Slave2MasterIP(PF.me))
3710 AT.WorkPointer=oldwork;
3712 }
while(tag!=PF_EMPTY_MSGTAG);
3722 static int PF_Wait4MasterIP(
int tag)
3728 fprintf(stderr,
"[%d] Starting to send to Master\n",PF.me);
3736 PF_Pack(&PF_linterms ,1,PF_LONG);
3737 PF_Pack(&(AM.S0->GenTerms) ,1,PF_LONG);
3738 PF_Pack(&(AM.S0->TermsLeft),1,PF_LONG);
3742 fprintf(stderr,
"[%d] Now sending with tag = %d\n",PF.me,tag);
3749 fprintf(stderr,
"[%d] returning from send\n",PF.me);
3766 static int PF_DoOneExpr(
void)
3775 WORD oldBracketOn = AR.BracketOn;
3776 WORD *oldBrackBuf = AT.BrackBuf;
3777 WORD oldbracketindexflag = AT.bracketindexflag;
3778 e = Expressions + PF.exprtodo;
3781 AR.SortType = AC.SortType;
3783 if ( ( e->vflags & ISFACTORIZED ) != 0 ) {
3785 AT.BrackBuf = AM.BracketFactors;
3786 AT.bracketindexflag = 1;
3789 position = AS.OldOnFile[i];
3790 if ( e->status == HIDDENLEXPRESSION || e->status == HIDDENGEXPRESSION ) {
3791 AR.GetFile = 2; fi = AR.hidefile;
3794 AR.GetFile = 0; fi = AR.infile;
3802 SetScratch(fi,&position);
3803 term = AT.WorkPointer;
3804 AR.CompressPointer = AR.CompressBuffer;
3805 AR.CompressPointer[0] = 0;
3807 if ( GetTerm(BHEAD term) <= 0 ) {
3808 MesPrint(
"Expression %d has problems in scratchfile",i);
3811 if ( AT.bracketindexflag > 0 ) OpenBracketIndex(i);
3813 PUTZERO(outposition);
3815 fout->POfill = fout->POfull = fout->PObuffer;
3816 fout->POposition = outposition;
3817 if ( fout->
handle >= 0 ) {
3818 fout->POposition = outposition;
3830 if (
PutOut(BHEAD term,&outposition,fout,0) < 0 )
return -1;
3832 AR.DeferFlag = AC.ComDefer;
3835 term = AT.WorkPointer;
3837 AR.MaxDum = AM.IndDum;
3839 while ( GetTerm(BHEAD term) ) {
3840 SeekScratch(fi,&position);
3841 AN.ninterms++; dd = AN.deferskipped;
3842 if ( ( e->vflags & ISFACTORIZED ) != 0 && term[1] == HAAKJE ) {
3846 if ( AC.CollectFun && *term <= (AM.MaxTer/(2*(LONG)
sizeof(WORD))) ) {
3847 if ( GetMoreTerms(term) < 0 ) {
3850 SeekScratch(fi,&position);
3852 AT.WorkPointer = term + *term;
3853 AN.RepPoint = AT.RepCount + 1;
3854 if ( AR.DeferFlag ) {
3855 AR.CurDum = AN.IndDum = Expressions[PF.exprtodo].numdummies;
3858 AN.IndDum = AM.IndDum;
3859 AR.CurDum = ReNumber(BHEAD term);
3861 if ( AC.SymChangeFlag ) MarkDirty(term,DIRTYSYMFLAG);
3863 if ( ( AC.modmode & ALSOFUNARGS ) != 0 ) MarkDirty(term,DIRTYFLAG);
3864 else if ( AR.PolyFun ) PolyFunDirty(BHEAD term);
3866 if ( ( AR.PolyFunType == 2 ) && ( AC.PolyRatFunChanged == 0 )
3867 && ( e->status == LOCALEXPRESSION || e->status == GLOBALEXPRESSION ) ) {
3868 PolyFunClean(BHEAD term);
3875 SetScratch(fi,&position);
3876 if ( fi == AR.hidefile ) {
3877 AR.InHiBuf = (fi->POfull-fi->PObuffer)
3878 -DIFBASE(position,fi->POposition)/
sizeof(WORD);
3881 AR.InInBuf = (fi->POfull-fi->PObuffer)
3882 -DIFBASE(position,fi->POposition)/
sizeof(WORD);
3886 if (
EndSort(BHEAD AM.S0->sBuffer,0) < 0 )
return(-1);
3887 e->numdummies = AR.MaxDum - AM.IndDum;
3888 AR.BracketOn = oldBracketOn;
3889 AT.BrackBuf = oldBrackBuf;
3890 if ( ( e->vflags & TOBEFACTORED ) != 0 )
3891 poly_factorize_expression(e);
3892 else if ( ( ( e->vflags & TOBEUNFACTORED ) != 0 )
3893 && ( ( e->vflags & ISFACTORIZED ) != 0 ) )
3894 poly_unfactorize_expression(e);
3895 if ( AM.S0->TermsLeft ) e->vflags &= ~ISZERO;
3896 else e->vflags |= ISZERO;
3897 if ( AR.expchanged == 0 ) e->vflags |= ISUNMODIFIED;
3901 AT.bracketindexflag = oldbracketindexflag;
3903 fout->POfull = fout->POfill;
3917 static int PF_Slave2MasterIP(
int src)
3927 if(PF.me != MASTER){
3928 e = Expressions + PF.exprtodo;
3930 memcpy(&(exprData.e), e,
sizeof(
struct ExPrEsSiOn));
3931 SeekScratch(fout,&pos);
3932 exprData.i=BASEPOSITION(pos);
3937 SETBASEPOSITION(pos,0);
3939 int blen=PF.exprbufsize*
sizeof(WORD);
3942 l=PF_SendChunkIP(fout,&pos, MASTER, blen);
3949 if ( fout->
handle >= 0 ) {
3953 PUTZERO(fout->POposition);
3954 PUTZERO(fout->filesize);
3955 fout->POfill = fout->POfull = fout->PObuffer;
3958 if ( AC.numpfirstnum > 0 ) {
3960 PF_PackRedefinedPreVars();
3967 e = Expressions +partodoexr[src];
3973 e->counter = exprData.e.counter;
3974 e->vflags = exprData.e.vflags;
3975 e->numdummies = exprData.e.numdummies;
3976 e->numfactors = exprData.e.numfactors;
3977 if ( !(e->vflags & ISZERO) ) AR.expflags |= ISZERO;
3978 if ( !(e->vflags & ISUNMODIFIED) ) AR.expflags |= ISUNMODIFIED;
3979 SeekScratch(fout,&pos);
3983 int blen=PF.exprbufsize*
sizeof(WORD);
3986 l=PF_RecvChunkIP(fout,src,blen);
3993 if ( AC.numpfirstnum > 0 ) {
3995 PF_UnpackRedefinedPreVars();
4005 static int PF_Master2SlaveIP(
int dest,
EXPRESSIONS e)
4018 memcpy(&(exprData.e), e,
sizeof(
struct ExPrEsSiOn));
4019 exprData.i=e-Expressions;
4020 if ( AC.StatsFlag && AC.OldParallelStats ) {
4022 MesPrint(
" Sending expression %s to slave %d",EXPRNAME(exprData.i),dest);
4026 if ( e->status == HIDDENLEXPRESSION || e->status == HIDDENGEXPRESSION )
4031 SetScratch(fi,&pos);
4033 l=PF_SendChunkIP(fi, &pos, dest, PF.exprbufsize*
sizeof(WORD));
4036 t=fi->PObuffer+ (DIFBASE(pos,fi->POposition))/
sizeof(WORD);
4037 ll=PF_WalkThrough(t,ll,l/
sizeof(WORD),&count);
4048 static int PF_ReadMaster(
void)
4063 if(tag == PF_EMPTY_MSGTAG)
4067 PF.exprtodo=exprData.i;
4068 e=Expressions + PF.exprtodo;
4071 if ( e->status == HIDDENLEXPRESSION || e->status == HIDDENGEXPRESSION )
4075 SetEndHScratch(fi,&pos);
4076 e->onfile=AS.OldOnFile[PF.exprtodo]=pos;
4079 l=PF_RecvChunkIP(fi,MASTER,PF.exprbufsize*
sizeof(WORD));
4082 t=fi->POfull-l/
sizeof(WORD);
4083 ll=PF_WalkThrough(t,ll,l/
sizeof(WORD),&count);
4087 fi->POfill=fi->POfull;
4088 return(PF_DATA_MSGTAG);
4097 static int PF_SendChunkIP(
FILEHANDLE *curfile,
POSITION *position,
int to, LONG thesize)
4101 ISLESSPOS(*position,curfile->POposition) ||
4102 ISGEPOSINC(*position,curfile->POposition,
4103 ((curfile->POfull-curfile->PObuffer)*
sizeof(WORD)-thesize) )
4106 l=(curfile->POfull-curfile->PObuffer)*
sizeof(WORD) - (LONG)(position->p1);
4108 PF_SetScratch(curfile,position);
4110 ISGEPOSINC(*position,curfile->POposition,
4111 ((curfile->POfull-curfile->PObuffer)*
sizeof(WORD)-thesize) )
4113 l=(curfile->POfull-curfile->PObuffer)*
sizeof(WORD) - (LONG)position->p1;
4118 if(
PF_RawSend(to,curfile->PObuffer+ (DIFBASE(*position,curfile->POposition))/
sizeof(WORD),l,0))
4129 static int PF_RecvChunkIP(
FILEHANDLE *curfile,
int from, LONG thesize)
4133 if( (LONG)((curfile->POstop - curfile->POfull)*
sizeof(WORD)) < thesize )
4134 if(PF_pushScratch(curfile))
4139 receivedBytes=
PF_RawRecv(&from,curfile->POfull,thesize,&tag);
4141 if(receivedBytes >= 0 ){
4142 curfile->POfull+=receivedBytes/
sizeof(WORD);
4143 curfile->POfill=curfile->POfull;
4145 return(receivedBytes);
4161 static int PF_WalkThrough(WORD *t, LONG l, LONG chunk, LONG *count)
4202 #define PF_SNDFILEBUFSIZE 4096 4215 if(
PF_RawSend(to,&to,
sizeof(
int),PF_EMPTY_MSGTAG))
4220 char buf[PF_SNDFILEBUFSIZE];
4222 l=fread(buf, 1, PF_SNDFILEBUFSIZE, fd);
4224 if(l==PF_SNDFILEBUFSIZE){
4225 if(
PF_RawSend(to,buf,PF_SNDFILEBUFSIZE,PF_BUFFER_MSGTAG))
4254 char buf[PF_SNDFILEBUFSIZE];
4256 l=
PF_RawRecv(&from,buf,PF_SNDFILEBUFSIZE,&tag);
4259 if(tag == PF_EMPTY_MSGTAG)
4262 if( fwrite(buf,l,1,fd)!=1 )
4265 }
while(tag!=PF_ENDBUFFER_MSGTAG);
4307 static int errorMessageLock = 0;
4308 static Vector(UBYTE, stdoutBuffer);
4309 static Vector(UBYTE, logBuffer);
4310 #define recvBuffer logBuffer 4316 #ifndef PF_ENABLE_STDOUT_BUFFERING 4318 #define PF_ENABLE_STDOUT_BUFFERING 4333 if ( errorMessageLock++ > 0 )
return;
4349 if ( --errorMessageLock > 0 )
return;
4377 if ( PF.me != MASTER && errorMessageLock > 0 ) {
4378 if ( handle == AM.StdOut ) {
4382 else if ( handle == AC.LogHandle ) {
4387 #ifdef PF_ENABLE_STDOUT_BUFFERING 4433 if ( PF.me == MASTER && handle == AM.StdOut ) {
4436 if ( (size > 0 && buffer[size - 1] != LINEFEED) || (size == 1 && buffer[0] == LINEFEED) ) {
4440 if ( (oldsize =
VectorSize(stdoutBuffer)) > 0 ) {
4448 else if ( ret < (LONG)oldsize ) {
4452 return ret - (LONG)oldsize;
4457 return WriteFileToFile(handle, buffer, size);
4471 #ifdef PF_ENABLE_STDOUT_BUFFERING 4472 if ( PF.me == MASTER &&
VectorSize(stdoutBuffer) > 0 ) {
4492 static void PF_ReceiveErrorMessage(
int src,
int tag)
4499 case PF_STDOUT_MSGTAG:
4505 int handle = (tag == PF_STDOUT_MSGTAG) ? AM.StdOut : AC.LogHandle;
4506 #ifdef PF_ENABLE_STDOUT_BUFFERING
4510 WriteFileToFile(handle,
VectorPtr(recvBuffer), size);
4529 static void PF_CatchErrorMessages(
int *src,
int *tag)
4537 if ( atag == PF_STDOUT_MSGTAG || atag == PF_LOG_MSGTAG ) {
4538 PF_ReceiveErrorMessage(asrc, atag);
4556 static void PF_CatchErrorMessagesForAll(
void)
4560 for ( i = 1; i < PF.numtasks; i++ ) {
4562 int tag = PF_ANY_MSGTAG;
4563 PF_CatchErrorMessages(&src, &tag);
4581 static int PF_ProbeWithCatchingErrorMessages(
int *src)
4586 if ( tag == PF_STDOUT_MSGTAG || tag == PF_LOG_MSGTAG ) {
4587 PF_ReceiveErrorMessage(newsrc, tag);
4590 if ( tag > 0 ) *src = newsrc;
int NormalModulus(UWORD *, WORD *)
VOID AddArgs(PHEAD WORD *, WORD *, WORD *)
int PF_Init(int *argc, char ***argv)
int PF_LongSingleUnpack(void *buffer, size_t count, MPI_Datatype type)
int PutPreVar(UBYTE *, UBYTE *, UBYTE *, int)
int PF_Pack(const void *buffer, size_t count, MPI_Datatype type)
int PF_LongSingleReceive(int src, int tag, int *psrc, int *ptag)
int PF_BroadcastCBuf(int bufnum)
#define VectorReserve(X, newcapacity)
void PF_BroadcastBuffer(WORD **buffer, LONG *length)
int PF_Unpack(void *buffer, size_t count, MPI_Datatype type)
#define VectorPushBacks(X, src, n)
int PF_IRecvRbuf(PF_BUFFER *, int, int)
LONG PF_RawRecv(int *src, void *buf, LONG thesize, int *tag)
VOID WriteStats(POSITION *, WORD)
int PF_BroadcastString(UBYTE *str)
int PF_BroadcastExpFlags(void)
int PF_PackString(const UBYTE *str)
WORD PF_Deferred(WORD *term, WORD level)
int PF_LongMultiBroadcast(void)
int PF_InParallelProcessor(void)
void PF_FreeErrorMessageBuffers(void)
LONG PF_GetSlaveTimes(void)
int PF_BroadcastExpr(EXPRESSIONS e, FILEHANDLE *file)
int PF_RecvWbuf(WORD *, LONG *, int *)
WORD InsertTerm(PHEAD WORD *, WORD, WORD, WORD *, WORD *, WORD)
int PF_SendFile(int to, FILE *fd)
int PF_BroadcastRedefinedPreVars(void)
WORD StoreTerm(PHEAD WORD *)
int PF_ISendSbuf(int to, int tag)
int PF_PrepareLongMultiPack(void)
#define UNPACK_LONG(p, n)
int PF_LongSingleSend(int to, int tag)
LONG PF_BroadcastNumber(LONG x)
int PF_RawProbe(int *src, int *tag, int *bytesize)
int PF_LibInit(int *, char ***)
int PF_Bcast(void *buffer, int count)
int PF_LongSinglePack(const void *buffer, size_t count, MPI_Datatype type)
int PF_CollectModifiedDollars(void)
int PF_Terminate(int errorcode)
int PF_BroadcastPreDollar(WORD **dbuffer, LONG *newsize, int *numterms)
WORD PutOut(PHEAD WORD *, POSITION *, FILEHANDLE *, WORD)
int PF_RawSend(int dest, void *buf, LONG l, int tag)
int PF_Send(int to, int tag)
WORD Generator(PHEAD WORD *, WORD)
LONG PF_WriteFileToFile(int handle, UBYTE *buffer, LONG size)
WORD FlushOut(POSITION *, FILEHANDLE *, int)
void PF_FlushStdOutBuffer(void)
int PF_PrepareLongSinglePack(void)
int PF_UnpackString(UBYTE *str)
int PF_Processor(EXPRESSIONS e, WORD i, WORD LastExpression)
WORD CompCoef(WORD *, WORD *)
int PF_BroadcastModifiedDollars(void)
int PF_RecvFile(int from, FILE *fd)
int PF_Receive(int src, int tag, int *psrc, int *ptag)
LONG EndSort(PHEAD WORD *, int)
int PF_WaitRbuf(PF_BUFFER *, int, LONG *)
int PF_BroadcastRHS(void)
#define VectorPushBack(X, x)