Skip to content

Commit 4ebfb7f

Browse files
committed
tmp
1 parent 7e0ddbf commit 4ebfb7f

4 files changed

Lines changed: 70 additions & 35 deletions

File tree

sources/compcomm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ static KEYWORDV onoffoptions[] = {
143143
,{"humanstats", &(AC.HumanStatsFlag), 1, 0}
144144
,{"humanstatistics", &(AC.HumanStatsFlag), 1, 0}
145145
,{"grccverbose", &(AC.GrccVerbose), 1, 0}
146+
,{"sortverbose", &(AC.SortVerbose), 1, 0}
146147
};
147148

148149
static WORD one = 1;

sources/sort.c

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,6 @@ extern LONG nummallocs;
7272
extern LONG numfrees;
7373
#endif
7474

75-
//#define COUNTCOMPARES
76-
#ifdef COUNTCOMPARES
77-
// This needs to be large enough for the number of threads.
78-
// It is hardcoded here, but 1024 should be enough.
79-
// Enabling this has a performance impact.
80-
LONG numcompares[1024];
81-
#endif
82-
8375
/*
8476
#] Includes :
8577
#[ SortUtilities :
@@ -164,10 +156,12 @@ void WriteStats(POSITION *plspace, WORD par, WORD checkLogType)
164156
char humanGenTermsText[HUMANSTRLEN] = "";
165157
char humanTermsLeftText[HUMANSTRLEN] = "";
166158
char humanBytesText[HUMANSTRLEN] = "";
159+
char humanComparisonsText[HUMANSTRLEN] = "";
167160
if ( AC.HumanStatsFlag ) {
168161
HumanString(humanGenTermsText, (float)(S->GenTerms), humanTermsSuffix);
169162
HumanString(humanTermsLeftText, (float)(S->TermsLeft), humanTermsSuffix);
170163
HumanString(humanBytesText, (float)(BASEPOSITION(*plspace)), humanBytesSuffix);
164+
HumanString(humanComparisonsText, (float)(S->verbComparisons), humanTermsSuffix);
171165
}
172166

173167
MLOCK(ErrorMessageLock);
@@ -315,6 +309,20 @@ void WriteStats(POSITION *plspace, WORD par, WORD checkLogType)
315309
MesPrint("%s", buf);
316310
}
317311

312+
if ( par == STATSPOSTSORT ) {
313+
if ( AC.SortVerbose ) {
314+
snprintf(buf, sizeof(buf), "%24s Comparisons =%11ld%s",
315+
"",S->verbComparisons,humanComparisonsText);
316+
MesPrint("%s", buf);
317+
snprintf(buf, sizeof(buf), "%24s Small Buffer =%5ld,%5ld",
318+
"",S->verbSBsortTerms,S->verbSBsortCap);
319+
MesPrint("%s", buf);
320+
snprintf(buf, sizeof(buf), "%24s Large Buffer =%5ld,%5ld",
321+
"",S->verbLBsortPatches,S->verbLBsortCap);
322+
MesPrint("%s", buf);
323+
}
324+
}
325+
318326
#ifdef WITHSTATS
319327
MesPrint("Total number of writes: %l, reads: %l, seeks, %l"
320328
,numwrites,numreads,numseeks);
@@ -362,14 +370,6 @@ int NewSort(PHEAD0)
362370
}
363371
if ( AR.sLevel == 0 ) {
364372

365-
#ifdef COUNTCOMPARES
366-
#ifdef WITHPTHREADS
367-
numcompares[AT.identity] = 0;
368-
#else
369-
numcompares[0] = 0;
370-
#endif
371-
#endif
372-
373373
AN.FunSorts[0] = AT.S0;
374374
if ( AR.PolyFun == 0 ) { AT.S0->PolyFlag = 0; }
375375
else if ( AR.PolyFunType == 1 ) { AT.S0->PolyFlag = 1; }
@@ -408,6 +408,12 @@ int NewSort(PHEAD0)
408408
409409
PUTZERO(AN.OldPosOut);
410410
*/
411+
// Zero the SortVerbose counters:
412+
S->verbComparisons = 0;
413+
S->verbSBsortTerms = 0;
414+
S->verbSBsortCap = 0;
415+
S->verbLBsortPatches = 0;
416+
S->verbLBsortCap = 0;
411417
return(0);
412418
}
413419

