Skip to content

Commit bec3258

Browse files
committed
Remove printf from ordering heuristics
1 parent a3a1f2f commit bec3258

File tree

21 files changed

+167
-197
lines changed

21 files changed

+167
-197
lines changed

cmake/sources.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ set(hipo_util_headers
254254
ipm/hipo/auxiliary/KrylovMethods.h
255255
ipm/hipo/auxiliary/Log.h
256256
ipm/hipo/auxiliary/mycblas.h
257+
ipm/hipo/auxiliary/OrderingPrint.h
257258
ipm/hipo/auxiliary/VectorOperations.h)
258259

259260
set(hipo_orderings_sources

extern/amd/SuiteSparse_config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
//------------------------------------------------------------------------------
1010

11-
/* SuiteSparse configuration : memory manager and printf functions.
11+
/* SuiteSparse configuration : memory manager
1212
*/
1313

1414
#include "SuiteSparse_config.h"

extern/amd/amd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ void Highs_amd_info (double Info [ ]) ;
341341
* This also works during compile-time:
342342
*
343343
* #if defined(AMD_VERSION) && (AMD_VERSION >= AMD_VERSION_CODE (1,2))
344-
* printf ("This is version 1.2 or later\n") ;
344+
* // This is version 1.2 or later
345345
* #else
346-
* printf ("This is an early version\n") ;
346+
* // This is an early version
347347
* #endif
348348
*
349349
* Versions 1.1 and earlier of AMD do not include a #define'd version number.

extern/amd/amd_control.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
#include "amd_internal.h"
17+
#include "ipm/hipo/auxiliary/OrderingPrint.h"
1718

1819
void Highs_amd_control
1920
(
@@ -34,31 +35,31 @@ void Highs_amd_control
3435
aggressive = AMD_DEFAULT_AGGRESSIVE ;
3536
}
3637

37-
printf (
38+
HIGHS_ORDERING_PRINT ((
3839
"\nAMD version %d.%d.%d, %s: approximate minimum degree ordering\n"
3940
" dense row parameter: %g\n", AMD_MAIN_VERSION, AMD_SUB_VERSION,
40-
AMD_SUBSUB_VERSION, AMD_DATE, alpha) ;
41+
AMD_SUBSUB_VERSION, AMD_DATE, alpha)) ;
4142

4243
if (alpha < 0)
4344
{
44-
printf (" no rows treated as dense\n") ;
45+
HIGHS_ORDERING_PRINT ((" no rows treated as dense\n")) ;
4546
}
4647
else
4748
{
48-
printf (
49+
HIGHS_ORDERING_PRINT ((
4950
" (rows with more than max (%g * sqrt (n), 16) entries are\n"
5051
" considered \"dense\", and placed last in output permutation)\n",
51-
alpha) ;
52+
alpha)) ;
5253
}
5354

5455
if (aggressive)
5556
{
56-
printf (" aggressive absorption: yes\n") ;
57+
HIGHS_ORDERING_PRINT ((" aggressive absorption: yes\n")) ;
5758
}
5859
else
5960
{
60-
printf (" aggressive absorption: no\n") ;
61+
HIGHS_ORDERING_PRINT ((" aggressive absorption: no\n")) ;
6162
}
6263

63-
printf (" size of AMD integer: %lu\n\n", sizeof (amd_int)) ;
64+
HIGHS_ORDERING_PRINT ((" size of AMD integer: %lu\n\n", sizeof (amd_int))) ;
6465
}

extern/amd/amd_info.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
*/
1414

1515
#include "amd_internal.h"
16+
#include "ipm/hipo/auxiliary/OrderingPrint.h"
1617

17-
#define PRI(format,x) { if (x >= 0) { printf (format, x) ; }}
18+
#define PRI(format,x) { if (x >= 0) { HIGHS_ORDERING_PRINT ((format, x)) ; }}
1819

