Skip to content

Commit 69dad23

Browse files
committed
feat: add "On SortVerbose;" for extra sort info
Add information to the final sort summaries (per thread and master) including the number of comparisons made, and the number of times the small and large buffers were sorted due to their capacities.
1 parent f1289ad commit 69dad23

4 files changed

Lines changed: 69 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: 35 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);
@@ -314,6 +308,19 @@ void WriteStats(POSITION *plspace, WORD par, WORD checkLogType)
314308
humanBytesText);
315309
MesPrint("%s", buf);
316310
}
311+
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+
}
317324
}
318325

319326
#ifdef WITHSTATS
@@ -363,14 +370,6 @@ int NewSort(PHEAD0)
363370
}
364371
if ( AR.sLevel == 0 ) {
365372

366-
#ifdef COUNTCOMPARES
367-
#ifdef WITHPTHREADS
368-
numcompares[AT.identity] = 0;
369-
#else
370-
numcompares[0] = 0;
371-
#endif
372-
#endif
373-
374373
AN.FunSorts[0] = AT.S0;
375374
if ( AR.PolyFun == 0 ) { AT.S0->PolyFlag = 0; }
376375
else if ( AR.PolyFunType == 1 ) { AT.S0->PolyFlag = 1; }
@@ -409,6 +408,12 @@ int NewSort(PHEAD0)
409408
410409
PUTZERO(AN.OldPosOut);
411410
*/
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;
412417
return(0);
413418
}
414419

@@ -622,6 +627,10 @@ LONG EndSort(PHEAD WORD *buffer, int par)
622627
/*
623628
The large buffer is too full. Merge and write it
624629
*/
630+
// Update SortVerbose counters
631+
if ( S->lPatch >= S->MaxPatches ) S->verbLBsortPatches++;
632+
else S->verbLBsortCap++;
633+
625634
#ifdef GZIPDEBUG
626635
MLOCK(ErrorMessageLock);
627636
MesPrint("%w EndSort: lPatch = %d, MaxPatches = %d,lFill = %x, sSpace = %ld, MaxTer = %d, lTop = %x"
@@ -978,18 +987,6 @@ LONG EndSort(PHEAD WORD *buffer, int par)
978987
}
979988
}
980989

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

2348-
#ifdef COUNTCOMPARES
23492345
if ( AR.sLevel == 0 ) {
2350-
#ifdef WITHPTHREADS
2351-
numcompares[AT.identity]++;
2352-
#else
2353-
numcompares[0]++;
2354-
#endif
2346+
// Update SortVerbose counter at ground level only
2347+
S->verbComparisons++;
23552348
}
2356-
#endif
23572349

23582350
if ( S->PolyFlag ) {
23592351
/*
@@ -4267,6 +4259,10 @@ int StoreTerm(PHEAD WORD *term)
42674259
/*
42684260
The small buffer is full. It has to be sorted and written.
42694261
*/
4262+
// Update SortVerbose counters
4263+
if ( S->sTerms >= S->TermsInSmall ) S->verbSBsortTerms++;
4264+
else S->verbSBsortCap++;
4265+
42704266
tover = over = S->sTerms;
42714267
ss = S->sPointer;
42724268
ss[over] = 0;
@@ -4299,6 +4295,10 @@ int StoreTerm(PHEAD WORD *term)
42994295
/*
43004296
The large buffer is too full. Merge and write it
43014297
*/
4298+
// Update SortVerbose counters
4299+
if ( S->lPatch >= S->MaxPatches ) S->verbLBsortPatches++;
4300+
else S->verbLBsortCap++;
4301+
43024302
if ( MergePatches(1) ) goto StoreCall;
43034303
/*
43044304
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)