@@ -621,6 +627,10 @@ LONG EndSort(PHEAD WORD *buffer, int par)
621627
/*
622628
The large buffer is too full. Merge and write it
623629
*/
630+
// Update SortVerbose counters
631+
if ( S->lPatch >= S->MaxPatches ) S->verbLBsortPatches++;
632+
else S->verbLBsortCap++;
633+
624634
#ifdef GZIPDEBUG
625635
MLOCK(ErrorMessageLock);
626636
MesPrint("%w EndSort: lPatch = %d, MaxPatches = %d,lFill = %x, sSpace = %ld, MaxTer = %d, lTop = %x"
@@ -977,18 +987,6 @@ LONG EndSort(PHEAD WORD *buffer, int par)
977987
}
978988
}
979989

980-
#ifdef COUNTCOMPARES
981-
if ( AR.sLevel < 0 ) {
982-
#ifdef WITHPTHREADS
983-
MLOCK(ErrorMessageLock);
984-
MesPrint(">>>number of calls to Compare: %l (tid %d)", numcompares[AT.identity], AT.identity);
985-
MUNLOCK(ErrorMessageLock);
986-
#else
987-
MesPrint(">>>number of calls to Compare: %l", numcompares[0]);
988-
#endif
989-
}
990-
#endif
991-
992990
return(retval);
993991
WorkSpaceError:
994992
MLOCK(ErrorMessageLock);
@@ -2344,15 +2342,10 @@ WORD Compare1(PHEAD WORD *term1, WORD *term2, WORD level)
23442342
WORD prevorder;
23452343
WORD count = -1, localPoly, polyhit = -1;
23462344

2347-
#ifdef COUNTCOMPARES
23482345
if ( AR.sLevel == 0 ) {
2349-
#ifdef WITHPTHREADS
2350-
numcompares[AT.identity]++;
2351-
#else
2352-
numcompares[0]++;
2353-
#endif
2346+
// Update SortVerbose counter at ground level only
2347+
S->verbComparisons++;
23542348
}
2355-
#endif
23562349