1920
void Highs_amd_info
2021
(
@@ -23,8 +24,8 @@ void Highs_amd_info
2324
{
2425
double n, ndiv, nmultsubs_ldl, nmultsubs_lu, lnz, lnzd ;
2526

26-
printf ("\nAMD version %d.%d.%d, %s, results:\n",
27-
AMD_MAIN_VERSION, AMD_SUB_VERSION, AMD_SUBSUB_VERSION, AMD_DATE) ;
27+
HIGHS_ORDERING_PRINT (("\nAMD version %d.%d.%d, %s, results:\n",
28+
AMD_MAIN_VERSION, AMD_SUB_VERSION, AMD_SUBSUB_VERSION, AMD_DATE)) ;
2829

2930
if (!Info)
3031
{
@@ -39,26 +40,26 @@ void Highs_amd_info
3940
lnzd = (n >= 0 && lnz >= 0) ? (n + lnz) : (-1) ;
4041

4142
/* AMD return status */
42-
printf (" status: ") ;
43+
HIGHS_ORDERING_PRINT ((" status: ")) ;
4344
if (Info [AMD_STATUS] == AMD_OK)
4445
{
45-
printf ("OK\n") ;
46+
HIGHS_ORDERING_PRINT (("OK\n")) ;
4647
}
4748
else if (Info [AMD_STATUS] == AMD_OUT_OF_MEMORY)
4849
{
49-
printf ("out of memory\n") ;
50+
HIGHS_ORDERING_PRINT (("out of memory\n")) ;
5051
}
5152
else if (Info [AMD_STATUS] == AMD_INVALID)
5253
{
53-
printf ("invalid matrix\n") ;
54+
HIGHS_ORDERING_PRINT (("invalid matrix\n")) ;
5455
}
5556
else if (Info [AMD_STATUS] == AMD_OK_BUT_JUMBLED)
5657
{
57-
printf ("OK, but jumbled\n") ;
58+
HIGHS_ORDERING_PRINT (("OK, but jumbled\n")) ;
5859
}
5960
else
6061
{
61-
printf ("unknown\n") ;
62+
HIGHS_ORDERING_PRINT (("unknown\n")) ;
6263
}
6364

6465
/* statistics about the input matrix */
@@ -81,11 +82,11 @@ void Highs_amd_info
8182
Info [AMD_NCMPA]) ;
8283

8384
/* statistics about the ordering quality */
84-
printf ("\n"
85+
HIGHS_ORDERING_PRINT (("\n"
8586
" The following approximate statistics are for a subsequent\n"
8687
" factorization of A(P,P) + A(P,P)'. They are slight upper\n"
8788
" bounds if there are no dense rows/columns in A+A', and become\n"
88-
" looser if dense rows/columns exist.\n\n") ;
89+
" looser if dense rows/columns exist.\n\n")) ;
8990

9091
PRI (" nonzeros in L (excluding diagonal): %.20g\n",
9192
lnz) ;
@@ -104,7 +105,7 @@ void Highs_amd_info
104105

105106
if (n >= 0 && ndiv >= 0 && nmultsubs_ldl >= 0 && nmultsubs_lu >= 0)
106107
{
107-
printf ("\n"
108+
HIGHS_ORDERING_PRINT (("\n"
108109
" chol flop count for real A, sqrt counted as 1 flop: %.20g\n"
109110
" LDL' flop count for real A: %.20g\n"
110111
" LDL' flop count for complex A: %.20g\n"
@@ -114,6 +115,6 @@ void Highs_amd_info
114115
ndiv + 2*nmultsubs_ldl,
115116
9*ndiv + 8*nmultsubs_ldl,
116117
ndiv + 2*nmultsubs_lu,
117-
9*ndiv + 8*nmultsubs_lu) ;
118+
9*ndiv + 8*nmultsubs_lu)) ;
118119
}
119120
}

extern/metis/GKlib/error.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,5 @@ This file contains functions dealing with error reporting and termination
1717
/*************************************************************************/
1818
void gk_errexit(char *f_str,...)
1919
{
20-
va_list argp;
21-
22-
va_start(argp, f_str);
23-
vfprintf(stderr, f_str, argp);
24-
va_end(argp);
25-
26-
fprintf(stderr,"\n");
27-
fflush(stderr);
28-
2920
abort();
3021
}

extern/metis/GKlib/gk_macros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/*-------------------------------------------------------------
2626
* dbglvl handling macros
2727
*-------------------------------------------------------------*/
28-
#define IFSET(a, flag, cmd) if ((a)&(flag)) (cmd);
28+
#define IFSET(a, flag, cmd) if ((a)&(flag)) cmd ;
2929

3030
/*-------------------------------------------------------------
3131
* CSR conversion macros

extern/metis/GKlib/gk_proto.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef _GK_PROTO_H_
1111
#define _GK_PROTO_H_
1212

13+
#include "ipm/hipo/auxiliary/OrderingPrint.h"
14+
1315
#ifdef __cplusplus
1416
extern "C" {
1517
#endif
@@ -23,6 +25,7 @@ void gk_free(void **ptr1);
2325
* error.c
2426
*-------------------------------------------------------------*/
2527
void gk_errexit(char *,...);
28+
#define GK_ERREXIT(params) { HIGHS_ORDERING_PRINT(params) ; abort(); }
2629

2730
/*-------------------------------------------------------------
2831
* random.c

extern/metis/GKlib/mcore.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ void *gk_mcoreMalloc(gk_mcore_t *mcore, size_t nbytes)
7979
gk_mcoreAdd(mcore, GK_MOPT_HEAP, nbytes, ptr);
8080
}
8181

82-
/*
83-
printf("MCMALLOC: %zu %d %8zu\n", mcore->cmop-1,
84-
mcore->mops[mcore->cmop-1].type, mcore->mops[mcore->cmop-1].nbytes);
85-
*/
86-
8782
return ptr;
8883
}
8984

