12 #define OMPMINOPS 50000 86 int isfvwgts,
int isfvsizes)
89 size_t nfields, nvtxs, nedges, fmt,
ncon, lnlen;
92 int readsizes=0, readwgts=0, readvals=0, numbering=0;
102 fpin =
gk_fopen(filename,
"r",
"gk_graph_Read: fpin");
106 }
while (line[0] ==
'%');
109 nfields = sscanf(line,
"%zu %zu %zu %zu", &nvtxs, &nedges, &fmt, &ncon);
111 gk_errexit(
SIGERR,
"Header line must contain at least 2 integers (#vtxs and #edges).\n");
116 gk_errexit(
SIGERR,
"Cannot read this type of file format [fmt=%zu]!\n", fmt);
118 sprintf(fmtstr,
"%03zu", fmt%1000);
119 readsizes = (fmtstr[0] ==
'1');
120 readwgts = (fmtstr[1] ==
'1');
121 readvals = (fmtstr[2] ==
'1');
123 ncon = (ncon == 0 ? 1 :
ncon);
131 graph->
nvtxs = nvtxs;
133 graph->
xadj = gk_zmalloc(nvtxs+1,
"gk_graph_Read: xadj");
134 graph->
adjncy = gk_i32malloc(nedges,
"gk_graph_Read: adjncy");
137 graph->
fadjwgt = gk_fmalloc(nedges,
"gk_graph_Read: fadjwgt");
139 graph->
iadjwgt = gk_i32malloc(nedges,
"gk_graph_Read: iadjwgt");
144 graph->
fvsizes = gk_fmalloc(nvtxs,
"gk_graph_Read: fvsizes");
146 graph->
ivsizes = gk_i32malloc(nvtxs,
"gk_graph_Read: ivsizes");
151 graph->
fvwgts = gk_fmalloc(nvtxs*ncon,
"gk_graph_Read: fvwgts");
153 graph->
ivwgts = gk_i32malloc(nvtxs*ncon,
"gk_graph_Read: ivwgts");
160 numbering = (numbering ? - 1 : 0);
161 for (graph->
xadj[0]=0, k=0, i=0; i<nvtxs; i++) {
164 gk_errexit(
SIGERR,
"Pregraphure end of input file: file while reading row %d\n", i);
165 }
while (line[0] ==
'%');
176 graph->
fvsizes[
i] = strtof(head, &tail);
179 gk_errexit(
SIGERR,
"The line for vertex %zd does not have size information\n", i+1);
184 graph->
ivsizes[
i] = strtol(head, &tail, 0);
186 gk_errexit(
SIGERR,
"The line for vertex %zd does not have size information\n", i+1);
195 for (l=0; l<
ncon; l++) {
200 graph->
fvwgts[i*ncon+
l] = strtof(head, &tail);
204 "for the %d constraints.\n", i+1, ncon);
205 if (graph->
fvwgts[i*ncon+l] < 0)
206 gk_errexit(
SIGERR,
"The weight vertex %zd and constraint %zd must be >= 0\n", i+1, l);
209 graph->
ivwgts[i*ncon+
l] = strtol(head, &tail, 0);
212 "for the %d constraints.\n", i+1, ncon);
213 if (graph->
ivwgts[i*ncon+l] < 0)
214 gk_errexit(
SIGERR,
"The weight vertex %zd and constraint %zd must be >= 0\n", i+1, l);
223 ival = (
int)strtol(head, &tail, 0);
228 if ((graph->
adjncy[k] = ival + numbering) < 0)
229 gk_errexit(
SIGERR,
"Error: Invalid column number %d at row %zd.\n", ival, i);
234 fval = (
float)strtod(head, &tail);
236 fval = strtof(head, &tail);
239 gk_errexit(
SIGERR,
"Value could not be found for edge! Vertex:%zd, NNZ:%zd\n", i, k);
244 ival = strtol(head, &tail, 0);
246 gk_errexit(
SIGERR,
"Value could not be found for edge! Vertex:%zd, NNZ:%zd\n", i, k);
254 graph->
xadj[i+1] = k;
258 gk_errexit(
SIGERR,
"gk_graph_Read: Something wrong with the number of edges in " 259 "the input file. nedges=%zd, Actualnedges=%zd.\n", nedges, k);
280 int hasvwgts, hasvsizes, hasewgts;
287 fpout =
gk_fopen(filename,
"w",
"gk_graph_Write: fpout");
297 fprintf(fpout,
"%d %zd", graph->
nvtxs, graph->
xadj[graph->
nvtxs]/2);
298 if (hasvwgts || hasvsizes || hasewgts)
299 fprintf(fpout,
" %d%d%d", hasvsizes, hasvwgts, hasewgts);
300 fprintf(fpout,
"\n");
303 for (i=0; i<graph->
nvtxs; i++) {
306 fprintf(fpout,
" %d", graph->
ivsizes[i]);
308 fprintf(fpout,
" %f", graph->
fvsizes[i]);
313 fprintf(fpout,
" %d", graph->
ivwgts[i]);
315 fprintf(fpout,
" %f", graph->
fvwgts[i]);
318 for (j=graph->
xadj[i]; j<graph->
xadj[i+1]; j++) {
319 fprintf(fpout,
" %d", graph->
adjncy[j]+1);
322 fprintf(fpout,
" %d", graph->
iadjwgt[j]);
324 fprintf(fpout,
" %f", graph->
fadjwgt[j]);
327 fprintf(fpout,
"\n");
351 gk_zmalloc(graph->
nvtxs+1,
"gk_graph_Dup: xadj"));
354 gk_i32malloc(graph->
nvtxs,
"gk_graph_Dup: ivwgts"));
357 gk_i32malloc(graph->
nvtxs,
"gk_graph_Dup: ivsizes"));
360 gk_i32malloc(graph->
nvtxs,
"gk_graph_Dup: ivlabels"));
363 gk_fmalloc(graph->
nvtxs,
"gk_graph_Dup: fvwgts"));
366 gk_fmalloc(graph->
nvtxs,
"gk_graph_Dup: fvsizes"));
371 gk_i32malloc(graph->
xadj[graph->
nvtxs],
"gk_graph_Dup: adjncy"));
374 gk_i32malloc(graph->
xadj[graph->
nvtxs],
"gk_graph_Dup: iadjwgt"));
377 gk_fmalloc(graph->
xadj[graph->
nvtxs],
"gk_graph_Dup: fadjwgt"));
396 if (vstart+nvtxs > graph->
nvtxs)
401 ngraph->
nvtxs = nvtxs;
405 ngraph->
xadj = gk_zcopy(nvtxs+1, graph->
xadj+vstart,
406 gk_zmalloc(nvtxs+1,
"gk_graph_ExtractSubgraph: xadj"));
407 for (i=nvtxs; i>=0; i--)
412 ngraph->
ivwgts = gk_i32copy(nvtxs, graph->
ivwgts+vstart,
413 gk_i32malloc(nvtxs,
"gk_graph_ExtractSubgraph: ivwgts"));
416 gk_i32malloc(nvtxs,
"gk_graph_ExtractSubgraph: ivsizes"));
419 gk_i32malloc(nvtxs,
"gk_graph_ExtractSubgraph: vlabels"));
423 gk_fmalloc(nvtxs,
"gk_graph_ExtractSubgraph: fvwgts"));
426 gk_fmalloc(nvtxs,
"gk_graph_ExtractSubgraph: fvsizes"));
431 ngraph->
adjncy = gk_i32copy(graph->
xadj[vstart+nvtxs]-graph->
xadj[vstart],
433 gk_i32malloc(graph->
xadj[vstart+nvtxs]-graph->
xadj[vstart],
434 "gk_graph_ExtractSubgraph: adjncy"));
436 ngraph->
iadjwgt = gk_i32copy(graph->
xadj[vstart+nvtxs]-graph->
xadj[vstart],
438 gk_i32malloc(graph->
xadj[vstart+nvtxs]-graph->
xadj[vstart],
439 "gk_graph_ExtractSubgraph: iadjwgt"));
441 ngraph->
fadjwgt = gk_fcopy(graph->
xadj[vstart+nvtxs]-graph->
xadj[vstart],
443 gk_fmalloc(graph->
xadj[vstart+nvtxs]-graph->
xadj[vstart],
444 "gk_graph_ExtractSubgraph: fadjwgt"));
463 int i, k, u,
v, nvtxs;
464 int freeperm=0, freeiperm=0;
479 ngraph->
xadj = gk_zmalloc(nvtxs+1,
"gk_graph_Reorder: xadj");
482 ngraph->
ivwgts = gk_i32malloc(nvtxs,
"gk_graph_Reorder: ivwgts");
485 ngraph->
ivsizes = gk_i32malloc(nvtxs,
"gk_graph_Reorder: ivsizes");
488 ngraph->
vlabels = gk_i32malloc(nvtxs,
"gk_graph_Reorder: ivlabels");
491 ngraph->
fvwgts = gk_fmalloc(nvtxs,
"gk_graph_Reorder: fvwgts");
494 ngraph->
fvsizes = gk_fmalloc(nvtxs,
"gk_graph_Reorder: fvsizes");
498 ngraph->
adjncy = gk_i32malloc(graph->
xadj[nvtxs],
"gk_graph_Reorder: adjncy");
501 ngraph->
iadjwgt = gk_i32malloc(graph->
xadj[nvtxs],
"gk_graph_Reorder: iadjwgt");
504 ngraph->
fadjwgt = gk_fmalloc(graph->
xadj[nvtxs],
"gk_graph_Reorder: fadjwgt");
510 perm = gk_i32malloc(nvtxs,
"gk_graph_Reorder: perm");
511 for (i=0; i<nvtxs; i++)
516 iperm = gk_i32malloc(nvtxs,
"gk_graph_Reorder: iperm");
517 for (i=0; i<nvtxs; i++)
522 ngraph->
xadj[0] = jj = 0;
523 for (v=0; v<nvtxs; v++) {
525 for (j=xadj[u]; j<xadj[u+1]; j++, jj++) {
526 ngraph->
adjncy[jj] = perm[adjncy[
j]];
543 ngraph->
xadj[v+1] = jj;
577 int32_t mustfree_ccsr=0, mustfree_where=0;
579 nvtxs = graph->
nvtxs;
585 cptr = gk_i32malloc(nvtxs+1,
"gk_graph_FindComponents: cptr");
586 cind = gk_i32malloc(nvtxs,
"gk_graph_FindComponents: cind");
592 todo = gk_i32incset(nvtxs, 0, gk_i32malloc(nvtxs,
"gk_graph_FindComponents: todo"));
597 pos = gk_i32incset(nvtxs, 0, gk_i32malloc(nvtxs,
"gk_graph_FindComponents: pos"));
608 cptr[++ncmps] =
first;
610 ASSERT(pos[todo[0]] != -1);
624 j = todo[k] = todo[--ntodo];
627 for (j=xadj[i]; j<xadj[i+1]; j++) {
635 cptr[++ncmps] =
first;
672 if (graph->
nvtxs <= 0)
675 nvtxs = graph->
nvtxs;
680 pos = gk_i32incset(nvtxs, 0, gk_i32malloc(nvtxs,
"gk_graph_ComputeBFSOrdering: pos"));
686 cot = gk_i32incset(nvtxs, 0, gk_i32malloc(nvtxs,
"gk_graph_ComputeBFSOrdering: cot"));
695 while (first < nvtxs) {
704 for (j=xadj[i]; j<xadj[i+1]; j++) {
711 cot[pos[k]] = cot[
last];
713 pos[cot[
last]] = pos[k];
722 if (r_perm !=
NULL) {
724 for (i=0; i<nvtxs; i++)
731 if (r_iperm !=
NULL) {
770 if (graph->
nvtxs <= 0)
773 nvtxs = graph->
nvtxs;
778 degrees = gk_i32smalloc(nvtxs, 0,
"gk_graph_ComputeBestFOrdering: degrees");
781 minIDs = gk_i32smalloc(nvtxs, nvtxs+1,
"gk_graph_ComputeBestFOrdering: minIDs");
784 open = gk_i32malloc(nvtxs,
"gk_graph_ComputeBestFOrdering: open");
789 perm = gk_i32smalloc(nvtxs, -1,
"gk_graph_ComputeBestFOrdering: perm");
792 queue = gk_i32pqCreate(nvtxs);
793 for (i=0; i<nvtxs; i++)
794 gk_i32pqInsert(queue, i, 0);
795 gk_i32pqUpdate(queue, v, 1);
800 for (i=0; i<nvtxs; i++) {
801 if ((v = gk_i32pqGetTop(queue)) == -1)
802 gk_errexit(
SIGERR,
"The priority queue got empty ahead of time [i=%d].\n", i);
808 for (j=xadj[v]; j<xadj[v+1]; j++) {
812 minIDs[u] = (i < minIDs[u] ? i : minIDs[u]);
816 gk_i32pqUpdate(queue, u, 1);
819 gk_i32pqUpdate(queue, u, degrees[u]);
822 for (k=0, jj=xadj[u]; jj<xadj[u+1]; jj++) {
823 if (perm[adjncy[jj]] != -1)
824 k += perm[adjncy[jj]];
826 gk_i32pqUpdate(queue, u, k);
830 for (k=0, jj=xadj[u]; jj<xadj[u+1]; jj++) {
831 if (perm[adjncy[jj]] != -1)
832 k += (i-perm[adjncy[jj]]);
834 gk_i32pqUpdate(queue, u, k);
845 if (r_perm !=
NULL) {
850 if (r_iperm !=
NULL) {
852 for (i=0; i<nvtxs; i++)
853 degrees[perm[i]] = i;
862 gk_i32pqDestroy(queue);
863 gk_free((
void **)&perm, °rees, &minIDs, &open,
LTERM);
891 int i, k, u, nvtxs, nopen, ntodo;
895 if (graph->
nvtxs <= 0)
898 nvtxs = graph->
nvtxs;
903 degrees = gk_i32smalloc(nvtxs, 0,
"gk_graph_ComputeBestFOrdering: degrees");
906 wdegrees = gk_i32smalloc(nvtxs, 0,
"gk_graph_ComputeBestFOrdering: wdegrees");
909 sod = gk_i32smalloc(nvtxs, 0,
"gk_graph_ComputeBestFOrdering: sod");
912 level = gk_i32smalloc(nvtxs, 0,
"gk_graph_ComputeBestFOrdering: level");
918 ot = gk_i32incset(nvtxs, 0, gk_i32malloc(nvtxs,
"gk_graph_FindComponents: ot"));
921 pos = gk_i32incset(nvtxs, 0, gk_i32malloc(nvtxs,
"gk_graph_FindComponents: pos"));
924 perm = gk_i32smalloc(nvtxs, -1,
"gk_graph_ComputeBestFOrdering: perm");
927 queue = gk_i32pqCreate(nvtxs);
928 gk_i32pqInsert(queue, v, 1);
937 for (i=0; i<nvtxs; i++) {
939 gk_i32pqInsert(queue, ot[0], 1);
943 if ((v = gk_i32pqGetTop(queue)) == -1)
944 gk_errexit(
SIGERR,
"The priority queue got empty ahead of time [i=%d].\n", i);
953 gk_errexit(
SIGERR,
"The position of v is not in open list. pos[%d]=%d is >=%d.\n", v, pos[v], nopen);
956 ot[pos[
v]] = ot[nopen-1];
957 pos[ot[nopen-1]] = pos[
v];
959 ot[nopen-1] = ot[ntodo-1];
960 pos[ot[ntodo-1]] = nopen-1;
965 for (j=xadj[v]; j<xadj[v+1]; j++) {
970 if (degrees[u] == 0) {
971 ot[pos[u]] = ot[nopen];
972 pos[ot[nopen]] = pos[u];
977 level[u] = level[
v]+1;
978 gk_i32pqInsert(queue, u, 0);
988 gk_i32pqUpdate(queue, u, 1000*(i+1)+degrees[u]);
992 gk_i32pqUpdate(queue, u, degrees[u]);
997 gk_i32pqUpdate(queue, u, wdegrees[u]);
1006 gk_i32pqUpdate(queue, u, -(1000*level[u] - degrees[u]));
1010 gk_i32pqUpdate(queue, u, (i+1)*degrees[u]);
1020 for (j=0; j<nopen; j++) {
1023 gk_errexit(
SIGERR,
"For i=%d, the open list contains a closed vertex: ot[%zd]=%d, perm[%d]=%d.\n", i, j, u, u, perm[u]);
1024 sod[u] += degrees[u];
1025 if (i<1000 || i%25==0)
1026 gk_i32pqUpdate(queue, u, sod[u]);
1041 if (r_perm !=
NULL) {
1046 if (r_iperm !=
NULL) {
1048 for (i=0; i<nvtxs; i++)
1049 degrees[perm[i]] = i;
1058 gk_i32pqDestroy(queue);
1059 gk_free((
void **)&perm, °rees, &wdegrees, &sod, &ot, &pos, &level,
LTERM);
1090 if (graph->
nvtxs <= 0)
1093 nvtxs = graph->
nvtxs;
1097 inqueue = gk_i32smalloc(nvtxs, 0,
"gk_graph_SingleSourceShortestPaths: inqueue");
1107 queue = gk_i32pqCreate(nvtxs);
1108 gk_i32pqInsert(queue, v, 0);
1111 sps = gk_i32smalloc(nvtxs, -1,
"gk_graph_SingleSourceShortestPaths: sps");
1115 while ((v = gk_i32pqGetTop(queue)) != -1) {
1119 for (i=xadj[v]; i<xadj[v+1]; i++) {
1121 if (inqueue[u] == 2)
1124 if (sps[u] < 0 || sps[v]+adjwgt[i] < sps[u]) {
1125 sps[u] = sps[
v]+adjwgt[
i];
1128 gk_i32pqUpdate(queue, u, -sps[u]);
1130 gk_i32pqInsert(queue, u, -sps[u]);
1137 *r_sps = (
void *)sps;
1139 gk_i32pqDestroy(queue);
1148 queue = gk_fpqCreate(nvtxs);
1149 gk_fpqInsert(queue, v, 0);
1152 sps = gk_fsmalloc(nvtxs, -1,
"gk_graph_SingleSourceShortestPaths: sps");
1156 while ((v = gk_fpqGetTop(queue)) != -1) {
1160 for (i=xadj[v]; i<xadj[v+1]; i++) {
1162 if (inqueue[u] == 2)
1165 if (sps[u] < 0 || sps[v]+adjwgt[i] < sps[u]) {
1166 sps[u] = sps[
v]+adjwgt[
i];
1169 gk_fpqUpdate(queue, u, -sps[u]);
1171 gk_fpqInsert(queue, u, -sps[u]);
1178 *r_sps = (
void *)sps;
1180 gk_fpqDestroy(queue);
1209 ptr = graph->rowptr;
1210 ind = graph->rowind;
1211 val = graph->rowval;
1216 gk_errexit(
SIGERR,
"Column-based view of the graphrix does not exists.\n");
1219 ptr = graph->colptr;
1220 ind = graph->colind;
1221 val = graph->colval;
1229 #pragma omp parallel if (n > 100) 1237 nn =
gk_max(nn, ptr[i+1]-ptr[i]);
1239 cand = gk_ikvmalloc(nn,
"gk_graph_SortIndices: cand");
1240 tval = gk_fmalloc(nn,
"gk_graph_SortIndices: tval");
1242 #pragma omp for schedule(static) 1243 for (i=0; i<
n; i++) {
1244 for (k=0, j=ptr[i]; j<ptr[i+1]; j++) {
1245 if (j > ptr[i] && ind[j] < ind[j-1])
1247 cand[j-ptr[
i]].val = j-ptr[
i];
1248 cand[j-ptr[
i]].key = ind[
j];
1249 tval[j-ptr[
i]] = val[
j];
1253 for (j=ptr[i]; j<ptr[i+1]; j++) {
1254 ind[
j] = cand[j-ptr[
i]].key;
1255 val[
j] = tval[cand[j-ptr[
i]].val];
1281 ngraph->nrows = nrows;
1282 ngraph->ncols = graph->ncols;
1284 for (nnz=0, i=0; i<nrows; i++)
1285 nnz += graph->rowptr[rind[i]+1]-graph->rowptr[rind[i]];
1287 ngraph->rowptr = gk_zmalloc(ngraph->nrows+1,
"gk_graph_ExtractPartition: rowptr");
1288 ngraph->rowind = gk_imalloc(nnz,
"gk_graph_ExtractPartition: rowind");
1289 ngraph->rowval = gk_fmalloc(nnz,
"gk_graph_ExtractPartition: rowval");
1291 ngraph->rowptr[0] = 0;
1292 for (nnz=0, j=0, ii=0; ii<nrows; ii++) {
1294 gk_icopy(graph->rowptr[i+1]-graph->rowptr[i], graph->rowind+graph->rowptr[i], ngraph->rowind+nnz);
1295 gk_fcopy(graph->rowptr[i+1]-graph->rowptr[i], graph->rowval+graph->rowptr[i], ngraph->rowval+nnz);
1296 nnz += graph->rowptr[i+1]-graph->rowptr[
i];
1297 ngraph->rowptr[++
j] = nnz;
1299 ASSERT(j == ngraph->nrows);
1321 ngraph->ncols = graph->ncols;
1323 for (nnz=0, i=0; i<graph->nrows; i++) {
1324 if (
part[i] == pid) {
1326 nnz += graph->rowptr[i+1]-graph->rowptr[
i];
1330 ngraph->rowptr = gk_zmalloc(ngraph->nrows+1,
"gk_graph_ExtractPartition: rowptr");
1331 ngraph->rowind = gk_imalloc(nnz,
"gk_graph_ExtractPartition: rowind");
1332 ngraph->rowval = gk_fmalloc(nnz,
"gk_graph_ExtractPartition: rowval");
1334 ngraph->rowptr[0] = 0;
1335 for (nnz=0, j=0, i=0; i<graph->nrows; i++) {
1336 if (
part[i] == pid) {
1337 gk_icopy(graph->rowptr[i+1]-graph->rowptr[i], graph->rowind+graph->rowptr[i], ngraph->rowind+nnz);
1338 gk_fcopy(graph->rowptr[i+1]-graph->rowptr[i], graph->rowval+graph->rowptr[i], ngraph->rowval+nnz);
1339 nnz += graph->rowptr[i+1]-graph->rowptr[
i];
1340 ngraph->rowptr[++
j] = nnz;
1343 ASSERT(j == ngraph->nrows);
1369 nrows = graph->nrows;
1370 rowptr = graph->rowptr;
1371 rowind = graph->rowind;
1372 rowval = graph->rowval;
1374 ncolors = gk_imax(rowptr[nrows], color)+1;
1377 for (i=0; i<ncolors; i++) {
1379 sgraphs[
i]->nrows = graph->nrows;
1380 sgraphs[
i]->ncols = graph->ncols;
1381 sgraphs[
i]->rowptr = gk_zsmalloc(nrows+1, 0,
"gk_graph_Split: sgraphs[i]->rowptr");
1384 for (i=0; i<nrows; i++) {
1385 for (j=rowptr[i]; j<rowptr[i+1]; j++)
1386 sgraphs[color[j]]->rowptr[i]++;
1388 for (i=0; i<ncolors; i++)
1389 MAKECSR(j, nrows, sgraphs[i]->rowptr);
1391 for (i=0; i<ncolors; i++) {
1392 sgraphs[
i]->rowind = gk_imalloc(sgraphs[i]->rowptr[nrows],
"gk_graph_Split: sgraphs[i]->rowind");
1393 sgraphs[
i]->rowval = gk_fmalloc(sgraphs[i]->rowptr[nrows],
"gk_graph_Split: sgraphs[i]->rowval");
1396 for (i=0; i<nrows; i++) {
1397 for (j=rowptr[i]; j<rowptr[i+1]; j++) {
1398 sgraphs[color[
j]]->rowind[sgraphs[color[
j]]->rowptr[
i]] = rowind[
j];
1399 sgraphs[color[
j]]->rowval[sgraphs[color[
j]]->rowptr[
i]] = rowval[
j];
1400 sgraphs[color[
j]]->rowptr[
i]++;
1404 for (i=0; i<ncolors; i++)
1405 SHIFTCSR(j, nrows, sgraphs[i]->rowptr);
1433 int *rowind, *nrowind, *collen;
1434 float *rowval, *nrowval;
1439 nrows = ngraph->nrows = graph->nrows;
1440 ncols = ngraph->ncols = graph->ncols;
1442 rowptr = graph->rowptr;
1443 rowind = graph->rowind;
1444 rowval = graph->rowval;
1446 nrowptr = ngraph->rowptr = gk_zmalloc(nrows+1,
"gk_graph_Prune: nrowptr");
1447 nrowind = ngraph->rowind = gk_imalloc(rowptr[nrows],
"gk_graph_Prune: nrowind");
1448 nrowval = ngraph->rowval = gk_fmalloc(rowptr[nrows],
"gk_graph_Prune: nrowval");
1453 collen = gk_ismalloc(ncols, 0,
"gk_graph_Prune: collen");
1455 for (i=0; i<nrows; i++) {
1456 for (j=rowptr[i]; j<rowptr[i+1]; j++) {
1457 ASSERT(rowind[j] < ncols);
1458 collen[rowind[
j]]++;
1461 for (i=0; i<ncols; i++)
1462 collen[i] = (collen[i] >= minf && collen[i] <= maxf ? 1 : 0);
1465 for (nnz=0, i=0; i<nrows; i++) {
1466 for (j=rowptr[i]; j<rowptr[i+1]; j++) {
1467 if (collen[rowind[j]]) {
1468 nrowind[nnz] = rowind[
j];
1469 nrowval[nnz] = rowval[
j];
1480 for (nnz=0, i=0; i<nrows; i++) {
1481 if (rowptr[i+1]-rowptr[i] >= minf && rowptr[i+1]-rowptr[i] <= maxf) {
1482 for (j=rowptr[i]; j<rowptr[i+1]; j++, nnz++) {
1483 nrowind[nnz] = rowind[
j];
1484 nrowval[nnz] = rowval[
j];
1511 void gk_graph_Normalize(
gk_graph_t *graph,
int what,
int norm)
1520 ptr = graph->rowptr;
1521 val = graph->rowval;
1523 #pragma omp parallel if (ptr[n] > OMPMINOPS) 1525 #pragma omp for private(j,sum) schedule(static) 1526 for (i=0; i<
n; i++) {
1527 for (sum=0.0, j=ptr[i]; j<ptr[i+1]; j++){
1529 sum += val[
j]*val[
j];
1538 for (j=ptr[i]; j<ptr[i+1]; j++)
1548 ptr = graph->colptr;
1549 val = graph->colval;
1551 #pragma omp parallel if (ptr[n] > OMPMINOPS) 1553 #pragma omp for private(j,sum) schedule(static) 1554 for (i=0; i<
n; i++) {
1555 for (sum=0.0, j=ptr[i]; j<ptr[i+1]; j++)
1557 sum += val[
j]*val[
j];
1565 for (j=ptr[i]; j<ptr[i+1]; j++)
FILE * gk_fopen(char *, char *, const char *)
gk_graph_t * gk_graph_Read(char *filename, int format, int isfewgts, int isfvwgts, int isfvsizes)
void gk_ikvsorti(size_t, gk_ikv_t *)
constexpr int last(int, int result)
int gk_graph_FindComponents(gk_graph_t *graph, int32_t *cptr, int32_t *cind)
idx_t idx_t idx_t idx_t idx_t idx_t idx_t real_t real_t idx_t idx_t idx_t * part
void gk_graph_Free(gk_graph_t **graph)
EIGEN_DEVICE_FUNC SegmentReturnType tail(Index n)
This is the const version of tail(Index).
int gk_fexists(char *fname)
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
gk_graph_t * gk_graph_ExtractSubgraph(gk_graph_t *graph, int vstart, int nvtxs)
idx_t idx_t idx_t idx_t idx_t idx_t * iperm
void gk_errexit(int signum, char *f_str,...)
NonlinearFactorGraph graph
#define ASSERT(expression)
static const Line3 l(Rot3(), 1, 1)
gk_idx_t gk_getline(char **lineptr, size_t *n, FILE *stream)
#define GK_GRAPH_FMT_METIS
constexpr int first(int i)
Implementation details for constexpr functions.
void gk_graph_FreeContents(gk_graph_t *graph)
idx_t idx_t idx_t idx_t idx_t * perm
const mpreal cot(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
const mpreal sum(const mpreal tab[], const unsigned long int n, int &status, mp_rnd_t mode=mpreal::get_default_rnd())
void gk_graph_Init(gk_graph_t *graph)
void gk_graph_Write(gk_graph_t *graph, char *filename, int format)
#define SHIFTCSR(i, n, a)
idx_t idx_t idx_t idx_t idx_t idx_t * adjwgt
void * gk_malloc(size_t nbytes, char *msg)
void gk_free(void **ptr1,...)
void gk_graph_ComputeBestFOrdering(gk_graph_t *graph, int v, int type, int32_t **r_perm, int32_t **r_iperm)
gk_graph_t * gk_graph_Reorder(gk_graph_t *graph, int32_t *perm, int32_t *iperm)
EIGEN_DEVICE_FUNC SegmentReturnType head(Index n)
This is the const version of head(Index).
idx_t idx_t idx_t * adjncy
void gk_graph_SingleSourceShortestPaths(gk_graph_t *graph, int v, void **r_sps)
void gk_graph_ComputeBFSOrdering(gk_graph_t *graph, int v, int32_t **r_perm, int32_t **r_iperm)
gk_graph_t * gk_graph_Dup(gk_graph_t *graph)
gk_graph_t * gk_graph_Create()
void gk_graph_ComputeBestFOrdering0(gk_graph_t *graph, int v, int type, int32_t **r_perm, int32_t **r_iperm)