23572350
if ( S->PolyFlag ) {
23582351
/*
@@ -4266,6 +4259,10 @@ int StoreTerm(PHEAD WORD *term)
42664259
/*
42674260
The small buffer is full. It has to be sorted and written.
42684261
*/
4262+
// Update SortVerbose counters
4263+
if ( S->sTerms >= S->TermsInSmall ) S->verbSBsortTerms++;
4264+
else S->verbSBsortCap++;
4265+
42694266
tover = over = S->sTerms;
42704267
ss = S->sPointer;
42714268
ss[over] = 0;
@@ -4298,6 +4295,10 @@ int StoreTerm(PHEAD WORD *term)
42984295
/*
42994296
The large buffer is too full. Merge and write it
43004297
*/
4298+
// Update SortVerbose counters
4299+
if ( S->lPatch >= S->MaxPatches ) S->verbLBsortPatches++;
4300+
else S->verbLBsortCap++;
4301+
43014302
if ( MergePatches(1) ) goto StoreCall;
43024303
/*
43034304
pp = S->SizeInFile[1];

sources/structs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,11 @@ typedef struct sOrT {
11561156
LONG SpaceLeft; /* Space needed for still existing terms */
11571157
LONG putinsize; /* Size of buffer in putin */
11581158
LONG ninterms; /* Which input term ? */
1159+
LONG verbComparisons; /* Counters for "On SortVerbose;" statistics */
1160+
LONG verbSBsortTerms;
1161+
LONG verbSBsortCap;
1162+
LONG verbLBsortPatches;
1163+
LONG verbLBsortCap;
11591164
int MaxPatches; /* Maximum number of patches in large buffer */
11601165
int MaxFpatches; /* Maximum number of patches in one filesort */
11611166
int type; /* Main, function or sub(routine) */
@@ -1826,6 +1831,7 @@ struct C_const {
18261831
int FlintPolyFlag; /* Use Flint for polynomial arithmetic */
18271832
int HumanStatsFlag; /* Print human-readable stats in the stats print? */
18281833
int GrccVerbose; /* Enable extra print statements in grcc? */
1834+
int SortVerbose; /* Enable extra sort stats information? */
18291835
int doloopstacksize;
18301836
int dolooplevel;
18311837
int CheckpointFlag; /**< Tells preprocessor whether checkpoint code must executed.

sources/threads.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,6 +1987,8 @@ void *RunSortBot(void *dummy)
19871987
AT.SB.FillBlock = 1;
19881988
AT.SB.MasterFill[1] = AT.SB.MasterStart[1];
19891989
SETBASEPOSITION(AN.theposition,0);
1990+
// Reset the sortbot comparison count
1991+
AT.SS->verbComparisons = 0;
19901992
break;
19911993
/*
19921994
#] INISORTBOT :
@@ -4052,10 +4054,21 @@ int MasterMerge(void)
40524054
fin->handle = -1;
40534055
position = S->SizeInFile[0];
40544056
MULPOS(position,sizeof(WORD));
4057+
4058+
// Collect global sort statistics information from the threads.
4059+
// The total GenTerms is the sum of the thread GenTerms.
4060+
// The total small/large buffer sort info is the sum of the thread info.
4061+
// The total comparison count is the sum of the thread counts.
40554062
S->GenTerms = 0;
40564063
for ( j = 1; j <= numberofworkers; j++ ) {
40574064
S->GenTerms += AB[j]->T.SS->GenTerms;
4065+
S->verbComparisons += AB[j]->T.SS->verbComparisons;
4066+
S->verbSBsortTerms += AB[j]->T.SS->verbSBsortTerms;
4067+
S->verbSBsortCap += AB[j]->T.SS->verbSBsortCap;
4068+
S->verbLBsortPatches += AB[j]->T.SS->verbLBsortPatches;
4069+
S->verbLBsortCap += AB[j]->T.SS->verbLBsortCap;
40584070
}
4071+
40594072
WriteStats(&position,STATSPOSTSORT,NOCHECKLOGTYPE);
40604073
Expressions[AR0.CurExpr].counter = S->TermsLeft;
40614074
Expressions[AR0.CurExpr].size = position;
@@ -4193,10 +4206,24 @@ int SortBotMasterMerge(void)
41934206
}
41944207
position = S->SizeInFile[0];
41954208
MULPOS(position,sizeof(WORD));
4209+
4210+
// Collect global sort statistics information from the threads.
4211+
// The total GenTerms is the sum of the thread GenTerms.
4212+
// The total small/large buffer sort info is the sum of the thread info.
4213+
// The total comparison count is the sum of the thread and sortbot counts.
41964214
S->GenTerms = 0;
41974215
for ( j = 1; j <= numberofworkers; j++ ) {
41984216
S->GenTerms += AB[j]->T.SS->GenTerms;
4217+
S->verbComparisons += AB[j]->T.SS->verbComparisons;
4218+
S->verbSBsortTerms += AB[j]->T.SS->verbSBsortTerms;
4219+
S->verbSBsortCap += AB[j]->T.SS->verbSBsortCap;
4220+
S->verbLBsortPatches += AB[j]->T.SS->verbLBsortPatches;
4221+
S->verbLBsortCap += AB[j]->T.SS->verbLBsortCap;
41994222
}
4223+
for ( j = numberofworkers+1; j <= numberofworkers+numberofsortbots; j++ ) {
4224+
S->verbComparisons += AB[j]->T.SS->verbComparisons;
4225+
}
4226+
42004227
S->TermsLeft = numberofterms;
42014228
WriteStats(&position,STATSPOSTSORT,NOCHECKLOGTYPE);
42024229
Expressions[AR.CurExpr].counter = S->TermsLeft;

0 commit comments

Comments
 (0)