@@ -96,7 +91,6 @@ void *gk_mcoreMalloc(gk_mcore_t *mcore, size_t nbytes)
9691
void gk_mcorePush(gk_mcore_t *mcore)
9792
{
9893
gk_mcoreAdd(mcore, GK_MOPT_MARK, 0, NULL);
99-
/* printf("MCPPUSH: %zu\n", mcore->cmop-1); */
10094
}
10195

10296

@@ -115,8 +109,8 @@ void gk_mcorePop(gk_mcore_t *mcore)
115109

116110
case GK_MOPT_CORE: /* core free */
117111
if (mcore->corecpos < mcore->mops[mcore->cmop].nbytes)
118-
gk_errexit("Internal Error: wspace's core is about to be over-freed [%zu, %zu, %zd]\n",
119-
mcore->coresize, mcore->corecpos, mcore->mops[mcore->cmop].nbytes);
112+
GK_ERREXIT(("Internal Error: wspace's core is about to be over-freed [%zu, %zu, %zd]\n",
113+
mcore->coresize, mcore->corecpos, mcore->mops[mcore->cmop].nbytes));
120114

121115
mcore->corecpos -= mcore->mops[mcore->cmop].nbytes;
122116
break;
@@ -126,13 +120,12 @@ void gk_mcorePop(gk_mcore_t *mcore)
126120
break;
127121

128122
default:
129-
gk_errexit("Unknown mop type of %d\n", mcore->mops[mcore->cmop].type);
123+
GK_ERREXIT(("Unknown mop type of %d\n", mcore->mops[mcore->cmop].type));
130124
}
131125
}
132126

133127
DONE:
134128
;
135-
/*printf("MCPPOP: %zu\n", mcore->cmop); */
136129
}
137130

138131

