int main ( int argc, char * argv[]) { FILE * fileptr; SCOTCH_Graph grafdat; SCOTCH_Num vertnbr; SCOTCH_Graph_64 grafdat_64; SCOTCH_Num_64 vertnbr_64; SCOTCH_errorProg (argv[0]); if (argc != 2) { SCOTCH_errorPrint ("usage: %s graph_file", argv[0]); exit (EXIT_FAILURE); } if ((SCOTCH_graphInit (&grafdat) != 0) || (SCOTCH_graphInit_64 (&grafdat_64) != 0)) { /* Initialize source graph */ SCOTCH_errorPrint ("main: cannot initialize graph"); exit (EXIT_FAILURE); } if ((fileptr = fopen (argv[1], "r")) == NULL) { SCOTCH_errorPrint ("main: cannot open file (1)"); exit (EXIT_FAILURE); } if (SCOTCH_graphLoad (&grafdat, fileptr, -1, 0) != 0) { /* Read source graph */ SCOTCH_errorPrint ("main: cannot load graph (1)"); exit (EXIT_FAILURE); } fclose (fileptr); if ((fileptr = fopen (argv[1], "r")) == NULL) { SCOTCH_errorPrint ("main: cannot open file (2)"); exit (EXIT_FAILURE); } if (SCOTCH_graphLoad_64 (&grafdat_64, fileptr, -1, 0) != 0) { /* Read source graph */ SCOTCH_errorPrint ("main: cannot load graph (2)"); exit (EXIT_FAILURE); } fclose (fileptr); SCOTCH_graphSize (&grafdat, &vertnbr, NULL); SCOTCH_graphSize_64 (&grafdat_64, &vertnbr_64, NULL); SCOTCH_graphExit (&grafdat); SCOTCH_graphExit_64 (&grafdat_64); exit (EXIT_SUCCESS); }
int main ( int argc, char * argv[]) { SCOTCH_Graph grafdat; SCOTCH_Strat stradat; SCOTCH_Num baseval; SCOTCH_Num partnbr; SCOTCH_Num partnum; SCOTCH_Num * restrict parttax; SCOTCH_Num vertnbr; SCOTCH_Num vertnum; SCOTCH_Num * verttab; SCOTCH_Num * vendtab; SCOTCH_Num * velotab; SCOTCH_Num * vlbltab; SCOTCH_Num * edgetax; SCOTCH_Num * restrict flagtab; SCOTCH_Num * restrict loadtab; SCOTCH_Num loadmin; SCOTCH_Num loadmax; SCOTCH_Num loadsum; double loadavg; FILE * fileptr; SCOTCH_errorProg (argv[0]); if ((argc < 4) || (argc > 5)) { SCOTCH_errorPrint ("usage: %s nparts input_source_graph_file output_mapping_file [strategy]", argv[0]); exit (EXIT_FAILURE); } if ((partnbr = (SCOTCH_Num) atoi (argv[1])) < 1) { SCOTCH_errorPrint ("main: invalid number of parts (\"%s\")", argv[1]); exit (EXIT_FAILURE); } if (SCOTCH_stratInit (&stradat) != 0) { SCOTCH_errorPrint ("main: cannot initialize strategy"); exit (EXIT_FAILURE); } if (argc == 5) { if (SCOTCH_stratGraphPartOvl (&stradat, argv[4]) != 0) { SCOTCH_errorPrint ("main: invalid user-provided strategy"); exit (EXIT_FAILURE); } } if (SCOTCH_graphInit (&grafdat) != 0) { SCOTCH_errorPrint ("main: cannot initialize graph"); exit (EXIT_FAILURE); } if ((fileptr = fopen (argv[2], "r")) == NULL) { SCOTCH_errorPrint ("main: cannot open file (1)"); exit (EXIT_FAILURE); } if (SCOTCH_graphLoad (&grafdat, fileptr, -1, 0) != 0) { SCOTCH_errorPrint ("main: cannot load graph"); exit (EXIT_FAILURE); } fclose (fileptr); SCOTCH_graphData (&grafdat, &baseval, &vertnbr, &verttab, &vendtab, &velotab, &vlbltab, NULL, &edgetax, NULL); if (((parttax = malloc (vertnbr * sizeof (SCOTCH_Num))) == NULL) || ((flagtab = malloc (partnbr * sizeof (SCOTCH_Num))) == NULL) || ((loadtab = malloc (partnbr * sizeof (SCOTCH_Num))) == NULL)) { SCOTCH_errorPrint ("main: out of memory"); exit (EXIT_FAILURE); } if (SCOTCH_graphPartOvl (&grafdat, partnbr, &stradat, parttax) != 0) { /* Parttax is not based yet */ SCOTCH_errorPrint ("main: cannot compute mapping"); exit (EXIT_FAILURE); } edgetax -= baseval; parttax -= baseval; memset (loadtab, 0, partnbr * sizeof (SCOTCH_Num)); /* Part loads set to 0 */ memset (flagtab, ~0, partnbr * sizeof (SCOTCH_Num)); /* Flags set to invalid vertex number */ for (vertnum = 0; vertnum < vertnbr; vertnum ++) { SCOTCH_Num veloval; SCOTCH_Num partval; veloval = (velotab == NULL) ? 1 : velotab[vertnum]; partval = parttax[vertnum + baseval]; /* vertnum is not based */ if (partval >= 0) /* If vertex belongs to one part only */ loadtab[partval] += veloval; /* Add vertex load to this part */ else { /* Vertex belongs to several parts */ SCOTCH_Num edgenum; for (edgenum = verttab[vertnum]; edgenum < vendtab[vertnum]; edgenum ++) { SCOTCH_Num vertend; SCOTCH_Num partend; vertend = edgetax[edgenum]; partend = parttax[vertend]; /* vertend is based */ if (partend < 0) /* If neighbor has no identifiable part */ continue; if (flagtab[partend] == vertnum) /* If neighbor part already accounted for, skip it */ continue; loadtab[partend] += veloval; /* Vertex load contributes to this part */ flagtab[partend] = vertnum; /* Record a contribution has been made */ } } } loadsum = loadmax = 0; loadmin = SCOTCH_NUMMAX; for (partnum = 0; partnum < partnbr; partnum ++) { loadsum += loadtab[partnum]; if (loadtab[partnum] > loadmax) loadmax = loadtab[partnum]; if (loadtab[partnum] < loadmin) loadmin = loadtab[partnum]; printf ("M\tCompload[%02ld]\t%ld\n", (long) partnum, (long) loadtab[partnum]); } loadavg = (double) loadsum / (double) partnbr; printf ("M\tCompLoadAvg\t%g\n", (double) loadavg); printf ("M\tCompLoadMax/Avg\t%g\n", (double) loadmax / loadavg); if ((fileptr = fopen (argv[3], "w")) == NULL) { SCOTCH_errorPrint ("main: cannot open file (2)"); exit (EXIT_FAILURE); } if (fprintf (fileptr, "%ld\n", (long) vertnbr) == EOF) { SCOTCH_errorPrint ("main: bad output (1)"); exit (EXIT_FAILURE); } for (vertnum = 0; vertnum < vertnbr; vertnum ++) { if (fprintf (fileptr, "%ld\t%ld\n", (long) ((vlbltab == NULL) ? vertnum : vlbltab[vertnum]), (long) parttax[vertnum + baseval]) == EOF) { SCOTCH_errorPrint ("main: bad output (2)"); exit (EXIT_FAILURE); } } fclose (fileptr); free (loadtab); free (flagtab); free (parttax + baseval); SCOTCH_stratExit (&stradat); SCOTCH_graphExit (&grafdat); exit (EXIT_SUCCESS); }
int main ( int argc, char * argv[]) { FILE * fileptr; SCOTCH_Graph grafdat; SCOTCH_Ordering ordedat; SCOTCH_Strat stradat; SCOTCH_Num baseval; SCOTCH_Num vertnbr; SCOTCH_Num vertnum; SCOTCH_Num listnbr; SCOTCH_Num listnum; SCOTCH_Num * listtab; SCOTCH_errorProg (argv[0]); if (SCOTCH_graphInit (&grafdat) != 0) { /* Initialize source graph */ SCOTCH_errorPrint ("main: cannot initialize graph"); return (1); } if ((fileptr = fopen (argv[1], "r")) == NULL) { SCOTCH_errorPrint ("main: cannot open file (1)"); return (1); } if (SCOTCH_graphLoad (&grafdat, fileptr, -1, 0) != 0) { /* Read source graph */ SCOTCH_errorPrint ("main: cannot load graph"); return (1); } fclose (fileptr); SCOTCH_graphData (&grafdat, &baseval, &vertnbr, NULL, NULL, NULL, NULL, NULL, NULL, NULL); listnbr = (vertnbr + 1) / 2; /* Only keep half of the vertices in induced graph */ if ((listtab = malloc (listnbr * sizeof (SCOTCH_Num))) == NULL) { SCOTCH_errorPrint ("main: out of memory (1)"); return (1); } for (listnum = 0, vertnum = baseval + (listnbr / 4); /* Keep only middle half of the vertices */ listnum < listnbr; listnum ++, vertnum ++) listtab[listnum] = vertnum; if ((fileptr = tmpfile ()) == NULL) { /* Open temporary file for resulting output */ SCOTCH_errorPrint ("main: cannot open file (2)"); return (1); } if (SCOTCH_stratInit (&stradat) != 0) { /* Initialize ordering strategy */ SCOTCH_errorPrint ("main: cannot initialize strategy"); return (1); } if (SCOTCH_graphOrderInit (&grafdat, &ordedat, NULL, NULL, NULL, NULL, NULL) != 0) { /* Initialize ordering */ SCOTCH_errorPrint ("main: cannot initialize ordering (1)"); return (1); } if (SCOTCH_graphOrderCompute (&grafdat, &ordedat, &stradat) != 0) { SCOTCH_errorPrint ("main: cannot order graph"); return (1); } if (SCOTCH_graphOrderCheck (&grafdat, &ordedat) != 0) { SCOTCH_errorPrint ("main: invalid ordering (1)"); return (1); } SCOTCH_graphOrderSave (&grafdat, &ordedat, fileptr); /* Test ordering data output routines */ SCOTCH_graphOrderSaveMap (&grafdat, &ordedat, fileptr); SCOTCH_graphOrderSaveTree (&grafdat, &ordedat, fileptr); SCOTCH_graphOrderExit (&grafdat, &ordedat); /* Free computed ordering */ if (SCOTCH_graphOrderInit (&grafdat, &ordedat, NULL, NULL, NULL, NULL, NULL) != 0) { /* Initialize ordering again */ SCOTCH_errorPrint ("main: cannot initialize ordering (2)"); return (1); } if (SCOTCH_graphOrderComputeList (&grafdat, &ordedat, listnbr, listtab, &stradat) != 0) { SCOTCH_errorPrint ("main: cannot order induced graph"); return (1); } if (SCOTCH_graphOrderCheck (&grafdat, &ordedat) != 0) { SCOTCH_errorPrint ("main: invalid ordering (2)"); return (1); } SCOTCH_graphOrderSave (&grafdat, &ordedat, fileptr); /* Test ordering data output routines */ SCOTCH_graphOrderSaveMap (&grafdat, &ordedat, fileptr); SCOTCH_graphOrderSaveTree (&grafdat, &ordedat, fileptr); free (listtab); SCOTCH_stratExit (&stradat); SCOTCH_graphOrderExit (&grafdat, &ordedat); SCOTCH_graphExit (&grafdat); return (0); }
int main ( int argc, char * argv[]) { FiboHeap fibodat; TestFibo * nodetab; TestFibo * nodeptr; int nodesiz; int nodemax; int nodenbr; int nodenum; int nodetmp; int randval; int randtmp; int passnbr; int passnum; SCOTCH_errorProg (argv[0]); if (fiboHeapInit (&fibodat, testFiboCmpFunc) != 0) { SCOTCH_errorPrint ("main: cannot initialize Fibonacci heap"); exit (EXIT_FAILURE); } intRandInit (); /* Initialize random generator */ nodesiz = 100; passnbr = -1; switch (argc) { case 4 : intRandSeed (MAX (0, atoi (argv[3]))); case 3 : passnbr = MAX (1, atoi (argv[2])); case 2 : nodesiz = MAX (1, atoi (argv[1])); case 1 : break; default : SCOTCH_errorPrint ("usage: %s [nodenbr [passnbr [seed]]]", argv[0]); exit (EXIT_FAILURE); } if (passnbr < 0) passnbr = 10 * nodesiz; if ((nodetab = malloc (nodesiz * sizeof (TestFibo))) == NULL) { SCOTCH_errorPrint ("main: out of memory"); exit (EXIT_FAILURE); } for (nodenum = 0; nodenum < nodesiz; nodenum ++) /* Initialize node array */ nodetab[nodenum].randval = -1; nodemax = nodesiz - 1; /* Set maximum index */ nodenbr = 0; /* Array is empty */ for (passnum = 0; passnum < passnbr; passnum ++) { switch (intRandVal (6)) { case 0 : /* Add node */ case 1 : case 2 : /* More additions than deletions on average */ if (nodenbr >= nodemax) break; for (nodenum = 0; nodenum <= nodemax; nodenum ++) { /* Search for a free slot */ if (nodetab[nodenum].randval < 0) break; } if (nodenum > nodemax) { SCOTCH_errorPrint ("main: invalid node array (1)"); exit (EXIT_FAILURE); } nodetab[nodenum].randval = abs (intRandVal (INTVALMAX)); fiboHeapAdd (&fibodat, (FiboNode *) &nodetab[nodenum]); nodenbr ++; break; case 3 : /* Remove arbitrary node */ if (nodenbr <= 0) break; nodetmp = intRandVal (nodenbr); for (nodenum = 0; ; nodenum ++) { /* Search for non-empty slot */ if (nodenum > nodemax) { SCOTCH_errorPrint ("main: invalid node array (2)"); exit (EXIT_FAILURE); } if (nodetab[nodenum].randval >= 0) { if (-- nodetmp <= 0) break; } } fiboHeapDel (&fibodat, (FiboNode *) &nodetab[nodenum]); nodetab[nodenum].randval = -1; nodenbr --; break; case 4 : /* Remove minimum node */ if (nodenbr <= 0) break; nodeptr = (TestFibo *) fiboHeapMin (&fibodat); randval = nodeptr->randval; /* Keep node key value */ fiboHeapDel (&fibodat, (FiboNode *) nodeptr); /* Remove node first */ nodeptr->randval = -1; nodenbr --; for (nodenum = 0; nodenum <= nodemax; nodenum ++) { /* Check if smaller node exists */ if ((nodetab[nodenum].randval >= 0) && (nodetab[nodenum].randval < randval)) { SCOTCH_errorPrint ("main: node is not of minimum key"); } } break; case 5 : /* Decrease value of arbitrary node */ if (nodenbr <= 0) break; nodetmp = intRandVal (nodenbr); for (nodenum = 0; ; nodenum ++) { /* Search for non-empty slot */ if (nodenum > nodemax) { SCOTCH_errorPrint ("main: invalid node array (3)"); exit (EXIT_FAILURE); } if (nodetab[nodenum].randval >= 0) { if (-- nodetmp <= 0) break; } } if (nodetab[nodenum].randval <= 0) /* Cannot decrease smallest value */ break; randtmp = intRandVal (nodetab[nodenum].randval + 1); if (randtmp > nodetab[nodenum].randval) break; nodetab[nodenum].randval -= randtmp; fiboHeapDecrease (&fibodat, (FiboNode *) &nodetab[nodenum]); break; } } fiboHeapExit (&fibodat); free (nodetab); exit (EXIT_SUCCESS); }
int main ( int argc, char * argv[]) { MPI_Comm proccomm; int procglbnbr; /* Number of processes sharing graph data */ int proclocnum; /* Number of this process */ SCOTCH_Num vertglbnbr; SCOTCH_Num vertlocnbr; SCOTCH_Num * fronloctab; SCOTCH_Num baseval; SCOTCH_Dgraph grafdat; SCOTCH_Dgraph bandgrafdat; SCOTCH_Num bandvertglbnbr; SCOTCH_Num bandvertlocnbr; SCOTCH_Num * bandvlblloctab; FILE * file; int procnum; #ifdef SCOTCH_PTHREAD int thrdlvlreqval; int thrdlvlproval; #endif /* SCOTCH_PTHREAD */ SCOTCH_errorProg (argv[0]); #ifdef SCOTCH_PTHREAD thrdlvlreqval = MPI_THREAD_MULTIPLE; if (MPI_Init_thread (&argc, &argv, thrdlvlreqval, &thrdlvlproval) != MPI_SUCCESS) SCOTCH_errorPrint ("main: Cannot initialize (1)"); if (thrdlvlreqval > thrdlvlproval) SCOTCH_errorPrint ("main: MPI implementation is not thread-safe: recompile without SCOTCH_PTHREAD"); #else /* SCOTCH_PTHREAD */ if (MPI_Init (&argc, &argv) != MPI_SUCCESS) SCOTCH_errorPrint ("main: Cannot initialize (2)"); #endif /* SCOTCH_PTHREAD */ if (argc != 2) { SCOTCH_errorPrint ("usage: %s graph_file", argv[0]); exit (EXIT_FAILURE); } proccomm = MPI_COMM_WORLD; MPI_Comm_size (proccomm, &procglbnbr); /* Get communicator data */ MPI_Comm_rank (proccomm, &proclocnum); fprintf (stderr, "Proc %2d of %2d, pid %d\n", proclocnum, procglbnbr, getpid ()); #ifdef SCOTCH_CHECK_NOAUTO if (proclocnum == 0) { /* Synchronize on keybord input */ char c; printf ("Waiting for key press...\n"); scanf ("%c", &c); } #endif /* SCOTCH_CHECK_NOAUTO */ if (MPI_Barrier (proccomm) != MPI_SUCCESS) { /* Synchronize for debug */ SCOTCH_errorPrint ("main: cannot communicate (1)"); exit (EXIT_FAILURE); } if (SCOTCH_dgraphInit (&grafdat, proccomm) != 0) { /* Initialize source graph */ SCOTCH_errorPrint ("main: cannot initialize graph (1)"); exit (EXIT_FAILURE); } file = NULL; if ((proclocnum == 0) && ((file = fopen (argv[1], "r")) == NULL)) { SCOTCH_errorPrint ("main: cannot open graph file"); exit (EXIT_FAILURE); } if (SCOTCH_dgraphLoad (&grafdat, file, 0, 0) != 0) { SCOTCH_errorPrint ("main: cannot load graph"); exit (EXIT_FAILURE); } if (file != NULL) fclose (file); if (MPI_Barrier (proccomm) != MPI_SUCCESS) { /* Synchronize for debug */ SCOTCH_errorPrint ("main: cannot communicate (2)"); exit (EXIT_FAILURE); } SCOTCH_dgraphData (&grafdat, NULL, &vertglbnbr, &vertlocnbr, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); if ((fronloctab = malloc (vertlocnbr * sizeof (SCOTCH_Num))) == NULL) { SCOTCH_errorPrint ("main: cannot allocate frontier array"); exit (EXIT_FAILURE); } if (SCOTCH_dgraphInit (&bandgrafdat, proccomm) != 0) { /* Initialize band graph */ SCOTCH_errorPrint ("main: cannot initialize graph (2)"); exit (EXIT_FAILURE); } fronloctab[0] = 0; if (SCOTCH_dgraphBand (&grafdat, (proclocnum == 1) ? 1 : 0, fronloctab, 4, &bandgrafdat) != 0) { SCOTCH_errorPrint ("main: cannot compute band graph"); exit (EXIT_FAILURE); } free (fronloctab); SCOTCH_dgraphData (&bandgrafdat, &baseval, &bandvertglbnbr, &bandvertlocnbr, NULL, NULL, NULL, NULL, NULL, &bandvlblloctab, NULL, NULL, NULL, NULL, NULL, NULL, NULL); for (procnum = 0; procnum < procglbnbr; procnum ++) { SCOTCH_Num bandvertlocnum; MPI_Barrier (proccomm); if (procnum == proclocnum) { if ((file = fopen ("/tmp/test_scotch_dgraph_band.map", (procnum == 0) ? "w" : "a+")) == NULL) { SCOTCH_errorPrint ("main: cannot open mapping file"); exit (EXIT_FAILURE); } if (procnum == 0) fprintf (file, "%ld\n", (long) bandvertglbnbr); for (bandvertlocnum = 0; bandvertlocnum < bandvertlocnbr; bandvertlocnum ++) fprintf (file, "%ld\t1\n", (long) bandvlblloctab[bandvertlocnum]); fclose (file); } } SCOTCH_dgraphExit (&bandgrafdat); SCOTCH_dgraphExit (&grafdat); MPI_Finalize (); exit (EXIT_SUCCESS); }