@@ -146,7 +139,7 @@ void gk_mcoreAdd(gk_mcore_t *mcore, int type, size_t nbytes, void *ptr)
146139
mcore->nmops *= 2;
147140
mcore->mops = realloc(mcore->mops, mcore->nmops*sizeof(gk_mop_t));
148141
if (mcore->mops == NULL)
149-
gk_errexit("***Memory allocation for gkmcore failed.\n");
142+
GK_ERREXIT(("***Memory allocation for gkmcore failed.\n"));
150143
}
151144

152145
mcore->mops[mcore->cmop].type = type;
@@ -167,17 +160,17 @@ void gk_mcoreDel(gk_mcore_t *mcore, void *ptr)
167160

168161
for (i=mcore->cmop-1; i>=0; i--) {
169162
if (mcore->mops[i].type == GK_MOPT_MARK)
170-
gk_errexit("Could not find pointer %p in mcore\n", ptr);
163+
GK_ERREXIT(("Could not find pointer %p in mcore\n", ptr));
171164

172165
if (mcore->mops[i].ptr == ptr) {
173166
if (mcore->mops[i].type != GK_MOPT_HEAP)
174-
gk_errexit("Trying to delete a non-HEAP mop.\n");
167+
GK_ERREXIT(("Trying to delete a non-HEAP mop.\n"));
175168

176169
mcore->mops[i] = mcore->mops[--mcore->cmop];
177170
return;
178171
}
179172
}
180173

181-
gk_errexit("mcoreDel should never have been here!\n");
174+
GK_ERREXIT(("mcoreDel should never have been here!\n"));
182175
}
183176

extern/metis/libmetis/balance.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ void Bnd2WayBalance(ctrl_t *ctrl, graph_t *graph, real_t *ntpwgts)
7373
to = (from+1)%2;
7474

7575
IFSET(ctrl->dbglvl, METIS_DBG_REFINE,
76-
printf("Partitions: [%6"PRIDX" %6"PRIDX"] T[%6"PRIDX" %6"PRIDX"], Nv-Nb[%6"PRIDX" %6"PRIDX"]. ICut: %6"PRIDX" [B]\n",
76+
HIGHS_ORDERING_PRINT(("Partitions: [%6"PRIDX" %6"PRIDX"] T[%6"PRIDX" %6"PRIDX"], Nv-Nb[%6"PRIDX" %6"PRIDX"]. ICut: %6"PRIDX" [B]\n",
7777
pwgts[0], pwgts[1], tpwgts[0], tpwgts[1], graph->nvtxs, graph->nbnd,
78-
graph->mincut));
78+
graph->mincut)));
7979

8080
queue = rpqCreate(nvtxs);
8181

@@ -106,7 +106,7 @@ void Bnd2WayBalance(ctrl_t *ctrl, graph_t *graph, real_t *ntpwgts)
106106
moved[higain] = nswaps;
107107

108108
IFSET(ctrl->dbglvl, METIS_DBG_MOVEINFO,
109-
printf("Moved %6"PRIDX" from %"PRIDX". [%3"PRIDX" %3"PRIDX"] %5"PRIDX" [%4"PRIDX" %4"PRIDX"]\n", higain, from, ed[higain]-id[higain], vwgt[higain], mincut, pwgts[0], pwgts[1]));
109+
HIGHS_ORDERING_PRINT(("Moved %6"PRIDX" from %"PRIDX". [%3"PRIDX" %3"PRIDX"] %5"PRIDX" [%4"PRIDX" %4"PRIDX"]\n", higain, from, ed[higain]-id[higain], vwgt[higain], mincut, pwgts[0], pwgts[1])));
110110

111111
/**************************************************************
112112
* Update the id[i]/ed[i] values of the affected nodes
@@ -143,7 +143,7 @@ void Bnd2WayBalance(ctrl_t *ctrl, graph_t *graph, real_t *ntpwgts)
143143
}
144144

145145
IFSET(ctrl->dbglvl, METIS_DBG_REFINE,
146-
printf("\tMinimum cut: %6"PRIDX", PWGTS: [%6"PRIDX" %6"PRIDX"], NBND: %6"PRIDX"\n", mincut, pwgts[0], pwgts[1], nbnd));
146+
HIGHS_ORDERING_PRINT(("\tMinimum cut: %6"PRIDX", PWGTS: [%6"PRIDX" %6"PRIDX"], NBND: %6"PRIDX"\n", mincut, pwgts[0], pwgts[1], nbnd)));
147147

148148
graph->mincut = mincut;
149149
graph->nbnd = nbnd;
@@ -197,8 +197,8 @@ void General2WayBalance(ctrl_t *ctrl, graph_t *graph, real_t *ntpwgts)
197197
to = (from+1)%2;
198198

199199
IFSET(ctrl->dbglvl, METIS_DBG_REFINE,
200-
printf("Partitions: [%6"PRIDX" %6"PRIDX"] T[%6"PRIDX" %6"PRIDX"], Nv-Nb[%6"PRIDX" %6"PRIDX"]. ICut: %6"PRIDX" [B]\n",
201-
pwgts[0], pwgts[1], tpwgts[0], tpwgts[1], graph->nvtxs, graph->nbnd, graph->mincut));
200+
HIGHS_ORDERING_PRINT(("Partitions: [%6"PRIDX" %6"PRIDX"] T[%6"PRIDX" %6"PRIDX"], Nv-Nb[%6"PRIDX" %6"PRIDX"]. ICut: %6"PRIDX" [B]\n",
201+
pwgts[0], pwgts[1], tpwgts[0], tpwgts[1], graph->nvtxs, graph->nbnd, graph->mincut)));
202202

203203
queue = rpqCreate(nvtxs);
204204

@@ -229,7 +229,7 @@ void General2WayBalance(ctrl_t *ctrl, graph_t *graph, real_t *ntpwgts)
229229
moved[higain] = nswaps;
230230

231231
IFSET(ctrl->dbglvl, METIS_DBG_MOVEINFO,
232-
printf("Moved %6"PRIDX" from %"PRIDX". [%3"PRIDX" %3"PRIDX"] %5"PRIDX" [%4"PRIDX" %4"PRIDX"]\n", higain, from, ed[higain]-id[higain], vwgt[higain], mincut, pwgts[0], pwgts[1]));
232+
HIGHS_ORDERING_PRINT(("Moved %6"PRIDX" from %"PRIDX". [%3"PRIDX" %3"PRIDX"] %5"PRIDX" [%4"PRIDX" %4"PRIDX"]\n", higain, from, ed[higain]-id[higain], vwgt[higain], mincut, pwgts[0], pwgts[1])));
233233

234234
/**************************************************************
235235
* Update the id[i]/ed[i] values of the affected nodes
@@ -259,7 +259,7 @@ void General2WayBalance(ctrl_t *ctrl, graph_t *graph, real_t *ntpwgts)
259259
}
260260

261261
IFSET(ctrl->dbglvl, METIS_DBG_REFINE,
262-
printf("\tMinimum cut: %6"PRIDX", PWGTS: [%6"PRIDX" %6"PRIDX"], NBND: %6"PRIDX"\n", mincut, pwgts[0], pwgts[1], nbnd));
262+
HIGHS_ORDERING_PRINT(("\tMinimum cut: %6"PRIDX", PWGTS: [%6"PRIDX" %6"PRIDX"], NBND: %6"PRIDX"\n", mincut, pwgts[0], pwgts[1], nbnd)));
263263

264264
graph->mincut = mincut;
265265
graph->nbnd = nbnd;
@@ -351,12 +351,12 @@ void McGeneral2WayBalance(ctrl_t *ctrl, graph_t *graph, real_t *ntpwgts)
351351
mincutorder = -1;
352352

353353
if (ctrl->dbglvl&METIS_DBG_REFINE) {
354-
printf("Parts: [");
354+
HIGHS_ORDERING_PRINT(("Parts: ["));
355355
for (l=0; l<ncon; l++)
356-
printf("(%6"PRIDX" %6"PRIDX" %.3"PRREAL" %.3"PRREAL") ",
357-
pwgts[l], pwgts[ncon+l], ntpwgts[l], ntpwgts[ncon+l]);
358-
printf("] Nv-Nb[%5"PRIDX", %5"PRIDX"]. ICut: %6"PRIDX", LB: %+.3"PRREAL" [B]\n",
359-
graph->nvtxs, graph->nbnd, graph->mincut, minbal);
356+
HIGHS_ORDERING_PRINT(("(%6"PRIDX" %6"PRIDX" %.3"PRREAL" %.3"PRREAL") ",
357+
pwgts[l], pwgts[ncon+l], ntpwgts[l], ntpwgts[ncon+l]));
358+
HIGHS_ORDERING_PRINT(("] Nv-Nb[%5"PRIDX", %5"PRIDX"]. ICut: %6"PRIDX", LB: %+.3"PRREAL" [B]\n",
359+
graph->nvtxs, graph->nbnd, graph->mincut, minbal));
360360
}
361361

362362
iset(nvtxs, -1, moved);
@@ -406,11 +406,11 @@ void McGeneral2WayBalance(ctrl_t *ctrl, graph_t *graph, real_t *ntpwgts)
406406
swaps[nswaps] = higain;
407407

408408
if (ctrl->dbglvl&METIS_DBG_MOVEINFO) {
409-
printf("Moved %6"PRIDX" from %"PRIDX"(%"PRIDX"). Gain: %5"PRIDX", "
410-
"Cut: %5"PRIDX", NPwgts: ", higain, from, cnum, ed[higain]-id[higain], newcut);
409+
HIGHS_ORDERING_PRINT(("Moved %6"PRIDX" from %"PRIDX"(%"PRIDX"). Gain: %5"PRIDX", "
410+
"Cut: %5"PRIDX", NPwgts: ", higain, from, cnum, ed[higain]-id[higain], newcut));
411411
for (l=0; l<ncon; l++)
412-
printf("(%6"PRIDX", %6"PRIDX") ", pwgts[l], pwgts[ncon+l]);
413-
printf(", %+.3"PRREAL" LB: %+.3"PRREAL"\n", minbal, newbal);
412+
HIGHS_ORDERING_PRINT(("(%6"PRIDX", %6"PRIDX") ", pwgts[l], pwgts[ncon+l]));
413+
HIGHS_ORDERING_PRINT((", %+.3"PRREAL" LB: %+.3"PRREAL"\n", minbal, newbal));
414414
}
415415

416416

@@ -472,11 +472,11 @@ void McGeneral2WayBalance(ctrl_t *ctrl, graph_t *graph, real_t *ntpwgts)
472472
}
473473

474474
if (ctrl->dbglvl&METIS_DBG_REFINE) {
475-
printf("\tMincut: %6"PRIDX" at %5"PRIDX", NBND: %6"PRIDX", NPwgts: [",
476-
mincut, mincutorder, nbnd);
475+
HIGHS_ORDERING_PRINT(("\tMincut: %6"PRIDX" at %5"PRIDX", NBND: %6"PRIDX", NPwgts: [",
476+
mincut, mincutorder, nbnd));
477477
for (l=0; l<ncon; l++)
478-
printf("(%6"PRIDX", %6"PRIDX") ", pwgts[l], pwgts[ncon+l]);
479-
printf("], LB: %.3"PRREAL"\n", ComputeLoadImbalance(graph, 2, ctrl->pijbm));
478+
HIGHS_ORDERING_PRINT(("(%6"PRIDX", %6"PRIDX") ", pwgts[l], pwgts[ncon+l]));
479+
HIGHS_ORDERING_PRINT(("], LB: %.3"PRREAL"\n", ComputeLoadImbalance(graph, 2, ctrl->pijbm)));
480480
}
481481

482482
graph->mincut = mincut;

0 commit comments

Comments
 (0)