diff options
| author | Tor Aamodt <[email protected]> | 2010-07-15 18:09:46 -0800 |
|---|---|---|
| committer | Tor Aamodt <[email protected]> | 2010-07-15 18:09:46 -0800 |
| commit | 69f2911e04ffb1b19eef1fafb8c040af271f656e (patch) | |
| tree | 231d3b6bdc3a202f7c255bfcf7bf2c36e32cee9e /benchmarks/CUDA/DG/3rdParty | |
creating branch for adding support for CUDA 3.x and Fermi
[git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 6829]
Diffstat (limited to 'benchmarks/CUDA/DG/3rdParty')
146 files changed, 51047 insertions, 0 deletions
diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/CHANGES b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/CHANGES new file mode 100644 index 0000000..1b1e6d0 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/CHANGES @@ -0,0 +1,144 @@ + +Changes in version 3.1 +- The mesh partitioning and dual creation routines have changed to support mixed + element meshes. + +- The parmetis.h header file has been restructured and is now C++ friendly. + +- Fortran bindings/renamings for various routines have been added. + +- A number of bugs have been fixed. + - tpwgts are now respected for small graphs. + - fixed various divide by zero errors. + - removed dependency on the old drand48() routines. + - fixed some memory leaks. + + + +Changes in version 3.0 + +- The names and calling sequence of all the routines have changed due to expanded + functionality that has been provided in this release. However, the 2.0 API calls + have been mapped to the new routines. However, the expanded functionality provided + with this release is only available by using the new calling sequences. + +- The four adaptive repartitioning routines: + ParMETIS_RepartLDiffusion, + ParMETIS_RepartGDiffusion, + ParMETIS_RepartRemap, and + ParMETIS_RepartMLRemap, + have been replaced by a single routine called ParMETIS_V3_AdpativeRepart that + implements a unified repartitioning algorithm which combines the best features + of the previous routines. + +- Multiple vertex weights/balance constraints are supported for most of the + routines. This allows ParMETIS to be used to partition graphs for multi-phase + and multi-physics simulations. + +- In order to optimize partitionings for specific heterogeneous computing + architectures, it is now possible to specify the target sub-domain weights + for each of the sub-domains and for each balance constraint. This feature, + for example, allows the user to compute a partitioning in which one of the + sub-domains is twice the size of all of the others. + +- The number of sub-domains has been de-coupled from the number of processors + in both the static and the adaptive partitioning schemes. Hence, it is now + possible to use the parallel partitioning and repartitioning algorithms + to compute a k-way partitioning independent of the number of processors + that are used. Note that Version 2.0 provided this functionality for the + static partitioning schemes only. + +- Routines are provided for both directly partitioning a finite element mesh, + and for constructing the dual graph of a mesh in parallel. + + + +Changes in version 2.0 + +- Changed the names and calling sequences of all the routines to make it + easier to use ParMETIS with Fortran. + +- Improved the performance of the diffusive adaptive repartitioning + algorithms. + +- Added a new set of adaptive repartitioning routines that are based on the + remapping paradigm. These routines are called ParMETIS_RepartRemap and + ParMETIS_RepartMLRemap + +- The number of partitions has been de-coupled from the number of processors. + You can now use the parallel partitioning algorithms to compute a k-way + partitioning independent of the number of processors that you use. + +- The partitioning and ordering algorithms in ParMETIS now utilize various + portions of the serial METIS library. As a result of this, the quality + of the produced partitionings and orderings have been improved. + Remember to link your code with both libmetis.a and libparmetis.a + + +Changes in version 1.0 + +- Added partitioning routines that take advantage of coordinate information. + These routines are based on space-filling curves and they are used to + quickly compute a initial distribution for PARKMETIS. + A total of three routines have been added called PARGKMETIS, PARGRMETIS, + and PARGMETIS + +- Added a fill-reducing ordering routine that is based on multilevel nested + dissection. This is similar to the ordering routine in the serial Metis + with the difference that is directly computes and refines vertex + separators. The new routine is called PAROMETIS and returns the new ordering + of the local nodes plus a vector describing the sizes of the various + separators that form the elimination tree. + +- Changed the calling sequence again! I found it awkward to require that + communicators and other scalar quantities being passed by reference. + +- Fixed a number of memory leaks. + + + +Changes in version 0.3 + +- Incorporated parallel multilevel diffusion algorithms for repartitioning + adaptively refined meshes. Two routines have been added for this purpose: + PARUAMETIS that performs undirected multilevel diffusion + PARDAMETIS that performs directed multilevel diffusion + +- Changed the names and calling sequences of the parallel partitioning + and refinement algorithms. Now they are called PARKMETIS for the + k-way partitioning and PARRMETIS for the k-way refinement. + Also the calling sequence has been changed slightly to make ParMETIS + Fortran callable. + +- Added an additional option for selecting the algorithm for initial + partitioning at the coarsest graph. Now you have the choice of selecting + either a serial or a parallel algorithm. The parallel initial partitioning + speeds up the algorithm especially for large number of processors. + NOTE that the parallel initial partitioning works only for partitions that + are power of two. If you want partitions that are not power of two you must + use the old serial initial partitioning option. + +- Fixed some bugs in the initial partitioning code. + +- Made parallel k-way refinement more robust by randomly ordering the + processors at each phase + + +Changes in version 0.2 + +- A complete reworking of the primary algorithms. The performance + of the code has improved considerably. Over 30% on 128 processor + Cray T3D. Improvement should be higher on machines with high + latencies. + + Here are some performance numbers on T3D using Cray's MPI + for 2 graphs, mdual (0.25M vertices) and mdual2 (1.0M vertices) + + 16PEs 32PEs 64PEs 128PEs + mdual 4.07 2.97 2.82 + mdual2 15.02 8.89 6.12 5.75 + +- The quality of the produced partitions has been improved. +- Added options[2] to specify C or Fortran style numbering. + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/COPYRIGHT b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/COPYRIGHT new file mode 100644 index 0000000..e6cdd3b --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/COPYRIGHT @@ -0,0 +1,19 @@ +Copyright Notice +---------------- + +The ParMETIS/METIS package is copyrighted by the Regents of the +University of Minnesota. It can be freely used for educational and +research purposes by non-profit institutions and US government agencies +only. Other organizations are allowed to use ParMETIS/METIS only for +evaluation purposes, and any further uses will require prior approval. +The software may not be sold or redistributed without prior approval. +One may make copies of the software for their use provided that the +copies, are not sold or distributed, are used under the same terms +and conditions. + +As unestablished research software, this code is provided on an +``as is'' basis without warranty of any kind, either expressed or +implied. The downloading, or executing any part of this software +constitutes an implicit agreement to these terms. These terms and +conditions are subject to change at any time without prior notice. + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Graphs/README b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Graphs/README new file mode 100644 index 0000000..afa7e16 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Graphs/README @@ -0,0 +1 @@ +../Programs/Makefile craps out if it can't find this directory, so this dummy file is in perforce to make sure directory is added -GY diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/INSTALL b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/INSTALL new file mode 100644 index 0000000..8af32a4 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/INSTALL @@ -0,0 +1,1961 @@ + +INSTALLATION +------------ + + To build ParMetis you need to edit the Makefile.in and set the appropriate + parameters for 'CC'. The default is to use mpicc from MPICH. + After that just type 'make' to build the libraries (libmetis.a and + libparmetis.a). + + The header file parmetis.h can be used to provided the prototypes for + the various routines in ParMetis. + + +TESTING THE LIBRARY +------------------- + + To test the library go to the directory Graphs and execute the program + 'ptest' that is in that directory. You can test the direct mesh partitioning + routines by using the program 'meshtest'. + Sample output of these two tests have been appended in this file. + + NOTE-1: You must have at least 256MB per node in order for the test + to go through. + + NOTE-2: The results on your machine will most likely look different + because of differences in the random number generators. + Look if the test programs reports any 'incorrect' results. + If the test goes through correctly, then you have compiled + ParMetis successfully! + + + + +------------------------------------------------------------------------- +------------------------------------------------------------------------- +------------------------------------------------------------------------- +------------------------------------------------------------------------- +% mpirun -np 4 ptest rotor.graph + + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 1}, Ncon: 1, Nparts: 8 + Setup: Max: 0.291, Sum: 0.789, Balance: 1.477 + Matching: Max: 0.618, Sum: 2.386, Balance: 1.035 +Contraction: Max: 0.522, Sum: 2.037, Balance: 1.026 + InitPart: Max: 0.044, Sum: 0.142, Balance: 1.248 + Project: Max: 0.024, Sum: 0.026, Balance: 3.641 + Initialize: Max: 0.212, Sum: 0.664, Balance: 1.275 + K-way: Max: 0.838, Sum: 3.210, Balance: 1.044 + Remap: Max: 0.000, Sum: -0.016, Balance: -0.021 + Total: Max: 2.476, Sum: 9.885, Balance: 1.002 +Final 8-way CUT: 14620 Balance: 1.049 avg: 1.049 +ParMETIS_V3_PartKway reported a cut of 14620 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 2}, Ncon: 1, Nparts: 8 + Setup: Max: 0.244, Sum: 0.737, Balance: 1.325 + Matching: Max: 0.565, Sum: 2.201, Balance: 1.028 +Contraction: Max: 0.494, Sum: 1.967, Balance: 1.004 + InitPart: Max: 0.024, Sum: 0.089, Balance: 1.095 + Project: Max: 0.050, Sum: 0.127, Balance: 1.579 + Initialize: Max: 0.204, Sum: 0.708, Balance: 1.152 + K-way: Max: 0.783, Sum: 3.089, Balance: 1.014 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.213 + Total: Max: 2.361, Sum: 9.427, Balance: 1.002 +Final 8-way CUT: 15371 Balance: 1.046 avg: 1.046 +ParMETIS_V3_PartKway reported a cut of 15371 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 1}, Ncon: 3, Nparts: 8 + Setup: Max: 0.216, Sum: 0.713, Balance: 1.212 + Matching: Max: 0.523, Sum: 2.042, Balance: 1.024 +Contraction: Max: 0.485, Sum: 1.909, Balance: 1.017 + InitPart: Max: 0.227, Sum: 0.902, Balance: 1.006 + Project: Max: 0.053, Sum: 0.141, Balance: 1.506 + Initialize: Max: 0.292, Sum: 1.058, Balance: 1.105 + K-way: Max: 0.858, Sum: 3.224, Balance: 1.065 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.016 + Total: Max: 2.601, Sum: 10.395, Balance: 1.001 +Final 8-way CUT: 24400 Balance: 1.047 1.044 1.046 avg: 1.046 +ParMETIS_V3_PartKway reported a cut of 24400 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 2}, Ncon: 3, Nparts: 8 + Setup: Max: 0.224, Sum: 0.725, Balance: 1.234 + Matching: Max: 0.761, Sum: 3.014, Balance: 1.009 +Contraction: Max: 0.440, Sum: 1.732, Balance: 1.017 + InitPart: Max: 0.213, Sum: 0.847, Balance: 1.008 + Project: Max: 0.045, Sum: 0.072, Balance: 2.515 + Initialize: Max: 0.215, Sum: 0.673, Balance: 1.278 + K-way: Max: 0.857, Sum: 3.289, Balance: 1.042 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.010 + Total: Max: 2.696, Sum: 10.771, Balance: 1.001 +Final 8-way CUT: 23755 Balance: 1.050 1.047 1.048 avg: 1.048 +ParMETIS_V3_PartKway reported a cut of 23755 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 1}, Ncon: 5, Nparts: 8 + Setup: Max: 0.258, Sum: 0.708, Balance: 1.455 + Matching: Max: 0.459, Sum: 1.797, Balance: 1.023 +Contraction: Max: 0.478, Sum: 1.841, Balance: 1.038 + InitPart: Max: 0.451, Sum: 1.800, Balance: 1.003 + Project: Max: 0.046, Sum: 0.123, Balance: 1.487 + Initialize: Max: 0.199, Sum: 0.699, Balance: 1.138 + K-way: Max: 0.854, Sum: 3.387, Balance: 1.009 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.039 + Total: Max: 2.725, Sum: 10.881, Balance: 1.002 +Final 8-way CUT: 25897 Balance: 1.049 1.050 1.044 1.047 1.049 avg: 1.048 +ParMETIS_V3_PartKway reported a cut of 25897 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 2}, Ncon: 5, Nparts: 8 + Setup: Max: 0.225, Sum: 0.718, Balance: 1.255 + Matching: Max: 0.601, Sum: 2.350, Balance: 1.022 +Contraction: Max: 0.480, Sum: 1.885, Balance: 1.019 + InitPart: Max: 0.493, Sum: 1.967, Balance: 1.004 + Project: Max: 0.045, Sum: 0.150, Balance: 1.211 + Initialize: Max: 0.194, Sum: 0.648, Balance: 1.198 + K-way: Max: 0.857, Sum: 3.333, Balance: 1.029 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.016 + Total: Max: 2.869, Sum: 11.443, Balance: 1.003 +Final 8-way CUT: 26340 Balance: 1.049 1.043 1.044 1.050 1.050 avg: 1.047 +ParMETIS_V3_PartKway reported a cut of 26340 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 1}, Ncon: 1, Nparts: 4 + Setup: Max: 0.284, Sum: 0.947, Balance: 1.198 + Matching: Max: 0.660, Sum: 2.609, Balance: 1.012 +Contraction: Max: 0.471, Sum: 1.824, Balance: 1.033 + InitPart: Max: 0.014, Sum: 0.054, Balance: 1.064 + Project: Max: 0.074, Sum: 0.183, Balance: 1.609 + Initialize: Max: 0.144, Sum: 0.491, Balance: 1.175 + K-way: Max: 0.785, Sum: 3.094, Balance: 1.014 + Remap: Max: 0.014, Sum: 0.050, Balance: 1.082 + Total: Max: 2.488, Sum: 9.937, Balance: 1.001 +Final 4-way CUT: 7782 Balance: 1.050 avg: 1.050 +ParMETIS_V3_PartKway reported a cut of 7782 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 2}, Ncon: 1, Nparts: 4 + Setup: Max: 0.264, Sum: 0.883, Balance: 1.194 + Matching: Max: 0.574, Sum: 2.170, Balance: 1.057 +Contraction: Max: 0.459, Sum: 1.829, Balance: 1.004 + InitPart: Max: 0.016, Sum: 0.062, Balance: 1.060 + Project: Max: 0.048, Sum: 0.103, Balance: 1.884 + Initialize: Max: 0.148, Sum: 0.537, Balance: 1.106 + K-way: Max: 0.821, Sum: 3.186, Balance: 1.030 + Remap: Max: 0.010, Sum: 0.036, Balance: 1.138 + Total: Max: 2.348, Sum: 9.364, Balance: 1.003 +Final 4-way CUT: 8448 Balance: 1.034 avg: 1.034 +ParMETIS_V3_PartKway reported a cut of 8448 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 1}, Ncon: 3, Nparts: 4 + Setup: Max: 0.278, Sum: 0.875, Balance: 1.269 + Matching: Max: 0.946, Sum: 3.670, Balance: 1.031 +Contraction: Max: 0.897, Sum: 3.577, Balance: 1.003 + InitPart: Max: 0.198, Sum: 0.790, Balance: 1.003 + Project: Max: 0.051, Sum: 0.174, Balance: 1.167 + Initialize: Max: 0.289, Sum: 1.127, Balance: 1.024 + K-way: Max: 1.475, Sum: 5.855, Balance: 1.008 + Remap: Max: 0.001, Sum: 0.001, Balance: 3.525 + Total: Max: 4.194, Sum: 16.766, Balance: 1.001 +Final 4-way CUT: 12108 Balance: 1.033 1.047 1.031 avg: 1.037 +ParMETIS_V3_PartKway reported a cut of 12108 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 2}, Ncon: 3, Nparts: 4 + Setup: Max: 0.251, Sum: 0.797, Balance: 1.258 + Matching: Max: 0.669, Sum: 2.493, Balance: 1.074 +Contraction: Max: 0.601, Sum: 2.346, Balance: 1.025 + InitPart: Max: 0.102, Sum: 0.407, Balance: 1.003 + Project: Max: 0.082, Sum: 0.220, Balance: 1.499 + Initialize: Max: 0.194, Sum: 0.729, Balance: 1.067 + K-way: Max: 0.869, Sum: 3.317, Balance: 1.048 + Remap: Max: 0.012, Sum: 0.043, Balance: 1.093 + Total: Max: 2.719, Sum: 10.868, Balance: 1.001 +Final 4-way CUT: 13048 Balance: 1.049 1.048 1.035 avg: 1.044 +ParMETIS_V3_PartKway reported a cut of 13048 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 1}, Ncon: 5, Nparts: 4 + Setup: Max: 0.251, Sum: 0.724, Balance: 1.388 + Matching: Max: 0.628, Sum: 2.416, Balance: 1.040 +Contraction: Max: 0.474, Sum: 1.887, Balance: 1.005 + InitPart: Max: 0.161, Sum: 0.637, Balance: 1.009 + Project: Max: 0.081, Sum: 0.236, Balance: 1.376 + Initialize: Max: 0.241, Sum: 0.789, Balance: 1.223 + K-way: Max: 1.024, Sum: 3.929, Balance: 1.043 + Remap: Max: 0.012, Sum: 0.044, Balance: 1.079 + Total: Max: 2.794, Sum: 11.162, Balance: 1.001 +Final 4-way CUT: 14978 Balance: 1.043 1.037 1.042 1.025 1.030 avg: 1.035 +ParMETIS_V3_PartKway reported a cut of 14978 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 2}, Ncon: 5, Nparts: 4 + Setup: Max: 0.298, Sum: 0.779, Balance: 1.529 + Matching: Max: 0.652, Sum: 2.570, Balance: 1.015 +Contraction: Max: 0.699, Sum: 2.778, Balance: 1.007 + InitPart: Max: 0.164, Sum: 0.652, Balance: 1.005 + Project: Max: 0.056, Sum: 0.133, Balance: 1.682 + Initialize: Max: 0.202, Sum: 0.704, Balance: 1.145 + K-way: Max: 0.820, Sum: 3.143, Balance: 1.043 + Remap: Max: 0.012, Sum: 0.044, Balance: 1.063 + Total: Max: 2.855, Sum: 11.407, Balance: 1.001 +Final 4-way CUT: 14768 Balance: 1.017 1.028 1.018 1.027 1.035 avg: 1.025 +ParMETIS_V3_PartKway reported a cut of 14768 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 1}, Ncon: 1, Nparts: 2 + Setup: Max: 0.251, Sum: 0.813, Balance: 1.237 + Matching: Max: 0.631, Sum: 2.385, Balance: 1.059 +Contraction: Max: 0.443, Sum: 1.757, Balance: 1.008 + InitPart: Max: 0.023, Sum: 0.086, Balance: 1.051 + Project: Max: 0.061, Sum: 0.190, Balance: 1.287 + Initialize: Max: 0.140, Sum: 0.483, Balance: 1.162 + K-way: Max: 0.618, Sum: 2.374, Balance: 1.042 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.022 + Total: Max: 2.195, Sum: 8.766, Balance: 1.001 +Final 2-way CUT: 2314 Balance: 1.048 avg: 1.048 +ParMETIS_V3_PartKway reported a cut of 2314 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 2}, Ncon: 1, Nparts: 2 + Setup: Max: 0.247, Sum: 0.727, Balance: 1.362 + Matching: Max: 0.573, Sum: 2.272, Balance: 1.008 +Contraction: Max: 0.502, Sum: 1.982, Balance: 1.012 + InitPart: Max: 0.010, Sum: 0.037, Balance: 1.077 + Project: Max: 0.040, Sum: 0.149, Balance: 1.062 + Initialize: Max: 0.141, Sum: 0.527, Balance: 1.067 + K-way: Max: 0.612, Sum: 2.410, Balance: 1.015 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.078 + Total: Max: 2.150, Sum: 8.572, Balance: 1.003 +Final 2-way CUT: 2068 Balance: 1.047 avg: 1.047 +ParMETIS_V3_PartKway reported a cut of 2068 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 1}, Ncon: 3, Nparts: 2 + Setup: Max: 0.268, Sum: 0.889, Balance: 1.204 + Matching: Max: 0.548, Sum: 2.108, Balance: 1.039 +Contraction: Max: 0.446, Sum: 1.775, Balance: 1.004 + InitPart: Max: 0.062, Sum: 0.243, Balance: 1.013 + Project: Max: 0.054, Sum: 0.156, Balance: 1.392 + Initialize: Max: 0.168, Sum: 0.574, Balance: 1.174 + K-way: Max: 0.791, Sum: 3.038, Balance: 1.042 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.032 + Total: Max: 2.358, Sum: 9.416, Balance: 1.002 +Final 2-way CUT: 6503 Balance: 1.028 1.035 1.041 avg: 1.035 +ParMETIS_V3_PartKway reported a cut of 6503 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 2}, Ncon: 3, Nparts: 2 + Setup: Max: 0.200, Sum: 0.636, Balance: 1.258 + Matching: Max: 0.664, Sum: 2.539, Balance: 1.047 +Contraction: Max: 0.452, Sum: 1.783, Balance: 1.015 + InitPart: Max: 0.046, Sum: 0.182, Balance: 1.005 + Project: Max: 0.044, Sum: 0.129, Balance: 1.345 + Initialize: Max: 0.166, Sum: 0.558, Balance: 1.191 + K-way: Max: 0.704, Sum: 2.778, Balance: 1.014 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.013 + Total: Max: 2.317, Sum: 9.258, Balance: 1.001 +Final 2-way CUT: 5999 Balance: 1.013 1.018 1.044 avg: 1.025 +ParMETIS_V3_PartKway reported a cut of 5999 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 1}, Ncon: 5, Nparts: 2 + Setup: Max: 0.209, Sum: 0.701, Balance: 1.190 + Matching: Max: 0.503, Sum: 1.942, Balance: 1.037 +Contraction: Max: 0.567, Sum: 2.220, Balance: 1.022 + InitPart: Max: 0.066, Sum: 0.262, Balance: 1.005 + Project: Max: 0.095, Sum: 0.257, Balance: 1.473 + Initialize: Max: 0.150, Sum: 0.501, Balance: 1.201 + K-way: Max: 0.652, Sum: 2.539, Balance: 1.027 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.084 + Total: Max: 2.220, Sum: 8.872, Balance: 1.001 +Final 2-way CUT: 2482 Balance: 1.020 1.021 1.018 1.020 1.022 avg: 1.020 +ParMETIS_V3_PartKway reported a cut of 2482 + +Testing ParMETIS_V3_PartKway with options[1-2] = {3 2}, Ncon: 5, Nparts: 2 + Setup: Max: 0.286, Sum: 0.807, Balance: 1.416 + Matching: Max: 0.518, Sum: 1.977, Balance: 1.049 +Contraction: Max: 0.507, Sum: 1.978, Balance: 1.026 + InitPart: Max: 0.065, Sum: 0.254, Balance: 1.029 + Project: Max: 0.051, Sum: 0.112, Balance: 1.832 + Initialize: Max: 0.175, Sum: 0.502, Balance: 1.390 + K-way: Max: 0.721, Sum: 2.753, Balance: 1.048 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.022 + Total: Max: 2.233, Sum: 8.916, Balance: 1.002 +Final 2-way CUT: 2539 Balance: 1.005 1.005 1.006 1.006 1.005 avg: 1.005 +ParMETIS_V3_PartKway reported a cut of 2539 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 1}, Ncon: 1, Nparts: 8 + Setup: Max: 0.190, Sum: 0.460, Balance: 1.651 + Total: Max: 3.549, Sum: 14.190, Balance: 1.000 +XYZ Cut: 417088 Balance: 1.000 [24905 99617 4] + Setup: Max: 4.012, Sum: 15.364, Balance: 1.044 + Matching: Max: 1.522, Sum: 6.034, Balance: 1.009 +Contraction: Max: 2.588, Sum: 10.293, Balance: 1.006 + InitPart: Max: 0.016, Sum: 0.063, Balance: 1.047 + Project: Max: 0.943, Sum: 1.055, Balance: 3.578 + Initialize: Max: 1.195, Sum: 3.759, Balance: 1.272 + K-way: Max: 0.857, Sum: 3.297, Balance: 1.040 + Move: Max: 2.255, Sum: 8.985, Balance: 1.004 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.058 + Total: Max: 13.646, Sum: 54.574, Balance: 1.000 +Final 8-way CUT: 15378 Balance: 1.049 avg: 1.049 +ParMETIS_V3_PartGeomKway reported a cut of 15378 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 2}, Ncon: 1, Nparts: 8 + Setup: Max: 0.107, Sum: 0.336, Balance: 1.273 + Total: Max: 0.316, Sum: 1.259, Balance: 1.003 +XYZ Cut: 419906 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.957, Sum: 3.774, Balance: 1.014 + Matching: Max: 1.233, Sum: 4.857, Balance: 1.015 +Contraction: Max: 2.783, Sum: 11.127, Balance: 1.000 + InitPart: Max: 0.018, Sum: 0.069, Balance: 1.033 + Project: Max: 0.170, Sum: 0.235, Balance: 2.883 + Initialize: Max: 0.443, Sum: 1.365, Balance: 1.297 + K-way: Max: 0.818, Sum: 3.127, Balance: 1.047 + Move: Max: 9.035, Sum: 36.117, Balance: 1.001 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.030 + Total: Max: 6.582, Sum: 26.301, Balance: 1.001 +Final 8-way CUT: 14413 Balance: 1.046 avg: 1.046 +ParMETIS_V3_PartGeomKway reported a cut of 14413 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 1}, Ncon: 3, Nparts: 8 + Setup: Max: 0.147, Sum: 0.488, Balance: 1.205 + Total: Max: 0.299, Sum: 1.192, Balance: 1.005 +XYZ Cut: 418507 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.936, Sum: 3.241, Balance: 1.155 + Matching: Max: 0.680, Sum: 2.642, Balance: 1.030 +Contraction: Max: 1.163, Sum: 4.652, Balance: 1.000 + InitPart: Max: 0.234, Sum: 0.935, Balance: 1.002 + Project: Max: 0.079, Sum: 0.169, Balance: 1.874 + Initialize: Max: 0.270, Sum: 0.983, Balance: 1.100 + K-way: Max: 0.868, Sum: 3.287, Balance: 1.056 + Move: Max: 3.337, Sum: 13.333, Balance: 1.001 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.022 + Total: Max: 4.428, Sum: 17.694, Balance: 1.001 +Final 8-way CUT: 23489 Balance: 1.046 1.047 1.050 avg: 1.048 +ParMETIS_V3_PartGeomKway reported a cut of 23489 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 2}, Ncon: 3, Nparts: 8 + Setup: Max: 0.215, Sum: 0.671, Balance: 1.282 + Total: Max: 0.355, Sum: 1.418, Balance: 1.002 +XYZ Cut: 418507 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.834, Sum: 2.604, Balance: 1.282 + Matching: Max: 0.780, Sum: 3.046, Balance: 1.025 +Contraction: Max: 1.036, Sum: 4.131, Balance: 1.003 + InitPart: Max: 0.221, Sum: 0.884, Balance: 1.002 + Project: Max: 0.078, Sum: 0.204, Balance: 1.523 + Initialize: Max: 0.355, Sum: 1.265, Balance: 1.123 + K-way: Max: 0.870, Sum: 3.364, Balance: 1.035 + Move: Max: 1.618, Sum: 6.456, Balance: 1.002 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.043 + Total: Max: 4.332, Sum: 17.312, Balance: 1.001 +Final 8-way CUT: 23546 Balance: 1.048 1.045 1.043 avg: 1.045 +ParMETIS_V3_PartGeomKway reported a cut of 23546 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 1}, Ncon: 5, Nparts: 8 + Setup: Max: 0.168, Sum: 0.486, Balance: 1.382 + Total: Max: 0.298, Sum: 1.187, Balance: 1.003 +XYZ Cut: 418507 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.704, Sum: 2.160, Balance: 1.303 + Matching: Max: 0.569, Sum: 2.209, Balance: 1.031 +Contraction: Max: 1.035, Sum: 4.134, Balance: 1.001 + InitPart: Max: 0.335, Sum: 1.338, Balance: 1.002 + Project: Max: 0.073, Sum: 0.195, Balance: 1.506 + Initialize: Max: 0.303, Sum: 1.071, Balance: 1.131 + K-way: Max: 0.933, Sum: 3.528, Balance: 1.058 + Move: Max: 1.039, Sum: 4.124, Balance: 1.008 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.049 + Total: Max: 4.035, Sum: 16.114, Balance: 1.002 +Final 8-way CUT: 28349 Balance: 1.048 1.041 1.046 1.050 1.047 avg: 1.046 +ParMETIS_V3_PartGeomKway reported a cut of 28349 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 2}, Ncon: 5, Nparts: 8 + Setup: Max: 0.102, Sum: 0.312, Balance: 1.309 + Total: Max: 0.193, Sum: 0.770, Balance: 1.005 +XYZ Cut: 418507 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.574, Sum: 1.851, Balance: 1.241 + Matching: Max: 0.500, Sum: 1.935, Balance: 1.034 +Contraction: Max: 0.658, Sum: 2.614, Balance: 1.007 + InitPart: Max: 0.326, Sum: 1.300, Balance: 1.001 + Project: Max: 0.048, Sum: 0.157, Balance: 1.209 + Initialize: Max: 0.266, Sum: 0.931, Balance: 1.144 + K-way: Max: 0.903, Sum: 3.442, Balance: 1.049 + Move: Max: 0.580, Sum: 2.295, Balance: 1.011 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.028 + Total: Max: 3.401, Sum: 13.572, Balance: 1.002 +Final 8-way CUT: 27483 Balance: 1.044 1.050 1.037 1.045 1.045 avg: 1.044 +ParMETIS_V3_PartGeomKway reported a cut of 27483 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 1}, Ncon: 1, Nparts: 4 + Setup: Max: 0.100, Sum: 0.298, Balance: 1.343 + Total: Max: 0.194, Sum: 0.738, Balance: 1.051 +XYZ Cut: 418507 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.596, Sum: 1.766, Balance: 1.350 + Matching: Max: 0.555, Sum: 2.169, Balance: 1.023 +Contraction: Max: 0.641, Sum: 2.517, Balance: 1.018 + InitPart: Max: 0.014, Sum: 0.054, Balance: 1.036 + Project: Max: 0.080, Sum: 0.181, Balance: 1.775 + Initialize: Max: 0.236, Sum: 0.704, Balance: 1.339 + K-way: Max: 0.766, Sum: 2.940, Balance: 1.042 + Move: Max: 0.262, Sum: 1.031, Balance: 1.018 + Remap: Max: -0.006, Sum: -0.027, Balance: 0.973 + Total: Max: 2.949, Sum: 11.769, Balance: 1.002 +Final 4-way CUT: 8815 Balance: 1.028 avg: 1.028 +ParMETIS_V3_PartGeomKway reported a cut of 8815 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 2}, Ncon: 1, Nparts: 4 + Setup: Max: 0.181, Sum: 0.472, Balance: 1.531 + Total: Max: 0.283, Sum: 1.133, Balance: 1.001 +XYZ Cut: 418507 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.655, Sum: 1.957, Balance: 1.338 + Matching: Max: 0.629, Sum: 2.387, Balance: 1.054 +Contraction: Max: 0.618, Sum: 2.438, Balance: 1.013 + InitPart: Max: 0.026, Sum: 0.102, Balance: 1.019 + Project: Max: 0.074, Sum: 0.198, Balance: 1.500 + Initialize: Max: 0.205, Sum: 0.733, Balance: 1.117 + K-way: Max: 0.839, Sum: 3.283, Balance: 1.022 + Move: Max: 1.827, Sum: 7.270, Balance: 1.005 + Remap: Max: 0.012, Sum: 0.048, Balance: 1.034 + Total: Max: 3.226, Sum: 12.876, Balance: 1.002 +Final 4-way CUT: 8442 Balance: 1.046 avg: 1.046 +ParMETIS_V3_PartGeomKway reported a cut of 8442 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 1}, Ncon: 3, Nparts: 4 + Setup: Max: 0.160, Sum: 0.513, Balance: 1.247 + Total: Max: 0.299, Sum: 1.194, Balance: 1.001 +XYZ Cut: 418507 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.648, Sum: 2.097, Balance: 1.235 + Matching: Max: 0.507, Sum: 2.008, Balance: 1.010 +Contraction: Max: 0.647, Sum: 2.541, Balance: 1.019 + InitPart: Max: 0.104, Sum: 0.416, Balance: 1.004 + Project: Max: 0.047, Sum: 0.033, Balance: 5.662 + Initialize: Max: 0.268, Sum: 0.862, Balance: 1.244 + K-way: Max: 0.851, Sum: 3.172, Balance: 1.074 + Move: Max: 0.940, Sum: 3.739, Balance: 1.005 + Remap: Max: -0.002, Sum: -0.008, Balance: 0.964 + Total: Max: 3.187, Sum: 12.722, Balance: 1.002 +Final 4-way CUT: 12726 Balance: 1.035 1.019 1.039 avg: 1.031 +ParMETIS_V3_PartGeomKway reported a cut of 12726 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 2}, Ncon: 3, Nparts: 4 + Setup: Max: 0.105, Sum: 0.288, Balance: 1.451 + Total: Max: 0.184, Sum: 0.733, Balance: 1.003 +XYZ Cut: 418507 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.574, Sum: 1.709, Balance: 1.345 + Matching: Max: 0.565, Sum: 2.180, Balance: 1.037 +Contraction: Max: 0.765, Sum: 3.044, Balance: 1.005 + InitPart: Max: 0.105, Sum: 0.417, Balance: 1.005 + Project: Max: 0.086, Sum: 0.217, Balance: 1.593 + Initialize: Max: 0.288, Sum: 0.906, Balance: 1.271 + K-way: Max: 0.798, Sum: 3.034, Balance: 1.052 + Move: Max: 0.767, Sum: 3.042, Balance: 1.009 + Remap: Max: 0.010, Sum: 0.040, Balance: 1.016 + Total: Max: 3.240, Sum: 12.933, Balance: 1.002 +Final 4-way CUT: 14695 Balance: 1.034 1.012 1.018 avg: 1.021 +ParMETIS_V3_PartGeomKway reported a cut of 14695 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 1}, Ncon: 5, Nparts: 4 + Setup: Max: 0.113, Sum: 0.268, Balance: 1.688 + Total: Max: 0.188, Sum: 0.749, Balance: 1.002 +XYZ Cut: 418507 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.703, Sum: 1.983, Balance: 1.418 + Matching: Max: 0.620, Sum: 2.423, Balance: 1.023 +Contraction: Max: 0.669, Sum: 2.631, Balance: 1.017 + InitPart: Max: 0.169, Sum: 0.675, Balance: 1.004 + Project: Max: 0.057, Sum: 0.129, Balance: 1.770 + Initialize: Max: 0.251, Sum: 0.842, Balance: 1.190 + K-way: Max: 0.867, Sum: 3.321, Balance: 1.044 + Move: Max: 0.330, Sum: 1.303, Balance: 1.015 + Remap: Max: -0.004, Sum: -0.017, Balance: 0.879 + Total: Max: 3.364, Sum: 13.428, Balance: 1.002 +Final 4-way CUT: 14470 Balance: 1.045 1.031 1.032 1.041 1.034 avg: 1.037 +ParMETIS_V3_PartGeomKway reported a cut of 14470 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 2}, Ncon: 5, Nparts: 4 + Setup: Max: 0.159, Sum: 0.354, Balance: 1.803 + Total: Max: 0.254, Sum: 1.015, Balance: 1.002 +XYZ Cut: 418507 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.722, Sum: 2.256, Balance: 1.280 + Matching: Max: 0.640, Sum: 2.453, Balance: 1.043 +Contraction: Max: 0.803, Sum: 3.153, Balance: 1.019 + InitPart: Max: 0.147, Sum: 0.586, Balance: 1.003 + Project: Max: 0.065, Sum: 0.111, Balance: 2.346 + Initialize: Max: 0.231, Sum: 0.822, Balance: 1.125 + K-way: Max: 0.888, Sum: 3.417, Balance: 1.039 + Move: Max: 1.576, Sum: 6.284, Balance: 1.003 + Remap: Max: 0.013, Sum: 0.052, Balance: 1.011 + Total: Max: 3.636, Sum: 14.520, Balance: 1.002 +Final 4-way CUT: 13886 Balance: 1.039 1.044 1.030 1.040 1.013 avg: 1.033 +ParMETIS_V3_PartGeomKway reported a cut of 13886 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 1}, Ncon: 1, Nparts: 2 + Setup: Max: 0.140, Sum: 0.409, Balance: 1.370 + Total: Max: 0.225, Sum: 0.894, Balance: 1.008 +XYZ Cut: 418507 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.634, Sum: 1.852, Balance: 1.369 + Matching: Max: 0.560, Sum: 2.169, Balance: 1.033 +Contraction: Max: 0.652, Sum: 2.573, Balance: 1.014 + InitPart: Max: 0.016, Sum: 0.061, Balance: 1.027 + Project: Max: 0.049, Sum: 0.150, Balance: 1.301 + Initialize: Max: 0.205, Sum: 0.693, Balance: 1.183 + K-way: Max: 0.627, Sum: 2.386, Balance: 1.051 + Move: Max: 0.755, Sum: 3.006, Balance: 1.004 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.018 + Total: Max: 2.863, Sum: 11.433, Balance: 1.001 +Final 2-way CUT: 2511 Balance: 1.019 avg: 1.019 +ParMETIS_V3_PartGeomKway reported a cut of 2511 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 2}, Ncon: 1, Nparts: 2 + Setup: Max: 0.271, Sum: 0.682, Balance: 1.588 + Total: Max: 0.340, Sum: 1.358, Balance: 1.001 +XYZ Cut: 418507 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.745, Sum: 2.226, Balance: 1.339 + Matching: Max: 0.625, Sum: 2.355, Balance: 1.062 +Contraction: Max: 0.701, Sum: 2.619, Balance: 1.071 + InitPart: Max: 0.018, Sum: 0.071, Balance: 1.030 + Project: Max: 0.134, Sum: 0.313, Balance: 1.713 + Initialize: Max: 0.264, Sum: 0.893, Balance: 1.184 + K-way: Max: 1.009, Sum: 3.929, Balance: 1.028 + Move: Max: 2.843, Sum: 11.330, Balance: 1.004 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.019 + Total: Max: 3.507, Sum: 13.989, Balance: 1.003 +Final 2-way CUT: 2964 Balance: 1.000 avg: 1.000 +ParMETIS_V3_PartGeomKway reported a cut of 2964 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 1}, Ncon: 3, Nparts: 2 + Setup: Max: 0.113, Sum: 0.373, Balance: 1.213 + Total: Max: 0.209, Sum: 0.835, Balance: 1.002 +XYZ Cut: 418507 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.706, Sum: 2.162, Balance: 1.305 + Matching: Max: 0.603, Sum: 2.342, Balance: 1.030 +Contraction: Max: 0.645, Sum: 2.574, Balance: 1.003 + InitPart: Max: 0.053, Sum: 0.209, Balance: 1.012 + Project: Max: 0.056, Sum: 0.056, Balance: 4.037 + Initialize: Max: 0.229, Sum: 0.770, Balance: 1.192 + K-way: Max: 0.828, Sum: 3.080, Balance: 1.075 + Move: Max: 0.656, Sum: 2.568, Balance: 1.022 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.009 + Total: Max: 3.174, Sum: 12.646, Balance: 1.004 +Final 2-way CUT: 6395 Balance: 1.038 1.036 1.035 avg: 1.036 +ParMETIS_V3_PartGeomKway reported a cut of 6395 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 2}, Ncon: 3, Nparts: 2 + Setup: Max: 0.214, Sum: 0.509, Balance: 1.683 + Total: Max: 0.324, Sum: 1.294, Balance: 1.001 +XYZ Cut: 418507 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.682, Sum: 2.004, Balance: 1.362 + Matching: Max: 0.591, Sum: 2.258, Balance: 1.046 +Contraction: Max: 0.938, Sum: 3.709, Balance: 1.012 + InitPart: Max: 0.045, Sum: 0.178, Balance: 1.009 + Project: Max: 0.067, Sum: 0.183, Balance: 1.473 + Initialize: Max: 0.221, Sum: 0.762, Balance: 1.158 + K-way: Max: 0.764, Sum: 2.969, Balance: 1.030 + Move: Max: 0.710, Sum: 2.799, Balance: 1.015 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.018 + Total: Max: 3.443, Sum: 13.742, Balance: 1.002 +Final 2-way CUT: 6299 Balance: 1.003 1.003 1.004 avg: 1.003 +ParMETIS_V3_PartGeomKway reported a cut of 6299 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 1}, Ncon: 5, Nparts: 2 + Setup: Max: 0.134, Sum: 0.348, Balance: 1.539 + Total: Max: 0.221, Sum: 0.849, Balance: 1.039 +XYZ Cut: 418507 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.600, Sum: 1.930, Balance: 1.243 + Matching: Max: 0.551, Sum: 2.096, Balance: 1.052 +Contraction: Max: 0.655, Sum: 2.576, Balance: 1.017 + InitPart: Max: 0.067, Sum: 0.268, Balance: 1.006 + Project: Max: 0.041, Sum: 0.048, Balance: 3.451 + Initialize: Max: 0.216, Sum: 0.684, Balance: 1.264 + K-way: Max: 0.702, Sum: 2.757, Balance: 1.018 + Move: Max: 0.803, Sum: 3.178, Balance: 1.010 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.024 + Total: Max: 2.977, Sum: 11.877, Balance: 1.003 +Final 2-way CUT: 2626 Balance: 1.022 1.029 1.029 1.030 1.038 avg: 1.029 +ParMETIS_V3_PartGeomKway reported a cut of 2626 + +Testing ParMETIS_V3_PartGeomKway with options[1-2] = {3 2}, Ncon: 5, Nparts: 2 + Setup: Max: 0.107, Sum: 0.263, Balance: 1.623 + Total: Max: 0.181, Sum: 0.723, Balance: 1.002 +XYZ Cut: 418507 Balance: 1.000 [24905 99617 4] + Setup: Max: 0.629, Sum: 1.818, Balance: 1.383 + Matching: Max: 0.567, Sum: 2.172, Balance: 1.044 +Contraction: Max: 0.663, Sum: 2.543, Balance: 1.043 + InitPart: Max: 0.066, Sum: 0.261, Balance: 1.006 + Project: Max: 0.051, Sum: 0.152, Balance: 1.341 + Initialize: Max: 0.166, Sum: 0.585, Balance: 1.137 + K-way: Max: 0.742, Sum: 2.856, Balance: 1.039 + Move: Max: 0.909, Sum: 3.611, Balance: 1.006 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.034 + Total: Max: 2.963, Sum: 11.818, Balance: 1.003 +Final 2-way CUT: 2423 Balance: 1.031 1.020 1.020 1.019 1.008 avg: 1.020 +ParMETIS_V3_PartGeomKway reported a cut of 2423 + +Testing ParMETIS_V3_PartGeom +ParMETIS_V3_PartGeom partition complete + +Testing ParMETIS_V3_RefineKway with default options (before move) + Setup: Max: 0.329, Sum: 0.914, Balance: 1.441 + Matching: Max: 0.247, Sum: 0.760, Balance: 1.301 +Contraction: Max: 0.345, Sum: 0.997, Balance: 1.383 + Project: Max: 0.011, Sum: 0.036, Balance: 1.200 + Initialize: Max: 0.302, Sum: 1.016, Balance: 1.189 + K-way: Max: 0.867, Sum: 3.290, Balance: 1.055 + Remap: Max: 0.010, Sum: 0.037, Balance: 1.112 + Total: Max: 2.032, Sum: 8.123, Balance: 1.001 +Final 4-way Cut: 20449 Balance: 1.050 +NMoved: 32025 11910 11068 22978 +ParMETIS_V3_RefineKway reported a cut of 20449 + +Testing ParMETIS_V3_RefineKway with options[1-3] = {3 1 1}, Ncon: 1, Nparts: 4 + Setup: Max: 0.075, Sum: 0.233, Balance: 1.288 + Matching: Max: 0.163, Sum: 0.622, Balance: 1.048 +Contraction: Max: 0.274, Sum: 0.767, Balance: 1.427 + Project: Max: 0.007, Sum: -0.015, Balance: -1.810 + Initialize: Max: 0.201, Sum: 0.667, Balance: 1.204 + K-way: Max: 0.435, Sum: 1.594, Balance: 1.093 + Remap: Max: -0.001, Sum: -0.011, Balance: 0.255 + Total: Max: 1.135, Sum: 4.536, Balance: 1.001 +Final 4-way Cut: 9124 Balance: 1.046 +NMoved: 140 77 91 168 +ParMETIS_V3_RefineKway reported a cut of 9124 + +Testing ParMETIS_V3_RefineKway with options[1-3] = {3 2 1}, Ncon: 1, Nparts: 4 + Setup: Max: 0.086, Sum: 0.274, Balance: 1.259 + Matching: Max: 0.089, Sum: 0.339, Balance: 1.048 +Contraction: Max: 0.338, Sum: 0.929, Balance: 1.456 + Project: Max: 0.007, Sum: 0.017, Balance: 1.758 + Initialize: Max: 0.191, Sum: 0.705, Balance: 1.083 + K-way: Max: 0.431, Sum: 1.635, Balance: 1.055 + Remap: Max: 0.010, Sum: 0.036, Balance: 1.156 + Total: Max: 1.167, Sum: 4.652, Balance: 1.003 +Final 4-way Cut: 9106 Balance: 1.045 +NMoved: 172 123 93 216 +ParMETIS_V3_RefineKway reported a cut of 9106 + +Testing ParMETIS_V3_RefineKway with options[1-3] = {3 1 1}, Ncon: 3, Nparts: 4 + Setup: Max: 0.120, Sum: 0.315, Balance: 1.526 + Matching: Max: 0.179, Sum: 0.666, Balance: 1.074 +Contraction: Max: 0.260, Sum: 0.769, Balance: 1.353 + Project: Max: 0.010, Sum: 0.033, Balance: 1.255 + Initialize: Max: 0.137, Sum: 0.487, Balance: 1.123 + K-way: Max: 0.518, Sum: 1.964, Balance: 1.056 + Remap: Max: 0.013, Sum: 0.031, Balance: 1.670 + Total: Max: 1.273, Sum: 5.088, Balance: 1.001 +Final 4-way Cut: 9018 Balance: 1.043 1.043 1.043 +NMoved: 260 135 100 235 +ParMETIS_V3_RefineKway reported a cut of 9018 + +Testing ParMETIS_V3_RefineKway with options[1-3] = {3 2 1}, Ncon: 3, Nparts: 4 + Setup: Max: 0.105, Sum: 0.347, Balance: 1.210 + Matching: Max: 0.213, Sum: 0.805, Balance: 1.058 +Contraction: Max: 0.310, Sum: 0.825, Balance: 1.504 + Project: Max: 0.009, Sum: -0.003, Balance: -12.691 + Initialize: Max: 0.135, Sum: 0.470, Balance: 1.150 + K-way: Max: 0.488, Sum: 1.774, Balance: 1.100 + Remap: Max: 0.011, Sum: 0.040, Balance: 1.107 + Total: Max: 1.304, Sum: 5.210, Balance: 1.001 +Final 4-way Cut: 9024 Balance: 1.043 1.043 1.043 +NMoved: 267 135 118 253 +ParMETIS_V3_RefineKway reported a cut of 9024 + +Testing ParMETIS_V3_RefineKway with options[1-3] = {3 1 1}, Ncon: 5, Nparts: 4 + Setup: Max: 0.113, Sum: 0.333, Balance: 1.364 + Matching: Max: 0.252, Sum: 0.916, Balance: 1.102 +Contraction: Max: 0.328, Sum: 0.814, Balance: 1.614 + Project: Max: 0.009, Sum: 0.002, Balance: 21.632 + Initialize: Max: 0.142, Sum: 0.500, Balance: 1.140 + K-way: Max: 0.557, Sum: 2.030, Balance: 1.097 + Remap: Max: 0.010, Sum: 0.035, Balance: 1.098 + Total: Max: 1.365, Sum: 5.454, Balance: 1.001 +Final 4-way Cut: 9081 Balance: 1.046 1.046 1.046 1.046 1.046 +NMoved: 192 135 100 235 +ParMETIS_V3_RefineKway reported a cut of 9081 + +Testing ParMETIS_V3_RefineKway with options[1-3] = {3 2 1}, Ncon: 5, Nparts: 4 + Setup: Max: 0.148, Sum: 0.373, Balance: 1.583 + Matching: Max: 0.226, Sum: 0.836, Balance: 1.084 +Contraction: Max: 0.330, Sum: 0.852, Balance: 1.549 + Project: Max: 0.011, Sum: 0.019, Balance: 2.309 + Initialize: Max: 0.134, Sum: 0.472, Balance: 1.137 + K-way: Max: 0.555, Sum: 2.154, Balance: 1.031 + Remap: Max: -0.006, Sum: -0.028, Balance: 0.854 + Total: Max: 1.408, Sum: 5.630, Balance: 1.001 +Final 4-way Cut: 9090 Balance: 1.045 1.045 1.045 1.045 1.045 +NMoved: 200 138 121 259 +ParMETIS_V3_RefineKway reported a cut of 9090 +Initial Load Imbalance: 1.3148, [26344 47967 145931] for afactor: 4 +Initial Load Imbalance: 1.6407, [35080 135843 331187] for afactor: 4 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 1000.000, Ncon: 1, Nparts: 8 +[ 99617 1324862 23436 26023][400] +[ 51520 769504 12144 13427][400] +[ 26858 411494 6350 6981][400] +[ 14060 218252 3344 3633][400] +[ 7404 115538 1780 1896][400] +[ 3912 60528 960 993][400] +[ 2101 31812 521 530][400] +[ 1146 16602 283 291][400] +[ 641 8632 157 167][400] +[ 365 4570 88 96][400] +nvtxs: 365, balance: 1.019 +nvtxs: 641, cut: 23753, balance: 1.050 +nvtxs: 1146, cut: 23103, balance: 1.052 +nvtxs: 2101, cut: 22312, balance: 1.049 +nvtxs: 3912, cut: 21159, balance: 1.050 +nvtxs: 7404, cut: 20171, balance: 1.050 +nvtxs: 14060, cut: 19304, balance: 1.050 +nvtxs: 26858, cut: 18461, balance: 1.050 +nvtxs: 51520, cut: 17456, balance: 1.050 +nvtxs: 99617, cut: 16161, balance: 1.050 + Setup: Max: 0.097, Sum: 0.252, Balance: 1.544 + Matching: Max: 0.281, Sum: 1.081, Balance: 1.040 +Contraction: Max: 0.457, Sum: 1.793, Balance: 1.020 + InitPart: Max: 0.032, Sum: 0.124, Balance: 1.049 + Project: Max: 0.022, Sum: 0.044, Balance: 2.022 + Initialize: Max: 0.177, Sum: 0.590, Balance: 1.200 + K-way: Max: 0.743, Sum: 2.885, Balance: 1.031 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.292 + Total: Max: 1.964, Sum: 7.851, Balance: 1.001 +Final 8-way Cut: 16161 Balance: 1.050 +NMoved: 27541 7332 7369 14701 +ParMETIS_V3_AdaptiveRepart reported a cut of 16161 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 1000.000, Ncon: 1, Nparts: 8 +[ 99617 1324862 23436 26023][400] +[ 51526 769238 12122 13433][400] +[ 26833 410954 6315 6981][400] +[ 14029 218176 3309 3638][400] +[ 7393 115482 1741 1919][400] +[ 3925 60784 921 1014][400] +[ 2098 31932 494 538][400] +[ 1137 16642 269 292][400] +[ 627 8640 149 161][400] +[ 355 4468 85 90][400] +nvtxs: 355, balance: 1.017 +nvtxs: 627, cut: 24572, balance: 1.048 +nvtxs: 1137, cut: 23125, balance: 1.046 +nvtxs: 2098, cut: 22008, balance: 1.049 +nvtxs: 3925, cut: 21385, balance: 1.051 +nvtxs: 7393, cut: 20507, balance: 1.050 +nvtxs: 14029, cut: 19749, balance: 1.050 +nvtxs: 26833, cut: 18945, balance: 1.050 +nvtxs: 51526, cut: 18010, balance: 1.050 +nvtxs: 99617, cut: 16894, balance: 1.050 + Setup: Max: 0.068, Sum: 0.124, Balance: 2.194 + Matching: Max: 0.281, Sum: 1.063, Balance: 1.058 +Contraction: Max: 0.383, Sum: 1.522, Balance: 1.007 + InitPart: Max: 0.031, Sum: 0.092, Balance: 1.359 + Project: Max: 0.029, Sum: 0.092, Balance: 1.252 + Initialize: Max: 0.186, Sum: 0.633, Balance: 1.174 + K-way: Max: 0.743, Sum: 2.884, Balance: 1.031 + Remap: Max: 0.000, Sum: 0.001, Balance: 2.075 + Total: Max: 1.876, Sum: 7.499, Balance: 1.001 +Final 8-way Cut: 16894 Balance: 1.050 +NMoved: 20370 6382 6395 12777 +ParMETIS_V3_AdaptiveRepart reported a cut of 16894 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 1.000, Ncon: 1, Nparts: 8 +[ 99617 1324862 23436 26023][400] +[ 51520 769504 12144 13427][400] +[ 26858 411494 6350 6981][400] +[ 14060 218252 3344 3633][400] +[ 7404 115538 1780 1896][400] +[ 3912 60528 960 993][400] +[ 2101 31812 521 530][400] +[ 1146 16602 283 291][400] +[ 641 8632 157 167][400] +[ 365 4570 88 96][400] +nvtxs: 365, balance: 1.055 +nvtxs: 641, cut: 28724, balance: 1.049 +nvtxs: 1146, cut: 26926, balance: 1.050 +nvtxs: 2101, cut: 25830, balance: 1.050 +nvtxs: 3912, cut: 25333, balance: 1.050 +nvtxs: 7404, cut: 24637, balance: 1.051 +nvtxs: 14060, cut: 23627, balance: 1.050 +nvtxs: 26858, cut: 22880, balance: 1.050 +nvtxs: 51520, cut: 21888, balance: 1.050 +nvtxs: 99617, cut: 20532, balance: 1.050 + Setup: Max: 0.115, Sum: 0.290, Balance: 1.579 + Matching: Max: 0.268, Sum: 0.987, Balance: 1.084 +Contraction: Max: 0.369, Sum: 1.441, Balance: 1.025 + InitPart: Max: 0.034, Sum: 0.116, Balance: 1.177 + Project: Max: 0.023, Sum: 0.026, Balance: 3.561 + Initialize: Max: 0.210, Sum: 0.651, Balance: 1.289 + K-way: Max: 0.801, Sum: 2.982, Balance: 1.074 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.261 + Total: Max: 1.905, Sum: 7.612, Balance: 1.001 +Final 8-way Cut: 20532 Balance: 1.050 +NMoved: 12975 5875 4424 10299 +ParMETIS_V3_AdaptiveRepart reported a cut of 20532 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 1.000, Ncon: 1, Nparts: 8 +[ 99617 1324862 23436 26023][400] +[ 51526 769238 12122 13433][400] +[ 26833 410954 6315 6981][400] +[ 14029 218176 3309 3638][400] +[ 7393 115482 1741 1919][400] +[ 3925 60784 921 1014][400] +[ 2098 31932 494 538][400] +[ 1137 16642 269 292][400] +[ 627 8640 149 161][400] +[ 355 4468 85 90][400] +nvtxs: 355, balance: 1.078 +nvtxs: 627, cut: 26717, balance: 1.049 +nvtxs: 1137, cut: 25875, balance: 1.048 +nvtxs: 2098, cut: 23702, balance: 1.050 +nvtxs: 3925, cut: 22721, balance: 1.050 +nvtxs: 7393, cut: 21980, balance: 1.050 +nvtxs: 14029, cut: 20698, balance: 1.050 +nvtxs: 26833, cut: 19922, balance: 1.050 +nvtxs: 51526, cut: 19108, balance: 1.050 +nvtxs: 99617, cut: 18235, balance: 1.050 + Setup: Max: 0.124, Sum: 0.324, Balance: 1.526 + Matching: Max: 0.260, Sum: 0.971, Balance: 1.072 +Contraction: Max: 0.365, Sum: 1.433, Balance: 1.020 + InitPart: Max: 0.029, Sum: 0.073, Balance: 1.566 + Project: Max: 0.033, Sum: 0.060, Balance: 2.183 + Initialize: Max: 0.207, Sum: 0.664, Balance: 1.248 + K-way: Max: 0.717, Sum: 2.756, Balance: 1.040 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.367 + Total: Max: 1.862, Sum: 7.442, Balance: 1.001 +Final 8-way Cut: 18235 Balance: 1.050 +NMoved: 13188 5310 3945 9255 +ParMETIS_V3_AdaptiveRepart reported a cut of 18235 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 0.001, Ncon: 1, Nparts: 8 +[ 99617 1324862 23436 26023][400] +[ 51520 769504 12144 13427][400] +[ 26858 411494 6350 6981][400] +[ 14060 218252 3344 3633][400] +[ 7404 115538 1780 1896][400] +[ 3912 60528 960 993][400] +[ 2101 31812 521 530][400] +[ 1146 16602 283 291][400] +[ 641 8632 157 167][400] +[ 365 4570 88 96][400] +nvtxs: 365, balance: 1.055 +nvtxs: 641, cut: 35651, balance: 1.056 +nvtxs: 1146, cut: 35763, balance: 1.056 +nvtxs: 2101, cut: 35878, balance: 1.056 +nvtxs: 3912, cut: 35801, balance: 1.056 +nvtxs: 7404, cut: 35770, balance: 1.056 +nvtxs: 14060, cut: 35796, balance: 1.056 +nvtxs: 26858, cut: 35784, balance: 1.056 +nvtxs: 51520, cut: 35777, balance: 1.056 +nvtxs: 99617, cut: 35750, balance: 1.056 + Setup: Max: 0.096, Sum: 0.223, Balance: 1.714 + Matching: Max: 0.299, Sum: 1.111, Balance: 1.076 +Contraction: Max: 0.379, Sum: 1.483, Balance: 1.022 + InitPart: Max: 0.039, Sum: 0.150, Balance: 1.035 + Project: Max: 0.046, Sum: 0.091, Balance: 2.028 + Initialize: Max: 0.255, Sum: 0.704, Balance: 1.450 + K-way: Max: 0.694, Sum: 2.595, Balance: 1.070 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.424 + Total: Max: 1.841, Sum: 7.359, Balance: 1.000 +Final 8-way Cut: 35750 Balance: 1.056 +NMoved: 11612 4910 4255 9165 +ParMETIS_V3_AdaptiveRepart reported a cut of 35750 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 0.001, Ncon: 1, Nparts: 8 +[ 99617 1324862 23436 26023][400] +[ 51526 769238 12122 13433][400] +[ 26833 410954 6315 6981][400] +[ 14029 218176 3309 3638][400] +[ 7393 115482 1741 1919][400] +[ 3925 60784 921 1014][400] +[ 2098 31932 494 538][400] +[ 1137 16642 269 292][400] +[ 627 8640 149 161][400] +[ 355 4468 85 90][400] +nvtxs: 355, balance: 1.078 +nvtxs: 627, cut: 36167, balance: 1.077 +nvtxs: 1137, cut: 35876, balance: 1.077 +nvtxs: 2098, cut: 36252, balance: 1.071 +nvtxs: 3925, cut: 36197, balance: 1.071 +nvtxs: 7393, cut: 36104, balance: 1.071 +nvtxs: 14029, cut: 36147, balance: 1.071 +nvtxs: 26833, cut: 36042, balance: 1.070 +nvtxs: 51526, cut: 36100, balance: 1.070 +nvtxs: 99617, cut: 36211, balance: 1.069 + Setup: Max: 0.090, Sum: 0.285, Balance: 1.256 + Matching: Max: 0.284, Sum: 1.100, Balance: 1.031 +Contraction: Max: 0.366, Sum: 1.422, Balance: 1.030 + InitPart: Max: 0.035, Sum: 0.133, Balance: 1.044 + Project: Max: 0.032, Sum: 0.063, Balance: 2.018 + Initialize: Max: 0.244, Sum: 0.798, Balance: 1.225 + K-way: Max: 0.679, Sum: 2.596, Balance: 1.046 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.452 + Total: Max: 1.852, Sum: 7.379, Balance: 1.004 +Final 8-way Cut: 36211 Balance: 1.069 +NMoved: 11045 4330 3954 8284 +ParMETIS_V3_AdaptiveRepart reported a cut of 36211 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 1000.000, Ncon: 3, Nparts: 8 +[ 99617 1324862 23436 26023][1200] +[ 51520 769504 12144 13427][1200] +[ 26792 410272 6326 6969][1200] +[ 13981 216770 3319 3623][1200] +[ 7338 114436 1750 1897][1200] +[ 3870 60218 928 995][1200] +[ 2066 31410 500 530][1200] +[ 1120 16380 274 285][1200] +nvtxs: 1120, balance: 1.008 1.010 1.010 +nvtxs: 2066, cut: 36476, balance: 1.047 1.048 1.036 +nvtxs: 3870, cut: 34085, balance: 1.049 1.047 1.044 +nvtxs: 7338, cut: 31995, balance: 1.051 1.048 1.037 +nvtxs: 13981, cut: 30120, balance: 1.041 1.050 1.036 +nvtxs: 26792, cut: 28468, balance: 1.045 1.045 1.037 +nvtxs: 51520, cut: 26657, balance: 1.043 1.040 1.041 +nvtxs: 99617, cut: 24463, balance: 1.043 1.047 1.050 + Setup: Max: 0.096, Sum: 0.243, Balance: 1.577 + Matching: Max: 0.302, Sum: 1.147, Balance: 1.053 +Contraction: Max: 0.334, Sum: 1.315, Balance: 1.017 + InitPart: Max: 0.350, Sum: 1.393, Balance: 1.004 + Project: Max: 0.030, Sum: -0.007, Balance: -17.571 + Initialize: Max: 0.141, Sum: 0.503, Balance: 1.124 + K-way: Max: 0.824, Sum: 3.109, Balance: 1.060 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.408 + Total: Max: 2.216, Sum: 8.858, Balance: 1.001 +Final 8-way Cut: 24463 Balance: 1.043 1.047 1.050 +NMoved: 59087 8982 9669 18651 +ParMETIS_V3_AdaptiveRepart reported a cut of 24463 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 1000.000, Ncon: 3, Nparts: 8 +[ 99617 1324862 23436 26023][1200] +[ 51526 769238 12122 13433][1200] +[ 26780 409760 6306 6964][1200] +[ 13964 216890 3300 3618][1200] +[ 7324 114522 1749 1892][1200] +[ 3861 60152 931 996][1200] +[ 2067 31478 501 532][1200] +[ 1121 16376 274 285][1200] +nvtxs: 1121, balance: 1.007 1.008 1.014 +nvtxs: 2067, cut: 35458, balance: 1.049 1.045 1.038 +nvtxs: 3861, cut: 33140, balance: 1.049 1.046 1.030 +nvtxs: 7324, cut: 31642, balance: 1.050 1.044 1.037 +nvtxs: 13964, cut: 29859, balance: 1.049 1.045 1.041 +nvtxs: 26780, cut: 28382, balance: 1.050 1.044 1.039 +nvtxs: 51526, cut: 26891, balance: 1.046 1.050 1.037 +nvtxs: 99617, cut: 24686, balance: 1.046 1.049 1.045 + Setup: Max: 0.048, Sum: 0.148, Balance: 1.289 + Matching: Max: 0.323, Sum: 1.243, Balance: 1.038 +Contraction: Max: 0.350, Sum: 1.381, Balance: 1.015 + InitPart: Max: 0.321, Sum: 1.279, Balance: 1.004 + Project: Max: 0.022, Sum: 0.033, Balance: 2.685 + Initialize: Max: 0.144, Sum: 0.506, Balance: 1.141 + K-way: Max: 0.789, Sum: 2.986, Balance: 1.057 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.451 + Total: Max: 2.180, Sum: 8.712, Balance: 1.001 +Final 8-way Cut: 24686 Balance: 1.046 1.049 1.045 +NMoved: 61678 11392 11729 23121 +ParMETIS_V3_AdaptiveRepart reported a cut of 24686 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 1.000, Ncon: 3, Nparts: 8 +[ 99617 1324862 23436 26023][1200] +[ 51520 769504 12144 13427][1200] +[ 26792 410272 6326 6969][1200] +[ 13981 216770 3319 3623][1200] +[ 7338 114436 1750 1897][1200] +[ 3870 60218 928 995][1200] +[ 2066 31410 500 530][1200] +[ 1120 16380 274 285][1200] +nvtxs: 1120, balance: 1.008 1.010 1.010 +nvtxs: 2066, cut: 36252, balance: 1.049 1.040 1.042 +nvtxs: 3870, cut: 34229, balance: 1.050 1.035 1.049 +nvtxs: 7338, cut: 31989, balance: 1.045 1.041 1.050 +nvtxs: 13981, cut: 30260, balance: 1.040 1.050 1.050 +nvtxs: 26792, cut: 28645, balance: 1.045 1.045 1.050 +nvtxs: 51520, cut: 26769, balance: 1.042 1.049 1.050 +nvtxs: 99617, cut: 24759, balance: 1.043 1.050 1.050 + Setup: Max: 0.053, Sum: 0.154, Balance: 1.370 + Matching: Max: 0.266, Sum: 1.039, Balance: 1.023 +Contraction: Max: 0.373, Sum: 1.491, Balance: 1.002 + InitPart: Max: 0.328, Sum: 1.310, Balance: 1.003 + Project: Max: 0.024, Sum: 0.059, Balance: 1.611 + Initialize: Max: 0.129, Sum: 0.453, Balance: 1.138 + K-way: Max: 0.819, Sum: 3.081, Balance: 1.063 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.367 + Total: Max: 2.226, Sum: 8.896, Balance: 1.001 +Final 8-way Cut: 24759 Balance: 1.043 1.050 1.050 +NMoved: 57772 8347 9197 17544 +ParMETIS_V3_AdaptiveRepart reported a cut of 24759 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 1.000, Ncon: 3, Nparts: 8 +[ 99617 1324862 23436 26023][1200] +[ 51526 769238 12122 13433][1200] +[ 26780 409760 6306 6964][1200] +[ 13964 216890 3300 3618][1200] +[ 7324 114522 1749 1892][1200] +[ 3861 60152 931 996][1200] +[ 2067 31478 501 532][1200] +[ 1121 16376 274 285][1200] +nvtxs: 1121, balance: 1.007 1.008 1.014 +nvtxs: 2067, cut: 35452, balance: 1.029 1.025 1.048 +nvtxs: 3861, cut: 33287, balance: 1.041 1.032 1.049 +nvtxs: 7324, cut: 31629, balance: 1.049 1.042 1.050 +nvtxs: 13964, cut: 30125, balance: 1.044 1.040 1.050 +nvtxs: 26780, cut: 28710, balance: 1.044 1.039 1.050 +nvtxs: 51526, cut: 27075, balance: 1.043 1.050 1.050 +nvtxs: 99617, cut: 24948, balance: 1.043 1.050 1.050 + Setup: Max: 0.070, Sum: 0.147, Balance: 1.917 + Matching: Max: 0.302, Sum: 1.192, Balance: 1.013 +Contraction: Max: 0.329, Sum: 1.282, Balance: 1.026 + InitPart: Max: 0.331, Sum: 1.320, Balance: 1.004 + Project: Max: 0.032, Sum: 0.064, Balance: 1.990 + Initialize: Max: 0.146, Sum: 0.565, Balance: 1.030 + K-way: Max: 0.806, Sum: 3.051, Balance: 1.056 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.454 + Total: Max: 2.217, Sum: 8.851, Balance: 1.002 +Final 8-way Cut: 24948 Balance: 1.043 1.050 1.050 +NMoved: 60554 11264 11726 22990 +ParMETIS_V3_AdaptiveRepart reported a cut of 24948 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 0.001, Ncon: 3, Nparts: 8 +[ 99617 1324862 23436 26023][1200] +[ 51520 769504 12144 13427][1200] +[ 26792 410272 6326 6969][1200] +[ 13981 216770 3319 3623][1200] +[ 7338 114436 1750 1897][1200] +[ 3870 60218 928 995][1200] +[ 2066 31410 500 530][1200] +[ 1120 16380 274 285][1200] +nvtxs: 1120, balance: 1.008 1.010 1.010 +nvtxs: 2066, cut: 52145, balance: 1.051 1.043 1.053 +nvtxs: 3870, cut: 52590, balance: 1.049 1.050 1.053 +nvtxs: 7338, cut: 52697, balance: 1.050 1.049 1.051 +nvtxs: 13981, cut: 52701, balance: 1.051 1.050 1.050 +nvtxs: 26792, cut: 52816, balance: 1.050 1.050 1.050 +nvtxs: 51520, cut: 52771, balance: 1.050 1.050 1.050 +nvtxs: 99617, cut: 52766, balance: 1.050 1.050 1.050 + Setup: Max: 0.086, Sum: 0.229, Balance: 1.496 + Matching: Max: 0.400, Sum: 1.565, Balance: 1.022 +Contraction: Max: 0.411, Sum: 1.639, Balance: 1.002 + InitPart: Max: 0.330, Sum: 1.315, Balance: 1.004 + Project: Max: 0.048, Sum: 0.098, Balance: 1.977 + Initialize: Max: 0.144, Sum: 0.565, Balance: 1.022 + K-way: Max: 0.711, Sum: 2.689, Balance: 1.058 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.404 + Total: Max: 2.369, Sum: 9.472, Balance: 1.001 +Final 8-way Cut: 52766 Balance: 1.050 1.050 1.050 +NMoved: 55215 8044 8937 16981 +ParMETIS_V3_AdaptiveRepart reported a cut of 52766 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 0.001, Ncon: 3, Nparts: 8 +[ 99617 1324862 23436 26023][1200] +[ 51526 769238 12122 13433][1200] +[ 26780 409760 6306 6964][1200] +[ 13964 216890 3300 3618][1200] +[ 7324 114522 1749 1892][1200] +[ 3861 60152 931 996][1200] +[ 2067 31478 501 532][1200] +[ 1121 16376 274 285][1200] +nvtxs: 1121, balance: 1.007 1.008 1.014 +nvtxs: 2067, cut: 54557, balance: 1.051 1.050 1.049 +nvtxs: 3861, cut: 54729, balance: 1.050 1.050 1.050 +nvtxs: 7324, cut: 54778, balance: 1.050 1.050 1.050 +nvtxs: 13964, cut: 54927, balance: 1.050 1.050 1.050 +nvtxs: 26780, cut: 54850, balance: 1.050 1.050 1.051 +nvtxs: 51526, cut: 54904, balance: 1.050 1.050 1.050 +nvtxs: 99617, cut: 54771, balance: 1.050 1.050 1.050 + Setup: Max: 0.084, Sum: 0.241, Balance: 1.399 + Matching: Max: 0.284, Sum: 1.075, Balance: 1.056 +Contraction: Max: 0.404, Sum: 1.607, Balance: 1.005 + InitPart: Max: 0.342, Sum: 1.357, Balance: 1.009 + Project: Max: 0.028, Sum: 0.051, Balance: 2.211 + Initialize: Max: 0.133, Sum: 0.511, Balance: 1.038 + K-way: Max: 0.838, Sum: 3.176, Balance: 1.056 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.446 + Total: Max: 2.343, Sum: 9.356, Balance: 1.002 +Final 8-way Cut: 54771 Balance: 1.050 1.050 1.050 +NMoved: 57592 10695 10795 21490 +ParMETIS_V3_AdaptiveRepart reported a cut of 54771 +Initial Load Imbalance: 1.5768, [214985 574403 1457095] for afactor: 4 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 1000.000, Ncon: 1, Nparts: 4 +[ 99617 1324862 23436 26023][200] +[ 51494 769096 12134 13452][200] +[ 26776 410992 6313 7001][200] +[ 14000 218130 3303 3662][200] +[ 7354 114978 1737 1927][200] +[ 3887 60418 920 1018][200] +[ 2072 31328 495 543][200] +[ 1117 16208 267 293][200] +[ 615 8340 146 162][200] +[ 349 4308 81 94][200] +[ 203 2244 46 55][200] +nvtxs: 203, balance: 1.001 +nvtxs: 349, cut: 16162, balance: 1.037 +nvtxs: 615, cut: 15156, balance: 1.046 +nvtxs: 1117, cut: 14700, balance: 1.046 +nvtxs: 2072, cut: 13210, balance: 1.034 +nvtxs: 3887, cut: 12774, balance: 1.034 +nvtxs: 7354, cut: 12299, balance: 1.033 +nvtxs: 14000, cut: 11602, balance: 1.034 +nvtxs: 26776, cut: 10987, balance: 1.031 +nvtxs: 51494, cut: 10376, balance: 1.031 +nvtxs: 99617, cut: 9458, balance: 1.031 + Setup: Max: 0.133, Sum: 0.346, Balance: 1.543 + Matching: Max: 0.169, Sum: 0.604, Balance: 1.118 +Contraction: Max: 0.246, Sum: 0.665, Balance: 1.476 + InitPart: Max: 0.023, Sum: 0.046, Balance: 2.026 + Project: Max: 0.009, Sum: 0.016, Balance: 2.205 + Initialize: Max: 0.198, Sum: 0.567, Balance: 1.395 + K-way: Max: 0.732, Sum: 2.741, Balance: 1.068 + Remap: Max: 0.013, Sum: 0.047, Balance: 1.109 + Total: Max: 1.636, Sum: 6.517, Balance: 1.004 +Final 4-way Cut: 9458 Balance: 1.031 +NMoved: 47151 21129 25998 47127 +ParMETIS_V3_AdaptiveRepart reported a cut of 9458 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 1000.000, Ncon: 1, Nparts: 4 +[ 99617 1324862 23436 26023][200] +[ 51513 768928 12122 13449][200] +[ 26792 410712 6304 7002][200] +[ 14015 218024 3307 3669][200] +[ 7368 115250 1741 1938][200] +[ 3896 60636 924 1032][200] +[ 2074 31366 497 549][200] +[ 1114 16162 268 296][200] +[ 614 8372 146 163][200] +[ 347 4332 82 94][200] +[ 202 2208 46 55][200] +nvtxs: 202, balance: 1.014 +nvtxs: 347, cut: 13219, balance: 1.049 +nvtxs: 614, cut: 12390, balance: 1.022 +nvtxs: 1114, cut: 11556, balance: 1.035 +nvtxs: 2074, cut: 10991, balance: 1.035 +nvtxs: 3896, cut: 10310, balance: 1.033 +nvtxs: 7368, cut: 9863, balance: 1.035 +nvtxs: 14015, cut: 9431, balance: 1.032 +nvtxs: 26792, cut: 8958, balance: 1.032 +nvtxs: 51513, cut: 8530, balance: 1.034 +nvtxs: 99617, cut: 7736, balance: 1.035 + Setup: Max: 0.057, Sum: 0.125, Balance: 1.814 + Matching: Max: 0.154, Sum: 0.568, Balance: 1.085 +Contraction: Max: 0.371, Sum: 0.986, Balance: 1.504 + InitPart: Max: 0.027, Sum: 0.058, Balance: 1.831 + Project: Max: 0.009, Sum: 0.018, Balance: 2.114 + Initialize: Max: 0.213, Sum: 0.593, Balance: 1.440 + K-way: Max: 0.677, Sum: 2.526, Balance: 1.071 + Remap: Max: 0.011, Sum: 0.016, Balance: 2.948 + Total: Max: 1.670, Sum: 6.673, Balance: 1.001 +Final 4-way Cut: 7736 Balance: 1.035 +NMoved: 39521 17820 13718 31538 +ParMETIS_V3_AdaptiveRepart reported a cut of 7736 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 1.000, Ncon: 1, Nparts: 4 +[ 99617 1324862 23436 26023][200] +[ 51494 769096 12134 13452][200] +[ 26776 410992 6313 7001][200] +[ 14000 218130 3303 3662][200] +[ 7354 114978 1737 1927][200] +[ 3887 60418 920 1018][200] +[ 2072 31328 495 543][200] +[ 1117 16208 267 293][200] +[ 615 8340 146 162][200] +[ 349 4308 81 94][200] +[ 203 2244 46 55][200] +nvtxs: 203, balance: 1.032 +nvtxs: 349, cut: 13934, balance: 1.051 +nvtxs: 615, cut: 13934, balance: 1.051 +nvtxs: 1117, cut: 13715, balance: 1.051 +nvtxs: 2072, cut: 13400, balance: 1.049 +nvtxs: 3887, cut: 13266, balance: 1.049 +nvtxs: 7354, cut: 12976, balance: 1.050 +nvtxs: 14000, cut: 12434, balance: 1.050 +nvtxs: 26776, cut: 12019, balance: 1.050 +nvtxs: 51494, cut: 11264, balance: 1.050 +nvtxs: 99617, cut: 10545, balance: 1.050 + Setup: Max: 0.124, Sum: 0.281, Balance: 1.765 + Matching: Max: 0.102, Sum: 0.381, Balance: 1.066 +Contraction: Max: 0.314, Sum: 0.823, Balance: 1.527 + InitPart: Max: 0.014, Sum: 0.047, Balance: 1.188 + Project: Max: 0.008, Sum: -0.017, Balance: -1.841 + Initialize: Max: 0.186, Sum: 0.597, Balance: 1.245 + K-way: Max: 0.726, Sum: 2.809, Balance: 1.033 + Remap: Max: -0.005, Sum: -0.026, Balance: 0.810 + Total: Max: 1.631, Sum: 6.494, Balance: 1.004 +Final 4-way Cut: 10545 Balance: 1.050 +NMoved: 8690 5183 7307 12490 +ParMETIS_V3_AdaptiveRepart reported a cut of 10545 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 1.000, Ncon: 1, Nparts: 4 +[ 99617 1324862 23436 26023][200] +[ 51513 768928 12122 13449][200] +[ 26792 410712 6304 7002][200] +[ 14015 218024 3307 3669][200] +[ 7368 115250 1741 1938][200] +[ 3896 60636 924 1032][200] +[ 2074 31366 497 549][200] +[ 1114 16162 268 296][200] +[ 614 8372 146 163][200] +[ 347 4332 82 94][200] +[ 202 2208 46 55][200] +nvtxs: 202, balance: 1.017 +nvtxs: 347, cut: 13505, balance: 1.047 +nvtxs: 614, cut: 12827, balance: 1.047 +nvtxs: 1114, cut: 11908, balance: 1.042 +nvtxs: 2074, cut: 11715, balance: 1.046 +nvtxs: 3896, cut: 11564, balance: 1.050 +nvtxs: 7368, cut: 11290, balance: 1.050 +nvtxs: 14015, cut: 11030, balance: 1.050 +nvtxs: 26792, cut: 10753, balance: 1.049 +nvtxs: 51513, cut: 10438, balance: 1.048 +nvtxs: 99617, cut: 10032, balance: 1.048 + Setup: Max: 0.082, Sum: 0.292, Balance: 1.128 + Matching: Max: 0.224, Sum: 0.862, Balance: 1.042 +Contraction: Max: 0.306, Sum: 0.802, Balance: 1.526 + InitPart: Max: 0.015, Sum: 0.052, Balance: 1.127 + Project: Max: 0.008, Sum: 0.019, Balance: 1.739 + Initialize: Max: 0.194, Sum: 0.579, Balance: 1.342 + K-way: Max: 0.675, Sum: 2.516, Balance: 1.074 + Remap: Max: 0.010, Sum: 0.010, Balance: 3.895 + Total: Max: 1.690, Sum: 6.748, Balance: 1.002 +Final 4-way Cut: 10032 Balance: 1.048 +NMoved: 8390 5353 8135 13488 +ParMETIS_V3_AdaptiveRepart reported a cut of 10032 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 0.001, Ncon: 1, Nparts: 4 +[ 99617 1324862 23436 26023][200] +[ 51494 769096 12134 13452][200] +[ 26776 410992 6313 7001][200] +[ 14000 218130 3303 3662][200] +[ 7354 114978 1737 1927][200] +[ 3887 60418 920 1018][200] +[ 2072 31328 495 543][200] +[ 1117 16208 267 293][200] +[ 615 8340 146 162][200] +[ 349 4308 81 94][200] +[ 203 2244 46 55][200] +nvtxs: 203, balance: 1.032 +nvtxs: 349, cut: 19274, balance: 1.044 +nvtxs: 615, cut: 19350, balance: 1.050 +nvtxs: 1117, cut: 19350, balance: 1.050 +nvtxs: 2072, cut: 19144, balance: 1.050 +nvtxs: 3887, cut: 19154, balance: 1.050 +nvtxs: 7354, cut: 19142, balance: 1.050 +nvtxs: 14000, cut: 19108, balance: 1.050 +nvtxs: 26776, cut: 19115, balance: 1.050 +nvtxs: 51494, cut: 19026, balance: 1.050 +nvtxs: 99617, cut: 18963, balance: 1.050 + Setup: Max: 0.141, Sum: 0.389, Balance: 1.450 + Matching: Max: 0.186, Sum: 0.697, Balance: 1.068 +Contraction: Max: 0.258, Sum: 0.667, Balance: 1.545 + InitPart: Max: 0.008, Sum: 0.027, Balance: 1.182 + Project: Max: 0.009, Sum: 0.017, Balance: 2.101 + Initialize: Max: 0.196, Sum: 0.678, Balance: 1.157 + K-way: Max: 0.546, Sum: 2.157, Balance: 1.012 + Remap: Max: 0.010, Sum: 0.007, Balance: 5.760 + Total: Max: 1.593, Sum: 6.366, Balance: 1.001 +Final 4-way Cut: 18963 Balance: 1.050 +NMoved: 7733 4841 7630 12471 +ParMETIS_V3_AdaptiveRepart reported a cut of 18963 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 0.001, Ncon: 1, Nparts: 4 +[ 99617 1324862 23436 26023][200] +[ 51513 768928 12122 13449][200] +[ 26792 410712 6304 7002][200] +[ 14015 218024 3307 3669][200] +[ 7368 115250 1741 1938][200] +[ 3896 60636 924 1032][200] +[ 2074 31366 497 549][200] +[ 1114 16162 268 296][200] +[ 614 8372 146 163][200] +[ 347 4332 82 94][200] +[ 202 2208 46 55][200] +nvtxs: 202, balance: 1.017 +nvtxs: 347, cut: 18114, balance: 1.048 +nvtxs: 614, cut: 16822, balance: 1.049 +nvtxs: 1114, cut: 16946, balance: 1.050 +nvtxs: 2074, cut: 16967, balance: 1.050 +nvtxs: 3896, cut: 16894, balance: 1.050 +nvtxs: 7368, cut: 16703, balance: 1.050 +nvtxs: 14015, cut: 16489, balance: 1.050 +nvtxs: 26792, cut: 16439, balance: 1.050 +nvtxs: 51513, cut: 16380, balance: 1.050 +nvtxs: 99617, cut: 16260, balance: 1.050 + Setup: Max: 0.092, Sum: 0.276, Balance: 1.335 + Matching: Max: 0.132, Sum: 0.445, Balance: 1.186 +Contraction: Max: 0.293, Sum: 0.744, Balance: 1.575 + InitPart: Max: 0.015, Sum: 0.057, Balance: 1.085 + Project: Max: 0.009, Sum: 0.017, Balance: 2.047 + Initialize: Max: 0.230, Sum: 0.729, Balance: 1.264 + K-way: Max: 0.591, Sum: 2.221, Balance: 1.064 + Remap: Max: 0.012, Sum: 0.042, Balance: 1.174 + Total: Max: 1.496, Sum: 5.981, Balance: 1.001 +Final 4-way Cut: 16260 Balance: 1.050 +NMoved: 7277 4459 7277 11736 +ParMETIS_V3_AdaptiveRepart reported a cut of 16260 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 1000.000, Ncon: 3, Nparts: 4 +[ 99617 1324862 23436 26023][600] +[ 51499 769386 12144 13447][600] +[ 26728 409462 6315 6969][600] +[ 13941 216690 3313 3637][600] +[ 7302 114216 1747 1907][600] +[ 3855 59716 927 1007][600] +[ 2051 31140 496 537][600] +[ 1104 16236 267 290][600] +[ 600 8228 145 158][600] +nvtxs: 600, balance: 1.011 1.014 1.009 +nvtxs: 1104, cut: 20053, balance: 1.046 1.033 1.045 +nvtxs: 2051, cut: 18748, balance: 1.047 1.034 1.043 +nvtxs: 3855, cut: 17630, balance: 1.050 1.044 1.044 +nvtxs: 7302, cut: 16458, balance: 1.049 1.033 1.050 +nvtxs: 13941, cut: 15557, balance: 1.050 1.034 1.046 +nvtxs: 26728, cut: 14382, balance: 1.050 1.034 1.049 +nvtxs: 51499, cut: 13462, balance: 1.050 1.035 1.049 +nvtxs: 99617, cut: 12123, balance: 1.050 1.035 1.050 + Setup: Max: 0.081, Sum: 0.220, Balance: 1.466 + Matching: Max: 0.227, Sum: 0.858, Balance: 1.058 +Contraction: Max: 0.296, Sum: 0.770, Balance: 1.539 + InitPart: Max: 0.145, Sum: 0.576, Balance: 1.009 + Project: Max: 0.009, Sum: 0.018, Balance: 1.977 + Initialize: Max: 0.167, Sum: 0.615, Balance: 1.084 + K-way: Max: 0.768, Sum: 2.848, Balance: 1.078 + Remap: Max: 0.014, Sum: 0.050, Balance: 1.150 + Total: Max: 1.855, Sum: 7.409, Balance: 1.001 +Final 4-way Cut: 12123 Balance: 1.050 1.035 1.050 +NMoved: 55390 16752 20755 37507 +ParMETIS_V3_AdaptiveRepart reported a cut of 12123 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 1000.000, Ncon: 3, Nparts: 4 +[ 99617 1324862 23436 26023][600] +[ 51520 769370 12126 13457][600] +[ 26721 409750 6303 6989][600] +[ 13940 216498 3302 3643][600] +[ 7302 113832 1728 1911][600] +[ 3846 59572 911 1007][600] +[ 2043 30980 486 534][600] +[ 1091 15974 265 282][600] +[ 599 8310 146 153][600] +nvtxs: 599, balance: 1.008 1.011 1.010 +nvtxs: 1091, cut: 21500, balance: 1.032 1.029 1.045 +nvtxs: 2043, cut: 19508, balance: 1.042 1.031 1.037 +nvtxs: 3846, cut: 18434, balance: 1.049 1.035 1.038 +nvtxs: 7302, cut: 17511, balance: 1.050 1.035 1.039 +nvtxs: 13940, cut: 16472, balance: 1.047 1.034 1.041 +nvtxs: 26721, cut: 15399, balance: 1.045 1.034 1.037 +nvtxs: 51520, cut: 14437, balance: 1.046 1.035 1.036 +nvtxs: 99617, cut: 13001, balance: 1.039 1.033 1.037 + Setup: Max: 0.089, Sum: 0.257, Balance: 1.389 + Matching: Max: 0.167, Sum: 0.634, Balance: 1.057 +Contraction: Max: 0.307, Sum: 0.795, Balance: 1.544 + InitPart: Max: 0.142, Sum: 0.532, Balance: 1.067 + Project: Max: 0.010, Sum: 0.004, Balance: 10.812 + Initialize: Max: 0.132, Sum: 0.470, Balance: 1.124 + K-way: Max: 0.756, Sum: 2.847, Balance: 1.062 + Remap: Max: 0.014, Sum: 0.048, Balance: 1.144 + Total: Max: 1.876, Sum: 7.478, Balance: 1.004 +Final 4-way Cut: 13001 Balance: 1.039 1.033 1.037 +NMoved: 54017 15326 19382 34708 +ParMETIS_V3_AdaptiveRepart reported a cut of 13001 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 1.000, Ncon: 3, Nparts: 4 +[ 99617 1324862 23436 26023][600] +[ 51499 769386 12144 13447][600] +[ 26728 409462 6315 6969][600] +[ 13941 216690 3313 3637][600] +[ 7302 114216 1747 1907][600] +[ 3855 59716 927 1007][600] +[ 2051 31140 496 537][600] +[ 1104 16236 267 290][600] +[ 600 8228 145 158][600] +nvtxs: 600, balance: 1.011 1.014 1.009 +nvtxs: 1104, cut: 19801, balance: 1.046 1.037 1.042 +nvtxs: 2051, cut: 18711, balance: 1.049 1.037 1.045 +nvtxs: 3855, cut: 17700, balance: 1.050 1.037 1.049 +nvtxs: 7302, cut: 16476, balance: 1.047 1.035 1.049 +nvtxs: 13941, cut: 15574, balance: 1.050 1.036 1.049 +nvtxs: 26728, cut: 14417, balance: 1.049 1.036 1.050 +nvtxs: 51499, cut: 13531, balance: 1.050 1.037 1.050 +nvtxs: 99617, cut: 12140, balance: 1.049 1.037 1.050 + Setup: Max: 0.155, Sum: 0.433, Balance: 1.436 + Matching: Max: 0.241, Sum: 0.911, Balance: 1.059 +Contraction: Max: 0.276, Sum: 0.778, Balance: 1.421 + InitPart: Max: 0.145, Sum: 0.576, Balance: 1.006 + Project: Max: 0.009, Sum: 0.021, Balance: 1.713 + Initialize: Max: 0.127, Sum: 0.491, Balance: 1.037 + K-way: Max: 0.747, Sum: 2.793, Balance: 1.070 + Remap: Max: 0.007, Sum: 0.020, Balance: 1.294 + Total: Max: 1.947, Sum: 7.785, Balance: 1.000 +Final 4-way Cut: 12140 Balance: 1.049 1.037 1.050 +NMoved: 54484 16279 20241 36520 +ParMETIS_V3_AdaptiveRepart reported a cut of 12140 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 1.000, Ncon: 3, Nparts: 4 +[ 99617 1324862 23436 26023][600] +[ 51520 769370 12126 13457][600] +[ 26721 409750 6303 6989][600] +[ 13940 216498 3302 3643][600] +[ 7302 113832 1728 1911][600] +[ 3846 59572 911 1007][600] +[ 2043 30980 486 534][600] +[ 1091 15974 265 282][600] +[ 599 8310 146 153][600] +nvtxs: 599, balance: 1.008 1.011 1.010 +nvtxs: 1091, cut: 20920, balance: 1.039 1.030 1.049 +nvtxs: 2043, cut: 19258, balance: 1.030 1.030 1.049 +nvtxs: 3846, cut: 18393, balance: 1.035 1.032 1.050 +nvtxs: 7302, cut: 17607, balance: 1.039 1.034 1.049 +nvtxs: 13940, cut: 16660, balance: 1.028 1.031 1.050 +nvtxs: 26721, cut: 15771, balance: 1.027 1.032 1.050 +nvtxs: 51520, cut: 14727, balance: 1.032 1.033 1.050 +nvtxs: 99617, cut: 13389, balance: 1.022 1.031 1.050 + Setup: Max: 0.102, Sum: 0.219, Balance: 1.857 + Matching: Max: 0.235, Sum: 0.860, Balance: 1.092 +Contraction: Max: 0.283, Sum: 0.749, Balance: 1.510 + InitPart: Max: 0.137, Sum: 0.540, Balance: 1.017 + Project: Max: 0.009, Sum: 0.002, Balance: 17.060 + Initialize: Max: 0.174, Sum: 0.575, Balance: 1.214 + K-way: Max: 0.828, Sum: 3.095, Balance: 1.070 + Remap: Max: -0.002, Sum: -0.015, Balance: 0.665 + Total: Max: 1.992, Sum: 7.938, Balance: 1.004 +Final 4-way Cut: 13389 Balance: 1.022 1.031 1.050 +NMoved: 52163 14831 18484 33315 +ParMETIS_V3_AdaptiveRepart reported a cut of 13389 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 0.001, Ncon: 3, Nparts: 4 +[ 99617 1324862 23436 26023][600] +[ 51499 769386 12144 13447][600] +[ 26728 409462 6315 6969][600] +[ 13941 216690 3313 3637][600] +[ 7302 114216 1747 1907][600] +[ 3855 59716 927 1007][600] +[ 2051 31140 496 537][600] +[ 1104 16236 267 290][600] +[ 600 8228 145 158][600] +nvtxs: 600, balance: 1.011 1.014 1.009 +nvtxs: 1104, cut: 45769, balance: 1.034 1.050 1.045 +nvtxs: 2051, cut: 46714, balance: 1.048 1.050 1.048 +nvtxs: 3855, cut: 47003, balance: 1.050 1.050 1.050 +nvtxs: 7302, cut: 47459, balance: 1.050 1.050 1.049 +nvtxs: 13941, cut: 47929, balance: 1.050 1.050 1.049 +nvtxs: 26728, cut: 47864, balance: 1.050 1.050 1.049 +nvtxs: 51499, cut: 48068, balance: 1.049 1.050 1.050 +nvtxs: 99617, cut: 47806, balance: 1.049 1.050 1.050 + Setup: Max: 0.126, Sum: 0.371, Balance: 1.362 + Matching: Max: 0.266, Sum: 0.965, Balance: 1.101 +Contraction: Max: 0.290, Sum: 0.696, Balance: 1.667 + InitPart: Max: 0.154, Sum: 0.578, Balance: 1.064 + Project: Max: 0.009, Sum: 0.020, Balance: 1.872 + Initialize: Max: 0.142, Sum: 0.522, Balance: 1.088 + K-way: Max: 0.830, Sum: 3.124, Balance: 1.063 + Remap: Max: -0.004, Sum: -0.021, Balance: 0.788 + Total: Max: 2.030, Sum: 8.117, Balance: 1.001 +Final 4-way Cut: 47806 Balance: 1.049 1.050 1.050 +NMoved: 44285 12496 14914 27410 +ParMETIS_V3_AdaptiveRepart reported a cut of 47806 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 0.001, Ncon: 3, Nparts: 4 +[ 99617 1324862 23436 26023][600] +[ 51520 769370 12126 13457][600] +[ 26721 409750 6303 6989][600] +[ 13940 216498 3302 3643][600] +[ 7302 113832 1728 1911][600] +[ 3846 59572 911 1007][600] +[ 2043 30980 486 534][600] +[ 1091 15974 265 282][600] +[ 599 8310 146 153][600] +nvtxs: 599, balance: 1.008 1.011 1.010 +nvtxs: 1091, cut: 37579, balance: 1.049 1.047 1.050 +nvtxs: 2043, cut: 38920, balance: 1.042 1.050 1.050 +nvtxs: 3846, cut: 40489, balance: 1.044 1.051 1.050 +nvtxs: 7302, cut: 41381, balance: 1.049 1.050 1.050 +nvtxs: 13940, cut: 41381, balance: 1.048 1.050 1.050 +nvtxs: 26721, cut: 41946, balance: 1.050 1.050 1.049 +nvtxs: 51520, cut: 42014, balance: 1.049 1.050 1.050 +nvtxs: 99617, cut: 41808, balance: 1.050 1.050 1.050 + Setup: Max: 0.129, Sum: 0.333, Balance: 1.543 + Matching: Max: 0.243, Sum: 0.935, Balance: 1.039 +Contraction: Max: 0.338, Sum: 0.892, Balance: 1.516 + InitPart: Max: 0.138, Sum: 0.552, Balance: 1.003 + Project: Max: 0.010, Sum: 0.037, Balance: 1.070 + Initialize: Max: 0.172, Sum: 0.604, Balance: 1.136 + K-way: Max: 0.806, Sum: 2.998, Balance: 1.075 + Remap: Max: -0.003, Sum: -0.015, Balance: 0.718 + Total: Max: 2.041, Sum: 8.160, Balance: 1.001 +Final 4-way Cut: 41808 Balance: 1.050 1.050 1.050 +NMoved: 46032 13318 16812 30130 +ParMETIS_V3_AdaptiveRepart reported a cut of 41808 +Initial Load Imbalance: 1.1933, [173610 310283 1040090] for afactor: 4 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 1000.000, Ncon: 1, Nparts: 2 +[ 99617 1324862 23436 26023][200] +[ 51474 768976 12144 13415][200] +[ 26794 410198 6335 6975][200] +[ 13996 217118 3315 3639][200] +[ 7354 114922 1754 1922][200] +[ 3881 60458 933 1013][200] +[ 2070 31578 509 540][200] +[ 1118 16218 268 293][200] +[ 615 8424 146 161][200] +[ 344 4400 82 92][200] +[ 196 2260 44 55][200] +nvtxs: 196, balance: 1.030 +nvtxs: 344, cut: 2281, balance: 1.030 +nvtxs: 615, cut: 2281, balance: 1.030 +nvtxs: 1118, cut: 2281, balance: 1.030 +nvtxs: 2070, cut: 2281, balance: 1.030 +nvtxs: 3881, cut: 2281, balance: 1.030 +nvtxs: 7354, cut: 2281, balance: 1.030 +nvtxs: 13996, cut: 2281, balance: 1.030 +nvtxs: 26794, cut: 2281, balance: 1.030 +nvtxs: 51474, cut: 2276, balance: 1.030 +nvtxs: 99617, cut: 2276, balance: 1.030 + Setup: Max: 0.069, Sum: 0.229, Balance: 1.213 + Matching: Max: 0.277, Sum: 1.043, Balance: 1.063 +Contraction: Max: 0.382, Sum: 1.494, Balance: 1.022 + Project: Max: 0.051, Sum: 0.103, Balance: 1.986 + Initialize: Max: 0.143, Sum: 0.503, Balance: 1.140 + K-way: Max: 0.250, Sum: 0.782, Balance: 1.279 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.298 + Total: Max: 1.315, Sum: 5.253, Balance: 1.001 +Final 2-way Cut: 2276 Balance: 1.030 +NMoved: 6 4 4 8 +ParMETIS_V3_AdaptiveRepart reported a cut of 2276 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 1000.000, Ncon: 1, Nparts: 2 +[ 99617 1324862 23436 26023][200] +[ 51467 768770 12119 13407][200] +[ 26758 410182 6309 6966][200] +[ 13973 217278 3305 3631][200] +[ 7332 114684 1742 1901][200] +[ 3869 60258 930 995][200] +[ 2064 31426 502 526][200] +[ 1117 16294 274 285][200] +[ 611 8534 151 155][200] +[ 344 4442 83 87][200] +[ 197 2300 47 51][200] +nvtxs: 197, balance: 1.030 +nvtxs: 344, cut: 2281, balance: 1.030 +nvtxs: 611, cut: 2281, balance: 1.030 +nvtxs: 1117, cut: 2281, balance: 1.030 +nvtxs: 2064, cut: 2281, balance: 1.030 +nvtxs: 3869, cut: 2281, balance: 1.030 +nvtxs: 7332, cut: 2281, balance: 1.030 +nvtxs: 13973, cut: 2281, balance: 1.030 +nvtxs: 26758, cut: 2281, balance: 1.030 +nvtxs: 51467, cut: 2280, balance: 1.030 +nvtxs: 99617, cut: 2280, balance: 1.030 + Setup: Max: 0.119, Sum: 0.377, Balance: 1.264 + Matching: Max: 0.378, Sum: 1.397, Balance: 1.083 +Contraction: Max: 0.498, Sum: 1.903, Balance: 1.046 + Project: Max: 0.015, Sum: 0.007, Balance: 8.124 + Initialize: Max: 0.141, Sum: 0.525, Balance: 1.073 + K-way: Max: 0.244, Sum: 0.859, Balance: 1.136 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.426 + Total: Max: 1.574, Sum: 6.254, Balance: 1.007 +Final 2-way Cut: 2280 Balance: 1.030 +NMoved: 2 2 2 4 +ParMETIS_V3_AdaptiveRepart reported a cut of 2280 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 1.000, Ncon: 1, Nparts: 2 +[ 99617 1324862 23436 26023][200] +[ 51474 768976 12144 13415][200] +[ 26794 410198 6335 6975][200] +[ 13996 217118 3315 3639][200] +[ 7354 114922 1754 1922][200] +[ 3881 60458 933 1013][200] +[ 2070 31578 509 540][200] +[ 1118 16218 268 293][200] +[ 615 8424 146 161][200] +[ 344 4400 82 92][200] +[ 196 2260 44 55][200] +nvtxs: 196, balance: 1.030 +nvtxs: 344, cut: 2281, balance: 1.030 +nvtxs: 615, cut: 2281, balance: 1.030 +nvtxs: 1118, cut: 2281, balance: 1.030 +nvtxs: 2070, cut: 2281, balance: 1.030 +nvtxs: 3881, cut: 2281, balance: 1.030 +nvtxs: 7354, cut: 2281, balance: 1.030 +nvtxs: 13996, cut: 2281, balance: 1.030 +nvtxs: 26794, cut: 2281, balance: 1.030 +nvtxs: 51474, cut: 2276, balance: 1.030 +nvtxs: 99617, cut: 2276, balance: 1.030 + Setup: Max: 0.132, Sum: 0.304, Balance: 1.735 + Matching: Max: 0.301, Sum: 1.161, Balance: 1.036 +Contraction: Max: 0.348, Sum: 1.370, Balance: 1.015 + Project: Max: 0.029, Sum: 0.095, Balance: 1.210 + Initialize: Max: 0.129, Sum: 0.471, Balance: 1.097 + K-way: Max: 0.212, Sum: 0.824, Balance: 1.030 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.428 + Total: Max: 1.359, Sum: 5.405, Balance: 1.006 +Final 2-way Cut: 2276 Balance: 1.030 +NMoved: 6 4 4 8 +ParMETIS_V3_AdaptiveRepart reported a cut of 2276 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 1.000, Ncon: 1, Nparts: 2 +[ 99617 1324862 23436 26023][200] +[ 51467 768770 12119 13407][200] +[ 26758 410182 6309 6966][200] +[ 13973 217278 3305 3631][200] +[ 7332 114684 1742 1901][200] +[ 3869 60258 930 995][200] +[ 2064 31426 502 526][200] +[ 1117 16294 274 285][200] +[ 611 8534 151 155][200] +[ 344 4442 83 87][200] +[ 197 2300 47 51][200] +nvtxs: 197, balance: 1.030 +nvtxs: 344, cut: 2281, balance: 1.030 +nvtxs: 611, cut: 2281, balance: 1.030 +nvtxs: 1117, cut: 2281, balance: 1.030 +nvtxs: 2064, cut: 2281, balance: 1.030 +nvtxs: 3869, cut: 2281, balance: 1.030 +nvtxs: 7332, cut: 2281, balance: 1.030 +nvtxs: 13973, cut: 2281, balance: 1.030 +nvtxs: 26758, cut: 2281, balance: 1.030 +nvtxs: 51467, cut: 2280, balance: 1.030 +nvtxs: 99617, cut: 2280, balance: 1.030 + Setup: Max: 0.101, Sum: 0.252, Balance: 1.601 + Matching: Max: 0.311, Sum: 1.127, Balance: 1.103 +Contraction: Max: 0.390, Sum: 1.511, Balance: 1.032 + Project: Max: 0.017, Sum: 0.011, Balance: 5.845 + Initialize: Max: 0.134, Sum: 0.463, Balance: 1.154 + K-way: Max: 0.256, Sum: 0.924, Balance: 1.109 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.312 + Total: Max: 1.349, Sum: 5.365, Balance: 1.006 +Final 2-way Cut: 2280 Balance: 1.030 +NMoved: 2 2 2 4 +ParMETIS_V3_AdaptiveRepart reported a cut of 2280 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 0.001, Ncon: 1, Nparts: 2 +[ 99617 1324862 23436 26023][200] +[ 51474 768976 12144 13415][200] +[ 26794 410198 6335 6975][200] +[ 13996 217118 3315 3639][200] +[ 7354 114922 1754 1922][200] +[ 3881 60458 933 1013][200] +[ 2070 31578 509 540][200] +[ 1118 16218 268 293][200] +[ 615 8424 146 161][200] +[ 344 4400 82 92][200] +[ 196 2260 44 55][200] +nvtxs: 196, balance: 1.030 +nvtxs: 344, cut: 2281, balance: 1.030 +nvtxs: 615, cut: 2281, balance: 1.030 +nvtxs: 1118, cut: 2281, balance: 1.030 +nvtxs: 2070, cut: 2281, balance: 1.030 +nvtxs: 3881, cut: 2281, balance: 1.030 +nvtxs: 7354, cut: 2281, balance: 1.030 +nvtxs: 13996, cut: 2281, balance: 1.030 +nvtxs: 26794, cut: 2281, balance: 1.030 +nvtxs: 51474, cut: 2281, balance: 1.030 +nvtxs: 99617, cut: 2281, balance: 1.030 + Setup: Max: 0.136, Sum: 0.367, Balance: 1.482 + Matching: Max: 0.277, Sum: 1.068, Balance: 1.039 +Contraction: Max: 0.388, Sum: 1.512, Balance: 1.026 + Project: Max: 0.023, Sum: 0.028, Balance: 3.275 + Initialize: Max: 0.164, Sum: 0.500, Balance: 1.312 + K-way: Max: 0.178, Sum: 0.652, Balance: 1.092 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.391 + Total: Max: 1.332, Sum: 5.320, Balance: 1.001 +Final 2-way Cut: 2281 Balance: 1.030 +NMoved: 0 0 0 0 +ParMETIS_V3_AdaptiveRepart reported a cut of 2281 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 0.001, Ncon: 1, Nparts: 2 +[ 99617 1324862 23436 26023][200] +[ 51467 768770 12119 13407][200] +[ 26758 410182 6309 6966][200] +[ 13973 217278 3305 3631][200] +[ 7332 114684 1742 1901][200] +[ 3869 60258 930 995][200] +[ 2064 31426 502 526][200] +[ 1117 16294 274 285][200] +[ 611 8534 151 155][200] +[ 344 4442 83 87][200] +[ 197 2300 47 51][200] +nvtxs: 197, balance: 1.030 +nvtxs: 344, cut: 2281, balance: 1.030 +nvtxs: 611, cut: 2281, balance: 1.030 +nvtxs: 1117, cut: 2281, balance: 1.030 +nvtxs: 2064, cut: 2281, balance: 1.030 +nvtxs: 3869, cut: 2281, balance: 1.030 +nvtxs: 7332, cut: 2281, balance: 1.030 +nvtxs: 13973, cut: 2281, balance: 1.030 +nvtxs: 26758, cut: 2281, balance: 1.030 +nvtxs: 51467, cut: 2281, balance: 1.030 +nvtxs: 99617, cut: 2281, balance: 1.030 + Setup: Max: 0.112, Sum: 0.355, Balance: 1.263 + Matching: Max: 0.359, Sum: 1.391, Balance: 1.031 +Contraction: Max: 0.488, Sum: 1.901, Balance: 1.027 + Project: Max: 0.037, Sum: 0.074, Balance: 2.016 + Initialize: Max: 0.113, Sum: 0.446, Balance: 1.016 + K-way: Max: 0.201, Sum: 0.758, Balance: 1.062 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.434 + Total: Max: 1.555, Sum: 6.212, Balance: 1.001 +Final 2-way Cut: 2281 Balance: 1.030 +NMoved: 0 0 0 0 +ParMETIS_V3_AdaptiveRepart reported a cut of 2281 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 1000.000, Ncon: 3, Nparts: 2 +[ 99617 1324862 23436 26023][600] +[ 51474 768976 12144 13415][600] +[ 26735 408876 6324 6959][600] +[ 13939 216334 3300 3611][600] +[ 7300 114028 1745 1893][600] +[ 3859 59852 936 999][600] +[ 2064 31208 510 527][600] +[ 1120 16180 274 288][600] +[ 615 8346 148 157][600] +nvtxs: 615, balance: 1.002 1.002 1.004 +nvtxs: 1120, cut: 9950, balance: 1.013 1.013 1.008 +nvtxs: 2064, cut: 9377, balance: 1.014 1.014 1.012 +nvtxs: 3859, cut: 8764, balance: 1.018 1.018 1.010 +nvtxs: 7300, cut: 8176, balance: 1.019 1.019 1.010 +nvtxs: 13939, cut: 7710, balance: 1.021 1.021 1.012 +nvtxs: 26735, cut: 7238, balance: 1.022 1.022 1.016 +nvtxs: 51474, cut: 6729, balance: 1.022 1.022 1.016 +nvtxs: 99617, cut: 6113, balance: 1.013 1.013 1.014 + Setup: Max: 0.096, Sum: 0.268, Balance: 1.435 + Matching: Max: 0.320, Sum: 1.241, Balance: 1.033 +Contraction: Max: 0.346, Sum: 1.380, Balance: 1.002 + InitPart: Max: 0.085, Sum: 0.299, Balance: 1.130 + Project: Max: 0.048, Sum: 0.138, Balance: 1.389 + Initialize: Max: 0.138, Sum: 0.517, Balance: 1.072 + K-way: Max: 0.666, Sum: 2.562, Balance: 1.040 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.516 + Total: Max: 1.883, Sum: 7.527, Balance: 1.001 +Final 2-way Cut: 6113 Balance: 1.013 1.013 1.014 +NMoved: 49732 24996 24996 49992 +ParMETIS_V3_AdaptiveRepart reported a cut of 6113 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 1000.000, Ncon: 3, Nparts: 2 +[ 99617 1324862 23436 26023][600] +[ 51467 768770 12119 13407][600] +[ 26704 408982 6292 6955][600] +[ 13898 215874 3282 3616][600] +[ 7275 113570 1724 1890][600] +[ 3830 59564 910 983][600] +[ 2024 30990 484 522][600] +[ 1083 16046 263 279][600] +[ 586 8180 143 154][600] +nvtxs: 586, balance: 1.006 1.006 1.004 +nvtxs: 1083, cut: 9178, balance: 1.015 1.015 1.003 +nvtxs: 2024, cut: 8626, balance: 1.026 1.026 1.012 +nvtxs: 3830, cut: 8358, balance: 1.030 1.030 1.015 +nvtxs: 7275, cut: 7886, balance: 1.033 1.033 1.018 +nvtxs: 13898, cut: 7312, balance: 1.039 1.039 1.023 +nvtxs: 26704, cut: 6956, balance: 1.039 1.039 1.022 +nvtxs: 51467, cut: 6583, balance: 1.043 1.043 1.023 +nvtxs: 99617, cut: 5980, balance: 1.050 1.050 1.026 + Setup: Max: 0.098, Sum: 0.277, Balance: 1.419 + Matching: Max: 0.304, Sum: 1.170, Balance: 1.039 +Contraction: Max: 0.364, Sum: 1.440, Balance: 1.012 + InitPart: Max: 0.075, Sum: 0.295, Balance: 1.013 + Project: Max: 0.028, Sum: 0.062, Balance: 1.797 + Initialize: Max: 0.141, Sum: 0.464, Balance: 1.218 + K-way: Max: 0.671, Sum: 2.585, Balance: 1.039 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.232 + Total: Max: 1.830, Sum: 7.293, Balance: 1.004 +Final 2-way Cut: 5980 Balance: 1.050 1.050 1.026 +NMoved: 48535 25319 25319 50638 +ParMETIS_V3_AdaptiveRepart reported a cut of 5980 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 1.000, Ncon: 3, Nparts: 2 +[ 99617 1324862 23436 26023][600] +[ 51474 768976 12144 13415][600] +[ 26735 408876 6324 6959][600] +[ 13939 216334 3300 3611][600] +[ 7300 114028 1745 1893][600] +[ 3859 59852 936 999][600] +[ 2064 31208 510 527][600] +[ 1120 16180 274 288][600] +[ 615 8346 148 157][600] +nvtxs: 615, balance: 1.002 1.002 1.004 +nvtxs: 1120, cut: 10122, balance: 1.003 1.003 1.002 +nvtxs: 2064, cut: 9523, balance: 1.012 1.012 1.008 +nvtxs: 3859, cut: 8934, balance: 1.007 1.007 1.010 +nvtxs: 7300, cut: 8137, balance: 1.005 1.005 1.015 +nvtxs: 13939, cut: 7757, balance: 1.006 1.006 1.015 +nvtxs: 26735, cut: 7257, balance: 1.008 1.008 1.015 +nvtxs: 51474, cut: 6833, balance: 1.009 1.009 1.015 +nvtxs: 99617, cut: 6214, balance: 1.025 1.025 1.010 + Setup: Max: 0.092, Sum: 0.280, Balance: 1.319 + Matching: Max: 0.315, Sum: 1.201, Balance: 1.048 +Contraction: Max: 0.358, Sum: 1.396, Balance: 1.026 + InitPart: Max: 0.068, Sum: 0.269, Balance: 1.011 + Project: Max: 0.052, Sum: 0.156, Balance: 1.337 + Initialize: Max: 0.076, Sum: 0.244, Balance: 1.238 + K-way: Max: 0.694, Sum: 2.643, Balance: 1.051 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.429 + Total: Max: 1.855, Sum: 7.412, Balance: 1.001 +Final 2-way Cut: 6214 Balance: 1.025 1.025 1.010 +NMoved: 47999 24270 24270 48540 +ParMETIS_V3_AdaptiveRepart reported a cut of 6214 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 1.000, Ncon: 3, Nparts: 2 +[ 99617 1324862 23436 26023][600] +[ 51467 768770 12119 13407][600] +[ 26704 408982 6292 6955][600] +[ 13898 215874 3282 3616][600] +[ 7275 113570 1724 1890][600] +[ 3830 59564 910 983][600] +[ 2024 30990 484 522][600] +[ 1083 16046 263 279][600] +[ 586 8180 143 154][600] +nvtxs: 586, balance: 1.006 1.006 1.004 +nvtxs: 1083, cut: 9230, balance: 1.013 1.013 1.002 +nvtxs: 2024, cut: 8706, balance: 1.034 1.034 1.010 +nvtxs: 3830, cut: 8425, balance: 1.034 1.034 1.011 +nvtxs: 7275, cut: 7826, balance: 1.048 1.048 1.019 +nvtxs: 13898, cut: 7364, balance: 1.050 1.050 1.019 +nvtxs: 26704, cut: 7000, balance: 1.050 1.050 1.019 +nvtxs: 51467, cut: 6669, balance: 1.050 1.050 1.019 +nvtxs: 99617, cut: 6215, balance: 1.050 1.050 1.016 + Setup: Max: 0.132, Sum: 0.431, Balance: 1.225 + Matching: Max: 0.412, Sum: 1.572, Balance: 1.049 +Contraction: Max: 0.471, Sum: 1.861, Balance: 1.012 + InitPart: Max: 0.074, Sum: 0.291, Balance: 1.015 + Project: Max: 0.022, Sum: -0.000, Balance: -200.449 + Initialize: Max: 0.150, Sum: 0.499, Balance: 1.200 + K-way: Max: 0.656, Sum: 2.512, Balance: 1.045 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.305 + Total: Max: 2.187, Sum: 8.744, Balance: 1.001 +Final 2-way Cut: 6215 Balance: 1.050 1.050 1.016 +NMoved: 48036 24919 24919 49838 +ParMETIS_V3_AdaptiveRepart reported a cut of 6215 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 1 1}, ipc2redist: 0.001, Ncon: 3, Nparts: 2 +[ 99617 1324862 23436 26023][600] +[ 51474 768976 12144 13415][600] +[ 26735 408876 6324 6959][600] +[ 13939 216334 3300 3611][600] +[ 7300 114028 1745 1893][600] +[ 3859 59852 936 999][600] +[ 2064 31208 510 527][600] +[ 1120 16180 274 288][600] +[ 615 8346 148 157][600] +nvtxs: 615, balance: 1.002 1.002 1.004 +nvtxs: 1120, cut: 24586, balance: 1.046 1.046 1.048 +nvtxs: 2064, cut: 24844, balance: 1.049 1.049 1.048 +nvtxs: 3859, cut: 25224, balance: 1.049 1.049 1.050 +nvtxs: 7300, cut: 25329, balance: 1.050 1.050 1.050 +nvtxs: 13939, cut: 25408, balance: 1.050 1.050 1.050 +nvtxs: 26735, cut: 25425, balance: 1.050 1.050 1.050 +nvtxs: 51474, cut: 25425, balance: 1.050 1.050 1.050 +nvtxs: 99617, cut: 25425, balance: 1.050 1.050 1.050 + Setup: Max: 0.073, Sum: 0.170, Balance: 1.719 + Matching: Max: 0.299, Sum: 1.169, Balance: 1.025 +Contraction: Max: 0.373, Sum: 1.487, Balance: 1.002 + InitPart: Max: 0.079, Sum: 0.311, Balance: 1.012 + Project: Max: 0.040, Sum: 0.110, Balance: 1.444 + Initialize: Max: 0.131, Sum: 0.443, Balance: 1.177 + K-way: Max: 0.455, Sum: 1.631, Balance: 1.116 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.358 + Total: Max: 1.629, Sum: 6.511, Balance: 1.001 +Final 2-way Cut: 25425 Balance: 1.050 1.050 1.050 +NMoved: 44489 22400 22400 44800 +ParMETIS_V3_AdaptiveRepart reported a cut of 25425 + +Testing ParMETIS_V3_AdaptiveRepart with options[1-3] = {7 2 1}, ipc2redist: 0.001, Ncon: 3, Nparts: 2 +[ 99617 1324862 23436 26023][600] +[ 51467 768770 12119 13407][600] +[ 26704 408982 6292 6955][600] +[ 13898 215874 3282 3616][600] +[ 7275 113570 1724 1890][600] +[ 3830 59564 910 983][600] +[ 2024 30990 484 522][600] +[ 1083 16046 263 279][600] +[ 586 8180 143 154][600] +nvtxs: 586, balance: 1.006 1.006 1.004 +nvtxs: 1083, cut: 24560, balance: 1.050 1.050 1.049 +nvtxs: 2024, cut: 24558, balance: 1.050 1.050 1.049 +nvtxs: 3830, cut: 24663, balance: 1.050 1.050 1.050 +nvtxs: 7275, cut: 24699, balance: 1.050 1.050 1.050 +nvtxs: 13898, cut: 24719, balance: 1.050 1.050 1.050 +nvtxs: 26704, cut: 24773, balance: 1.050 1.050 1.050 +nvtxs: 51467, cut: 24773, balance: 1.050 1.050 1.050 +nvtxs: 99617, cut: 24773, balance: 1.050 1.050 1.050 + Setup: Max: 0.120, Sum: 0.304, Balance: 1.585 + Matching: Max: 0.304, Sum: 1.145, Balance: 1.062 +Contraction: Max: 0.368, Sum: 1.393, Balance: 1.058 + InitPart: Max: 0.062, Sum: 0.244, Balance: 1.017 + Project: Max: 0.045, Sum: 0.093, Balance: 1.937 + Initialize: Max: 0.170, Sum: 0.606, Balance: 1.122 + K-way: Max: 0.420, Sum: 1.629, Balance: 1.030 + Remap: Max: 0.000, Sum: 0.000, Balance: 1.448 + Total: Max: 1.703, Sum: 6.803, Balance: 1.001 +Final 2-way Cut: 24773 Balance: 1.050 1.050 1.050 +NMoved: 44478 22395 22395 44790 +ParMETIS_V3_AdaptiveRepart reported a cut of 24773 + +Testing ParMETIS_V3_NodeND with options[1-3] = {3 1 1} + Setup: Max: 0.242, Sum: 0.818, Balance: 1.182 + Matching: Max: 0.485, Sum: 1.839, Balance: 1.055 +Contraction: Max: 0.499, Sum: 1.954, Balance: 1.022 + InitPart: Max: 0.018, Sum: 0.069, Balance: 1.018 + Project: Max: 0.039, Sum: 0.066, Balance: 2.352 + Initialize: Max: 0.244, Sum: 0.676, Balance: 1.443 + K-way: Max: 0.831, Sum: 3.129, Balance: 1.062 + Total: Max: 2.236, Sum: 8.943, Balance: 1.000 +SepSizes: 511 [47236 51870] +SepSizes: 901 [23636 22699] 570 [26836 24464] + Setup: Max: 0.450, Sum: 1.348, Balance: 1.334 + Matching: Max: 0.666, Sum: 2.290, Balance: 1.164 +Contraction: Max: 1.009, Sum: 3.461, Balance: 1.167 + InitPart: Max: 0.102, Sum: 0.395, Balance: 1.034 + Project: Max: 0.057, Sum: 0.108, Balance: 2.107 + Initialize: Max: 0.252, Sum: 0.799, Balance: 1.261 + K-way: Max: 1.304, Sum: 5.084, Balance: 1.026 + Move: Max: 4.609, Sum: 12.909, Balance: 1.428 + Total: Max: 6.972, Sum: 27.820, Balance: 1.002 + +Testing ParMETIS_V3_NodeND with options[1-3] = {3 1 2} + Setup: Max: 0.268, Sum: 0.820, Balance: 1.308 + Matching: Max: 0.440, Sum: 1.704, Balance: 1.032 +Contraction: Max: 0.560, Sum: 2.205, Balance: 1.016 + InitPart: Max: 0.012, Sum: 0.047, Balance: 1.024 + Project: Max: 0.066, Sum: 0.185, Balance: 1.435 + Initialize: Max: 0.187, Sum: 0.670, Balance: 1.114 + K-way: Max: 0.765, Sum: 3.004, Balance: 1.019 + Total: Max: 2.302, Sum: 9.206, Balance: 1.000 +SepSizes: 511 [47236 51870] +SepSizes: 901 [23636 22699] 570 [26836 24464] + Setup: Max: 0.394, Sum: 1.187, Balance: 1.328 + Matching: Max: 0.634, Sum: 2.294, Balance: 1.106 +Contraction: Max: 1.103, Sum: 3.570, Balance: 1.236 + InitPart: Max: 0.092, Sum: 0.313, Balance: 1.181 + Project: Max: 0.066, Sum: 0.191, Balance: 1.374 + Initialize: Max: 0.256, Sum: 0.867, Balance: 1.182 + K-way: Max: 1.234, Sum: 4.827, Balance: 1.023 + Move: Max: 2.786, Sum: 6.572, Balance: 1.696 + Total: Max: 6.896, Sum: 27.577, Balance: 1.000 + +------------------------------------------------------------------------- +------------------------------------------------------------------------- +------------------------------------------------------------------------- +------------------------------------------------------------------------- +% mpirun -np 4 mtest bricks.hex3d 2 + +Nelements: 117649, Nnodes: 125000, EType: 3 +MGCNUM: 2 +Completed Dual Graph -- Nvtxs: 117649, Nedges: 2046222 +[117649 2046222 29412 29413] [100] [ 0.000] [ 0.000] +[ 60230 1195682 15032 15075] [100] [ 0.000] [ 0.000] +[ 30905 630126 7712 7738] [100] [ 0.000] [ 0.000] +[ 15878 308518 3958 3976] [100] [ 0.000] [ 0.000] +[ 8188 150574 2039 2055] [100] [ 0.000] [ 0.000] +[ 4240 74750 1057 1063] [100] [ 0.000] [ 0.000] +[ 2208 37340 547 555] [100] [ 0.000] [ 0.001] +[ 1155 18804 285 291] [100] [ 0.000] [ 0.001] +[ 606 9272 149 154] [100] [ 0.000] [ 0.002] +[ 321 4636 79 82] [100] [ 0.000] [ 0.004] +[ 175 2312 43 46] [100] [ 0.000] [ 0.008] +[ 96 1166 23 25] [100] [ 0.000] [ 0.016] +nvtxs: 96, balance: 1.029 +nvtxs: 175, cut: 52846, balance: 1.034 +nvtxs: 321, cut: 49105, balance: 1.044 +nvtxs: 606, cut: 46830, balance: 1.049 +nvtxs: 1155, cut: 44937, balance: 1.007 +nvtxs: 2208, cut: 42026, balance: 1.010 +nvtxs: 4240, cut: 39423, balance: 1.004 +nvtxs: 8188, cut: 36607, balance: 1.003 +nvtxs: 15878, cut: 34521, balance: 1.004 +nvtxs: 30905, cut: 32557, balance: 1.003 +nvtxs: 60230, cut: 30095, balance: 1.003 +nvtxs: 117649, cut: 27431, balance: 1.003 + Setup: Max: 0.085, Sum: 0.288, Balance: 1.179 + Matching: Max: 0.328, Sum: 1.220, Balance: 1.073 +Contraction: Max: 0.424, Sum: 1.680, Balance: 1.010 + InitPart: Max: 0.035, Sum: 0.130, Balance: 1.060 + Project: Max: 0.065, Sum: 0.150, Balance: 1.731 + Initialize: Max: 0.188, Sum: 0.646, Balance: 1.164 + K-way: Max: 0.668, Sum: 2.591, Balance: 1.031 + Remap: Max: 0.015, Sum: 0.057, Balance: 1.066 + Total: Max: 2.030, Sum: 8.085, Balance: 1.004 +Final 4-way CUT: 27431 Balance: 1.003 avg: 1.003 + Mesh2Dual: Max: 0.899, Sum: 3.592, Balance: 1.001 + ParMETIS: Max: 2.192, Sum: 8.754, Balance: 1.002 + Total: Max: 3.091, Sum: 12.347, Balance: 1.001 + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/Makefile b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/Makefile new file mode 100644 index 0000000..eafd97a --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/Makefile @@ -0,0 +1,45 @@ +include ../Makefile.in + + +CFLAGS = $(COPTIONS) $(OPTFLAGS) -I. $(INCDIR) + + +OBJS = coarsen.o fm.o initpart.o match.o ccgraph.o \ + pmetis.o pqueue.o refine.o util.o timing.o debug.o \ + bucketsort.o graph.o stat.o kmetis.o kwayrefine.o \ + kwayfm.o balance.o ometis.o srefine.o sfm.o separator.o \ + mincover.o mmd.o mesh.o meshpart.o frename.o fortran.o \ + myqsort.o compress.o parmetis.o estmem.o \ + mpmetis.o mcoarsen.o mmatch.o minitpart.o mbalance.o \ + mutil.o mkmetis.o mkwayrefine.o mkwayfmh.o \ + mrefine2.o minitpart2.o mbalance2.o mfm2.o \ + kvmetis.o kwayvolrefine.o kwayvolfm.o subdomains.o \ + mfm.o memory.o mrefine.o checkgraph.o + +.c.o: + $(CC) $(CFLAGS) -c $*.c + +../libmetis.a: $(OBJS) + $(AR) $@ $(OBJS) + $(RANLIB) $@ + +clean: + rm -f *.o + +realclean: + rm -f *.o ; rm -f ../libmetis.a + + +checkin: + @for file in *.[c,h]; \ + do \ + ci -u -m'Maintance' $$file;\ + done + +checkin2: + @for file in *.[c,h]; \ + do \ + ci $$file;\ + rcs -U $$file;\ + co $$file;\ + done diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_checkgraph.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_checkgraph.c new file mode 100644 index 0000000..aea0094 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_checkgraph.c @@ -0,0 +1,127 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * checkgraph.c + * + * This file contains routines related to I/O + * + * Started 8/28/94 + * George + * + * $Id: NEW_checkgraph.c,v 1.1 2003/07/16 15:55:13 karypis Exp $ + * + */ + +#include <metis.h> + + + +/************************************************************************* +* This function checks if a graph is valid +**************************************************************************/ +int CheckGraph(GraphType *graph) +{ + int i, j, k, l; + int nvtxs, ncon, err=0; + int minedge, maxedge, minewgt, maxewgt; + float minvwgt[MAXNCON], maxvwgt[MAXNCON]; + idxtype *xadj, *adjncy, *adjwgt, *htable; + float *nvwgt, ntvwgts[MAXNCON]; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + htable = idxsmalloc(nvtxs, 0, "htable"); + + if (ncon > 1) { + for (j=0; j<ncon; j++) { + minvwgt[j] = maxvwgt[j] = nvwgt[j]; + ntvwgts[j] = 0.0; + } + } + + minedge = maxedge = adjncy[0]; + minewgt = maxewgt = adjwgt[0]; + + for (i=0; i<nvtxs; i++) { + if (ncon > 1) { + for (j=0; j<ncon; j++) { + ntvwgts[j] += nvwgt[i*ncon+j]; + minvwgt[j] = (nvwgt[i*ncon+j] < minvwgt[j]) ? nvwgt[i*ncon+j] : minvwgt[j]; + maxvwgt[j] = (nvwgt[i*ncon+j] > maxvwgt[j]) ? nvwgt[i*ncon+j] : maxvwgt[j]; + } + } + + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + + minedge = (k < minedge) ? k : minedge; + maxedge = (k > maxedge) ? k : maxedge; + minewgt = (adjwgt[j] < minewgt) ? adjwgt[j] : minewgt; + maxewgt = (adjwgt[j] > maxewgt) ? adjwgt[j] : maxewgt; + + if (i == k) { + printf("Vertex %d contains a self-loop (i.e., diagonal entry in the matrix)!\n", i); + err++; + } + else { + for (l=xadj[k]; l<xadj[k+1]; l++) { + if (adjncy[l] == i) { + if (adjwgt != NULL && adjwgt[l] != adjwgt[j]) { + printf("Edges (%d %d) and (%d %d) do not have the same weight! %d %d\n", i,k,k,i, adjwgt[l], adjwgt[j]); + err++; + } + break; + } + } + if (l == xadj[k+1]) { + printf("Missing edge: (%d %d)!\n", k, i); + err++; + } + } + + if (htable[k] == 0) { + htable[k]++; + } + else { + printf("Edge %d from vertex %d is repeated %d times\n", k, i, htable[k]++); + err++; + } + } + + for (j=xadj[i]; j<xadj[i+1]; j++) { + htable[adjncy[j]] = 0; + } + } + + if (ncon > 1) { + for (j=0; j<ncon; j++) { + if (fabs(ntvwgts[j] - 1.0) > 0.0001) { + printf("Normalized vwgts don't sum to one. Weight %d = %.8f.\n", j, ntvwgts[j]); + err++; + } + } + } + +/* + printf("errs: %d, adjncy: [%d %d], adjwgt: [%d %d]\n", + err, minedge, maxedge, minewgt, maxewgt); + if (ncon > 1) { + for (j=0; j<ncon; j++) + printf("[%.5f %.5f] ", minvwgt[j], maxvwgt[j]); + printf("\n"); + } +*/ + + if (err > 0) { + printf("A total of %d errors exist in the input file. Correct them, and run again!\n", err); + } + + GKfree(&htable, LTERM); + return (err == 0 ? 1 : 0); +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_memory.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_memory.c new file mode 100644 index 0000000..aa03b9d --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_memory.c @@ -0,0 +1,208 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * memory.c + * + * This file contains routines that deal with memory allocation + * + * Started 2/24/96 + * George + * + * $Id: NEW_memory.c,v 1.1 2003/07/16 15:55:13 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function allocates memory for the workspace +**************************************************************************/ +void AllocateWorkSpace(CtrlType *ctrl, GraphType *graph, int nparts) +{ + ctrl->wspace.pmat = NULL; + + if (ctrl->optype == OP_KMETIS) { + ctrl->wspace.edegrees = (EDegreeType *)GKmalloc(graph->nedges*sizeof(EDegreeType), "AllocateWorkSpace: edegrees"); + ctrl->wspace.vedegrees = NULL; + ctrl->wspace.auxcore = (idxtype *)ctrl->wspace.edegrees; + + ctrl->wspace.pmat = idxmalloc(nparts*nparts, "AllocateWorkSpace: pmat"); + + /* Memory requirements for different phases + Coarsening + Matching: 4*nvtxs vectors + Contraction: 2*nvtxs vectors (from the above 4), 1*nparts, 1*Nedges + Total = MAX(4*nvtxs, 2*nvtxs+nparts+nedges) + + Refinement + Random Refinement/Balance: 5*nparts + 1*nvtxs + 2*nedges + Greedy Refinement/Balance: 5*nparts + 2*nvtxs + 2*nedges + 1*PQueue(==Nvtxs) + Total = 5*nparts + 3*nvtxs + 2*nedges + + Total = 5*nparts + 3*nvtxs + 2*nedges + */ + ctrl->wspace.maxcore = 3*(graph->nvtxs+1) + /* Match/Refinement vectors */ + 5*(nparts+1) + /* Partition weights etc */ + graph->nvtxs*(sizeof(ListNodeType)/sizeof(idxtype)) + /* Greedy k-way balance/refine */ + 20 /* padding for 64 bit machines */ + ; + } + else if (ctrl->optype == OP_KVMETIS) { + ctrl->wspace.edegrees = NULL; + ctrl->wspace.vedegrees = (VEDegreeType *)GKmalloc(graph->nedges*sizeof(VEDegreeType), "AllocateWorkSpace: vedegrees"); + ctrl->wspace.auxcore = (idxtype *)ctrl->wspace.vedegrees; + + ctrl->wspace.pmat = idxmalloc(nparts*nparts, "AllocateWorkSpace: pmat"); + + /* Memory requirements for different phases are identical to KMETIS */ + ctrl->wspace.maxcore = 3*(graph->nvtxs+1) + /* Match/Refinement vectors */ + 3*(nparts+1) + /* Partition weights etc */ + graph->nvtxs*(sizeof(ListNodeType)/sizeof(idxtype)) + /* Greedy k-way balance/refine */ + 20 /* padding for 64 bit machines */ + ; + } + else { + ctrl->wspace.edegrees = (EDegreeType *)idxmalloc(graph->nedges, "AllocateWorkSpace: edegrees"); + ctrl->wspace.vedegrees = NULL; + ctrl->wspace.auxcore = (idxtype *)ctrl->wspace.edegrees; + + ctrl->wspace.maxcore = 5*(graph->nvtxs+1) + /* Refinement vectors */ + 4*(nparts+1) + /* Partition weights etc */ + 2*graph->ncon*graph->nvtxs*(sizeof(ListNodeType)/sizeof(idxtype)) + /* 2-way refinement */ + 2*graph->ncon*(NEG_GAINSPAN+PLUS_GAINSPAN+1)*(sizeof(ListNodeType *)/sizeof(idxtype)) + /* 2-way refinement */ + 20 /* padding for 64 bit machines */ + ; + } + + ctrl->wspace.maxcore += HTLENGTH; + ctrl->wspace.core = idxmalloc(ctrl->wspace.maxcore, "AllocateWorkSpace: maxcore"); + ctrl->wspace.ccore = 0; +} + + +/************************************************************************* +* This function allocates memory for the workspace +**************************************************************************/ +void FreeWorkSpace(CtrlType *ctrl, GraphType *graph) +{ + GKfree(&ctrl->wspace.edegrees, &ctrl->wspace.vedegrees, &ctrl->wspace.core, &ctrl->wspace.pmat, LTERM); +} + +/************************************************************************* +* This function returns how may words are left in the workspace +**************************************************************************/ +int WspaceAvail(CtrlType *ctrl) +{ + return ctrl->wspace.maxcore - ctrl->wspace.ccore; +} + + +/************************************************************************* +* This function allocate space from the core +**************************************************************************/ +idxtype *idxwspacemalloc(CtrlType *ctrl, int n) +{ + n += n%2; /* This is a fix for 64 bit machines that require 8-byte pointer allignment */ + + ctrl->wspace.ccore += n; + ASSERT(ctrl->wspace.ccore <= ctrl->wspace.maxcore); + return ctrl->wspace.core + ctrl->wspace.ccore - n; +} + +/************************************************************************* +* This function frees space from the core +**************************************************************************/ +void idxwspacefree(CtrlType *ctrl, int n) +{ + n += n%2; /* This is a fix for 64 bit machines that require 8-byte pointer allignment */ + + ctrl->wspace.ccore -= n; + ASSERT(ctrl->wspace.ccore >= 0); +} + + +/************************************************************************* +* This function allocate space from the core +**************************************************************************/ +float *fwspacemalloc(CtrlType *ctrl, int n) +{ + n += n%2; /* This is a fix for 64 bit machines that require 8-byte pointer allignment */ + + ctrl->wspace.ccore += n; + ASSERT(ctrl->wspace.ccore <= ctrl->wspace.maxcore); + return (float *) (ctrl->wspace.core + ctrl->wspace.ccore - n); +} + +/************************************************************************* +* This function frees space from the core +**************************************************************************/ +void fwspacefree(CtrlType *ctrl, int n) +{ + n += n%2; /* This is a fix for 64 bit machines that require 8-byte pointer allignment */ + + ctrl->wspace.ccore -= n; + ASSERT(ctrl->wspace.ccore >= 0); +} + + + +/************************************************************************* +* This function creates a CoarseGraphType data structure and initializes +* the various fields +**************************************************************************/ +GraphType *CreateGraph(void) +{ + GraphType *graph; + + graph = (GraphType *)GKmalloc(sizeof(GraphType), "CreateCoarseGraph: graph"); + + InitGraph(graph); + + return graph; +} + + +/************************************************************************* +* This function creates a CoarseGraphType data structure and initializes +* the various fields +**************************************************************************/ +void InitGraph(GraphType *graph) +{ + graph->gdata = graph->rdata = NULL; + + graph->nvtxs = graph->nedges = -1; + graph->mincut = graph->minvol = -1; + + graph->xadj = graph->vwgt = graph->adjncy = graph->adjwgt = NULL; + graph->adjwgtsum = NULL; + graph->label = NULL; + graph->cmap = NULL; + + graph->where = graph->pwgts = NULL; + graph->id = graph->ed = NULL; + graph->bndptr = graph->bndind = NULL; + graph->rinfo = NULL; + graph->vrinfo = NULL; + graph->nrinfo = NULL; + + graph->ncon = -1; + graph->nvwgt = NULL; + graph->npwgts = NULL; + + graph->vsize = NULL; + + graph->coarser = graph->finer = NULL; + +} + +/************************************************************************* +* This function deallocates any memory stored in a graph +**************************************************************************/ +void FreeGraph(GraphType *graph) +{ + + GKfree(&graph->gdata, &graph->nvwgt, &graph->rdata, &graph->npwgts, LTERM); + free(graph); +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_mfm.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_mfm.c new file mode 100644 index 0000000..9f37848 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_mfm.c @@ -0,0 +1,341 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mfm.c + * + * This file contains code that implements the edge-based FM refinement + * + * Started 7/23/97 + * George + * + * $Id: NEW_mfm.c,v 1.1 2003/07/16 15:55:13 karypis Exp $ + */ + +#include <metis.h> + + +/************************************************************************* +* This function performs an edge-based FM refinement +**************************************************************************/ +void MocFM_2WayEdgeRefine(CtrlType *ctrl, GraphType *graph, float *tpwgts, int npasses) +{ + int i, ii, j, k, l, kwgt, nvtxs, ncon, nbnd, nswaps, from, to, pass, me, limit, tmp, cnum; + idxtype *xadj, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind; + idxtype *moved, *swaps, *perm, *qnum; + float *nvwgt, *npwgts, mindiff[MAXNCON], origbal, minbal, newbal; + PQueueType parts[MAXNCON][2]; + int higain, oldgain, mincut, initcut, newcut, mincutorder; + float rtpwgts[2]; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + id = graph->id; + ed = graph->ed; + npwgts = graph->npwgts; + bndptr = graph->bndptr; + bndind = graph->bndind; + + moved = idxwspacemalloc(ctrl, nvtxs); + swaps = idxwspacemalloc(ctrl, nvtxs); + perm = idxwspacemalloc(ctrl, nvtxs); + qnum = idxwspacemalloc(ctrl, nvtxs); + + limit = amin(amax(0.01*nvtxs, 25), 150); + + /* Initialize the queues */ + for (i=0; i<ncon; i++) { + PQueueInit(ctrl, &parts[i][0], nvtxs, PLUS_GAINSPAN+1); + PQueueInit(ctrl, &parts[i][1], nvtxs, PLUS_GAINSPAN+1); + } + for (i=0; i<nvtxs; i++) + qnum[i] = samax(ncon, nvwgt+i*ncon); + + origbal = Compute2WayHLoadImbalance(ncon, npwgts, tpwgts); + + rtpwgts[0] = origbal*tpwgts[0]; + rtpwgts[1] = origbal*tpwgts[1]; + + if (ctrl->dbglvl&DBG_REFINE) { + printf("Parts: ["); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf("] T[%.3f %.3f], Nv-Nb[%5d, %5d]. ICut: %6d, LB: %.3f\n", tpwgts[0], tpwgts[1], graph->nvtxs, graph->nbnd, graph->mincut, origbal); + } + + idxset(nvtxs, -1, moved); + for (pass=0; pass<npasses; pass++) { /* Do a number of passes */ + for (i=0; i<ncon; i++) { + PQueueReset(&parts[i][0]); + PQueueReset(&parts[i][1]); + } + + mincutorder = -1; + newcut = mincut = initcut = graph->mincut; + for (i=0; i<ncon; i++) + mindiff[i] = fabs(tpwgts[0]-npwgts[i]); + minbal = Compute2WayHLoadImbalance(ncon, npwgts, tpwgts); + + ASSERT(ComputeCut(graph, where) == graph->mincut); + ASSERT(CheckBnd(graph)); + + /* Insert boundary nodes in the priority queues */ + nbnd = graph->nbnd; + RandomPermute(nbnd, perm, 1); + for (ii=0; ii<nbnd; ii++) { + i = bndind[perm[ii]]; + ASSERT(ed[i] > 0 || id[i] == 0); + ASSERT(bndptr[i] != -1); + PQueueInsert(&parts[qnum[i]][where[i]], i, ed[i]-id[i]); + } + + for (nswaps=0; nswaps<nvtxs; nswaps++) { + SelectQueue(ncon, npwgts, rtpwgts, &from, &cnum, parts); + to = (from+1)%2; + + if (from == -1 || (higain = PQueueGetMax(&parts[cnum][from])) == -1) + break; + ASSERT(bndptr[higain] != -1); + + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + + newcut -= (ed[higain]-id[higain]); + newbal = Compute2WayHLoadImbalance(ncon, npwgts, tpwgts); + + if ((newcut < mincut && newbal-origbal <= .00001) || + (newcut == mincut && (newbal < minbal || + (newbal == minbal && BetterBalance(ncon, npwgts, tpwgts, mindiff))))) { + mincut = newcut; + minbal = newbal; + mincutorder = nswaps; + for (i=0; i<ncon; i++) + mindiff[i] = fabs(tpwgts[0]-npwgts[i]); + } + else if (nswaps-mincutorder > limit) { /* We hit the limit, undo last move */ + newcut += (ed[higain]-id[higain]); + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + break; + } + + where[higain] = to; + moved[higain] = nswaps; + swaps[nswaps] = higain; + + if (ctrl->dbglvl&DBG_MOVEINFO) { + printf("Moved %6d from %d(%d). Gain: %5d, Cut: %5d, NPwgts: ", higain, from, cnum, ed[higain]-id[higain], newcut); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf(", %.3f LB: %.3f\n", minbal, newbal); + } + + + /************************************************************** + * Update the id[i]/ed[i] values of the affected nodes + ***************************************************************/ + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + oldgain = ed[k]-id[k]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + /* Update its boundary information and queue position */ + if (bndptr[k] != -1) { /* If k was a boundary vertex */ + if (ed[k] == 0) { /* Not a boundary vertex any more */ + BNDDelete(nbnd, bndind, bndptr, k); + if (moved[k] == -1) /* Remove it if in the queues */ + PQueueDelete(&parts[qnum[k]][where[k]], k, oldgain); + } + else { /* If it has not been moved, update its position in the queue */ + if (moved[k] == -1) + PQueueUpdate(&parts[qnum[k]][where[k]], k, oldgain, ed[k]-id[k]); + } + } + else { + if (ed[k] > 0) { /* It will now become a boundary vertex */ + BNDInsert(nbnd, bndind, bndptr, k); + if (moved[k] == -1) + PQueueInsert(&parts[qnum[k]][where[k]], k, ed[k]-id[k]); + } + } + } + + } + + + /**************************************************************** + * Roll back computations + *****************************************************************/ + for (i=0; i<nswaps; i++) + moved[swaps[i]] = -1; /* reset moved array */ + for (nswaps--; nswaps>mincutorder; nswaps--) { + higain = swaps[nswaps]; + + to = where[higain] = (where[higain]+1)%2; + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + else if (ed[higain] > 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+((to+1)%2)*ncon, 1); + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + if (bndptr[k] != -1 && ed[k] == 0) + BNDDelete(nbnd, bndind, bndptr, k); + if (bndptr[k] == -1 && ed[k] > 0) + BNDInsert(nbnd, bndind, bndptr, k); + } + } + + if (ctrl->dbglvl&DBG_REFINE) { + printf("\tMincut: %6d at %5d, NBND: %6d, NPwgts: [", mincut, mincutorder, nbnd); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf("], LB: %.3f\n", Compute2WayHLoadImbalance(ncon, npwgts, tpwgts)); + } + + graph->mincut = mincut; + graph->nbnd = nbnd; + + if (mincutorder == -1 || mincut == initcut) + break; + } + + for (i=0; i<ncon; i++) { + PQueueFree(ctrl, &parts[i][0]); + PQueueFree(ctrl, &parts[i][1]); + } + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + +} + + +/************************************************************************* +* This function selects the partition number and the queue from which +* we will move vertices out +**************************************************************************/ +void SelectQueue(int ncon, float *npwgts, float *tpwgts, int *from, int *cnum, PQueueType queues[MAXNCON][2]) +{ + int i, part, maxgain=0; + float max, maxdiff=0.0; + + *from = -1; + *cnum = -1; + + /* First determine the side and the queue, irrespective of the presence of nodes */ + for (part=0; part<2; part++) { + for (i=0; i<ncon; i++) { + if (npwgts[part*ncon+i]-tpwgts[part] >= maxdiff) { + maxdiff = npwgts[part*ncon+i]-tpwgts[part]; + *from = part; + *cnum = i; + } + } + } + + /* printf("Selected %d(%d) -> %d\n", *from, *cnum, PQueueGetSize(&queues[*cnum][*from])); */ + + if (*from != -1 && PQueueGetSize(&queues[*cnum][*from]) == 0) { + /* The desired queue is empty, select a node from that side anyway */ + for (i=0; i<ncon; i++) { + if (PQueueGetSize(&queues[i][*from]) > 0) { + max = npwgts[(*from)*ncon + i]; + *cnum = i; + break; + } + } + + for (i++; i<ncon; i++) { + if (npwgts[(*from)*ncon + i] > max && PQueueGetSize(&queues[i][*from]) > 0) { + max = npwgts[(*from)*ncon + i]; + *cnum = i; + } + } + } + + /* Check to see if you can focus on the cut */ + if (maxdiff <= 0.0 || *from == -1) { + maxgain = -100000; + + for (part=0; part<2; part++) { + for (i=0; i<ncon; i++) { + if (PQueueGetSize(&queues[i][part]) > 0 && PQueueGetKey(&queues[i][part]) > maxgain) { + maxgain = PQueueGetKey(&queues[i][part]); + *from = part; + *cnum = i; + } + } + } + } +} + + + + + +/************************************************************************* +* This function checks if the balance achieved is better than the diff +* For now, it uses a 2-norm measure +**************************************************************************/ +int BetterBalance(int ncon, float *npwgts, float *tpwgts, float *diff) +{ + int i; + float ndiff[MAXNCON]; + + for (i=0; i<ncon; i++) + ndiff[i] = fabs(tpwgts[0]-npwgts[i]); + + return snorm2(ncon, ndiff) < snorm2(ncon, diff); +} + + + +/************************************************************************* +* This function computes the load imbalance over all the constrains +**************************************************************************/ +float Compute2WayHLoadImbalance(int ncon, float *npwgts, float *tpwgts) +{ + int i; + float max=0.0, temp; + + for (i=0; i<ncon; i++) { + /* temp = amax(npwgts[i]/tpwgts[0], npwgts[ncon+i]/tpwgts[1]); */ + temp = fabs(tpwgts[0]-npwgts[i])/tpwgts[0]; + max = (max < temp ? temp : max); + } + return 1.0+max; +} + + +/************************************************************************* +* This function computes the load imbalance over all the constrains +* For now assume that we just want balanced partitionings +**************************************************************************/ +void Compute2WayHLoadImbalanceVec(int ncon, float *npwgts, float *tpwgts, float *lbvec) +{ + int i; + + for (i=0; i<ncon; i++) + lbvec[i] = 1.0 + fabs(tpwgts[0]-npwgts[i])/tpwgts[0]; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_mrefine.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_mrefine.c new file mode 100644 index 0000000..9cea995 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_mrefine.c @@ -0,0 +1,219 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * refine.c + * + * This file contains the driving routines for multilevel refinement + * + * Started 7/24/97 + * George + * + * $Id: NEW_mrefine.c,v 1.1 2003/07/16 15:55:14 karypis Exp $ + */ + +#include <metis.h> + + +/************************************************************************* +* This function is the entry point of refinement +**************************************************************************/ +void MocRefine2Way(CtrlType *ctrl, GraphType *orggraph, GraphType *graph, float *tpwgts, float ubfactor) +{ + int i; + float tubvec[MAXNCON]; + + for (i=0; i<graph->ncon; i++) + tubvec[i] = 1.0; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->UncoarsenTmr)); + + /* Compute the parameters of the coarsest graph */ + MocCompute2WayPartitionParams(ctrl, graph); + + for (;;) { + ASSERT(CheckBnd(graph)); + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->RefTmr)); + switch (ctrl->RType) { + case RTYPE_FM: + MocBalance2Way(ctrl, graph, tpwgts, 1.03); + MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 8); + break; + case 2: + MocBalance2Way(ctrl, graph, tpwgts, 1.03); + MocFM_2WayEdgeRefine2(ctrl, graph, tpwgts, tubvec, 8); + break; + default: + errexit("Unknown refinement type: %d\n", ctrl->RType); + } + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->RefTmr)); + + if (graph == orggraph) + break; + + graph = graph->finer; + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ProjectTmr)); + MocProject2WayPartition(ctrl, graph); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ProjectTmr)); + } + + MocBalance2Way(ctrl, graph, tpwgts, 1.01); + MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 8); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->UncoarsenTmr)); +} + + +/************************************************************************* +* This function allocates memory for 2-way edge refinement +**************************************************************************/ +void MocAllocate2WayPartitionMemory(CtrlType *ctrl, GraphType *graph) +{ + int nvtxs, ncon; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + + graph->rdata = idxmalloc(5*nvtxs, "Allocate2WayPartitionMemory: rdata"); + graph->where = graph->rdata; + graph->id = graph->rdata + nvtxs; + graph->ed = graph->rdata + 2*nvtxs; + graph->bndptr = graph->rdata + 3*nvtxs; + graph->bndind = graph->rdata + 4*nvtxs; + + graph->npwgts = fmalloc(2*ncon, "npwgts"); +} + + +/************************************************************************* +* This function computes the initial id/ed +**************************************************************************/ +void MocCompute2WayPartitionParams(CtrlType *ctrl, GraphType *graph) +{ + int i, j, k, l, nvtxs, ncon, nbnd, mincut; + idxtype *xadj, *adjncy, *adjwgt; + float *nvwgt, *npwgts; + idxtype *id, *ed, *where; + idxtype *bndptr, *bndind; + int me, other; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + where = graph->where; + npwgts = sset(2*ncon, 0.0, graph->npwgts); + id = idxset(nvtxs, 0, graph->id); + ed = idxset(nvtxs, 0, graph->ed); + bndptr = idxset(nvtxs, -1, graph->bndptr); + bndind = graph->bndind; + + + /*------------------------------------------------------------ + / Compute now the id/ed degrees + /------------------------------------------------------------*/ + nbnd = mincut = 0; + for (i=0; i<nvtxs; i++) { + ASSERT(where[i] >= 0 && where[i] <= 1); + me = where[i]; + saxpy(ncon, 1.0, nvwgt+i*ncon, 1, npwgts+me*ncon, 1); + + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (me == where[adjncy[j]]) + id[i] += adjwgt[j]; + else + ed[i] += adjwgt[j]; + } + + if (ed[i] > 0 || xadj[i] == xadj[i+1]) { + mincut += ed[i]; + bndptr[i] = nbnd; + bndind[nbnd++] = i; + } + } + + graph->mincut = mincut/2; + graph->nbnd = nbnd; + +} + + + +/************************************************************************* +* This function projects a partition, and at the same time computes the +* parameters for refinement. +**************************************************************************/ +void MocProject2WayPartition(CtrlType *ctrl, GraphType *graph) +{ + int i, j, k, nvtxs, nbnd, me; + idxtype *xadj, *adjncy, *adjwgt, *adjwgtsum; + idxtype *cmap, *where, *id, *ed, *bndptr, *bndind; + idxtype *cwhere, *cid, *ced, *cbndptr; + GraphType *cgraph; + + cgraph = graph->coarser; + cwhere = cgraph->where; + cid = cgraph->id; + ced = cgraph->ed; + cbndptr = cgraph->bndptr; + + nvtxs = graph->nvtxs; + cmap = graph->cmap; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + adjwgtsum = graph->adjwgtsum; + + MocAllocate2WayPartitionMemory(ctrl, graph); + + where = graph->where; + id = idxset(nvtxs, 0, graph->id); + ed = idxset(nvtxs, 0, graph->ed); + bndptr = idxset(nvtxs, -1, graph->bndptr); + bndind = graph->bndind; + + + /* Go through and project partition and compute id/ed for the nodes */ + for (i=0; i<nvtxs; i++) { + k = cmap[i]; + where[i] = cwhere[k]; + cmap[i] = cbndptr[k]; + } + + for (nbnd=0, i=0; i<nvtxs; i++) { + me = where[i]; + + id[i] = adjwgtsum[i]; + + if (xadj[i] == xadj[i+1]) { + bndptr[i] = nbnd; + bndind[nbnd++] = i; + } + else { + if (cmap[i] != -1) { /* If it is an interface node. Note that cmap[i] = cbndptr[cmap[i]] */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (me != where[adjncy[j]]) + ed[i] += adjwgt[j]; + } + id[i] -= ed[i]; + + if (ed[i] > 0 || xadj[i] == xadj[i+1]) { + bndptr[i] = nbnd; + bndind[nbnd++] = i; + } + } + } + } + + graph->mincut = cgraph->mincut; + graph->nbnd = nbnd; + scopy(2*graph->ncon, cgraph->npwgts, graph->npwgts); + + FreeGraph(graph->coarser); + graph->coarser = NULL; + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_parmetis.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_parmetis.c new file mode 100644 index 0000000..bd97917 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_parmetis.c @@ -0,0 +1,155 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * parmetis.c + * + * This file contains the top level routines for the multilevel recursive + * bisection algorithm PMETIS. + * + * Started 7/24/97 + * George + * + * $Id: NEW_parmetis.c,v 1.1 2003/07/16 15:55:14 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function is the entry point for PWMETIS that accepts exact weights +* for the target partitions +**************************************************************************/ +void METIS_mCPartGraphRecursive2(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, + idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, + float *tpwgts, int *options, int *edgecut, idxtype *part) +{ + int i, j; + GraphType graph; + CtrlType ctrl; + float *mytpwgts; +idxtype wgt[2048], minwgt, maxwgt, sumwgt; +float avgwgt; + + if (*numflag == 1) + Change2CNumbering(*nvtxs, xadj, adjncy); + + SetUpGraph(&graph, OP_PMETIS, *nvtxs, *ncon, xadj, adjncy, vwgt, adjwgt, *wgtflag); + graph.npwgts = NULL; + mytpwgts = fmalloc(*nparts, "mytpwgts"); + scopy(*nparts, tpwgts, mytpwgts); + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = McPMETIS_CTYPE; + ctrl.IType = McPMETIS_ITYPE; + ctrl.RType = McPMETIS_RTYPE; + ctrl.dbglvl = McPMETIS_DBGLVL; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + } + ctrl.optype = OP_PMETIS; + ctrl.CoarsenTo = 100; + + ctrl.nmaxvwgt = 1.5/(1.0*ctrl.CoarsenTo); + + InitRandom(options[7]); + + AllocateWorkSpace(&ctrl, &graph, *nparts); + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + ASSERT(CheckGraph(&graph)); + *edgecut = MCMlevelRecursiveBisection2(&ctrl, &graph, *nparts, mytpwgts, part, 1.000, 0); +/* +printf("nvtxs: %d, nparts: %d, ncon: %d\n", graph.nvtxs, *nparts, *ncon); +for (i=0; i<(*nparts)*(*ncon); i++) + wgt[i] = 0; +for (i=0; i<graph.nvtxs; i++) + for (j=0; j<*ncon; j++) + wgt[part[i]*(*ncon)+j] += vwgt[i*(*ncon)+j]; + +for (j=0; j<*ncon; j++) { + minwgt = maxwgt = sumwgt = 0; + for (i=0; i<(*nparts); i++) { + minwgt = (wgt[i*(*ncon)+j] < wgt[minwgt*(*ncon)+j]) ? i : minwgt; + maxwgt = (wgt[i*(*ncon)+j] > wgt[maxwgt*(*ncon)+j]) ? i : maxwgt; + sumwgt += wgt[i*(*ncon)+j]; + } + avgwgt = (float)sumwgt / (float)*nparts; + printf("min: %5d, max: %5d, avg: %5.2f, balance: %6.3f\n", wgt[minwgt*(*ncon)+j], wgt[maxwgt*(*ncon)+j], avgwgt, (float)wgt[maxwgt*(*ncon)+j] / avgwgt); +} +printf("\n"); +*/ + + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); + + FreeWorkSpace(&ctrl, &graph); + GKfree((void *)&mytpwgts, LTERM); + + if (*numflag == 1) + Change2FNumbering(*nvtxs, xadj, adjncy, part); +} + + + +/************************************************************************* +* This function takes a graph and produces a bisection of it +**************************************************************************/ +int MCMlevelRecursiveBisection2(CtrlType *ctrl, GraphType *graph, int nparts, + float *tpwgts, idxtype *part, float ubfactor, int fpart) +{ + int i, nvtxs, cut; + float wsum, tpwgts2[2]; + idxtype *label, *where; + GraphType lgraph, rgraph; + + nvtxs = graph->nvtxs; + if (nvtxs == 0) { +/* printf("\t***Cannot bisect a graph with 0 vertices!\n\t***You are trying to partition a graph into too many parts!\n"); */ + return 0; + } + + /* Determine the weights of the partitions */ + tpwgts2[0] = ssum(nparts/2, tpwgts); + tpwgts2[1] = 1.0-tpwgts2[0]; + + MCMlevelEdgeBisection(ctrl, graph, tpwgts2, ubfactor); + cut = graph->mincut; + + label = graph->label; + where = graph->where; + for (i=0; i<nvtxs; i++) + part[label[i]] = where[i] + fpart; + + if (nparts > 2) + SplitGraphPart(ctrl, graph, &lgraph, &rgraph); + + /* Free the memory of the top level graph */ + GKfree(&graph->gdata, &graph->nvwgt, &graph->rdata, &graph->label, &graph->npwgts, LTERM); + + /* Scale the fractions in the tpwgts according to the true weight */ + wsum = ssum(nparts/2, tpwgts); + sscale(nparts/2, 1.0/wsum, tpwgts); + sscale(nparts-nparts/2, 1.0/(1.0-wsum), tpwgts+nparts/2); + + /* Do the recursive call */ + if (nparts > 3) { + cut += MCMlevelRecursiveBisection2(ctrl, &lgraph, nparts/2, tpwgts, part, ubfactor, fpart); + cut += MCMlevelRecursiveBisection2(ctrl, &rgraph, nparts-nparts/2, tpwgts+nparts/2, part, ubfactor, fpart+nparts/2); + } + else if (nparts == 3) { + cut += MCMlevelRecursiveBisection2(ctrl, &rgraph, nparts-nparts/2, tpwgts+nparts/2, part, ubfactor, fpart+nparts/2); + GKfree(&lgraph.gdata, &lgraph.nvwgt, &lgraph.label, LTERM); + } + + return cut; + +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_stats.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_stats.c new file mode 100644 index 0000000..9e04b23 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/NEW_stats.c @@ -0,0 +1,44 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * stat.c + * + * This file computes various statistics + * + * Started 7/25/97 + * George + * + * $Id: NEW_stats.c,v 1.1 2003/07/16 15:55:15 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function computes the balance of the partitioning +**************************************************************************/ +void Moc_ComputePartitionBalance(GraphType *graph, int nparts, idxtype *where, float *ubvec) +{ + int i, j, nvtxs, ncon; + float *kpwgts, *nvwgt; + float balance; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + nvwgt = graph->nvwgt; + + kpwgts = fmalloc(nparts, "ComputePartitionInfo: kpwgts"); + + for (j=0; j<ncon; j++) { + sset(nparts, 0.0, kpwgts); + for (i=0; i<graph->nvtxs; i++) + kpwgts[where[i]] += nvwgt[i*ncon+j]; + + ubvec[j] = (float)nparts*kpwgts[samax(nparts, kpwgts)]/ssum(nparts, kpwgts); + } + + free(kpwgts); + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/balance.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/balance.c new file mode 100644 index 0000000..ac951da --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/balance.c @@ -0,0 +1,278 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * balance.c + * + * This file contains code that is used to forcefully balance either + * bisections or k-sections + * + * Started 7/29/97 + * George + * + * $Id: balance.c,v 1.1 2003/07/16 15:54:58 karypis Exp $ + * + */ + +#include <metis.h> + +/************************************************************************* +* This function is the entry point of the bisection balancing algorithms. +**************************************************************************/ +void Balance2Way(CtrlType *ctrl, GraphType *graph, int *tpwgts, float ubfactor) +{ + int i, j, nvtxs, from, imax, gain, mindiff; + idxtype *id, *ed; + + /* Return right away if the balance is OK */ + mindiff = abs(tpwgts[0]-graph->pwgts[0]); + if (mindiff < 3*(graph->pwgts[0]+graph->pwgts[1])/graph->nvtxs) + return; + if (graph->pwgts[0] > tpwgts[0] && graph->pwgts[0] < (int)(ubfactor*tpwgts[0])) + return; + if (graph->pwgts[1] > tpwgts[1] && graph->pwgts[1] < (int)(ubfactor*tpwgts[1])) + return; + + if (graph->nbnd > 0) + Bnd2WayBalance(ctrl, graph, tpwgts); + else + General2WayBalance(ctrl, graph, tpwgts); + +} + + + +/************************************************************************* +* This function balances two partitions by moving boundary nodes +* from the domain that is overweight to the one that is underweight. +**************************************************************************/ +void Bnd2WayBalance(CtrlType *ctrl, GraphType *graph, int *tpwgts) +{ + int i, ii, j, k, kwgt, nvtxs, nbnd, nswaps, from, to, pass, me, tmp; + idxtype *xadj, *vwgt, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind, *pwgts; + idxtype *moved, *perm; + PQueueType parts; + int higain, oldgain, mincut, mindiff; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + id = graph->id; + ed = graph->ed; + pwgts = graph->pwgts; + bndptr = graph->bndptr; + bndind = graph->bndind; + + moved = idxwspacemalloc(ctrl, nvtxs); + perm = idxwspacemalloc(ctrl, nvtxs); + + /* Determine from which domain you will be moving data */ + mindiff = abs(tpwgts[0]-pwgts[0]); + from = (pwgts[0] < tpwgts[0] ? 1 : 0); + to = (from+1)%2; + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("Partitions: [%6d %6d] T[%6d %6d], Nv-Nb[%6d %6d]. ICut: %6d [B]\n", + pwgts[0], pwgts[1], tpwgts[0], tpwgts[1], graph->nvtxs, graph->nbnd, graph->mincut)); + + tmp = graph->adjwgtsum[idxamax(nvtxs, graph->adjwgtsum)]; + PQueueInit(ctrl, &parts, nvtxs, tmp); + + idxset(nvtxs, -1, moved); + + ASSERT(ComputeCut(graph, where) == graph->mincut); + ASSERT(CheckBnd(graph)); + + /* Insert the boundary nodes of the proper partition whose size is OK in the priority queue */ + nbnd = graph->nbnd; + RandomPermute(nbnd, perm, 1); + for (ii=0; ii<nbnd; ii++) { + i = perm[ii]; + ASSERT(ed[bndind[i]] > 0 || id[bndind[i]] == 0); + ASSERT(bndptr[bndind[i]] != -1); + if (where[bndind[i]] == from && vwgt[bndind[i]] <= mindiff) + PQueueInsert(&parts, bndind[i], ed[bndind[i]]-id[bndind[i]]); + } + + mincut = graph->mincut; + for (nswaps=0; nswaps<nvtxs; nswaps++) { + if ((higain = PQueueGetMax(&parts)) == -1) + break; + ASSERT(bndptr[higain] != -1); + + if (pwgts[to]+vwgt[higain] > tpwgts[to]) + break; + + mincut -= (ed[higain]-id[higain]); + INC_DEC(pwgts[to], pwgts[from], vwgt[higain]); + + where[higain] = to; + moved[higain] = nswaps; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, + printf("Moved %6d from %d. [%3d %3d] %5d [%4d %4d]\n", higain, from, ed[higain]-id[higain], vwgt[higain], mincut, pwgts[0], pwgts[1])); + + /************************************************************** + * Update the id[i]/ed[i] values of the affected nodes + ***************************************************************/ + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + oldgain = ed[k]-id[k]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + /* Update its boundary information and queue position */ + if (bndptr[k] != -1) { /* If k was a boundary vertex */ + if (ed[k] == 0) { /* Not a boundary vertex any more */ + BNDDelete(nbnd, bndind, bndptr, k); + if (moved[k] == -1 && where[k] == from && vwgt[k] <= mindiff) /* Remove it if in the queues */ + PQueueDelete(&parts, k, oldgain); + } + else { /* If it has not been moved, update its position in the queue */ + if (moved[k] == -1 && where[k] == from && vwgt[k] <= mindiff) + PQueueUpdate(&parts, k, oldgain, ed[k]-id[k]); + } + } + else { + if (ed[k] > 0) { /* It will now become a boundary vertex */ + BNDInsert(nbnd, bndind, bndptr, k); + if (moved[k] == -1 && where[k] == from && vwgt[k] <= mindiff) + PQueueInsert(&parts, k, ed[k]-id[k]); + } + } + } + } + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\tMinimum cut: %6d, PWGTS: [%6d %6d], NBND: %6d\n", mincut, pwgts[0], pwgts[1], nbnd)); + + graph->mincut = mincut; + graph->nbnd = nbnd; + + PQueueFree(ctrl, &parts); + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + +/************************************************************************* +* This function balances two partitions by moving the highest gain +* (including negative gain) vertices to the other domain. +* It is used only when tha unbalance is due to non contigous +* subdomains. That is, the are no boundary vertices. +* It moves vertices from the domain that is overweight to the one that +* is underweight. +**************************************************************************/ +void General2WayBalance(CtrlType *ctrl, GraphType *graph, int *tpwgts) +{ + int i, ii, j, k, kwgt, nvtxs, nbnd, nswaps, from, to, pass, me, tmp; + idxtype *xadj, *vwgt, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind, *pwgts; + idxtype *moved, *perm; + PQueueType parts; + int higain, oldgain, mincut, mindiff; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + id = graph->id; + ed = graph->ed; + pwgts = graph->pwgts; + bndptr = graph->bndptr; + bndind = graph->bndind; + + moved = idxwspacemalloc(ctrl, nvtxs); + perm = idxwspacemalloc(ctrl, nvtxs); + + /* Determine from which domain you will be moving data */ + mindiff = abs(tpwgts[0]-pwgts[0]); + from = (pwgts[0] < tpwgts[0] ? 1 : 0); + to = (from+1)%2; + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("Partitions: [%6d %6d] T[%6d %6d], Nv-Nb[%6d %6d]. ICut: %6d [B]\n", + pwgts[0], pwgts[1], tpwgts[0], tpwgts[1], graph->nvtxs, graph->nbnd, graph->mincut)); + + tmp = graph->adjwgtsum[idxamax(nvtxs, graph->adjwgtsum)]; + PQueueInit(ctrl, &parts, nvtxs, tmp); + + idxset(nvtxs, -1, moved); + + ASSERT(ComputeCut(graph, where) == graph->mincut); + ASSERT(CheckBnd(graph)); + + /* Insert the nodes of the proper partition whose size is OK in the priority queue */ + RandomPermute(nvtxs, perm, 1); + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + if (where[i] == from && vwgt[i] <= mindiff) + PQueueInsert(&parts, i, ed[i]-id[i]); + } + + mincut = graph->mincut; + nbnd = graph->nbnd; + for (nswaps=0; nswaps<nvtxs; nswaps++) { + if ((higain = PQueueGetMax(&parts)) == -1) + break; + + if (pwgts[to]+vwgt[higain] > tpwgts[to]) + break; + + mincut -= (ed[higain]-id[higain]); + INC_DEC(pwgts[to], pwgts[from], vwgt[higain]); + + where[higain] = to; + moved[higain] = nswaps; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, + printf("Moved %6d from %d. [%3d %3d] %5d [%4d %4d]\n", higain, from, ed[higain]-id[higain], vwgt[higain], mincut, pwgts[0], pwgts[1])); + + /************************************************************** + * Update the id[i]/ed[i] values of the affected nodes + ***************************************************************/ + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + if (ed[higain] > 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + oldgain = ed[k]-id[k]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + /* Update the queue position */ + if (moved[k] == -1 && where[k] == from && vwgt[k] <= mindiff) + PQueueUpdate(&parts, k, oldgain, ed[k]-id[k]); + + /* Update its boundary information */ + if (ed[k] == 0 && bndptr[k] != -1) + BNDDelete(nbnd, bndind, bndptr, k); + else if (ed[k] > 0 && bndptr[k] == -1) + BNDInsert(nbnd, bndind, bndptr, k); + } + } + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\tMinimum cut: %6d, PWGTS: [%6d %6d], NBND: %6d\n", mincut, pwgts[0], pwgts[1], nbnd)); + + graph->mincut = mincut; + graph->nbnd = nbnd; + + PQueueFree(ctrl, &parts); + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/bucketsort.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/bucketsort.c new file mode 100644 index 0000000..14aa213 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/bucketsort.c @@ -0,0 +1,43 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * bucketsort.c + * + * This file contains code that implement a variety of counting sorting + * algorithms + * + * Started 7/25/97 + * George + * + * $Id: bucketsort.c,v 1.1 2003/07/16 15:55:00 karypis Exp $ + * + */ + +#include <metis.h> + + + +/************************************************************************* +* This function uses simple counting sort to return a permutation array +* corresponding to the sorted order. The keys are assumed to start from +* 0 and they are positive. This sorting is used during matching. +**************************************************************************/ +void BucketSortKeysInc(int n, int max, idxtype *keys, idxtype *tperm, idxtype *perm) +{ + int i, ii; + idxtype *counts; + + counts = idxsmalloc(max+2, 0, "BucketSortKeysInc: counts"); + + for (i=0; i<n; i++) + counts[keys[i]]++; + MAKECSR(i, max+1, counts); + + for (ii=0; ii<n; ii++) { + i = tperm[ii]; + perm[counts[keys[i]]++] = i; + } + + free(counts); +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/ccgraph.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/ccgraph.c new file mode 100644 index 0000000..3485ab0 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/ccgraph.c @@ -0,0 +1,599 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * ccgraph.c + * + * This file contains the functions that create the coarse graph + * + * Started 8/11/97 + * George + * + * $Id: ccgraph.c,v 1.1 2003/07/16 15:55:00 karypis Exp $ + * + */ + +#include <metis.h> + + + +/************************************************************************* +* This function creates the coarser graph +**************************************************************************/ +void CreateCoarseGraph(CtrlType *ctrl, GraphType *graph, int cnvtxs, idxtype *match, idxtype *perm) +{ + int i, j, jj, k, kk, l, m, istart, iend, nvtxs, nedges, ncon, cnedges, v, u, mask, dovsize; + idxtype *xadj, *vwgt, *vsize, *adjncy, *adjwgt, *adjwgtsum, *auxadj; + idxtype *cmap, *htable; + idxtype *cxadj, *cvwgt, *cvsize, *cadjncy, *cadjwgt, *cadjwgtsum; + float *nvwgt, *cnvwgt; + GraphType *cgraph; + + dovsize = (ctrl->optype == OP_KVMETIS ? 1 : 0); + + mask = HTLENGTH; + if (cnvtxs < 8*mask || graph->nedges/graph->nvtxs > 15) { + CreateCoarseGraphNoMask(ctrl, graph, cnvtxs, match, perm); + return; + } + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ContractTmr)); + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + vwgt = graph->vwgt; + vsize = graph->vsize; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + adjwgtsum = graph->adjwgtsum; + cmap = graph->cmap; + + /* Initialize the coarser graph */ + cgraph = SetUpCoarseGraph(graph, cnvtxs, dovsize); + cxadj = cgraph->xadj; + cvwgt = cgraph->vwgt; + cvsize = cgraph->vsize; + cnvwgt = cgraph->nvwgt; + cadjwgtsum = cgraph->adjwgtsum; + cadjncy = cgraph->adjncy; + cadjwgt = cgraph->adjwgt; + + + iend = xadj[nvtxs]; + auxadj = ctrl->wspace.auxcore; + memcpy(auxadj, adjncy, iend*sizeof(idxtype)); + for (i=0; i<iend; i++) + auxadj[i] = cmap[auxadj[i]]; + + htable = idxset(mask+1, -1, idxwspacemalloc(ctrl, mask+1)); + + cxadj[0] = cnvtxs = cnedges = 0; + for (i=0; i<nvtxs; i++) { + v = perm[i]; + if (cmap[v] != cnvtxs) + continue; + + u = match[v]; + if (ncon == 1) + cvwgt[cnvtxs] = vwgt[v]; + else + scopy(ncon, nvwgt+v*ncon, cnvwgt+cnvtxs*ncon); + + if (dovsize) + cvsize[cnvtxs] = vsize[v]; + + cadjwgtsum[cnvtxs] = adjwgtsum[v]; + nedges = 0; + + istart = xadj[v]; + iend = xadj[v+1]; + for (j=istart; j<iend; j++) { + k = auxadj[j]; + kk = k&mask; + if ((m = htable[kk]) == -1) { + cadjncy[nedges] = k; + cadjwgt[nedges] = adjwgt[j]; + htable[kk] = nedges++; + } + else if (cadjncy[m] == k) { + cadjwgt[m] += adjwgt[j]; + } + else { + for (jj=0; jj<nedges; jj++) { + if (cadjncy[jj] == k) { + cadjwgt[jj] += adjwgt[j]; + break; + } + } + if (jj == nedges) { + cadjncy[nedges] = k; + cadjwgt[nedges++] = adjwgt[j]; + } + } + } + + if (v != u) { + if (ncon == 1) + cvwgt[cnvtxs] += vwgt[u]; + else + saxpy(ncon, 1.0, nvwgt+u*ncon, 1, cnvwgt+cnvtxs*ncon, 1); + + if (dovsize) + cvsize[cnvtxs] += vsize[u]; + + cadjwgtsum[cnvtxs] += adjwgtsum[u]; + + istart = xadj[u]; + iend = xadj[u+1]; + for (j=istart; j<iend; j++) { + k = auxadj[j]; + kk = k&mask; + if ((m = htable[kk]) == -1) { + cadjncy[nedges] = k; + cadjwgt[nedges] = adjwgt[j]; + htable[kk] = nedges++; + } + else if (cadjncy[m] == k) { + cadjwgt[m] += adjwgt[j]; + } + else { + for (jj=0; jj<nedges; jj++) { + if (cadjncy[jj] == k) { + cadjwgt[jj] += adjwgt[j]; + break; + } + } + if (jj == nedges) { + cadjncy[nedges] = k; + cadjwgt[nedges++] = adjwgt[j]; + } + } + } + + /* Remove the contracted adjacency weight */ + jj = htable[cnvtxs&mask]; + if (jj >= 0 && cadjncy[jj] != cnvtxs) { + for (jj=0; jj<nedges; jj++) { + if (cadjncy[jj] == cnvtxs) + break; + } + } + if (jj >= 0 && cadjncy[jj] == cnvtxs) { /* This 2nd check is needed for non-adjacent matchings */ + cadjwgtsum[cnvtxs] -= cadjwgt[jj]; + cadjncy[jj] = cadjncy[--nedges]; + cadjwgt[jj] = cadjwgt[nedges]; + } + } + + ASSERTP(cadjwgtsum[cnvtxs] == idxsum(nedges, cadjwgt), ("%d %d %d %d %d\n", cnvtxs, cadjwgtsum[cnvtxs], idxsum(nedges, cadjwgt), adjwgtsum[u], adjwgtsum[v])); + + for (j=0; j<nedges; j++) + htable[cadjncy[j]&mask] = -1; /* Zero out the htable */ + htable[cnvtxs&mask] = -1; + + cnedges += nedges; + cxadj[++cnvtxs] = cnedges; + cadjncy += nedges; + cadjwgt += nedges; + } + + cgraph->nedges = cnedges; + + ReAdjustMemory(graph, cgraph, dovsize); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ContractTmr)); + + idxwspacefree(ctrl, mask+1); + +} + + +/************************************************************************* +* This function creates the coarser graph +**************************************************************************/ +void CreateCoarseGraphNoMask(CtrlType *ctrl, GraphType *graph, int cnvtxs, idxtype *match, idxtype *perm) +{ + int i, j, k, m, istart, iend, nvtxs, nedges, ncon, cnedges, v, u, dovsize; + idxtype *xadj, *vwgt, *vsize, *adjncy, *adjwgt, *adjwgtsum, *auxadj; + idxtype *cmap, *htable; + idxtype *cxadj, *cvwgt, *cvsize, *cadjncy, *cadjwgt, *cadjwgtsum; + float *nvwgt, *cnvwgt; + GraphType *cgraph; + + dovsize = (ctrl->optype == OP_KVMETIS ? 1 : 0); + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ContractTmr)); + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + vwgt = graph->vwgt; + vsize = graph->vsize; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + adjwgtsum = graph->adjwgtsum; + cmap = graph->cmap; + + + /* Initialize the coarser graph */ + cgraph = SetUpCoarseGraph(graph, cnvtxs, dovsize); + cxadj = cgraph->xadj; + cvwgt = cgraph->vwgt; + cvsize = cgraph->vsize; + cnvwgt = cgraph->nvwgt; + cadjwgtsum = cgraph->adjwgtsum; + cadjncy = cgraph->adjncy; + cadjwgt = cgraph->adjwgt; + + + htable = idxset(cnvtxs, -1, idxwspacemalloc(ctrl, cnvtxs)); + + iend = xadj[nvtxs]; + auxadj = ctrl->wspace.auxcore; + memcpy(auxadj, adjncy, iend*sizeof(idxtype)); + for (i=0; i<iend; i++) + auxadj[i] = cmap[auxadj[i]]; + + cxadj[0] = cnvtxs = cnedges = 0; + for (i=0; i<nvtxs; i++) { + v = perm[i]; + if (cmap[v] != cnvtxs) + continue; + + u = match[v]; + if (ncon == 1) + cvwgt[cnvtxs] = vwgt[v]; + else + scopy(ncon, nvwgt+v*ncon, cnvwgt+cnvtxs*ncon); + + if (dovsize) + cvsize[cnvtxs] = vsize[v]; + + cadjwgtsum[cnvtxs] = adjwgtsum[v]; + nedges = 0; + + istart = xadj[v]; + iend = xadj[v+1]; + for (j=istart; j<iend; j++) { + k = auxadj[j]; + if ((m = htable[k]) == -1) { + cadjncy[nedges] = k; + cadjwgt[nedges] = adjwgt[j]; + htable[k] = nedges++; + } + else { + cadjwgt[m] += adjwgt[j]; + } + } + + if (v != u) { + if (ncon == 1) + cvwgt[cnvtxs] += vwgt[u]; + else + saxpy(ncon, 1.0, nvwgt+u*ncon, 1, cnvwgt+cnvtxs*ncon, 1); + + if (dovsize) + cvsize[cnvtxs] += vsize[u]; + + cadjwgtsum[cnvtxs] += adjwgtsum[u]; + + istart = xadj[u]; + iend = xadj[u+1]; + for (j=istart; j<iend; j++) { + k = auxadj[j]; + if ((m = htable[k]) == -1) { + cadjncy[nedges] = k; + cadjwgt[nedges] = adjwgt[j]; + htable[k] = nedges++; + } + else { + cadjwgt[m] += adjwgt[j]; + } + } + + /* Remove the contracted adjacency weight */ + if ((j = htable[cnvtxs]) != -1) { + ASSERT(cadjncy[j] == cnvtxs); + cadjwgtsum[cnvtxs] -= cadjwgt[j]; + cadjncy[j] = cadjncy[--nedges]; + cadjwgt[j] = cadjwgt[nedges]; + htable[cnvtxs] = -1; + } + } + + ASSERTP(cadjwgtsum[cnvtxs] == idxsum(nedges, cadjwgt), ("%d %d\n", cadjwgtsum[cnvtxs], idxsum(nedges, cadjwgt))); + + for (j=0; j<nedges; j++) + htable[cadjncy[j]] = -1; /* Zero out the htable */ + + cnedges += nedges; + cxadj[++cnvtxs] = cnedges; + cadjncy += nedges; + cadjwgt += nedges; + } + + cgraph->nedges = cnedges; + + ReAdjustMemory(graph, cgraph, dovsize); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ContractTmr)); + + idxwspacefree(ctrl, cnvtxs); +} + + +/************************************************************************* +* This function creates the coarser graph +**************************************************************************/ +void CreateCoarseGraph_NVW(CtrlType *ctrl, GraphType *graph, int cnvtxs, idxtype *match, idxtype *perm) +{ + int i, j, jj, k, kk, l, m, istart, iend, nvtxs, nedges, ncon, cnedges, v, u, mask; + idxtype *xadj, *adjncy, *adjwgtsum, *auxadj; + idxtype *cmap, *htable; + idxtype *cxadj, *cvwgt, *cadjncy, *cadjwgt, *cadjwgtsum; + float *nvwgt, *cnvwgt; + GraphType *cgraph; + + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ContractTmr)); + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgtsum = graph->adjwgtsum; + cmap = graph->cmap; + + /* Initialize the coarser graph */ + cgraph = SetUpCoarseGraph(graph, cnvtxs, 0); + cxadj = cgraph->xadj; + cvwgt = cgraph->vwgt; + cnvwgt = cgraph->nvwgt; + cadjwgtsum = cgraph->adjwgtsum; + cadjncy = cgraph->adjncy; + cadjwgt = cgraph->adjwgt; + + + iend = xadj[nvtxs]; + auxadj = ctrl->wspace.auxcore; + memcpy(auxadj, adjncy, iend*sizeof(idxtype)); + for (i=0; i<iend; i++) + auxadj[i] = cmap[auxadj[i]]; + + mask = HTLENGTH; + htable = idxset(mask+1, -1, idxwspacemalloc(ctrl, mask+1)); + + cxadj[0] = cnvtxs = cnedges = 0; + for (i=0; i<nvtxs; i++) { + v = perm[i]; + if (cmap[v] != cnvtxs) + continue; + + u = match[v]; + cvwgt[cnvtxs] = 1; + cadjwgtsum[cnvtxs] = adjwgtsum[v]; + nedges = 0; + + istart = xadj[v]; + iend = xadj[v+1]; + for (j=istart; j<iend; j++) { + k = auxadj[j]; + kk = k&mask; + if ((m = htable[kk]) == -1) { + cadjncy[nedges] = k; + cadjwgt[nedges] = 1; + htable[kk] = nedges++; + } + else if (cadjncy[m] == k) { + cadjwgt[m]++; + } + else { + for (jj=0; jj<nedges; jj++) { + if (cadjncy[jj] == k) { + cadjwgt[jj]++; + break; + } + } + if (jj == nedges) { + cadjncy[nedges] = k; + cadjwgt[nedges++] = 1; + } + } + } + + if (v != u) { + cvwgt[cnvtxs]++; + cadjwgtsum[cnvtxs] += adjwgtsum[u]; + + istart = xadj[u]; + iend = xadj[u+1]; + for (j=istart; j<iend; j++) { + k = auxadj[j]; + kk = k&mask; + if ((m = htable[kk]) == -1) { + cadjncy[nedges] = k; + cadjwgt[nedges] = 1; + htable[kk] = nedges++; + } + else if (cadjncy[m] == k) { + cadjwgt[m]++; + } + else { + for (jj=0; jj<nedges; jj++) { + if (cadjncy[jj] == k) { + cadjwgt[jj]++; + break; + } + } + if (jj == nedges) { + cadjncy[nedges] = k; + cadjwgt[nedges++] = 1; + } + } + } + + /* Remove the contracted adjacency weight */ + jj = htable[cnvtxs&mask]; + if (jj >= 0 && cadjncy[jj] != cnvtxs) { + for (jj=0; jj<nedges; jj++) { + if (cadjncy[jj] == cnvtxs) + break; + } + } + if (jj >= 0 && cadjncy[jj] == cnvtxs) { /* This 2nd check is needed for non-adjacent matchings */ + cadjwgtsum[cnvtxs] -= cadjwgt[jj]; + cadjncy[jj] = cadjncy[--nedges]; + cadjwgt[jj] = cadjwgt[nedges]; + } + } + + ASSERTP(cadjwgtsum[cnvtxs] == idxsum(nedges, cadjwgt), ("%d %d %d %d %d\n", cnvtxs, cadjwgtsum[cnvtxs], idxsum(nedges, cadjwgt), adjwgtsum[u], adjwgtsum[v])); + + for (j=0; j<nedges; j++) + htable[cadjncy[j]&mask] = -1; /* Zero out the htable */ + htable[cnvtxs&mask] = -1; + + cnedges += nedges; + cxadj[++cnvtxs] = cnedges; + cadjncy += nedges; + cadjwgt += nedges; + } + + cgraph->nedges = cnedges; + + ReAdjustMemory(graph, cgraph, 0); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ContractTmr)); + + idxwspacefree(ctrl, mask+1); + +} + + +/************************************************************************* +* Setup the various arrays for the coarse graph +**************************************************************************/ +GraphType *SetUpCoarseGraph(GraphType *graph, int cnvtxs, int dovsize) +{ + GraphType *cgraph; + + cgraph = CreateGraph(); + cgraph->nvtxs = cnvtxs; + cgraph->ncon = graph->ncon; + + cgraph->finer = graph; + graph->coarser = cgraph; + + + /* Allocate memory for the coarser graph */ + if (graph->ncon == 1) { + if (dovsize) { + cgraph->gdata = idxmalloc(5*cnvtxs+1 + 2*graph->nedges, "SetUpCoarseGraph: gdata"); + cgraph->xadj = cgraph->gdata; + cgraph->vwgt = cgraph->gdata + cnvtxs+1; + cgraph->vsize = cgraph->gdata + 2*cnvtxs+1; + cgraph->adjwgtsum = cgraph->gdata + 3*cnvtxs+1; + cgraph->cmap = cgraph->gdata + 4*cnvtxs+1; + cgraph->adjncy = cgraph->gdata + 5*cnvtxs+1; + cgraph->adjwgt = cgraph->gdata + 5*cnvtxs+1 + graph->nedges; + } + else { + cgraph->gdata = idxmalloc(4*cnvtxs+1 + 2*graph->nedges, "SetUpCoarseGraph: gdata"); + cgraph->xadj = cgraph->gdata; + cgraph->vwgt = cgraph->gdata + cnvtxs+1; + cgraph->adjwgtsum = cgraph->gdata + 2*cnvtxs+1; + cgraph->cmap = cgraph->gdata + 3*cnvtxs+1; + cgraph->adjncy = cgraph->gdata + 4*cnvtxs+1; + cgraph->adjwgt = cgraph->gdata + 4*cnvtxs+1 + graph->nedges; + } + } + else { + if (dovsize) { + cgraph->gdata = idxmalloc(4*cnvtxs+1 + 2*graph->nedges, "SetUpCoarseGraph: gdata"); + cgraph->xadj = cgraph->gdata; + cgraph->vsize = cgraph->gdata + cnvtxs+1; + cgraph->adjwgtsum = cgraph->gdata + 2*cnvtxs+1; + cgraph->cmap = cgraph->gdata + 3*cnvtxs+1; + cgraph->adjncy = cgraph->gdata + 4*cnvtxs+1; + cgraph->adjwgt = cgraph->gdata + 4*cnvtxs+1 + graph->nedges; + } + else { + cgraph->gdata = idxmalloc(3*cnvtxs+1 + 2*graph->nedges, "SetUpCoarseGraph: gdata"); + cgraph->xadj = cgraph->gdata; + cgraph->adjwgtsum = cgraph->gdata + cnvtxs+1; + cgraph->cmap = cgraph->gdata + 2*cnvtxs+1; + cgraph->adjncy = cgraph->gdata + 3*cnvtxs+1; + cgraph->adjwgt = cgraph->gdata + 3*cnvtxs+1 + graph->nedges; + } + + cgraph->nvwgt = fmalloc(graph->ncon*cnvtxs, "SetUpCoarseGraph: nvwgt"); + } + + return cgraph; +} + + +/************************************************************************* +* This function re-adjusts the amount of memory that was allocated if +* it will lead to significant savings +**************************************************************************/ +void ReAdjustMemory(GraphType *graph, GraphType *cgraph, int dovsize) +{ + + if (cgraph->nedges > 100000 && graph->nedges < 0.7*graph->nedges) { + idxcopy(cgraph->nedges, cgraph->adjwgt, cgraph->adjncy+cgraph->nedges); + + if (graph->ncon == 1) { + if (dovsize) { + cgraph->gdata = realloc(cgraph->gdata, (5*cgraph->nvtxs+1 + 2*cgraph->nedges)*sizeof(idxtype)); + + /* Do this, in case everything was copied into new space */ + cgraph->xadj = cgraph->gdata; + cgraph->vwgt = cgraph->gdata + cgraph->nvtxs+1; + cgraph->vsize = cgraph->gdata + 2*cgraph->nvtxs+1; + cgraph->adjwgtsum = cgraph->gdata + 3*cgraph->nvtxs+1; + cgraph->cmap = cgraph->gdata + 4*cgraph->nvtxs+1; + cgraph->adjncy = cgraph->gdata + 5*cgraph->nvtxs+1; + cgraph->adjwgt = cgraph->gdata + 5*cgraph->nvtxs+1 + cgraph->nedges; + } + else { + cgraph->gdata = realloc(cgraph->gdata, (4*cgraph->nvtxs+1 + 2*cgraph->nedges)*sizeof(idxtype)); + + /* Do this, in case everything was copied into new space */ + cgraph->xadj = cgraph->gdata; + cgraph->vwgt = cgraph->gdata + cgraph->nvtxs+1; + cgraph->adjwgtsum = cgraph->gdata + 2*cgraph->nvtxs+1; + cgraph->cmap = cgraph->gdata + 3*cgraph->nvtxs+1; + cgraph->adjncy = cgraph->gdata + 4*cgraph->nvtxs+1; + cgraph->adjwgt = cgraph->gdata + 4*cgraph->nvtxs+1 + cgraph->nedges; + } + } + else { + if (dovsize) { + cgraph->gdata = realloc(cgraph->gdata, (4*cgraph->nvtxs+1 + 2*cgraph->nedges)*sizeof(idxtype)); + + /* Do this, in case everything was copied into new space */ + cgraph->xadj = cgraph->gdata; + cgraph->vsize = cgraph->gdata + cgraph->nvtxs+1; + cgraph->adjwgtsum = cgraph->gdata + 2*cgraph->nvtxs+1; + cgraph->cmap = cgraph->gdata + 3*cgraph->nvtxs+1; + cgraph->adjncy = cgraph->gdata + 4*cgraph->nvtxs+1; + cgraph->adjwgt = cgraph->gdata + 4*cgraph->nvtxs+1 + cgraph->nedges; + } + else { + cgraph->gdata = realloc(cgraph->gdata, (3*cgraph->nvtxs+1 + 2*cgraph->nedges)*sizeof(idxtype)); + + /* Do this, in case everything was copied into new space */ + cgraph->xadj = cgraph->gdata; + cgraph->adjwgtsum = cgraph->gdata + cgraph->nvtxs+1; + cgraph->cmap = cgraph->gdata + 2*cgraph->nvtxs+1; + cgraph->adjncy = cgraph->gdata + 3*cgraph->nvtxs+1; + cgraph->adjwgt = cgraph->gdata + 3*cgraph->nvtxs+1 + cgraph->nedges; + } + } + } + +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/checkgraph.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/checkgraph.c new file mode 100644 index 0000000..0134ec1 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/checkgraph.c @@ -0,0 +1,127 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * checkgraph.c + * + * This file contains routines related to I/O + * + * Started 8/28/94 + * George + * + * $Id: checkgraph.c,v 1.1 2003/07/24 18:39:06 karypis Exp $ + * + */ + +#include <metis.h> + + + +/************************************************************************* +* This function checks if a graph is valid +**************************************************************************/ +int CheckGraph(GraphType *graph) +{ + int i, j, k, l; + int nvtxs, ncon, err=0; + int minedge, maxedge, minewgt, maxewgt; + float minvwgt[MAXNCON], maxvwgt[MAXNCON]; + idxtype *xadj, *adjncy, *adjwgt, *htable; + float *nvwgt, ntvwgts[MAXNCON]; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + htable = idxsmalloc(nvtxs, 0, "htable"); + + if (ncon > 1) { + for (j=0; j<ncon; j++) { + minvwgt[j] = maxvwgt[j] = nvwgt[j]; + ntvwgts[j] = 0.0; + } + } + + minedge = maxedge = adjncy[0]; + minewgt = maxewgt = adjwgt[0]; + + for (i=0; i<nvtxs; i++) { + if (ncon > 1) { + for (j=0; j<ncon; j++) { + ntvwgts[j] += nvwgt[i*ncon+j]; + minvwgt[j] = (nvwgt[i*ncon+j] < minvwgt[j]) ? nvwgt[i*ncon+j] : minvwgt[j]; + maxvwgt[j] = (nvwgt[i*ncon+j] > maxvwgt[j]) ? nvwgt[i*ncon+j] : maxvwgt[j]; + } + } + + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + + minedge = (k < minedge) ? k : minedge; + maxedge = (k > maxedge) ? k : maxedge; + minewgt = (adjwgt[j] < minewgt) ? adjwgt[j] : minewgt; + maxewgt = (adjwgt[j] > maxewgt) ? adjwgt[j] : maxewgt; + + if (i == k) { + printf("Vertex %d contains a self-loop (i.e., diagonal entry in the matrix)!\n", i); + err++; + } + else { + for (l=xadj[k]; l<xadj[k+1]; l++) { + if (adjncy[l] == i) { + if (adjwgt != NULL && adjwgt[l] != adjwgt[j]) { + printf("Edges (%d %d) and (%d %d) do not have the same weight! %d %d\n", i,k,k,i, adjwgt[l], adjwgt[j]); + err++; + } + break; + } + } + if (l == xadj[k+1]) { + printf("Missing edge: (%d %d)!\n", k, i); + err++; + } + } + + if (htable[k] == 0) { + htable[k]++; + } + else { + printf("Edge %d from vertex %d is repeated %d times\n", k, i, htable[k]++); + err++; + } + } + + for (j=xadj[i]; j<xadj[i+1]; j++) { + htable[adjncy[j]] = 0; + } + } + + if (ncon > 1) { + for (j=0; j<ncon; j++) { + if (fabs(ntvwgts[j] - 1.0) > 0.0001) { + printf("Normalized vwgts don't sum to one. Weight %d = %.8f.\n", j, ntvwgts[j]); + err++; + } + } + } + +/* + printf("errs: %d, adjncy: [%d %d], adjwgt: [%d %d]\n", + err, minedge, maxedge, minewgt, maxewgt); + if (ncon > 1) { + for (j=0; j<ncon; j++) + printf("[%.5f %.5f] ", minvwgt[j], maxvwgt[j]); + printf("\n"); + } +*/ + + if (err > 0) { + printf("A total of %d errors exist in the input file. Correct them, and run again!\n", err); + } + + GKfree(&htable, LTERM); + return (err == 0 ? 1 : 0); +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/coarsen.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/coarsen.c new file mode 100644 index 0000000..15f06d3 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/coarsen.c @@ -0,0 +1,86 @@ +/* + * coarsen.c + * + * This file contains the driving routines for the coarsening process + * + * Started 7/23/97 + * George + * + * $Id: coarsen.c,v 1.2 2003/07/31 16:23:29 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function takes a graph and creates a sequence of coarser graphs +**************************************************************************/ +GraphType *Coarsen2Way(CtrlType *ctrl, GraphType *graph) +{ + int clevel; + GraphType *cgraph; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->CoarsenTmr)); + + cgraph = graph; + + /* The following is ahack to allow the multiple bisections to go through with correct + coarsening */ + if (ctrl->CType > 20) { + clevel = 1; + ctrl->CType -= 20; + } + else + clevel = 0; + + do { + IFSET(ctrl->dbglvl, DBG_COARSEN, printf("%6d %7d [%d] [%d %d]\n", + cgraph->nvtxs, cgraph->nedges, ctrl->CoarsenTo, ctrl->maxvwgt, + (cgraph->vwgt ? idxsum(cgraph->nvtxs, cgraph->vwgt) : cgraph->nvtxs))); + + if (cgraph->adjwgt) { + switch (ctrl->CType) { + case MATCH_RM: + Match_RM(ctrl, cgraph); + break; + case MATCH_HEM: + if (clevel < 1 || cgraph->nedges == 0) + Match_RM(ctrl, cgraph); + else + Match_HEM(ctrl, cgraph); + break; + case MATCH_SHEM: + if (clevel < 1 || cgraph->nedges == 0) + Match_RM(ctrl, cgraph); + else + Match_SHEM(ctrl, cgraph); + break; + case MATCH_SHEMKWAY: + if (cgraph->nedges == 0) + Match_RM(ctrl, cgraph); + else + Match_SHEM(ctrl, cgraph); + break; + default: + errexit("Unknown CType: %d\n", ctrl->CType); + } + } + else { + Match_RM_NVW(ctrl, cgraph); + } + + cgraph = cgraph->coarser; + clevel++; + + } while (cgraph->nvtxs > ctrl->CoarsenTo && cgraph->nvtxs < COARSEN_FRACTION2*cgraph->finer->nvtxs && cgraph->nedges > cgraph->nvtxs/2); + + IFSET(ctrl->dbglvl, DBG_COARSEN, printf("%6d %7d [%d] [%d %d]\n", + cgraph->nvtxs, cgraph->nedges, ctrl->CoarsenTo, ctrl->maxvwgt, + (cgraph->vwgt ? idxsum(cgraph->nvtxs, cgraph->vwgt) : cgraph->nvtxs))); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->CoarsenTmr)); + + return cgraph; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/compress.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/compress.c new file mode 100644 index 0000000..6b1cf13 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/compress.c @@ -0,0 +1,256 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * compress.c + * + * This file contains code for compressing nodes with identical adjacency + * structure and for prunning dense columns + * + * Started 9/17/97 + * George + * + * $Id: compress.c,v 1.1 2003/07/16 15:55:01 karypis Exp $ + */ + +#include <metis.h> + +/************************************************************************* +* This function compresses a graph by merging identical vertices +* The compression should lead to at least 10% reduction. +**************************************************************************/ +void CompressGraph(CtrlType *ctrl, GraphType *graph, int nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *cptr, idxtype *cind) +{ + int i, ii, iii, j, jj, k, l, cnvtxs, cnedges; + idxtype *cxadj, *cadjncy, *cvwgt, *mark, *map; + KeyValueType *keys; + + mark = idxsmalloc(nvtxs, -1, "CompressGraph: mark"); + map = idxsmalloc(nvtxs, -1, "CompressGraph: map"); + keys = (KeyValueType *)GKmalloc(nvtxs*sizeof(KeyValueType), "CompressGraph: keys"); + + /* Compute a key for each adjacency list */ + for (i=0; i<nvtxs; i++) { + k = 0; + for (j=xadj[i]; j<xadj[i+1]; j++) + k += adjncy[j]; + keys[i].key = k+i; /* Add the diagonal entry as well */ + keys[i].val = i; + } + + ikeysort(nvtxs, keys); + + l = cptr[0] = 0; + for (cnvtxs=i=0; i<nvtxs; i++) { + ii = keys[i].val; + if (map[ii] == -1) { + mark[ii] = i; /* Add the diagonal entry */ + for (j=xadj[ii]; j<xadj[ii+1]; j++) + mark[adjncy[j]] = i; + + cind[l++] = ii; + map[ii] = cnvtxs; + + for (j=i+1; j<nvtxs; j++) { + iii = keys[j].val; + + if (keys[i].key != keys[j].key || xadj[ii+1]-xadj[ii] != xadj[iii+1]-xadj[iii]) + break; /* Break if keys or degrees are different */ + + if (map[iii] == -1) { /* Do a comparison if iii has not been mapped */ + for (jj=xadj[iii]; jj<xadj[iii+1]; jj++) { + if (mark[adjncy[jj]] != i) + break; + } + + if (jj == xadj[iii+1]) { /* Identical adjacency structure */ + map[iii] = cnvtxs; + cind[l++] = iii; + } + } + } + + cptr[++cnvtxs] = l; + } + } + + /* printf("Original: %6d, Compressed: %6d\n", nvtxs, cnvtxs); */ + + + InitGraph(graph); + + if (cnvtxs >= COMPRESSION_FRACTION*nvtxs) { + graph->nvtxs = nvtxs; + graph->nedges = xadj[nvtxs]; + graph->ncon = 1; + graph->xadj = xadj; + graph->adjncy = adjncy; + + graph->gdata = idxmalloc(3*nvtxs+graph->nedges, "CompressGraph: gdata"); + graph->vwgt = graph->gdata; + graph->adjwgtsum = graph->gdata+nvtxs; + graph->cmap = graph->gdata+2*nvtxs; + graph->adjwgt = graph->gdata+3*nvtxs; + + idxset(nvtxs, 1, graph->vwgt); + idxset(graph->nedges, 1, graph->adjwgt); + for (i=0; i<nvtxs; i++) + graph->adjwgtsum[i] = xadj[i+1]-xadj[i]; + + graph->label = idxmalloc(nvtxs, "CompressGraph: label"); + for (i=0; i<nvtxs; i++) + graph->label[i] = i; + } + else { /* Ok, form the compressed graph */ + cnedges = 0; + for (i=0; i<cnvtxs; i++) { + ii = cind[cptr[i]]; + cnedges += xadj[ii+1]-xadj[ii]; + } + + /* Allocate memory for the compressed graph*/ + graph->gdata = idxmalloc(4*cnvtxs+1 + 2*cnedges, "CompressGraph: gdata"); + cxadj = graph->xadj = graph->gdata; + cvwgt = graph->vwgt = graph->gdata + cnvtxs+1; + graph->adjwgtsum = graph->gdata + 2*cnvtxs+1; + graph->cmap = graph->gdata + 3*cnvtxs+1; + cadjncy = graph->adjncy = graph->gdata + 4*cnvtxs+1; + graph->adjwgt = graph->gdata + 4*cnvtxs+1 + cnedges; + + /* Now go and compress the graph */ + idxset(nvtxs, -1, mark); + l = cxadj[0] = 0; + for (i=0; i<cnvtxs; i++) { + cvwgt[i] = cptr[i+1]-cptr[i]; + mark[i] = i; /* Remove any dioganal entries in the compressed graph */ + for (j=cptr[i]; j<cptr[i+1]; j++) { + ii = cind[j]; + for (jj=xadj[ii]; jj<xadj[ii+1]; jj++) { + k = map[adjncy[jj]]; + if (mark[k] != i) + cadjncy[l++] = k; + mark[k] = i; + } + } + cxadj[i+1] = l; + } + + graph->nvtxs = cnvtxs; + graph->nedges = l; + graph->ncon = 1; + + idxset(graph->nedges, 1, graph->adjwgt); + for (i=0; i<cnvtxs; i++) + graph->adjwgtsum[i] = cxadj[i+1]-cxadj[i]; + + graph->label = idxmalloc(cnvtxs, "CompressGraph: label"); + for (i=0; i<cnvtxs; i++) + graph->label[i] = i; + + } + + GKfree(&keys, &map, &mark, LTERM); +} + + + +/************************************************************************* +* This function prunes all the vertices in a graph with degree greater +* than factor*average +**************************************************************************/ +void PruneGraph(CtrlType *ctrl, GraphType *graph, int nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *iperm, float factor) +{ + int i, j, k, l, nlarge, pnvtxs, pnedges; + idxtype *pxadj, *padjncy, *padjwgt, *pvwgt; + idxtype *perm; + + perm = idxmalloc(nvtxs, "PruneGraph: perm"); + + factor = factor*xadj[nvtxs]/nvtxs; + + pnvtxs = pnedges = nlarge = 0; + for (i=0; i<nvtxs; i++) { + if (xadj[i+1]-xadj[i] < factor) { + perm[i] = pnvtxs; + iperm[pnvtxs++] = i; + pnedges += xadj[i+1]-xadj[i]; + } + else { + perm[i] = nvtxs - ++nlarge; + iperm[nvtxs-nlarge] = i; + } + } + + /* printf("Pruned %d vertices\n", nlarge); */ + + InitGraph(graph); + + if (nlarge == 0) { /* No prunning */ + graph->nvtxs = nvtxs; + graph->nedges = xadj[nvtxs]; + graph->ncon = 1; + graph->xadj = xadj; + graph->adjncy = adjncy; + + graph->gdata = idxmalloc(3*nvtxs+graph->nedges, "CompressGraph: gdata"); + graph->vwgt = graph->gdata; + graph->adjwgtsum = graph->gdata+nvtxs; + graph->cmap = graph->gdata+2*nvtxs; + graph->adjwgt = graph->gdata+3*nvtxs; + + idxset(nvtxs, 1, graph->vwgt); + idxset(graph->nedges, 1, graph->adjwgt); + for (i=0; i<nvtxs; i++) + graph->adjwgtsum[i] = xadj[i+1]-xadj[i]; + + graph->label = idxmalloc(nvtxs, "CompressGraph: label"); + for (i=0; i<nvtxs; i++) + graph->label[i] = i; + } + else { /* Prune the graph */ + /* Allocate memory for the compressed graph*/ + graph->gdata = idxmalloc(4*pnvtxs+1 + 2*pnedges, "PruneGraph: gdata"); + pxadj = graph->xadj = graph->gdata; + graph->vwgt = graph->gdata + pnvtxs+1; + graph->adjwgtsum = graph->gdata + 2*pnvtxs+1; + graph->cmap = graph->gdata + 3*pnvtxs+1; + padjncy = graph->adjncy = graph->gdata + 4*pnvtxs+1; + graph->adjwgt = graph->gdata + 4*pnvtxs+1 + pnedges; + + pxadj[0] = pnedges = l = 0; + for (i=0; i<nvtxs; i++) { + if (xadj[i+1]-xadj[i] < factor) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = perm[adjncy[j]]; + if (k < pnvtxs) + padjncy[pnedges++] = k; + } + pxadj[++l] = pnedges; + } + } + + graph->nvtxs = pnvtxs; + graph->nedges = pnedges; + graph->ncon = 1; + + idxset(pnvtxs, 1, graph->vwgt); + idxset(pnedges, 1, graph->adjwgt); + for (i=0; i<pnvtxs; i++) + graph->adjwgtsum[i] = pxadj[i+1]-pxadj[i]; + + graph->label = idxmalloc(pnvtxs, "CompressGraph: label"); + for (i=0; i<pnvtxs; i++) + graph->label[i] = i; + } + + free(perm); + +} + + + + + + + + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/debug.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/debug.c new file mode 100644 index 0000000..b71fe2f --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/debug.c @@ -0,0 +1,239 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * debug.c + * + * This file contains code that performs self debuging + * + * Started 7/24/97 + * George + * + * $Id: debug.c,v 1.1 2003/07/16 15:55:01 karypis Exp $ + * + */ + +#include <metis.h> + +/************************************************************************* +* This function computes the cut given the graph and a where vector +**************************************************************************/ +int ComputeCut(GraphType *graph, idxtype *where) +{ + int i, j, cut; + + if (graph->adjwgt == NULL) { + for (cut=0, i=0; i<graph->nvtxs; i++) { + for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++) + if (where[i] != where[graph->adjncy[j]]) + cut++; + } + } + else { + for (cut=0, i=0; i<graph->nvtxs; i++) { + for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++) + if (where[i] != where[graph->adjncy[j]]) + cut += graph->adjwgt[j]; + } + } + + return cut/2; +} + + +/************************************************************************* +* This function checks whether or not the boundary information is correct +**************************************************************************/ +int CheckBnd(GraphType *graph) +{ + int i, j, nvtxs, nbnd; + idxtype *xadj, *adjncy, *where, *bndptr, *bndind; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + where = graph->where; + bndptr = graph->bndptr; + bndind = graph->bndind; + + for (nbnd=0, i=0; i<nvtxs; i++) { + if (xadj[i+1]-xadj[i] == 0) + nbnd++; /* Islands are considered to be boundary vertices */ + + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (where[i] != where[adjncy[j]]) { + nbnd++; + ASSERT(bndptr[i] != -1); + ASSERT(bndind[bndptr[i]] == i); + break; + } + } + } + + ASSERTP(nbnd == graph->nbnd, ("%d %d\n", nbnd, graph->nbnd)); + + return 1; +} + + + +/************************************************************************* +* This function checks whether or not the boundary information is correct +**************************************************************************/ +int CheckBnd2(GraphType *graph) +{ + int i, j, nvtxs, nbnd, id, ed; + idxtype *xadj, *adjncy, *where, *bndptr, *bndind; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + where = graph->where; + bndptr = graph->bndptr; + bndind = graph->bndind; + + for (nbnd=0, i=0; i<nvtxs; i++) { + id = ed = 0; + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (where[i] != where[adjncy[j]]) + ed += graph->adjwgt[j]; + else + id += graph->adjwgt[j]; + } + if (ed - id >= 0 && xadj[i] < xadj[i+1]) { + nbnd++; + ASSERTP(bndptr[i] != -1, ("%d %d %d\n", i, id, ed)); + ASSERT(bndind[bndptr[i]] == i); + } + } + + ASSERTP(nbnd == graph->nbnd, ("%d %d\n", nbnd, graph->nbnd)); + + return 1; +} + +/************************************************************************* +* This function checks whether or not the boundary information is correct +**************************************************************************/ +int CheckNodeBnd(GraphType *graph, int onbnd) +{ + int i, j, nvtxs, nbnd; + idxtype *xadj, *adjncy, *where, *bndptr, *bndind; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + where = graph->where; + bndptr = graph->bndptr; + bndind = graph->bndind; + + for (nbnd=0, i=0; i<nvtxs; i++) { + if (where[i] == 2) + nbnd++; + } + + ASSERTP(nbnd == onbnd, ("%d %d\n", nbnd, onbnd)); + + for (i=0; i<nvtxs; i++) { + if (where[i] != 2) { + ASSERTP(bndptr[i] == -1, ("%d %d\n", i, bndptr[i])); + } + else { + ASSERTP(bndptr[i] != -1, ("%d %d\n", i, bndptr[i])); + } + } + + return 1; +} + + + +/************************************************************************* +* This function checks whether or not the rinfo of a vertex is consistent +**************************************************************************/ +int CheckRInfo(RInfoType *rinfo) +{ + int i, j; + + for (i=0; i<rinfo->ndegrees; i++) { + for (j=i+1; j<rinfo->ndegrees; j++) + ASSERTP(rinfo->edegrees[i].pid != rinfo->edegrees[j].pid, ("%d %d %d %d\n", i, j, rinfo->edegrees[i].pid, rinfo->edegrees[j].pid)); + } + + return 1; +} + + + +/************************************************************************* +* This function checks the correctness of the NodeFM data structures +**************************************************************************/ +int CheckNodePartitionParams(GraphType *graph) +{ + int i, j, k, l, nvtxs, me, other; + idxtype *xadj, *adjncy, *adjwgt, *vwgt, *where; + idxtype edegrees[2], pwgts[3]; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + where = graph->where; + + /*------------------------------------------------------------ + / Compute now the separator external degrees + /------------------------------------------------------------*/ + pwgts[0] = pwgts[1] = pwgts[2] = 0; + for (i=0; i<nvtxs; i++) { + me = where[i]; + pwgts[me] += vwgt[i]; + + if (me == 2) { /* If it is on the separator do some computations */ + edegrees[0] = edegrees[1] = 0; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + other = where[adjncy[j]]; + if (other != 2) + edegrees[other] += vwgt[adjncy[j]]; + } + if (edegrees[0] != graph->nrinfo[i].edegrees[0] || edegrees[1] != graph->nrinfo[i].edegrees[1]) { + printf("Something wrong with edegrees: %d %d %d %d %d\n", i, edegrees[0], edegrees[1], graph->nrinfo[i].edegrees[0], graph->nrinfo[i].edegrees[1]); + return 0; + } + } + } + + if (pwgts[0] != graph->pwgts[0] || pwgts[1] != graph->pwgts[1] || pwgts[2] != graph->pwgts[2]) + printf("Something wrong with part-weights: %d %d %d %d %d %d\n", pwgts[0], pwgts[1], pwgts[2], graph->pwgts[0], graph->pwgts[1], graph->pwgts[2]); + + return 1; +} + + +/************************************************************************* +* This function checks if the separator is indeed a separator +**************************************************************************/ +int IsSeparable(GraphType *graph) +{ + int i, j, nvtxs, other; + idxtype *xadj, *adjncy, *where; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + where = graph->where; + + for (i=0; i<nvtxs; i++) { + if (where[i] == 2) + continue; + other = (where[i]+1)%2; + for (j=xadj[i]; j<xadj[i+1]; j++) { + ASSERTP(where[adjncy[j]] != other, ("%d %d %d %d %d %d\n", i, where[i], adjncy[j], where[adjncy[j]], xadj[i+1]-xadj[i], xadj[adjncy[j]+1]-xadj[adjncy[j]])); + } + } + + return 1; +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/defs.h b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/defs.h new file mode 100644 index 0000000..8df42c7 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/defs.h @@ -0,0 +1,161 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * defs.h + * + * This file contains constant definitions + * + * Started 8/27/94 + * George + * + * $Id: defs.h,v 1.1 2003/07/16 15:55:01 karypis Exp $ + * + */ + +#define METISTITLE " METIS 4.0 Copyright 1998, Regents of the University of Minnesota\n\n" +#define MAXLINE 1280000 + +#define LTERM (void **) 0 /* List terminator for GKfree() */ + +#define MAXNCON 16 /* The maximum number of constrains */ +#define MAXNOBJ 16 /* The maximum number of objectives */ + +#define PLUS_GAINSPAN 500 /* Parameters for FM buckets */ +#define NEG_GAINSPAN 500 + +#define HTLENGTH ((1<<11)-1) + +/* Meaning of various options[] parameters */ +#define OPTION_PTYPE 0 +#define OPTION_CTYPE 1 +#define OPTION_ITYPE 2 +#define OPTION_RTYPE 3 +#define OPTION_DBGLVL 4 +#define OPTION_OFLAGS 5 +#define OPTION_PFACTOR 6 +#define OPTION_NSEPS 7 + +#define OFLAG_COMPRESS 1 /* Try to compress the graph */ +#define OFLAG_CCMP 2 /* Find and order connected components */ + + +/* Default options for PMETIS */ +#define PMETIS_CTYPE MATCH_SHEM +#define PMETIS_ITYPE IPART_GGPKL +#define PMETIS_RTYPE RTYPE_FM +#define PMETIS_DBGLVL 0 + +/* Default options for KMETIS */ +#define KMETIS_CTYPE MATCH_SHEM +#define KMETIS_ITYPE IPART_PMETIS +#define KMETIS_RTYPE RTYPE_KWAYRANDOM_MCONN +#define KMETIS_DBGLVL 0 + +/* Default options for OEMETIS */ +#define OEMETIS_CTYPE MATCH_SHEM +#define OEMETIS_ITYPE IPART_GGPKL +#define OEMETIS_RTYPE RTYPE_FM +#define OEMETIS_DBGLVL 0 + +/* Default options for ONMETIS */ +#define ONMETIS_CTYPE MATCH_SHEM +#define ONMETIS_ITYPE IPART_GGPKL +#define ONMETIS_RTYPE RTYPE_SEP1SIDED +#define ONMETIS_DBGLVL 0 +#define ONMETIS_OFLAGS OFLAG_COMPRESS +#define ONMETIS_PFACTOR -1 +#define ONMETIS_NSEPS 1 + +/* Default options for McPMETIS */ +#define McPMETIS_CTYPE MATCH_SHEBM_ONENORM +#define McPMETIS_ITYPE IPART_RANDOM +#define McPMETIS_RTYPE RTYPE_FM +#define McPMETIS_DBGLVL 0 + +/* Default options for McKMETIS */ +#define McKMETIS_CTYPE MATCH_SHEBM_ONENORM +#define McKMETIS_ITYPE IPART_McHPMETIS +#define McKMETIS_RTYPE RTYPE_KWAYRANDOM +#define McKMETIS_DBGLVL 0 + +/* Default options for KVMETIS */ +#define KVMETIS_CTYPE MATCH_SHEM +#define KVMETIS_ITYPE IPART_PMETIS +#define KVMETIS_RTYPE RTYPE_KWAYRANDOM +#define KVMETIS_DBGLVL 0 + + +/* Operations supported by stand-alone code */ +#define OP_PMETIS 1 +#define OP_KMETIS 2 +#define OP_OEMETIS 3 +#define OP_ONMETIS 4 +#define OP_ONWMETIS 5 +#define OP_KVMETIS 6 + + +/* Matching Schemes */ +#define MATCH_RM 1 +#define MATCH_HEM 2 +#define MATCH_SHEM 3 +#define MATCH_SHEMKWAY 4 +#define MATCH_SHEBM_ONENORM 5 +#define MATCH_SHEBM_INFNORM 6 +#define MATCH_SBHEM_ONENORM 7 +#define MATCH_SBHEM_INFNORM 8 + +/* Initial partitioning schemes for PMETIS and ONMETIS */ +#define IPART_GGPKL 1 +#define IPART_GGPKLNODE 2 +#define IPART_RANDOM 2 + +/* Refinement schemes for PMETIS */ +#define RTYPE_FM 1 + +/* Initial partitioning schemes for KMETIS */ +#define IPART_PMETIS 1 + +/* Refinement schemes for KMETIS */ +#define RTYPE_KWAYRANDOM 1 +#define RTYPE_KWAYGREEDY 2 +#define RTYPE_KWAYRANDOM_MCONN 3 + +/* Refinement schemes for ONMETIS */ +#define RTYPE_SEP2SIDED 1 +#define RTYPE_SEP1SIDED 2 + +/* Initial Partitioning Schemes for McKMETIS */ +#define IPART_McPMETIS 1 /* Simple McPMETIS */ +#define IPART_McHPMETIS 2 /* horizontally relaxed McPMETIS */ + +#define UNMATCHED -1 + +#define HTABLE_EMPTY -1 + +#define NGR_PASSES 4 /* Number of greedy refinement passes */ +#define NLGR_PASSES 5 /* Number of GR refinement during IPartition */ + +#define LARGENIPARTS 8 /* Number of random initial partitions */ +#define SMALLNIPARTS 3 /* Number of random initial partitions */ + +#define COARSEN_FRACTION 0.75 /* Node reduction between succesive coarsening levels */ +#define COARSEN_FRACTION2 0.90 /* Node reduction between succesive coarsening levels */ +#define UNBALANCE_FRACTION 1.05 + +#define COMPRESSION_FRACTION 0.85 + +#define ORDER_UNBALANCE_FRACTION 1.10 + +#define MMDSWITCH 200 + +#define HORIZONTAL_IMBALANCE 1.05 + +/* Debug Levels */ +#define DBG_TIME 1 /* Perform timing analysis */ +#define DBG_OUTPUT 2 +#define DBG_COARSEN 4 /* Show the coarsening progress */ +#define DBG_REFINE 8 /* Show info on communication during folding */ +#define DBG_IPART 16 /* Show info on initial partition */ +#define DBG_MOVEINFO 32 /* Show info on communication during folding */ +#define DBG_KWAYPINFO 64 /* Show info on communication during folding */ +#define DBG_SEPINFO 128 /* Show info on communication during folding */ diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/estmem.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/estmem.c new file mode 100644 index 0000000..82b9ac9 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/estmem.c @@ -0,0 +1,157 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * estmem.c + * + * This file contains code for estimating the amount of memory required by + * the various routines in METIS + * + * Started 11/4/97 + * George + * + * $Id: estmem.c,v 1.1 2003/07/16 15:55:02 karypis Exp $ + * + */ + +#include <metis.h> + +/************************************************************************* +* This function computes how much memory will be required by the various +* routines in METIS +**************************************************************************/ +void METIS_EstimateMemory(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *optype, int *nbytes) +{ + int i, j, k, nedges, nlevels; + float vfraction, efraction, vmult, emult; + int coresize, gdata, rdata; + + if (*numflag == 1) + Change2CNumbering(*nvtxs, xadj, adjncy); + + nedges = xadj[*nvtxs]; + + InitRandom(-1); + EstimateCFraction(*nvtxs, xadj, adjncy, &vfraction, &efraction); + + /* Estimate the amount of memory for coresize */ + if (*optype == 2) + coresize = nedges; + else + coresize = 0; + coresize += nedges + 11*(*nvtxs) + 4*1024 + 2*(NEG_GAINSPAN+PLUS_GAINSPAN+1)*(sizeof(ListNodeType *)/sizeof(idxtype)); + coresize += 2*(*nvtxs); /* add some more fore other vectors */ + + gdata = nedges; /* Assume that the user does not pass weights */ + + nlevels = (int)(log(100.0/(*nvtxs))/log(vfraction) + .5); + vmult = 0.5 + (1.0 - pow(vfraction, nlevels))/(1.0 - vfraction); + emult = 1.0 + (1.0 - pow(efraction, nlevels+1))/(1.0 - efraction); + + gdata += vmult*4*(*nvtxs) + emult*2*nedges; + if ((vmult-1.0)*4*(*nvtxs) + (emult-1.0)*2*nedges < 5*(*nvtxs)) + rdata = 0; + else + rdata = 5*(*nvtxs); + + *nbytes = sizeof(idxtype)*(coresize+gdata+rdata+(*nvtxs)); + + if (*numflag == 1) + Change2FNumbering2(*nvtxs, xadj, adjncy); +} + + +/************************************************************************* +* This function finds a matching using the HEM heuristic +**************************************************************************/ +void EstimateCFraction(int nvtxs, idxtype *xadj, idxtype *adjncy, float *vfraction, float *efraction) +{ + int i, ii, j, cnvtxs, cnedges, maxidx; + idxtype *match, *cmap, *perm; + + cmap = idxmalloc(nvtxs, "cmap"); + match = idxsmalloc(nvtxs, UNMATCHED, "match"); + perm = idxmalloc(nvtxs, "perm"); + RandomPermute(nvtxs, perm, 1); + + cnvtxs = 0; + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + + if (match[i] == UNMATCHED) { /* Unmatched */ + maxidx = i; + + /* Find a random matching, subject to maxvwgt constraints */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (match[adjncy[j]] == UNMATCHED) { + maxidx = adjncy[j]; + break; + } + } + + cmap[i] = cmap[maxidx] = cnvtxs++; + match[i] = maxidx; + match[maxidx] = i; + } + } + + cnedges = ComputeCoarseGraphSize(nvtxs, xadj, adjncy, cnvtxs, cmap, match, perm); + + *vfraction = (1.0*cnvtxs)/(1.0*nvtxs); + *efraction = (1.0*cnedges)/(1.0*xadj[nvtxs]); + + GKfree(&cmap, &match, &perm, LTERM); +} + + + + +/************************************************************************* +* This function computes the size of the coarse graph +**************************************************************************/ +int ComputeCoarseGraphSize(int nvtxs, idxtype *xadj, idxtype *adjncy, int cnvtxs, idxtype *cmap, idxtype *match, idxtype *perm) +{ + int i, j, k, istart, iend, nedges, cnedges, v, u; + idxtype *htable; + + htable = idxsmalloc(cnvtxs, -1, "htable"); + + cnvtxs = cnedges = 0; + for (i=0; i<nvtxs; i++) { + v = perm[i]; + if (cmap[v] != cnvtxs) + continue; + + htable[cnvtxs] = cnvtxs; + + u = match[v]; + + istart = xadj[v]; + iend = xadj[v+1]; + for (j=istart; j<iend; j++) { + k = cmap[adjncy[j]]; + if (htable[k] != cnvtxs) { + htable[k] = cnvtxs; + cnedges++; + } + } + + if (v != u) { + istart = xadj[u]; + iend = xadj[u+1]; + for (j=istart; j<iend; j++) { + k = cmap[adjncy[j]]; + if (htable[k] != cnvtxs) { + htable[k] = cnvtxs; + cnedges++; + } + } + } + cnvtxs++; + } + + GKfree(&htable, LTERM); + + return cnedges; +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/fm.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/fm.c new file mode 100644 index 0000000..2fc08d2 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/fm.c @@ -0,0 +1,194 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * fm.c + * + * This file contains code that implements the edge-based FM refinement + * + * Started 7/23/97 + * George + * + * $Id: fm.c,v 1.1 2003/07/16 15:55:02 karypis Exp $ + */ + +#include <metis.h> + + +/************************************************************************* +* This function performs an edge-based FM refinement +**************************************************************************/ +void FM_2WayEdgeRefine(CtrlType *ctrl, GraphType *graph, int *tpwgts, int npasses) +{ + int i, ii, j, k, kwgt, nvtxs, nbnd, nswaps, from, to, pass, me, limit, tmp; + idxtype *xadj, *vwgt, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind, *pwgts; + idxtype *moved, *swaps, *perm; + PQueueType parts[2]; + int higain, oldgain, mincut, mindiff, origdiff, initcut, newcut, mincutorder, avgvwgt; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + id = graph->id; + ed = graph->ed; + pwgts = graph->pwgts; + bndptr = graph->bndptr; + bndind = graph->bndind; + + moved = idxwspacemalloc(ctrl, nvtxs); + swaps = idxwspacemalloc(ctrl, nvtxs); + perm = idxwspacemalloc(ctrl, nvtxs); + + limit = amin(amax(0.01*nvtxs, 15), 100); + avgvwgt = amin((pwgts[0]+pwgts[1])/20, 2*(pwgts[0]+pwgts[1])/nvtxs); + + tmp = graph->adjwgtsum[idxamax(nvtxs, graph->adjwgtsum)]; + PQueueInit(ctrl, &parts[0], nvtxs, tmp); + PQueueInit(ctrl, &parts[1], nvtxs, tmp); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("Partitions: [%6d %6d] T[%6d %6d], Nv-Nb[%6d %6d]. ICut: %6d\n", + pwgts[0], pwgts[1], tpwgts[0], tpwgts[1], graph->nvtxs, graph->nbnd, graph->mincut)); + + origdiff = abs(tpwgts[0]-pwgts[0]); + idxset(nvtxs, -1, moved); + for (pass=0; pass<npasses; pass++) { /* Do a number of passes */ + PQueueReset(&parts[0]); + PQueueReset(&parts[1]); + + mincutorder = -1; + newcut = mincut = initcut = graph->mincut; + mindiff = abs(tpwgts[0]-pwgts[0]); + + ASSERT(ComputeCut(graph, where) == graph->mincut); + ASSERT(CheckBnd(graph)); + + /* Insert boundary nodes in the priority queues */ + nbnd = graph->nbnd; + RandomPermute(nbnd, perm, 1); + for (ii=0; ii<nbnd; ii++) { + i = perm[ii]; + ASSERT(ed[bndind[i]] > 0 || id[bndind[i]] == 0); + ASSERT(bndptr[bndind[i]] != -1); + PQueueInsert(&parts[where[bndind[i]]], bndind[i], ed[bndind[i]]-id[bndind[i]]); + } + + for (nswaps=0; nswaps<nvtxs; nswaps++) { + from = (tpwgts[0]-pwgts[0] < tpwgts[1]-pwgts[1] ? 0 : 1); + to = (from+1)%2; + + if ((higain = PQueueGetMax(&parts[from])) == -1) + break; + ASSERT(bndptr[higain] != -1); + + newcut -= (ed[higain]-id[higain]); + INC_DEC(pwgts[to], pwgts[from], vwgt[higain]); + + if ((newcut < mincut && abs(tpwgts[0]-pwgts[0]) <= origdiff+avgvwgt) || + (newcut == mincut && abs(tpwgts[0]-pwgts[0]) < mindiff)) { + mincut = newcut; + mindiff = abs(tpwgts[0]-pwgts[0]); + mincutorder = nswaps; + } + else if (nswaps-mincutorder > limit) { /* We hit the limit, undo last move */ + newcut += (ed[higain]-id[higain]); + INC_DEC(pwgts[from], pwgts[to], vwgt[higain]); + break; + } + + where[higain] = to; + moved[higain] = nswaps; + swaps[nswaps] = higain; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, + printf("Moved %6d from %d. [%3d %3d] %5d [%4d %4d]\n", higain, from, ed[higain]-id[higain], vwgt[higain], newcut, pwgts[0], pwgts[1])); + + /************************************************************** + * Update the id[i]/ed[i] values of the affected nodes + ***************************************************************/ + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + oldgain = ed[k]-id[k]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + /* Update its boundary information and queue position */ + if (bndptr[k] != -1) { /* If k was a boundary vertex */ + if (ed[k] == 0) { /* Not a boundary vertex any more */ + BNDDelete(nbnd, bndind, bndptr, k); + if (moved[k] == -1) /* Remove it if in the queues */ + PQueueDelete(&parts[where[k]], k, oldgain); + } + else { /* If it has not been moved, update its position in the queue */ + if (moved[k] == -1) + PQueueUpdate(&parts[where[k]], k, oldgain, ed[k]-id[k]); + } + } + else { + if (ed[k] > 0) { /* It will now become a boundary vertex */ + BNDInsert(nbnd, bndind, bndptr, k); + if (moved[k] == -1) + PQueueInsert(&parts[where[k]], k, ed[k]-id[k]); + } + } + } + + } + + + /**************************************************************** + * Roll back computations + *****************************************************************/ + for (i=0; i<nswaps; i++) + moved[swaps[i]] = -1; /* reset moved array */ + for (nswaps--; nswaps>mincutorder; nswaps--) { + higain = swaps[nswaps]; + + to = where[higain] = (where[higain]+1)%2; + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + else if (ed[higain] > 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + INC_DEC(pwgts[to], pwgts[(to+1)%2], vwgt[higain]); + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + if (bndptr[k] != -1 && ed[k] == 0) + BNDDelete(nbnd, bndind, bndptr, k); + if (bndptr[k] == -1 && ed[k] > 0) + BNDInsert(nbnd, bndind, bndptr, k); + } + } + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\tMinimum cut: %6d at %5d, PWGTS: [%6d %6d], NBND: %6d\n", mincut, mincutorder, pwgts[0], pwgts[1], nbnd)); + + graph->mincut = mincut; + graph->nbnd = nbnd; + + if (mincutorder == -1 || mincut == initcut) + break; + } + + PQueueFree(ctrl, &parts[0]); + PQueueFree(ctrl, &parts[1]); + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/fortran.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/fortran.c new file mode 100644 index 0000000..46ebefd --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/fortran.c @@ -0,0 +1,141 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * fortran.c + * + * This file contains code for the fortran to C interface + * + * Started 8/19/97 + * George + * + * $Id: fortran.c,v 1.1 2003/07/16 15:55:02 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function changes the numbering to start from 0 instead of 1 +**************************************************************************/ +void Change2CNumbering(int nvtxs, idxtype *xadj, idxtype *adjncy) +{ + int i, nedges; + + for (i=0; i<=nvtxs; i++) + xadj[i]--; + + nedges = xadj[nvtxs]; + for (i=0; i<nedges; i++) + adjncy[i]--; +} + +/************************************************************************* +* This function changes the numbering to start from 1 instead of 0 +**************************************************************************/ +void Change2FNumbering(int nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vector) +{ + int i, nedges; + + for (i=0; i<nvtxs; i++) + vector[i]++; + + nedges = xadj[nvtxs]; + for (i=0; i<nedges; i++) + adjncy[i]++; + + for (i=0; i<=nvtxs; i++) + xadj[i]++; +} + +/************************************************************************* +* This function changes the numbering to start from 1 instead of 0 +**************************************************************************/ +void Change2FNumbering2(int nvtxs, idxtype *xadj, idxtype *adjncy) +{ + int i, nedges; + + nedges = xadj[nvtxs]; + for (i=0; i<nedges; i++) + adjncy[i]++; + + for (i=0; i<=nvtxs; i++) + xadj[i]++; +} + + + +/************************************************************************* +* This function changes the numbering to start from 1 instead of 0 +**************************************************************************/ +void Change2FNumberingOrder(int nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *v1, idxtype *v2) +{ + int i, nedges; + + for (i=0; i<nvtxs; i++) { + v1[i]++; + v2[i]++; + } + + nedges = xadj[nvtxs]; + for (i=0; i<nedges; i++) + adjncy[i]++; + + for (i=0; i<=nvtxs; i++) + xadj[i]++; + +} + + + +/************************************************************************* +* This function changes the numbering to start from 0 instead of 1 +**************************************************************************/ +void ChangeMesh2CNumbering(int n, idxtype *mesh) +{ + int i; + + for (i=0; i<n; i++) + mesh[i]--; + +} + + +/************************************************************************* +* This function changes the numbering to start from 1 instead of 0 +**************************************************************************/ +void ChangeMesh2FNumbering(int n, idxtype *mesh, int nvtxs, idxtype *xadj, idxtype *adjncy) +{ + int i, nedges; + + for (i=0; i<n; i++) + mesh[i]++; + + nedges = xadj[nvtxs]; + for (i=0; i<nedges; i++) + adjncy[i]++; + + for (i=0; i<=nvtxs; i++) + xadj[i]++; + +} + + +/************************************************************************* +* This function changes the numbering to start from 1 instead of 0 +**************************************************************************/ +void ChangeMesh2FNumbering2(int n, idxtype *mesh, int ne, int nn, idxtype *epart, idxtype *npart) +{ + int i, nedges; + + for (i=0; i<n; i++) + mesh[i]++; + + for (i=0; i<ne; i++) + epart[i]++; + + for (i=0; i<nn; i++) + npart[i]++; + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/frename.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/frename.c new file mode 100644 index 0000000..5cde8b6 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/frename.c @@ -0,0 +1,312 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * frename.c + * + * This file contains some renaming routines to deal with different Fortran compilers + * + * Started 9/15/97 + * George + * + * $Id: frename.c,v 1.1 2003/07/16 15:55:03 karypis Exp $ + * + */ + +#include <metis.h> + + +void METIS_PARTGRAPHRECURSIVE(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, idxtype *part) +{ + METIS_PartGraphRecursive(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, options, edgecut, part); +} +void metis_partgraphrecursive(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, idxtype *part) +{ + METIS_PartGraphRecursive(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, options, edgecut, part); +} +void metis_partgraphrecursive_(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, idxtype *part) +{ + METIS_PartGraphRecursive(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, options, edgecut, part); +} +void metis_partgraphrecursive__(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, idxtype *part) +{ + METIS_PartGraphRecursive(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, options, edgecut, part); +} + + +void METIS_WPARTGRAPHRECURSIVE(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, float *tpwgts, int *options, int *edgecut, idxtype *part) +{ + METIS_WPartGraphRecursive(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, tpwgts, options, edgecut, part); +} +void metis_wpartgraphrecursive(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, float *tpwgts, int *options, int *edgecut, idxtype *part) +{ + METIS_WPartGraphRecursive(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, tpwgts, options, edgecut, part); +} +void metis_wpartgraphrecursive_(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, float *tpwgts, int *options, int *edgecut, idxtype *part) +{ + METIS_WPartGraphRecursive(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, tpwgts, options, edgecut, part); +} +void metis_wpartgraphrecursive__(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, float *tpwgts, int *options, int *edgecut, idxtype *part) +{ + METIS_WPartGraphRecursive(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, tpwgts, options, edgecut, part); +} + + + +void METIS_PARTGRAPHKWAY(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, idxtype *part) +{ + METIS_PartGraphKway(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, options, edgecut, part); +} +void metis_partgraphkway(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, idxtype *part) +{ + METIS_PartGraphKway(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, options, edgecut, part); +} +void metis_partgraphkway_(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, idxtype *part) +{ + METIS_PartGraphKway(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, options, edgecut, part); +} +void metis_partgraphkway__(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, idxtype *part) +{ + METIS_PartGraphKway(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, options, edgecut, part); +} + + + +void METIS_WPARTGRAPHKWAY(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, float *tpwgts, int *options, int *edgecut, idxtype *part) +{ + METIS_WPartGraphKway(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, tpwgts, options, edgecut, part); +} +void metis_wpartgraphkway(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, float *tpwgts, int *options, int *edgecut, idxtype *part) +{ + METIS_WPartGraphKway(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, tpwgts, options, edgecut, part); +} +void metis_wpartgraphkway_(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, float *tpwgts, int *options, int *edgecut, idxtype *part) +{ + METIS_WPartGraphKway(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, tpwgts, options, edgecut, part); +} +void metis_wpartgraphkway__(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, float *tpwgts, int *options, int *edgecut, idxtype *part) +{ + METIS_WPartGraphKway(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, tpwgts, options, edgecut, part); +} + + + +void METIS_EDGEND(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *options, idxtype *perm, idxtype *iperm) +{ + METIS_EdgeND(nvtxs, xadj, adjncy, numflag, options, perm, iperm); +} +void metis_edgend(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *options, idxtype *perm, idxtype *iperm) +{ + METIS_EdgeND(nvtxs, xadj, adjncy, numflag, options, perm, iperm); +} +void metis_edgend_(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *options, idxtype *perm, idxtype *iperm) +{ + METIS_EdgeND(nvtxs, xadj, adjncy, numflag, options, perm, iperm); +} +void metis_edgend__(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *options, idxtype *perm, idxtype *iperm) +{ + METIS_EdgeND(nvtxs, xadj, adjncy, numflag, options, perm, iperm); +} + + + +void METIS_NODEND(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *options, idxtype *perm, idxtype *iperm) +{ + METIS_NodeND(nvtxs, xadj, adjncy, numflag, options, perm, iperm); +} +void metis_nodend(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *options, idxtype *perm, idxtype *iperm) +{ + METIS_NodeND(nvtxs, xadj, adjncy, numflag, options, perm, iperm); +} +void metis_nodend_(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *options, idxtype *perm, idxtype *iperm) +{ + METIS_NodeND(nvtxs, xadj, adjncy, numflag, options, perm, iperm); +} +void metis_nodend__(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *options, idxtype *perm, idxtype *iperm) +{ + METIS_NodeND(nvtxs, xadj, adjncy, numflag, options, perm, iperm); +} + + + +void METIS_NODEWND(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, int *numflag, int *options, idxtype *perm, idxtype *iperm) +{ + METIS_NodeWND(nvtxs, xadj, adjncy, vwgt, numflag, options, perm, iperm); +} +void metis_nodewnd(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, int *numflag, int *options, idxtype *perm, idxtype *iperm) +{ + METIS_NodeWND(nvtxs, xadj, adjncy, vwgt, numflag, options, perm, iperm); +} +void metis_nodewnd_(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, int *numflag, int *options, idxtype *perm, idxtype *iperm) +{ + METIS_NodeWND(nvtxs, xadj, adjncy, vwgt, numflag, options, perm, iperm); +} +void metis_nodewnd__(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, int *numflag, int *options, idxtype *perm, idxtype *iperm) +{ + METIS_NodeWND(nvtxs, xadj, adjncy, vwgt, numflag, options, perm, iperm); +} + + + +void METIS_PARTMESHNODAL(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, int *nparts, int *edgecut, idxtype *epart, idxtype *npart) +{ + METIS_PartMeshNodal(ne, nn, elmnts, etype, numflag, nparts, edgecut, epart, npart); +} +void metis_partmeshnodal(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, int *nparts, int *edgecut, idxtype *epart, idxtype *npart) +{ + METIS_PartMeshNodal(ne, nn, elmnts, etype, numflag, nparts, edgecut, epart, npart); +} +void metis_partmeshnodal_(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, int *nparts, int *edgecut, idxtype *epart, idxtype *npart) +{ + METIS_PartMeshNodal(ne, nn, elmnts, etype, numflag, nparts, edgecut, epart, npart); +} +void metis_partmeshnodal__(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, int *nparts, int *edgecut, idxtype *epart, idxtype *npart) +{ + METIS_PartMeshNodal(ne, nn, elmnts, etype, numflag, nparts, edgecut, epart, npart); +} + + +void METIS_PARTMESHDUAL(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, int *nparts, int *edgecut, idxtype *epart, idxtype *npart) +{ + METIS_PartMeshDual(ne, nn, elmnts, etype, numflag, nparts, edgecut, epart, npart); +} +void metis_partmeshdual(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, int *nparts, int *edgecut, idxtype *epart, idxtype *npart) +{ + METIS_PartMeshDual(ne, nn, elmnts, etype, numflag, nparts, edgecut, epart, npart); +} +void metis_partmeshdual_(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, int *nparts, int *edgecut, idxtype *epart, idxtype *npart) +{ + METIS_PartMeshDual(ne, nn, elmnts, etype, numflag, nparts, edgecut, epart, npart); +} +void metis_partmeshdual__(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, int *nparts, int *edgecut, idxtype *epart, idxtype *npart) +{ + METIS_PartMeshDual(ne, nn, elmnts, etype, numflag, nparts, edgecut, epart, npart); +} + + +void METIS_MESHTONODAL(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, idxtype *dxadj, idxtype *dadjncy) +{ + METIS_MeshToNodal(ne, nn, elmnts, etype, numflag, dxadj, dadjncy); +} +void metis_meshtonodal(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, idxtype *dxadj, idxtype *dadjncy) +{ + METIS_MeshToNodal(ne, nn, elmnts, etype, numflag, dxadj, dadjncy); +} +void metis_meshtonodal_(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, idxtype *dxadj, idxtype *dadjncy) +{ + METIS_MeshToNodal(ne, nn, elmnts, etype, numflag, dxadj, dadjncy); +} +void metis_meshtonodal__(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, idxtype *dxadj, idxtype *dadjncy) +{ + METIS_MeshToNodal(ne, nn, elmnts, etype, numflag, dxadj, dadjncy); +} + + +void METIS_MESHTODUAL(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, idxtype *dxadj, idxtype *dadjncy) +{ + METIS_MeshToDual(ne, nn, elmnts, etype, numflag, dxadj, dadjncy); +} +void metis_meshtodual(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, idxtype *dxadj, idxtype *dadjncy) +{ + METIS_MeshToDual(ne, nn, elmnts, etype, numflag, dxadj, dadjncy); +} +void metis_meshtodual_(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, idxtype *dxadj, idxtype *dadjncy) +{ + METIS_MeshToDual(ne, nn, elmnts, etype, numflag, dxadj, dadjncy); +} +void metis_meshtodual__(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, idxtype *dxadj, idxtype *dadjncy) +{ + METIS_MeshToDual(ne, nn, elmnts, etype, numflag, dxadj, dadjncy); +} + + +void METIS_ESTIMATEMEMORY(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *optype, int *nbytes) +{ + METIS_EstimateMemory(nvtxs, xadj, adjncy, numflag, optype, nbytes); +} +void metis_estimatememory(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *optype, int *nbytes) +{ + METIS_EstimateMemory(nvtxs, xadj, adjncy, numflag, optype, nbytes); +} +void metis_estimatememory_(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *optype, int *nbytes) +{ + METIS_EstimateMemory(nvtxs, xadj, adjncy, numflag, optype, nbytes); +} +void metis_estimatememory__(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *optype, int *nbytes) +{ + METIS_EstimateMemory(nvtxs, xadj, adjncy, numflag, optype, nbytes); +} + + + +void METIS_MCPARTGRAPHRECURSIVE(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, idxtype *part) +{ + METIS_mCPartGraphRecursive(nvtxs, ncon, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, options, edgecut, part); +} +void metis_mcpartgraphrecursive(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, idxtype *part) +{ + METIS_mCPartGraphRecursive(nvtxs, ncon, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, options, edgecut, part); +} +void metis_mcpartgraphrecursive_(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, idxtype *part) +{ + METIS_mCPartGraphRecursive(nvtxs, ncon, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, options, edgecut, part); +} +void metis_mcpartgraphrecursive__(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, idxtype *part) +{ + METIS_mCPartGraphRecursive(nvtxs, ncon, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, options, edgecut, part); +} + + +void METIS_MCPARTGRAPHKWAY(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, float *rubvec, int *options, int *edgecut, idxtype *part) +{ + METIS_mCPartGraphKway(nvtxs, ncon, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, rubvec, options, edgecut, part); +} +void metis_mcpartgraphkway(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, float *rubvec, int *options, int *edgecut, idxtype *part) +{ + METIS_mCPartGraphKway(nvtxs, ncon, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, rubvec, options, edgecut, part); +} +void metis_mcpartgraphkway_(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, float *rubvec, int *options, int *edgecut, idxtype *part) +{ + METIS_mCPartGraphKway(nvtxs, ncon, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, rubvec, options, edgecut, part); +} +void metis_mcpartgraphkway__(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, float *rubvec, int *options, int *edgecut, idxtype *part) +{ + METIS_mCPartGraphKway(nvtxs, ncon, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, rubvec, options, edgecut, part); +} + + +void METIS_PARTGRAPHVKWAY(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *vsize, int *wgtflag, int *numflag, int *nparts, int *options, int *volume, idxtype *part) +{ + METIS_PartGraphVKway(nvtxs, xadj, adjncy, vwgt, vsize, wgtflag, numflag, nparts, options, volume, part); +} +void metis_partgraphvkaway(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *vsize, int *wgtflag, int *numflag, int *nparts, int *options, int *volume, idxtype *part) +{ + METIS_PartGraphVKway(nvtxs, xadj, adjncy, vwgt, vsize, wgtflag, numflag, nparts, options, volume, part); +} +void metis_partgraphvkaway_(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *vsize, int *wgtflag, int *numflag, int *nparts, int *options, int *volume, idxtype *part) +{ + METIS_PartGraphVKway(nvtxs, xadj, adjncy, vwgt, vsize, wgtflag, numflag, nparts, options, volume, part); +} +void metis_partgraphvkaway__(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *vsize, int *wgtflag, int *numflag, int *nparts, int *options, int *volume, idxtype *part) +{ + METIS_PartGraphVKway(nvtxs, xadj, adjncy, vwgt, vsize, wgtflag, numflag, nparts, options, volume, part); +} + +void METIS_WPARTGRAPHVKWAY(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *vsize, int *wgtflag, int *numflag, int *nparts, float *tpwgts, int *options, int *volume, idxtype *part) +{ + METIS_WPartGraphVKway(nvtxs, xadj, adjncy, vwgt, vsize, wgtflag, numflag, nparts, tpwgts, options, volume, part); +} +void metis_wpartgraphvkaway(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *vsize, int *wgtflag, int *numflag, int *nparts, float *tpwgts, int *options, int *volume, idxtype *part) +{ + METIS_WPartGraphVKway(nvtxs, xadj, adjncy, vwgt, vsize, wgtflag, numflag, nparts, tpwgts, options, volume, part); +} +void metis_wpartgraphvkaway_(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *vsize, int *wgtflag, int *numflag, int *nparts, float *tpwgts, int *options, int *volume, idxtype *part) +{ + METIS_WPartGraphVKway(nvtxs, xadj, adjncy, vwgt, vsize, wgtflag, numflag, nparts, tpwgts, options, volume, part); +} +void metis_wpartgraphvkaway__(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *vsize, int *wgtflag, int *numflag, int *nparts, float *tpwgts, int *options, int *volume, idxtype *part) +{ + METIS_WPartGraphVKway(nvtxs, xadj, adjncy, vwgt, vsize, wgtflag, numflag, nparts, tpwgts, options, volume, part); +} + + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/graph.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/graph.c new file mode 100644 index 0000000..9a93784 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/graph.c @@ -0,0 +1,616 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * graph.c + * + * This file contains functions that deal with setting up the graphs + * for METIS. + * + * Started 7/25/97 + * George + * + * $Id: graph.c,v 1.2 2003/07/31 06:14:01 karypis Exp $ + * + */ + +#include <metis.h> + +/************************************************************************* +* This function sets up the graph from the user input +**************************************************************************/ +void SetUpGraph(GraphType *graph, int OpType, int nvtxs, int ncon, + idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int wgtflag) +{ + int i, j, k, sum, gsize; + float *nvwgt; + idxtype tvwgt[MAXNCON]; + + if (OpType == OP_KMETIS && ncon == 1 && (wgtflag&2) == 0 && (wgtflag&1) == 0) { + SetUpGraphKway(graph, nvtxs, xadj, adjncy); + return; + } + + InitGraph(graph); + + graph->nvtxs = nvtxs; + graph->nedges = xadj[nvtxs]; + graph->ncon = ncon; + graph->xadj = xadj; + graph->adjncy = adjncy; + + if (ncon == 1) { /* We are in the non mC mode */ + gsize = 0; + if ((wgtflag&2) == 0) + gsize += nvtxs; + if ((wgtflag&1) == 0) + gsize += graph->nedges; + + gsize += 2*nvtxs; + + graph->gdata = idxmalloc(gsize, "SetUpGraph: gdata"); + + /* Create the vertex/edge weight vectors if they are not supplied */ + gsize = 0; + if ((wgtflag&2) == 0) { + vwgt = graph->vwgt = idxset(nvtxs, 1, graph->gdata); + gsize += nvtxs; + } + else + graph->vwgt = vwgt; + + if ((wgtflag&1) == 0) { + adjwgt = graph->adjwgt = idxset(graph->nedges, 1, graph->gdata+gsize); + gsize += graph->nedges; + } + else + graph->adjwgt = adjwgt; + + + /* Compute the initial values of the adjwgtsum */ + graph->adjwgtsum = graph->gdata + gsize; + gsize += nvtxs; + + for (i=0; i<nvtxs; i++) { + sum = 0; + for (j=xadj[i]; j<xadj[i+1]; j++) + sum += adjwgt[j]; + graph->adjwgtsum[i] = sum; + } + + graph->cmap = graph->gdata + gsize; + gsize += nvtxs; + + } + else { /* Set up the graph in MOC mode */ + gsize = 0; + if ((wgtflag&1) == 0) + gsize += graph->nedges; + + gsize += 2*nvtxs; + + graph->gdata = idxmalloc(gsize, "SetUpGraph: gdata"); + gsize = 0; + + for (i=0; i<ncon; i++) + tvwgt[i] = idxsum_strd(nvtxs, vwgt+i, ncon); + + nvwgt = graph->nvwgt = fmalloc(ncon*nvtxs, "SetUpGraph: nvwgt"); + + for (i=0; i<nvtxs; i++) { + for (j=0; j<ncon; j++) + nvwgt[i*ncon+j] = (1.0*vwgt[i*ncon+j])/(1.0*tvwgt[j]); + } + + + /* Create the edge weight vectors if they are not supplied */ + if ((wgtflag&1) == 0) { + adjwgt = graph->adjwgt = idxset(graph->nedges, 1, graph->gdata+gsize); + gsize += graph->nedges; + } + else + graph->adjwgt = adjwgt; + + /* Compute the initial values of the adjwgtsum */ + graph->adjwgtsum = graph->gdata + gsize; + gsize += nvtxs; + + for (i=0; i<nvtxs; i++) { + sum = 0; + for (j=xadj[i]; j<xadj[i+1]; j++) + sum += adjwgt[j]; + graph->adjwgtsum[i] = sum; + } + + graph->cmap = graph->gdata + gsize; + gsize += nvtxs; + + } + + if (OpType != OP_KMETIS && OpType != OP_KVMETIS) { + graph->label = idxmalloc(nvtxs, "SetUpGraph: label"); + + for (i=0; i<nvtxs; i++) + graph->label[i] = i; + } + +} + + +/************************************************************************* +* This function sets up the graph from the user input +**************************************************************************/ +void SetUpGraphKway(GraphType *graph, int nvtxs, idxtype *xadj, idxtype *adjncy) +{ + int i; + + InitGraph(graph); + + graph->nvtxs = nvtxs; + graph->nedges = xadj[nvtxs]; + graph->ncon = 1; + graph->xadj = xadj; + graph->vwgt = NULL; + graph->adjncy = adjncy; + graph->adjwgt = NULL; + + graph->gdata = idxmalloc(2*nvtxs, "SetUpGraph: gdata"); + graph->adjwgtsum = graph->gdata; + graph->cmap = graph->gdata + nvtxs; + + /* Compute the initial values of the adjwgtsum */ + for (i=0; i<nvtxs; i++) + graph->adjwgtsum[i] = xadj[i+1]-xadj[i]; + +} + + + +/************************************************************************* +* This function sets up the graph from the user input +**************************************************************************/ +void SetUpGraph2(GraphType *graph, int nvtxs, int ncon, idxtype *xadj, + idxtype *adjncy, float *nvwgt, idxtype *adjwgt) +{ + int i, j, sum; + + InitGraph(graph); + + graph->nvtxs = nvtxs; + graph->nedges = xadj[nvtxs]; + graph->ncon = ncon; + graph->xadj = xadj; + graph->adjncy = adjncy; + graph->adjwgt = adjwgt; + + graph->nvwgt = fmalloc(nvtxs*ncon, "SetUpGraph2: graph->nvwgt"); + scopy(nvtxs*ncon, nvwgt, graph->nvwgt); + + graph->gdata = idxmalloc(2*nvtxs, "SetUpGraph: gdata"); + + /* Compute the initial values of the adjwgtsum */ + graph->adjwgtsum = graph->gdata; + for (i=0; i<nvtxs; i++) { + sum = 0; + for (j=xadj[i]; j<xadj[i+1]; j++) + sum += adjwgt[j]; + graph->adjwgtsum[i] = sum; + } + + graph->cmap = graph->gdata+nvtxs; + + graph->label = idxmalloc(nvtxs, "SetUpGraph: label"); + for (i=0; i<nvtxs; i++) + graph->label[i] = i; + +} + + +/************************************************************************* +* This function sets up the graph from the user input +**************************************************************************/ +void VolSetUpGraph(GraphType *graph, int OpType, int nvtxs, int ncon, idxtype *xadj, + idxtype *adjncy, idxtype *vwgt, idxtype *vsize, int wgtflag) +{ + int i, j, k, sum, gsize; + idxtype *adjwgt; + float *nvwgt; + idxtype tvwgt[MAXNCON]; + + InitGraph(graph); + + graph->nvtxs = nvtxs; + graph->nedges = xadj[nvtxs]; + graph->ncon = ncon; + graph->xadj = xadj; + graph->adjncy = adjncy; + + if (ncon == 1) { /* We are in the non mC mode */ + gsize = graph->nedges; /* This is for the edge weights */ + if ((wgtflag&2) == 0) + gsize += nvtxs; /* vwgts */ + if ((wgtflag&1) == 0) + gsize += nvtxs; /* vsize */ + + gsize += 2*nvtxs; + + graph->gdata = idxmalloc(gsize, "SetUpGraph: gdata"); + + /* Create the vertex/edge weight vectors if they are not supplied */ + gsize = 0; + if ((wgtflag&2) == 0) { + vwgt = graph->vwgt = idxset(nvtxs, 1, graph->gdata); + gsize += nvtxs; + } + else + graph->vwgt = vwgt; + + if ((wgtflag&1) == 0) { + vsize = graph->vsize = idxset(nvtxs, 1, graph->gdata); + gsize += nvtxs; + } + else + graph->vsize = vsize; + + /* Allocate memory for edge weights and initialize them to the sum of the vsize */ + adjwgt = graph->adjwgt = graph->gdata+gsize; + gsize += graph->nedges; + + for (i=0; i<nvtxs; i++) { + for (j=xadj[i]; j<xadj[i+1]; j++) + adjwgt[j] = 1+vsize[i]+vsize[adjncy[j]]; + } + + + /* Compute the initial values of the adjwgtsum */ + graph->adjwgtsum = graph->gdata + gsize; + gsize += nvtxs; + + for (i=0; i<nvtxs; i++) { + sum = 0; + for (j=xadj[i]; j<xadj[i+1]; j++) + sum += adjwgt[j]; + graph->adjwgtsum[i] = sum; + } + + graph->cmap = graph->gdata + gsize; + gsize += nvtxs; + + } + else { /* Set up the graph in MOC mode */ + gsize = graph->nedges; + if ((wgtflag&1) == 0) + gsize += nvtxs; + + gsize += 2*nvtxs; + + graph->gdata = idxmalloc(gsize, "SetUpGraph: gdata"); + gsize = 0; + + /* Create the normalized vertex weights along each constrain */ + if ((wgtflag&2) == 0) + vwgt = idxsmalloc(nvtxs, 1, "SetUpGraph: vwgt"); + + for (i=0; i<ncon; i++) + tvwgt[i] = idxsum_strd(nvtxs, vwgt+i, ncon); + + nvwgt = graph->nvwgt = fmalloc(ncon*nvtxs, "SetUpGraph: nvwgt"); + + for (i=0; i<nvtxs; i++) { + for (j=0; j<ncon; j++) + nvwgt[i*ncon+j] = (1.0*vwgt[i*ncon+j])/(1.0*tvwgt[j]); + } + if ((wgtflag&2) == 0) + free(vwgt); + + + /* Create the vsize vector if it is not supplied */ + if ((wgtflag&1) == 0) { + vsize = graph->vsize = idxset(nvtxs, 1, graph->gdata); + gsize += nvtxs; + } + else + graph->vsize = vsize; + + /* Allocate memory for edge weights and initialize them to the sum of the vsize */ + adjwgt = graph->adjwgt = graph->gdata+gsize; + gsize += graph->nedges; + + for (i=0; i<nvtxs; i++) { + for (j=xadj[i]; j<xadj[i+1]; j++) + adjwgt[j] = 1+vsize[i]+vsize[adjncy[j]]; + } + + /* Compute the initial values of the adjwgtsum */ + graph->adjwgtsum = graph->gdata + gsize; + gsize += nvtxs; + + for (i=0; i<nvtxs; i++) { + sum = 0; + for (j=xadj[i]; j<xadj[i+1]; j++) + sum += adjwgt[j]; + graph->adjwgtsum[i] = sum; + } + + graph->cmap = graph->gdata + gsize; + gsize += nvtxs; + + } + + if (OpType != OP_KVMETIS) { + graph->label = idxmalloc(nvtxs, "SetUpGraph: label"); + + for (i=0; i<nvtxs; i++) + graph->label[i] = i; + } + +} + + +/************************************************************************* +* This function randomly permutes the adjacency lists of a graph +**************************************************************************/ +void RandomizeGraph(GraphType *graph) +{ + int i, j, k, l, tmp, nvtxs; + idxtype *xadj, *adjncy, *adjwgt; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + for (i=0; i<nvtxs; i++) { + l = xadj[i+1]-xadj[i]; + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = xadj[i] + RandomInRange(l); + SWAP(adjncy[j], adjncy[k], tmp); + SWAP(adjwgt[j], adjwgt[k], tmp); + } + } +} + + +/************************************************************************* +* This function checks whether or not partition pid is contigous +**************************************************************************/ +int IsConnectedSubdomain(CtrlType *ctrl, GraphType *graph, int pid, int report) +{ + int i, j, k, nvtxs, first, last, nleft, ncmps, wgt; + idxtype *xadj, *adjncy, *where, *touched, *queue; + idxtype *cptr; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + where = graph->where; + + touched = idxsmalloc(nvtxs, 0, "IsConnected: touched"); + queue = idxmalloc(nvtxs, "IsConnected: queue"); + cptr = idxmalloc(nvtxs+1, "IsConnected: cptr"); + + nleft = 0; + for (i=0; i<nvtxs; i++) { + if (where[i] == pid) + nleft++; + } + + for (i=0; i<nvtxs; i++) { + if (where[i] == pid) + break; + } + + touched[i] = 1; + queue[0] = i; + first = 0; last = 1; + + cptr[0] = 0; /* This actually points to queue */ + ncmps = 0; + while (first != nleft) { + if (first == last) { /* Find another starting vertex */ + cptr[++ncmps] = first; + for (i=0; i<nvtxs; i++) { + if (where[i] == pid && !touched[i]) + break; + } + queue[last++] = i; + touched[i] = 1; + } + + i = queue[first++]; + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (where[k] == pid && !touched[k]) { + queue[last++] = k; + touched[k] = 1; + } + } + } + cptr[++ncmps] = first; + + if (ncmps > 1 && report) { + printf("The graph has %d connected components in partition %d:\t", ncmps, pid); + for (i=0; i<ncmps; i++) { + wgt = 0; + for (j=cptr[i]; j<cptr[i+1]; j++) + wgt += graph->vwgt[queue[j]]; + printf("[%5d %5d] ", cptr[i+1]-cptr[i], wgt); + /* + if (cptr[i+1]-cptr[i] == 1) + printf("[%d %d] ", queue[cptr[i]], xadj[queue[cptr[i]]+1]-xadj[queue[cptr[i]]]); + */ + } + printf("\n"); + } + + GKfree(&touched, &queue, &cptr, LTERM); + + return (ncmps == 1 ? 1 : 0); +} + + +/************************************************************************* +* This function checks whether a graph is contigous or not +**************************************************************************/ +int IsConnected(CtrlType *ctrl, GraphType *graph, int report) +{ + int i, j, k, nvtxs, first, last; + idxtype *xadj, *adjncy, *touched, *queue; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + + touched = idxsmalloc(nvtxs, 0, "IsConnected: touched"); + queue = idxmalloc(nvtxs, "IsConnected: queue"); + + touched[0] = 1; + queue[0] = 0; + first = 0; last = 1; + + while (first < last) { + i = queue[first++]; + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (!touched[k]) { + queue[last++] = k; + touched[k] = 1; + } + } + } + + if (first != nvtxs && report) + printf("The graph is not connected. It has %d disconnected vertices!\n", nvtxs-first); + + return (first == nvtxs ? 1 : 0); +} + + +/************************************************************************* +* This function checks whether or not partition pid is contigous +**************************************************************************/ +int IsConnected2(GraphType *graph, int report) +{ + int i, j, k, nvtxs, first, last, nleft, ncmps, wgt; + idxtype *xadj, *adjncy, *where, *touched, *queue; + idxtype *cptr; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + where = graph->where; + + touched = idxsmalloc(nvtxs, 0, "IsConnected: touched"); + queue = idxmalloc(nvtxs, "IsConnected: queue"); + cptr = idxmalloc(nvtxs+1, "IsConnected: cptr"); + + nleft = nvtxs; + touched[0] = 1; + queue[0] = 0; + first = 0; last = 1; + + cptr[0] = 0; /* This actually points to queue */ + ncmps = 0; + while (first != nleft) { + if (first == last) { /* Find another starting vertex */ + cptr[++ncmps] = first; + for (i=0; i<nvtxs; i++) { + if (!touched[i]) + break; + } + queue[last++] = i; + touched[i] = 1; + } + + i = queue[first++]; + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (!touched[k]) { + queue[last++] = k; + touched[k] = 1; + } + } + } + cptr[++ncmps] = first; + + if (ncmps > 1 && report) { + printf("%d connected components:\t", ncmps); + for (i=0; i<ncmps; i++) { + if (cptr[i+1]-cptr[i] > 200) + printf("[%5d] ", cptr[i+1]-cptr[i]); + } + printf("\n"); + } + + GKfree(&touched, &queue, &cptr, LTERM); + + return (ncmps == 1 ? 1 : 0); +} + + +/************************************************************************* +* This function returns the number of connected components in cptr,cind +* The separator of the graph is used to split it and then find its components. +**************************************************************************/ +int FindComponents(CtrlType *ctrl, GraphType *graph, idxtype *cptr, idxtype *cind) +{ + int i, j, k, nvtxs, first, last, nleft, ncmps, wgt; + idxtype *xadj, *adjncy, *where, *touched, *queue; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + where = graph->where; + + touched = idxsmalloc(nvtxs, 0, "IsConnected: queue"); + + for (i=0; i<graph->nbnd; i++) + touched[graph->bndind[i]] = 1; + + queue = cind; + + nleft = 0; + for (i=0; i<nvtxs; i++) { + if (where[i] != 2) + nleft++; + } + + for (i=0; i<nvtxs; i++) { + if (where[i] != 2) + break; + } + + touched[i] = 1; + queue[0] = i; + first = 0; last = 1; + + cptr[0] = 0; /* This actually points to queue */ + ncmps = 0; + while (first != nleft) { + if (first == last) { /* Find another starting vertex */ + cptr[++ncmps] = first; + for (i=0; i<nvtxs; i++) { + if (!touched[i]) + break; + } + queue[last++] = i; + touched[i] = 1; + } + + i = queue[first++]; + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (!touched[k]) { + queue[last++] = k; + touched[k] = 1; + } + } + } + cptr[++ncmps] = first; + + free(touched); + + return ncmps; +} + + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/initpart.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/initpart.c new file mode 100644 index 0000000..075cfb9 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/initpart.c @@ -0,0 +1,425 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * initpart.c + * + * This file contains code that performs the initial partition of the + * coarsest graph + * + * Started 7/23/97 + * George + * + * $Id: initpart.c,v 1.2 2003/07/31 16:23:29 karypis Exp $ + * + */ + +#include <metis.h> + +/************************************************************************* +* This function computes the initial bisection of the coarsest graph +**************************************************************************/ +void Init2WayPartition(CtrlType *ctrl, GraphType *graph, int *tpwgts, float ubfactor) +{ + int dbglvl; + + dbglvl = ctrl->dbglvl; + IFSET(ctrl->dbglvl, DBG_REFINE, ctrl->dbglvl -= DBG_REFINE); + IFSET(ctrl->dbglvl, DBG_MOVEINFO, ctrl->dbglvl -= DBG_MOVEINFO); + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->InitPartTmr)); + + switch (ctrl->IType) { + case IPART_GGPKL: + if (graph->nedges == 0) + RandomBisection(ctrl, graph, tpwgts, ubfactor); + else + GrowBisection(ctrl, graph, tpwgts, ubfactor); + break; + case 3: + RandomBisection(ctrl, graph, tpwgts, ubfactor); + break; + default: + errexit("Unknown initial partition type: %d\n", ctrl->IType); + } + + IFSET(ctrl->dbglvl, DBG_IPART, printf("Initial Cut: %d\n", graph->mincut)); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->InitPartTmr)); + ctrl->dbglvl = dbglvl; + +/* + IsConnectedSubdomain(ctrl, graph, 0); + IsConnectedSubdomain(ctrl, graph, 1); +*/ +} + +/************************************************************************* +* This function computes the initial bisection of the coarsest graph +**************************************************************************/ +void InitSeparator(CtrlType *ctrl, GraphType *graph, float ubfactor) +{ + int dbglvl; + + dbglvl = ctrl->dbglvl; + IFSET(ctrl->dbglvl, DBG_REFINE, ctrl->dbglvl -= DBG_REFINE); + IFSET(ctrl->dbglvl, DBG_MOVEINFO, ctrl->dbglvl -= DBG_MOVEINFO); + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->InitPartTmr)); + + GrowBisectionNode(ctrl, graph, ubfactor); + Compute2WayNodePartitionParams(ctrl, graph); + + IFSET(ctrl->dbglvl, DBG_IPART, printf("Initial Sep: %d\n", graph->mincut)); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->InitPartTmr)); + + ctrl->dbglvl = dbglvl; + +} + + + +/************************************************************************* +* This function takes a graph and produces a bisection by using a region +* growing algorithm. The resulting partition is returned in +* graph->where +**************************************************************************/ +void GrowBisection(CtrlType *ctrl, GraphType *graph, int *tpwgts, float ubfactor) +{ + int i, j, k, nvtxs, drain, nleft, first, last, pwgts[2], minpwgt[2], maxpwgt[2], from, bestcut, icut, mincut, me, pass, nbfs; + idxtype *xadj, *vwgt, *adjncy, *adjwgt, *where; + idxtype *queue, *touched, *gain, *bestwhere; + + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + Allocate2WayPartitionMemory(ctrl, graph); + where = graph->where; + + bestwhere = idxmalloc(nvtxs, "BisectGraph: bestwhere"); + queue = idxmalloc(nvtxs, "BisectGraph: queue"); + touched = idxmalloc(nvtxs, "BisectGraph: touched"); + + ASSERTP(tpwgts[0]+tpwgts[1] == idxsum(nvtxs, vwgt), ("%d %d\n", tpwgts[0]+tpwgts[1], idxsum(nvtxs, vwgt))); + + maxpwgt[0] = ubfactor*tpwgts[0]; + maxpwgt[1] = ubfactor*tpwgts[1]; + minpwgt[0] = (1.0/ubfactor)*tpwgts[0]; + minpwgt[1] = (1.0/ubfactor)*tpwgts[1]; + + nbfs = (nvtxs <= ctrl->CoarsenTo ? SMALLNIPARTS : LARGENIPARTS); + bestcut = idxsum(nvtxs, graph->adjwgtsum)+1; /* The +1 is for the 0 edges case */ + for (; nbfs>0; nbfs--) { + idxset(nvtxs, 0, touched); + + pwgts[1] = tpwgts[0]+tpwgts[1]; + pwgts[0] = 0; + + idxset(nvtxs, 1, where); + + queue[0] = RandomInRange(nvtxs); + touched[queue[0]] = 1; + first = 0; last = 1; + nleft = nvtxs-1; + drain = 0; + + /* Start the BFS from queue to get a partition */ + for (;;) { + if (first == last) { /* Empty. Disconnected graph! */ + if (nleft == 0 || drain) + break; + + k = RandomInRange(nleft); + for (i=0; i<nvtxs; i++) { + if (touched[i] == 0) { + if (k == 0) + break; + else + k--; + } + } + + queue[0] = i; + touched[i] = 1; + first = 0; last = 1;; + nleft--; + } + + i = queue[first++]; + if (pwgts[0] > 0 && pwgts[1]-vwgt[i] < minpwgt[1]) { + drain = 1; + continue; + } + + where[i] = 0; + INC_DEC(pwgts[0], pwgts[1], vwgt[i]); + if (pwgts[1] <= maxpwgt[1]) + break; + + drain = 0; + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (touched[k] == 0) { + queue[last++] = k; + touched[k] = 1; + nleft--; + } + } + } + + /* Check to see if we hit any bad limiting cases */ + if (pwgts[1] == 0) { + i = RandomInRange(nvtxs); + where[i] = 1; + INC_DEC(pwgts[1], pwgts[0], vwgt[i]); + } + + /************************************************************* + * Do some partition refinement + **************************************************************/ + Compute2WayPartitionParams(ctrl, graph); + /*printf("IPART: %3d [%5d %5d] [%5d %5d] %5d\n", graph->nvtxs, pwgts[0], pwgts[1], graph->pwgts[0], graph->pwgts[1], graph->mincut); */ + + Balance2Way(ctrl, graph, tpwgts, ubfactor); + /*printf("BPART: [%5d %5d] %5d\n", graph->pwgts[0], graph->pwgts[1], graph->mincut);*/ + + FM_2WayEdgeRefine(ctrl, graph, tpwgts, 4); + /*printf("RPART: [%5d %5d] %5d\n", graph->pwgts[0], graph->pwgts[1], graph->mincut);*/ + + if (bestcut > graph->mincut) { + bestcut = graph->mincut; + idxcopy(nvtxs, where, bestwhere); + if (bestcut == 0) + break; + } + } + + graph->mincut = bestcut; + idxcopy(nvtxs, bestwhere, where); + + GKfree(&bestwhere, &queue, &touched, LTERM); +} + + + + +/************************************************************************* +* This function takes a graph and produces a bisection by using a region +* growing algorithm. The resulting partition is returned in +* graph->where +**************************************************************************/ +void GrowBisectionNode(CtrlType *ctrl, GraphType *graph, float ubfactor) +{ + int i, j, k, nvtxs, drain, nleft, first, last, pwgts[2], tpwgts[2], minpwgt[2], maxpwgt[2], from, bestcut, icut, mincut, me, pass, nbfs; + idxtype *xadj, *vwgt, *adjncy, *adjwgt, *where, *bndind; + idxtype *queue, *touched, *gain, *bestwhere; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + bestwhere = idxmalloc(nvtxs, "BisectGraph: bestwhere"); + queue = idxmalloc(nvtxs, "BisectGraph: queue"); + touched = idxmalloc(nvtxs, "BisectGraph: touched"); + + tpwgts[0] = idxsum(nvtxs, vwgt); + tpwgts[1] = tpwgts[0]/2; + tpwgts[0] -= tpwgts[1]; + + maxpwgt[0] = ubfactor*tpwgts[0]; + maxpwgt[1] = ubfactor*tpwgts[1]; + minpwgt[0] = (1.0/ubfactor)*tpwgts[0]; + minpwgt[1] = (1.0/ubfactor)*tpwgts[1]; + + /* Allocate memory for graph->rdata. Allocate sufficient memory for both edge and node */ + graph->rdata = idxmalloc(5*nvtxs+3, "GrowBisectionNode: graph->rdata"); + graph->pwgts = graph->rdata; + graph->where = graph->rdata + 3; + graph->bndptr = graph->rdata + nvtxs + 3; + graph->bndind = graph->rdata + 2*nvtxs + 3; + graph->nrinfo = (NRInfoType *)(graph->rdata + 3*nvtxs + 3); + graph->id = graph->rdata + 3*nvtxs + 3; + graph->ed = graph->rdata + 4*nvtxs + 3; + + where = graph->where; + bndind = graph->bndind; + + nbfs = (nvtxs <= ctrl->CoarsenTo ? SMALLNIPARTS : LARGENIPARTS); + bestcut = tpwgts[0]+tpwgts[1]; + for (nbfs++; nbfs>0; nbfs--) { + idxset(nvtxs, 0, touched); + + pwgts[1] = tpwgts[0]+tpwgts[1]; + pwgts[0] = 0; + + idxset(nvtxs, 1, where); + + queue[0] = RandomInRange(nvtxs); + touched[queue[0]] = 1; + first = 0; last = 1; + nleft = nvtxs-1; + drain = 0; + + /* Start the BFS from queue to get a partition */ + if (nbfs >= 1) { + for (;;) { + if (first == last) { /* Empty. Disconnected graph! */ + if (nleft == 0 || drain) + break; + + k = RandomInRange(nleft); + for (i=0; i<nvtxs; i++) { + if (touched[i] == 0) { + if (k == 0) + break; + else + k--; + } + } + + queue[0] = i; + touched[i] = 1; + first = 0; last = 1;; + nleft--; + } + + i = queue[first++]; + if (pwgts[1]-vwgt[i] < minpwgt[1]) { + drain = 1; + continue; + } + + where[i] = 0; + INC_DEC(pwgts[0], pwgts[1], vwgt[i]); + if (pwgts[1] <= maxpwgt[1]) + break; + + drain = 0; + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (touched[k] == 0) { + queue[last++] = k; + touched[k] = 1; + nleft--; + } + } + } + } + + /************************************************************* + * Do some partition refinement + **************************************************************/ + Compute2WayPartitionParams(ctrl, graph); + Balance2Way(ctrl, graph, tpwgts, ubfactor); + FM_2WayEdgeRefine(ctrl, graph, tpwgts, 4); + + /* Construct and refine the vertex separator */ + for (i=0; i<graph->nbnd; i++) + where[bndind[i]] = 2; + + Compute2WayNodePartitionParams(ctrl, graph); + FM_2WayNodeRefine(ctrl, graph, ubfactor, 6); + + /* printf("ISep: [%d %d %d] %d\n", graph->pwgts[0], graph->pwgts[1], graph->pwgts[2], bestcut); */ + + if (bestcut > graph->mincut) { + bestcut = graph->mincut; + idxcopy(nvtxs, where, bestwhere); + } + } + + graph->mincut = bestcut; + idxcopy(nvtxs, bestwhere, where); + + Compute2WayNodePartitionParams(ctrl, graph); + + GKfree(&bestwhere, &queue, &touched, LTERM); +} + + +/************************************************************************* +* This function takes a graph and produces a bisection by using a region +* growing algorithm. The resulting partition is returned in +* graph->where +**************************************************************************/ +void RandomBisection(CtrlType *ctrl, GraphType *graph, int *tpwgts, float ubfactor) +{ + int i, ii, j, k, nvtxs, pwgts[2], minpwgt[2], maxpwgt[2], from, bestcut, icut, mincut, me, pass, nbfs; + idxtype *xadj, *vwgt, *adjncy, *adjwgt, *where; + idxtype *perm, *bestwhere; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + Allocate2WayPartitionMemory(ctrl, graph); + where = graph->where; + + bestwhere = idxmalloc(nvtxs, "BisectGraph: bestwhere"); + perm = idxmalloc(nvtxs, "BisectGraph: queue"); + + ASSERTP(tpwgts[0]+tpwgts[1] == idxsum(nvtxs, vwgt), ("%d %d\n", tpwgts[0]+tpwgts[1], idxsum(nvtxs, vwgt))); + + maxpwgt[0] = ubfactor*tpwgts[0]; + maxpwgt[1] = ubfactor*tpwgts[1]; + minpwgt[0] = (1.0/ubfactor)*tpwgts[0]; + minpwgt[1] = (1.0/ubfactor)*tpwgts[1]; + + nbfs = (nvtxs <= ctrl->CoarsenTo ? SMALLNIPARTS : LARGENIPARTS); + bestcut = idxsum(nvtxs, graph->adjwgtsum)+1; /* The +1 is for the 0 edges case */ + for (; nbfs>0; nbfs--) { + RandomPermute(nvtxs, perm, 1); + + idxset(nvtxs, 1, where); + pwgts[1] = tpwgts[0]+tpwgts[1]; + pwgts[0] = 0; + + + if (nbfs != 1) { + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + if (pwgts[0]+vwgt[i] < maxpwgt[0]) { + where[i] = 0; + pwgts[0] += vwgt[i]; + pwgts[1] -= vwgt[i]; + if (pwgts[0] > minpwgt[0]) + break; + } + } + } + + /************************************************************* + * Do some partition refinement + **************************************************************/ + Compute2WayPartitionParams(ctrl, graph); + /* printf("IPART: %3d [%5d %5d] [%5d %5d] %5d\n", graph->nvtxs, pwgts[0], pwgts[1], graph->pwgts[0], graph->pwgts[1], graph->mincut); */ + + Balance2Way(ctrl, graph, tpwgts, ubfactor); + /* printf("BPART: [%5d %5d] %5d\n", graph->pwgts[0], graph->pwgts[1], graph->mincut); */ + + FM_2WayEdgeRefine(ctrl, graph, tpwgts, 4); + /* printf("RPART: [%5d %5d] %5d\n", graph->pwgts[0], graph->pwgts[1], graph->mincut); */ + + if (bestcut > graph->mincut) { + bestcut = graph->mincut; + idxcopy(nvtxs, where, bestwhere); + if (bestcut == 0) + break; + } + } + + graph->mincut = bestcut; + idxcopy(nvtxs, bestwhere, where); + + GKfree(&bestwhere, &perm, LTERM); +} + + + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kmetis.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kmetis.c new file mode 100644 index 0000000..87c3a59 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kmetis.c @@ -0,0 +1,129 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * kmetis.c + * + * This file contains the top level routines for the multilevel k-way partitioning + * algorithm KMETIS. + * + * Started 7/28/97 + * George + * + * $Id: kmetis.c,v 1.1 2003/07/16 15:55:04 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function is the entry point for KMETIS +**************************************************************************/ +void METIS_PartGraphKway(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, + int *options, int *edgecut, idxtype *part) +{ + int i; + float *tpwgts; + + tpwgts = fmalloc(*nparts, "KMETIS: tpwgts"); + for (i=0; i<*nparts; i++) + tpwgts[i] = 1.0/(1.0*(*nparts)); + + METIS_WPartGraphKway(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, + tpwgts, options, edgecut, part); + + free(tpwgts); +} + + +/************************************************************************* +* This function is the entry point for KWMETIS +**************************************************************************/ +void METIS_WPartGraphKway(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, + float *tpwgts, int *options, int *edgecut, idxtype *part) +{ + int i, j; + GraphType graph; + CtrlType ctrl; + + if (*numflag == 1) + Change2CNumbering(*nvtxs, xadj, adjncy); + + SetUpGraph(&graph, OP_KMETIS, *nvtxs, 1, xadj, adjncy, vwgt, adjwgt, *wgtflag); + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = KMETIS_CTYPE; + ctrl.IType = KMETIS_ITYPE; + ctrl.RType = KMETIS_RTYPE; + ctrl.dbglvl = KMETIS_DBGLVL; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + } + ctrl.optype = OP_KMETIS; + ctrl.CoarsenTo = amax((*nvtxs)/(40*log2Int(*nparts)), 20*(*nparts)); + ctrl.maxvwgt = 1.5*((graph.vwgt ? idxsum(*nvtxs, graph.vwgt) : (*nvtxs))/ctrl.CoarsenTo); + + InitRandom(-1); + + AllocateWorkSpace(&ctrl, &graph, *nparts); + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + *edgecut = MlevelKWayPartitioning(&ctrl, &graph, *nparts, part, tpwgts, 1.03); + + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); + + FreeWorkSpace(&ctrl, &graph); + + if (*numflag == 1) + Change2FNumbering(*nvtxs, xadj, adjncy, part); +} + + +/************************************************************************* +* This function takes a graph and produces a bisection of it +**************************************************************************/ +int MlevelKWayPartitioning(CtrlType *ctrl, GraphType *graph, int nparts, idxtype *part, float *tpwgts, float ubfactor) +{ + int i, j, nvtxs, tvwgt, tpwgts2[2]; + GraphType *cgraph; + int wgtflag=3, numflag=0, options[10], edgecut; + + cgraph = Coarsen2Way(ctrl, graph); + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->InitPartTmr)); + AllocateKWayPartitionMemory(ctrl, cgraph, nparts); + + options[0] = 1; + options[OPTION_CTYPE] = MATCH_SHEMKWAY; + options[OPTION_ITYPE] = IPART_GGPKL; + options[OPTION_RTYPE] = RTYPE_FM; + options[OPTION_DBGLVL] = 0; + + METIS_WPartGraphRecursive(&cgraph->nvtxs, cgraph->xadj, cgraph->adjncy, cgraph->vwgt, + cgraph->adjwgt, &wgtflag, &numflag, &nparts, tpwgts, options, + &edgecut, cgraph->where); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->InitPartTmr)); + IFSET(ctrl->dbglvl, DBG_IPART, printf("Initial %d-way partitioning cut: %d\n", nparts, edgecut)); + + IFSET(ctrl->dbglvl, DBG_KWAYPINFO, ComputePartitionInfo(cgraph, nparts, cgraph->where)); + + RefineKWay(ctrl, graph, cgraph, nparts, tpwgts, ubfactor); + + idxcopy(graph->nvtxs, graph->where, part); + + GKfree(&graph->gdata, &graph->rdata, LTERM); + + return graph->mincut; + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kvmetis.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kvmetis.c new file mode 100644 index 0000000..5bc0a67 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kvmetis.c @@ -0,0 +1,130 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * kvmetis.c + * + * This file contains the top level routines for the multilevel k-way partitioning + * algorithm KMETIS. + * + * Started 7/28/97 + * George + * + * $Id: kvmetis.c,v 1.1 2003/07/16 15:55:04 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function is the entry point for KMETIS +**************************************************************************/ +void METIS_PartGraphVKway(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *vsize, int *wgtflag, int *numflag, int *nparts, + int *options, int *volume, idxtype *part) +{ + int i; + float *tpwgts; + + tpwgts = fmalloc(*nparts, "KMETIS: tpwgts"); + for (i=0; i<*nparts; i++) + tpwgts[i] = 1.0/(1.0*(*nparts)); + + METIS_WPartGraphVKway(nvtxs, xadj, adjncy, vwgt, vsize, wgtflag, numflag, nparts, + tpwgts, options, volume, part); + + free(tpwgts); +} + + +/************************************************************************* +* This function is the entry point for KWMETIS +**************************************************************************/ +void METIS_WPartGraphVKway(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *vsize, int *wgtflag, int *numflag, int *nparts, + float *tpwgts, int *options, int *volume, idxtype *part) +{ + int i, j; + GraphType graph; + CtrlType ctrl; + + if (*numflag == 1) + Change2CNumbering(*nvtxs, xadj, adjncy); + + VolSetUpGraph(&graph, OP_KVMETIS, *nvtxs, 1, xadj, adjncy, vwgt, vsize, *wgtflag); + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = KVMETIS_CTYPE; + ctrl.IType = KVMETIS_ITYPE; + ctrl.RType = KVMETIS_RTYPE; + ctrl.dbglvl = KVMETIS_DBGLVL; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + } + ctrl.optype = OP_KVMETIS; + ctrl.CoarsenTo = amax((*nvtxs)/(40*log2Int(*nparts)), 20*(*nparts)); + ctrl.maxvwgt = 1.5*((graph.vwgt ? idxsum(*nvtxs, graph.vwgt) : (*nvtxs))/ctrl.CoarsenTo); + + InitRandom(-1); + + AllocateWorkSpace(&ctrl, &graph, *nparts); + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + *volume = MlevelVolKWayPartitioning(&ctrl, &graph, *nparts, part, tpwgts, 1.03); + + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); + + FreeWorkSpace(&ctrl, &graph); + + if (*numflag == 1) + Change2FNumbering(*nvtxs, xadj, adjncy, part); +} + + +/************************************************************************* +* This function takes a graph and produces a bisection of it +**************************************************************************/ +int MlevelVolKWayPartitioning(CtrlType *ctrl, GraphType *graph, int nparts, idxtype *part, + float *tpwgts, float ubfactor) +{ + int i, j, nvtxs, tvwgt, tpwgts2[2]; + GraphType *cgraph; + int wgtflag=3, numflag=0, options[10], edgecut; + + cgraph = Coarsen2Way(ctrl, graph); + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->InitPartTmr)); + AllocateVolKWayPartitionMemory(ctrl, cgraph, nparts); + + options[0] = 1; + options[OPTION_CTYPE] = MATCH_SHEMKWAY; + options[OPTION_ITYPE] = IPART_GGPKL; + options[OPTION_RTYPE] = RTYPE_FM; + options[OPTION_DBGLVL] = 0; + + METIS_WPartGraphRecursive(&cgraph->nvtxs, cgraph->xadj, cgraph->adjncy, cgraph->vwgt, + cgraph->adjwgt, &wgtflag, &numflag, &nparts, tpwgts, options, + &edgecut, cgraph->where); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->InitPartTmr)); + IFSET(ctrl->dbglvl, DBG_IPART, printf("Initial %d-way partitioning cut: %d\n", nparts, edgecut)); + + IFSET(ctrl->dbglvl, DBG_KWAYPINFO, ComputePartitionInfo(cgraph, nparts, cgraph->where)); + + RefineVolKWay(ctrl, graph, cgraph, nparts, tpwgts, ubfactor); + + idxcopy(graph->nvtxs, graph->where, part); + + GKfree(&graph->gdata, &graph->rdata, LTERM); + + return graph->minvol; + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kwayfm.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kwayfm.c new file mode 100644 index 0000000..170dcf3 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kwayfm.c @@ -0,0 +1,672 @@ +/* + * kwayfm.c + * + * This file contains code that implements the multilevel k-way refinement + * + * Started 7/28/97 + * George + * + * $Id: kwayfm.c,v 1.1 2003/07/16 15:55:04 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function performs k-way refinement +**************************************************************************/ +void Random_KWayEdgeRefine(CtrlType *ctrl, GraphType *graph, int nparts, float *tpwgts, float ubfactor, int npasses, int ffactor) +{ + int i, ii, iii, j, jj, k, l, pass, nvtxs, nmoves, nbnd, tvwgt, myndegrees; + int from, me, to, oldcut, vwgt, gain; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *where, *pwgts, *perm, *bndptr, *bndind, *minwgt, *maxwgt, *itpwgts; + EDegreeType *myedegrees; + RInfoType *myrinfo; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + bndptr = graph->bndptr; + bndind = graph->bndind; + + where = graph->where; + pwgts = graph->pwgts; + + /* Setup the weight intervals of the various subdomains */ + minwgt = idxwspacemalloc(ctrl, nparts); + maxwgt = idxwspacemalloc(ctrl, nparts); + itpwgts = idxwspacemalloc(ctrl, nparts); + tvwgt = idxsum(nparts, pwgts); + ASSERT(tvwgt == idxsum(nvtxs, graph->vwgt)); + + for (i=0; i<nparts; i++) { + itpwgts[i] = tpwgts[i]*tvwgt; + maxwgt[i] = tpwgts[i]*tvwgt*ubfactor; + minwgt[i] = tpwgts[i]*tvwgt*(1.0/ubfactor); + } + + perm = idxwspacemalloc(ctrl, nvtxs); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("Partitions: [%6d %6d]-[%6d %6d], Balance: %5.3f, Nv-Nb[%6d %6d]. Cut: %6d\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], minwgt[0], maxwgt[0], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nvtxs, graph->nbnd, + graph->mincut)); + + for (pass=0; pass<npasses; pass++) { + ASSERT(ComputeCut(graph, where) == graph->mincut); + + oldcut = graph->mincut; + nbnd = graph->nbnd; + + RandomPermute(nbnd, perm, 1); + for (nmoves=iii=0; iii<graph->nbnd; iii++) { + ii = perm[iii]; + if (ii >= nbnd) + continue; + i = bndind[ii]; + + myrinfo = graph->rinfo+i; + + if (myrinfo->ed >= myrinfo->id) { /* Total ED is too high */ + from = where[i]; + vwgt = graph->vwgt[i]; + + if (myrinfo->id > 0 && pwgts[from]-vwgt < minwgt[from]) + continue; /* This cannot be moved! */ + + myedegrees = myrinfo->edegrees; + myndegrees = myrinfo->ndegrees; + + j = myrinfo->id; + for (k=0; k<myndegrees; k++) { + to = myedegrees[k].pid; + gain = myedegrees[k].ed-j; /* j = myrinfo->id. Allow good nodes to move */ + if (pwgts[to]+vwgt <= maxwgt[to]+ffactor*gain && gain >= 0) + break; + } + if (k == myndegrees) + continue; /* break out if you did not find a candidate */ + + for (j=k+1; j<myndegrees; j++) { + to = myedegrees[j].pid; + if ((myedegrees[j].ed > myedegrees[k].ed && pwgts[to]+vwgt <= maxwgt[to]) || + (myedegrees[j].ed == myedegrees[k].ed && + itpwgts[myedegrees[k].pid]*pwgts[to] < itpwgts[to]*pwgts[myedegrees[k].pid])) + k = j; + } + + to = myedegrees[k].pid; + + j = 0; + if (myedegrees[k].ed-myrinfo->id > 0) + j = 1; + else if (myedegrees[k].ed-myrinfo->id == 0) { + if ((iii&7) == 0 || pwgts[from] >= maxwgt[from] || itpwgts[from]*(pwgts[to]+vwgt) < itpwgts[to]*pwgts[from]) + j = 1; + } + if (j == 0) + continue; + + /*===================================================================== + * If we got here, we can now move the vertex from 'from' to 'to' + *======================================================================*/ + graph->mincut -= myedegrees[k].ed-myrinfo->id; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, printf("\t\tMoving %6d to %3d. Gain: %4d. Cut: %6d\n", i, to, myedegrees[k].ed-myrinfo->id, graph->mincut)); + + /* Update where, weight, and ID/ED information of the vertex you moved */ + where[i] = to; + INC_DEC(pwgts[to], pwgts[from], vwgt); + myrinfo->ed += myrinfo->id-myedegrees[k].ed; + SWAP(myrinfo->id, myedegrees[k].ed, j); + if (myedegrees[k].ed == 0) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].pid = from; + + if (myrinfo->ed-myrinfo->id < 0) + BNDDelete(nbnd, bndind, bndptr, i); + + /* Update the degrees of adjacent vertices */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + ii = adjncy[j]; + me = where[ii]; + + myrinfo = graph->rinfo+ii; + if (myrinfo->edegrees == NULL) { + myrinfo->edegrees = ctrl->wspace.edegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += xadj[ii+1]-xadj[ii]; + } + myedegrees = myrinfo->edegrees; + + ASSERT(CheckRInfo(myrinfo)); + + if (me == from) { + INC_DEC(myrinfo->ed, myrinfo->id, adjwgt[j]); + + if (myrinfo->ed-myrinfo->id >= 0 && bndptr[ii] == -1) + BNDInsert(nbnd, bndind, bndptr, ii); + } + else if (me == to) { + INC_DEC(myrinfo->id, myrinfo->ed, adjwgt[j]); + + if (myrinfo->ed-myrinfo->id < 0 && bndptr[ii] != -1) + BNDDelete(nbnd, bndind, bndptr, ii); + } + + /* Remove contribution from the .ed of 'from' */ + if (me != from) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == from) { + if (myedegrees[k].ed == adjwgt[j]) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].ed -= adjwgt[j]; + break; + } + } + } + + /* Add contribution to the .ed of 'to' */ + if (me != to) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == to) { + myedegrees[k].ed += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + myedegrees[myrinfo->ndegrees].pid = to; + myedegrees[myrinfo->ndegrees++].ed = adjwgt[j]; + } + } + + ASSERT(myrinfo->ndegrees <= xadj[ii+1]-xadj[ii]); + ASSERT(CheckRInfo(myrinfo)); + + } + nmoves++; + } + } + + graph->nbnd = nbnd; + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\t[%6d %6d], Balance: %5.3f, Nb: %6d. Nmoves: %5d, Cut: %6d, Vol: %6d\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nbnd, nmoves, graph->mincut, ComputeVolume(graph, where))); + + if (graph->mincut == oldcut) + break; + } + + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nvtxs); +} + + + + + + +/************************************************************************* +* This function performs k-way refinement +**************************************************************************/ +void Greedy_KWayEdgeRefine(CtrlType *ctrl, GraphType *graph, int nparts, float *tpwgts, float ubfactor, int npasses) +{ + int i, ii, iii, j, jj, k, l, pass, nvtxs, nbnd, tvwgt, myndegrees, oldgain, gain; + int from, me, to, oldcut, vwgt; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *where, *pwgts, *perm, *bndptr, *bndind, *minwgt, *maxwgt, *moved, *itpwgts; + EDegreeType *myedegrees; + RInfoType *myrinfo; + PQueueType queue; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + bndind = graph->bndind; + bndptr = graph->bndptr; + + where = graph->where; + pwgts = graph->pwgts; + + /* Setup the weight intervals of the various subdomains */ + minwgt = idxwspacemalloc(ctrl, nparts); + maxwgt = idxwspacemalloc(ctrl, nparts); + itpwgts = idxwspacemalloc(ctrl, nparts); + tvwgt = idxsum(nparts, pwgts); + ASSERT(tvwgt == idxsum(nvtxs, graph->vwgt)); + + for (i=0; i<nparts; i++) { + itpwgts[i] = tpwgts[i]*tvwgt; + maxwgt[i] = tpwgts[i]*tvwgt*ubfactor; + minwgt[i] = tpwgts[i]*tvwgt*(1.0/ubfactor); + } + + perm = idxwspacemalloc(ctrl, nvtxs); + moved = idxwspacemalloc(ctrl, nvtxs); + + PQueueInit(ctrl, &queue, nvtxs, graph->adjwgtsum[idxamax(nvtxs, graph->adjwgtsum)]); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("Partitions: [%6d %6d]-[%6d %6d], Balance: %5.3f, Nv-Nb[%6d %6d]. Cut: %6d\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], minwgt[0], maxwgt[0], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nvtxs, graph->nbnd, + graph->mincut)); + + for (pass=0; pass<npasses; pass++) { + ASSERT(ComputeCut(graph, where) == graph->mincut); + + PQueueReset(&queue); + idxset(nvtxs, -1, moved); + + oldcut = graph->mincut; + nbnd = graph->nbnd; + + RandomPermute(nbnd, perm, 1); + for (ii=0; ii<nbnd; ii++) { + i = bndind[perm[ii]]; + PQueueInsert(&queue, i, graph->rinfo[i].ed - graph->rinfo[i].id); + moved[i] = 2; + } + + for (iii=0;;iii++) { + if ((i = PQueueGetMax(&queue)) == -1) + break; + moved[i] = 1; + + myrinfo = graph->rinfo+i; + from = where[i]; + vwgt = graph->vwgt[i]; + + if (pwgts[from]-vwgt < minwgt[from]) + continue; /* This cannot be moved! */ + + myedegrees = myrinfo->edegrees; + myndegrees = myrinfo->ndegrees; + + j = myrinfo->id; + for (k=0; k<myndegrees; k++) { + to = myedegrees[k].pid; + gain = myedegrees[k].ed-j; /* j = myrinfo->id. Allow good nodes to move */ + if (pwgts[to]+vwgt <= maxwgt[to]+gain && gain >= 0) + break; + } + if (k == myndegrees) + continue; /* break out if you did not find a candidate */ + + for (j=k+1; j<myndegrees; j++) { + to = myedegrees[j].pid; + if ((myedegrees[j].ed > myedegrees[k].ed && pwgts[to]+vwgt <= maxwgt[to]) || + (myedegrees[j].ed == myedegrees[k].ed && + itpwgts[myedegrees[k].pid]*pwgts[to] < itpwgts[to]*pwgts[myedegrees[k].pid])) + k = j; + } + + to = myedegrees[k].pid; + + j = 0; + if (myedegrees[k].ed-myrinfo->id > 0) + j = 1; + else if (myedegrees[k].ed-myrinfo->id == 0) { + if ((iii&7) == 0 || pwgts[from] >= maxwgt[from] || itpwgts[from]*(pwgts[to]+vwgt) < itpwgts[to]*pwgts[from]) + j = 1; + } + if (j == 0) + continue; + + /*===================================================================== + * If we got here, we can now move the vertex from 'from' to 'to' + *======================================================================*/ + graph->mincut -= myedegrees[k].ed-myrinfo->id; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, printf("\t\tMoving %6d to %3d. Gain: %4d. Cut: %6d\n", i, to, myedegrees[k].ed-myrinfo->id, graph->mincut)); + + /* Update where, weight, and ID/ED information of the vertex you moved */ + where[i] = to; + INC_DEC(pwgts[to], pwgts[from], vwgt); + myrinfo->ed += myrinfo->id-myedegrees[k].ed; + SWAP(myrinfo->id, myedegrees[k].ed, j); + if (myedegrees[k].ed == 0) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].pid = from; + + if (myrinfo->ed < myrinfo->id) + BNDDelete(nbnd, bndind, bndptr, i); + + /* Update the degrees of adjacent vertices */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + ii = adjncy[j]; + me = where[ii]; + + myrinfo = graph->rinfo+ii; + if (myrinfo->edegrees == NULL) { + myrinfo->edegrees = ctrl->wspace.edegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += xadj[ii+1]-xadj[ii]; + } + myedegrees = myrinfo->edegrees; + + ASSERT(CheckRInfo(myrinfo)); + + oldgain = (myrinfo->ed-myrinfo->id); + + if (me == from) { + INC_DEC(myrinfo->ed, myrinfo->id, adjwgt[j]); + + if (myrinfo->ed-myrinfo->id >= 0 && bndptr[ii] == -1) + BNDInsert(nbnd, bndind, bndptr, ii); + } + else if (me == to) { + INC_DEC(myrinfo->id, myrinfo->ed, adjwgt[j]); + + if (myrinfo->ed-myrinfo->id < 0 && bndptr[ii] != -1) + BNDDelete(nbnd, bndind, bndptr, ii); + } + + /* Remove contribution from the .ed of 'from' */ + if (me != from) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == from) { + if (myedegrees[k].ed == adjwgt[j]) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].ed -= adjwgt[j]; + break; + } + } + } + + /* Add contribution to the .ed of 'to' */ + if (me != to) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == to) { + myedegrees[k].ed += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + myedegrees[myrinfo->ndegrees].pid = to; + myedegrees[myrinfo->ndegrees++].ed = adjwgt[j]; + } + } + + /* Update the queue */ + if (me == to || me == from) { + gain = myrinfo->ed-myrinfo->id; + if (moved[ii] == 2) { + if (gain >= 0) + PQueueUpdate(&queue, ii, oldgain, gain); + else { + PQueueDelete(&queue, ii, oldgain); + moved[ii] = -1; + } + } + else if (moved[ii] == -1 && gain >= 0) { + PQueueInsert(&queue, ii, gain); + moved[ii] = 2; + } + } + + ASSERT(myrinfo->ndegrees <= xadj[ii+1]-xadj[ii]); + ASSERT(CheckRInfo(myrinfo)); + + } + } + + graph->nbnd = nbnd; + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\t[%6d %6d], Balance: %5.3f, Nb: %6d. Cut: %6d\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nbnd, graph->mincut)); + + if (graph->mincut == oldcut) + break; + } + + PQueueFree(ctrl, &queue); + + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + +} + + +/************************************************************************* +* This function performs k-way refinement +**************************************************************************/ +void Greedy_KWayEdgeBalance(CtrlType *ctrl, GraphType *graph, int nparts, float *tpwgts, float ubfactor, int npasses) +{ + int i, ii, iii, j, jj, k, l, pass, nvtxs, nbnd, tvwgt, myndegrees, oldgain, gain, nmoves; + int from, me, to, oldcut, vwgt; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *where, *pwgts, *perm, *bndptr, *bndind, *minwgt, *maxwgt, *moved, *itpwgts; + EDegreeType *myedegrees; + RInfoType *myrinfo; + PQueueType queue; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + bndind = graph->bndind; + bndptr = graph->bndptr; + + where = graph->where; + pwgts = graph->pwgts; + + /* Setup the weight intervals of the various subdomains */ + minwgt = idxwspacemalloc(ctrl, nparts); + maxwgt = idxwspacemalloc(ctrl, nparts); + itpwgts = idxwspacemalloc(ctrl, nparts); + tvwgt = idxsum(nparts, pwgts); + ASSERT(tvwgt == idxsum(nvtxs, graph->vwgt)); + + for (i=0; i<nparts; i++) { + itpwgts[i] = tpwgts[i]*tvwgt; + maxwgt[i] = tpwgts[i]*tvwgt*ubfactor; + minwgt[i] = tpwgts[i]*tvwgt*(1.0/ubfactor); + } + + perm = idxwspacemalloc(ctrl, nvtxs); + moved = idxwspacemalloc(ctrl, nvtxs); + + PQueueInit(ctrl, &queue, nvtxs, graph->adjwgtsum[idxamax(nvtxs, graph->adjwgtsum)]); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("Partitions: [%6d %6d]-[%6d %6d], Balance: %5.3f, Nv-Nb[%6d %6d]. Cut: %6d [B]\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], minwgt[0], maxwgt[0], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nvtxs, graph->nbnd, + graph->mincut)); + + for (pass=0; pass<npasses; pass++) { + ASSERT(ComputeCut(graph, where) == graph->mincut); + + /* Check to see if things are out of balance, given the tolerance */ + for (i=0; i<nparts; i++) { + if (pwgts[i] > maxwgt[i]) + break; + } + if (i == nparts) /* Things are balanced. Return right away */ + break; + + PQueueReset(&queue); + idxset(nvtxs, -1, moved); + + oldcut = graph->mincut; + nbnd = graph->nbnd; + + RandomPermute(nbnd, perm, 1); + for (ii=0; ii<nbnd; ii++) { + i = bndind[perm[ii]]; + PQueueInsert(&queue, i, graph->rinfo[i].ed - graph->rinfo[i].id); + moved[i] = 2; + } + + nmoves = 0; + for (;;) { + if ((i = PQueueGetMax(&queue)) == -1) + break; + moved[i] = 1; + + myrinfo = graph->rinfo+i; + from = where[i]; + vwgt = graph->vwgt[i]; + + if (pwgts[from]-vwgt < minwgt[from]) + continue; /* This cannot be moved! */ + + myedegrees = myrinfo->edegrees; + myndegrees = myrinfo->ndegrees; + + for (k=0; k<myndegrees; k++) { + to = myedegrees[k].pid; + if (pwgts[to]+vwgt <= maxwgt[to] || itpwgts[from]*(pwgts[to]+vwgt) <= itpwgts[to]*pwgts[from]) + break; + } + if (k == myndegrees) + continue; /* break out if you did not find a candidate */ + + for (j=k+1; j<myndegrees; j++) { + to = myedegrees[j].pid; + if (itpwgts[myedegrees[k].pid]*pwgts[to] < itpwgts[to]*pwgts[myedegrees[k].pid]) + k = j; + } + + to = myedegrees[k].pid; + + if (pwgts[from] < maxwgt[from] && pwgts[to] > minwgt[to] && myedegrees[k].ed-myrinfo->id < 0) + continue; + + /*===================================================================== + * If we got here, we can now move the vertex from 'from' to 'to' + *======================================================================*/ + graph->mincut -= myedegrees[k].ed-myrinfo->id; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, printf("\t\tMoving %6d to %3d. Gain: %4d. Cut: %6d\n", i, to, myedegrees[k].ed-myrinfo->id, graph->mincut)); + + /* Update where, weight, and ID/ED information of the vertex you moved */ + where[i] = to; + INC_DEC(pwgts[to], pwgts[from], vwgt); + myrinfo->ed += myrinfo->id-myedegrees[k].ed; + SWAP(myrinfo->id, myedegrees[k].ed, j); + if (myedegrees[k].ed == 0) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].pid = from; + + if (myrinfo->ed == 0) + BNDDelete(nbnd, bndind, bndptr, i); + + /* Update the degrees of adjacent vertices */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + ii = adjncy[j]; + me = where[ii]; + + myrinfo = graph->rinfo+ii; + if (myrinfo->edegrees == NULL) { + myrinfo->edegrees = ctrl->wspace.edegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += xadj[ii+1]-xadj[ii]; + } + myedegrees = myrinfo->edegrees; + + ASSERT(CheckRInfo(myrinfo)); + + oldgain = (myrinfo->ed-myrinfo->id); + + if (me == from) { + INC_DEC(myrinfo->ed, myrinfo->id, adjwgt[j]); + + if (myrinfo->ed > 0 && bndptr[ii] == -1) + BNDInsert(nbnd, bndind, bndptr, ii); + } + else if (me == to) { + INC_DEC(myrinfo->id, myrinfo->ed, adjwgt[j]); + + if (myrinfo->ed == 0 && bndptr[ii] != -1) + BNDDelete(nbnd, bndind, bndptr, ii); + } + + /* Remove contribution from the .ed of 'from' */ + if (me != from) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == from) { + if (myedegrees[k].ed == adjwgt[j]) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].ed -= adjwgt[j]; + break; + } + } + } + + /* Add contribution to the .ed of 'to' */ + if (me != to) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == to) { + myedegrees[k].ed += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + myedegrees[myrinfo->ndegrees].pid = to; + myedegrees[myrinfo->ndegrees++].ed = adjwgt[j]; + } + } + + /* Update the queue */ + if (me == to || me == from) { + gain = myrinfo->ed-myrinfo->id; + if (moved[ii] == 2) { + if (myrinfo->ed > 0) + PQueueUpdate(&queue, ii, oldgain, gain); + else { + PQueueDelete(&queue, ii, oldgain); + moved[ii] = -1; + } + } + else if (moved[ii] == -1 && myrinfo->ed > 0) { + PQueueInsert(&queue, ii, gain); + moved[ii] = 2; + } + } + + ASSERT(myrinfo->ndegrees <= xadj[ii+1]-xadj[ii]); + ASSERT(CheckRInfo(myrinfo)); + } + nmoves++; + } + + graph->nbnd = nbnd; + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\t[%6d %6d], Balance: %5.3f, Nb: %6d. Nmoves: %5d, Cut: %6d\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nbnd, nmoves, graph->mincut)); + } + + PQueueFree(ctrl, &queue); + + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kwayrefine.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kwayrefine.c new file mode 100644 index 0000000..a6d58f7 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kwayrefine.c @@ -0,0 +1,392 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * kwayrefine.c + * + * This file contains the driving routines for multilevel k-way refinement + * + * Started 7/28/97 + * George + * + * $Id: kwayrefine.c,v 1.1 2003/07/16 15:55:05 karypis Exp $ + */ + +#include <metis.h> + + +/************************************************************************* +* This function is the entry point of refinement +**************************************************************************/ +void RefineKWay(CtrlType *ctrl, GraphType *orggraph, GraphType *graph, int nparts, float *tpwgts, float ubfactor) +{ + int i, nlevels, mustfree=0; + GraphType *ptr; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->UncoarsenTmr)); + + /* Compute the parameters of the coarsest graph */ + ComputeKWayPartitionParams(ctrl, graph, nparts); + + /* Take care any non-contiguity */ + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->AuxTmr1)); + if (ctrl->RType == RTYPE_KWAYRANDOM_MCONN) { + EliminateComponents(ctrl, graph, nparts, tpwgts, 1.25); + EliminateSubDomainEdges(ctrl, graph, nparts, tpwgts); + EliminateComponents(ctrl, graph, nparts, tpwgts, 1.25); + } + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->AuxTmr1)); + + /* Determine how many levels are there */ + for (ptr=graph, nlevels=0; ptr!=orggraph; ptr=ptr->finer, nlevels++); + + for (i=0; ;i++) { + /* PrintSubDomainGraph(graph, nparts, graph->where); */ + if (ctrl->RType == RTYPE_KWAYRANDOM_MCONN && (i == nlevels/2 || i == nlevels/2+1)) + EliminateSubDomainEdges(ctrl, graph, nparts, tpwgts); + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->RefTmr)); + + if (2*i >= nlevels && !IsBalanced(graph->pwgts, nparts, tpwgts, 1.04*ubfactor)) { + ComputeKWayBalanceBoundary(ctrl, graph, nparts); + if (ctrl->RType == RTYPE_KWAYRANDOM_MCONN) + Greedy_KWayEdgeBalanceMConn(ctrl, graph, nparts, tpwgts, ubfactor, 1); + else + Greedy_KWayEdgeBalance(ctrl, graph, nparts, tpwgts, ubfactor, 1); + ComputeKWayBoundary(ctrl, graph, nparts); + } + + switch (ctrl->RType) { + case RTYPE_KWAYRANDOM: + Random_KWayEdgeRefine(ctrl, graph, nparts, tpwgts, ubfactor, 10, 1); + break; + case RTYPE_KWAYGREEDY: + Greedy_KWayEdgeRefine(ctrl, graph, nparts, tpwgts, ubfactor, 10); + break; + case RTYPE_KWAYRANDOM_MCONN: + Random_KWayEdgeRefineMConn(ctrl, graph, nparts, tpwgts, ubfactor, 10, 1); + break; + } + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->RefTmr)); + + if (graph == orggraph) + break; + + GKfree(&graph->gdata, LTERM); /* Deallocate the graph related arrays */ + + graph = graph->finer; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ProjectTmr)); + if (graph->vwgt == NULL) { + graph->vwgt = idxsmalloc(graph->nvtxs, 1, "RefineKWay: graph->vwgt"); + graph->adjwgt = idxsmalloc(graph->nedges, 1, "RefineKWay: graph->adjwgt"); + mustfree = 1; + } + ProjectKWayPartition(ctrl, graph, nparts); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ProjectTmr)); + } + + if (!IsBalanced(graph->pwgts, nparts, tpwgts, ubfactor)) { + ComputeKWayBalanceBoundary(ctrl, graph, nparts); + if (ctrl->RType == RTYPE_KWAYRANDOM_MCONN) { + Greedy_KWayEdgeBalanceMConn(ctrl, graph, nparts, tpwgts, ubfactor, 8); + Random_KWayEdgeRefineMConn(ctrl, graph, nparts, tpwgts, ubfactor, 10, 0); + } + else { + Greedy_KWayEdgeBalance(ctrl, graph, nparts, tpwgts, ubfactor, 8); + Random_KWayEdgeRefine(ctrl, graph, nparts, tpwgts, ubfactor, 10, 0); + } + } + + /* Take care any trivial non-contiguity */ + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->AuxTmr2)); + EliminateComponents(ctrl, graph, nparts, tpwgts, ubfactor); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->AuxTmr2)); + + if (mustfree) + GKfree(&graph->vwgt, &graph->adjwgt, LTERM); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->UncoarsenTmr)); +} + + +/************************************************************************* +* This function allocates memory for k-way edge refinement +**************************************************************************/ +void AllocateKWayPartitionMemory(CtrlType *ctrl, GraphType *graph, int nparts) +{ + int nvtxs, pad64; + + nvtxs = graph->nvtxs; + + pad64 = (3*nvtxs+nparts)%2; + + graph->rdata = idxmalloc(3*nvtxs+nparts+(sizeof(RInfoType)/sizeof(idxtype))*nvtxs+pad64, "AllocateKWayPartitionMemory: rdata"); + graph->pwgts = graph->rdata; + graph->where = graph->rdata + nparts; + graph->bndptr = graph->rdata + nvtxs + nparts; + graph->bndind = graph->rdata + 2*nvtxs + nparts; + graph->rinfo = (RInfoType *)(graph->rdata + 3*nvtxs+nparts + pad64); + +/* + if (ctrl->wspace.edegrees != NULL) + free(ctrl->wspace.edegrees); + ctrl->wspace.edegrees = (EDegreeType *)GKmalloc(graph->nedges*sizeof(EDegreeType), "AllocateKWayPartitionMemory: edegrees"); +*/ +} + + +/************************************************************************* +* This function computes the initial id/ed +**************************************************************************/ +void ComputeKWayPartitionParams(CtrlType *ctrl, GraphType *graph, int nparts) +{ + int i, j, k, l, nvtxs, nbnd, mincut, me, other; + idxtype *xadj, *vwgt, *adjncy, *adjwgt, *pwgts, *where, *bndind, *bndptr; + RInfoType *rinfo, *myrinfo; + EDegreeType *myedegrees; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + where = graph->where; + pwgts = idxset(nparts, 0, graph->pwgts); + bndind = graph->bndind; + bndptr = idxset(nvtxs, -1, graph->bndptr); + rinfo = graph->rinfo; + + + /*------------------------------------------------------------ + / Compute now the id/ed degrees + /------------------------------------------------------------*/ + ctrl->wspace.cdegree = 0; + nbnd = mincut = 0; + for (i=0; i<nvtxs; i++) { + me = where[i]; + pwgts[me] += vwgt[i]; + + myrinfo = rinfo+i; + myrinfo->id = myrinfo->ed = myrinfo->ndegrees = 0; + myrinfo->edegrees = NULL; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (me != where[adjncy[j]]) + myrinfo->ed += adjwgt[j]; + } + myrinfo->id = graph->adjwgtsum[i] - myrinfo->ed; + + if (myrinfo->ed > 0) + mincut += myrinfo->ed; + + if (myrinfo->ed-myrinfo->id >= 0) + BNDInsert(nbnd, bndind, bndptr, i); + + /* Time to compute the particular external degrees */ + if (myrinfo->ed > 0) { + myedegrees = myrinfo->edegrees = ctrl->wspace.edegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += xadj[i+1]-xadj[i]; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + other = where[adjncy[j]]; + if (me != other) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == other) { + myedegrees[k].ed += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + myedegrees[myrinfo->ndegrees].pid = other; + myedegrees[myrinfo->ndegrees++].ed = adjwgt[j]; + } + } + } + + ASSERT(myrinfo->ndegrees <= xadj[i+1]-xadj[i]); + } + } + + graph->mincut = mincut/2; + graph->nbnd = nbnd; + +} + + + +/************************************************************************* +* This function projects a partition, and at the same time computes the +* parameters for refinement. +**************************************************************************/ +void ProjectKWayPartition(CtrlType *ctrl, GraphType *graph, int nparts) +{ + int i, j, k, nvtxs, nbnd, me, other, istart, iend, ndegrees; + idxtype *xadj, *adjncy, *adjwgt, *adjwgtsum; + idxtype *cmap, *where, *bndptr, *bndind; + idxtype *cwhere; + GraphType *cgraph; + RInfoType *crinfo, *rinfo, *myrinfo; + EDegreeType *myedegrees; + idxtype *htable; + + cgraph = graph->coarser; + cwhere = cgraph->where; + crinfo = cgraph->rinfo; + + nvtxs = graph->nvtxs; + cmap = graph->cmap; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + adjwgtsum = graph->adjwgtsum; + + AllocateKWayPartitionMemory(ctrl, graph, nparts); + where = graph->where; + rinfo = graph->rinfo; + bndind = graph->bndind; + bndptr = idxset(nvtxs, -1, graph->bndptr); + + /* Go through and project partition and compute id/ed for the nodes */ + for (i=0; i<nvtxs; i++) { + k = cmap[i]; + where[i] = cwhere[k]; + cmap[i] = crinfo[k].ed; /* For optimization */ + } + + htable = idxset(nparts, -1, idxwspacemalloc(ctrl, nparts)); + + ctrl->wspace.cdegree = 0; + for (nbnd=0, i=0; i<nvtxs; i++) { + me = where[i]; + + myrinfo = rinfo+i; + myrinfo->id = myrinfo->ed = myrinfo->ndegrees = 0; + myrinfo->edegrees = NULL; + + myrinfo->id = adjwgtsum[i]; + + if (cmap[i] > 0) { /* If it is an interface node. Note cmap[i] = crinfo[cmap[i]].ed */ + istart = xadj[i]; + iend = xadj[i+1]; + + myedegrees = myrinfo->edegrees = ctrl->wspace.edegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += iend-istart; + + ndegrees = 0; + for (j=istart; j<iend; j++) { + other = where[adjncy[j]]; + if (me != other) { + myrinfo->ed += adjwgt[j]; + if ((k = htable[other]) == -1) { + htable[other] = ndegrees; + myedegrees[ndegrees].pid = other; + myedegrees[ndegrees++].ed = adjwgt[j]; + } + else { + myedegrees[k].ed += adjwgt[j]; + } + } + } + myrinfo->id -= myrinfo->ed; + + /* Remove space for edegrees if it was interior */ + if (myrinfo->ed == 0) { + myrinfo->edegrees = NULL; + ctrl->wspace.cdegree -= iend-istart; + } + else { + if (myrinfo->ed-myrinfo->id >= 0) + BNDInsert(nbnd, bndind, bndptr, i); + + myrinfo->ndegrees = ndegrees; + + for (j=0; j<ndegrees; j++) + htable[myedegrees[j].pid] = -1; + } + } + } + + idxcopy(nparts, cgraph->pwgts, graph->pwgts); + graph->mincut = cgraph->mincut; + graph->nbnd = nbnd; + + FreeGraph(graph->coarser); + graph->coarser = NULL; + + idxwspacefree(ctrl, nparts); + + ASSERT(CheckBnd2(graph)); + +} + + + +/************************************************************************* +* This function checks if the partition weights are within the balance +* contraints +**************************************************************************/ +int IsBalanced(idxtype *pwgts, int nparts, float *tpwgts, float ubfactor) +{ + int i, j, tvwgt; + + tvwgt = idxsum(nparts, pwgts); + for (i=0; i<nparts; i++) { + if (pwgts[i] > tpwgts[i]*tvwgt*(ubfactor+0.005)) + return 0; + } + + return 1; +} + + +/************************************************************************* +* This function computes the boundary definition for balancing +**************************************************************************/ +void ComputeKWayBoundary(CtrlType *ctrl, GraphType *graph, int nparts) +{ + int i, nvtxs, nbnd; + idxtype *bndind, *bndptr; + + nvtxs = graph->nvtxs; + bndind = graph->bndind; + bndptr = idxset(nvtxs, -1, graph->bndptr); + + + /*------------------------------------------------------------ + / Compute the new boundary + /------------------------------------------------------------*/ + nbnd = 0; + for (i=0; i<nvtxs; i++) { + if (graph->rinfo[i].ed-graph->rinfo[i].id >= 0) + BNDInsert(nbnd, bndind, bndptr, i); + } + + graph->nbnd = nbnd; +} + +/************************************************************************* +* This function computes the boundary definition for balancing +**************************************************************************/ +void ComputeKWayBalanceBoundary(CtrlType *ctrl, GraphType *graph, int nparts) +{ + int i, nvtxs, nbnd; + idxtype *bndind, *bndptr; + + nvtxs = graph->nvtxs; + bndind = graph->bndind; + bndptr = idxset(nvtxs, -1, graph->bndptr); + + + /*------------------------------------------------------------ + / Compute the new boundary + /------------------------------------------------------------*/ + nbnd = 0; + for (i=0; i<nvtxs; i++) { + if (graph->rinfo[i].ed > 0) + BNDInsert(nbnd, bndind, bndptr, i); + } + + graph->nbnd = nbnd; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kwayvolfm.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kwayvolfm.c new file mode 100644 index 0000000..4e1112d --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kwayvolfm.c @@ -0,0 +1,1778 @@ +/* + * kwayvolfm.c + * + * This file contains code that implements the multilevel k-way refinement + * + * Started 7/8/98 + * George + * + * $Id: kwayvolfm.c,v 1.2 2003/07/31 06:14:01 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function performs k-way refinement +**************************************************************************/ +void Random_KWayVolRefine(CtrlType *ctrl, GraphType *graph, int nparts, float *tpwgts, + float ubfactor, int npasses, int ffactor) +{ + int i, ii, iii, j, jj, k, kk, l, u, pass, nvtxs, nmoves, tvwgt, myndegrees, xgain; + int from, me, to, oldcut, oldvol, vwgt; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *where, *pwgts, *perm, *bndptr, *bndind, *minwgt, *maxwgt, *itpwgts, *updind, *marker, *phtable; + VEDegreeType *myedegrees; + VRInfoType *myrinfo; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + bndptr = graph->bndptr; + bndind = graph->bndind; + + where = graph->where; + pwgts = graph->pwgts; + + /* Setup the weight intervals of the various subdomains */ + minwgt = idxwspacemalloc(ctrl, nparts); + maxwgt = idxwspacemalloc(ctrl, nparts); + itpwgts = idxwspacemalloc(ctrl, nparts); + tvwgt = idxsum(nparts, pwgts); + ASSERT(tvwgt == idxsum(nvtxs, graph->vwgt)); + + updind = idxmalloc(nvtxs, "Random_KWayVolRefine: updind"); + marker = idxsmalloc(nvtxs, 0, "Random_KWayVolRefine: marker"); + phtable = idxsmalloc(nparts, -1, "Random_KWayVolRefine: phtable"); + + for (i=0; i<nparts; i++) { + itpwgts[i] = tpwgts[i]*tvwgt; + maxwgt[i] = tpwgts[i]*tvwgt*ubfactor; + minwgt[i] = tpwgts[i]*tvwgt*(1.0/ubfactor); + } + + perm = idxwspacemalloc(ctrl, nvtxs); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("VolPart: [%5d %5d]-[%5d %5d], Balance: %3.2f, Nv-Nb[%5d %5d]. Cut: %5d, Vol: %5d\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], minwgt[0], maxwgt[0], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nvtxs, graph->nbnd, + graph->mincut, graph->minvol)); + + for (pass=0; pass<npasses; pass++) { + ASSERT(ComputeCut(graph, where) == graph->mincut); + + oldcut = graph->mincut; + oldvol = graph->minvol; + + RandomPermute(graph->nbnd, perm, 1); + for (nmoves=iii=0; iii<graph->nbnd; iii++) { + ii = perm[iii]; + if (ii >= graph->nbnd) + continue; + i = bndind[ii]; + myrinfo = graph->vrinfo+i; + + if (myrinfo->gv >= 0) { /* Total volume gain is too high */ + from = where[i]; + vwgt = graph->vwgt[i]; + + if (myrinfo->id > 0 && pwgts[from]-vwgt < minwgt[from]) + continue; /* This cannot be moved! */ + + xgain = (myrinfo->id == 0 && myrinfo->ed > 0 ? graph->vsize[i] : 0); + + myedegrees = myrinfo->edegrees; + myndegrees = myrinfo->ndegrees; + + for (k=0; k<myndegrees; k++) { + to = myedegrees[k].pid; + if (pwgts[to]+vwgt <= maxwgt[to]+ffactor*myedegrees[k].gv && xgain+myedegrees[k].gv >= 0) + break; + } + if (k == myndegrees) + continue; /* break out if you did not find a candidate */ + + for (j=k+1; j<myndegrees; j++) { + to = myedegrees[j].pid; + if (pwgts[to]+vwgt > maxwgt[to]) + continue; + if (myedegrees[j].gv > myedegrees[k].gv || + (myedegrees[j].gv == myedegrees[k].gv && myedegrees[j].ed > myedegrees[k].ed) || + (myedegrees[j].gv == myedegrees[k].gv && myedegrees[j].ed == myedegrees[k].ed && + itpwgts[myedegrees[k].pid]*pwgts[to] < itpwgts[to]*pwgts[myedegrees[k].pid])) + k = j; + } + + to = myedegrees[k].pid; + + j = 0; + if (xgain+myedegrees[k].gv > 0 || myedegrees[k].ed-myrinfo->id > 0) + j = 1; + else if (myedegrees[k].ed-myrinfo->id == 0) { + if ((iii&5) == 0 || pwgts[from] >= maxwgt[from] || itpwgts[from]*(pwgts[to]+vwgt) < itpwgts[to]*pwgts[from]) + j = 1; + } + if (j == 0) + continue; + + /*===================================================================== + * If we got here, we can now move the vertex from 'from' to 'to' + *======================================================================*/ + INC_DEC(pwgts[to], pwgts[from], vwgt); + graph->mincut -= myedegrees[k].ed-myrinfo->id; + graph->minvol -= (xgain+myedegrees[k].gv); + where[i] = to; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, printf("\t\tMoving %6d from %3d to %3d. Gain: [%4d %4d]. Cut: %6d, Vol: %6d\n", + i, from, to, xgain+myedegrees[k].gv, myedegrees[k].ed-myrinfo->id, graph->mincut, graph->minvol)); + + KWayVolUpdate(ctrl, graph, i, from, to, marker, phtable, updind); + + nmoves++; + + /* CheckVolKWayPartitionParams(ctrl, graph, nparts); */ + } + } + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\t[%6d %6d], Balance: %5.3f, Nb: %6d. Nmoves: %5d, Cut: %6d, Vol: %6d\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nbnd, nmoves, graph->mincut, + graph->minvol)); + + if (graph->minvol == oldvol && graph->mincut == oldcut) + break; + } + + GKfree(&marker, &updind, &phtable, LTERM); + + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nvtxs); +} + + +/************************************************************************* +* This function performs k-way refinement +**************************************************************************/ +void Random_KWayVolRefineMConn(CtrlType *ctrl, GraphType *graph, int nparts, float *tpwgts, + float ubfactor, int npasses, int ffactor) +{ + int i, ii, iii, j, jj, k, kk, l, u, pass, nvtxs, nmoves, tvwgt, myndegrees, xgain; + int from, me, to, oldcut, oldvol, vwgt, nadd, maxndoms; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *where, *pwgts, *perm, *bndptr, *bndind, *minwgt, *maxwgt, *itpwgts, *updind, *marker, *phtable; + idxtype *pmat, *pmatptr, *ndoms; + VEDegreeType *myedegrees; + VRInfoType *myrinfo; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + bndptr = graph->bndptr; + bndind = graph->bndind; + + where = graph->where; + pwgts = graph->pwgts; + + /* Setup the weight intervals of the various subdomains */ + minwgt = idxwspacemalloc(ctrl, nparts); + maxwgt = idxwspacemalloc(ctrl, nparts); + itpwgts = idxwspacemalloc(ctrl, nparts); + tvwgt = idxsum(nparts, pwgts); + ASSERT(tvwgt == idxsum(nvtxs, graph->vwgt)); + + updind = idxmalloc(nvtxs, "Random_KWayVolRefine: updind"); + marker = idxsmalloc(nvtxs, 0, "Random_KWayVolRefine: marker"); + phtable = idxsmalloc(nparts, -1, "Random_KWayVolRefine: phtable"); + + pmat = ctrl->wspace.pmat; + ndoms = idxwspacemalloc(ctrl, nparts); + + ComputeVolSubDomainGraph(graph, nparts, pmat, ndoms); + + for (i=0; i<nparts; i++) { + itpwgts[i] = tpwgts[i]*tvwgt; + maxwgt[i] = tpwgts[i]*tvwgt*ubfactor; + minwgt[i] = tpwgts[i]*tvwgt*(1.0/ubfactor); + } + + perm = idxwspacemalloc(ctrl, nvtxs); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("VolPart: [%5d %5d]-[%5d %5d], Balance: %3.2f, Nv-Nb[%5d %5d]. Cut: %5d, Vol: %5d\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], minwgt[0], maxwgt[0], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nvtxs, graph->nbnd, + graph->mincut, graph->minvol)); + + for (pass=0; pass<npasses; pass++) { + ASSERT(ComputeCut(graph, where) == graph->mincut); + + maxndoms = ndoms[idxamax(nparts, ndoms)]; + + oldcut = graph->mincut; + oldvol = graph->minvol; + + RandomPermute(graph->nbnd, perm, 1); + for (nmoves=iii=0; iii<graph->nbnd; iii++) { + ii = perm[iii]; + if (ii >= graph->nbnd) + continue; + i = bndind[ii]; + myrinfo = graph->vrinfo+i; + + if (myrinfo->gv >= 0) { /* Total volume gain is too high */ + from = where[i]; + vwgt = graph->vwgt[i]; + + if (myrinfo->id > 0 && pwgts[from]-vwgt < minwgt[from]) + continue; /* This cannot be moved! */ + + xgain = (myrinfo->id == 0 && myrinfo->ed > 0 ? graph->vsize[i] : 0); + + myedegrees = myrinfo->edegrees; + myndegrees = myrinfo->ndegrees; + + /* Determine the valid domains */ + for (j=0; j<myndegrees; j++) { + to = myedegrees[j].pid; + phtable[to] = 1; + pmatptr = pmat + to*nparts; + for (nadd=0, k=0; k<myndegrees; k++) { + if (k == j) + continue; + + l = myedegrees[k].pid; + if (pmatptr[l] == 0) { + if (ndoms[l] > maxndoms-1) { + phtable[to] = 0; + nadd = maxndoms; + break; + } + nadd++; + } + } + if (ndoms[to]+nadd > maxndoms) + phtable[to] = 0; + if (nadd == 0) + phtable[to] = 2; + } + + for (k=0; k<myndegrees; k++) { + to = myedegrees[k].pid; + if (!phtable[to]) + continue; + if (pwgts[to]+vwgt <= maxwgt[to]+ffactor*myedegrees[k].gv && xgain+myedegrees[k].gv >= 0) + break; + } + if (k == myndegrees) + continue; /* break out if you did not find a candidate */ + + for (j=k+1; j<myndegrees; j++) { + to = myedegrees[j].pid; + if (!phtable[to] || pwgts[to]+vwgt > maxwgt[to]) + continue; + if (myedegrees[j].gv > myedegrees[k].gv || + (myedegrees[j].gv == myedegrees[k].gv && myedegrees[j].ed > myedegrees[k].ed) || + (myedegrees[j].gv == myedegrees[k].gv && myedegrees[j].ed == myedegrees[k].ed && + itpwgts[myedegrees[k].pid]*pwgts[to] < itpwgts[to]*pwgts[myedegrees[k].pid])) + k = j; + } + + to = myedegrees[k].pid; + + j = 0; + if (xgain+myedegrees[k].gv > 0 || myedegrees[k].ed-myrinfo->id > 0) + j = 1; + else if (myedegrees[k].ed-myrinfo->id == 0) { + if ((iii&5) == 0 || phtable[myedegrees[k].pid] == 2 || pwgts[from] >= maxwgt[from] || itpwgts[from]*(pwgts[to]+vwgt) < itpwgts[to]*pwgts[from]) + j = 1; + } + + if (j == 0) + continue; + + for (j=0; j<myndegrees; j++) + phtable[myedegrees[j].pid] = -1; + + + /*===================================================================== + * If we got here, we can now move the vertex from 'from' to 'to' + *======================================================================*/ + INC_DEC(pwgts[to], pwgts[from], vwgt); + graph->mincut -= myedegrees[k].ed-myrinfo->id; + graph->minvol -= (xgain+myedegrees[k].gv); + where[i] = to; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, printf("\t\tMoving %6d from %3d to %3d. Gain: [%4d %4d]. Cut: %6d, Vol: %6d\n", + i, from, to, xgain+myedegrees[k].gv, myedegrees[k].ed-myrinfo->id, graph->mincut, graph->minvol)); + + /* Update pmat to reflect the move of 'i' */ + pmat[from*nparts+to] += (myrinfo->id-myedegrees[k].ed); + pmat[to*nparts+from] += (myrinfo->id-myedegrees[k].ed); + if (pmat[from*nparts+to] == 0) { + ndoms[from]--; + if (ndoms[from]+1 == maxndoms) + maxndoms = ndoms[idxamax(nparts, ndoms)]; + } + if (pmat[to*nparts+from] == 0) { + ndoms[to]--; + if (ndoms[to]+1 == maxndoms) + maxndoms = ndoms[idxamax(nparts, ndoms)]; + } + + for (j=xadj[i]; j<xadj[i+1]; j++) { + ii = adjncy[j]; + me = where[ii]; + + /* Update pmat to reflect the move of 'i' for domains other than 'from' and 'to' */ + if (me != from && me != to) { + pmat[me*nparts+from] -= adjwgt[j]; + pmat[from*nparts+me] -= adjwgt[j]; + if (pmat[me*nparts+from] == 0) { + ndoms[me]--; + if (ndoms[me]+1 == maxndoms) + maxndoms = ndoms[idxamax(nparts, ndoms)]; + } + if (pmat[from*nparts+me] == 0) { + ndoms[from]--; + if (ndoms[from]+1 == maxndoms) + maxndoms = ndoms[idxamax(nparts, ndoms)]; + } + + if (pmat[me*nparts+to] == 0) { + ndoms[me]++; + if (ndoms[me] > maxndoms) { + IFSET(ctrl->dbglvl, DBG_REFINE, printf("You just increased the maxndoms: %d %d\n", ndoms[me], maxndoms)); + maxndoms = ndoms[me]; + } + } + if (pmat[to*nparts+me] == 0) { + ndoms[to]++; + if (ndoms[to] > maxndoms) { + IFSET(ctrl->dbglvl, DBG_REFINE, printf("You just increased the maxndoms: %d %d\n", ndoms[to], maxndoms)); + maxndoms = ndoms[to]; + } + } + pmat[me*nparts+to] += adjwgt[j]; + pmat[to*nparts+me] += adjwgt[j]; + } + } + + KWayVolUpdate(ctrl, graph, i, from, to, marker, phtable, updind); + + nmoves++; + + /* CheckVolKWayPartitionParams(ctrl, graph, nparts); */ + } + } + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\t[%6d %6d], Balance: %5.3f, Nb: %6d. Nmoves: %5d, Cut: %6d, Vol: %6d\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nbnd, nmoves, graph->mincut, + graph->minvol)); + + if (graph->minvol == oldvol && graph->mincut == oldcut) + break; + } + + GKfree(&marker, &updind, &phtable, LTERM); + + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nvtxs); +} + + + + +/************************************************************************* +* This function performs k-way refinement +**************************************************************************/ +void Greedy_KWayVolBalance(CtrlType *ctrl, GraphType *graph, int nparts, float *tpwgts, + float ubfactor, int npasses) +{ + int i, ii, iii, j, jj, k, kk, l, u, pass, nvtxs, nmoves, tvwgt, myndegrees, xgain; + int from, me, to, vwgt, gain; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *where, *pwgts, *perm, *moved, *bndptr, *bndind, *minwgt, *maxwgt, *itpwgts, *updind, *marker, *phtable; + VEDegreeType *myedegrees; + VRInfoType *myrinfo; + PQueueType queue; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + bndptr = graph->bndptr; + bndind = graph->bndind; + + where = graph->where; + pwgts = graph->pwgts; + + /* Setup the weight intervals of the various subdomains */ + minwgt = idxwspacemalloc(ctrl, nparts); + maxwgt = idxwspacemalloc(ctrl, nparts); + itpwgts = idxwspacemalloc(ctrl, nparts); + tvwgt = idxsum(nparts, pwgts); + ASSERT(tvwgt == idxsum(nvtxs, graph->vwgt)); + + updind = idxmalloc(nvtxs, "Random_KWayVolRefine: updind"); + marker = idxsmalloc(nvtxs, 0, "Random_KWayVolRefine: marker"); + phtable = idxsmalloc(nparts, -1, "Random_KWayVolRefine: phtable"); + + for (i=0; i<nparts; i++) { + itpwgts[i] = tpwgts[i]*tvwgt; + maxwgt[i] = tpwgts[i]*tvwgt*ubfactor; + minwgt[i] = tpwgts[i]*tvwgt*(1.0/ubfactor); + } + + perm = idxwspacemalloc(ctrl, nvtxs); + moved = idxwspacemalloc(ctrl, nvtxs); + + PQueueInit(ctrl, &queue, nvtxs, graph->adjwgtsum[idxamax(nvtxs, graph->adjwgtsum)]); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("VolPart: [%5d %5d]-[%5d %5d], Balance: %3.2f, Nv-Nb[%5d %5d]. Cut: %5d, Vol: %5d [B]\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], minwgt[0], maxwgt[0], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nvtxs, graph->nbnd, + graph->mincut, graph->minvol)); + + + for (pass=0; pass<npasses; pass++) { + ASSERT(ComputeCut(graph, where) == graph->mincut); + /* Check to see if things are out of balance, given the tolerance */ + for (i=0; i<nparts; i++) { + if (pwgts[i] > maxwgt[i]) + break; + } + if (i == nparts) /* Things are balanced. Return right away */ + break; + + PQueueReset(&queue); + idxset(nvtxs, -1, moved); + + RandomPermute(graph->nbnd, perm, 1); + for (ii=0; ii<graph->nbnd; ii++) { + i = bndind[perm[ii]]; + PQueueInsert(&queue, i, graph->vrinfo[i].gv); + moved[i] = 2; + } + + for (nmoves=0;;) { + if ((i = PQueueGetMax(&queue)) == -1) + break; + moved[i] = 1; + + myrinfo = graph->vrinfo+i; + from = where[i]; + vwgt = graph->vwgt[i]; + + if (pwgts[from]-vwgt < minwgt[from]) + continue; /* This cannot be moved! */ + + xgain = (myrinfo->id == 0 && myrinfo->ed > 0 ? graph->vsize[i] : 0); + + myedegrees = myrinfo->edegrees; + myndegrees = myrinfo->ndegrees; + + for (k=0; k<myndegrees; k++) { + to = myedegrees[k].pid; + if (pwgts[to]+vwgt <= maxwgt[to] || + itpwgts[from]*(pwgts[to]+vwgt) <= itpwgts[to]*pwgts[from]) + break; + } + if (k == myndegrees) + continue; /* break out if you did not find a candidate */ + + for (j=k+1; j<myndegrees; j++) { + to = myedegrees[j].pid; + if (itpwgts[myedegrees[k].pid]*pwgts[to] < itpwgts[to]*pwgts[myedegrees[k].pid]) + k = j; + } + + to = myedegrees[k].pid; + + if (pwgts[from] < maxwgt[from] && pwgts[to] > minwgt[to] && + (xgain+myedegrees[k].gv < 0 || + (xgain+myedegrees[k].gv == 0 && myedegrees[k].ed-myrinfo->id < 0)) + ) + continue; + + + /*===================================================================== + * If we got here, we can now move the vertex from 'from' to 'to' + *======================================================================*/ + INC_DEC(pwgts[to], pwgts[from], vwgt); + graph->mincut -= myedegrees[k].ed-myrinfo->id; + graph->minvol -= (xgain+myedegrees[k].gv); + where[i] = to; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, printf("\t\tMoving %6d from %3d to %3d. Gain: [%4d %4d]. Cut: %6d, Vol: %6d\n", + i, from, to, xgain+myedegrees[k].gv, myedegrees[k].ed-myrinfo->id, graph->mincut, graph->minvol)); + + KWayVolUpdate(ctrl, graph, i, from, to, marker, phtable, updind); + + nmoves++; + + /*CheckVolKWayPartitionParams(ctrl, graph, nparts); */ + } + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\t[%6d %6d], Balance: %5.3f, Nb: %6d. Nmoves: %5d, Cut: %6d, Vol: %6d\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nbnd, nmoves, graph->mincut, + graph->minvol)); + + } + + GKfree(&marker, &updind, &phtable, LTERM); + + PQueueFree(ctrl, &queue); + + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + + +/************************************************************************* +* This function performs k-way refinement +**************************************************************************/ +void Greedy_KWayVolBalanceMConn(CtrlType *ctrl, GraphType *graph, int nparts, float *tpwgts, + float ubfactor, int npasses) +{ + int i, ii, iii, j, jj, k, kk, l, u, pass, nvtxs, nmoves, tvwgt, myndegrees, xgain; + int from, me, to, vwgt, gain, maxndoms, nadd; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *where, *pwgts, *perm, *moved, *bndptr, *bndind, *minwgt, *maxwgt, *itpwgts, *updind, *marker, *phtable; + idxtype *pmat, *pmatptr, *ndoms; + VEDegreeType *myedegrees; + VRInfoType *myrinfo; + PQueueType queue; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + bndptr = graph->bndptr; + bndind = graph->bndind; + + where = graph->where; + pwgts = graph->pwgts; + + /* Setup the weight intervals of the various subdomains */ + minwgt = idxwspacemalloc(ctrl, nparts); + maxwgt = idxwspacemalloc(ctrl, nparts); + itpwgts = idxwspacemalloc(ctrl, nparts); + tvwgt = idxsum(nparts, pwgts); + ASSERT(tvwgt == idxsum(nvtxs, graph->vwgt)); + + updind = idxmalloc(nvtxs, "Random_KWayVolRefine: updind"); + marker = idxsmalloc(nvtxs, 0, "Random_KWayVolRefine: marker"); + phtable = idxsmalloc(nparts, -1, "Random_KWayVolRefine: phtable"); + + pmat = ctrl->wspace.pmat; + ndoms = idxwspacemalloc(ctrl, nparts); + + ComputeVolSubDomainGraph(graph, nparts, pmat, ndoms); + + for (i=0; i<nparts; i++) { + itpwgts[i] = tpwgts[i]*tvwgt; + maxwgt[i] = tpwgts[i]*tvwgt*ubfactor; + minwgt[i] = tpwgts[i]*tvwgt*(1.0/ubfactor); + } + + perm = idxwspacemalloc(ctrl, nvtxs); + moved = idxwspacemalloc(ctrl, nvtxs); + + PQueueInit(ctrl, &queue, nvtxs, graph->adjwgtsum[idxamax(nvtxs, graph->adjwgtsum)]); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("VolPart: [%5d %5d]-[%5d %5d], Balance: %3.2f, Nv-Nb[%5d %5d]. Cut: %5d, Vol: %5d [B]\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], minwgt[0], maxwgt[0], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nvtxs, graph->nbnd, + graph->mincut, graph->minvol)); + + + for (pass=0; pass<npasses; pass++) { + ASSERT(ComputeCut(graph, where) == graph->mincut); + /* Check to see if things are out of balance, given the tolerance */ + for (i=0; i<nparts; i++) { + if (pwgts[i] > maxwgt[i]) + break; + } + if (i == nparts) /* Things are balanced. Return right away */ + break; + + PQueueReset(&queue); + idxset(nvtxs, -1, moved); + + RandomPermute(graph->nbnd, perm, 1); + for (ii=0; ii<graph->nbnd; ii++) { + i = bndind[perm[ii]]; + PQueueInsert(&queue, i, graph->vrinfo[i].gv); + moved[i] = 2; + } + + maxndoms = ndoms[idxamax(nparts, ndoms)]; + + for (nmoves=0;;) { + if ((i = PQueueGetMax(&queue)) == -1) + break; + moved[i] = 1; + + myrinfo = graph->vrinfo+i; + from = where[i]; + vwgt = graph->vwgt[i]; + + if (pwgts[from]-vwgt < minwgt[from]) + continue; /* This cannot be moved! */ + + xgain = (myrinfo->id == 0 && myrinfo->ed > 0 ? graph->vsize[i] : 0); + + myedegrees = myrinfo->edegrees; + myndegrees = myrinfo->ndegrees; + + /* Determine the valid domains */ + for (j=0; j<myndegrees; j++) { + to = myedegrees[j].pid; + phtable[to] = 1; + pmatptr = pmat + to*nparts; + for (nadd=0, k=0; k<myndegrees; k++) { + if (k == j) + continue; + + l = myedegrees[k].pid; + if (pmatptr[l] == 0) { + if (ndoms[l] > maxndoms-1) { + phtable[to] = 0; + nadd = maxndoms; + break; + } + nadd++; + } + } + if (ndoms[to]+nadd > maxndoms) + phtable[to] = 0; + } + + for (k=0; k<myndegrees; k++) { + to = myedegrees[k].pid; + if (!phtable[to]) + continue; + if (pwgts[to]+vwgt <= maxwgt[to] || + itpwgts[from]*(pwgts[to]+vwgt) <= itpwgts[to]*pwgts[from]) + break; + } + if (k == myndegrees) + continue; /* break out if you did not find a candidate */ + + for (j=k+1; j<myndegrees; j++) { + to = myedegrees[j].pid; + if (!phtable[to]) + continue; + if (itpwgts[myedegrees[k].pid]*pwgts[to] < itpwgts[to]*pwgts[myedegrees[k].pid]) + k = j; + } + + to = myedegrees[k].pid; + + for (j=0; j<myndegrees; j++) + phtable[myedegrees[j].pid] = -1; + + if (pwgts[from] < maxwgt[from] && pwgts[to] > minwgt[to] && + (xgain+myedegrees[k].gv < 0 || + (xgain+myedegrees[k].gv == 0 && myedegrees[k].ed-myrinfo->id < 0)) + ) + continue; + + + /*===================================================================== + * If we got here, we can now move the vertex from 'from' to 'to' + *======================================================================*/ + INC_DEC(pwgts[to], pwgts[from], vwgt); + graph->mincut -= myedegrees[k].ed-myrinfo->id; + graph->minvol -= (xgain+myedegrees[k].gv); + where[i] = to; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, printf("\t\tMoving %6d from %3d to %3d. Gain: [%4d %4d]. Cut: %6d, Vol: %6d\n", + i, from, to, xgain+myedegrees[k].gv, myedegrees[k].ed-myrinfo->id, graph->mincut, graph->minvol)); + + /* Update pmat to reflect the move of 'i' */ + pmat[from*nparts+to] += (myrinfo->id-myedegrees[k].ed); + pmat[to*nparts+from] += (myrinfo->id-myedegrees[k].ed); + if (pmat[from*nparts+to] == 0) { + ndoms[from]--; + if (ndoms[from]+1 == maxndoms) + maxndoms = ndoms[idxamax(nparts, ndoms)]; + } + if (pmat[to*nparts+from] == 0) { + ndoms[to]--; + if (ndoms[to]+1 == maxndoms) + maxndoms = ndoms[idxamax(nparts, ndoms)]; + } + + for (j=xadj[i]; j<xadj[i+1]; j++) { + ii = adjncy[j]; + me = where[ii]; + + /* Update pmat to reflect the move of 'i' for domains other than 'from' and 'to' */ + if (me != from && me != to) { + pmat[me*nparts+from] -= adjwgt[j]; + pmat[from*nparts+me] -= adjwgt[j]; + if (pmat[me*nparts+from] == 0) { + ndoms[me]--; + if (ndoms[me]+1 == maxndoms) + maxndoms = ndoms[idxamax(nparts, ndoms)]; + } + if (pmat[from*nparts+me] == 0) { + ndoms[from]--; + if (ndoms[from]+1 == maxndoms) + maxndoms = ndoms[idxamax(nparts, ndoms)]; + } + + if (pmat[me*nparts+to] == 0) { + ndoms[me]++; + if (ndoms[me] > maxndoms) { + IFSET(ctrl->dbglvl, DBG_REFINE, printf("You just increased the maxndoms: %d %d\n", ndoms[me], maxndoms)); + maxndoms = ndoms[me]; + } + } + if (pmat[to*nparts+me] == 0) { + ndoms[to]++; + if (ndoms[to] > maxndoms) { + IFSET(ctrl->dbglvl, DBG_REFINE, printf("You just increased the maxndoms: %d %d\n", ndoms[to], maxndoms)); + maxndoms = ndoms[to]; + } + } + pmat[me*nparts+to] += adjwgt[j]; + pmat[to*nparts+me] += adjwgt[j]; + } + } + + KWayVolUpdate(ctrl, graph, i, from, to, marker, phtable, updind); + + nmoves++; + + /*CheckVolKWayPartitionParams(ctrl, graph, nparts); */ + } + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\t[%6d %6d], Balance: %5.3f, Nb: %6d. Nmoves: %5d, Cut: %6d, Vol: %6d\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nbnd, nmoves, graph->mincut, + graph->minvol)); + + } + + GKfree(&marker, &updind, &phtable, LTERM); + + PQueueFree(ctrl, &queue); + + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + + + +/************************************************************************* +* This function updates the edge and volume gains as a result of moving +* v from 'from' to 'to'. +* The working arrays marker and phtable are assumed to be initialized to +* -1, and they left to -1 upon return +**************************************************************************/ +void KWayVolUpdate(CtrlType *ctrl, GraphType *graph, int v, int from, int to, + idxtype *marker, idxtype *phtable, idxtype *updind) +{ + int ii, iii, j, jj, k, kk, l, u, nupd, other, me, myidx; + idxtype *xadj, *vsize, *adjncy, *adjwgt, *where; + VEDegreeType *myedegrees, *oedegrees; + VRInfoType *myrinfo, *orinfo; + + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + vsize = graph->vsize; + where = graph->where; + + myrinfo = graph->vrinfo+v; + myedegrees = myrinfo->edegrees; + + + /*====================================================================== + * Remove the contributions on the gain made by 'v'. + *=====================================================================*/ + for (k=0; k<myrinfo->ndegrees; k++) + phtable[myedegrees[k].pid] = k; + phtable[from] = k; + + myidx = phtable[to]; /* Keep track of the index in myedegrees of the 'to' domain */ + + for (j=xadj[v]; j<xadj[v+1]; j++) { + ii = adjncy[j]; + other = where[ii]; + orinfo = graph->vrinfo+ii; + oedegrees = orinfo->edegrees; + + if (other == from) { + for (k=0; k<orinfo->ndegrees; k++) { + if (phtable[oedegrees[k].pid] == -1) + oedegrees[k].gv += vsize[v]; + } + } + else { + ASSERT(phtable[other] != -1); + + if (myedegrees[phtable[other]].ned > 1) { + for (k=0; k<orinfo->ndegrees; k++) { + if (phtable[oedegrees[k].pid] == -1) + oedegrees[k].gv += vsize[v]; + } + } + else { /* There is only one connection */ + for (k=0; k<orinfo->ndegrees; k++) { + if (phtable[oedegrees[k].pid] != -1) + oedegrees[k].gv -= vsize[v]; + } + } + } + } + + for (k=0; k<myrinfo->ndegrees; k++) + phtable[myedegrees[k].pid] = -1; + phtable[from] = -1; + + + /*====================================================================== + * Update the id/ed of vertex 'v' + *=====================================================================*/ + myrinfo->ed += myrinfo->id-myedegrees[myidx].ed; + SWAP(myrinfo->id, myedegrees[myidx].ed, j); + SWAP(myrinfo->nid, myedegrees[myidx].ned, j); + if (myedegrees[myidx].ed == 0) + myedegrees[myidx] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[myidx].pid = from; + + /*====================================================================== + * Update the degrees of adjacent vertices and their volume gains + *=====================================================================*/ + marker[v] = 1; + updind[0] = v; + nupd = 1; + for (j=xadj[v]; j<xadj[v+1]; j++) { + ii = adjncy[j]; + me = where[ii]; + + if (!marker[ii]) { /* The marking is done for boundary and max gv calculations */ + marker[ii] = 2; + updind[nupd++] = ii; + } + + myrinfo = graph->vrinfo+ii; + if (myrinfo->edegrees == NULL) { + myrinfo->edegrees = ctrl->wspace.vedegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += xadj[ii+1]-xadj[ii]; + } + myedegrees = myrinfo->edegrees; + + if (me == from) { + INC_DEC(myrinfo->ed, myrinfo->id, adjwgt[j]); + myrinfo->nid--; + } + else if (me == to) { + INC_DEC(myrinfo->id, myrinfo->ed, adjwgt[j]); + myrinfo->nid++; + } + + /* Remove the edgeweight from the 'pid == from' entry of the vertex */ + if (me != from) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == from) { + if (myedegrees[k].ned == 1) { + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + marker[ii] = 1; /* You do a complete .gv calculation */ + + /* All vertices adjacent to 'ii' need to be updated */ + for (jj=xadj[ii]; jj<xadj[ii+1]; jj++) { + u = adjncy[jj]; + other = where[u]; + orinfo = graph->vrinfo+u; + oedegrees = orinfo->edegrees; + + for (kk=0; kk<orinfo->ndegrees; kk++) { + if (oedegrees[kk].pid == from) { + oedegrees[kk].gv -= vsize[ii]; + break; + } + } + } + } + else { + myedegrees[k].ed -= adjwgt[j]; + myedegrees[k].ned--; + + /* Update the gv due to single 'ii' connection to 'from' */ + if (myedegrees[k].ned == 1) { + /* find the vertex 'u' that 'ii' was connected into 'from' */ + for (jj=xadj[ii]; jj<xadj[ii+1]; jj++) { + u = adjncy[jj]; + other = where[u]; + orinfo = graph->vrinfo+u; + oedegrees = orinfo->edegrees; + + if (other == from) { + for (kk=0; kk<orinfo->ndegrees; kk++) + oedegrees[kk].gv += vsize[ii]; + break; + } + } + } + } + + break; + } + } + } + + /* Add the edgeweight to the 'pid == to' entry of the vertex */ + if (me != to) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == to) { + myedegrees[k].ed += adjwgt[j]; + myedegrees[k].ned++; + + /* Update the gv due to non-single 'ii' connection to 'to' */ + if (myedegrees[k].ned == 2) { + /* find the vertex 'u' that 'ii' was connected into 'to' */ + for (jj=xadj[ii]; jj<xadj[ii+1]; jj++) { + u = adjncy[jj]; + other = where[u]; + orinfo = graph->vrinfo+u; + oedegrees = orinfo->edegrees; + + if (u != v && other == to) { + for (kk=0; kk<orinfo->ndegrees; kk++) + oedegrees[kk].gv -= vsize[ii]; + break; + } + } + } + break; + } + } + + if (k == myrinfo->ndegrees) { + myedegrees[myrinfo->ndegrees].pid = to; + myedegrees[myrinfo->ndegrees].ed = adjwgt[j]; + myedegrees[myrinfo->ndegrees++].ned = 1; + marker[ii] = 1; /* You do a complete .gv calculation */ + + /* All vertices adjacent to 'ii' need to be updated */ + for (jj=xadj[ii]; jj<xadj[ii+1]; jj++) { + u = adjncy[jj]; + other = where[u]; + orinfo = graph->vrinfo+u; + oedegrees = orinfo->edegrees; + + for (kk=0; kk<orinfo->ndegrees; kk++) { + if (oedegrees[kk].pid == to) { + oedegrees[kk].gv += vsize[ii]; + if (!marker[u]) { /* Need to update boundary etc */ + marker[u] = 2; + updind[nupd++] = u; + } + break; + } + } + } + } + } + + ASSERT(myrinfo->ndegrees <= xadj[ii+1]-xadj[ii]); + } + + /*====================================================================== + * Add the contributions on the volume gain due to 'v' + *=====================================================================*/ + myrinfo = graph->vrinfo+v; + myedegrees = myrinfo->edegrees; + for (k=0; k<myrinfo->ndegrees; k++) + phtable[myedegrees[k].pid] = k; + phtable[to] = k; + + for (j=xadj[v]; j<xadj[v+1]; j++) { + ii = adjncy[j]; + other = where[ii]; + orinfo = graph->vrinfo+ii; + oedegrees = orinfo->edegrees; + + if (other == to) { + for (k=0; k<orinfo->ndegrees; k++) { + if (phtable[oedegrees[k].pid] == -1) + oedegrees[k].gv -= vsize[v]; + } + } + else { + ASSERT(phtable[other] != -1); + + if (myedegrees[phtable[other]].ned > 1) { + for (k=0; k<orinfo->ndegrees; k++) { + if (phtable[oedegrees[k].pid] == -1) + oedegrees[k].gv -= vsize[v]; + } + } + else { /* There is only one connection */ + for (k=0; k<orinfo->ndegrees; k++) { + if (phtable[oedegrees[k].pid] != -1) + oedegrees[k].gv += vsize[v]; + } + } + } + } + for (k=0; k<myrinfo->ndegrees; k++) + phtable[myedegrees[k].pid] = -1; + phtable[to] = -1; + + + /*====================================================================== + * Recompute the volume information of the 'hard' nodes, and update the + * max volume gain for all the update vertices + *=====================================================================*/ + ComputeKWayVolume(graph, nupd, updind, marker, phtable); + + + /*====================================================================== + * Maintain a consistent boundary + *=====================================================================*/ + for (j=0; j<nupd; j++) { + k = updind[j]; + marker[k] = 0; + myrinfo = graph->vrinfo+k; + + if ((myrinfo->gv >= 0 || myrinfo->ed-myrinfo->id >= 0) && graph->bndptr[k] == -1) + BNDInsert(graph->nbnd, graph->bndind, graph->bndptr, k); + + if (myrinfo->gv < 0 && myrinfo->ed-myrinfo->id < 0 && graph->bndptr[k] != -1) + BNDDelete(graph->nbnd, graph->bndind, graph->bndptr, k); + } + +} + + + + +/************************************************************************* +* This function computes the initial id/ed +**************************************************************************/ +void ComputeKWayVolume(GraphType *graph, int nupd, idxtype *updind, idxtype *marker, idxtype *phtable) +{ + int ii, iii, i, j, k, kk, l, nvtxs, me, other, pid; + idxtype *xadj, *vsize, *adjncy, *adjwgt, *where; + VRInfoType *rinfo, *myrinfo, *orinfo; + VEDegreeType *myedegrees, *oedegrees; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vsize = graph->vsize; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + rinfo = graph->vrinfo; + + + /*------------------------------------------------------------ + / Compute now the iv/ev degrees + /------------------------------------------------------------*/ + for (iii=0; iii<nupd; iii++) { + i = updind[iii]; + me = where[i]; + + myrinfo = rinfo+i; + myedegrees = myrinfo->edegrees; + + if (marker[i] == 1) { /* Only complete gain updates go through */ + for (k=0; k<myrinfo->ndegrees; k++) + myedegrees[k].gv = 0; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + ii = adjncy[j]; + other = where[ii]; + orinfo = rinfo+ii; + oedegrees = orinfo->edegrees; + + for (kk=0; kk<orinfo->ndegrees; kk++) + phtable[oedegrees[kk].pid] = kk; + phtable[other] = 1; + + if (me == other) { + /* Find which domains 'i' is connected and 'ii' is not and update their gain */ + for (k=0; k<myrinfo->ndegrees; k++) { + if (phtable[myedegrees[k].pid] == -1) + myedegrees[k].gv -= vsize[ii]; + } + } + else { + ASSERT(phtable[me] != -1); + + /* I'm the only connection of 'ii' in 'me' */ + if (oedegrees[phtable[me]].ned == 1) { + /* Increase the gains for all the common domains between 'i' and 'ii' */ + for (k=0; k<myrinfo->ndegrees; k++) { + if (phtable[myedegrees[k].pid] != -1) + myedegrees[k].gv += vsize[ii]; + } + } + else { + /* Find which domains 'i' is connected and 'ii' is not and update their gain */ + for (k=0; k<myrinfo->ndegrees; k++) { + if (phtable[myedegrees[k].pid] == -1) + myedegrees[k].gv -= vsize[ii]; + } + } + } + + for (kk=0; kk<orinfo->ndegrees; kk++) + phtable[oedegrees[kk].pid] = -1; + phtable[other] = -1; + + } + } + + myrinfo->gv = -MAXIDX; + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].gv > myrinfo->gv) + myrinfo->gv = myedegrees[k].gv; + } + if (myrinfo->ed > 0 && myrinfo->id == 0) + myrinfo->gv += vsize[i]; + + } + +} + + + +/************************************************************************* +* This function computes the total volume +**************************************************************************/ +int ComputeVolume(GraphType *graph, idxtype *where) +{ + int i, j, k, me, nvtxs, nparts, totalv; + idxtype *xadj, *adjncy, *vsize, *marker; + + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + vsize = (graph->vsize == NULL ? graph->vwgt : graph->vsize); + + nparts = where[idxamax(nvtxs, where)]+1; + marker = idxsmalloc(nparts, -1, "ComputeVolume: marker"); + + totalv = 0; + + for (i=0; i<nvtxs; i++) { + marker[where[i]] = i; + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = where[adjncy[j]]; + if (marker[k] != i) { + marker[k] = i; + totalv += vsize[i]; + } + } + } + + free(marker); + + return totalv; +} + + + + + +/************************************************************************* +* This function computes the initial id/ed +**************************************************************************/ +void CheckVolKWayPartitionParams(CtrlType *ctrl, GraphType *graph, int nparts) +{ + int i, ii, j, k, kk, l, nvtxs, nbnd, mincut, minvol, me, other, pid; + idxtype *xadj, *vsize, *adjncy, *adjwgt, *pwgts, *where, *bndind, *bndptr; + VRInfoType *rinfo, *myrinfo, *orinfo, tmprinfo; + VEDegreeType *myedegrees, *oedegrees, *tmpdegrees; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vsize = graph->vsize; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + rinfo = graph->vrinfo; + + tmpdegrees = (VEDegreeType *)GKmalloc(nparts*sizeof(VEDegreeType), "CheckVolKWayPartitionParams: tmpdegrees"); + + /*------------------------------------------------------------ + / Compute now the iv/ev degrees + /------------------------------------------------------------*/ + for (i=0; i<nvtxs; i++) { + me = where[i]; + + myrinfo = rinfo+i; + myedegrees = myrinfo->edegrees; + + for (k=0; k<myrinfo->ndegrees; k++) + tmpdegrees[k] = myedegrees[k]; + + tmprinfo.ndegrees = myrinfo->ndegrees; + tmprinfo.id = myrinfo->id; + tmprinfo.ed = myrinfo->ed; + + myrinfo = &tmprinfo; + myedegrees = tmpdegrees; + + + for (k=0; k<myrinfo->ndegrees; k++) + myedegrees[k].gv = 0; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + ii = adjncy[j]; + other = where[ii]; + orinfo = rinfo+ii; + oedegrees = orinfo->edegrees; + + if (me == other) { + /* Find which domains 'i' is connected and 'ii' is not and update their gain */ + for (k=0; k<myrinfo->ndegrees; k++) { + pid = myedegrees[k].pid; + for (kk=0; kk<orinfo->ndegrees; kk++) { + if (oedegrees[kk].pid == pid) + break; + } + if (kk == orinfo->ndegrees) + myedegrees[k].gv -= vsize[ii]; + } + } + else { + /* Find the orinfo[me].ed and see if I'm the only connection */ + for (k=0; k<orinfo->ndegrees; k++) { + if (oedegrees[k].pid == me) + break; + } + + if (oedegrees[k].ned == 1) { /* I'm the only connection of 'ii' in 'me' */ + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == other) { + myedegrees[k].gv += vsize[ii]; + break; + } + } + + /* Increase the gains for all the common domains between 'i' and 'ii' */ + for (k=0; k<myrinfo->ndegrees; k++) { + if ((pid = myedegrees[k].pid) == other) + continue; + for (kk=0; kk<orinfo->ndegrees; kk++) { + if (oedegrees[kk].pid == pid) { + myedegrees[k].gv += vsize[ii]; + break; + } + } + } + + } + else { + /* Find which domains 'i' is connected and 'ii' is not and update their gain */ + for (k=0; k<myrinfo->ndegrees; k++) { + if ((pid = myedegrees[k].pid) == other) + continue; + for (kk=0; kk<orinfo->ndegrees; kk++) { + if (oedegrees[kk].pid == pid) + break; + } + if (kk == orinfo->ndegrees) + myedegrees[k].gv -= vsize[ii]; + } + } + } + } + + myrinfo = rinfo+i; + myedegrees = myrinfo->edegrees; + + for (k=0; k<myrinfo->ndegrees; k++) { + pid = myedegrees[k].pid; + for (kk=0; kk<tmprinfo.ndegrees; kk++) { + if (tmpdegrees[kk].pid == pid) { + if (tmpdegrees[kk].gv != myedegrees[k].gv) + printf("[%d %d %d %d]\n", i, pid, myedegrees[k].gv, tmpdegrees[kk].gv); + break; + } + } + } + + } + + free(tmpdegrees); + +} + + +/************************************************************************* +* This function computes the subdomain graph +**************************************************************************/ +void ComputeVolSubDomainGraph(GraphType *graph, int nparts, idxtype *pmat, idxtype *ndoms) +{ + int i, j, k, me, nvtxs, ndegrees; + idxtype *xadj, *adjncy, *adjwgt, *where; + VRInfoType *rinfo; + VEDegreeType *edegrees; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + rinfo = graph->vrinfo; + + idxset(nparts*nparts, 0, pmat); + + for (i=0; i<nvtxs; i++) { + if (rinfo[i].ed > 0) { + me = where[i]; + ndegrees = rinfo[i].ndegrees; + edegrees = rinfo[i].edegrees; + + k = me*nparts; + for (j=0; j<ndegrees; j++) + pmat[k+edegrees[j].pid] += edegrees[j].ed; + } + } + + for (i=0; i<nparts; i++) { + ndoms[i] = 0; + for (j=0; j<nparts; j++) { + if (pmat[i*nparts+j] > 0) + ndoms[i]++; + } + } +} + + + +/************************************************************************* +* This function computes the subdomain graph +**************************************************************************/ +void EliminateVolSubDomainEdges(CtrlType *ctrl, GraphType *graph, int nparts, float *tpwgts) +{ + int i, ii, j, k, me, other, nvtxs, total, max, avg, totalout, nind, ncand, ncand2, target, target2, nadd; + int min, move, cpwgt, tvwgt; + idxtype *xadj, *adjncy, *vwgt, *adjwgt, *pwgts, *where, *maxpwgt, *pmat, *ndoms, *mypmat, *otherpmat, *ind; + KeyValueType *cand, *cand2; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + vwgt = graph->vwgt; + adjwgt = graph->adjwgt; + + where = graph->where; + pwgts = idxset(nparts, 0, graph->pwgts); + + maxpwgt = idxwspacemalloc(ctrl, nparts); + ndoms = idxwspacemalloc(ctrl, nparts); + otherpmat = idxwspacemalloc(ctrl, nparts); + ind = idxwspacemalloc(ctrl, nvtxs); + pmat = idxset(nparts*nparts, 0, ctrl->wspace.pmat); + + cand = (KeyValueType *)GKmalloc(nparts*sizeof(KeyValueType), "EliminateSubDomainEdges: cand"); + cand2 = (KeyValueType *)GKmalloc(nparts*sizeof(KeyValueType), "EliminateSubDomainEdges: cand"); + + /* Compute the pmat matrix */ + for (i=0; i<nvtxs; i++) { + me = where[i]; + pwgts[me] += vwgt[i]; + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (where[k] != me) + pmat[me*nparts+where[k]] += adjwgt[j]; + } + } + + /* Compute the maximum allowed weight for each domain */ + tvwgt = idxsum(nparts, pwgts); + for (i=0; i<nparts; i++) + maxpwgt[i] = 1.25*tpwgts[i]*tvwgt; + + /* Determine the domain connectivity */ + for (i=0; i<nparts; i++) { + for (k=0, j=0; j<nparts; j++) { + if (pmat[i*nparts+j] > 0) + k++; + } + ndoms[i] = k; + } + + /* Get into the loop eliminating subdomain connections */ + for (;;) { + total = idxsum(nparts, ndoms); + avg = total/nparts; + max = ndoms[idxamax(nparts, ndoms)]; + + /* printf("Adjacent Subdomain Stats: Total: %3d, Max: %3d, Avg: %3d\n", total, max, avg); */ + + if (max < 1.5*avg) + break; + + me = idxamax(nparts, ndoms); + mypmat = pmat + me*nparts; + totalout = idxsum(nparts, mypmat); + + /*printf("Me: %d, TotalOut: %d,\n", me, totalout);*/ + + /* Sort the connections according to their cut */ + for (ncand2=0, i=0; i<nparts; i++) { + if (mypmat[i] > 0) { + cand2[ncand2].key = mypmat[i]; + cand2[ncand2++].val = i; + } + } + ikeysort(ncand2, cand2); + + move = 0; + for (min=0; min<ncand2; min++) { + if (cand2[min].key > totalout/(2*ndoms[me])) + break; + + other = cand2[min].val; + + /*printf("\tMinOut: %d to %d\n", mypmat[other], other);*/ + + idxset(nparts, 0, otherpmat); + + /* Go and find the vertices in 'other' that are connected in 'me' */ + for (nind=0, i=0; i<nvtxs; i++) { + if (where[i] == other) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (where[adjncy[j]] == me) { + ind[nind++] = i; + break; + } + } + } + } + + /* Go and construct the otherpmat to see where these nind vertices are connected to */ + for (cpwgt=0, ii=0; ii<nind; ii++) { + i = ind[ii]; + cpwgt += vwgt[i]; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (where[k] != other) + otherpmat[where[k]] += adjwgt[j]; + } + } + + for (ncand=0, i=0; i<nparts; i++) { + if (otherpmat[i] > 0) { + cand[ncand].key = -otherpmat[i]; + cand[ncand++].val = i; + } + } + ikeysort(ncand, cand); + + /* + * Go through and the select the first domain that is common with 'me', and + * does not increase the ndoms[target] higher than my ndoms, subject to the + * maxpwgt constraint. Traversal is done from the mostly connected to the least. + */ + target = target2 = -1; + for (i=0; i<ncand; i++) { + k = cand[i].val; + + if (mypmat[k] > 0) { + if (pwgts[k] + cpwgt > maxpwgt[k]) /* Check if balance will go off */ + continue; + + for (j=0; j<nparts; j++) { + if (otherpmat[j] > 0 && ndoms[j] >= ndoms[me]-1 && pmat[nparts*j+k] == 0) + break; + } + if (j == nparts) { /* No bad second level effects */ + for (nadd=0, j=0; j<nparts; j++) { + if (otherpmat[j] > 0 && pmat[nparts*k+j] == 0) + nadd++; + } + + /*printf("\t\tto=%d, nadd=%d, %d\n", k, nadd, ndoms[k]);*/ + if (target2 == -1 && ndoms[k]+nadd < ndoms[me]) { + target2 = k; + } + if (nadd == 0) { + target = k; + break; + } + } + } + } + if (target == -1 && target2 != -1) + target = target2; + + if (target == -1) { + /* printf("\t\tCould not make the move\n");*/ + continue; + } + + /*printf("\t\tMoving to %d\n", target);*/ + + /* Update the partition weights */ + INC_DEC(pwgts[target], pwgts[other], cpwgt); + + /* Set all nind vertices to belong to 'target' */ + for (ii=0; ii<nind; ii++) { + i = ind[ii]; + where[i] = target; + + /* First remove any contribution that this vertex may have made */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (where[k] != other) { + if (pmat[nparts*other + where[k]] == 0) + printf("Something wrong\n"); + pmat[nparts*other + where[k]] -= adjwgt[j]; + if (pmat[nparts*other + where[k]] == 0) + ndoms[other]--; + + if (pmat[nparts*where[k] + other] == 0) + printf("Something wrong\n"); + pmat[nparts*where[k] + other] -= adjwgt[j]; + if (pmat[nparts*where[k] + other] == 0) + ndoms[where[k]]--; + } + } + + /* Next add the new contributions as a result of the move */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (where[k] != target) { + if (pmat[nparts*target + where[k]] == 0) + ndoms[target]++; + pmat[nparts*target + where[k]] += adjwgt[j]; + + if (pmat[nparts*where[k] + target] == 0) + ndoms[where[k]]++; + pmat[nparts*where[k] + target] += adjwgt[j]; + } + } + } + + move = 1; + break; + } + + if (move == 0) + break; + } + + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nvtxs); + + GKfree(&cand, &cand2, LTERM); +} + + + +/************************************************************************* +* This function finds all the connected components induced by the +* partitioning vector in wgraph->where and tries to push them around to +* remove some of them +**************************************************************************/ +void EliminateVolComponents(CtrlType *ctrl, GraphType *graph, int nparts, float *tpwgts, float ubfactor) +{ + int i, ii, j, jj, k, me, nvtxs, tvwgt, first, last, nleft, ncmps, cwgt, ncand, other, target, deltawgt; + idxtype *xadj, *adjncy, *vwgt, *adjwgt, *where, *pwgts, *maxpwgt; + idxtype *cpvec, *touched, *perm, *todo, *cind, *cptr, *npcmps; + KeyValueType *cand; + int recompute=0; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + vwgt = graph->vwgt; + adjwgt = graph->adjwgt; + + where = graph->where; + pwgts = idxset(nparts, 0, graph->pwgts); + + touched = idxset(nvtxs, 0, idxwspacemalloc(ctrl, nvtxs)); + cptr = idxwspacemalloc(ctrl, nvtxs+1); + cind = idxwspacemalloc(ctrl, nvtxs); + perm = idxwspacemalloc(ctrl, nvtxs); + todo = idxwspacemalloc(ctrl, nvtxs); + maxpwgt = idxwspacemalloc(ctrl, nparts); + cpvec = idxwspacemalloc(ctrl, nparts); + npcmps = idxset(nparts, 0, idxwspacemalloc(ctrl, nparts)); + + for (i=0; i<nvtxs; i++) + perm[i] = todo[i] = i; + + /* Find the connected componends induced by the partition */ + ncmps = -1; + first = last = 0; + nleft = nvtxs; + while (nleft > 0) { + if (first == last) { /* Find another starting vertex */ + cptr[++ncmps] = first; + ASSERT(touched[todo[0]] == 0); + i = todo[0]; + cind[last++] = i; + touched[i] = 1; + me = where[i]; + npcmps[me]++; + } + + i = cind[first++]; + k = perm[i]; + j = todo[k] = todo[--nleft]; + perm[j] = k; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (where[k] == me && !touched[k]) { + cind[last++] = k; + touched[k] = 1; + } + } + } + cptr[++ncmps] = first; + + /* printf("I found %d components, for this %d-way partition\n", ncmps, nparts); */ + + if (ncmps > nparts) { /* There are more components than processors */ + cand = (KeyValueType *)GKmalloc(nparts*sizeof(KeyValueType), "EliminateSubDomainEdges: cand"); + + /* First determine the partition sizes and max allowed load imbalance */ + for (i=0; i<nvtxs; i++) + pwgts[where[i]] += vwgt[i]; + tvwgt = idxsum(nparts, pwgts); + for (i=0; i<nparts; i++) + maxpwgt[i] = ubfactor*tpwgts[i]*tvwgt; + + deltawgt = tvwgt/(100*nparts); + deltawgt = 5; + + for (i=0; i<ncmps; i++) { + me = where[cind[cptr[i]]]; /* Get the domain of this component */ + if (npcmps[me] == 1) + continue; /* Skip it because it is contigous */ + + /*printf("Trying to move %d from %d\n", i, me); */ + + /* Determine the connectivity */ + idxset(nparts, 0, cpvec); + for (cwgt=0, j=cptr[i]; j<cptr[i+1]; j++) { + ii = cind[j]; + cwgt += vwgt[ii]; + for (jj=xadj[ii]; jj<xadj[ii+1]; jj++) { + other = where[adjncy[jj]]; + if (me != other) + cpvec[other] += adjwgt[jj]; + } + } + + /*printf("\tCmp weight: %d\n", cwgt);*/ + + if (cwgt > .30*pwgts[me]) + continue; /* Skip the component if it is over 30% of the weight */ + + for (ncand=0, j=0; j<nparts; j++) { + if (cpvec[j] > 0) { + cand[ncand].key = -cpvec[j]; + cand[ncand++].val = j; + } + } + if (ncand == 0) + continue; + + ikeysort(ncand, cand); + + target = -1; + for (j=0; j<ncand; j++) { + k = cand[j].val; + if (cwgt < deltawgt || pwgts[k] + cwgt < maxpwgt[k]) { + target = k; + break; + } + } + + /*printf("\tMoving it to %d [%d]\n", target, cpvec[target]);*/ + + if (target != -1) { + /* Assign all the vertices of 'me' to 'target' and update data structures */ + pwgts[me] -= cwgt; + pwgts[target] += cwgt; + npcmps[me]--; + + for (j=cptr[i]; j<cptr[i+1]; j++) + where[cind[j]] = target; + + graph->mincut -= cpvec[target]; + recompute = 1; + } + } + + free(cand); + } + + if (recompute) { + int ttlv; + idxtype *marker; + + marker = idxset(nparts, -1, cpvec); + for (ttlv=0, i=0; i<nvtxs; i++) { + marker[where[i]] = i; + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (marker[where[adjncy[j]]] != i) { + ttlv += graph->vsize[i]; + marker[where[adjncy[j]]] = i; + } + } + } + graph->minvol = ttlv; + } + + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs+1); + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kwayvolrefine.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kwayvolrefine.c new file mode 100644 index 0000000..7cf248d --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/kwayvolrefine.c @@ -0,0 +1,468 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * kwayvolrefine.c + * + * This file contains the driving routines for multilevel k-way refinement + * + * Started 7/28/97 + * George + * + * $Id: kwayvolrefine.c,v 1.1 2003/07/16 15:55:05 karypis Exp $ + */ + +#include <metis.h> + + +/************************************************************************* +* This function is the entry point of refinement +**************************************************************************/ +void RefineVolKWay(CtrlType *ctrl, GraphType *orggraph, GraphType *graph, int nparts, + float *tpwgts, float ubfactor) +{ + int i, nlevels; + GraphType *ptr; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->UncoarsenTmr)); + + /* Take care any non-contiguity */ + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->AuxTmr1)); + if (ctrl->RType == RTYPE_KWAYRANDOM_MCONN) { + ComputeVolKWayPartitionParams(ctrl, graph, nparts); + EliminateVolComponents(ctrl, graph, nparts, tpwgts, 1.25); + EliminateVolSubDomainEdges(ctrl, graph, nparts, tpwgts); + EliminateVolComponents(ctrl, graph, nparts, tpwgts, 1.25); + } + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->AuxTmr1)); + + + /* Determine how many levels are there */ + for (ptr=graph, nlevels=0; ptr!=orggraph; ptr=ptr->finer, nlevels++); + + /* Compute the parameters of the coarsest graph */ + ComputeVolKWayPartitionParams(ctrl, graph, nparts); + + for (i=0; ;i++) { + /*PrintSubDomainGraph(graph, nparts, graph->where);*/ + MALLOC_CHECK(NULL); + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->RefTmr)); + + if (2*i >= nlevels && !IsBalanced(graph->pwgts, nparts, tpwgts, 1.04*ubfactor)) { + ComputeVolKWayBalanceBoundary(ctrl, graph, nparts); + switch (ctrl->RType) { + case RTYPE_KWAYRANDOM: + Greedy_KWayVolBalance(ctrl, graph, nparts, tpwgts, ubfactor, 1); + break; + case RTYPE_KWAYRANDOM_MCONN: + Greedy_KWayVolBalanceMConn(ctrl, graph, nparts, tpwgts, ubfactor, 1); + break; + } + ComputeVolKWayBoundary(ctrl, graph, nparts); + } + + switch (ctrl->RType) { + case RTYPE_KWAYRANDOM: + Random_KWayVolRefine(ctrl, graph, nparts, tpwgts, ubfactor, 10, 1); + break; + case RTYPE_KWAYRANDOM_MCONN: + Random_KWayVolRefineMConn(ctrl, graph, nparts, tpwgts, ubfactor, 10, 1); + break; + } + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->RefTmr)); + + if (graph == orggraph) + break; + + GKfree(&graph->gdata, LTERM); /* Deallocate the graph related arrays */ + + graph = graph->finer; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ProjectTmr)); + ProjectVolKWayPartition(ctrl, graph, nparts); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ProjectTmr)); + } + + if (!IsBalanced(graph->pwgts, nparts, tpwgts, ubfactor)) { + ComputeVolKWayBalanceBoundary(ctrl, graph, nparts); + switch (ctrl->RType) { + case RTYPE_KWAYRANDOM: + Greedy_KWayVolBalance(ctrl, graph, nparts, tpwgts, ubfactor, 8); + Random_KWayVolRefine(ctrl, graph, nparts, tpwgts, ubfactor, 10, 0); + break; + case RTYPE_KWAYRANDOM_MCONN: + Greedy_KWayVolBalanceMConn(ctrl, graph, nparts, tpwgts, ubfactor, 8); + Random_KWayVolRefineMConn(ctrl, graph, nparts, tpwgts, ubfactor, 10, 0); + break; + } + } + + EliminateVolComponents(ctrl, graph, nparts, tpwgts, ubfactor); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->UncoarsenTmr)); +} + + + +/************************************************************************* +* This function allocates memory for k-way edge refinement +**************************************************************************/ +void AllocateVolKWayPartitionMemory(CtrlType *ctrl, GraphType *graph, int nparts) +{ + int nvtxs, pad64; + + nvtxs = graph->nvtxs; + + pad64 = (3*nvtxs+nparts)%2; + + graph->rdata = idxmalloc(3*nvtxs+nparts+(sizeof(VRInfoType)/sizeof(idxtype))*nvtxs+pad64, "AllocateVolKWayPartitionMemory: rdata"); + graph->pwgts = graph->rdata; + graph->where = graph->rdata + nparts; + graph->bndptr = graph->rdata + nvtxs + nparts; + graph->bndind = graph->rdata + 2*nvtxs + nparts; + graph->vrinfo = (VRInfoType *)(graph->rdata + 3*nvtxs+nparts + pad64); + +} + + + +/************************************************************************* +* This function computes the initial id/ed +**************************************************************************/ +void ComputeVolKWayPartitionParams(CtrlType *ctrl, GraphType *graph, int nparts) +{ + int i, ii, j, k, kk, l, nvtxs, nbnd, mincut, minvol, me, other, pid; + idxtype *xadj, *vwgt, *adjncy, *adjwgt, *pwgts, *where; + VRInfoType *rinfo, *myrinfo, *orinfo; + VEDegreeType *myedegrees, *oedegrees; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + where = graph->where; + pwgts = idxset(nparts, 0, graph->pwgts); + rinfo = graph->vrinfo; + +starttimer(ctrl->AuxTmr1); + + /*------------------------------------------------------------ + / Compute now the id/ed degrees + /------------------------------------------------------------*/ + ctrl->wspace.cdegree = 0; + mincut = 0; + for (i=0; i<nvtxs; i++) { + me = where[i]; + pwgts[me] += vwgt[i]; + + myrinfo = rinfo+i; + myrinfo->id = myrinfo->ed = myrinfo->nid = myrinfo->ndegrees = 0; + myrinfo->edegrees = NULL; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (me == where[adjncy[j]]) { + myrinfo->id += adjwgt[j]; + myrinfo->nid++; + } + } + myrinfo->ed = graph->adjwgtsum[i] - myrinfo->id; + + mincut += myrinfo->ed; + + /* Time to compute the particular external degrees */ + if (myrinfo->ed > 0) { + myedegrees = myrinfo->edegrees = ctrl->wspace.vedegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += xadj[i+1]-xadj[i]; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + other = where[adjncy[j]]; + if (me != other) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == other) { + myedegrees[k].ed += adjwgt[j]; + myedegrees[k].ned++; + break; + } + } + if (k == myrinfo->ndegrees) { + myedegrees[myrinfo->ndegrees].gv = 0; + myedegrees[myrinfo->ndegrees].pid = other; + myedegrees[myrinfo->ndegrees].ed = adjwgt[j]; + myedegrees[myrinfo->ndegrees++].ned = 1; + } + } + } + + ASSERT(myrinfo->ndegrees <= xadj[i+1]-xadj[i]); + } + } + graph->mincut = mincut/2; + +stoptimer(ctrl->AuxTmr1); + + ComputeKWayVolGains(ctrl, graph, nparts); + +} + + + +/************************************************************************* +* This function computes the initial id/ed +**************************************************************************/ +void ComputeKWayVolGains(CtrlType *ctrl, GraphType *graph, int nparts) +{ + int i, ii, j, k, kk, l, nvtxs, me, other, pid, myndegrees; + idxtype *xadj, *vsize, *adjncy, *adjwgt, *where, *bndind, *bndptr, *ophtable; + VRInfoType *rinfo, *myrinfo, *orinfo; + VEDegreeType *myedegrees, *oedegrees; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vsize = graph->vsize; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + where = graph->where; + bndind = graph->bndind; + bndptr = idxset(nvtxs, -1, graph->bndptr); + rinfo = graph->vrinfo; + +starttimer(ctrl->AuxTmr2); + + ophtable = idxset(nparts, -1, idxwspacemalloc(ctrl, nparts)); + + /*------------------------------------------------------------ + / Compute now the iv/ev degrees + /------------------------------------------------------------*/ + graph->minvol = graph->nbnd = 0; + for (i=0; i<nvtxs; i++) { + myrinfo = rinfo+i; + myrinfo->gv = -MAXIDX; + + if (myrinfo->ndegrees > 0) { + me = where[i]; + myedegrees = myrinfo->edegrees; + myndegrees = myrinfo->ndegrees; + + graph->minvol += myndegrees*vsize[i]; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + ii = adjncy[j]; + other = where[ii]; + orinfo = rinfo+ii; + oedegrees = orinfo->edegrees; + + for (k=0; k<orinfo->ndegrees; k++) + ophtable[oedegrees[k].pid] = k; + ophtable[other] = 1; /* this is to simplify coding */ + + if (me == other) { + /* Find which domains 'i' is connected and 'ii' is not and update their gain */ + for (k=0; k<myndegrees; k++) { + if (ophtable[myedegrees[k].pid] == -1) + myedegrees[k].gv -= vsize[ii]; + } + } + else { + ASSERT(ophtable[me] != -1); + + if (oedegrees[ophtable[me]].ned == 1) { /* I'm the only connection of 'ii' in 'me' */ + /* Increase the gains for all the common domains between 'i' and 'ii' */ + for (k=0; k<myndegrees; k++) { + if (ophtable[myedegrees[k].pid] != -1) + myedegrees[k].gv += vsize[ii]; + } + } + else { + /* Find which domains 'i' is connected and 'ii' is not and update their gain */ + for (k=0; k<myndegrees; k++) { + if (ophtable[myedegrees[k].pid] == -1) + myedegrees[k].gv -= vsize[ii]; + } + } + } + + for (kk=0; kk<orinfo->ndegrees; kk++) + ophtable[oedegrees[kk].pid] = -1; + ophtable[other] = -1; + } + + /* Compute the max vgain */ + for (k=0; k<myndegrees; k++) { + if (myedegrees[k].gv > myrinfo->gv) + myrinfo->gv = myedegrees[k].gv; + } + } + + if (myrinfo->ed > 0 && myrinfo->id == 0) + myrinfo->gv += vsize[i]; + + if (myrinfo->gv >= 0 || myrinfo->ed-myrinfo->id >= 0) + BNDInsert(graph->nbnd, bndind, bndptr, i); + } + +stoptimer(ctrl->AuxTmr2); + + idxwspacefree(ctrl, nparts); + +} + + + +/************************************************************************* +* This function projects a partition, and at the same time computes the +* parameters for refinement. +**************************************************************************/ +void ProjectVolKWayPartition(CtrlType *ctrl, GraphType *graph, int nparts) +{ + int i, j, k, nvtxs, me, other, istart, iend, ndegrees; + idxtype *xadj, *adjncy, *adjwgt, *adjwgtsum; + idxtype *cmap, *where; + idxtype *cwhere; + GraphType *cgraph; + VRInfoType *crinfo, *rinfo, *myrinfo; + VEDegreeType *myedegrees; + idxtype *htable; + + cgraph = graph->coarser; + cwhere = cgraph->where; + crinfo = cgraph->vrinfo; + + nvtxs = graph->nvtxs; + cmap = graph->cmap; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + adjwgtsum = graph->adjwgtsum; + + AllocateVolKWayPartitionMemory(ctrl, graph, nparts); + where = graph->where; + rinfo = graph->vrinfo; + + /* Go through and project partition and compute id/ed for the nodes */ + for (i=0; i<nvtxs; i++) { + k = cmap[i]; + where[i] = cwhere[k]; + cmap[i] = crinfo[k].ed; /* For optimization */ + } + + htable = idxset(nparts, -1, idxwspacemalloc(ctrl, nparts)); + + ctrl->wspace.cdegree = 0; + for (i=0; i<nvtxs; i++) { + me = where[i]; + + myrinfo = rinfo+i; + myrinfo->id = myrinfo->ed = myrinfo->nid = myrinfo->ndegrees = 0; + myrinfo->edegrees = NULL; + + myrinfo->id = adjwgtsum[i]; + myrinfo->nid = xadj[i+1]-xadj[i]; + + if (cmap[i] > 0) { /* If it is an interface node. Note cmap[i] = crinfo[cmap[i]].ed */ + istart = xadj[i]; + iend = xadj[i+1]; + + myedegrees = myrinfo->edegrees = ctrl->wspace.vedegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += iend-istart; + + ndegrees = 0; + for (j=istart; j<iend; j++) { + other = where[adjncy[j]]; + if (me != other) { + myrinfo->ed += adjwgt[j]; + myrinfo->nid--; + if ((k = htable[other]) == -1) { + htable[other] = ndegrees; + myedegrees[ndegrees].gv = 0; + myedegrees[ndegrees].pid = other; + myedegrees[ndegrees].ed = adjwgt[j]; + myedegrees[ndegrees++].ned = 1; + } + else { + myedegrees[k].ed += adjwgt[j]; + myedegrees[k].ned++; + } + } + } + myrinfo->id -= myrinfo->ed; + + /* Remove space for edegrees if it was interior */ + if (myrinfo->ed == 0) { + myrinfo->edegrees = NULL; + ctrl->wspace.cdegree -= iend-istart; + } + else { + myrinfo->ndegrees = ndegrees; + + for (j=0; j<ndegrees; j++) + htable[myedegrees[j].pid] = -1; + } + } + } + + ComputeKWayVolGains(ctrl, graph, nparts); + + idxcopy(nparts, cgraph->pwgts, graph->pwgts); + graph->mincut = cgraph->mincut; + + FreeGraph(graph->coarser); + graph->coarser = NULL; + + idxwspacefree(ctrl, nparts); + +} + + + +/************************************************************************* +* This function computes the boundary definition for balancing +**************************************************************************/ +void ComputeVolKWayBoundary(CtrlType *ctrl, GraphType *graph, int nparts) +{ + int i, nvtxs, nbnd; + idxtype *bndind, *bndptr; + + nvtxs = graph->nvtxs; + bndind = graph->bndind; + bndptr = idxset(nvtxs, -1, graph->bndptr); + + + /*------------------------------------------------------------ + / Compute the new boundary + /------------------------------------------------------------*/ + nbnd = 0; + for (i=0; i<nvtxs; i++) { + if (graph->vrinfo[i].gv >=0 || graph->vrinfo[i].ed-graph->vrinfo[i].id >= 0) + BNDInsert(nbnd, bndind, bndptr, i); + } + + graph->nbnd = nbnd; +} + +/************************************************************************* +* This function computes the boundary definition for balancing +**************************************************************************/ +void ComputeVolKWayBalanceBoundary(CtrlType *ctrl, GraphType *graph, int nparts) +{ + int i, nvtxs, nbnd; + idxtype *bndind, *bndptr; + + nvtxs = graph->nvtxs; + bndind = graph->bndind; + bndptr = idxset(nvtxs, -1, graph->bndptr); + + + /*------------------------------------------------------------ + / Compute the new boundary + /------------------------------------------------------------*/ + nbnd = 0; + for (i=0; i<nvtxs; i++) { + if (graph->vrinfo[i].ed > 0) + BNDInsert(nbnd, bndind, bndptr, i); + } + + graph->nbnd = nbnd; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/macros.h b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/macros.h new file mode 100644 index 0000000..97e42a2 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/macros.h @@ -0,0 +1,138 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * macros.h + * + * This file contains macros used in multilevel + * + * Started 9/25/94 + * George + * + * $Id: macros.h,v 1.7 2003/07/21 19:11:40 karypis Exp $ + * + */ + + +/************************************************************************* +* The following macro returns a random number in the specified range +**************************************************************************/ +#define RandomInRange(u) ((int)(1.0*(u)*rand()/(RAND_MAX+1.0))) + +#define amax(a, b) ((a) >= (b) ? (a) : (b)) +#define amin(a, b) ((a) >= (b) ? (b) : (a)) + +#define AND(a, b) ((a) < 0 ? ((-(a))&(b)) : ((a)&(b))) +#define OR(a, b) ((a) < 0 ? -((-(a))|(b)) : ((a)|(b))) +#define XOR(a, b) ((a) < 0 ? -((-(a))^(b)) : ((a)^(b))) + +#define SWAP(a, b, tmp) \ + do {(tmp) = (a); (a) = (b); (b) = (tmp);} while(0) + +#define INC_DEC(a, b, val) \ + do {(a) += (val); (b) -= (val);} while(0) + + +#define scopy(n, a, b) (float *)memcpy((void *)(b), (void *)(a), sizeof(float)*(n)) +#define idxcopy(n, a, b) (idxtype *)memcpy((void *)(b), (void *)(a), sizeof(idxtype)*(n)) + +#define HASHFCT(key, size) ((key)%(size)) + + +/************************************************************************* +* Timer macros +**************************************************************************/ +#define cleartimer(tmr) (tmr = 0.0) +#define starttimer(tmr) (tmr -= seconds()) +#define stoptimer(tmr) (tmr += seconds()) +#define gettimer(tmr) (tmr) + + +/************************************************************************* +* This macro is used to handle dbglvl +**************************************************************************/ +#define IFSET(a, flag, cmd) if ((a)&(flag)) (cmd); + +/************************************************************************* +* These macros are used for debuging memory leaks +**************************************************************************/ +#ifdef DMALLOC +#define imalloc(n, msg) (malloc(sizeof(int)*(n))) +#define fmalloc(n, msg) (malloc(sizeof(float)*(n))) +#define idxmalloc(n, msg) (malloc(sizeof(idxtype)*(n))) +#define ismalloc(n, val, msg) (iset((n), (val), malloc(sizeof(int)*(n)))) +#define idxsmalloc(n, val, msg) (idxset((n), (val), malloc(sizeof(idxtype)*(n)))) +#define GKmalloc(a, b) (malloc((a))) +#endif + +#ifdef DMALLOC +# define MALLOC_CHECK(ptr); +/* +# define MALLOC_CHECK(ptr) \ + if (malloc_verify((ptr)) == DMALLOC_VERIFY_ERROR) { \ + printf("***MALLOC_CHECK failed on line %d of file %s: " #ptr "\n", \ + __LINE__, __FILE__); \ + abort(); \ + } +*/ +#else +# define MALLOC_CHECK(ptr) ; +#endif + + + +/************************************************************************* +* This macro converts a length array in a CSR one +**************************************************************************/ +#define MAKECSR(i, n, a) \ + do { \ + for (i=1; i<n; i++) a[i] += a[i-1]; \ + for (i=n; i>0; i--) a[i] = a[i-1]; \ + a[0] = 0; \ + } while(0) + + +/************************************************************************* +* These macros insert and remove nodes from the boundary list +**************************************************************************/ +#define BNDInsert(nbnd, bndind, bndptr, vtx) \ + do { \ + ASSERT(bndptr[vtx] == -1); \ + bndind[nbnd] = vtx; \ + bndptr[vtx] = nbnd++;\ + } while(0) + +#define BNDDelete(nbnd, bndind, bndptr, vtx) \ + do { \ + ASSERT(bndptr[vtx] != -1); \ + bndind[bndptr[vtx]] = bndind[--nbnd]; \ + bndptr[bndind[nbnd]] = bndptr[vtx]; \ + bndptr[vtx] = -1; \ + } while(0) + + + +/************************************************************************* +* These are debugging macros +**************************************************************************/ +#ifdef DEBUG +# define ASSERT(expr) \ + if (!(expr)) { \ + printf("***ASSERTION failed on line %d of file %s: " #expr "\n", \ + __LINE__, __FILE__); \ + abort(); \ + } +#else +# define ASSERT(expr) ; +#endif + +#ifdef DEBUG +# define ASSERTP(expr, msg) \ + if (!(expr)) { \ + printf("***ASSERTION failed on line %d of file %s: " #expr "\n", \ + __LINE__, __FILE__); \ + printf msg ; \ + abort(); \ + } +#else +# define ASSERTP(expr, msg) ; +#endif diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/match.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/match.c new file mode 100644 index 0000000..509f457 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/match.c @@ -0,0 +1,267 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * match.c + * + * This file contains the code that computes matchings and creates the next + * level coarse graph. + * + * Started 7/23/97 + * George + * + * $Id: match.c,v 1.1 2003/07/16 15:55:06 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function finds a matching using the HEM heuristic +**************************************************************************/ +void Match_RM(CtrlType *ctrl, GraphType *graph) +{ + int i, ii, j, nvtxs, cnvtxs, maxidx; + idxtype *xadj, *vwgt, *adjncy, *adjwgt; + idxtype *match, *cmap, *perm; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->MatchTmr)); + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + cmap = graph->cmap; + match = idxset(nvtxs, UNMATCHED, idxwspacemalloc(ctrl, nvtxs)); + + perm = idxwspacemalloc(ctrl, nvtxs); + RandomPermute(nvtxs, perm, 1); + + cnvtxs = 0; + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + + if (match[i] == UNMATCHED) { /* Unmatched */ + maxidx = i; + + /* Find a random matching, subject to maxvwgt constraints */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (match[adjncy[j]] == UNMATCHED && vwgt[i]+vwgt[adjncy[j]] <= ctrl->maxvwgt) { + maxidx = adjncy[j]; + break; + } + } + + cmap[i] = cmap[maxidx] = cnvtxs++; + match[i] = maxidx; + match[maxidx] = i; + } + } + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->MatchTmr)); + + CreateCoarseGraph(ctrl, graph, cnvtxs, match, perm); + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + +/************************************************************************* +* This function finds a matching using the HEM heuristic +**************************************************************************/ +void Match_RM_NVW(CtrlType *ctrl, GraphType *graph) +{ + int i, ii, j, nvtxs, cnvtxs, maxidx; + idxtype *xadj, *adjncy; + idxtype *match, *cmap, *perm; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->MatchTmr)); + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + + cmap = graph->cmap; + match = idxset(nvtxs, UNMATCHED, idxwspacemalloc(ctrl, nvtxs)); + + perm = idxwspacemalloc(ctrl, nvtxs); + RandomPermute(nvtxs, perm, 1); + + cnvtxs = 0; + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + + if (match[i] == UNMATCHED) { /* Unmatched */ + maxidx = i; + + /* Find a random matching, subject to maxvwgt constraints */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (match[adjncy[j]] == UNMATCHED) { + maxidx = adjncy[j]; + break; + } + } + + cmap[i] = cmap[maxidx] = cnvtxs++; + match[i] = maxidx; + match[maxidx] = i; + } + } + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->MatchTmr)); + + CreateCoarseGraph_NVW(ctrl, graph, cnvtxs, match, perm); + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + + +/************************************************************************* +* This function finds a matching using the HEM heuristic +**************************************************************************/ +void Match_HEM(CtrlType *ctrl, GraphType *graph) +{ + int i, ii, j, k, nvtxs, cnvtxs, maxidx, maxwgt; + idxtype *xadj, *vwgt, *adjncy, *adjwgt; + idxtype *match, *cmap, *perm; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->MatchTmr)); + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + cmap = graph->cmap; + match = idxset(nvtxs, UNMATCHED, idxwspacemalloc(ctrl, nvtxs)); + + perm = idxwspacemalloc(ctrl, nvtxs); + RandomPermute(nvtxs, perm, 1); + + cnvtxs = 0; + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + + if (match[i] == UNMATCHED) { /* Unmatched */ + maxidx = i; + maxwgt = 0; + + /* Find a heavy-edge matching, subject to maxvwgt constraints */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (match[k] == UNMATCHED && maxwgt < adjwgt[j] && vwgt[i]+vwgt[k] <= ctrl->maxvwgt) { + maxwgt = adjwgt[j]; + maxidx = adjncy[j]; + } + } + + cmap[i] = cmap[maxidx] = cnvtxs++; + match[i] = maxidx; + match[maxidx] = i; + } + } + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->MatchTmr)); + + CreateCoarseGraph(ctrl, graph, cnvtxs, match, perm); + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + + +/************************************************************************* +* This function finds a matching using the HEM heuristic +**************************************************************************/ +void Match_SHEM(CtrlType *ctrl, GraphType *graph) +{ + int i, ii, j, k, nvtxs, cnvtxs, maxidx, maxwgt, avgdegree; + idxtype *xadj, *vwgt, *adjncy, *adjwgt; + idxtype *match, *cmap, *degrees, *perm, *tperm; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->MatchTmr)); + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + cmap = graph->cmap; + match = idxset(nvtxs, UNMATCHED, idxwspacemalloc(ctrl, nvtxs)); + + perm = idxwspacemalloc(ctrl, nvtxs); + tperm = idxwspacemalloc(ctrl, nvtxs); + degrees = idxwspacemalloc(ctrl, nvtxs); + + RandomPermute(nvtxs, tperm, 1); + avgdegree = 0.7*(xadj[nvtxs]/nvtxs); + for (i=0; i<nvtxs; i++) + degrees[i] = (xadj[i+1]-xadj[i] > avgdegree ? avgdegree : xadj[i+1]-xadj[i]); + BucketSortKeysInc(nvtxs, avgdegree, degrees, tperm, perm); + + cnvtxs = 0; + + /* Take care any islands. Islands are matched with non-islands due to coarsening */ + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + + if (match[i] == UNMATCHED) { /* Unmatched */ + if (xadj[i] < xadj[i+1]) + break; + + maxidx = i; + for (j=nvtxs-1; j>ii; j--) { + k = perm[j]; + if (match[k] == UNMATCHED && xadj[k] < xadj[k+1]) { + maxidx = k; + break; + } + } + + cmap[i] = cmap[maxidx] = cnvtxs++; + match[i] = maxidx; + match[maxidx] = i; + } + } + + /* Continue with normal matching */ + for (; ii<nvtxs; ii++) { + i = perm[ii]; + + if (match[i] == UNMATCHED) { /* Unmatched */ + maxidx = i; + maxwgt = 0; + + /* Find a heavy-edge matching, subject to maxvwgt constraints */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (match[adjncy[j]] == UNMATCHED && maxwgt < adjwgt[j] && vwgt[i]+vwgt[adjncy[j]] <= ctrl->maxvwgt) { + maxwgt = adjwgt[j]; + maxidx = adjncy[j]; + } + } + + cmap[i] = cmap[maxidx] = cnvtxs++; + match[i] = maxidx; + match[maxidx] = i; + } + } + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->MatchTmr)); + + idxwspacefree(ctrl, nvtxs); /* degrees */ + idxwspacefree(ctrl, nvtxs); /* tperm */ + + CreateCoarseGraph(ctrl, graph, cnvtxs, match, perm); + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mbalance.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mbalance.c new file mode 100644 index 0000000..65e9961 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mbalance.c @@ -0,0 +1,260 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mbalance.c + * + * This file contains code that is used to forcefully balance either + * bisections or k-sections + * + * Started 7/29/97 + * George + * + * $Id: mbalance.c,v 1.1 2003/07/16 15:55:07 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function is the entry point of the bisection balancing algorithms. +**************************************************************************/ +void MocBalance2Way(CtrlType *ctrl, GraphType *graph, float *tpwgts, float lbfactor) +{ + + if (Compute2WayHLoadImbalance(graph->ncon, graph->npwgts, tpwgts) < lbfactor) + return; + + MocGeneral2WayBalance(ctrl, graph, tpwgts, lbfactor); + +} + + +/************************************************************************* +* This function performs an edge-based FM refinement +**************************************************************************/ +void MocGeneral2WayBalance(CtrlType *ctrl, GraphType *graph, float *tpwgts, float lbfactor) +{ + int i, ii, j, k, l, kwgt, nvtxs, ncon, nbnd, nswaps, from, to, pass, me, limit, tmp, cnum; + idxtype *xadj, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind; + idxtype *moved, *swaps, *perm, *qnum; + float *nvwgt, *npwgts, mindiff[MAXNCON], origbal, minbal, newbal; + PQueueType parts[MAXNCON][2]; + int higain, oldgain, mincut, newcut, mincutorder; + int qsizes[MAXNCON][2]; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + id = graph->id; + ed = graph->ed; + npwgts = graph->npwgts; + bndptr = graph->bndptr; + bndind = graph->bndind; + + moved = idxwspacemalloc(ctrl, nvtxs); + swaps = idxwspacemalloc(ctrl, nvtxs); + perm = idxwspacemalloc(ctrl, nvtxs); + qnum = idxwspacemalloc(ctrl, nvtxs); + + limit = amin(amax(0.01*nvtxs, 15), 100); + + /* Initialize the queues */ + for (i=0; i<ncon; i++) { + PQueueInit(ctrl, &parts[i][0], nvtxs, PLUS_GAINSPAN+1); + PQueueInit(ctrl, &parts[i][1], nvtxs, PLUS_GAINSPAN+1); + qsizes[i][0] = qsizes[i][1] = 0; + } + + for (i=0; i<nvtxs; i++) { + qnum[i] = samax(ncon, nvwgt+i*ncon); + qsizes[qnum[i]][where[i]]++; + } + +/* + printf("Weight Distribution: \t"); + for (i=0; i<ncon; i++) + printf(" [%d %d]", qsizes[i][0], qsizes[i][1]); + printf("\n"); +*/ + + for (from=0; from<2; from++) { + for (j=0; j<ncon; j++) { + if (qsizes[j][from] == 0) { + for (i=0; i<nvtxs; i++) { + if (where[i] != from) + continue; + + k = samax2(ncon, nvwgt+i*ncon); + if (k == j && qsizes[qnum[i]][from] > qsizes[j][from] && nvwgt[i*ncon+qnum[i]] < 1.3*nvwgt[i*ncon+j]) { + qsizes[qnum[i]][from]--; + qsizes[j][from]++; + qnum[i] = j; + } + } + } + } + } + +/* + printf("Weight Distribution (after):\t "); + for (i=0; i<ncon; i++) + printf(" [%d %d]", qsizes[i][0], qsizes[i][1]); + printf("\n"); +*/ + + + + for (i=0; i<ncon; i++) + mindiff[i] = fabs(tpwgts[0]-npwgts[i]); + minbal = origbal = Compute2WayHLoadImbalance(ncon, npwgts, tpwgts); + newcut = mincut = graph->mincut; + mincutorder = -1; + + if (ctrl->dbglvl&DBG_REFINE) { + printf("Parts: ["); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf("] T[%.3f %.3f], Nv-Nb[%5d, %5d]. ICut: %6d, LB: %.3f [B]\n", tpwgts[0], tpwgts[1], graph->nvtxs, graph->nbnd, graph->mincut, origbal); + } + + idxset(nvtxs, -1, moved); + + ASSERT(ComputeCut(graph, where) == graph->mincut); + ASSERT(CheckBnd(graph)); + + /* Insert all nodes in the priority queues */ + nbnd = graph->nbnd; + RandomPermute(nvtxs, perm, 1); + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + PQueueInsert(&parts[qnum[i]][where[i]], i, ed[i]-id[i]); + } + + for (nswaps=0; nswaps<nvtxs; nswaps++) { + if (minbal < lbfactor) + break; + + SelectQueue(ncon, npwgts, tpwgts, &from, &cnum, parts); + to = (from+1)%2; + + if (from == -1 || (higain = PQueueGetMax(&parts[cnum][from])) == -1) + break; + + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + newcut -= (ed[higain]-id[higain]); + newbal = Compute2WayHLoadImbalance(ncon, npwgts, tpwgts); + + if (newbal < minbal || (newbal == minbal && + (newcut < mincut || (newcut == mincut && BetterBalance(ncon, npwgts, tpwgts, mindiff))))) { + mincut = newcut; + minbal = newbal; + mincutorder = nswaps; + for (i=0; i<ncon; i++) + mindiff[i] = fabs(tpwgts[0]-npwgts[i]); + } + else if (nswaps-mincutorder > limit) { /* We hit the limit, undo last move */ + newcut += (ed[higain]-id[higain]); + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + break; + } + + where[higain] = to; + moved[higain] = nswaps; + swaps[nswaps] = higain; + + if (ctrl->dbglvl&DBG_MOVEINFO) { + printf("Moved %6d from %d(%d). Gain: %5d, Cut: %5d, NPwgts: ", higain, from, cnum, ed[higain]-id[higain], newcut); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf(", %.3f LB: %.3f\n", minbal, newbal); + } + + + /************************************************************** + * Update the id[i]/ed[i] values of the affected nodes + ***************************************************************/ + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + if (ed[higain] > 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + oldgain = ed[k]-id[k]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + /* Update the queue position */ + if (moved[k] == -1) + PQueueUpdate(&parts[qnum[k]][where[k]], k, oldgain, ed[k]-id[k]); + + /* Update its boundary information */ + if (ed[k] == 0 && bndptr[k] != -1) + BNDDelete(nbnd, bndind, bndptr, k); + else if (ed[k] > 0 && bndptr[k] == -1) + BNDInsert(nbnd, bndind, bndptr, k); + } + } + + + + /**************************************************************** + * Roll back computations + *****************************************************************/ + for (nswaps--; nswaps>mincutorder; nswaps--) { + higain = swaps[nswaps]; + + to = where[higain] = (where[higain]+1)%2; + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + else if (ed[higain] > 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+((to+1)%2)*ncon, 1); + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + if (bndptr[k] != -1 && ed[k] == 0) + BNDDelete(nbnd, bndind, bndptr, k); + if (bndptr[k] == -1 && ed[k] > 0) + BNDInsert(nbnd, bndind, bndptr, k); + } + } + + if (ctrl->dbglvl&DBG_REFINE) { + printf("\tMincut: %6d at %5d, NBND: %6d, NPwgts: [", mincut, mincutorder, nbnd); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf("], LB: %.3f\n", Compute2WayHLoadImbalance(ncon, npwgts, tpwgts)); + } + + graph->mincut = mincut; + graph->nbnd = nbnd; + + + for (i=0; i<ncon; i++) { + PQueueFree(ctrl, &parts[i][0]); + PQueueFree(ctrl, &parts[i][1]); + } + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mbalance2.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mbalance2.c new file mode 100644 index 0000000..d39f1e0 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mbalance2.c @@ -0,0 +1,328 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mbalance2.c + * + * This file contains code that is used to forcefully balance either + * bisections or k-sections + * + * Started 7/29/97 + * George + * + * $Id: mbalance2.c,v 1.1 2003/07/16 15:55:07 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function is the entry point of the bisection balancing algorithms. +**************************************************************************/ +void MocBalance2Way2(CtrlType *ctrl, GraphType *graph, float *tpwgts, float *ubvec) +{ + int i; + float tvec[MAXNCON]; + + Compute2WayHLoadImbalanceVec(graph->ncon, graph->npwgts, tpwgts, tvec); + if (!AreAllBelow(graph->ncon, tvec, ubvec)) + MocGeneral2WayBalance2(ctrl, graph, tpwgts, ubvec); +} + + + +/************************************************************************* +* This function performs an edge-based FM refinement +**************************************************************************/ +void MocGeneral2WayBalance2(CtrlType *ctrl, GraphType *graph, float *tpwgts, float *ubvec) +{ + int i, ii, j, k, l, kwgt, nvtxs, ncon, nbnd, nswaps, from, to, pass, me, limit, tmp, cnum; + idxtype *xadj, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind; + idxtype *moved, *swaps, *perm, *qnum; + float *nvwgt, *npwgts, origbal[MAXNCON], minbal[MAXNCON], newbal[MAXNCON]; + PQueueType parts[MAXNCON][2]; + int higain, oldgain, mincut, newcut, mincutorder; + float *maxwgt, *minwgt, tvec[MAXNCON]; + + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + id = graph->id; + ed = graph->ed; + npwgts = graph->npwgts; + bndptr = graph->bndptr; + bndind = graph->bndind; + + moved = idxwspacemalloc(ctrl, nvtxs); + swaps = idxwspacemalloc(ctrl, nvtxs); + perm = idxwspacemalloc(ctrl, nvtxs); + qnum = idxwspacemalloc(ctrl, nvtxs); + + limit = amin(amax(0.01*nvtxs, 15), 100); + + /* Setup the weight intervals of the two subdomains */ + minwgt = fwspacemalloc(ctrl, 2*ncon); + maxwgt = fwspacemalloc(ctrl, 2*ncon); + + for (i=0; i<2; i++) { + for (j=0; j<ncon; j++) { + maxwgt[i*ncon+j] = tpwgts[i]*ubvec[j]; + minwgt[i*ncon+j] = tpwgts[i]*(1.0/ubvec[j]); + } + } + + + /* Initialize the queues */ + for (i=0; i<ncon; i++) { + PQueueInit(ctrl, &parts[i][0], nvtxs, PLUS_GAINSPAN+1); + PQueueInit(ctrl, &parts[i][1], nvtxs, PLUS_GAINSPAN+1); + } + for (i=0; i<nvtxs; i++) + qnum[i] = samax(ncon, nvwgt+i*ncon); + + Compute2WayHLoadImbalanceVec(ncon, npwgts, tpwgts, origbal); + for (i=0; i<ncon; i++) + minbal[i] = origbal[i]; + + newcut = mincut = graph->mincut; + mincutorder = -1; + + if (ctrl->dbglvl&DBG_REFINE) { + printf("Parts: ["); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf("] T[%.3f %.3f], Nv-Nb[%5d, %5d]. ICut: %6d, LB: ", tpwgts[0], tpwgts[1], + graph->nvtxs, graph->nbnd, graph->mincut); + for (i=0; i<ncon; i++) + printf("%.3f ", origbal[i]); + printf("[B]\n"); + } + + idxset(nvtxs, -1, moved); + + ASSERT(ComputeCut(graph, where) == graph->mincut); + ASSERT(CheckBnd(graph)); + + /* Insert all nodes in the priority queues */ + nbnd = graph->nbnd; + RandomPermute(nvtxs, perm, 1); + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + PQueueInsert(&parts[qnum[i]][where[i]], i, ed[i]-id[i]); + } + + + for (nswaps=0; nswaps<nvtxs; nswaps++) { + if (AreAllBelow(ncon, minbal, ubvec)) + break; + + SelectQueue3(ncon, npwgts, tpwgts, &from, &cnum, parts, maxwgt); + to = (from+1)%2; + + if (from == -1 || (higain = PQueueGetMax(&parts[cnum][from])) == -1) + break; + + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + newcut -= (ed[higain]-id[higain]); + Compute2WayHLoadImbalanceVec(ncon, npwgts, tpwgts, newbal); + + if (IsBetter2wayBalance(ncon, newbal, minbal, ubvec) || + (IsBetter2wayBalance(ncon, newbal, origbal, ubvec) && newcut < mincut)) { + mincut = newcut; + for (i=0; i<ncon; i++) + minbal[i] = newbal[i]; + mincutorder = nswaps; + } + else if (nswaps-mincutorder > limit) { /* We hit the limit, undo last move */ + newcut += (ed[higain]-id[higain]); + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + break; + } + + where[higain] = to; + moved[higain] = nswaps; + swaps[nswaps] = higain; + + if (ctrl->dbglvl&DBG_MOVEINFO) { + printf("Moved %6d from %d(%d). Gain: %5d, Cut: %5d, NPwgts: ", higain, from, cnum, ed[higain]-id[higain], newcut); + for (i=0; i<ncon; i++) + printf("(%.3f, %.3f) ", npwgts[i], npwgts[ncon+i]); + + Compute2WayHLoadImbalanceVec(ncon, npwgts, tpwgts, tvec); + printf(", LB: "); + for (i=0; i<ncon; i++) + printf("%.3f ", tvec[i]); + if (mincutorder == nswaps) + printf(" *\n"); + else + printf("\n"); + } + + + /************************************************************** + * Update the id[i]/ed[i] values of the affected nodes + ***************************************************************/ + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + if (ed[higain] > 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + oldgain = ed[k]-id[k]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + /* Update the queue position */ + if (moved[k] == -1) + PQueueUpdate(&parts[qnum[k]][where[k]], k, oldgain, ed[k]-id[k]); + + /* Update its boundary information */ + if (ed[k] == 0 && bndptr[k] != -1) + BNDDelete(nbnd, bndind, bndptr, k); + else if (ed[k] > 0 && bndptr[k] == -1) + BNDInsert(nbnd, bndind, bndptr, k); + } + + } + + + + /**************************************************************** + * Roll back computations + *****************************************************************/ + for (i=0; i<nswaps; i++) + moved[swaps[i]] = -1; /* reset moved array */ + for (nswaps--; nswaps>mincutorder; nswaps--) { + higain = swaps[nswaps]; + + to = where[higain] = (where[higain]+1)%2; + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + else if (ed[higain] > 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+((to+1)%2)*ncon, 1); + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + if (bndptr[k] != -1 && ed[k] == 0) + BNDDelete(nbnd, bndind, bndptr, k); + if (bndptr[k] == -1 && ed[k] > 0) + BNDInsert(nbnd, bndind, bndptr, k); + } + } + + if (ctrl->dbglvl&DBG_REFINE) { + printf("\tMincut: %6d at %5d, NBND: %6d, NPwgts: [", mincut, mincutorder, nbnd); + for (i=0; i<ncon; i++) + printf("(%.3f, %.3f) ", npwgts[i], npwgts[ncon+i]); + printf("], LB: "); + Compute2WayHLoadImbalanceVec(ncon, npwgts, tpwgts, tvec); + for (i=0; i<ncon; i++) + printf("%.3f ", tvec[i]); + printf("\n"); + } + + graph->mincut = mincut; + graph->nbnd = nbnd; + + + for (i=0; i<ncon; i++) { + PQueueFree(ctrl, &parts[i][0]); + PQueueFree(ctrl, &parts[i][1]); + } + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + fwspacefree(ctrl, 2*ncon); + fwspacefree(ctrl, 2*ncon); + +} + + + + +/************************************************************************* +* This function selects the partition number and the queue from which +* we will move vertices out +**************************************************************************/ +void SelectQueue3(int ncon, float *npwgts, float *tpwgts, int *from, int *cnum, + PQueueType queues[MAXNCON][2], float *maxwgt) +{ + int i, j, maxgain=0; + float maxdiff=0.0, diff; + + *from = -1; + *cnum = -1; + + /* First determine the side and the queue, irrespective of the presence of nodes */ + for (j=0; j<2; j++) { + for (i=0; i<ncon; i++) { + diff = npwgts[j*ncon+i]-maxwgt[j*ncon+i]; + if (diff >= maxdiff) { + maxdiff = diff; + *from = j; + *cnum = i; + } + } + } + +/* DELETE +j = *from; +for (i=0; i<ncon; i++) + printf("[%5d %5d %.4f %.4f] ", i, PQueueGetSize(&queues[i][j]), npwgts[j*ncon+i], maxwgt[j*ncon+i]); +printf("***[%5d %5d]\n", *cnum, *from); +*/ + + /* If the desired queue is empty, select a node from that side anyway */ + if (*from != -1 && PQueueGetSize(&queues[*cnum][*from]) == 0) { + for (i=0; i<ncon; i++) { + if (PQueueGetSize(&queues[i][*from]) > 0) { + maxdiff = (npwgts[(*from)*ncon+i] - maxwgt[(*from)*ncon+i]); + *cnum = i; + break; + } + } + + for (i++; i<ncon; i++) { + diff = npwgts[(*from)*ncon+i] - maxwgt[(*from)*ncon+i]; + if (diff > maxdiff && PQueueGetSize(&queues[i][*from]) > 0) { + maxdiff = diff; + *cnum = i; + } + } + } + + /* If the constraints ar OK, select a high gain vertex */ + if (*from == -1) { + maxgain = -100000; + for (j=0; j<2; j++) { + for (i=0; i<ncon; i++) { + if (PQueueGetSize(&queues[i][j]) > 0 && PQueueGetKey(&queues[i][j]) > maxgain) { + maxgain = PQueueGetKey(&queues[i][0]); + *from = j; + *cnum = i; + } + } + } + + /* printf("(%2d %2d) %3d\n", *from, *cnum, maxgain); */ + } +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mcoarsen.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mcoarsen.c new file mode 100644 index 0000000..336e6c6 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mcoarsen.c @@ -0,0 +1,106 @@ +/* + * mcoarsen.c + * + * This file contains the driving routines for the coarsening process + * + * Started 7/23/97 + * George + * + * $Id: mcoarsen.c,v 1.2 2003/07/31 16:23:29 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function takes a graph and creates a sequence of coarser graphs +**************************************************************************/ +GraphType *MCCoarsen2Way(CtrlType *ctrl, GraphType *graph) +{ + int i, clevel; + GraphType *cgraph; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->CoarsenTmr)); + + cgraph = graph; + + clevel = 0; + do { + if (ctrl->dbglvl&DBG_COARSEN) { + printf("%6d %7d %10d [%d] [%6.4f", cgraph->nvtxs, cgraph->nedges, + idxsum(cgraph->nvtxs, cgraph->adjwgtsum), ctrl->CoarsenTo, ctrl->nmaxvwgt); + for (i=0; i<graph->ncon; i++) + printf(" %5.3f", ssum_strd(cgraph->nvtxs, cgraph->nvwgt+i, cgraph->ncon)); + printf("]\n"); + } + + switch (ctrl->CType) { + case MATCH_RM: + MCMatch_RM(ctrl, cgraph); + break; + case MATCH_HEM: + if (clevel < 1 || cgraph->nedges == 0) + MCMatch_RM(ctrl, cgraph); + else + MCMatch_HEM(ctrl, cgraph); + break; + case MATCH_SHEM: + if (clevel < 1 || cgraph->nedges == 0) + MCMatch_RM(ctrl, cgraph); + else + MCMatch_SHEM(ctrl, cgraph); + break; + case MATCH_SHEMKWAY: + if (clevel < 1 || cgraph->nedges == 0) + MCMatch_RM(ctrl, cgraph); + else + MCMatch_SHEM(ctrl, cgraph); + break; + case MATCH_SHEBM_ONENORM: + if (clevel < 1 || cgraph->nedges == 0) + MCMatch_RM(ctrl, cgraph); + else + MCMatch_SHEBM(ctrl, cgraph, 1); + break; + case MATCH_SHEBM_INFNORM: + if (clevel < 1 || cgraph->nedges == 0) + MCMatch_RM(ctrl, cgraph); + else + MCMatch_SHEBM(ctrl, cgraph, -1); + break; + case MATCH_SBHEM_ONENORM: + if (clevel < 1 || cgraph->nedges == 0) + MCMatch_RM(ctrl, cgraph); + else + MCMatch_SBHEM(ctrl, cgraph, 1); + break; + case MATCH_SBHEM_INFNORM: + if (clevel < 1 || cgraph->nedges == 0) + MCMatch_RM(ctrl, cgraph); + else + MCMatch_SBHEM(ctrl, cgraph, -1); + break; + default: + errexit("Unknown CType: %d\n", ctrl->CType); + } + + cgraph = cgraph->coarser; + clevel++; + + } while (cgraph->nvtxs > ctrl->CoarsenTo && cgraph->nvtxs < COARSEN_FRACTION2*cgraph->finer->nvtxs && cgraph->nedges > cgraph->nvtxs/2); + + if (ctrl->dbglvl&DBG_COARSEN) { + printf("%6d %7d %10d [%d] [%6.4f", cgraph->nvtxs, cgraph->nedges, + idxsum(cgraph->nvtxs, cgraph->adjwgtsum), ctrl->CoarsenTo, ctrl->nmaxvwgt); + for (i=0; i<graph->ncon; i++) + printf(" %5.3f", ssum_strd(cgraph->nvtxs, cgraph->nvwgt+i, cgraph->ncon)); + printf("]\n"); + } + + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->CoarsenTmr)); + + return cgraph; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/memory.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/memory.c new file mode 100644 index 0000000..0082b8c --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/memory.c @@ -0,0 +1,208 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * memory.c + * + * This file contains routines that deal with memory allocation + * + * Started 2/24/96 + * George + * + * $Id: memory.c,v 1.1 2003/07/24 18:39:08 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function allocates memory for the workspace +**************************************************************************/ +void AllocateWorkSpace(CtrlType *ctrl, GraphType *graph, int nparts) +{ + ctrl->wspace.pmat = NULL; + + if (ctrl->optype == OP_KMETIS) { + ctrl->wspace.edegrees = (EDegreeType *)GKmalloc(graph->nedges*sizeof(EDegreeType), "AllocateWorkSpace: edegrees"); + ctrl->wspace.vedegrees = NULL; + ctrl->wspace.auxcore = (idxtype *)ctrl->wspace.edegrees; + + ctrl->wspace.pmat = idxmalloc(nparts*nparts, "AllocateWorkSpace: pmat"); + + /* Memory requirements for different phases + Coarsening + Matching: 4*nvtxs vectors + Contraction: 2*nvtxs vectors (from the above 4), 1*nparts, 1*Nedges + Total = MAX(4*nvtxs, 2*nvtxs+nparts+nedges) + + Refinement + Random Refinement/Balance: 5*nparts + 1*nvtxs + 2*nedges + Greedy Refinement/Balance: 5*nparts + 2*nvtxs + 2*nedges + 1*PQueue(==Nvtxs) + Total = 5*nparts + 3*nvtxs + 2*nedges + + Total = 5*nparts + 3*nvtxs + 2*nedges + */ + ctrl->wspace.maxcore = 3*(graph->nvtxs+1) + /* Match/Refinement vectors */ + 5*(nparts+1) + /* Partition weights etc */ + graph->nvtxs*(sizeof(ListNodeType)/sizeof(idxtype)) + /* Greedy k-way balance/refine */ + 20 /* padding for 64 bit machines */ + ; + } + else if (ctrl->optype == OP_KVMETIS) { + ctrl->wspace.edegrees = NULL; + ctrl->wspace.vedegrees = (VEDegreeType *)GKmalloc(graph->nedges*sizeof(VEDegreeType), "AllocateWorkSpace: vedegrees"); + ctrl->wspace.auxcore = (idxtype *)ctrl->wspace.vedegrees; + + ctrl->wspace.pmat = idxmalloc(nparts*nparts, "AllocateWorkSpace: pmat"); + + /* Memory requirements for different phases are identical to KMETIS */ + ctrl->wspace.maxcore = 3*(graph->nvtxs+1) + /* Match/Refinement vectors */ + 3*(nparts+1) + /* Partition weights etc */ + graph->nvtxs*(sizeof(ListNodeType)/sizeof(idxtype)) + /* Greedy k-way balance/refine */ + 20 /* padding for 64 bit machines */ + ; + } + else { + ctrl->wspace.edegrees = (EDegreeType *)idxmalloc(graph->nedges, "AllocateWorkSpace: edegrees"); + ctrl->wspace.vedegrees = NULL; + ctrl->wspace.auxcore = (idxtype *)ctrl->wspace.edegrees; + + ctrl->wspace.maxcore = 5*(graph->nvtxs+1) + /* Refinement vectors */ + 4*(nparts+1) + /* Partition weights etc */ + 2*graph->ncon*graph->nvtxs*(sizeof(ListNodeType)/sizeof(idxtype)) + /* 2-way refinement */ + 2*graph->ncon*(NEG_GAINSPAN+PLUS_GAINSPAN+1)*(sizeof(ListNodeType *)/sizeof(idxtype)) + /* 2-way refinement */ + 20 /* padding for 64 bit machines */ + ; + } + + ctrl->wspace.maxcore += HTLENGTH; + ctrl->wspace.core = idxmalloc(ctrl->wspace.maxcore, "AllocateWorkSpace: maxcore"); + ctrl->wspace.ccore = 0; +} + + +/************************************************************************* +* This function allocates memory for the workspace +**************************************************************************/ +void FreeWorkSpace(CtrlType *ctrl, GraphType *graph) +{ + GKfree(&ctrl->wspace.edegrees, &ctrl->wspace.vedegrees, &ctrl->wspace.core, &ctrl->wspace.pmat, LTERM); +} + +/************************************************************************* +* This function returns how may words are left in the workspace +**************************************************************************/ +int WspaceAvail(CtrlType *ctrl) +{ + return ctrl->wspace.maxcore - ctrl->wspace.ccore; +} + + +/************************************************************************* +* This function allocate space from the core +**************************************************************************/ +idxtype *idxwspacemalloc(CtrlType *ctrl, int n) +{ + n += n%2; /* This is a fix for 64 bit machines that require 8-byte pointer allignment */ + + ctrl->wspace.ccore += n; + ASSERT(ctrl->wspace.ccore <= ctrl->wspace.maxcore); + return ctrl->wspace.core + ctrl->wspace.ccore - n; +} + +/************************************************************************* +* This function frees space from the core +**************************************************************************/ +void idxwspacefree(CtrlType *ctrl, int n) +{ + n += n%2; /* This is a fix for 64 bit machines that require 8-byte pointer allignment */ + + ctrl->wspace.ccore -= n; + ASSERT(ctrl->wspace.ccore >= 0); +} + + +/************************************************************************* +* This function allocate space from the core +**************************************************************************/ +float *fwspacemalloc(CtrlType *ctrl, int n) +{ + n += n%2; /* This is a fix for 64 bit machines that require 8-byte pointer allignment */ + + ctrl->wspace.ccore += n; + ASSERT(ctrl->wspace.ccore <= ctrl->wspace.maxcore); + return (float *) (ctrl->wspace.core + ctrl->wspace.ccore - n); +} + +/************************************************************************* +* This function frees space from the core +**************************************************************************/ +void fwspacefree(CtrlType *ctrl, int n) +{ + n += n%2; /* This is a fix for 64 bit machines that require 8-byte pointer allignment */ + + ctrl->wspace.ccore -= n; + ASSERT(ctrl->wspace.ccore >= 0); +} + + + +/************************************************************************* +* This function creates a CoarseGraphType data structure and initializes +* the various fields +**************************************************************************/ +GraphType *CreateGraph(void) +{ + GraphType *graph; + + graph = (GraphType *)GKmalloc(sizeof(GraphType), "CreateCoarseGraph: graph"); + + InitGraph(graph); + + return graph; +} + + +/************************************************************************* +* This function creates a CoarseGraphType data structure and initializes +* the various fields +**************************************************************************/ +void InitGraph(GraphType *graph) +{ + graph->gdata = graph->rdata = NULL; + + graph->nvtxs = graph->nedges = -1; + graph->mincut = graph->minvol = -1; + + graph->xadj = graph->vwgt = graph->adjncy = graph->adjwgt = NULL; + graph->adjwgtsum = NULL; + graph->label = NULL; + graph->cmap = NULL; + + graph->where = graph->pwgts = NULL; + graph->id = graph->ed = NULL; + graph->bndptr = graph->bndind = NULL; + graph->rinfo = NULL; + graph->vrinfo = NULL; + graph->nrinfo = NULL; + + graph->ncon = -1; + graph->nvwgt = NULL; + graph->npwgts = NULL; + + graph->vsize = NULL; + + graph->coarser = graph->finer = NULL; + +} + +/************************************************************************* +* This function deallocates any memory stored in a graph +**************************************************************************/ +void FreeGraph(GraphType *graph) +{ + + GKfree(&graph->gdata, &graph->nvwgt, &graph->rdata, &graph->npwgts, LTERM); + free(graph); +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mesh.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mesh.c new file mode 100644 index 0000000..3d93628 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mesh.c @@ -0,0 +1,399 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mesh.c + * + * This file contains routines for converting 3D and 4D finite element + * meshes into dual or nodal graphs + * + * Started 8/18/97 + * George + * + * $Id: mesh.c,v 1.2 2003/07/22 20:29:03 karypis Exp $ + * + */ + +#include <metis.h> + +/***************************************************************************** +* This function creates a graph corresponding to the dual of a finite element +* mesh. At this point the supported elements are triangles, tetrahedrons, and +* bricks. +******************************************************************************/ +void METIS_MeshToDual(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, + idxtype *dxadj, idxtype *dadjncy) +{ + int esizes[] = {-1, 3, 4, 8, 4}; + + if (*numflag == 1) + ChangeMesh2CNumbering((*ne)*esizes[*etype], elmnts); + + GENDUALMETIS(*ne, *nn, *etype, elmnts, dxadj, dadjncy); + + if (*numflag == 1) + ChangeMesh2FNumbering((*ne)*esizes[*etype], elmnts, *ne, dxadj, dadjncy); +} + + +/***************************************************************************** +* This function creates a graph corresponding to the finite element mesh. +* At this point the supported elements are triangles, tetrahedrons. +******************************************************************************/ +void METIS_MeshToNodal(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, + idxtype *dxadj, idxtype *dadjncy) +{ + int esizes[] = {-1, 3, 4, 8, 4}; + + if (*numflag == 1) + ChangeMesh2CNumbering((*ne)*esizes[*etype], elmnts); + + switch (*etype) { + case 1: + TRINODALMETIS(*ne, *nn, elmnts, dxadj, dadjncy); + break; + case 2: + TETNODALMETIS(*ne, *nn, elmnts, dxadj, dadjncy); + break; + case 3: + HEXNODALMETIS(*ne, *nn, elmnts, dxadj, dadjncy); + break; + case 4: + QUADNODALMETIS(*ne, *nn, elmnts, dxadj, dadjncy); + break; + } + + if (*numflag == 1) + ChangeMesh2FNumbering((*ne)*esizes[*etype], elmnts, *nn, dxadj, dadjncy); +} + + + +/***************************************************************************** +* This function creates the dual of a finite element mesh +******************************************************************************/ +void GENDUALMETIS(int nelmnts, int nvtxs, int etype, idxtype *elmnts, idxtype *dxadj, + idxtype *dadjncy) +{ + int i, j, jj, k, kk, kkk, l, m, n, nedges, mask; + idxtype *nptr, *nind; + idxtype *mark, ind[200], wgt[200]; + int esize, esizes[] = {-1, 3, 4, 8, 4}, + mgcnum, mgcnums[] = {-1, 2, 3, 4, 2}; + + mask = (1<<11)-1; + mark = idxsmalloc(mask+1, -1, "GENDUALMETIS: mark"); + + /* Get the element size and magic number for the particular element */ + esize = esizes[etype]; + mgcnum = mgcnums[etype]; + + /* Construct the node-element list first */ + nptr = idxsmalloc(nvtxs+1, 0, "GENDUALMETIS: nptr"); + for (j=esize*nelmnts, i=0; i<j; i++) + nptr[elmnts[i]]++; + MAKECSR(i, nvtxs, nptr); + + nind = idxmalloc(nptr[nvtxs], "GENDUALMETIS: nind"); + for (k=i=0; i<nelmnts; i++) { + for (j=0; j<esize; j++, k++) + nind[nptr[elmnts[k]]++] = i; + } + for (i=nvtxs; i>0; i--) + nptr[i] = nptr[i-1]; + nptr[0] = 0; + + for (i=0; i<nelmnts; i++) + dxadj[i] = esize*i; + + for (i=0; i<nelmnts; i++) { + for (m=j=0; j<esize; j++) { + n = elmnts[esize*i+j]; + for (k=nptr[n+1]-1; k>=nptr[n]; k--) { + if ((kk = nind[k]) <= i) + break; + + kkk = kk&mask; + if ((l = mark[kkk]) == -1) { + ind[m] = kk; + wgt[m] = 1; + mark[kkk] = m++; + } + else if (ind[l] == kk) { + wgt[l]++; + } + else { + for (jj=0; jj<m; jj++) { + if (ind[jj] == kk) { + wgt[jj]++; + break; + } + } + if (jj == m) { + ind[m] = kk; + wgt[m++] = 1; + } + } + } + } + for (j=0; j<m; j++) { + if (wgt[j] == mgcnum) { + k = ind[j]; + dadjncy[dxadj[i]++] = k; + dadjncy[dxadj[k]++] = i; + } + mark[ind[j]&mask] = -1; + } + } + + /* Go and consolidate the dxadj and dadjncy */ + for (j=i=0; i<nelmnts; i++) { + for (k=esize*i; k<dxadj[i]; k++, j++) + dadjncy[j] = dadjncy[k]; + dxadj[i] = j; + } + for (i=nelmnts; i>0; i--) + dxadj[i] = dxadj[i-1]; + dxadj[0] = 0; + + free(mark); + free(nptr); + free(nind); + +} + + + + +/***************************************************************************** +* This function creates the nodal graph of a finite element mesh +******************************************************************************/ +void TRINODALMETIS(int nelmnts, int nvtxs, idxtype *elmnts, idxtype *dxadj, idxtype *dadjncy) +{ + int i, j, jj, k, kk, kkk, l, m, n, nedges; + idxtype *nptr, *nind; + idxtype *mark; + + /* Construct the node-element list first */ + nptr = idxsmalloc(nvtxs+1, 0, "TRINODALMETIS: nptr"); + for (j=3*nelmnts, i=0; i<j; i++) + nptr[elmnts[i]]++; + MAKECSR(i, nvtxs, nptr); + + nind = idxmalloc(nptr[nvtxs], "TRINODALMETIS: nind"); + for (k=i=0; i<nelmnts; i++) { + for (j=0; j<3; j++, k++) + nind[nptr[elmnts[k]]++] = i; + } + for (i=nvtxs; i>0; i--) + nptr[i] = nptr[i-1]; + nptr[0] = 0; + + + mark = idxsmalloc(nvtxs, -1, "TRINODALMETIS: mark"); + + nedges = dxadj[0] = 0; + for (i=0; i<nvtxs; i++) { + mark[i] = i; + for (j=nptr[i]; j<nptr[i+1]; j++) { + for (jj=3*nind[j], k=0; k<3; k++, jj++) { + kk = elmnts[jj]; + if (mark[kk] != i) { + mark[kk] = i; + dadjncy[nedges++] = kk; + } + } + } + dxadj[i+1] = nedges; + } + + free(mark); + free(nptr); + free(nind); + +} + + +/***************************************************************************** +* This function creates the nodal graph of a finite element mesh +******************************************************************************/ +void TETNODALMETIS(int nelmnts, int nvtxs, idxtype *elmnts, idxtype *dxadj, idxtype *dadjncy) +{ + int i, j, jj, k, kk, kkk, l, m, n, nedges; + idxtype *nptr, *nind; + idxtype *mark; + + /* Construct the node-element list first */ + nptr = idxsmalloc(nvtxs+1, 0, "TETNODALMETIS: nptr"); + for (j=4*nelmnts, i=0; i<j; i++) + nptr[elmnts[i]]++; + MAKECSR(i, nvtxs, nptr); + + nind = idxmalloc(nptr[nvtxs], "TETNODALMETIS: nind"); + for (k=i=0; i<nelmnts; i++) { + for (j=0; j<4; j++, k++) + nind[nptr[elmnts[k]]++] = i; + } + for (i=nvtxs; i>0; i--) + nptr[i] = nptr[i-1]; + nptr[0] = 0; + + + mark = idxsmalloc(nvtxs, -1, "TETNODALMETIS: mark"); + + nedges = dxadj[0] = 0; + for (i=0; i<nvtxs; i++) { + mark[i] = i; + for (j=nptr[i]; j<nptr[i+1]; j++) { + for (jj=4*nind[j], k=0; k<4; k++, jj++) { + kk = elmnts[jj]; + if (mark[kk] != i) { + mark[kk] = i; + dadjncy[nedges++] = kk; + } + } + } + dxadj[i+1] = nedges; + } + + free(mark); + free(nptr); + free(nind); + +} + + +/***************************************************************************** +* This function creates the nodal graph of a finite element mesh +******************************************************************************/ +void HEXNODALMETIS(int nelmnts, int nvtxs, idxtype *elmnts, idxtype *dxadj, idxtype *dadjncy) +{ + int i, j, jj, k, kk, kkk, l, m, n, nedges; + idxtype *nptr, *nind; + idxtype *mark; + int table[8][3] = {1, 3, 4, + 0, 2, 5, + 1, 3, 6, + 0, 2, 7, + 0, 5, 7, + 1, 4, 6, + 2, 5, 7, + 3, 4, 6}; + + /* Construct the node-element list first */ + nptr = idxsmalloc(nvtxs+1, 0, "HEXNODALMETIS: nptr"); + for (j=8*nelmnts, i=0; i<j; i++) + nptr[elmnts[i]]++; + MAKECSR(i, nvtxs, nptr); + + nind = idxmalloc(nptr[nvtxs], "HEXNODALMETIS: nind"); + for (k=i=0; i<nelmnts; i++) { + for (j=0; j<8; j++, k++) + nind[nptr[elmnts[k]]++] = i; + } + for (i=nvtxs; i>0; i--) + nptr[i] = nptr[i-1]; + nptr[0] = 0; + + + mark = idxsmalloc(nvtxs, -1, "HEXNODALMETIS: mark"); + + nedges = dxadj[0] = 0; + for (i=0; i<nvtxs; i++) { + mark[i] = i; + for (j=nptr[i]; j<nptr[i+1]; j++) { + jj=8*nind[j]; + for (k=0; k<8; k++) { + if (elmnts[jj+k] == i) + break; + } + ASSERT(k != 8); + + /* You found the index, now go and put the 3 neighbors */ + kk = elmnts[jj+table[k][0]]; + if (mark[kk] != i) { + mark[kk] = i; + dadjncy[nedges++] = kk; + } + kk = elmnts[jj+table[k][1]]; + if (mark[kk] != i) { + mark[kk] = i; + dadjncy[nedges++] = kk; + } + kk = elmnts[jj+table[k][2]]; + if (mark[kk] != i) { + mark[kk] = i; + dadjncy[nedges++] = kk; + } + } + dxadj[i+1] = nedges; + } + + free(mark); + free(nptr); + free(nind); + +} + + +/***************************************************************************** +* This function creates the nodal graph of a finite element mesh +******************************************************************************/ +void QUADNODALMETIS(int nelmnts, int nvtxs, idxtype *elmnts, idxtype *dxadj, idxtype *dadjncy) +{ + int i, j, jj, k, kk, kkk, l, m, n, nedges; + idxtype *nptr, *nind; + idxtype *mark; + int table[4][2] = {1, 3, + 0, 2, + 1, 3, + 0, 2}; + + /* Construct the node-element list first */ + nptr = idxsmalloc(nvtxs+1, 0, "QUADNODALMETIS: nptr"); + for (j=4*nelmnts, i=0; i<j; i++) + nptr[elmnts[i]]++; + MAKECSR(i, nvtxs, nptr); + + nind = idxmalloc(nptr[nvtxs], "QUADNODALMETIS: nind"); + for (k=i=0; i<nelmnts; i++) { + for (j=0; j<4; j++, k++) + nind[nptr[elmnts[k]]++] = i; + } + for (i=nvtxs; i>0; i--) + nptr[i] = nptr[i-1]; + nptr[0] = 0; + + + mark = idxsmalloc(nvtxs, -1, "QUADNODALMETIS: mark"); + + nedges = dxadj[0] = 0; + for (i=0; i<nvtxs; i++) { + mark[i] = i; + for (j=nptr[i]; j<nptr[i+1]; j++) { + jj=4*nind[j]; + for (k=0; k<4; k++) { + if (elmnts[jj+k] == i) + break; + } + ASSERT(k != 4); + + /* You found the index, now go and put the 2 neighbors */ + kk = elmnts[jj+table[k][0]]; + if (mark[kk] != i) { + mark[kk] = i; + dadjncy[nedges++] = kk; + } + kk = elmnts[jj+table[k][1]]; + if (mark[kk] != i) { + mark[kk] = i; + dadjncy[nedges++] = kk; + } + } + dxadj[i+1] = nedges; + } + + free(mark); + free(nptr); + free(nind); + +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/meshpart.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/meshpart.c new file mode 100644 index 0000000..4ca3a2a --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/meshpart.c @@ -0,0 +1,204 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * meshpart.c + * + * This file contains routines for partitioning finite element meshes. + * + * Started 9/29/97 + * George + * + * $Id: meshpart.c,v 1.1 2003/07/16 15:55:08 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function partitions a finite element mesh by partitioning its nodal +* graph using KMETIS and then assigning elements in a load balanced fashion. +**************************************************************************/ +void METIS_PartMeshNodal(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, + int *nparts, int *edgecut, idxtype *epart, idxtype *npart) +{ + int i, j, k, me; + idxtype *xadj, *adjncy, *pwgts; + int options[10], pnumflag=0, wgtflag=0; + int nnbrs, nbrind[200], nbrwgt[200], maxpwgt; + int esize, esizes[] = {-1, 3, 4, 8, 4}; + + esize = esizes[*etype]; + + if (*numflag == 1) + ChangeMesh2CNumbering((*ne)*esize, elmnts); + + xadj = idxmalloc(*nn+1, "METIS_MESHPARTNODAL: xadj"); + adjncy = idxmalloc(20*(*nn), "METIS_MESHPARTNODAL: adjncy"); + + METIS_MeshToNodal(ne, nn, elmnts, etype, &pnumflag, xadj, adjncy); + + adjncy = realloc(adjncy, xadj[*nn]*sizeof(idxtype)); + + options[0] = 0; + METIS_PartGraphKway(nn, xadj, adjncy, NULL, NULL, &wgtflag, &pnumflag, nparts, options, edgecut, npart); + + /* OK, now compute an element partition based on the nodal partition npart */ + idxset(*ne, -1, epart); + pwgts = idxsmalloc(*nparts, 0, "METIS_MESHPARTNODAL: pwgts"); + for (i=0; i<*ne; i++) { + me = npart[elmnts[i*esize]]; + for (j=1; j<esize; j++) { + if (npart[elmnts[i*esize+j]] != me) + break; + } + if (j == esize) { + epart[i] = me; + pwgts[me]++; + } + } + + maxpwgt = 1.03*(*ne)/(*nparts); + for (i=0; i<*ne; i++) { + if (epart[i] == -1) { /* Assign the boundary element */ + nnbrs = 0; + for (j=0; j<esize; j++) { + me = npart[elmnts[i*esize+j]]; + for (k=0; k<nnbrs; k++) { + if (nbrind[k] == me) { + nbrwgt[k]++; + break; + } + } + if (k == nnbrs) { + nbrind[nnbrs] = me; + nbrwgt[nnbrs++] = 1; + } + } + /* Try to assign it first to the domain with most things in common */ + j = iamax(nnbrs, nbrwgt); + if (pwgts[nbrind[j]] < maxpwgt) { + epart[i] = nbrind[j]; + } + else { + /* If that fails, assign it to a light domain */ + for (j=0; j<nnbrs; j++) { + if (pwgts[nbrind[j]] < maxpwgt) { + epart[i] = nbrind[j]; + break; + } + } + if (j == nnbrs) + epart[i] = nbrind[iamax(nnbrs, nbrwgt)]; + } + pwgts[epart[i]]++; + } + } + + if (*numflag == 1) + ChangeMesh2FNumbering2((*ne)*esize, elmnts, *ne, *nn, epart, npart); + + GKfree(&xadj, &adjncy, &pwgts, LTERM); + +} + + +/************************************************************************* +* This function partitions a finite element mesh by partitioning its dual +* graph using KMETIS and then assigning nodes in a load balanced fashion. +**************************************************************************/ +void METIS_PartMeshDual(int *ne, int *nn, idxtype *elmnts, int *etype, int *numflag, + int *nparts, int *edgecut, idxtype *epart, idxtype *npart) +{ + int i, j, k, me; + idxtype *xadj, *adjncy, *pwgts, *nptr, *nind; + int options[10], pnumflag=0, wgtflag=0; + int nnbrs, nbrind[200], nbrwgt[200], maxpwgt; + int esize, esizes[] = {-1, 3, 4, 8, 4}; + + esize = esizes[*etype]; + + if (*numflag == 1) + ChangeMesh2CNumbering((*ne)*esize, elmnts); + + xadj = idxmalloc(*ne+1, "METIS_MESHPARTNODAL: xadj"); + adjncy = idxmalloc(esize*(*ne), "METIS_MESHPARTNODAL: adjncy"); + + METIS_MeshToDual(ne, nn, elmnts, etype, &pnumflag, xadj, adjncy); + + options[0] = 0; + METIS_PartGraphKway(ne, xadj, adjncy, NULL, NULL, &wgtflag, &pnumflag, nparts, options, edgecut, epart); + + /* Construct the node-element list */ + nptr = idxsmalloc(*nn+1, 0, "METIS_MESHPARTDUAL: nptr"); + for (j=esize*(*ne), i=0; i<j; i++) + nptr[elmnts[i]]++; + MAKECSR(i, *nn, nptr); + + nind = idxmalloc(nptr[*nn], "METIS_MESHPARTDUAL: nind"); + for (k=i=0; i<(*ne); i++) { + for (j=0; j<esize; j++, k++) + nind[nptr[elmnts[k]]++] = i; + } + for (i=(*nn); i>0; i--) + nptr[i] = nptr[i-1]; + nptr[0] = 0; + + + /* OK, now compute a nodal partition based on the element partition npart */ + idxset(*nn, -1, npart); + pwgts = idxsmalloc(*nparts, 0, "METIS_MESHPARTDUAL: pwgts"); + for (i=0; i<*nn; i++) { + me = epart[nind[nptr[i]]]; + for (j=nptr[i]+1; j<nptr[i+1]; j++) { + if (epart[nind[j]] != me) + break; + } + if (j == nptr[i+1]) { + npart[i] = me; + pwgts[me]++; + } + } + + maxpwgt = 1.03*(*nn)/(*nparts); + for (i=0; i<*nn; i++) { + if (npart[i] == -1) { /* Assign the boundary element */ + nnbrs = 0; + for (j=nptr[i]; j<nptr[i+1]; j++) { + me = epart[nind[j]]; + for (k=0; k<nnbrs; k++) { + if (nbrind[k] == me) { + nbrwgt[k]++; + break; + } + } + if (k == nnbrs) { + nbrind[nnbrs] = me; + nbrwgt[nnbrs++] = 1; + } + } + /* Try to assign it first to the domain with most things in common */ + j = iamax(nnbrs, nbrwgt); + if (pwgts[nbrind[j]] < maxpwgt) { + npart[i] = nbrind[j]; + } + else { + /* If that fails, assign it to a light domain */ + npart[i] = nbrind[0]; + for (j=0; j<nnbrs; j++) { + if (pwgts[nbrind[j]] < maxpwgt) { + npart[i] = nbrind[j]; + break; + } + } + } + pwgts[npart[i]]++; + } + } + + if (*numflag == 1) + ChangeMesh2FNumbering2((*ne)*esize, elmnts, *ne, *nn, epart, npart); + + GKfree(&xadj, &adjncy, &pwgts, &nptr, &nind, LTERM); + +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/metis.h b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/metis.h new file mode 100644 index 0000000..b655d90 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/metis.h @@ -0,0 +1,31 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * metis.h + * + * This file includes all necessary header files + * + * Started 8/27/94 + * George + * + * $Id: metis.h,v 1.3 2003/07/25 13:52:00 karypis Exp $ + */ + +/* +#define DEBUG 1 +#define DMALLOC 1 +*/ + +#include <stdheaders.h> + +#ifdef DMALLOC +#include <dmalloc.h> +#endif + +#include "../parmetis.h" /* Get the idxtype definition */ +#include <defs.h> +#include <struct.h> +#include <macros.h> +#include <rename.h> +#include <proto.h> + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mfm.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mfm.c new file mode 100644 index 0000000..d0047e5 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mfm.c @@ -0,0 +1,341 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mfm.c + * + * This file contains code that implements the edge-based FM refinement + * + * Started 7/23/97 + * George + * + * $Id: mfm.c,v 1.1 2003/07/24 18:39:09 karypis Exp $ + */ + +#include <metis.h> + + +/************************************************************************* +* This function performs an edge-based FM refinement +**************************************************************************/ +void MocFM_2WayEdgeRefine(CtrlType *ctrl, GraphType *graph, float *tpwgts, int npasses) +{ + int i, ii, j, k, l, kwgt, nvtxs, ncon, nbnd, nswaps, from, to, pass, me, limit, tmp, cnum; + idxtype *xadj, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind; + idxtype *moved, *swaps, *perm, *qnum; + float *nvwgt, *npwgts, mindiff[MAXNCON], origbal, minbal, newbal; + PQueueType parts[MAXNCON][2]; + int higain, oldgain, mincut, initcut, newcut, mincutorder; + float rtpwgts[2]; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + id = graph->id; + ed = graph->ed; + npwgts = graph->npwgts; + bndptr = graph->bndptr; + bndind = graph->bndind; + + moved = idxwspacemalloc(ctrl, nvtxs); + swaps = idxwspacemalloc(ctrl, nvtxs); + perm = idxwspacemalloc(ctrl, nvtxs); + qnum = idxwspacemalloc(ctrl, nvtxs); + + limit = amin(amax(0.01*nvtxs, 25), 150); + + /* Initialize the queues */ + for (i=0; i<ncon; i++) { + PQueueInit(ctrl, &parts[i][0], nvtxs, PLUS_GAINSPAN+1); + PQueueInit(ctrl, &parts[i][1], nvtxs, PLUS_GAINSPAN+1); + } + for (i=0; i<nvtxs; i++) + qnum[i] = samax(ncon, nvwgt+i*ncon); + + origbal = Compute2WayHLoadImbalance(ncon, npwgts, tpwgts); + + rtpwgts[0] = origbal*tpwgts[0]; + rtpwgts[1] = origbal*tpwgts[1]; + + if (ctrl->dbglvl&DBG_REFINE) { + printf("Parts: ["); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf("] T[%.3f %.3f], Nv-Nb[%5d, %5d]. ICut: %6d, LB: %.3f\n", tpwgts[0], tpwgts[1], graph->nvtxs, graph->nbnd, graph->mincut, origbal); + } + + idxset(nvtxs, -1, moved); + for (pass=0; pass<npasses; pass++) { /* Do a number of passes */ + for (i=0; i<ncon; i++) { + PQueueReset(&parts[i][0]); + PQueueReset(&parts[i][1]); + } + + mincutorder = -1; + newcut = mincut = initcut = graph->mincut; + for (i=0; i<ncon; i++) + mindiff[i] = fabs(tpwgts[0]-npwgts[i]); + minbal = Compute2WayHLoadImbalance(ncon, npwgts, tpwgts); + + ASSERT(ComputeCut(graph, where) == graph->mincut); + ASSERT(CheckBnd(graph)); + + /* Insert boundary nodes in the priority queues */ + nbnd = graph->nbnd; + RandomPermute(nbnd, perm, 1); + for (ii=0; ii<nbnd; ii++) { + i = bndind[perm[ii]]; + ASSERT(ed[i] > 0 || id[i] == 0); + ASSERT(bndptr[i] != -1); + PQueueInsert(&parts[qnum[i]][where[i]], i, ed[i]-id[i]); + } + + for (nswaps=0; nswaps<nvtxs; nswaps++) { + SelectQueue(ncon, npwgts, rtpwgts, &from, &cnum, parts); + to = (from+1)%2; + + if (from == -1 || (higain = PQueueGetMax(&parts[cnum][from])) == -1) + break; + ASSERT(bndptr[higain] != -1); + + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + + newcut -= (ed[higain]-id[higain]); + newbal = Compute2WayHLoadImbalance(ncon, npwgts, tpwgts); + + if ((newcut < mincut && newbal-origbal <= .00001) || + (newcut == mincut && (newbal < minbal || + (newbal == minbal && BetterBalance(ncon, npwgts, tpwgts, mindiff))))) { + mincut = newcut; + minbal = newbal; + mincutorder = nswaps; + for (i=0; i<ncon; i++) + mindiff[i] = fabs(tpwgts[0]-npwgts[i]); + } + else if (nswaps-mincutorder > limit) { /* We hit the limit, undo last move */ + newcut += (ed[higain]-id[higain]); + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + break; + } + + where[higain] = to; + moved[higain] = nswaps; + swaps[nswaps] = higain; + + if (ctrl->dbglvl&DBG_MOVEINFO) { + printf("Moved %6d from %d(%d). Gain: %5d, Cut: %5d, NPwgts: ", higain, from, cnum, ed[higain]-id[higain], newcut); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf(", %.3f LB: %.3f\n", minbal, newbal); + } + + + /************************************************************** + * Update the id[i]/ed[i] values of the affected nodes + ***************************************************************/ + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + oldgain = ed[k]-id[k]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + /* Update its boundary information and queue position */ + if (bndptr[k] != -1) { /* If k was a boundary vertex */ + if (ed[k] == 0) { /* Not a boundary vertex any more */ + BNDDelete(nbnd, bndind, bndptr, k); + if (moved[k] == -1) /* Remove it if in the queues */ + PQueueDelete(&parts[qnum[k]][where[k]], k, oldgain); + } + else { /* If it has not been moved, update its position in the queue */ + if (moved[k] == -1) + PQueueUpdate(&parts[qnum[k]][where[k]], k, oldgain, ed[k]-id[k]); + } + } + else { + if (ed[k] > 0) { /* It will now become a boundary vertex */ + BNDInsert(nbnd, bndind, bndptr, k); + if (moved[k] == -1) + PQueueInsert(&parts[qnum[k]][where[k]], k, ed[k]-id[k]); + } + } + } + + } + + + /**************************************************************** + * Roll back computations + *****************************************************************/ + for (i=0; i<nswaps; i++) + moved[swaps[i]] = -1; /* reset moved array */ + for (nswaps--; nswaps>mincutorder; nswaps--) { + higain = swaps[nswaps]; + + to = where[higain] = (where[higain]+1)%2; + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + else if (ed[higain] > 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+((to+1)%2)*ncon, 1); + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + if (bndptr[k] != -1 && ed[k] == 0) + BNDDelete(nbnd, bndind, bndptr, k); + if (bndptr[k] == -1 && ed[k] > 0) + BNDInsert(nbnd, bndind, bndptr, k); + } + } + + if (ctrl->dbglvl&DBG_REFINE) { + printf("\tMincut: %6d at %5d, NBND: %6d, NPwgts: [", mincut, mincutorder, nbnd); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf("], LB: %.3f\n", Compute2WayHLoadImbalance(ncon, npwgts, tpwgts)); + } + + graph->mincut = mincut; + graph->nbnd = nbnd; + + if (mincutorder == -1 || mincut == initcut) + break; + } + + for (i=0; i<ncon; i++) { + PQueueFree(ctrl, &parts[i][0]); + PQueueFree(ctrl, &parts[i][1]); + } + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + +} + + +/************************************************************************* +* This function selects the partition number and the queue from which +* we will move vertices out +**************************************************************************/ +void SelectQueue(int ncon, float *npwgts, float *tpwgts, int *from, int *cnum, PQueueType queues[MAXNCON][2]) +{ + int i, part, maxgain=0; + float max, maxdiff=0.0; + + *from = -1; + *cnum = -1; + + /* First determine the side and the queue, irrespective of the presence of nodes */ + for (part=0; part<2; part++) { + for (i=0; i<ncon; i++) { + if (npwgts[part*ncon+i]-tpwgts[part] >= maxdiff) { + maxdiff = npwgts[part*ncon+i]-tpwgts[part]; + *from = part; + *cnum = i; + } + } + } + + /* printf("Selected %d(%d) -> %d\n", *from, *cnum, PQueueGetSize(&queues[*cnum][*from])); */ + + if (*from != -1 && PQueueGetSize(&queues[*cnum][*from]) == 0) { + /* The desired queue is empty, select a node from that side anyway */ + for (i=0; i<ncon; i++) { + if (PQueueGetSize(&queues[i][*from]) > 0) { + max = npwgts[(*from)*ncon + i]; + *cnum = i; + break; + } + } + + for (i++; i<ncon; i++) { + if (npwgts[(*from)*ncon + i] > max && PQueueGetSize(&queues[i][*from]) > 0) { + max = npwgts[(*from)*ncon + i]; + *cnum = i; + } + } + } + + /* Check to see if you can focus on the cut */ + if (maxdiff <= 0.0 || *from == -1) { + maxgain = -100000; + + for (part=0; part<2; part++) { + for (i=0; i<ncon; i++) { + if (PQueueGetSize(&queues[i][part]) > 0 && PQueueGetKey(&queues[i][part]) > maxgain) { + maxgain = PQueueGetKey(&queues[i][part]); + *from = part; + *cnum = i; + } + } + } + } +} + + + + + +/************************************************************************* +* This function checks if the balance achieved is better than the diff +* For now, it uses a 2-norm measure +**************************************************************************/ +int BetterBalance(int ncon, float *npwgts, float *tpwgts, float *diff) +{ + int i; + float ndiff[MAXNCON]; + + for (i=0; i<ncon; i++) + ndiff[i] = fabs(tpwgts[0]-npwgts[i]); + + return snorm2(ncon, ndiff) < snorm2(ncon, diff); +} + + + +/************************************************************************* +* This function computes the load imbalance over all the constrains +**************************************************************************/ +float Compute2WayHLoadImbalance(int ncon, float *npwgts, float *tpwgts) +{ + int i; + float max=0.0, temp; + + for (i=0; i<ncon; i++) { + /* temp = amax(npwgts[i]/tpwgts[0], npwgts[ncon+i]/tpwgts[1]); */ + temp = fabs(tpwgts[0]-npwgts[i])/tpwgts[0]; + max = (max < temp ? temp : max); + } + return 1.0+max; +} + + +/************************************************************************* +* This function computes the load imbalance over all the constrains +* For now assume that we just want balanced partitionings +**************************************************************************/ +void Compute2WayHLoadImbalanceVec(int ncon, float *npwgts, float *tpwgts, float *lbvec) +{ + int i; + + for (i=0; i<ncon; i++) + lbvec[i] = 1.0 + fabs(tpwgts[0]-npwgts[i])/tpwgts[0]; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mfm2.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mfm2.c new file mode 100644 index 0000000..ce4eb8b --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mfm2.c @@ -0,0 +1,349 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mfm2.c + * + * This file contains code that implements the edge-based FM refinement + * + * Started 7/23/97 + * George + * + * $Id: mfm2.c,v 1.1 2003/07/16 15:55:09 karypis Exp $ + */ + +#include <metis.h> + + +/************************************************************************* +* This function performs an edge-based FM refinement +**************************************************************************/ +void MocFM_2WayEdgeRefine2(CtrlType *ctrl, GraphType *graph, float *tpwgts, float *orgubvec, + int npasses) +{ + int i, ii, j, k, l, kwgt, nvtxs, ncon, nbnd, nswaps, from, to, pass, me, limit, tmp, cnum; + idxtype *xadj, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind; + idxtype *moved, *swaps, *perm, *qnum; + float *nvwgt, *npwgts, origdiff[MAXNCON], origbal[MAXNCON], minbal[MAXNCON]; + PQueueType parts[MAXNCON][2]; + int higain, oldgain, mincut, initcut, newcut, mincutorder; + float *maxwgt, *minwgt, ubvec[MAXNCON], tvec[MAXNCON]; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + id = graph->id; + ed = graph->ed; + npwgts = graph->npwgts; + bndptr = graph->bndptr; + bndind = graph->bndind; + + moved = idxwspacemalloc(ctrl, nvtxs); + swaps = idxwspacemalloc(ctrl, nvtxs); + perm = idxwspacemalloc(ctrl, nvtxs); + qnum = idxwspacemalloc(ctrl, nvtxs); + + limit = amin(amax(0.01*nvtxs, 15), 100); + + Compute2WayHLoadImbalanceVec(ncon, npwgts, tpwgts, origbal); + for (i=0; i<ncon; i++) { + origdiff[i] = fabs(tpwgts[0]-npwgts[i]); + ubvec[i] = amax(origbal[i], orgubvec[i]); + } + + /* Setup the weight intervals of the two subdomains */ + minwgt = fwspacemalloc(ctrl, 2*ncon); + maxwgt = fwspacemalloc(ctrl, 2*ncon); + + for (i=0; i<2; i++) { + for (j=0; j<ncon; j++) { + maxwgt[i*ncon+j] = tpwgts[i]*ubvec[j]; + minwgt[i*ncon+j] = tpwgts[i]*(1.0/ubvec[j]); + } + } + + /* Initialize the queues */ + for (i=0; i<ncon; i++) { + PQueueInit(ctrl, &parts[i][0], nvtxs, PLUS_GAINSPAN+1); + PQueueInit(ctrl, &parts[i][1], nvtxs, PLUS_GAINSPAN+1); + } + for (i=0; i<nvtxs; i++) + qnum[i] = samax(ncon, nvwgt+i*ncon); + + + if (ctrl->dbglvl&DBG_REFINE) { + printf("Parts: ["); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf("] T[%.3f %.3f], Nv-Nb[%5d, %5d]. ICut: %6d, LB: ", tpwgts[0], tpwgts[1], + graph->nvtxs, graph->nbnd, graph->mincut); + for (i=0; i<ncon; i++) + printf("%.3f ", origbal[i]); + printf("\n"); + } + + idxset(nvtxs, -1, moved); + for (pass=0; pass<npasses; pass++) { /* Do a number of passes */ + for (i=0; i<ncon; i++) { + PQueueReset(&parts[i][0]); + PQueueReset(&parts[i][1]); + } + + mincutorder = -1; + newcut = mincut = initcut = graph->mincut; + Compute2WayHLoadImbalanceVec(ncon, npwgts, tpwgts, minbal); + + ASSERT(ComputeCut(graph, where) == graph->mincut); + ASSERT(CheckBnd(graph)); + + /* Insert boundary nodes in the priority queues */ + nbnd = graph->nbnd; + RandomPermute(nbnd, perm, 1); + for (ii=0; ii<nbnd; ii++) { + i = bndind[perm[ii]]; + ASSERT(ed[i] > 0 || id[i] == 0); + ASSERT(bndptr[i] != -1); + PQueueInsert(&parts[qnum[i]][where[i]], i, ed[i]-id[i]); + } + + for (nswaps=0; nswaps<nvtxs; nswaps++) { + SelectQueue2(ncon, npwgts, tpwgts, &from, &cnum, parts, maxwgt); + to = (from+1)%2; + + if (from == -1 || (higain = PQueueGetMax(&parts[cnum][from])) == -1) + break; + ASSERT(bndptr[higain] != -1); + + newcut -= (ed[higain]-id[higain]); + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + + Compute2WayHLoadImbalanceVec(ncon, npwgts, tpwgts, tvec); + if ((newcut < mincut && AreAllBelow(ncon, tvec, ubvec)) || + (newcut == mincut && IsBetter2wayBalance(ncon, tvec, minbal, ubvec))) { + mincut = newcut; + for (i=0; i<ncon; i++) + minbal[i] = tvec[i]; + mincutorder = nswaps; + } + else if (nswaps-mincutorder > limit) { /* We hit the limit, undo last move */ + newcut += (ed[higain]-id[higain]); + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + break; + } + + where[higain] = to; + moved[higain] = nswaps; + swaps[nswaps] = higain; + + if (ctrl->dbglvl&DBG_MOVEINFO) { + printf("Moved %6d from %d(%d). Gain: %5d, Cut: %5d, NPwgts: ", higain, from, cnum, ed[higain]-id[higain], newcut); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + + printf(", LB: "); + for (i=0; i<ncon; i++) + printf("%.3f ", tvec[i]); + if (mincutorder == nswaps) + printf(" *\n"); + else + printf("\n"); + } + + + /************************************************************** + * Update the id[i]/ed[i] values of the affected nodes + ***************************************************************/ + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + oldgain = ed[k]-id[k]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + /* Update its boundary information and queue position */ + if (bndptr[k] != -1) { /* If k was a boundary vertex */ + if (ed[k] == 0) { /* Not a boundary vertex any more */ + BNDDelete(nbnd, bndind, bndptr, k); + if (moved[k] == -1) /* Remove it if in the queues */ + PQueueDelete(&parts[qnum[k]][where[k]], k, oldgain); + } + else { /* If it has not been moved, update its position in the queue */ + if (moved[k] == -1) + PQueueUpdate(&parts[qnum[k]][where[k]], k, oldgain, ed[k]-id[k]); + } + } + else { + if (ed[k] > 0) { /* It will now become a boundary vertex */ + BNDInsert(nbnd, bndind, bndptr, k); + if (moved[k] == -1) + PQueueInsert(&parts[qnum[k]][where[k]], k, ed[k]-id[k]); + } + } + } + + } + + + /**************************************************************** + * Roll back computations + *****************************************************************/ + for (i=0; i<nswaps; i++) + moved[swaps[i]] = -1; /* reset moved array */ + for (nswaps--; nswaps>mincutorder; nswaps--) { + higain = swaps[nswaps]; + + to = where[higain] = (where[higain]+1)%2; + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + else if (ed[higain] > 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+((to+1)%2)*ncon, 1); + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + if (bndptr[k] != -1 && ed[k] == 0) + BNDDelete(nbnd, bndind, bndptr, k); + if (bndptr[k] == -1 && ed[k] > 0) + BNDInsert(nbnd, bndind, bndptr, k); + } + } + + if (ctrl->dbglvl&DBG_REFINE) { + printf("\tMincut: %6d at %5d, NBND: %6d, NPwgts: [", mincut, mincutorder, nbnd); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf("], LB: "); + Compute2WayHLoadImbalanceVec(ncon, npwgts, tpwgts, tvec); + for (i=0; i<ncon; i++) + printf("%.3f ", tvec[i]); + printf("\n"); + } + + graph->mincut = mincut; + graph->nbnd = nbnd; + + if (mincutorder == -1 || mincut == initcut) + break; + } + + for (i=0; i<ncon; i++) { + PQueueFree(ctrl, &parts[i][0]); + PQueueFree(ctrl, &parts[i][1]); + } + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + fwspacefree(ctrl, 2*ncon); + fwspacefree(ctrl, 2*ncon); + +} + + +/************************************************************************* +* This function selects the partition number and the queue from which +* we will move vertices out +**************************************************************************/ +void SelectQueue2(int ncon, float *npwgts, float *tpwgts, int *from, int *cnum, + PQueueType queues[MAXNCON][2], float *maxwgt) +{ + int i, j, maxgain=0; + float diff, max, maxdiff=0.0; + + *from = -1; + *cnum = -1; + + /* First determine the side and the queue, irrespective of the presence of nodes */ + for (j=0; j<2; j++) { + for (i=0; i<ncon; i++) { + diff = npwgts[j*ncon+i]-maxwgt[j*ncon+i]; + if (diff >= maxdiff) { + maxdiff = diff; + *from = j; + *cnum = i; + } + } + } + + if (*from != -1 && PQueueGetSize(&queues[*cnum][*from]) == 0) { + /* The desired queue is empty, select a node from that side anyway */ + for (i=0; i<ncon; i++) { + if (PQueueGetSize(&queues[i][*from]) > 0) { + max = (npwgts[(*from)*ncon+i] - maxwgt[(*from)*ncon+i]); + *cnum = i; + break; + } + } + + for (i++; i<ncon; i++) { + diff = npwgts[(*from)*ncon+i] - maxwgt[(*from)*ncon+i]; + if (diff > max && PQueueGetSize(&queues[i][*from]) > 0) { + max = diff; + *cnum = i; + } + } + } + + /* Check to see if you can focus on the cut */ + if (maxdiff <= 0.0) { + maxgain = -100000; + + for (j=0; j<2; j++) { + for (i=0; i<ncon; i++) { + if (PQueueGetSize(&queues[i][j]) > 0 && PQueueGetKey(&queues[i][j]) > maxgain) { + maxgain = PQueueGetKey(&queues[i][j]); + *from = j; + *cnum = i; + } + } + } + + /* printf("(%2d %2d) %3d\n", *from, *cnum, maxgain); */ + } +} + + +/************************************************************************* +* This function checks if the newbal is better than oldbal given the +* ubvector ubvec +**************************************************************************/ +int IsBetter2wayBalance(int ncon, float *newbal, float *oldbal, float *ubvec) +{ + int i, j; + float max1=0.0, max2=0.0, sum1=0.0, sum2=0.0, tmp; + + for (i=0; i<ncon; i++) { + tmp = (newbal[i]-1)/(ubvec[i]-1); + max1 = (max1 < tmp ? tmp : max1); + sum1 += tmp; + + tmp = (oldbal[i]-1)/(ubvec[i]-1); + max2 = (max2 < tmp ? tmp : max2); + sum2 += tmp; + } + + if (max1 < max2) + return 1; + else if (max1 > max2) + return 0; + else + return sum1 <= sum2; +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mincover.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mincover.c new file mode 100644 index 0000000..789022b --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mincover.c @@ -0,0 +1,259 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mincover.c + * + * This file implements the minimum cover algorithm + * + * Started 8/1/97 + * George + * + * $Id: mincover.c,v 1.1 2003/07/16 15:55:09 karypis Exp $ + */ + +#include <metis.h> + +/************************************************************************* +* Constants used by mincover algorithm +**************************************************************************/ +#define INCOL 10 +#define INROW 20 +#define VC 1 +#define SC 2 +#define HC 3 +#define VR 4 +#define SR 5 +#define HR 6 + + +/************************************************************************* +* This function returns the min-cover of a bipartite graph. +* The algorithm used is due to Hopcroft and Karp as modified by Duff etal +* adj: the adjacency list of the bipartite graph +* asize: the number of vertices in the first part of the bipartite graph +* bsize-asize: the number of vertices in the second part +* 0..(asize-1) > A vertices +* asize..bsize > B vertices +* +* Returns: +* cover : the actual cover (array) +* csize : the size of the cover +**************************************************************************/ +void MinCover(idxtype *xadj, idxtype *adjncy, int asize, int bsize, idxtype *cover, int *csize) +{ + int i, j; + idxtype *mate, *queue, *flag, *level, *lst; + int fptr, rptr, lstptr; + int row, maxlevel, col; + + mate = idxsmalloc(bsize, -1, "MinCover: mate"); + flag = idxmalloc(bsize, "MinCover: flag"); + level = idxmalloc(bsize, "MinCover: level"); + queue = idxmalloc(bsize, "MinCover: queue"); + lst = idxmalloc(bsize, "MinCover: lst"); + + /* Get a cheap matching */ + for (i=0; i<asize; i++) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (mate[adjncy[j]] == -1) { + mate[i] = adjncy[j]; + mate[adjncy[j]] = i; + break; + } + } + } + + /* Get into the main loop */ + while (1) { + /* Initialization */ + fptr = rptr = 0; /* Empty Queue */ + lstptr = 0; /* Empty List */ + for (i=0; i<bsize; i++) { + level[i] = -1; + flag[i] = 0; + } + maxlevel = bsize; + + /* Insert free nodes into the queue */ + for (i=0; i<asize; i++) + if (mate[i] == -1) { + queue[rptr++] = i; + level[i] = 0; + } + + /* Perform the BFS */ + while (fptr != rptr) { + row = queue[fptr++]; + if (level[row] < maxlevel) { + flag[row] = 1; + for (j=xadj[row]; j<xadj[row+1]; j++) { + col = adjncy[j]; + if (!flag[col]) { /* If this column has not been accessed yet */ + flag[col] = 1; + if (mate[col] == -1) { /* Free column node was found */ + maxlevel = level[row]; + lst[lstptr++] = col; + } + else { /* This column node is matched */ + if (flag[mate[col]]) + printf("\nSomething wrong, flag[%d] is 1",mate[col]); + queue[rptr++] = mate[col]; + level[mate[col]] = level[row] + 1; + } + } + } + } + } + + if (lstptr == 0) + break; /* No free columns can be reached */ + + /* Perform restricted DFS from the free column nodes */ + for (i=0; i<lstptr; i++) + MinCover_Augment(xadj, adjncy, lst[i], mate, flag, level, maxlevel); + } + + MinCover_Decompose(xadj, adjncy, asize, bsize, mate, cover, csize); + + GKfree(&mate, &flag, &level, &queue, &lst, LTERM); + +} + + +/************************************************************************* +* This function perfoms a restricted DFS and augments matchings +**************************************************************************/ +int MinCover_Augment(idxtype *xadj, idxtype *adjncy, int col, idxtype *mate, idxtype *flag, idxtype *level, int maxlevel) +{ + int i; + int row = -1; + int status; + + flag[col] = 2; + for (i=xadj[col]; i<xadj[col+1]; i++) { + row = adjncy[i]; + + if (flag[row] == 1) { /* First time through this row node */ + if (level[row] == maxlevel) { /* (col, row) is an edge of the G^T */ + flag[row] = 2; /* Mark this node as being visited */ + if (maxlevel != 0) + status = MinCover_Augment(xadj, adjncy, mate[row], mate, flag, level, maxlevel-1); + else + status = 1; + + if (status) { + mate[col] = row; + mate[row] = col; + return 1; + } + } + } + } + + return 0; +} + + + +/************************************************************************* +* This function performs a coarse decomposition and determines the +* min-cover. +* REF: Pothen ACMTrans. on Amth Software +**************************************************************************/ +void MinCover_Decompose(idxtype *xadj, idxtype *adjncy, int asize, int bsize, idxtype *mate, idxtype *cover, int *csize) +{ + int i, k; + idxtype *where; + int card[10]; + + where = idxmalloc(bsize, "MinCover_Decompose: where"); + for (i=0; i<10; i++) + card[i] = 0; + + for (i=0; i<asize; i++) + where[i] = SC; + for (; i<bsize; i++) + where[i] = SR; + + for (i=0; i<asize; i++) + if (mate[i] == -1) + MinCover_ColDFS(xadj, adjncy, i, mate, where, INCOL); + for (; i<bsize; i++) + if (mate[i] == -1) + MinCover_RowDFS(xadj, adjncy, i, mate, where, INROW); + + for (i=0; i<bsize; i++) + card[where[i]]++; + + k = 0; + if (abs(card[VC]+card[SC]-card[HR]) < abs(card[VC]-card[SR]-card[HR])) { /* S = VC+SC+HR */ + /* printf("%d %d ",vc+sc, hr); */ + for (i=0; i<bsize; i++) + if (where[i] == VC || where[i] == SC || where[i] == HR) + cover[k++] = i; + } + else { /* S = VC+SR+HR */ + /* printf("%d %d ",vc, hr+sr); */ + for (i=0; i<bsize; i++) + if (where[i] == VC || where[i] == SR || where[i] == HR) + cover[k++] = i; + } + + *csize = k; + free(where); + +} + + +/************************************************************************* +* This function perfoms a dfs starting from an unmatched col node +* forming alternate paths +**************************************************************************/ +void MinCover_ColDFS(idxtype *xadj, idxtype *adjncy, int root, idxtype *mate, idxtype *where, int flag) +{ + int i; + + if (flag == INCOL) { + if (where[root] == HC) + return; + where[root] = HC; + for (i=xadj[root]; i<xadj[root+1]; i++) + MinCover_ColDFS(xadj, adjncy, adjncy[i], mate, where, INROW); + } + else { + if (where[root] == HR) + return; + where[root] = HR; + if (mate[root] != -1) + MinCover_ColDFS(xadj, adjncy, mate[root], mate, where, INCOL); + } + +} + +/************************************************************************* +* This function perfoms a dfs starting from an unmatched col node +* forming alternate paths +**************************************************************************/ +void MinCover_RowDFS(idxtype *xadj, idxtype *adjncy, int root, idxtype *mate, idxtype *where, int flag) +{ + int i; + + if (flag == INROW) { + if (where[root] == VR) + return; + where[root] = VR; + for (i=xadj[root]; i<xadj[root+1]; i++) + MinCover_RowDFS(xadj, adjncy, adjncy[i], mate, where, INCOL); + } + else { + if (where[root] == VC) + return; + where[root] = VC; + if (mate[root] != -1) + MinCover_RowDFS(xadj, adjncy, mate[root], mate, where, INROW); + } + +} + + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/minitpart.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/minitpart.c new file mode 100644 index 0000000..58dfcea --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/minitpart.c @@ -0,0 +1,358 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * minitpart.c + * + * This file contains code that performs the initial partition of the + * coarsest graph + * + * Started 7/23/97 + * George + * + * $Id: minitpart.c,v 1.2 2003/07/31 16:23:29 karypis Exp $ + * + */ + +#include <metis.h> + +/************************************************************************* +* This function computes the initial bisection of the coarsest graph +**************************************************************************/ +void MocInit2WayPartition(CtrlType *ctrl, GraphType *graph, float *tpwgts, float ubfactor) +{ + int i, dbglvl; + + dbglvl = ctrl->dbglvl; + IFSET(ctrl->dbglvl, DBG_REFINE, ctrl->dbglvl -= DBG_REFINE); + IFSET(ctrl->dbglvl, DBG_MOVEINFO, ctrl->dbglvl -= DBG_MOVEINFO); + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->InitPartTmr)); + + switch (ctrl->IType) { + case IPART_GGPKL: + if (graph->nedges == 0) + MocRandomBisection(ctrl, graph, tpwgts, ubfactor); + else + MocGrowBisection(ctrl, graph, tpwgts, ubfactor); + break; + case IPART_RANDOM: + MocRandomBisection(ctrl, graph, tpwgts, ubfactor); + break; + default: + errexit("Unknown initial partition type: %d\n", ctrl->IType); + } + + IFSET(ctrl->dbglvl, DBG_IPART, printf("Initial Cut: %d\n", graph->mincut)); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->InitPartTmr)); + ctrl->dbglvl = dbglvl; + +} + + + + + +/************************************************************************* +* This function takes a graph and produces a bisection by using a region +* growing algorithm. The resulting partition is returned in +* graph->where +**************************************************************************/ +void MocGrowBisection(CtrlType *ctrl, GraphType *graph, float *tpwgts, float ubfactor) +{ + int i, j, k, nvtxs, ncon, from, bestcut, mincut, nbfs; + idxtype *bestwhere, *where; + + nvtxs = graph->nvtxs; + + MocAllocate2WayPartitionMemory(ctrl, graph); + where = graph->where; + + bestwhere = idxmalloc(nvtxs, "BisectGraph: bestwhere"); + nbfs = 2*(nvtxs <= ctrl->CoarsenTo ? SMALLNIPARTS : LARGENIPARTS); + bestcut = idxsum(graph->nedges, graph->adjwgt); + + for (; nbfs>0; nbfs--) { + idxset(nvtxs, 1, where); + where[RandomInRange(nvtxs)] = 0; + + MocCompute2WayPartitionParams(ctrl, graph); + + MocInit2WayBalance(ctrl, graph, tpwgts); + + MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 4); + + MocBalance2Way(ctrl, graph, tpwgts, 1.02); + MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 4); + + if (bestcut > graph->mincut) { + bestcut = graph->mincut; + idxcopy(nvtxs, where, bestwhere); + if (bestcut == 0) + break; + } + } + + graph->mincut = bestcut; + idxcopy(nvtxs, bestwhere, where); + + GKfree(&bestwhere, LTERM); +} + + + +/************************************************************************* +* This function takes a graph and produces a bisection by using a region +* growing algorithm. The resulting partition is returned in +* graph->where +**************************************************************************/ +void MocRandomBisection(CtrlType *ctrl, GraphType *graph, float *tpwgts, float ubfactor) +{ + int i, ii, j, k, nvtxs, ncon, from, bestcut, mincut, nbfs, qnum; + idxtype *bestwhere, *where, *perm; + int counts[MAXNCON]; + float *nvwgt; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + nvwgt = graph->nvwgt; + + MocAllocate2WayPartitionMemory(ctrl, graph); + where = graph->where; + + bestwhere = idxmalloc(nvtxs, "BisectGraph: bestwhere"); + nbfs = 2*(nvtxs <= ctrl->CoarsenTo ? SMALLNIPARTS : LARGENIPARTS); + bestcut = idxsum(graph->nedges, graph->adjwgt); + perm = idxmalloc(nvtxs, "BisectGraph: perm"); + + for (; nbfs>0; nbfs--) { + for (i=0; i<ncon; i++) + counts[i] = 0; + + RandomPermute(nvtxs, perm, 1); + + /* Partition by spliting the queues randomly */ + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + qnum = samax(ncon, nvwgt+i*ncon); + where[i] = counts[qnum]; + counts[qnum] = (counts[qnum]+1)%2; + } + + MocCompute2WayPartitionParams(ctrl, graph); + + MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 6); + MocBalance2Way(ctrl, graph, tpwgts, 1.02); + MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 6); + MocBalance2Way(ctrl, graph, tpwgts, 1.02); + MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 6); + + /* + printf("Edgecut: %6d, NPwgts: [", graph->mincut); + for (i=0; i<graph->ncon; i++) + printf("(%.3f %.3f) ", graph->npwgts[i], graph->npwgts[graph->ncon+i]); + printf("]\n"); + */ + + if (bestcut > graph->mincut) { + bestcut = graph->mincut; + idxcopy(nvtxs, where, bestwhere); + if (bestcut == 0) + break; + } + } + + graph->mincut = bestcut; + idxcopy(nvtxs, bestwhere, where); + + GKfree(&bestwhere, &perm, LTERM); +} + + + + +/************************************************************************* +* This function balances two partitions by moving the highest gain +* (including negative gain) vertices to the other domain. +* It is used only when tha unbalance is due to non contigous +* subdomains. That is, the are no boundary vertices. +* It moves vertices from the domain that is overweight to the one that +* is underweight. +**************************************************************************/ +void MocInit2WayBalance(CtrlType *ctrl, GraphType *graph, float *tpwgts) +{ + int i, ii, j, k, l, kwgt, nvtxs, nbnd, ncon, nswaps, from, to, pass, me, cnum, tmp; + idxtype *xadj, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind; + idxtype *perm, *qnum; + float *nvwgt, *npwgts; + PQueueType parts[MAXNCON][2]; + int higain, oldgain, mincut; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + adjncy = graph->adjncy; + nvwgt = graph->nvwgt; + adjwgt = graph->adjwgt; + where = graph->where; + id = graph->id; + ed = graph->ed; + npwgts = graph->npwgts; + bndptr = graph->bndptr; + bndind = graph->bndind; + + perm = idxwspacemalloc(ctrl, nvtxs); + qnum = idxwspacemalloc(ctrl, nvtxs); + + /* This is called for initial partitioning so we know from where to pick nodes */ + from = 1; + to = (from+1)%2; + + if (ctrl->dbglvl&DBG_REFINE) { + printf("Parts: ["); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf("] T[%.3f %.3f], Nv-Nb[%5d, %5d]. ICut: %6d, LB: %.3f [B]\n", tpwgts[0], tpwgts[1], + graph->nvtxs, graph->nbnd, graph->mincut, + Compute2WayHLoadImbalance(ncon, npwgts, tpwgts)); + } + + for (i=0; i<ncon; i++) { + PQueueInit(ctrl, &parts[i][0], nvtxs, PLUS_GAINSPAN+1); + PQueueInit(ctrl, &parts[i][1], nvtxs, PLUS_GAINSPAN+1); + } + + ASSERT(ComputeCut(graph, where) == graph->mincut); + ASSERT(CheckBnd(graph)); + ASSERT(CheckGraph(graph)); + + /* Compute the queues in which each vertex will be assigned to */ + for (i=0; i<nvtxs; i++) + qnum[i] = samax(ncon, nvwgt+i*ncon); + + /* Insert the nodes of the proper partition in the appropriate priority queue */ + RandomPermute(nvtxs, perm, 1); + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + if (where[i] == from) { + if (ed[i] > 0) + PQueueInsert(&parts[qnum[i]][0], i, ed[i]-id[i]); + else + PQueueInsert(&parts[qnum[i]][1], i, ed[i]-id[i]); + } + } + + + mincut = graph->mincut; + nbnd = graph->nbnd; + for (nswaps=0; nswaps<nvtxs; nswaps++) { + if (AreAnyVwgtsBelow(ncon, 1.0, npwgts+from*ncon, 0.0, nvwgt, tpwgts[from])) + break; + + if ((cnum = SelectQueueOneWay(ncon, npwgts, tpwgts, from, parts)) == -1) + break; + + if ((higain = PQueueGetMax(&parts[cnum][0])) == -1) + higain = PQueueGetMax(&parts[cnum][1]); + + mincut -= (ed[higain]-id[higain]); + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + + where[higain] = to; + + if (ctrl->dbglvl&DBG_MOVEINFO) { + printf("Moved %6d from %d(%d). [%5d] %5d, NPwgts: ", higain, from, cnum, ed[higain]-id[higain], mincut); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf(", LB: %.3f\n", Compute2WayHLoadImbalance(ncon, npwgts, tpwgts)); + if (ed[higain] == 0 && id[higain] > 0) + printf("\t Pulled from the interior!\n"); + } + + + /************************************************************** + * Update the id[i]/ed[i] values of the affected nodes + ***************************************************************/ + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + if (ed[higain] > 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + oldgain = ed[k]-id[k]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + /* Update the queue position */ + if (where[k] == from) { + if (ed[k] > 0 && bndptr[k] == -1) { /* It moves in boundary */ + PQueueDelete(&parts[qnum[k]][1], k, oldgain); + PQueueInsert(&parts[qnum[k]][0], k, ed[k]-id[k]); + } + else { /* It must be in the boundary already */ + if (bndptr[k] == -1) + printf("What you thought was wrong!\n"); + PQueueUpdate(&parts[qnum[k]][0], k, oldgain, ed[k]-id[k]); + } + } + + /* Update its boundary information */ + if (ed[k] == 0 && bndptr[k] != -1) + BNDDelete(nbnd, bndind, bndptr, k); + else if (ed[k] > 0 && bndptr[k] == -1) + BNDInsert(nbnd, bndind, bndptr, k); + } + + ASSERTP(ComputeCut(graph, where) == mincut, ("%d != %d\n", ComputeCut(graph, where), mincut)); + + } + + if (ctrl->dbglvl&DBG_REFINE) { + printf("\tMincut: %6d, NBND: %6d, NPwgts: ", mincut, nbnd); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf(", LB: %.3f\n", Compute2WayHLoadImbalance(ncon, npwgts, tpwgts)); + } + + graph->mincut = mincut; + graph->nbnd = nbnd; + + for (i=0; i<ncon; i++) { + PQueueFree(ctrl, &parts[i][0]); + PQueueFree(ctrl, &parts[i][1]); + } + + ASSERT(ComputeCut(graph, where) == graph->mincut); + ASSERT(CheckBnd(graph)); + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + + + +/************************************************************************* +* This function selects the partition number and the queue from which +* we will move vertices out +**************************************************************************/ +int SelectQueueOneWay(int ncon, float *npwgts, float *tpwgts, int from, PQueueType queues[MAXNCON][2]) +{ + int i, cnum=-1; + float max=0.0; + + for (i=0; i<ncon; i++) { + if (npwgts[from*ncon+i]-tpwgts[from] >= max && + PQueueGetSize(&queues[i][0]) + PQueueGetSize(&queues[i][1]) > 0) { + max = npwgts[from*ncon+i]-tpwgts[0]; + cnum = i; + } + } + + return cnum; +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/minitpart2.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/minitpart2.c new file mode 100644 index 0000000..4c1e1b1 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/minitpart2.c @@ -0,0 +1,368 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * minitpart2.c + * + * This file contains code that performs the initial partition of the + * coarsest graph + * + * Started 7/23/97 + * George + * + * $Id: minitpart2.c,v 1.1 2003/07/16 15:55:10 karypis Exp $ + * + */ + +#include <metis.h> + +/************************************************************************* +* This function computes the initial bisection of the coarsest graph +**************************************************************************/ +void MocInit2WayPartition2(CtrlType *ctrl, GraphType *graph, float *tpwgts, float *ubvec) +{ + int dbglvl; + + dbglvl = ctrl->dbglvl; + IFSET(ctrl->dbglvl, DBG_REFINE, ctrl->dbglvl -= DBG_REFINE); + IFSET(ctrl->dbglvl, DBG_MOVEINFO, ctrl->dbglvl -= DBG_MOVEINFO); + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->InitPartTmr)); + + switch (ctrl->IType) { + case IPART_GGPKL: + case IPART_RANDOM: + MocGrowBisection2(ctrl, graph, tpwgts, ubvec); + break; + case 3: + MocGrowBisectionNew2(ctrl, graph, tpwgts, ubvec); + break; + default: + errexit("Unknown initial partition type: %d\n", ctrl->IType); + } + + IFSET(ctrl->dbglvl, DBG_IPART, printf("Initial Cut: %d\n", graph->mincut)); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->InitPartTmr)); + ctrl->dbglvl = dbglvl; + +} + + + + +/************************************************************************* +* This function takes a graph and produces a bisection by using a region +* growing algorithm. The resulting partition is returned in +* graph->where +**************************************************************************/ +void MocGrowBisection2(CtrlType *ctrl, GraphType *graph, float *tpwgts, float *ubvec) +{ + int i, j, k, nvtxs, ncon, from, bestcut, mincut, nbfs; + idxtype *bestwhere, *where; + + nvtxs = graph->nvtxs; + + MocAllocate2WayPartitionMemory(ctrl, graph); + where = graph->where; + + bestwhere = idxmalloc(nvtxs, "BisectGraph: bestwhere"); + nbfs = 2*(nvtxs <= ctrl->CoarsenTo ? SMALLNIPARTS : LARGENIPARTS); + bestcut = idxsum(graph->nedges, graph->adjwgt); + + for (; nbfs>0; nbfs--) { + idxset(nvtxs, 1, where); + where[RandomInRange(nvtxs)] = 0; + + MocCompute2WayPartitionParams(ctrl, graph); + + MocBalance2Way2(ctrl, graph, tpwgts, ubvec); + + MocFM_2WayEdgeRefine2(ctrl, graph, tpwgts, ubvec, 4); + + MocBalance2Way2(ctrl, graph, tpwgts, ubvec); + MocFM_2WayEdgeRefine2(ctrl, graph, tpwgts, ubvec, 4); + + if (bestcut > graph->mincut) { + bestcut = graph->mincut; + idxcopy(nvtxs, where, bestwhere); + if (bestcut == 0) + break; + } + } + + graph->mincut = bestcut; + idxcopy(nvtxs, bestwhere, where); + + GKfree(&bestwhere, LTERM); +} + + + + + + +/************************************************************************* +* This function takes a graph and produces a bisection by using a region +* growing algorithm. The resulting partition is returned in +* graph->where +**************************************************************************/ +void MocGrowBisectionNew2(CtrlType *ctrl, GraphType *graph, float *tpwgts, float *ubvec) +{ + int i, j, k, nvtxs, ncon, from, bestcut, mincut, nbfs; + idxtype *bestwhere, *where; + + nvtxs = graph->nvtxs; + + MocAllocate2WayPartitionMemory(ctrl, graph); + where = graph->where; + + bestwhere = idxmalloc(nvtxs, "BisectGraph: bestwhere"); + nbfs = 2*(nvtxs <= ctrl->CoarsenTo ? SMALLNIPARTS : LARGENIPARTS); + bestcut = idxsum(graph->nedges, graph->adjwgt); + + for (; nbfs>0; nbfs--) { + idxset(nvtxs, 1, where); + where[RandomInRange(nvtxs)] = 0; + + MocCompute2WayPartitionParams(ctrl, graph); + + MocInit2WayBalance2(ctrl, graph, tpwgts, ubvec); + + MocFM_2WayEdgeRefine2(ctrl, graph, tpwgts, ubvec, 4); + + if (bestcut > graph->mincut) { + bestcut = graph->mincut; + idxcopy(nvtxs, where, bestwhere); + if (bestcut == 0) + break; + } + } + + graph->mincut = bestcut; + idxcopy(nvtxs, bestwhere, where); + + GKfree(&bestwhere, LTERM); +} + + + +/************************************************************************* +* This function balances two partitions by moving the highest gain +* (including negative gain) vertices to the other domain. +* It is used only when tha unbalance is due to non contigous +* subdomains. That is, the are no boundary vertices. +* It moves vertices from the domain that is overweight to the one that +* is underweight. +**************************************************************************/ +void MocInit2WayBalance2(CtrlType *ctrl, GraphType *graph, float *tpwgts, float *ubvec) +{ + int i, ii, j, k, l, kwgt, nvtxs, nbnd, ncon, nswaps, from, to, pass, me, cnum, tmp, imin; + idxtype *xadj, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind; + idxtype *moved, *perm, *qnum; + float *nvwgt, *npwgts, minwgt; + PQueueType parts[MAXNCON][2]; + int higain, oldgain, mincut; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + adjncy = graph->adjncy; + nvwgt = graph->nvwgt; + adjwgt = graph->adjwgt; + where = graph->where; + id = graph->id; + ed = graph->ed; + npwgts = graph->npwgts; + bndptr = graph->bndptr; + bndind = graph->bndind; + + moved = idxwspacemalloc(ctrl, nvtxs); + perm = idxwspacemalloc(ctrl, nvtxs); + qnum = idxwspacemalloc(ctrl, nvtxs); + + /* This is called for initial partitioning so we know from where to pick nodes */ + from = 1; + to = (from+1)%2; + + if (ctrl->dbglvl&DBG_REFINE) { + printf("Parts: ["); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf("] T[%.3f %.3f], Nv-Nb[%5d, %5d]. ICut: %6d, LB: %.3f [B]\n", tpwgts[0], tpwgts[1], graph->nvtxs, graph->nbnd, graph->mincut, ComputeLoadImbalance(ncon, 2, npwgts, tpwgts)); + } + + for (i=0; i<ncon; i++) { + PQueueInit(ctrl, &parts[i][0], nvtxs, PLUS_GAINSPAN+1); + PQueueInit(ctrl, &parts[i][1], nvtxs, PLUS_GAINSPAN+1); + } + + idxset(nvtxs, -1, moved); + + ASSERT(ComputeCut(graph, where) == graph->mincut); + ASSERT(CheckBnd(graph)); + ASSERT(CheckGraph(graph)); + + /* Compute the queues in which each vertex will be assigned to */ + for (i=0; i<nvtxs; i++) + qnum[i] = samax(ncon, nvwgt+i*ncon); + + /* Insert the nodes of the proper partition in the appropriate priority queue */ + RandomPermute(nvtxs, perm, 1); + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + if (where[i] == from) { + if (ed[i] > 0) + PQueueInsert(&parts[qnum[i]][0], i, ed[i]-id[i]); + else + PQueueInsert(&parts[qnum[i]][1], i, ed[i]-id[i]); + } + } + +/* + for (i=0; i<ncon; i++) + printf("Queue #%d has %d %d\n", i, parts[i][0].nnodes, parts[i][1].nnodes); +*/ + + /* Determine the termination criterion */ + imin = 0; + for (i=1; i<ncon; i++) + imin = (ubvec[i] < ubvec[imin] ? i : imin); + minwgt = .5/ubvec[imin]; + + mincut = graph->mincut; + nbnd = graph->nbnd; + for (nswaps=0; nswaps<nvtxs; nswaps++) { + /* Exit as soon as the minimum weight crossed over */ + if (npwgts[to*ncon+imin] > minwgt) + break; + + if ((cnum = SelectQueueOneWay2(ncon, npwgts+to*ncon, parts, ubvec)) == -1) + break; + + if ((higain = PQueueGetMax(&parts[cnum][0])) == -1) + higain = PQueueGetMax(&parts[cnum][1]); + + mincut -= (ed[higain]-id[higain]); + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + + where[higain] = to; + moved[higain] = nswaps; + + if (ctrl->dbglvl&DBG_MOVEINFO) { + printf("Moved %6d from %d(%d). [%5d] %5d, NPwgts: ", higain, from, cnum, ed[higain]-id[higain], mincut); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf(", LB: %.3f\n", ComputeLoadImbalance(ncon, 2, npwgts, tpwgts)); + if (ed[higain] == 0 && id[higain] > 0) + printf("\t Pulled from the interior!\n"); + } + + + /************************************************************** + * Update the id[i]/ed[i] values of the affected nodes + ***************************************************************/ + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + if (ed[higain] > 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + oldgain = ed[k]-id[k]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + /* Update the queue position */ + if (moved[k] == -1 && where[k] == from) { + if (ed[k] > 0 && bndptr[k] == -1) { /* It moves in boundary */ + PQueueDelete(&parts[qnum[k]][1], k, oldgain); + PQueueInsert(&parts[qnum[k]][0], k, ed[k]-id[k]); + } + else { /* It must be in the boundary already */ + if (bndptr[k] == -1) + printf("What you thought was wrong!\n"); + PQueueUpdate(&parts[qnum[k]][0], k, oldgain, ed[k]-id[k]); + } + } + + /* Update its boundary information */ + if (ed[k] == 0 && bndptr[k] != -1) + BNDDelete(nbnd, bndind, bndptr, k); + else if (ed[k] > 0 && bndptr[k] == -1) + BNDInsert(nbnd, bndind, bndptr, k); + } + + ASSERTP(ComputeCut(graph, where) == mincut, ("%d != %d\n", ComputeCut(graph, where), mincut)); + + } + + if (ctrl->dbglvl&DBG_REFINE) { + printf("\tMincut: %6d, NBND: %6d, NPwgts: ", mincut, nbnd); + for (l=0; l<ncon; l++) + printf("(%.3f, %.3f) ", npwgts[l], npwgts[ncon+l]); + printf(", LB: %.3f\n", ComputeLoadImbalance(ncon, 2, npwgts, tpwgts)); + } + + graph->mincut = mincut; + graph->nbnd = nbnd; + + for (i=0; i<ncon; i++) { + PQueueFree(ctrl, &parts[i][0]); + PQueueFree(ctrl, &parts[i][1]); + } + + ASSERT(ComputeCut(graph, where) == graph->mincut); + ASSERT(CheckBnd(graph)); + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + + +/************************************************************************* +* This function selects the partition number and the queue from which +* we will move vertices out +**************************************************************************/ +int SelectQueueOneWay2(int ncon, float *pto, PQueueType queues[MAXNCON][2], float *ubvec) +{ + int i, cnum=-1, imax, maxgain; + float max=0.0; + float twgt[MAXNCON]; + + for (i=0; i<ncon; i++) { + if (max < pto[i]) { + imax = i; + max = pto[i]; + } + } + for (i=0; i<ncon; i++) + twgt[i] = (max/(ubvec[imax]*ubvec[i]))/pto[i]; + twgt[imax] = 0.0; + + max = 0.0; + for (i=0; i<ncon; i++) { + if (max < twgt[i] && (PQueueGetSize(&queues[i][0]) > 0 || PQueueGetSize(&queues[i][1]) > 0)) { + max = twgt[i]; + cnum = i; + } + } + if (max > 1) + return cnum; + + /* optimize of cut */ + maxgain = -10000000; + for (i=0; i<ncon; i++) { + if (PQueueGetSize(&queues[i][0]) > 0 && PQueueGetKey(&queues[i][0]) > maxgain) { + maxgain = PQueueGetKey(&queues[i][0]); + cnum = i; + } + } + + return cnum; + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mkmetis.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mkmetis.c new file mode 100644 index 0000000..55c7c9b --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mkmetis.c @@ -0,0 +1,124 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mkmetis.c + * + * This file contains the top level routines for the multilevel k-way partitioning + * algorithm KMETIS. + * + * Started 7/28/97 + * George + * + * $Id: mkmetis.c,v 1.1 2003/07/16 15:55:10 karypis Exp $ + * + */ + +#include <metis.h> + + + +/************************************************************************* +* This function is the entry point for KWMETIS +**************************************************************************/ +void METIS_mCPartGraphKway(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, + idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, + int *nparts, float *rubvec, int *options, int *edgecut, + idxtype *part) +{ + int i, j; + GraphType graph; + CtrlType ctrl; + + if (*numflag == 1) + Change2CNumbering(*nvtxs, xadj, adjncy); + + SetUpGraph(&graph, OP_KMETIS, *nvtxs, *ncon, xadj, adjncy, vwgt, adjwgt, *wgtflag); + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = McKMETIS_CTYPE; + ctrl.IType = McKMETIS_ITYPE; + ctrl.RType = McKMETIS_RTYPE; + ctrl.dbglvl = McKMETIS_DBGLVL; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + } + ctrl.optype = OP_KMETIS; + ctrl.CoarsenTo = amax((*nvtxs)/(20*log2Int(*nparts)), 30*(*nparts)); + + ctrl.nmaxvwgt = 1.5/(1.0*ctrl.CoarsenTo); + + InitRandom(-1); + + AllocateWorkSpace(&ctrl, &graph, *nparts); + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + ASSERT(CheckGraph(&graph)); + *edgecut = MCMlevelKWayPartitioning(&ctrl, &graph, *nparts, part, rubvec); + + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); + + FreeWorkSpace(&ctrl, &graph); + + if (*numflag == 1) + Change2FNumbering(*nvtxs, xadj, adjncy, part); +} + + +/************************************************************************* +* This function takes a graph and produces a bisection of it +**************************************************************************/ +int MCMlevelKWayPartitioning(CtrlType *ctrl, GraphType *graph, int nparts, idxtype *part, + float *rubvec) +{ + int i, j, nvtxs; + GraphType *cgraph; + int options[10], edgecut; + + cgraph = MCCoarsen2Way(ctrl, graph); + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->InitPartTmr)); + MocAllocateKWayPartitionMemory(ctrl, cgraph, nparts); + + options[0] = 1; + options[OPTION_CTYPE] = MATCH_SBHEM_INFNORM; + options[OPTION_ITYPE] = IPART_RANDOM; + options[OPTION_RTYPE] = RTYPE_FM; + options[OPTION_DBGLVL] = 0; + + /* Determine what you will use as the initial partitioner, based on tolerances */ + for (i=0; i<graph->ncon; i++) { + if (rubvec[i] > 1.2) + break; + } + if (i == graph->ncon) + METIS_mCPartGraphRecursiveInternal(&cgraph->nvtxs, &cgraph->ncon, + cgraph->xadj, cgraph->adjncy, cgraph->nvwgt, cgraph->adjwgt, &nparts, + options, &edgecut, cgraph->where); + else + METIS_mCHPartGraphRecursiveInternal(&cgraph->nvtxs, &cgraph->ncon, + cgraph->xadj, cgraph->adjncy, cgraph->nvwgt, cgraph->adjwgt, &nparts, + rubvec, options, &edgecut, cgraph->where); + + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->InitPartTmr)); + IFSET(ctrl->dbglvl, DBG_IPART, printf("Initial %d-way partitioning cut: %d\n", nparts, edgecut)); + + IFSET(ctrl->dbglvl, DBG_KWAYPINFO, ComputePartitionInfo(cgraph, nparts, cgraph->where)); + + MocRefineKWayHorizontal(ctrl, graph, cgraph, nparts, rubvec); + + idxcopy(graph->nvtxs, graph->where, part); + + GKfree(&graph->nvwgt, &graph->gdata, &graph->rdata, LTERM); + + return graph->mincut; + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mkwayfmh.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mkwayfmh.c new file mode 100644 index 0000000..69a781a --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mkwayfmh.c @@ -0,0 +1,677 @@ +/* + * mkwayfmh.c + * + * This file contains code that implements the multilevel k-way refinement + * + * Started 7/28/97 + * George + * + * $Id: mkwayfmh.c,v 1.1 2003/07/16 15:55:10 karypis Exp $ + * + */ + +#include <metis.h> + + + +/************************************************************************* +* This function performs k-way refinement +**************************************************************************/ +void MCRandom_KWayEdgeRefineHorizontal(CtrlType *ctrl, GraphType *graph, int nparts, + float *orgubvec, int npasses) +{ + int i, ii, iii, j, jj, k, l, pass, nvtxs, ncon, nmoves, nbnd, myndegrees, same; + int from, me, to, oldcut, gain; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *where, *perm, *bndptr, *bndind; + EDegreeType *myedegrees; + RInfoType *myrinfo; + float *npwgts, *nvwgt, *minwgt, *maxwgt, maxlb, minlb, ubvec[MAXNCON], tvec[MAXNCON]; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + bndptr = graph->bndptr; + bndind = graph->bndind; + + where = graph->where; + npwgts = graph->npwgts; + + /* Setup the weight intervals of the various subdomains */ + minwgt = fwspacemalloc(ctrl, nparts*ncon); + maxwgt = fwspacemalloc(ctrl, nparts*ncon); + + /* See if the orgubvec consists of identical constraints */ + maxlb = minlb = orgubvec[0]; + for (i=1; i<ncon; i++) { + minlb = (orgubvec[i] < minlb ? orgubvec[i] : minlb); + maxlb = (orgubvec[i] > maxlb ? orgubvec[i] : maxlb); + } + same = (fabs(maxlb-minlb) < .01 ? 1 : 0); + + + /* Let's not get very optimistic. Let Balancing do the work */ + ComputeHKWayLoadImbalance(ncon, nparts, npwgts, ubvec); + for (i=0; i<ncon; i++) + ubvec[i] = amax(ubvec[i], orgubvec[i]); + + if (!same) { + for (i=0; i<nparts; i++) { + for (j=0; j<ncon; j++) { + maxwgt[i*ncon+j] = ubvec[j]/nparts; + minwgt[i*ncon+j] = 1.0/(ubvec[j]*nparts); + } + } + } + else { + maxlb = ubvec[0]; + for (i=1; i<ncon; i++) + maxlb = (ubvec[i] > maxlb ? ubvec[i] : maxlb); + + for (i=0; i<nparts; i++) { + for (j=0; j<ncon; j++) { + maxwgt[i*ncon+j] = maxlb/nparts; + minwgt[i*ncon+j] = 1.0/(maxlb*nparts); + } + } + } + + + perm = idxwspacemalloc(ctrl, nvtxs); + + if (ctrl->dbglvl&DBG_REFINE) { + printf("Partitions: [%5.4f %5.4f], Nv-Nb[%6d %6d]. Cut: %6d, LB: ", + npwgts[samin(ncon*nparts, npwgts)], npwgts[samax(ncon*nparts, npwgts)], + graph->nvtxs, graph->nbnd, graph->mincut); + ComputeHKWayLoadImbalance(ncon, nparts, npwgts, tvec); + for (i=0; i<ncon; i++) + printf("%.3f ", tvec[i]); + printf("\n"); + } + + for (pass=0; pass<npasses; pass++) { + ASSERT(ComputeCut(graph, where) == graph->mincut); + + oldcut = graph->mincut; + nbnd = graph->nbnd; + + RandomPermute(nbnd, perm, 1); + for (nmoves=iii=0; iii<graph->nbnd; iii++) { + ii = perm[iii]; + if (ii >= nbnd) + continue; + i = bndind[ii]; + + myrinfo = graph->rinfo+i; + + if (myrinfo->ed >= myrinfo->id) { /* Total ED is too high */ + from = where[i]; + nvwgt = graph->nvwgt+i*ncon; + + if (myrinfo->id > 0 && AreAllHVwgtsBelow(ncon, 1.0, npwgts+from*ncon, -1.0, nvwgt, minwgt+from*ncon)) + continue; /* This cannot be moved! */ + + myedegrees = myrinfo->edegrees; + myndegrees = myrinfo->ndegrees; + + for (k=0; k<myndegrees; k++) { + to = myedegrees[k].pid; + gain = myedegrees[k].ed - myrinfo->id; + if (gain >= 0 && + (AreAllHVwgtsBelow(ncon, 1.0, npwgts+to*ncon, 1.0, nvwgt, maxwgt+to*ncon) || + IsHBalanceBetterFT(ncon, nparts, npwgts+from*ncon, npwgts+to*ncon, nvwgt, ubvec))) + break; + } + if (k == myndegrees) + continue; /* break out if you did not find a candidate */ + + for (j=k+1; j<myndegrees; j++) { + to = myedegrees[j].pid; + if ((myedegrees[j].ed > myedegrees[k].ed && + (AreAllHVwgtsBelow(ncon, 1.0, npwgts+to*ncon, 1.0, nvwgt, maxwgt+to*ncon) || + IsHBalanceBetterFT(ncon, nparts, npwgts+from*ncon, npwgts+to*ncon, nvwgt, ubvec))) || + (myedegrees[j].ed == myedegrees[k].ed && + IsHBalanceBetterTT(ncon, nparts, npwgts+myedegrees[k].pid*ncon, npwgts+to*ncon, nvwgt, ubvec))) + k = j; + } + + to = myedegrees[k].pid; + + if (myedegrees[k].ed-myrinfo->id == 0 + && !IsHBalanceBetterFT(ncon, nparts, npwgts+from*ncon, npwgts+to*ncon, nvwgt, ubvec) + && AreAllHVwgtsBelow(ncon, 1.0, npwgts+from*ncon, 0.0, npwgts+from*ncon, maxwgt+from*ncon)) + continue; + + /*===================================================================== + * If we got here, we can now move the vertex from 'from' to 'to' + *======================================================================*/ + graph->mincut -= myedegrees[k].ed-myrinfo->id; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, printf("\t\tMoving %6d to %3d. Gain: %4d. Cut: %6d\n", i, to, myedegrees[k].ed-myrinfo->id, graph->mincut)); + + /* Update where, weight, and ID/ED information of the vertex you moved */ + saxpy(ncon, 1.0, nvwgt, 1, npwgts+to*ncon, 1); + saxpy(ncon, -1.0, nvwgt, 1, npwgts+from*ncon, 1); + where[i] = to; + myrinfo->ed += myrinfo->id-myedegrees[k].ed; + SWAP(myrinfo->id, myedegrees[k].ed, j); + if (myedegrees[k].ed == 0) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].pid = from; + + if (myrinfo->ed-myrinfo->id < 0) + BNDDelete(nbnd, bndind, bndptr, i); + + /* Update the degrees of adjacent vertices */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + ii = adjncy[j]; + me = where[ii]; + + myrinfo = graph->rinfo+ii; + if (myrinfo->edegrees == NULL) { + myrinfo->edegrees = ctrl->wspace.edegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += xadj[ii+1]-xadj[ii]; + } + myedegrees = myrinfo->edegrees; + + ASSERT(CheckRInfo(myrinfo)); + + if (me == from) { + INC_DEC(myrinfo->ed, myrinfo->id, adjwgt[j]); + + if (myrinfo->ed-myrinfo->id >= 0 && bndptr[ii] == -1) + BNDInsert(nbnd, bndind, bndptr, ii); + } + else if (me == to) { + INC_DEC(myrinfo->id, myrinfo->ed, adjwgt[j]); + + if (myrinfo->ed-myrinfo->id < 0 && bndptr[ii] != -1) + BNDDelete(nbnd, bndind, bndptr, ii); + } + + /* Remove contribution from the .ed of 'from' */ + if (me != from) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == from) { + if (myedegrees[k].ed == adjwgt[j]) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].ed -= adjwgt[j]; + break; + } + } + } + + /* Add contribution to the .ed of 'to' */ + if (me != to) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == to) { + myedegrees[k].ed += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + myedegrees[myrinfo->ndegrees].pid = to; + myedegrees[myrinfo->ndegrees++].ed = adjwgt[j]; + } + } + + ASSERT(myrinfo->ndegrees <= xadj[ii+1]-xadj[ii]); + ASSERT(CheckRInfo(myrinfo)); + + } + nmoves++; + } + } + + graph->nbnd = nbnd; + + if (ctrl->dbglvl&DBG_REFINE) { + printf("\t [%5.4f %5.4f], Nb: %6d, Nmoves: %5d, Cut: %6d, LB: ", + npwgts[samin(ncon*nparts, npwgts)], npwgts[samax(ncon*nparts, npwgts)], + nbnd, nmoves, graph->mincut); + ComputeHKWayLoadImbalance(ncon, nparts, npwgts, tvec); + for (i=0; i<ncon; i++) + printf("%.3f ", tvec[i]); + printf("\n"); + } + + if (graph->mincut == oldcut) + break; + } + + fwspacefree(ctrl, ncon*nparts); + fwspacefree(ctrl, ncon*nparts); + idxwspacefree(ctrl, nvtxs); +} + + + +/************************************************************************* +* This function performs k-way refinement +**************************************************************************/ +void MCGreedy_KWayEdgeBalanceHorizontal(CtrlType *ctrl, GraphType *graph, int nparts, + float *ubvec, int npasses) +{ + int i, ii, iii, j, jj, k, l, pass, nvtxs, ncon, nbnd, myndegrees, oldgain, gain, nmoves; + int from, me, to, oldcut; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *where, *perm, *bndptr, *bndind, *moved; + EDegreeType *myedegrees; + RInfoType *myrinfo; + PQueueType queue; + float *npwgts, *nvwgt, *minwgt, *maxwgt, tvec[MAXNCON]; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + bndind = graph->bndind; + bndptr = graph->bndptr; + + where = graph->where; + npwgts = graph->npwgts; + + /* Setup the weight intervals of the various subdomains */ + minwgt = fwspacemalloc(ctrl, ncon*nparts); + maxwgt = fwspacemalloc(ctrl, ncon*nparts); + + for (i=0; i<nparts; i++) { + for (j=0; j<ncon; j++) { + maxwgt[i*ncon+j] = ubvec[j]/nparts; + minwgt[i*ncon+j] = 1.0/(ubvec[j]*nparts); + } + } + + perm = idxwspacemalloc(ctrl, nvtxs); + moved = idxwspacemalloc(ctrl, nvtxs); + + PQueueInit(ctrl, &queue, nvtxs, graph->adjwgtsum[idxamax(nvtxs, graph->adjwgtsum)]); + + if (ctrl->dbglvl&DBG_REFINE) { + printf("Partitions: [%5.4f %5.4f], Nv-Nb[%6d %6d]. Cut: %6d, LB: ", + npwgts[samin(ncon*nparts, npwgts)], npwgts[samax(ncon*nparts, npwgts)], + graph->nvtxs, graph->nbnd, graph->mincut); + ComputeHKWayLoadImbalance(ncon, nparts, npwgts, tvec); + for (i=0; i<ncon; i++) + printf("%.3f ", tvec[i]); + printf("[B]\n"); + } + + + for (pass=0; pass<npasses; pass++) { + ASSERT(ComputeCut(graph, where) == graph->mincut); + + /* Check to see if things are out of balance, given the tolerance */ + if (MocIsHBalanced(ncon, nparts, npwgts, ubvec)) + break; + + PQueueReset(&queue); + idxset(nvtxs, -1, moved); + + oldcut = graph->mincut; + nbnd = graph->nbnd; + + RandomPermute(nbnd, perm, 1); + for (ii=0; ii<nbnd; ii++) { + i = bndind[perm[ii]]; + PQueueInsert(&queue, i, graph->rinfo[i].ed - graph->rinfo[i].id); + moved[i] = 2; + } + + nmoves = 0; + for (;;) { + if ((i = PQueueGetMax(&queue)) == -1) + break; + moved[i] = 1; + + myrinfo = graph->rinfo+i; + from = where[i]; + nvwgt = graph->nvwgt+i*ncon; + + if (AreAllHVwgtsBelow(ncon, 1.0, npwgts+from*ncon, -1.0, nvwgt, minwgt+from*ncon)) + continue; /* This cannot be moved! */ + + myedegrees = myrinfo->edegrees; + myndegrees = myrinfo->ndegrees; + + for (k=0; k<myndegrees; k++) { + to = myedegrees[k].pid; + if (IsHBalanceBetterFT(ncon, nparts, npwgts+from*ncon, npwgts+to*ncon, nvwgt, ubvec)) + break; + } + if (k == myndegrees) + continue; /* break out if you did not find a candidate */ + + for (j=k+1; j<myndegrees; j++) { + to = myedegrees[j].pid; + if (IsHBalanceBetterTT(ncon, nparts, npwgts+myedegrees[k].pid*ncon, npwgts+to*ncon, nvwgt, ubvec)) + k = j; + } + + to = myedegrees[k].pid; + + j = 0; + if (!AreAllHVwgtsBelow(ncon, 1.0, npwgts+from*ncon, 0.0, nvwgt, maxwgt+from*ncon)) + j++; + if (myedegrees[k].ed-myrinfo->id >= 0) + j++; + if (!AreAllHVwgtsAbove(ncon, 1.0, npwgts+to*ncon, 0.0, nvwgt, minwgt+to*ncon) && + AreAllHVwgtsBelow(ncon, 1.0, npwgts+to*ncon, 1.0, nvwgt, maxwgt+to*ncon)) + j++; + if (j == 0) + continue; + +/* DELETE + if (myedegrees[k].ed-myrinfo->id < 0 && + AreAllHVwgtsBelow(ncon, 1.0, npwgts+from*ncon, 0.0, nvwgt, maxwgt+from*ncon) && + AreAllHVwgtsAbove(ncon, 1.0, npwgts+to*ncon, 0.0, nvwgt, minwgt+to*ncon) && + AreAllHVwgtsBelow(ncon, 1.0, npwgts+to*ncon, 1.0, nvwgt, maxwgt+to*ncon)) + continue; +*/ + /*===================================================================== + * If we got here, we can now move the vertex from 'from' to 'to' + *======================================================================*/ + graph->mincut -= myedegrees[k].ed-myrinfo->id; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, printf("\t\tMoving %6d to %3d. Gain: %4d. Cut: %6d\n", i, to, myedegrees[k].ed-myrinfo->id, graph->mincut)); + + /* Update where, weight, and ID/ED information of the vertex you moved */ + saxpy(ncon, 1.0, nvwgt, 1, npwgts+to*ncon, 1); + saxpy(ncon, -1.0, nvwgt, 1, npwgts+from*ncon, 1); + where[i] = to; + myrinfo->ed += myrinfo->id-myedegrees[k].ed; + SWAP(myrinfo->id, myedegrees[k].ed, j); + if (myedegrees[k].ed == 0) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].pid = from; + + if (myrinfo->ed == 0) + BNDDelete(nbnd, bndind, bndptr, i); + + /* Update the degrees of adjacent vertices */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + ii = adjncy[j]; + me = where[ii]; + + myrinfo = graph->rinfo+ii; + if (myrinfo->edegrees == NULL) { + myrinfo->edegrees = ctrl->wspace.edegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += xadj[ii+1]-xadj[ii]; + } + myedegrees = myrinfo->edegrees; + + ASSERT(CheckRInfo(myrinfo)); + + oldgain = (myrinfo->ed-myrinfo->id); + + if (me == from) { + INC_DEC(myrinfo->ed, myrinfo->id, adjwgt[j]); + + if (myrinfo->ed > 0 && bndptr[ii] == -1) + BNDInsert(nbnd, bndind, bndptr, ii); + } + else if (me == to) { + INC_DEC(myrinfo->id, myrinfo->ed, adjwgt[j]); + + if (myrinfo->ed == 0 && bndptr[ii] != -1) + BNDDelete(nbnd, bndind, bndptr, ii); + } + + /* Remove contribution from the .ed of 'from' */ + if (me != from) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == from) { + if (myedegrees[k].ed == adjwgt[j]) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].ed -= adjwgt[j]; + break; + } + } + } + + /* Add contribution to the .ed of 'to' */ + if (me != to) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == to) { + myedegrees[k].ed += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + myedegrees[myrinfo->ndegrees].pid = to; + myedegrees[myrinfo->ndegrees++].ed = adjwgt[j]; + } + } + + + /* Update the queue */ + if (me == to || me == from) { + gain = myrinfo->ed-myrinfo->id; + if (moved[ii] == 2) { + if (myrinfo->ed > 0) + PQueueUpdate(&queue, ii, oldgain, gain); + else { + PQueueDelete(&queue, ii, oldgain); + moved[ii] = -1; + } + } + else if (moved[ii] == -1 && myrinfo->ed > 0) { + PQueueInsert(&queue, ii, gain); + moved[ii] = 2; + } + } + + ASSERT(myrinfo->ndegrees <= xadj[ii+1]-xadj[ii]); + ASSERT(CheckRInfo(myrinfo)); + } + nmoves++; + } + + graph->nbnd = nbnd; + + if (ctrl->dbglvl&DBG_REFINE) { + printf("\t [%5.4f %5.4f], Nb: %6d, Nmoves: %5d, Cut: %6d, LB: ", + npwgts[samin(ncon*nparts, npwgts)], npwgts[samax(ncon*nparts, npwgts)], + nbnd, nmoves, graph->mincut); + ComputeHKWayLoadImbalance(ncon, nparts, npwgts, tvec); + for (i=0; i<ncon; i++) + printf("%.3f ", tvec[i]); + printf("\n"); + } + + if (nmoves == 0) + break; + } + + PQueueFree(ctrl, &queue); + + fwspacefree(ctrl, ncon*nparts); + fwspacefree(ctrl, ncon*nparts); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + +} + + + + + +/************************************************************************* +* This function checks if the vertex weights of two vertices are below +* a given set of values +**************************************************************************/ +int AreAllHVwgtsBelow(int ncon, float alpha, float *vwgt1, float beta, float *vwgt2, float *limit) +{ + int i; + + for (i=0; i<ncon; i++) + if (alpha*vwgt1[i] + beta*vwgt2[i] > limit[i]) + return 0; + + return 1; +} + + + +/************************************************************************* +* This function checks if the vertex weights of two vertices are above +* a given set of values +**************************************************************************/ +int AreAllHVwgtsAbove(int ncon, float alpha, float *vwgt1, float beta, float *vwgt2, float *limit) +{ + int i; + + for (i=0; i<ncon; i++) + if (alpha*vwgt1[i] + beta*vwgt2[i] < limit[i]) + return 0; + + return 1; +} + + +/************************************************************************* +* This function computes the load imbalance over all the constrains +* For now assume that we just want balanced partitionings +**************************************************************************/ +void ComputeHKWayLoadImbalance(int ncon, int nparts, float *npwgts, float *lbvec) +{ + int i, j; + float max; + + for (i=0; i<ncon; i++) { + max = 0.0; + for (j=0; j<nparts; j++) { + if (npwgts[j*ncon+i] > max) + max = npwgts[j*ncon+i]; + } + + lbvec[i] = max*nparts; + } +} + + +/************************************************************************* +* This function determines if a partitioning is horizontally balanced +**************************************************************************/ +int MocIsHBalanced(int ncon, int nparts, float *npwgts, float *ubvec) +{ + int i, j; + float max; + + for (i=0; i<ncon; i++) { + max = 0.0; + for (j=0; j<nparts; j++) { + if (npwgts[j*ncon+i] > max) + max = npwgts[j*ncon+i]; + } + + if (ubvec[i] < max*nparts) + return 0; + } + + return 1; +} + + + + + +/************************************************************************* +* This function checks if the pairwise balance of the between the two +* partitions will improve by moving the vertex v from pfrom to pto, +* subject to the target partition weights of tfrom, and tto respectively +**************************************************************************/ +int IsHBalanceBetterFT(int ncon, int nparts, float *pfrom, float *pto, float *vwgt, float *ubvec) +{ + int i, j, k; + float blb1=0.0, alb1=0.0, sblb=0.0, salb=0.0; + float blb2=0.0, alb2=0.0; + float temp; + + for (i=0; i<ncon; i++) { + temp = amax(pfrom[i], pto[i])*nparts/ubvec[i]; + if (blb1 < temp) { + blb2 = blb1; + blb1 = temp; + } + else if (blb2 < temp) + blb2 = temp; + sblb += temp; + + temp = amax(pfrom[i]-vwgt[i], pto[i]+vwgt[i])*nparts/ubvec[i]; + if (alb1 < temp) { + alb2 = alb1; + alb1 = temp; + } + else if (alb2 < temp) + alb2 = temp; + salb += temp; + } + + if (alb1 < blb1) + return 1; + if (blb1 < alb1) + return 0; + if (alb2 < blb2) + return 1; + if (blb2 < alb2) + return 0; + + return salb < sblb; + +} + + + + +/************************************************************************* +* This function checks if it will be better to move a vertex to pt2 than +* to pt1 subject to their target weights of tt1 and tt2, respectively +* This routine takes into account the weight of the vertex in question +**************************************************************************/ +int IsHBalanceBetterTT(int ncon, int nparts, float *pt1, float *pt2, float *vwgt, float *ubvec) +{ + int i; + float m11=0.0, m12=0.0, m21=0.0, m22=0.0, sm1=0.0, sm2=0.0, temp; + + for (i=0; i<ncon; i++) { + temp = (pt1[i]+vwgt[i])*nparts/ubvec[i]; + if (m11 < temp) { + m12 = m11; + m11 = temp; + } + else if (m12 < temp) + m12 = temp; + sm1 += temp; + + temp = (pt2[i]+vwgt[i])*nparts/ubvec[i]; + if (m21 < temp) { + m22 = m21; + m21 = temp; + } + else if (m22 < temp) + m22 = temp; + sm2 += temp; + } + + if (m21 < m11) + return 1; + if (m21 > m11) + return 0; + if (m22 < m12) + return 1; + if (m22 > m12) + return 0; + + return sm2 < sm1; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mkwayrefine.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mkwayrefine.c new file mode 100644 index 0000000..15836db --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mkwayrefine.c @@ -0,0 +1,296 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mkwayrefine.c + * + * This file contains the driving routines for multilevel k-way refinement + * + * Started 7/28/97 + * George + * + * $Id: mkwayrefine.c,v 1.1 2003/07/16 15:55:11 karypis Exp $ + */ + +#include <metis.h> + + +/************************************************************************* +* This function is the entry point of refinement +**************************************************************************/ +void MocRefineKWayHorizontal(CtrlType *ctrl, GraphType *orggraph, GraphType *graph, int nparts, + float *ubvec) +{ + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->UncoarsenTmr)); + + /* Compute the parameters of the coarsest graph */ + MocComputeKWayPartitionParams(ctrl, graph, nparts); + + for (;;) { + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->RefTmr)); + + if (!MocIsHBalanced(graph->ncon, nparts, graph->npwgts, ubvec)) { + MocComputeKWayBalanceBoundary(ctrl, graph, nparts); + MCGreedy_KWayEdgeBalanceHorizontal(ctrl, graph, nparts, ubvec, 4); + ComputeKWayBoundary(ctrl, graph, nparts); + } + + MCRandom_KWayEdgeRefineHorizontal(ctrl, graph, nparts, ubvec, 10); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->RefTmr)); + + if (graph == orggraph) + break; + + graph = graph->finer; + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ProjectTmr)); + MocProjectKWayPartition(ctrl, graph, nparts); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ProjectTmr)); + } + + if (!MocIsHBalanced(graph->ncon, nparts, graph->npwgts, ubvec)) { + MocComputeKWayBalanceBoundary(ctrl, graph, nparts); + MCGreedy_KWayEdgeBalanceHorizontal(ctrl, graph, nparts, ubvec, 4); + ComputeKWayBoundary(ctrl, graph, nparts); + MCRandom_KWayEdgeRefineHorizontal(ctrl, graph, nparts, ubvec, 10); + } + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->UncoarsenTmr)); +} + + + + +/************************************************************************* +* This function allocates memory for k-way edge refinement +**************************************************************************/ +void MocAllocateKWayPartitionMemory(CtrlType *ctrl, GraphType *graph, int nparts) +{ + int nvtxs, ncon, pad64; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + + pad64 = (3*nvtxs+nparts)%2; + + graph->rdata = idxmalloc(3*nvtxs+ncon*nparts+(sizeof(RInfoType)/sizeof(idxtype))*nvtxs+pad64, "AllocateKWayPartitionMemory: rdata"); + graph->npwgts = (float *)graph->rdata; + graph->where = graph->rdata + ncon*nparts; + graph->bndptr = graph->rdata + nvtxs + ncon*nparts; + graph->bndind = graph->rdata + 2*nvtxs + ncon*nparts; + graph->rinfo = (RInfoType *)(graph->rdata + 3*nvtxs+ncon*nparts + pad64); +} + + +/************************************************************************* +* This function computes the initial id/ed +**************************************************************************/ +void MocComputeKWayPartitionParams(CtrlType *ctrl, GraphType *graph, int nparts) +{ + int i, j, k, l, nvtxs, ncon, nbnd, mincut, me, other; + idxtype *xadj, *adjncy, *adjwgt, *where, *bndind, *bndptr; + RInfoType *rinfo, *myrinfo; + EDegreeType *myedegrees; + float *nvwgt, *npwgts; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + where = graph->where; + npwgts = sset(ncon*nparts, 0.0, graph->npwgts); + bndind = graph->bndind; + bndptr = idxset(nvtxs, -1, graph->bndptr); + rinfo = graph->rinfo; + + + /*------------------------------------------------------------ + / Compute now the id/ed degrees + /------------------------------------------------------------*/ + ctrl->wspace.cdegree = 0; + nbnd = mincut = 0; + for (i=0; i<nvtxs; i++) { + me = where[i]; + saxpy(ncon, 1.0, nvwgt+i*ncon, 1, npwgts+me*ncon, 1); + + myrinfo = rinfo+i; + myrinfo->id = myrinfo->ed = myrinfo->ndegrees = 0; + myrinfo->edegrees = NULL; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (me != where[adjncy[j]]) + myrinfo->ed += adjwgt[j]; + } + myrinfo->id = graph->adjwgtsum[i] - myrinfo->ed; + + if (myrinfo->ed > 0) + mincut += myrinfo->ed; + + if (myrinfo->ed-myrinfo->id >= 0) + BNDInsert(nbnd, bndind, bndptr, i); + + /* Time to compute the particular external degrees */ + if (myrinfo->ed > 0) { + myedegrees = myrinfo->edegrees = ctrl->wspace.edegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += xadj[i+1]-xadj[i]; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + other = where[adjncy[j]]; + if (me != other) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == other) { + myedegrees[k].ed += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + myedegrees[myrinfo->ndegrees].pid = other; + myedegrees[myrinfo->ndegrees++].ed = adjwgt[j]; + } + } + } + + ASSERT(myrinfo->ndegrees <= xadj[i+1]-xadj[i]); + } + } + + graph->mincut = mincut/2; + graph->nbnd = nbnd; + +} + + + +/************************************************************************* +* This function projects a partition, and at the same time computes the +* parameters for refinement. +**************************************************************************/ +void MocProjectKWayPartition(CtrlType *ctrl, GraphType *graph, int nparts) +{ + int i, j, k, nvtxs, nbnd, me, other, istart, iend, ndegrees; + idxtype *xadj, *adjncy, *adjwgt, *adjwgtsum; + idxtype *cmap, *where, *bndptr, *bndind; + idxtype *cwhere; + GraphType *cgraph; + RInfoType *crinfo, *rinfo, *myrinfo; + EDegreeType *myedegrees; + idxtype *htable; + + cgraph = graph->coarser; + cwhere = cgraph->where; + crinfo = cgraph->rinfo; + + nvtxs = graph->nvtxs; + cmap = graph->cmap; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + adjwgtsum = graph->adjwgtsum; + + MocAllocateKWayPartitionMemory(ctrl, graph, nparts); + where = graph->where; + rinfo = graph->rinfo; + bndind = graph->bndind; + bndptr = idxset(nvtxs, -1, graph->bndptr); + + /* Go through and project partition and compute id/ed for the nodes */ + for (i=0; i<nvtxs; i++) { + k = cmap[i]; + where[i] = cwhere[k]; + cmap[i] = crinfo[k].ed; /* For optimization */ + } + + htable = idxset(nparts, -1, idxwspacemalloc(ctrl, nparts)); + + ctrl->wspace.cdegree = 0; + for (nbnd=0, i=0; i<nvtxs; i++) { + me = where[i]; + + myrinfo = rinfo+i; + myrinfo->id = myrinfo->ed = myrinfo->ndegrees = 0; + myrinfo->edegrees = NULL; + + myrinfo->id = adjwgtsum[i]; + + if (cmap[i] > 0) { /* If it is an interface node. Note cmap[i] = crinfo[cmap[i]].ed */ + istart = xadj[i]; + iend = xadj[i+1]; + + myedegrees = myrinfo->edegrees = ctrl->wspace.edegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += iend-istart; + + ndegrees = 0; + for (j=istart; j<iend; j++) { + other = where[adjncy[j]]; + if (me != other) { + myrinfo->ed += adjwgt[j]; + if ((k = htable[other]) == -1) { + htable[other] = ndegrees; + myedegrees[ndegrees].pid = other; + myedegrees[ndegrees++].ed = adjwgt[j]; + } + else { + myedegrees[k].ed += adjwgt[j]; + } + } + } + myrinfo->id -= myrinfo->ed; + + /* Remove space for edegrees if it was interior */ + if (myrinfo->ed == 0) { + myrinfo->edegrees = NULL; + ctrl->wspace.cdegree -= iend-istart; + } + else { + if (myrinfo->ed-myrinfo->id >= 0) + BNDInsert(nbnd, bndind, bndptr, i); + + myrinfo->ndegrees = ndegrees; + + for (j=0; j<ndegrees; j++) + htable[myedegrees[j].pid] = -1; + } + } + } + + scopy(graph->ncon*nparts, cgraph->npwgts, graph->npwgts); + graph->mincut = cgraph->mincut; + graph->nbnd = nbnd; + + FreeGraph(graph->coarser); + graph->coarser = NULL; + + idxwspacefree(ctrl, nparts); + + ASSERT(CheckBnd2(graph)); + +} + + + +/************************************************************************* +* This function computes the boundary definition for balancing +**************************************************************************/ +void MocComputeKWayBalanceBoundary(CtrlType *ctrl, GraphType *graph, int nparts) +{ + int i, nvtxs, nbnd; + idxtype *bndind, *bndptr; + + nvtxs = graph->nvtxs; + bndind = graph->bndind; + bndptr = idxset(nvtxs, -1, graph->bndptr); + + + /* Compute the new boundary */ + nbnd = 0; + for (i=0; i<nvtxs; i++) { + if (graph->rinfo[i].ed > 0) + BNDInsert(nbnd, bndind, bndptr, i); + } + + graph->nbnd = nbnd; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mmatch.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mmatch.c new file mode 100644 index 0000000..2666dd3 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mmatch.c @@ -0,0 +1,501 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mmatch.c + * + * This file contains the code that computes matchings and creates the next + * level coarse graph. + * + * Started 7/23/97 + * George + * + * $Id: mmatch.c,v 1.1 2003/07/16 15:55:11 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function finds a matching using the HEM heuristic +**************************************************************************/ +void MCMatch_RM(CtrlType *ctrl, GraphType *graph) +{ + int i, ii, j, k, nvtxs, ncon, cnvtxs, maxidx; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *match, *cmap, *perm; + float *nvwgt; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->MatchTmr)); + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + cmap = graph->cmap; + match = idxset(nvtxs, UNMATCHED, idxwspacemalloc(ctrl, nvtxs)); + + perm = idxwspacemalloc(ctrl, nvtxs); + RandomPermute(nvtxs, perm, 1); + + cnvtxs = 0; + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + + if (match[i] == UNMATCHED) { /* Unmatched */ + maxidx = i; + + /* Find a random matching, subject to maxvwgt constraints */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (match[k] == UNMATCHED && AreAllVwgtsBelowFast(ncon, nvwgt+i*ncon, nvwgt+k*ncon, ctrl->nmaxvwgt)) { + maxidx = k; + break; + } + } + + cmap[i] = cmap[maxidx] = cnvtxs++; + match[i] = maxidx; + match[maxidx] = i; + } + } + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->MatchTmr)); + + CreateCoarseGraph(ctrl, graph, cnvtxs, match, perm); + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + + +/************************************************************************* +* This function finds a matching using the HEM heuristic +**************************************************************************/ +void MCMatch_HEM(CtrlType *ctrl, GraphType *graph) +{ + int i, ii, j, k, l, nvtxs, cnvtxs, ncon, maxidx, maxwgt; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *match, *cmap, *perm; + float *nvwgt; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->MatchTmr)); + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + cmap = graph->cmap; + match = idxset(nvtxs, UNMATCHED, idxwspacemalloc(ctrl, nvtxs)); + + perm = idxwspacemalloc(ctrl, nvtxs); + RandomPermute(nvtxs, perm, 1); + + cnvtxs = 0; + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + + if (match[i] == UNMATCHED) { /* Unmatched */ + maxidx = i; + maxwgt = 0; + + /* Find a heavy-edge matching, subject to maxvwgt constraints */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (match[k] == UNMATCHED && maxwgt <= adjwgt[j] && + AreAllVwgtsBelowFast(ncon, nvwgt+i*ncon, nvwgt+k*ncon, ctrl->nmaxvwgt)) { + maxwgt = adjwgt[j]; + maxidx = adjncy[j]; + } + } + + cmap[i] = cmap[maxidx] = cnvtxs++; + match[i] = maxidx; + match[maxidx] = i; + } + } + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->MatchTmr)); + + CreateCoarseGraph(ctrl, graph, cnvtxs, match, perm); + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + + +/************************************************************************* +* This function finds a matching using the HEM heuristic +**************************************************************************/ +void MCMatch_SHEM(CtrlType *ctrl, GraphType *graph) +{ + int i, ii, j, k, nvtxs, cnvtxs, ncon, maxidx, maxwgt, avgdegree; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *match, *cmap, *degrees, *perm, *tperm; + float *nvwgt; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->MatchTmr)); + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + cmap = graph->cmap; + match = idxset(nvtxs, UNMATCHED, idxwspacemalloc(ctrl, nvtxs)); + + perm = idxwspacemalloc(ctrl, nvtxs); + tperm = idxwspacemalloc(ctrl, nvtxs); + degrees = idxwspacemalloc(ctrl, nvtxs); + + RandomPermute(nvtxs, tperm, 1); + avgdegree = 0.7*(xadj[nvtxs]/nvtxs); + for (i=0; i<nvtxs; i++) + degrees[i] = (xadj[i+1]-xadj[i] > avgdegree ? avgdegree : xadj[i+1]-xadj[i]); + BucketSortKeysInc(nvtxs, avgdegree, degrees, tperm, perm); + + cnvtxs = 0; + + /* Take care any islands. Islands are matched with non-islands due to coarsening */ + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + + if (match[i] == UNMATCHED) { /* Unmatched */ + if (xadj[i] < xadj[i+1]) + break; + + maxidx = i; + for (j=nvtxs-1; j>ii; j--) { + k = perm[j]; + if (match[k] == UNMATCHED && xadj[k] < xadj[k+1]) { + maxidx = k; + break; + } + } + + cmap[i] = cmap[maxidx] = cnvtxs++; + match[i] = maxidx; + match[maxidx] = i; + } + } + + /* Continue with normal matching */ + for (; ii<nvtxs; ii++) { + i = perm[ii]; + + if (match[i] == UNMATCHED) { /* Unmatched */ + maxidx = i; + maxwgt = 0; + + /* Find a heavy-edge matching, subject to maxvwgt constraints */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (match[k] == UNMATCHED && maxwgt <= adjwgt[j] && + AreAllVwgtsBelowFast(ncon, nvwgt+i*ncon, nvwgt+k*ncon, ctrl->nmaxvwgt)) { + maxwgt = adjwgt[j]; + maxidx = adjncy[j]; + } + } + + cmap[i] = cmap[maxidx] = cnvtxs++; + match[i] = maxidx; + match[maxidx] = i; + } + } + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->MatchTmr)); + + idxwspacefree(ctrl, nvtxs); /* degrees */ + idxwspacefree(ctrl, nvtxs); /* tperm */ + + CreateCoarseGraph(ctrl, graph, cnvtxs, match, perm); + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + + +/************************************************************************* +* This function finds a matching using the HEM heuristic +**************************************************************************/ +void MCMatch_SHEBM(CtrlType *ctrl, GraphType *graph, int norm) +{ + int i, ii, j, k, nvtxs, cnvtxs, ncon, maxidx, maxwgt, avgdegree; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *match, *cmap, *degrees, *perm, *tperm; + float *nvwgt; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->MatchTmr)); + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + cmap = graph->cmap; + match = idxset(nvtxs, UNMATCHED, idxwspacemalloc(ctrl, nvtxs)); + + perm = idxwspacemalloc(ctrl, nvtxs); + tperm = idxwspacemalloc(ctrl, nvtxs); + degrees = idxwspacemalloc(ctrl, nvtxs); + + RandomPermute(nvtxs, tperm, 1); + avgdegree = 0.7*(xadj[nvtxs]/nvtxs); + for (i=0; i<nvtxs; i++) + degrees[i] = (xadj[i+1]-xadj[i] > avgdegree ? avgdegree : xadj[i+1]-xadj[i]); + BucketSortKeysInc(nvtxs, avgdegree, degrees, tperm, perm); + + cnvtxs = 0; + + /* Take care any islands. Islands are matched with non-islands due to coarsening */ + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + + if (match[i] == UNMATCHED) { /* Unmatched */ + if (xadj[i] < xadj[i+1]) + break; + + maxidx = i; + for (j=nvtxs-1; j>ii; j--) { + k = perm[j]; + if (match[k] == UNMATCHED && xadj[k] < xadj[k+1]) { + maxidx = k; + break; + } + } + + cmap[i] = cmap[maxidx] = cnvtxs++; + match[i] = maxidx; + match[maxidx] = i; + } + } + + /* Continue with normal matching */ + for (; ii<nvtxs; ii++) { + i = perm[ii]; + + if (match[i] == UNMATCHED) { /* Unmatched */ + maxidx = i; + maxwgt = -1; + + /* Find a heavy-edge matching, subject to maxvwgt constraints */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + + if (match[k] == UNMATCHED && + AreAllVwgtsBelowFast(ncon, nvwgt+i*ncon, nvwgt+k*ncon, ctrl->nmaxvwgt) && + (maxwgt < adjwgt[j] || + (maxwgt == adjwgt[j] && + BetterVBalance(ncon, norm, nvwgt+i*ncon, nvwgt+maxidx*ncon, nvwgt+k*ncon) >= 0 + ) + ) + ) { + maxwgt = adjwgt[j]; + maxidx = k; + } + } + + cmap[i] = cmap[maxidx] = cnvtxs++; + match[i] = maxidx; + match[maxidx] = i; + } + } + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->MatchTmr)); + + idxwspacefree(ctrl, nvtxs); /* degrees */ + idxwspacefree(ctrl, nvtxs); /* tperm */ + + CreateCoarseGraph(ctrl, graph, cnvtxs, match, perm); + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + + +/************************************************************************* +* This function finds a matching using the HEM heuristic +**************************************************************************/ +void MCMatch_SBHEM(CtrlType *ctrl, GraphType *graph, int norm) +{ + int i, ii, j, k, nvtxs, cnvtxs, ncon, maxidx, maxwgt, avgdegree; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *match, *cmap, *degrees, *perm, *tperm; + float *nvwgt, vbal; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->MatchTmr)); + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + cmap = graph->cmap; + match = idxset(nvtxs, UNMATCHED, idxwspacemalloc(ctrl, nvtxs)); + + perm = idxwspacemalloc(ctrl, nvtxs); + tperm = idxwspacemalloc(ctrl, nvtxs); + degrees = idxwspacemalloc(ctrl, nvtxs); + + RandomPermute(nvtxs, tperm, 1); + avgdegree = 0.7*(xadj[nvtxs]/nvtxs); + for (i=0; i<nvtxs; i++) + degrees[i] = (xadj[i+1]-xadj[i] > avgdegree ? avgdegree : xadj[i+1]-xadj[i]); + BucketSortKeysInc(nvtxs, avgdegree, degrees, tperm, perm); + + cnvtxs = 0; + + /* Take care any islands. Islands are matched with non-islands due to coarsening */ + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + + if (match[i] == UNMATCHED) { /* Unmatched */ + if (xadj[i] < xadj[i+1]) + break; + + maxidx = i; + for (j=nvtxs-1; j>ii; j--) { + k = perm[j]; + if (match[k] == UNMATCHED && xadj[k] < xadj[k+1]) { + maxidx = k; + break; + } + } + + cmap[i] = cmap[maxidx] = cnvtxs++; + match[i] = maxidx; + match[maxidx] = i; + } + } + + /* Continue with normal matching */ + for (; ii<nvtxs; ii++) { + i = perm[ii]; + + if (match[i] == UNMATCHED) { /* Unmatched */ + maxidx = i; + maxwgt = -1; + vbal = 0.0; + + /* Find a heavy-edge matching, subject to maxvwgt constraints */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (match[k] == UNMATCHED && AreAllVwgtsBelowFast(ncon, nvwgt+i*ncon, nvwgt+k*ncon, ctrl->nmaxvwgt)) { + if (maxidx != i) + vbal = BetterVBalance(ncon, norm, nvwgt+i*ncon, nvwgt+maxidx*ncon, nvwgt+k*ncon); + + if (vbal > 0 || (vbal > -.01 && maxwgt < adjwgt[j])) { + maxwgt = adjwgt[j]; + maxidx = k; + } + } + } + + cmap[i] = cmap[maxidx] = cnvtxs++; + match[i] = maxidx; + match[maxidx] = i; + } + } + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->MatchTmr)); + + idxwspacefree(ctrl, nvtxs); /* degrees */ + idxwspacefree(ctrl, nvtxs); /* tperm */ + + CreateCoarseGraph(ctrl, graph, cnvtxs, match, perm); + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + + + + +/************************************************************************* +* This function checks if v+u2 provides a better balance in the weight +* vector that v+u1 +**************************************************************************/ +float BetterVBalance(int ncon, int norm, float *vwgt, float *u1wgt, float *u2wgt) +{ + int i; + float sum1, sum2, max1, max2, min1, min2, diff1, diff2; + + if (norm == -1) { + max1 = min1 = vwgt[0]+u1wgt[0]; + max2 = min2 = vwgt[0]+u2wgt[0]; + sum1 = vwgt[0]+u1wgt[0]; + sum2 = vwgt[0]+u2wgt[0]; + + for (i=1; i<ncon; i++) { + if (max1 < vwgt[i]+u1wgt[i]) + max1 = vwgt[i]+u1wgt[i]; + if (min1 > vwgt[i]+u1wgt[i]) + min1 = vwgt[i]+u1wgt[i]; + + if (max2 < vwgt[i]+u2wgt[i]) + max2 = vwgt[i]+u2wgt[i]; + if (min2 > vwgt[i]+u2wgt[i]) + min2 = vwgt[i]+u2wgt[i]; + + sum1 += vwgt[i]+u1wgt[i]; + sum2 += vwgt[i]+u2wgt[i]; + } + + return ((max1-min1)/sum1) - ((max2-min2)/sum2); + } + else if (norm == 1) { + sum1 = sum2 = 0.0; + for (i=0; i<ncon; i++) { + sum1 += vwgt[i]+u1wgt[i]; + sum2 += vwgt[i]+u2wgt[i]; + } + sum1 = sum1/(1.0*ncon); + sum2 = sum2/(1.0*ncon); + + diff1 = diff2 = 0.0; + for (i=0; i<ncon; i++) { + diff1 += fabs(sum1 - (vwgt[i]+u1wgt[i])); + diff2 += fabs(sum2 - (vwgt[i]+u2wgt[i])); + } + + return diff1 - diff2; + } + else { + errexit("Unknown norm: %d\n", norm); + } + return 0.0; +} + + +/************************************************************************* +* This function checks if the vertex weights of two vertices are below +* a given set of values +**************************************************************************/ +int AreAllVwgtsBelowFast(int ncon, float *vwgt1, float *vwgt2, float limit) +{ + int i; + + for (i=0; i<ncon; i++) + if (vwgt1[i] + vwgt2[i] > limit) + return 0; + + return 1; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mmd.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mmd.c new file mode 100644 index 0000000..1b43618 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mmd.c @@ -0,0 +1,593 @@ +/* + * mmd.c + * + * ************************************************************** + * The following C function was developed from a FORTRAN subroutine + * in SPARSPAK written by Eleanor Chu, Alan George, Joseph Liu + * and Esmond Ng. + * + * The FORTRAN-to-C transformation and modifications such as dynamic + * memory allocation and deallocation were performed by Chunguang + * Sun. + * ************************************************************** + * + * Taken from SMMS, George 12/13/94 + * + * The meaning of invperm, and perm vectors is different from that + * in genqmd_ of SparsPak + * + * $Id: mmd.c,v 1.1 2003/07/16 15:55:11 karypis Exp $ + */ + +#include <metis.h> + + +/************************************************************************* +* genmmd -- multiple minimum external degree +* purpose -- this routine implements the minimum degree +* algorithm. it makes use of the implicit representation +* of elimination graphs by quotient graphs, and the notion +* of indistinguishable nodes. It also implements the modifications +* by multiple elimination and minimum external degree. +* Caution -- the adjacency vector adjncy will be destroyed. +* Input parameters -- +* neqns -- number of equations. +* (xadj, adjncy) -- the adjacency structure. +* delta -- tolerance value for multiple elimination. +* maxint -- maximum machine representable (short) integer +* (any smaller estimate will do) for marking nodes. +* Output parameters -- +* perm -- the minimum degree ordering. +* invp -- the inverse of perm. +* *ncsub -- an upper bound on the number of nonzero subscripts +* for the compressed storage scheme. +* Working parameters -- +* head -- vector for head of degree lists. +* invp -- used temporarily for degree forward link. +* perm -- used temporarily for degree backward link. +* qsize -- vector for size of supernodes. +* list -- vector for temporary linked lists. +* marker -- a temporary marker vector. +* Subroutines used -- mmdelm, mmdint, mmdnum, mmdupd. +**************************************************************************/ +void genmmd(int neqns, idxtype *xadj, idxtype *adjncy, idxtype *invp, idxtype *perm, + int delta, idxtype *head, idxtype *qsize, idxtype *list, idxtype *marker, + int maxint, int *ncsub) +{ + int ehead, i, mdeg, mdlmt, mdeg_node, nextmd, num, tag; + + if (neqns <= 0) + return; + + /* Adjust from C to Fortran */ + xadj--; adjncy--; invp--; perm--; head--; qsize--; list--; marker--; + + /* initialization for the minimum degree algorithm. */ + *ncsub = 0; + mmdint(neqns, xadj, adjncy, head, invp, perm, qsize, list, marker); + + /* 'num' counts the number of ordered nodes plus 1. */ + num = 1; + + /* eliminate all isolated nodes. */ + nextmd = head[1]; + while (nextmd > 0) { + mdeg_node = nextmd; + nextmd = invp[mdeg_node]; + marker[mdeg_node] = maxint; + invp[mdeg_node] = -num; + num = num + 1; + } + + /* search for node of the minimum degree. 'mdeg' is the current */ + /* minimum degree; 'tag' is used to facilitate marking nodes. */ + if (num > neqns) + goto n1000; + tag = 1; + head[1] = 0; + mdeg = 2; + + /* infinite loop here ! */ + while (1) { + while (head[mdeg] <= 0) + mdeg++; + + /* use value of 'delta' to set up 'mdlmt', which governs */ + /* when a degree update is to be performed. */ + mdlmt = mdeg + delta; + ehead = 0; + +n500: + mdeg_node = head[mdeg]; + while (mdeg_node <= 0) { + mdeg++; + + if (mdeg > mdlmt) + goto n900; + mdeg_node = head[mdeg]; + }; + + /* remove 'mdeg_node' from the degree structure. */ + nextmd = invp[mdeg_node]; + head[mdeg] = nextmd; + if (nextmd > 0) + perm[nextmd] = -mdeg; + invp[mdeg_node] = -num; + *ncsub += mdeg + qsize[mdeg_node] - 2; + if ((num+qsize[mdeg_node]) > neqns) + goto n1000; + + /* eliminate 'mdeg_node' and perform quotient graph */ + /* transformation. reset 'tag' value if necessary. */ + tag++; + if (tag >= maxint) { + tag = 1; + for (i = 1; i <= neqns; i++) + if (marker[i] < maxint) + marker[i] = 0; + }; + + mmdelm(mdeg_node, xadj, adjncy, head, invp, perm, qsize, list, marker, maxint, tag); + + num += qsize[mdeg_node]; + list[mdeg_node] = ehead; + ehead = mdeg_node; + if (delta >= 0) + goto n500; + + n900: + /* update degrees of the nodes involved in the */ + /* minimum degree nodes elimination. */ + if (num > neqns) + goto n1000; + mmdupd( ehead, neqns, xadj, adjncy, delta, &mdeg, head, invp, perm, qsize, list, marker, maxint, &tag); + }; /* end of -- while ( 1 ) -- */ + +n1000: + mmdnum( neqns, perm, invp, qsize ); + + /* Adjust from Fortran back to C*/ + xadj++; adjncy++; invp++; perm++; head++; qsize++; list++; marker++; +} + + +/************************************************************************** +* mmdelm ...... multiple minimum degree elimination +* Purpose -- This routine eliminates the node mdeg_node of minimum degree +* from the adjacency structure, which is stored in the quotient +* graph format. It also transforms the quotient graph representation +* of the elimination graph. +* Input parameters -- +* mdeg_node -- node of minimum degree. +* maxint -- estimate of maximum representable (short) integer. +* tag -- tag value. +* Updated parameters -- +* (xadj, adjncy) -- updated adjacency structure. +* (head, forward, backward) -- degree doubly linked structure. +* qsize -- size of supernode. +* marker -- marker vector. +* list -- temporary linked list of eliminated nabors. +***************************************************************************/ +void mmdelm(int mdeg_node, idxtype *xadj, idxtype *adjncy, idxtype *head, idxtype *forward, + idxtype *backward, idxtype *qsize, idxtype *list, idxtype *marker, int maxint,int tag) +{ + int element, i, istop, istart, j, + jstop, jstart, link, + nabor, node, npv, nqnbrs, nxnode, + pvnode, rlmt, rloc, rnode, xqnbr; + + /* find the reachable set of 'mdeg_node' and */ + /* place it in the data structure. */ + marker[mdeg_node] = tag; + istart = xadj[mdeg_node]; + istop = xadj[mdeg_node+1] - 1; + + /* 'element' points to the beginning of the list of */ + /* eliminated nabors of 'mdeg_node', and 'rloc' gives the */ + /* storage location for the next reachable node. */ + element = 0; + rloc = istart; + rlmt = istop; + for ( i = istart; i <= istop; i++ ) { + nabor = adjncy[i]; + if ( nabor == 0 ) break; + if ( marker[nabor] < tag ) { + marker[nabor] = tag; + if ( forward[nabor] < 0 ) { + list[nabor] = element; + element = nabor; + } else { + adjncy[rloc] = nabor; + rloc++; + }; + }; /* end of -- if -- */ + }; /* end of -- for -- */ + + /* merge with reachable nodes from generalized elements. */ + while ( element > 0 ) { + adjncy[rlmt] = -element; + link = element; + +n400: + jstart = xadj[link]; + jstop = xadj[link+1] - 1; + for ( j = jstart; j <= jstop; j++ ) { + node = adjncy[j]; + link = -node; + if ( node < 0 ) goto n400; + if ( node == 0 ) break; + if ((marker[node]<tag)&&(forward[node]>=0)) { + marker[node] = tag; + /*use storage from eliminated nodes if necessary.*/ + while ( rloc >= rlmt ) { + link = -adjncy[rlmt]; + rloc = xadj[link]; + rlmt = xadj[link+1] - 1; + }; + adjncy[rloc] = node; + rloc++; + }; + }; /* end of -- for ( j = jstart; -- */ + element = list[element]; + }; /* end of -- while ( element > 0 ) -- */ + if ( rloc <= rlmt ) adjncy[rloc] = 0; + /* for each node in the reachable set, do the following. */ + link = mdeg_node; + +n1100: + istart = xadj[link]; + istop = xadj[link+1] - 1; + for ( i = istart; i <= istop; i++ ) { + rnode = adjncy[i]; + link = -rnode; + if ( rnode < 0 ) goto n1100; + if ( rnode == 0 ) return; + + /* 'rnode' is in the degree list structure. */ + pvnode = backward[rnode]; + if (( pvnode != 0 ) && ( pvnode != (-maxint) )) { + /* then remove 'rnode' from the structure. */ + nxnode = forward[rnode]; + if ( nxnode > 0 ) backward[nxnode] = pvnode; + if ( pvnode > 0 ) forward[pvnode] = nxnode; + npv = -pvnode; + if ( pvnode < 0 ) head[npv] = nxnode; + }; + + /* purge inactive quotient nabors of 'rnode'. */ + jstart = xadj[rnode]; + jstop = xadj[rnode+1] - 1; + xqnbr = jstart; + for ( j = jstart; j <= jstop; j++ ) { + nabor = adjncy[j]; + if ( nabor == 0 ) break; + if ( marker[nabor] < tag ) { + adjncy[xqnbr] = nabor; + xqnbr++; + }; + }; + + /* no active nabor after the purging. */ + nqnbrs = xqnbr - jstart; + if ( nqnbrs <= 0 ) { + /* merge 'rnode' with 'mdeg_node'. */ + qsize[mdeg_node] += qsize[rnode]; + qsize[rnode] = 0; + marker[rnode] = maxint; + forward[rnode] = -mdeg_node; + backward[rnode] = -maxint; + } else { + /* flag 'rnode' for degree update, and */ + /* add 'mdeg_node' as a nabor of 'rnode'. */ + forward[rnode] = nqnbrs + 1; + backward[rnode] = 0; + adjncy[xqnbr] = mdeg_node; + xqnbr++; + if ( xqnbr <= jstop ) adjncy[xqnbr] = 0; + }; + }; /* end of -- for ( i = istart; -- */ + return; + } + +/*************************************************************************** +* mmdint ---- mult minimum degree initialization +* purpose -- this routine performs initialization for the +* multiple elimination version of the minimum degree algorithm. +* input parameters -- +* neqns -- number of equations. +* (xadj, adjncy) -- adjacency structure. +* output parameters -- +* (head, dfrow, backward) -- degree doubly linked structure. +* qsize -- size of supernode ( initialized to one). +* list -- linked list. +* marker -- marker vector. +****************************************************************************/ +int mmdint(int neqns, idxtype *xadj, idxtype *adjncy, idxtype *head, idxtype *forward, + idxtype *backward, idxtype *qsize, idxtype *list, idxtype *marker) +{ + int fnode, ndeg, node; + + for ( node = 1; node <= neqns; node++ ) { + head[node] = 0; + qsize[node] = 1; + marker[node] = 0; + list[node] = 0; + }; + + /* initialize the degree doubly linked lists. */ + for ( node = 1; node <= neqns; node++ ) { + ndeg = xadj[node+1] - xadj[node]/* + 1*/; /* george */ + if (ndeg == 0) + ndeg = 1; + fnode = head[ndeg]; + forward[node] = fnode; + head[ndeg] = node; + if ( fnode > 0 ) backward[fnode] = node; + backward[node] = -ndeg; + }; + return 0; +} + +/**************************************************************************** +* mmdnum --- multi minimum degree numbering +* purpose -- this routine performs the final step in producing +* the permutation and inverse permutation vectors in the +* multiple elimination version of the minimum degree +* ordering algorithm. +* input parameters -- +* neqns -- number of equations. +* qsize -- size of supernodes at elimination. +* updated parameters -- +* invp -- inverse permutation vector. on input, +* if qsize[node] = 0, then node has been merged +* into the node -invp[node]; otherwise, +* -invp[node] is its inverse labelling. +* output parameters -- +* perm -- the permutation vector. +****************************************************************************/ +void mmdnum(int neqns, idxtype *perm, idxtype *invp, idxtype *qsize) +{ + int father, nextf, node, nqsize, num, root; + + for ( node = 1; node <= neqns; node++ ) { + nqsize = qsize[node]; + if ( nqsize <= 0 ) perm[node] = invp[node]; + if ( nqsize > 0 ) perm[node] = -invp[node]; + }; + + /* for each node which has been merged, do the following. */ + for ( node = 1; node <= neqns; node++ ) { + if ( perm[node] <= 0 ) { + + /* trace the merged tree until one which has not */ + /* been merged, call it root. */ + father = node; + while ( perm[father] <= 0 ) + father = - perm[father]; + + /* number node after root. */ + root = father; + num = perm[root] + 1; + invp[node] = -num; + perm[root] = num; + + /* shorten the merged tree. */ + father = node; + nextf = - perm[father]; + while ( nextf > 0 ) { + perm[father] = -root; + father = nextf; + nextf = -perm[father]; + }; + }; /* end of -- if ( perm[node] <= 0 ) -- */ + }; /* end of -- for ( node = 1; -- */ + + /* ready to compute perm. */ + for ( node = 1; node <= neqns; node++ ) { + num = -invp[node]; + invp[node] = num; + perm[num] = node; + }; + return; +} + +/**************************************************************************** +* mmdupd ---- multiple minimum degree update +* purpose -- this routine updates the degrees of nodes after a +* multiple elimination step. +* input parameters -- +* ehead -- the beginning of the list of eliminated nodes +* (i.e., newly formed elements). +* neqns -- number of equations. +* (xadj, adjncy) -- adjacency structure. +* delta -- tolerance value for multiple elimination. +* maxint -- maximum machine representable (short) integer. +* updated parameters -- +* mdeg -- new minimum degree after degree update. +* (head, forward, backward) -- degree doubly linked structure. +* qsize -- size of supernode. +* list -- marker vector for degree update. +* *tag -- tag value. +****************************************************************************/ +void mmdupd(int ehead, int neqns, idxtype *xadj, idxtype *adjncy, int delta, int *mdeg, + idxtype *head, idxtype *forward, idxtype *backward, idxtype *qsize, idxtype *list, + idxtype *marker, int maxint,int *tag) +{ + int deg, deg0, element, enode, fnode, i, iq2, istop, + istart, j, jstop, jstart, link, mdeg0, mtag, nabor, + node, q2head, qxhead; + + mdeg0 = *mdeg + delta; + element = ehead; + +n100: + if ( element <= 0 ) return; + + /* for each of the newly formed element, do the following. */ + /* reset tag value if necessary. */ + mtag = *tag + mdeg0; + if ( mtag >= maxint ) { + *tag = 1; + for ( i = 1; i <= neqns; i++ ) + if ( marker[i] < maxint ) marker[i] = 0; + mtag = *tag + mdeg0; + }; + + /* create two linked lists from nodes associated with 'element': */ + /* one with two nabors (q2head) in the adjacency structure, and the*/ + /* other with more than two nabors (qxhead). also compute 'deg0',*/ + /* number of nodes in this element. */ + q2head = 0; + qxhead = 0; + deg0 = 0; + link =element; + +n400: + istart = xadj[link]; + istop = xadj[link+1] - 1; + for ( i = istart; i <= istop; i++ ) { + enode = adjncy[i]; + link = -enode; + if ( enode < 0 ) goto n400; + if ( enode == 0 ) break; + if ( qsize[enode] != 0 ) { + deg0 += qsize[enode]; + marker[enode] = mtag; + + /*'enode' requires a degree update*/ + if ( backward[enode] == 0 ) { + /* place either in qxhead or q2head list. */ + if ( forward[enode] != 2 ) { + list[enode] = qxhead; + qxhead = enode; + } else { + list[enode] = q2head; + q2head = enode; + }; + }; + }; /* enf of -- if ( qsize[enode] != 0 ) -- */ + }; /* end of -- for ( i = istart; -- */ + + /* for each node in q2 list, do the following. */ + enode = q2head; + iq2 = 1; + +n900: + if ( enode <= 0 ) goto n1500; + if ( backward[enode] != 0 ) goto n2200; + (*tag)++; + deg = deg0; + + /* identify the other adjacent element nabor. */ + istart = xadj[enode]; + nabor = adjncy[istart]; + if ( nabor == element ) nabor = adjncy[istart+1]; + link = nabor; + if ( forward[nabor] >= 0 ) { + /* nabor is uneliminated, increase degree count. */ + deg += qsize[nabor]; + goto n2100; + }; + + /* the nabor is eliminated. for each node in the 2nd element */ + /* do the following. */ +n1000: + istart = xadj[link]; + istop = xadj[link+1] - 1; + for ( i = istart; i <= istop; i++ ) { + node = adjncy[i]; + link = -node; + if ( node != enode ) { + if ( node < 0 ) goto n1000; + if ( node == 0 ) goto n2100; + if ( qsize[node] != 0 ) { + if ( marker[node] < *tag ) { + /* 'node' is not yet considered. */ + marker[node] = *tag; + deg += qsize[node]; + } else { + if ( backward[node] == 0 ) { + if ( forward[node] == 2 ) { + /* 'node' is indistinguishable from 'enode'.*/ + /* merge them into a new supernode. */ + qsize[enode] += qsize[node]; + qsize[node] = 0; + marker[node] = maxint; + forward[node] = -enode; + backward[node] = -maxint; + } else { + /* 'node' is outmacthed by 'enode' */ + if (backward[node]==0) backward[node] = -maxint; + }; + }; /* end of -- if ( backward[node] == 0 ) -- */ + }; /* end of -- if ( marker[node] < *tag ) -- */ + }; /* end of -- if ( qsize[node] != 0 ) -- */ + }; /* end of -- if ( node != enode ) -- */ + }; /* end of -- for ( i = istart; -- */ + goto n2100; + +n1500: + /* for each 'enode' in the 'qx' list, do the following. */ + enode = qxhead; + iq2 = 0; + +n1600: if ( enode <= 0 ) goto n2300; + if ( backward[enode] != 0 ) goto n2200; + (*tag)++; + deg = deg0; + + /*for each unmarked nabor of 'enode', do the following.*/ + istart = xadj[enode]; + istop = xadj[enode+1] - 1; + for ( i = istart; i <= istop; i++ ) { + nabor = adjncy[i]; + if ( nabor == 0 ) break; + if ( marker[nabor] < *tag ) { + marker[nabor] = *tag; + link = nabor; + if ( forward[nabor] >= 0 ) + /*if uneliminated, include it in deg count.*/ + deg += qsize[nabor]; + else { +n1700: + /* if eliminated, include unmarked nodes in this*/ + /* element into the degree count. */ + jstart = xadj[link]; + jstop = xadj[link+1] - 1; + for ( j = jstart; j <= jstop; j++ ) { + node = adjncy[j]; + link = -node; + if ( node < 0 ) goto n1700; + if ( node == 0 ) break; + if ( marker[node] < *tag ) { + marker[node] = *tag; + deg += qsize[node]; + }; + }; /* end of -- for ( j = jstart; -- */ + }; /* end of -- if ( forward[nabor] >= 0 ) -- */ + }; /* end of -- if ( marker[nabor] < *tag ) -- */ + }; /* end of -- for ( i = istart; -- */ + +n2100: + /* update external degree of 'enode' in degree structure, */ + /* and '*mdeg' if necessary. */ + deg = deg - qsize[enode] + 1; + fnode = head[deg]; + forward[enode] = fnode; + backward[enode] = -deg; + if ( fnode > 0 ) backward[fnode] = enode; + head[deg] = enode; + if ( deg < *mdeg ) *mdeg = deg; + +n2200: + /* get next enode in current element. */ + enode = list[enode]; + if ( iq2 == 1 ) goto n900; + goto n1600; + +n2300: + /* get next element in the list. */ + *tag = mtag; + element = list[element]; + goto n100; + } diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mpmetis.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mpmetis.c new file mode 100644 index 0000000..3b7aa9f --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mpmetis.c @@ -0,0 +1,402 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mpmetis.c + * + * This file contains the top level routines for the multilevel recursive + * bisection algorithm PMETIS. + * + * Started 7/24/97 + * George + * + * $Id: mpmetis.c,v 1.1 2003/07/16 15:55:12 karypis Exp $ + * + */ + +#include <metis.h> + + + +/************************************************************************* +* This function is the entry point for PWMETIS that accepts exact weights +* for the target partitions +**************************************************************************/ +void METIS_mCPartGraphRecursive(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, + idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, + int *options, int *edgecut, idxtype *part) +{ + int i, j; + GraphType graph; + CtrlType ctrl; + + if (*numflag == 1) + Change2CNumbering(*nvtxs, xadj, adjncy); + + SetUpGraph(&graph, OP_PMETIS, *nvtxs, *ncon, xadj, adjncy, vwgt, adjwgt, *wgtflag); + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = McPMETIS_CTYPE; + ctrl.IType = McPMETIS_ITYPE; + ctrl.RType = McPMETIS_RTYPE; + ctrl.dbglvl = McPMETIS_DBGLVL; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + } + ctrl.optype = OP_PMETIS; + ctrl.CoarsenTo = 100; + + ctrl.nmaxvwgt = 1.5/(1.0*ctrl.CoarsenTo); + + InitRandom(-1); + + AllocateWorkSpace(&ctrl, &graph, *nparts); + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + *edgecut = MCMlevelRecursiveBisection(&ctrl, &graph, *nparts, part, 1.000, 0); + + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); + + FreeWorkSpace(&ctrl, &graph); + + if (*numflag == 1) + Change2FNumbering(*nvtxs, xadj, adjncy, part); +} + + + +/************************************************************************* +* This function is the entry point for PWMETIS that accepts exact weights +* for the target partitions +**************************************************************************/ +void METIS_mCHPartGraphRecursive(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, + idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, + float *ubvec, int *options, int *edgecut, idxtype *part) +{ + int i, j; + GraphType graph; + CtrlType ctrl; + float *myubvec; + + if (*numflag == 1) + Change2CNumbering(*nvtxs, xadj, adjncy); + + SetUpGraph(&graph, OP_PMETIS, *nvtxs, *ncon, xadj, adjncy, vwgt, adjwgt, *wgtflag); + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = PMETIS_CTYPE; + ctrl.IType = PMETIS_ITYPE; + ctrl.RType = PMETIS_RTYPE; + ctrl.dbglvl = PMETIS_DBGLVL; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + } + ctrl.optype = OP_PMETIS; + ctrl.CoarsenTo = 100; + + ctrl.nmaxvwgt = 1.5/(1.0*ctrl.CoarsenTo); + + myubvec = fmalloc(*ncon, "PWMETIS: mytpwgts"); + scopy(*ncon, ubvec, myubvec); + + InitRandom(-1); + + AllocateWorkSpace(&ctrl, &graph, *nparts); + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + *edgecut = MCHMlevelRecursiveBisection(&ctrl, &graph, *nparts, part, myubvec, 0); + + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); + + FreeWorkSpace(&ctrl, &graph); + GKfree(&myubvec, LTERM); + + if (*numflag == 1) + Change2FNumbering(*nvtxs, xadj, adjncy, part); +} + + + +/************************************************************************* +* This function is the entry point for PWMETIS that accepts exact weights +* for the target partitions +**************************************************************************/ +void METIS_mCPartGraphRecursiveInternal(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, + float *nvwgt, idxtype *adjwgt, int *nparts, int *options, int *edgecut, idxtype *part) +{ + int i, j; + GraphType graph; + CtrlType ctrl; + + SetUpGraph2(&graph, *nvtxs, *ncon, xadj, adjncy, nvwgt, adjwgt); + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = PMETIS_CTYPE; + ctrl.IType = PMETIS_ITYPE; + ctrl.RType = PMETIS_RTYPE; + ctrl.dbglvl = PMETIS_DBGLVL; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + } + ctrl.optype = OP_PMETIS; + ctrl.CoarsenTo = 100; + + ctrl.nmaxvwgt = 1.5/(1.0*ctrl.CoarsenTo); + + InitRandom(-1); + + AllocateWorkSpace(&ctrl, &graph, *nparts); + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + *edgecut = MCMlevelRecursiveBisection(&ctrl, &graph, *nparts, part, 1.000, 0); + + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); + + FreeWorkSpace(&ctrl, &graph); + +} + + +/************************************************************************* +* This function is the entry point for PWMETIS that accepts exact weights +* for the target partitions +**************************************************************************/ +void METIS_mCHPartGraphRecursiveInternal(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, + float *nvwgt, idxtype *adjwgt, int *nparts, float *ubvec, int *options, int *edgecut, + idxtype *part) +{ + int i, j; + GraphType graph; + CtrlType ctrl; + float *myubvec; + + SetUpGraph2(&graph, *nvtxs, *ncon, xadj, adjncy, nvwgt, adjwgt); + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = PMETIS_CTYPE; + ctrl.IType = PMETIS_ITYPE; + ctrl.RType = PMETIS_RTYPE; + ctrl.dbglvl = PMETIS_DBGLVL; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + } + ctrl.optype = OP_PMETIS; + ctrl.CoarsenTo = 100; + + ctrl.nmaxvwgt = 1.5/(1.0*ctrl.CoarsenTo); + + myubvec = fmalloc(*ncon, "PWMETIS: mytpwgts"); + scopy(*ncon, ubvec, myubvec); + + InitRandom(-1); + + AllocateWorkSpace(&ctrl, &graph, *nparts); + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + *edgecut = MCHMlevelRecursiveBisection(&ctrl, &graph, *nparts, part, myubvec, 0); + + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); + + FreeWorkSpace(&ctrl, &graph); + GKfree(&myubvec, LTERM); + +} + + + + +/************************************************************************* +* This function takes a graph and produces a bisection of it +**************************************************************************/ +int MCMlevelRecursiveBisection(CtrlType *ctrl, GraphType *graph, int nparts, idxtype *part, + float ubfactor, int fpart) +{ + int i, j, nvtxs, ncon, cut; + idxtype *label, *where; + GraphType lgraph, rgraph; + float tpwgts[2]; + + nvtxs = graph->nvtxs; + if (nvtxs == 0) { + printf("\t***Cannot bisect a graph with 0 vertices!\n\t***You are trying to partition a graph into too many parts!\n"); + return 0; + } + + /* Determine the weights of the partitions */ + tpwgts[0] = 1.0*(nparts>>1)/(1.0*nparts); + tpwgts[1] = 1.0 - tpwgts[0]; + + MCMlevelEdgeBisection(ctrl, graph, tpwgts, ubfactor); + cut = graph->mincut; + + label = graph->label; + where = graph->where; + for (i=0; i<nvtxs; i++) + part[label[i]] = where[i] + fpart; + + if (nparts > 2) + SplitGraphPart(ctrl, graph, &lgraph, &rgraph); + + /* Free the memory of the top level graph */ + GKfree(&graph->gdata, &graph->nvwgt, &graph->rdata, &graph->label, LTERM); + + + /* Do the recursive call */ + if (nparts > 3) { + cut += MCMlevelRecursiveBisection(ctrl, &lgraph, nparts/2, part, ubfactor, fpart); + cut += MCMlevelRecursiveBisection(ctrl, &rgraph, nparts-nparts/2, part, ubfactor, fpart+nparts/2); + } + else if (nparts == 3) { + cut += MCMlevelRecursiveBisection(ctrl, &rgraph, nparts-nparts/2, part, ubfactor, fpart+nparts/2); + GKfree(&lgraph.gdata, &lgraph.nvwgt, &lgraph.label, LTERM); + } + + return cut; + +} + + + +/************************************************************************* +* This function takes a graph and produces a bisection of it +**************************************************************************/ +int MCHMlevelRecursiveBisection(CtrlType *ctrl, GraphType *graph, int nparts, idxtype *part, + float *ubvec, int fpart) +{ + int i, j, nvtxs, ncon, cut; + idxtype *label, *where; + GraphType lgraph, rgraph; + float tpwgts[2], *npwgts, *lubvec, *rubvec; + + lubvec = rubvec = NULL; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + if (nvtxs == 0) { + printf("\t***Cannot bisect a graph with 0 vertices!\n\t***You are trying to partition a graph into too many parts!\n"); + return 0; + } + + /* Determine the weights of the partitions */ + tpwgts[0] = 1.0*(nparts>>1)/(1.0*nparts); + tpwgts[1] = 1.0 - tpwgts[0]; + + /* For now, relax at the coarsest level only */ + if (nparts == 2) + MCHMlevelEdgeBisection(ctrl, graph, tpwgts, ubvec); + else + MCMlevelEdgeBisection(ctrl, graph, tpwgts, 1.000); + cut = graph->mincut; + + label = graph->label; + where = graph->where; + for (i=0; i<nvtxs; i++) + part[label[i]] = where[i] + fpart; + + if (nparts > 2) { + /* Adjust the ubvecs before the split */ + npwgts = graph->npwgts; + lubvec = fmalloc(ncon, "MCHMlevelRecursiveBisection"); + rubvec = fmalloc(ncon, "MCHMlevelRecursiveBisection"); + + for (i=0; i<ncon; i++) { + lubvec[i] = ubvec[i]*tpwgts[0]/npwgts[i]; + lubvec[i] = amax(lubvec[i], 1.01); + + rubvec[i] = ubvec[i]*tpwgts[1]/npwgts[ncon+i]; + rubvec[i] = amax(rubvec[i], 1.01); + } + + SplitGraphPart(ctrl, graph, &lgraph, &rgraph); + } + + /* Free the memory of the top level graph */ + GKfree(&graph->gdata, &graph->nvwgt, &graph->rdata, &graph->label, LTERM); + + + /* Do the recursive call */ + if (nparts > 3) { + cut += MCHMlevelRecursiveBisection(ctrl, &lgraph, nparts/2, part, lubvec, fpart); + cut += MCHMlevelRecursiveBisection(ctrl, &rgraph, nparts-nparts/2, part, rubvec, fpart+nparts/2); + } + else if (nparts == 3) { + cut += MCHMlevelRecursiveBisection(ctrl, &rgraph, nparts-nparts/2, part, rubvec, fpart+nparts/2); + GKfree(&lgraph.gdata, &lgraph.nvwgt, &lgraph.label, LTERM); + } + + GKfree(&lubvec, &rubvec, LTERM); + + return cut; + +} + + + + +/************************************************************************* +* This function performs multilevel bisection +**************************************************************************/ +void MCMlevelEdgeBisection(CtrlType *ctrl, GraphType *graph, float *tpwgts, float ubfactor) +{ + GraphType *cgraph; + + cgraph = MCCoarsen2Way(ctrl, graph); + + MocInit2WayPartition(ctrl, cgraph, tpwgts, ubfactor); + + MocRefine2Way(ctrl, graph, cgraph, tpwgts, ubfactor); + +} + + + +/************************************************************************* +* This function performs multilevel bisection +**************************************************************************/ +void MCHMlevelEdgeBisection(CtrlType *ctrl, GraphType *graph, float *tpwgts, float *ubvec) +{ + int i; + GraphType *cgraph; + +/* + for (i=0; i<graph->ncon; i++) + printf("%.4f ", ubvec[i]); + printf("\n"); +*/ + + cgraph = MCCoarsen2Way(ctrl, graph); + + MocInit2WayPartition2(ctrl, cgraph, tpwgts, ubvec); + + MocRefine2Way2(ctrl, graph, cgraph, tpwgts, ubvec); + +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mrefine.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mrefine.c new file mode 100644 index 0000000..3e28dc7 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mrefine.c @@ -0,0 +1,219 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * refine.c + * + * This file contains the driving routines for multilevel refinement + * + * Started 7/24/97 + * George + * + * $Id: mrefine.c,v 1.1 2003/07/24 18:39:10 karypis Exp $ + */ + +#include <metis.h> + + +/************************************************************************* +* This function is the entry point of refinement +**************************************************************************/ +void MocRefine2Way(CtrlType *ctrl, GraphType *orggraph, GraphType *graph, float *tpwgts, float ubfactor) +{ + int i; + float tubvec[MAXNCON]; + + for (i=0; i<graph->ncon; i++) + tubvec[i] = 1.0; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->UncoarsenTmr)); + + /* Compute the parameters of the coarsest graph */ + MocCompute2WayPartitionParams(ctrl, graph); + + for (;;) { + ASSERT(CheckBnd(graph)); + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->RefTmr)); + switch (ctrl->RType) { + case RTYPE_FM: + MocBalance2Way(ctrl, graph, tpwgts, 1.03); + MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 8); + break; + case 2: + MocBalance2Way(ctrl, graph, tpwgts, 1.03); + MocFM_2WayEdgeRefine2(ctrl, graph, tpwgts, tubvec, 8); + break; + default: + errexit("Unknown refinement type: %d\n", ctrl->RType); + } + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->RefTmr)); + + if (graph == orggraph) + break; + + graph = graph->finer; + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ProjectTmr)); + MocProject2WayPartition(ctrl, graph); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ProjectTmr)); + } + + MocBalance2Way(ctrl, graph, tpwgts, 1.01); + MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 8); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->UncoarsenTmr)); +} + + +/************************************************************************* +* This function allocates memory for 2-way edge refinement +**************************************************************************/ +void MocAllocate2WayPartitionMemory(CtrlType *ctrl, GraphType *graph) +{ + int nvtxs, ncon; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + + graph->rdata = idxmalloc(5*nvtxs, "Allocate2WayPartitionMemory: rdata"); + graph->where = graph->rdata; + graph->id = graph->rdata + nvtxs; + graph->ed = graph->rdata + 2*nvtxs; + graph->bndptr = graph->rdata + 3*nvtxs; + graph->bndind = graph->rdata + 4*nvtxs; + + graph->npwgts = fmalloc(2*ncon, "npwgts"); +} + + +/************************************************************************* +* This function computes the initial id/ed +**************************************************************************/ +void MocCompute2WayPartitionParams(CtrlType *ctrl, GraphType *graph) +{ + int i, j, k, l, nvtxs, ncon, nbnd, mincut; + idxtype *xadj, *adjncy, *adjwgt; + float *nvwgt, *npwgts; + idxtype *id, *ed, *where; + idxtype *bndptr, *bndind; + int me, other; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + where = graph->where; + npwgts = sset(2*ncon, 0.0, graph->npwgts); + id = idxset(nvtxs, 0, graph->id); + ed = idxset(nvtxs, 0, graph->ed); + bndptr = idxset(nvtxs, -1, graph->bndptr); + bndind = graph->bndind; + + + /*------------------------------------------------------------ + / Compute now the id/ed degrees + /------------------------------------------------------------*/ + nbnd = mincut = 0; + for (i=0; i<nvtxs; i++) { + ASSERT(where[i] >= 0 && where[i] <= 1); + me = where[i]; + saxpy(ncon, 1.0, nvwgt+i*ncon, 1, npwgts+me*ncon, 1); + + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (me == where[adjncy[j]]) + id[i] += adjwgt[j]; + else + ed[i] += adjwgt[j]; + } + + if (ed[i] > 0 || xadj[i] == xadj[i+1]) { + mincut += ed[i]; + bndptr[i] = nbnd; + bndind[nbnd++] = i; + } + } + + graph->mincut = mincut/2; + graph->nbnd = nbnd; + +} + + + +/************************************************************************* +* This function projects a partition, and at the same time computes the +* parameters for refinement. +**************************************************************************/ +void MocProject2WayPartition(CtrlType *ctrl, GraphType *graph) +{ + int i, j, k, nvtxs, nbnd, me; + idxtype *xadj, *adjncy, *adjwgt, *adjwgtsum; + idxtype *cmap, *where, *id, *ed, *bndptr, *bndind; + idxtype *cwhere, *cid, *ced, *cbndptr; + GraphType *cgraph; + + cgraph = graph->coarser; + cwhere = cgraph->where; + cid = cgraph->id; + ced = cgraph->ed; + cbndptr = cgraph->bndptr; + + nvtxs = graph->nvtxs; + cmap = graph->cmap; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + adjwgtsum = graph->adjwgtsum; + + MocAllocate2WayPartitionMemory(ctrl, graph); + + where = graph->where; + id = idxset(nvtxs, 0, graph->id); + ed = idxset(nvtxs, 0, graph->ed); + bndptr = idxset(nvtxs, -1, graph->bndptr); + bndind = graph->bndind; + + + /* Go through and project partition and compute id/ed for the nodes */ + for (i=0; i<nvtxs; i++) { + k = cmap[i]; + where[i] = cwhere[k]; + cmap[i] = cbndptr[k]; + } + + for (nbnd=0, i=0; i<nvtxs; i++) { + me = where[i]; + + id[i] = adjwgtsum[i]; + + if (xadj[i] == xadj[i+1]) { + bndptr[i] = nbnd; + bndind[nbnd++] = i; + } + else { + if (cmap[i] != -1) { /* If it is an interface node. Note that cmap[i] = cbndptr[cmap[i]] */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (me != where[adjncy[j]]) + ed[i] += adjwgt[j]; + } + id[i] -= ed[i]; + + if (ed[i] > 0 || xadj[i] == xadj[i+1]) { + bndptr[i] = nbnd; + bndind[nbnd++] = i; + } + } + } + } + + graph->mincut = cgraph->mincut; + graph->nbnd = nbnd; + scopy(2*graph->ncon, cgraph->npwgts, graph->npwgts); + + FreeGraph(graph->coarser); + graph->coarser = NULL; + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mrefine2.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mrefine2.c new file mode 100644 index 0000000..91ad0b5 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mrefine2.c @@ -0,0 +1,55 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mrefine2.c + * + * This file contains the driving routines for multilevel refinement + * + * Started 7/24/97 + * George + * + * $Id: mrefine2.c,v 1.1 2003/07/16 15:55:12 karypis Exp $ + */ + +#include <metis.h> + + +/************************************************************************* +* This function is the entry point of refinement +**************************************************************************/ +void MocRefine2Way2(CtrlType *ctrl, GraphType *orggraph, GraphType *graph, float *tpwgts, + float *ubvec) +{ + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->UncoarsenTmr)); + + /* Compute the parameters of the coarsest graph */ + MocCompute2WayPartitionParams(ctrl, graph); + + for (;;) { + ASSERT(CheckBnd(graph)); + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->RefTmr)); + switch (ctrl->RType) { + case RTYPE_FM: + MocBalance2Way2(ctrl, graph, tpwgts, ubvec); + MocFM_2WayEdgeRefine2(ctrl, graph, tpwgts, ubvec, 8); + break; + default: + errexit("Unknown refinement type: %d\n", ctrl->RType); + } + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->RefTmr)); + + if (graph == orggraph) + break; + + graph = graph->finer; + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ProjectTmr)); + MocProject2WayPartition(ctrl, graph); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ProjectTmr)); + } + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->UncoarsenTmr)); +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mutil.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mutil.c new file mode 100644 index 0000000..68dc5c5 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mutil.c @@ -0,0 +1,101 @@ +/* + * mutil.c + * + * This file contains various utility functions for the MOC portion of the + * code + * + * Started 2/15/98 + * George + * + * $Id: mutil.c,v 1.1 2003/07/16 15:55:13 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function checks if the vertex weights of two vertices are below +* a given set of values +**************************************************************************/ +int AreAllVwgtsBelow(int ncon, float alpha, float *vwgt1, float beta, float *vwgt2, float limit) +{ + int i; + + for (i=0; i<ncon; i++) + if (alpha*vwgt1[i] + beta*vwgt2[i] > limit) + return 0; + + return 1; +} + + +/************************************************************************* +* This function checks if the vertex weights of two vertices are below +* a given set of values +**************************************************************************/ +int AreAnyVwgtsBelow(int ncon, float alpha, float *vwgt1, float beta, float *vwgt2, float limit) +{ + int i; + + for (i=0; i<ncon; i++) + if (alpha*vwgt1[i] + beta*vwgt2[i] < limit) + return 1; + + return 0; +} + + + +/************************************************************************* +* This function checks if the vertex weights of two vertices are above +* a given set of values +**************************************************************************/ +int AreAllVwgtsAbove(int ncon, float alpha, float *vwgt1, float beta, float *vwgt2, float limit) +{ + int i; + + for (i=0; i<ncon; i++) + if (alpha*vwgt1[i] + beta*vwgt2[i] < limit) + return 0; + + return 1; +} + + +/************************************************************************* +* This function computes the load imbalance over all the constrains +* For now assume that we just want balanced partitionings +**************************************************************************/ +float ComputeLoadImbalance(int ncon, int nparts, float *npwgts, float *tpwgts) +{ + int i, j; + float max, lb=0.0; + + for (i=0; i<ncon; i++) { + max = 0.0; + for (j=0; j<nparts; j++) { + if (npwgts[j*ncon+i] > max) + max = npwgts[j*ncon+i]; + } + if (max*nparts > lb) + lb = max*nparts; + } + + return lb; +} + +/************************************************************************* +* This function checks if the vertex weights of two vertices are below +* a given set of values +**************************************************************************/ +int AreAllBelow(int ncon, float *v1, float *v2) +{ + int i; + + for (i=0; i<ncon; i++) + if (v1[i] > v2[i]) + return 0; + + return 1; +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/myqsort.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/myqsort.c new file mode 100644 index 0000000..a6939ce --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/myqsort.c @@ -0,0 +1,547 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * myqsort.c + * + * This file contains a fast idxtype increasing qsort algorithm. + * Addopted from TeX + * + * Started 10/18/96 + * George + * + * $Id: myqsort.c,v 1.1 2003/07/16 15:55:13 karypis Exp $ + */ + +#include <metis.h> /* only for type declarations */ + +#define THRESH 1 /* threshold for insertion */ +#define MTHRESH 6 /* threshold for median */ + + + + +static void siqst(idxtype *, idxtype *); +static void iiqst(int *, int *); +static void keyiqst(KeyValueType *, KeyValueType *); +static void keyvaliqst(KeyValueType *, KeyValueType *); + + +/************************************************************************* +* Entry point of idxtype increasing sort +**************************************************************************/ +void iidxsort(int n, idxtype *base) +{ + register idxtype *i; + register idxtype *j; + register idxtype *lo; + register idxtype *hi; + register idxtype *min; + register idxtype c; + idxtype *max; + + if (n <= 1) + return; + + max = base + n; + + if (n >= THRESH) { + siqst(base, max); + hi = base + THRESH; + } + else + hi = max; + + for (j = lo = base; lo++ < hi;) { + if (*j > *lo) + j = lo; + } + if (j != base) { /* swap j into place */ + c = *base; + *base = *j; + *j = c; + } + + for (min = base; (hi = min += 1) < max;) { + while (*(--hi) > *min); + if ((hi += 1) != min) { + for (lo = min + 1; --lo >= min;) { + c = *lo; + for (i = j = lo; (j -= 1) >= hi; i = j) + *i = *j; + *i = c; + } + } + } +} + +static void siqst(idxtype *base, idxtype *max) +{ + register idxtype *i; + register idxtype *j; + register idxtype *jj; + register idxtype *mid; + register int ii; + register idxtype c; + idxtype *tmp; + int lo; + int hi; + + lo = max - base; /* number of elements as idxtype */ + do { + mid = base + ((unsigned) lo>>1); + if (lo >= MTHRESH) { + j = (*base > *mid ? base : mid); + tmp = max - 1; + if (*j > *tmp) { + j = (j == base ? mid : base); /* switch to first loser */ + if (*j < *tmp) + j = tmp; + } + + if (j != mid) { /* SWAP */ + c = *mid; + *mid = *j; + *j = c; + } + } + + /* Semi-standard quicksort partitioning/swapping */ + for (i = base, j = max - 1;;) { + while (i < mid && *i <= *mid) + i++; + while (j > mid) { + if (*mid <= *j) { + j--; + continue; + } + tmp = i + 1; /* value of i after swap */ + if (i == mid) /* j <-> mid, new mid is j */ + mid = jj = j; + else /* i <-> j */ + jj = j--; + goto swap; + } + + if (i == mid) + break; + else { /* i <-> mid, new mid is i */ + jj = mid; + tmp = mid = i; /* value of i after swap */ + j--; + } +swap: + c = *i; + *i = *jj; + *jj = c; + i = tmp; + } + + i = (j = mid) + 1; + if ((lo = j - base) <= (hi = max - i)) { + if (lo >= THRESH) + siqst(base, j); + base = i; + lo = hi; + } + else { + if (hi >= THRESH) + siqst(i, max); + max = j; + } + } while (lo >= THRESH); +} + + + + + +/************************************************************************* +* Entry point of int increasing sort +**************************************************************************/ +void iintsort(int n, int *base) +{ + register int *i; + register int *j; + register int *lo; + register int *hi; + register int *min; + register int c; + int *max; + + if (n <= 1) + return; + + max = base + n; + + if (n >= THRESH) { + iiqst(base, max); + hi = base + THRESH; + } + else + hi = max; + + for (j = lo = base; lo++ < hi;) { + if (*j > *lo) + j = lo; + } + if (j != base) { /* swap j into place */ + c = *base; + *base = *j; + *j = c; + } + + for (min = base; (hi = min += 1) < max;) { + while (*(--hi) > *min); + if ((hi += 1) != min) { + for (lo = min + 1; --lo >= min;) { + c = *lo; + for (i = j = lo; (j -= 1) >= hi; i = j) + *i = *j; + *i = c; + } + } + } +} + + +static void iiqst(int *base, int *max) +{ + register int *i; + register int *j; + register int *jj; + register int *mid; + register int ii; + register int c; + int *tmp; + int lo; + int hi; + + lo = max - base; /* number of elements as ints */ + do { + mid = base + ((unsigned) lo>>1); + if (lo >= MTHRESH) { + j = (*base > *mid ? base : mid); + tmp = max - 1; + if (*j > *tmp) { + j = (j == base ? mid : base); /* switch to first loser */ + if (*j < *tmp) + j = tmp; + } + + if (j != mid) { /* SWAP */ + c = *mid; + *mid = *j; + *j = c; + } + } + + /* Semi-standard quicksort partitioning/swapping */ + for (i = base, j = max - 1;;) { + while (i < mid && *i <= *mid) + i++; + while (j > mid) { + if (*mid <= *j) { + j--; + continue; + } + tmp = i + 1; /* value of i after swap */ + if (i == mid) /* j <-> mid, new mid is j */ + mid = jj = j; + else /* i <-> j */ + jj = j--; + goto swap; + } + + if (i == mid) + break; + else { /* i <-> mid, new mid is i */ + jj = mid; + tmp = mid = i; /* value of i after swap */ + j--; + } +swap: + c = *i; + *i = *jj; + *jj = c; + i = tmp; + } + + i = (j = mid) + 1; + if ((lo = j - base) <= (hi = max - i)) { + if (lo >= THRESH) + iiqst(base, j); + base = i; + lo = hi; + } + else { + if (hi >= THRESH) + iiqst(i, max); + max = j; + } + } while (lo >= THRESH); +} + + + + + +/************************************************************************* +* Entry point of KeyVal increasing sort, ONLY key part +**************************************************************************/ +void ikeysort(int n, KeyValueType *base) +{ + register KeyValueType *i; + register KeyValueType *j; + register KeyValueType *lo; + register KeyValueType *hi; + register KeyValueType *min; + register KeyValueType c; + KeyValueType *max; + + if (n <= 1) + return; + + max = base + n; + + if (n >= THRESH) { + keyiqst(base, max); + hi = base + THRESH; + } + else + hi = max; + + for (j = lo = base; lo++ < hi;) { + if (j->key > lo->key) + j = lo; + } + if (j != base) { /* swap j into place */ + c = *base; + *base = *j; + *j = c; + } + + for (min = base; (hi = min += 1) < max;) { + while ((--hi)->key > min->key); + if ((hi += 1) != min) { + for (lo = min + 1; --lo >= min;) { + c = *lo; + for (i = j = lo; (j -= 1) >= hi; i = j) + *i = *j; + *i = c; + } + } + } + + /* Sanity check */ + { + int i; + for (i=0; i<n-1; i++) + if (base[i].key > base[i+1].key) + printf("Something went wrong!\n"); + } +} + + +static void keyiqst(KeyValueType *base, KeyValueType *max) +{ + register KeyValueType *i; + register KeyValueType *j; + register KeyValueType *jj; + register KeyValueType *mid; + register KeyValueType c; + KeyValueType *tmp; + int lo; + int hi; + + lo = (max - base)>>1; /* number of elements as KeyValueType */ + do { + mid = base + ((unsigned) lo>>1); + if (lo >= MTHRESH) { + j = (base->key > mid->key ? base : mid); + tmp = max - 1; + if (j->key > tmp->key) { + j = (j == base ? mid : base); /* switch to first loser */ + if (j->key < tmp->key) + j = tmp; + } + + if (j != mid) { /* SWAP */ + c = *mid; + *mid = *j; + *j = c; + } + } + + /* Semi-standard quicksort partitioning/swapping */ + for (i = base, j = max - 1;;) { + while (i < mid && i->key <= mid->key) + i++; + while (j > mid) { + if (mid->key <= j->key) { + j--; + continue; + } + tmp = i + 1; /* value of i after swap */ + if (i == mid) /* j <-> mid, new mid is j */ + mid = jj = j; + else /* i <-> j */ + jj = j--; + goto swap; + } + + if (i == mid) + break; + else { /* i <-> mid, new mid is i */ + jj = mid; + tmp = mid = i; /* value of i after swap */ + j--; + } +swap: + c = *i; + *i = *jj; + *jj = c; + i = tmp; + } + + i = (j = mid) + 1; + if ((lo = (j - base)>>1) <= (hi = (max - i)>>1)) { + if (lo >= THRESH) + keyiqst(base, j); + base = i; + lo = hi; + } + else { + if (hi >= THRESH) + keyiqst(i, max); + max = j; + } + } while (lo >= THRESH); +} + + + + +/************************************************************************* +* Entry point of KeyVal increasing sort, BOTH key and val part +**************************************************************************/ +void ikeyvalsort(int n, KeyValueType *base) +{ + register KeyValueType *i; + register KeyValueType *j; + register KeyValueType *lo; + register KeyValueType *hi; + register KeyValueType *min; + register KeyValueType c; + KeyValueType *max; + + if (n <= 1) + return; + + max = base + n; + + if (n >= THRESH) { + keyvaliqst(base, max); + hi = base + THRESH; + } + else + hi = max; + + for (j = lo = base; lo++ < hi;) { + if ((j->key > lo->key) || (j->key == lo->key && j->val > lo->val)) + j = lo; + } + if (j != base) { /* swap j into place */ + c = *base; + *base = *j; + *j = c; + } + + for (min = base; (hi = min += 1) < max;) { + while ((--hi)->key > min->key || (hi->key == min->key && hi->val > min->val)); + if ((hi += 1) != min) { + for (lo = min + 1; --lo >= min;) { + c = *lo; + for (i = j = lo; (j -= 1) >= hi; i = j) + *i = *j; + *i = c; + } + } + } +} + + +static void keyvaliqst(KeyValueType *base, KeyValueType *max) +{ + register KeyValueType *i; + register KeyValueType *j; + register KeyValueType *jj; + register KeyValueType *mid; + register KeyValueType c; + KeyValueType *tmp; + int lo; + int hi; + + lo = (max - base)>>1; /* number of elements as KeyValueType */ + do { + mid = base + ((unsigned) lo>>1); + if (lo >= MTHRESH) { + j = (base->key > mid->key || (base->key == mid->key && base->val > mid->val) ? base : mid); + tmp = max - 1; + if (j->key > tmp->key || (j->key == tmp->key && j->val > tmp->val)) { + j = (j == base ? mid : base); /* switch to first loser */ + if (j->key < tmp->key || (j->key == tmp->key && j->val < tmp->val)) + j = tmp; + } + + if (j != mid) { /* SWAP */ + c = *mid; + *mid = *j; + *j = c; + } + } + + /* Semi-standard quicksort partitioning/swapping */ + for (i = base, j = max - 1;;) { + while (i < mid && (i->key < mid->key || (i->key == mid->key && i->val <= mid->val))) + i++; + while (j > mid) { + if (mid->key < j->key || (mid->key == j->key && mid->val <= j->val)) { + j--; + continue; + } + tmp = i + 1; /* value of i after swap */ + if (i == mid) /* j <-> mid, new mid is j */ + mid = jj = j; + else /* i <-> j */ + jj = j--; + goto swap; + } + + if (i == mid) + break; + else { /* i <-> mid, new mid is i */ + jj = mid; + tmp = mid = i; /* value of i after swap */ + j--; + } +swap: + c = *i; + *i = *jj; + *jj = c; + i = tmp; + } + + i = (j = mid) + 1; + if ((lo = (j - base)>>1) <= (hi = (max - i)>>1)) { + if (lo >= THRESH) + keyvaliqst(base, j); + base = i; + lo = hi; + } + else { + if (hi >= THRESH) + keyvaliqst(i, max); + max = j; + } + } while (lo >= THRESH); +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/ometis.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/ometis.c new file mode 100644 index 0000000..e972e88 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/ometis.c @@ -0,0 +1,764 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * ometis.c + * + * This file contains the top level routines for the multilevel recursive + * bisection algorithm PMETIS. + * + * Started 7/24/97 + * George + * + * $Id: ometis.c,v 1.2 2003/07/31 06:14:01 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function is the entry point for OEMETIS +**************************************************************************/ +void METIS_EdgeND(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *options, + idxtype *perm, idxtype *iperm) +{ + int i, j; + GraphType graph; + CtrlType ctrl; + + if (*numflag == 1) + Change2CNumbering(*nvtxs, xadj, adjncy); + + SetUpGraph(&graph, OP_OEMETIS, *nvtxs, 1, xadj, adjncy, NULL, NULL, 0); + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = OEMETIS_CTYPE; + ctrl.IType = OEMETIS_ITYPE; + ctrl.RType = OEMETIS_RTYPE; + ctrl.dbglvl = OEMETIS_DBGLVL; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + } + ctrl.oflags = 0; + ctrl.pfactor = -1; + ctrl.nseps = 1; + + ctrl.optype = OP_OEMETIS; + ctrl.CoarsenTo = 20; + ctrl.maxvwgt = 1.5*(idxsum(*nvtxs, graph.vwgt)/ctrl.CoarsenTo); + + InitRandom(-1); + + AllocateWorkSpace(&ctrl, &graph, 2); + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + MlevelNestedDissection(&ctrl, &graph, iperm, ORDER_UNBALANCE_FRACTION, *nvtxs); + + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); + + for (i=0; i<*nvtxs; i++) + perm[iperm[i]] = i; + + FreeWorkSpace(&ctrl, &graph); + + if (*numflag == 1) + Change2FNumberingOrder(*nvtxs, xadj, adjncy, perm, iperm); +} + + +/************************************************************************* +* This function is the entry point for ONCMETIS +**************************************************************************/ +void METIS_NodeND(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *options, + idxtype *perm, idxtype *iperm) +{ + int i, ii, j, l, wflag, nflag; + GraphType graph; + CtrlType ctrl; + idxtype *cptr, *cind, *piperm; + + if (*numflag == 1) + Change2CNumbering(*nvtxs, xadj, adjncy); + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = ONMETIS_CTYPE; + ctrl.IType = ONMETIS_ITYPE; + ctrl.RType = ONMETIS_RTYPE; + ctrl.dbglvl = ONMETIS_DBGLVL; + ctrl.oflags = ONMETIS_OFLAGS; + ctrl.pfactor = ONMETIS_PFACTOR; + ctrl.nseps = ONMETIS_NSEPS; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + ctrl.oflags = options[OPTION_OFLAGS]; + ctrl.pfactor = options[OPTION_PFACTOR]; + ctrl.nseps = options[OPTION_NSEPS]; + } + if (ctrl.nseps < 1) + ctrl.nseps = 1; + + ctrl.optype = OP_ONMETIS; + ctrl.CoarsenTo = 100; + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + InitRandom(-1); + + if (ctrl.pfactor > 0) { + /*============================================================ + * Prune the dense columns + ==============================================================*/ + piperm = idxmalloc(*nvtxs, "ONMETIS: piperm"); + + PruneGraph(&ctrl, &graph, *nvtxs, xadj, adjncy, piperm, (float)(0.1*ctrl.pfactor)); + } + else if (ctrl.oflags&OFLAG_COMPRESS) { + /*============================================================ + * Compress the graph + ==============================================================*/ + cptr = idxmalloc(*nvtxs+1, "ONMETIS: cptr"); + cind = idxmalloc(*nvtxs, "ONMETIS: cind"); + + CompressGraph(&ctrl, &graph, *nvtxs, xadj, adjncy, cptr, cind); + + if (graph.nvtxs >= COMPRESSION_FRACTION*(*nvtxs)) { + ctrl.oflags--; /* We actually performed no compression */ + GKfree(&cptr, &cind, LTERM); + } + else if (2*graph.nvtxs < *nvtxs && ctrl.nseps == 1) + ctrl.nseps = 2; + } + else { + SetUpGraph(&graph, OP_ONMETIS, *nvtxs, 1, xadj, adjncy, NULL, NULL, 0); + } + + + /*============================================================= + * Do the nested dissection ordering + --=============================================================*/ + ctrl.maxvwgt = 1.5*(idxsum(graph.nvtxs, graph.vwgt)/ctrl.CoarsenTo); + AllocateWorkSpace(&ctrl, &graph, 2); + + if (ctrl.oflags&OFLAG_CCMP) + MlevelNestedDissectionCC(&ctrl, &graph, iperm, ORDER_UNBALANCE_FRACTION, graph.nvtxs); + else + MlevelNestedDissection(&ctrl, &graph, iperm, ORDER_UNBALANCE_FRACTION, graph.nvtxs); + + FreeWorkSpace(&ctrl, &graph); + + if (ctrl.pfactor > 0) { /* Order any prunned vertices */ + if (graph.nvtxs < *nvtxs) { + idxcopy(graph.nvtxs, iperm, perm); /* Use perm as an auxiliary array */ + for (i=0; i<graph.nvtxs; i++) + iperm[piperm[i]] = perm[i]; + for (i=graph.nvtxs; i<*nvtxs; i++) + iperm[piperm[i]] = i; + } + + GKfree(&piperm, LTERM); + } + else if (ctrl.oflags&OFLAG_COMPRESS) { /* Uncompress the ordering */ + if (graph.nvtxs < COMPRESSION_FRACTION*(*nvtxs)) { + /* construct perm from iperm */ + for (i=0; i<graph.nvtxs; i++) + perm[iperm[i]] = i; + for (l=ii=0; ii<graph.nvtxs; ii++) { + i = perm[ii]; + for (j=cptr[i]; j<cptr[i+1]; j++) + iperm[cind[j]] = l++; + } + } + + GKfree(&cptr, &cind, LTERM); + } + + + for (i=0; i<*nvtxs; i++) + perm[iperm[i]] = i; + + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); + + if (*numflag == 1) + Change2FNumberingOrder(*nvtxs, xadj, adjncy, perm, iperm); + +} + + +/************************************************************************* +* This function is the entry point for ONWMETIS. It requires weights on the +* vertices. It is for the case that the matrix has been pre-compressed. +**************************************************************************/ +void METIS_NodeWND(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, int *numflag, + int *options, idxtype *perm, idxtype *iperm) +{ + int i, j, tvwgt; + GraphType graph; + CtrlType ctrl; + + if (*numflag == 1) + Change2CNumbering(*nvtxs, xadj, adjncy); + + SetUpGraph(&graph, OP_ONMETIS, *nvtxs, 1, xadj, adjncy, vwgt, NULL, 2); + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = ONMETIS_CTYPE; + ctrl.IType = ONMETIS_ITYPE; + ctrl.RType = ONMETIS_RTYPE; + ctrl.dbglvl = ONMETIS_DBGLVL; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + } + + ctrl.oflags = OFLAG_COMPRESS; + ctrl.pfactor = 0; + ctrl.nseps = 2; + ctrl.optype = OP_ONMETIS; + ctrl.CoarsenTo = 100; + ctrl.maxvwgt = 1.5*(idxsum(*nvtxs, graph.vwgt)/ctrl.CoarsenTo); + + InitRandom(-1); + + AllocateWorkSpace(&ctrl, &graph, 2); + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + MlevelNestedDissection(&ctrl, &graph, iperm, ORDER_UNBALANCE_FRACTION, *nvtxs); + + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); + + for (i=0; i<*nvtxs; i++) + perm[iperm[i]] = i; + + FreeWorkSpace(&ctrl, &graph); + + if (*numflag == 1) + Change2FNumberingOrder(*nvtxs, xadj, adjncy, perm, iperm); +} + + + + +/************************************************************************* +* This function takes a graph and produces a bisection of it +**************************************************************************/ +void MlevelNestedDissection(CtrlType *ctrl, GraphType *graph, idxtype *order, float ubfactor, int lastvtx) +{ + int i, j, nvtxs, nbnd, tvwgt, tpwgts2[2]; + idxtype *label, *bndind; + GraphType lgraph, rgraph; + + nvtxs = graph->nvtxs; + + /* Determine the weights of the partitions */ + tvwgt = idxsum(nvtxs, graph->vwgt); + tpwgts2[0] = tvwgt/2; + tpwgts2[1] = tvwgt-tpwgts2[0]; + + switch (ctrl->optype) { + case OP_OEMETIS: + MlevelEdgeBisection(ctrl, graph, tpwgts2, ubfactor); + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->SepTmr)); + ConstructMinCoverSeparator(ctrl, graph, ubfactor); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->SepTmr)); + + break; + case OP_ONMETIS: + MlevelNodeBisectionMultiple(ctrl, graph, tpwgts2, ubfactor); + + IFSET(ctrl->dbglvl, DBG_SEPINFO, printf("Nvtxs: %6d, [%6d %6d %6d]\n", graph->nvtxs, graph->pwgts[0], graph->pwgts[1], graph->pwgts[2])); + + break; + } + + /* Order the nodes in the separator */ + nbnd = graph->nbnd; + bndind = graph->bndind; + label = graph->label; + for (i=0; i<nbnd; i++) + order[label[bndind[i]]] = --lastvtx; + + SplitGraphOrder(ctrl, graph, &lgraph, &rgraph); + + /* Free the memory of the top level graph */ + GKfree(&graph->gdata, &graph->rdata, &graph->label, LTERM); + + if (rgraph.nvtxs > MMDSWITCH) + MlevelNestedDissection(ctrl, &rgraph, order, ubfactor, lastvtx); + else { + MMDOrder(ctrl, &rgraph, order, lastvtx); + GKfree(&rgraph.gdata, &rgraph.rdata, &rgraph.label, LTERM); + } + if (lgraph.nvtxs > MMDSWITCH) + MlevelNestedDissection(ctrl, &lgraph, order, ubfactor, lastvtx-rgraph.nvtxs); + else { + MMDOrder(ctrl, &lgraph, order, lastvtx-rgraph.nvtxs); + GKfree(&lgraph.gdata, &lgraph.rdata, &lgraph.label, LTERM); + } +} + + +/************************************************************************* +* This function takes a graph and produces a bisection of it +**************************************************************************/ +void MlevelNestedDissectionCC(CtrlType *ctrl, GraphType *graph, idxtype *order, float ubfactor, int lastvtx) +{ + int i, j, nvtxs, nbnd, tvwgt, tpwgts2[2], nsgraphs, ncmps, rnvtxs; + idxtype *label, *bndind; + idxtype *cptr, *cind; + GraphType *sgraphs; + + nvtxs = graph->nvtxs; + + /* Determine the weights of the partitions */ + tvwgt = idxsum(nvtxs, graph->vwgt); + tpwgts2[0] = tvwgt/2; + tpwgts2[1] = tvwgt-tpwgts2[0]; + + MlevelNodeBisectionMultiple(ctrl, graph, tpwgts2, ubfactor); + IFSET(ctrl->dbglvl, DBG_SEPINFO, printf("Nvtxs: %6d, [%6d %6d %6d]\n", graph->nvtxs, graph->pwgts[0], graph->pwgts[1], graph->pwgts[2])); + + /* Order the nodes in the separator */ + nbnd = graph->nbnd; + bndind = graph->bndind; + label = graph->label; + for (i=0; i<nbnd; i++) + order[label[bndind[i]]] = --lastvtx; + + cptr = idxmalloc(nvtxs+1, "MlevelNestedDissectionCC: cptr"); + cind = idxmalloc(nvtxs, "MlevelNestedDissectionCC: cind"); + ncmps = FindComponents(ctrl, graph, cptr, cind); + +/* + if (ncmps > 2) + printf("[%5d] has %3d components\n", nvtxs, ncmps); +*/ + + sgraphs = (GraphType *)GKmalloc(ncmps*sizeof(GraphType), "MlevelNestedDissectionCC: sgraphs"); + + nsgraphs = SplitGraphOrderCC(ctrl, graph, sgraphs, ncmps, cptr, cind); + + GKfree(&cptr, &cind, LTERM); + + /* Free the memory of the top level graph */ + GKfree(&graph->gdata, &graph->rdata, &graph->label, LTERM); + + /* Go and process the subgraphs */ + for (rnvtxs=i=0; i<nsgraphs; i++) { + if (sgraphs[i].adjwgt == NULL) { + MMDOrder(ctrl, sgraphs+i, order, lastvtx-rnvtxs); + GKfree(&sgraphs[i].gdata, &sgraphs[i].label, LTERM); + } + else { + MlevelNestedDissectionCC(ctrl, sgraphs+i, order, ubfactor, lastvtx-rnvtxs); + } + rnvtxs += sgraphs[i].nvtxs; + } + + free(sgraphs); +} + + + +/************************************************************************* +* This function performs multilevel bisection. It performs multiple +* bisections and selects the best. +**************************************************************************/ +void MlevelNodeBisectionMultiple(CtrlType *ctrl, GraphType *graph, int *tpwgts, float ubfactor) +{ + int i, nvtxs, cnvtxs, mincut, tmp; + GraphType *cgraph; + idxtype *bestwhere; + + if (ctrl->nseps == 1 || graph->nvtxs < (ctrl->oflags&OFLAG_COMPRESS ? 1000 : 2000)) { + MlevelNodeBisection(ctrl, graph, tpwgts, ubfactor); + return; + } + + nvtxs = graph->nvtxs; + + if (ctrl->oflags&OFLAG_COMPRESS) { /* Multiple separators at the original graph */ + bestwhere = idxmalloc(nvtxs, "MlevelNodeBisection2: bestwhere"); + mincut = nvtxs; + + for (i=ctrl->nseps; i>0; i--) { + MlevelNodeBisection(ctrl, graph, tpwgts, ubfactor); + + /* printf("%5d ", cgraph->mincut); */ + + if (graph->mincut < mincut) { + mincut = graph->mincut; + idxcopy(nvtxs, graph->where, bestwhere); + } + + GKfree(&graph->rdata, LTERM); + + if (mincut == 0) + break; + } + /* printf("[%5d]\n", mincut); */ + + Allocate2WayNodePartitionMemory(ctrl, graph); + idxcopy(nvtxs, bestwhere, graph->where); + free(bestwhere); + + Compute2WayNodePartitionParams(ctrl, graph); + } + else { /* Coarsen it a bit */ + ctrl->CoarsenTo = nvtxs-1; + + cgraph = Coarsen2Way(ctrl, graph); + + cnvtxs = cgraph->nvtxs; + + bestwhere = idxmalloc(cnvtxs, "MlevelNodeBisection2: bestwhere"); + mincut = nvtxs; + + for (i=ctrl->nseps; i>0; i--) { + ctrl->CType += 20; /* This is a hack. Look at coarsen.c */ + MlevelNodeBisection(ctrl, cgraph, tpwgts, ubfactor); + + /* printf("%5d ", cgraph->mincut); */ + + if (cgraph->mincut < mincut) { + mincut = cgraph->mincut; + idxcopy(cnvtxs, cgraph->where, bestwhere); + } + + GKfree(&cgraph->rdata, LTERM); + + if (mincut == 0) + break; + } + /* printf("[%5d]\n", mincut); */ + + Allocate2WayNodePartitionMemory(ctrl, cgraph); + idxcopy(cnvtxs, bestwhere, cgraph->where); + free(bestwhere); + + Compute2WayNodePartitionParams(ctrl, cgraph); + + Refine2WayNode(ctrl, graph, cgraph, ubfactor); + } + +} + +/************************************************************************* +* This function performs multilevel bisection +**************************************************************************/ +void MlevelNodeBisection(CtrlType *ctrl, GraphType *graph, int *tpwgts, float ubfactor) +{ + GraphType *cgraph; + + ctrl->CoarsenTo = graph->nvtxs/8; + if (ctrl->CoarsenTo > 100) + ctrl->CoarsenTo = 100; + else if (ctrl->CoarsenTo < 40) + ctrl->CoarsenTo = 40; + ctrl->maxvwgt = 1.5*((tpwgts[0]+tpwgts[1])/ctrl->CoarsenTo); + + cgraph = Coarsen2Way(ctrl, graph); + + switch (ctrl->IType) { + case IPART_GGPKL: + Init2WayPartition(ctrl, cgraph, tpwgts, ubfactor); + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->SepTmr)); + + Compute2WayPartitionParams(ctrl, cgraph); + ConstructSeparator(ctrl, cgraph, ubfactor); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->SepTmr)); + break; + case IPART_GGPKLNODE: + InitSeparator(ctrl, cgraph, ubfactor); + break; + } + + Refine2WayNode(ctrl, graph, cgraph, ubfactor); + +} + + + + +/************************************************************************* +* This function takes a graph and a bisection and splits it into two graphs. +* This function relies on the fact that adjwgt is all equal to 1. +**************************************************************************/ +void SplitGraphOrder(CtrlType *ctrl, GraphType *graph, GraphType *lgraph, GraphType *rgraph) +{ + int i, ii, j, k, l, istart, iend, mypart, nvtxs, snvtxs[3], snedges[3]; + idxtype *xadj, *vwgt, *adjncy, *adjwgt, *adjwgtsum, *label, *where, *bndptr, *bndind; + idxtype *sxadj[2], *svwgt[2], *sadjncy[2], *sadjwgt[2], *sadjwgtsum[2], *slabel[2]; + idxtype *rename; + idxtype *auxadjncy, *auxadjwgt; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->SplitTmr)); + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + adjwgtsum = graph->adjwgtsum; + label = graph->label; + where = graph->where; + bndptr = graph->bndptr; + bndind = graph->bndind; + ASSERT(bndptr != NULL); + + rename = idxwspacemalloc(ctrl, nvtxs); + + snvtxs[0] = snvtxs[1] = snvtxs[2] = snedges[0] = snedges[1] = snedges[2] = 0; + for (i=0; i<nvtxs; i++) { + k = where[i]; + rename[i] = snvtxs[k]++; + snedges[k] += xadj[i+1]-xadj[i]; + } + + SetUpSplitGraph(graph, lgraph, snvtxs[0], snedges[0]); + sxadj[0] = lgraph->xadj; + svwgt[0] = lgraph->vwgt; + sadjwgtsum[0] = lgraph->adjwgtsum; + sadjncy[0] = lgraph->adjncy; + sadjwgt[0] = lgraph->adjwgt; + slabel[0] = lgraph->label; + + SetUpSplitGraph(graph, rgraph, snvtxs[1], snedges[1]); + sxadj[1] = rgraph->xadj; + svwgt[1] = rgraph->vwgt; + sadjwgtsum[1] = rgraph->adjwgtsum; + sadjncy[1] = rgraph->adjncy; + sadjwgt[1] = rgraph->adjwgt; + slabel[1] = rgraph->label; + + /* Go and use bndptr to also mark the boundary nodes in the two partitions */ + for (ii=0; ii<graph->nbnd; ii++) { + i = bndind[ii]; + for (j=xadj[i]; j<xadj[i+1]; j++) + bndptr[adjncy[j]] = 1; + } + + snvtxs[0] = snvtxs[1] = snedges[0] = snedges[1] = 0; + sxadj[0][0] = sxadj[1][0] = 0; + for (i=0; i<nvtxs; i++) { + if ((mypart = where[i]) == 2) + continue; + + istart = xadj[i]; + iend = xadj[i+1]; + if (bndptr[i] == -1) { /* This is an interior vertex */ + auxadjncy = sadjncy[mypart] + snedges[mypart] - istart; + for(j=istart; j<iend; j++) + auxadjncy[j] = adjncy[j]; + snedges[mypart] += iend-istart; + } + else { + auxadjncy = sadjncy[mypart]; + l = snedges[mypart]; + for (j=istart; j<iend; j++) { + k = adjncy[j]; + if (where[k] == mypart) + auxadjncy[l++] = k; + } + snedges[mypart] = l; + } + + svwgt[mypart][snvtxs[mypart]] = vwgt[i]; + sadjwgtsum[mypart][snvtxs[mypart]] = snedges[mypart]-sxadj[mypart][snvtxs[mypart]]; + slabel[mypart][snvtxs[mypart]] = label[i]; + sxadj[mypart][++snvtxs[mypart]] = snedges[mypart]; + } + + for (mypart=0; mypart<2; mypart++) { + iend = snedges[mypart]; + idxset(iend, 1, sadjwgt[mypart]); + + auxadjncy = sadjncy[mypart]; + for (i=0; i<iend; i++) + auxadjncy[i] = rename[auxadjncy[i]]; + } + + lgraph->nvtxs = snvtxs[0]; + lgraph->nedges = snedges[0]; + rgraph->nvtxs = snvtxs[1]; + rgraph->nedges = snedges[1]; + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->SplitTmr)); + + idxwspacefree(ctrl, nvtxs); + +} + +/************************************************************************* +* This function uses MMD to order the graph. The vertices are numbered +* from lastvtx downwards +**************************************************************************/ +void MMDOrder(CtrlType *ctrl, GraphType *graph, idxtype *order, int lastvtx) +{ + int i, j, k, nvtxs, nofsub, firstvtx; + idxtype *xadj, *adjncy, *label; + idxtype *perm, *iperm, *head, *qsize, *list, *marker; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + + /* Relabel the vertices so that it starts from 1 */ + k = xadj[nvtxs]; + for (i=0; i<k; i++) + adjncy[i]++; + for (i=0; i<nvtxs+1; i++) + xadj[i]++; + + perm = idxmalloc(6*(nvtxs+5), "MMDOrder: perm"); + iperm = perm + nvtxs + 5; + head = iperm + nvtxs + 5; + qsize = head + nvtxs + 5; + list = qsize + nvtxs + 5; + marker = list + nvtxs + 5; + + genmmd(nvtxs, xadj, adjncy, iperm, perm, 1, head, qsize, list, marker, MAXIDX, &nofsub); + + label = graph->label; + firstvtx = lastvtx-nvtxs; + for (i=0; i<nvtxs; i++) + order[label[i]] = firstvtx+iperm[i]-1; + + free(perm); + + /* Relabel the vertices so that it starts from 0 */ + for (i=0; i<nvtxs+1; i++) + xadj[i]--; + k = xadj[nvtxs]; + for (i=0; i<k; i++) + adjncy[i]--; +} + + +/************************************************************************* +* This function takes a graph and a bisection and splits it into two graphs. +* It relies on the fact that adjwgt is all set to 1. +**************************************************************************/ +int SplitGraphOrderCC(CtrlType *ctrl, GraphType *graph, GraphType *sgraphs, int ncmps, idxtype *cptr, idxtype *cind) +{ + int i, ii, iii, j, k, l, istart, iend, mypart, nvtxs, snvtxs, snedges; + idxtype *xadj, *vwgt, *adjncy, *adjwgt, *adjwgtsum, *label, *where, *bndptr, *bndind; + idxtype *sxadj, *svwgt, *sadjncy, *sadjwgt, *sadjwgtsum, *slabel; + idxtype *rename; + idxtype *auxadjncy, *auxadjwgt; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->SplitTmr)); + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + adjwgtsum = graph->adjwgtsum; + label = graph->label; + where = graph->where; + bndptr = graph->bndptr; + bndind = graph->bndind; + ASSERT(bndptr != NULL); + + /* Go and use bndptr to also mark the boundary nodes in the two partitions */ + for (ii=0; ii<graph->nbnd; ii++) { + i = bndind[ii]; + for (j=xadj[i]; j<xadj[i+1]; j++) + bndptr[adjncy[j]] = 1; + } + + rename = idxwspacemalloc(ctrl, nvtxs); + + /* Go and split the graph a component at a time */ + for (iii=0; iii<ncmps; iii++) { + RandomPermute(cptr[iii+1]-cptr[iii], cind+cptr[iii], 0); + snvtxs = snedges = 0; + for (j=cptr[iii]; j<cptr[iii+1]; j++) { + i = cind[j]; + rename[i] = snvtxs++; + snedges += xadj[i+1]-xadj[i]; + } + + SetUpSplitGraph(graph, sgraphs+iii, snvtxs, snedges); + sxadj = sgraphs[iii].xadj; + svwgt = sgraphs[iii].vwgt; + sadjwgtsum = sgraphs[iii].adjwgtsum; + sadjncy = sgraphs[iii].adjncy; + sadjwgt = sgraphs[iii].adjwgt; + slabel = sgraphs[iii].label; + + snvtxs = snedges = sxadj[0] = 0; + for (ii=cptr[iii]; ii<cptr[iii+1]; ii++) { + i = cind[ii]; + + istart = xadj[i]; + iend = xadj[i+1]; + if (bndptr[i] == -1) { /* This is an interior vertex */ + auxadjncy = sadjncy + snedges - istart; + auxadjwgt = sadjwgt + snedges - istart; + for(j=istart; j<iend; j++) + auxadjncy[j] = adjncy[j]; + snedges += iend-istart; + } + else { + l = snedges; + for (j=istart; j<iend; j++) { + k = adjncy[j]; + if (where[k] != 2) + sadjncy[l++] = k; + } + snedges = l; + } + + svwgt[snvtxs] = vwgt[i]; + sadjwgtsum[snvtxs] = snedges-sxadj[snvtxs]; + slabel[snvtxs] = label[i]; + sxadj[++snvtxs] = snedges; + } + + idxset(snedges, 1, sadjwgt); + for (i=0; i<snedges; i++) + sadjncy[i] = rename[sadjncy[i]]; + + sgraphs[iii].nvtxs = snvtxs; + sgraphs[iii].nedges = snedges; + sgraphs[iii].ncon = 1; + + if (snvtxs < MMDSWITCH) + sgraphs[iii].adjwgt = NULL; /* A marker to call MMD on the driver */ + } + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->SplitTmr)); + + idxwspacefree(ctrl, nvtxs); + + return ncmps; + +} + + + + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/parmetis.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/parmetis.c new file mode 100644 index 0000000..d183082 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/parmetis.c @@ -0,0 +1,512 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * parmetis.c + * + * This file contains top level routines that are used by ParMETIS + * + * Started 10/14/97 + * George + * + * $Id: parmetis.c,v 1.2 2003/07/24 18:39:11 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function is the entry point for KMETIS with seed specification +* in options[7] +**************************************************************************/ +void METIS_PartGraphKway2(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, + int *options, int *edgecut, idxtype *part) +{ + int i; + float *tpwgts; + + tpwgts = fmalloc(*nparts, "KMETIS: tpwgts"); + for (i=0; i<*nparts; i++) + tpwgts[i] = 1.0/(1.0*(*nparts)); + + METIS_WPartGraphKway2(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, + tpwgts, options, edgecut, part); + + free(tpwgts); +} + + +/************************************************************************* +* This function is the entry point for KWMETIS with seed specification +* in options[7] +**************************************************************************/ +void METIS_WPartGraphKway2(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, + float *tpwgts, int *options, int *edgecut, idxtype *part) +{ + int i, j; + GraphType graph; + CtrlType ctrl; + + if (*numflag == 1) + Change2CNumbering(*nvtxs, xadj, adjncy); + + SetUpGraph(&graph, OP_KMETIS, *nvtxs, 1, xadj, adjncy, vwgt, adjwgt, *wgtflag); + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = KMETIS_CTYPE; + ctrl.IType = KMETIS_ITYPE; + ctrl.RType = KMETIS_RTYPE; + ctrl.dbglvl = KMETIS_DBGLVL; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + } + ctrl.optype = OP_KMETIS; + ctrl.CoarsenTo = 20*(*nparts); + ctrl.maxvwgt = 1.5*((graph.vwgt ? idxsum(*nvtxs, graph.vwgt) : (*nvtxs))/ctrl.CoarsenTo); + + InitRandom(options[7]); + + AllocateWorkSpace(&ctrl, &graph, *nparts); + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + *edgecut = MlevelKWayPartitioning(&ctrl, &graph, *nparts, part, tpwgts, 1.000); + + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); + + FreeWorkSpace(&ctrl, &graph); + + if (*numflag == 1) + Change2FNumbering(*nvtxs, xadj, adjncy, part); +} + + +/************************************************************************* +* This function is the entry point for the node ND code for ParMETIS +**************************************************************************/ +void METIS_NodeNDP(int nvtxs, idxtype *xadj, idxtype *adjncy, int npes, + int *options, idxtype *perm, idxtype *iperm, idxtype *sizes) +{ + int i, ii, j, l, wflag, nflag; + GraphType graph; + CtrlType ctrl; + idxtype *cptr, *cind; + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = ONMETIS_CTYPE; + ctrl.IType = ONMETIS_ITYPE; + ctrl.RType = ONMETIS_RTYPE; + ctrl.dbglvl = ONMETIS_DBGLVL; + ctrl.oflags = ONMETIS_OFLAGS; + ctrl.pfactor = ONMETIS_PFACTOR; + ctrl.nseps = ONMETIS_NSEPS; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + ctrl.oflags = options[OPTION_OFLAGS]; + ctrl.pfactor = options[OPTION_PFACTOR]; + ctrl.nseps = options[OPTION_NSEPS]; + } + if (ctrl.nseps < 1) + ctrl.nseps = 1; + + ctrl.optype = OP_ONMETIS; + ctrl.CoarsenTo = 100; + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + InitRandom(-1); + + if (ctrl.oflags&OFLAG_COMPRESS) { + /*============================================================ + * Compress the graph + ==============================================================*/ + cptr = idxmalloc(nvtxs+1, "ONMETIS: cptr"); + cind = idxmalloc(nvtxs, "ONMETIS: cind"); + + CompressGraph(&ctrl, &graph, nvtxs, xadj, adjncy, cptr, cind); + + if (graph.nvtxs >= COMPRESSION_FRACTION*(nvtxs)) { + ctrl.oflags--; /* We actually performed no compression */ + GKfree(&cptr, &cind, LTERM); + } + else if (2*graph.nvtxs < nvtxs && ctrl.nseps == 1) + ctrl.nseps = 2; + } + else { + SetUpGraph(&graph, OP_ONMETIS, nvtxs, 1, xadj, adjncy, NULL, NULL, 0); + } + + + /*============================================================= + * Do the nested dissection ordering + --=============================================================*/ + ctrl.maxvwgt = 1.5*(idxsum(graph.nvtxs, graph.vwgt)/ctrl.CoarsenTo); + AllocateWorkSpace(&ctrl, &graph, 2); + + idxset(2*npes-1, 0, sizes); + MlevelNestedDissectionP(&ctrl, &graph, iperm, graph.nvtxs, npes, 0, sizes); + + FreeWorkSpace(&ctrl, &graph); + + if (ctrl.oflags&OFLAG_COMPRESS) { /* Uncompress the ordering */ + if (graph.nvtxs < COMPRESSION_FRACTION*(nvtxs)) { + /* construct perm from iperm */ + for (i=0; i<graph.nvtxs; i++) + perm[iperm[i]] = i; + for (l=ii=0; ii<graph.nvtxs; ii++) { + i = perm[ii]; + for (j=cptr[i]; j<cptr[i+1]; j++) + iperm[cind[j]] = l++; + } + } + + GKfree(&cptr, &cind, LTERM); + } + + + for (i=0; i<nvtxs; i++) + perm[iperm[i]] = i; + + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); + +} + + + +/************************************************************************* +* This function takes a graph and produces a bisection of it +**************************************************************************/ +void MlevelNestedDissectionP(CtrlType *ctrl, GraphType *graph, idxtype *order, int lastvtx, + int npes, int cpos, idxtype *sizes) +{ + int i, j, nvtxs, nbnd, tvwgt, tpwgts2[2]; + idxtype *label, *bndind; + GraphType lgraph, rgraph; + float ubfactor; + + nvtxs = graph->nvtxs; + + if (nvtxs == 0) { + GKfree(&graph->gdata, &graph->rdata, &graph->label, LTERM); + return; + } + + /* Determine the weights of the partitions */ + tvwgt = idxsum(nvtxs, graph->vwgt); + tpwgts2[0] = tvwgt/2; + tpwgts2[1] = tvwgt-tpwgts2[0]; + + if (cpos >= npes-1) + ubfactor = ORDER_UNBALANCE_FRACTION; + else + ubfactor = 1.05; + + + MlevelNodeBisectionMultiple(ctrl, graph, tpwgts2, ubfactor); + + IFSET(ctrl->dbglvl, DBG_SEPINFO, printf("Nvtxs: %6d, [%6d %6d %6d]\n", graph->nvtxs, graph->pwgts[0], graph->pwgts[1], graph->pwgts[2])); + + if (cpos < npes-1) { + sizes[2*npes-2-cpos] = graph->pwgts[2]; + sizes[2*npes-2-(2*cpos+1)] = graph->pwgts[1]; + sizes[2*npes-2-(2*cpos+2)] = graph->pwgts[0]; + } + + /* Order the nodes in the separator */ + nbnd = graph->nbnd; + bndind = graph->bndind; + label = graph->label; + for (i=0; i<nbnd; i++) + order[label[bndind[i]]] = --lastvtx; + + SplitGraphOrder(ctrl, graph, &lgraph, &rgraph); + + /* Free the memory of the top level graph */ + GKfree(&graph->gdata, &graph->rdata, &graph->label, LTERM); + + if (rgraph.nvtxs > MMDSWITCH || 2*cpos+1 < npes-1) + MlevelNestedDissectionP(ctrl, &rgraph, order, lastvtx, npes, 2*cpos+1, sizes); + else { + MMDOrder(ctrl, &rgraph, order, lastvtx); + GKfree(&rgraph.gdata, &rgraph.rdata, &rgraph.label, LTERM); + } + if (lgraph.nvtxs > MMDSWITCH || 2*cpos+2 < npes-1) + MlevelNestedDissectionP(ctrl, &lgraph, order, lastvtx-rgraph.nvtxs, npes, 2*cpos+2, sizes); + else { + MMDOrder(ctrl, &lgraph, order, lastvtx-rgraph.nvtxs); + GKfree(&lgraph.gdata, &lgraph.rdata, &lgraph.label, LTERM); + } +} + + + + +/************************************************************************* +* This function is the entry point for ONWMETIS. It requires weights on the +* vertices. It is for the case that the matrix has been pre-compressed. +**************************************************************************/ +void METIS_NodeComputeSeparator(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *options, int *sepsize, idxtype *part) +{ + int i, j, tvwgt, tpwgts[2]; + GraphType graph; + CtrlType ctrl; + + SetUpGraph(&graph, OP_ONMETIS, *nvtxs, 1, xadj, adjncy, vwgt, adjwgt, 3); + tvwgt = idxsum(*nvtxs, graph.vwgt); + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = ONMETIS_CTYPE; + ctrl.IType = ONMETIS_ITYPE; + ctrl.RType = ONMETIS_RTYPE; + ctrl.dbglvl = ONMETIS_DBGLVL; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + } + + ctrl.oflags = 0; + ctrl.pfactor = 0; + ctrl.nseps = 1; + ctrl.optype = OP_ONMETIS; + ctrl.CoarsenTo = amin(100, *nvtxs-1); + ctrl.maxvwgt = 1.5*tvwgt/ctrl.CoarsenTo; + + InitRandom(options[7]); + + AllocateWorkSpace(&ctrl, &graph, 2); + + /*============================================================ + * Perform the bisection + *============================================================*/ + tpwgts[0] = tvwgt/2; + tpwgts[1] = tvwgt-tpwgts[0]; + + MlevelNodeBisectionMultiple(&ctrl, &graph, tpwgts, 1.05); + + *sepsize = graph.pwgts[2]; + idxcopy(*nvtxs, graph.where, part); + + GKfree(&graph.gdata, &graph.rdata, &graph.label, LTERM); + + + FreeWorkSpace(&ctrl, &graph); + +} + + + +/************************************************************************* +* This function is the entry point for ONWMETIS. It requires weights on the +* vertices. It is for the case that the matrix has been pre-compressed. +**************************************************************************/ +void METIS_EdgeComputeSeparator(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *options, int *sepsize, idxtype *part) +{ + int i, j, tvwgt, tpwgts[2]; + GraphType graph; + CtrlType ctrl; + + SetUpGraph(&graph, OP_ONMETIS, *nvtxs, 1, xadj, adjncy, vwgt, adjwgt, 3); + tvwgt = idxsum(*nvtxs, graph.vwgt); + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = ONMETIS_CTYPE; + ctrl.IType = ONMETIS_ITYPE; + ctrl.RType = ONMETIS_RTYPE; + ctrl.dbglvl = ONMETIS_DBGLVL; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + } + + ctrl.oflags = 0; + ctrl.pfactor = 0; + ctrl.nseps = 1; + ctrl.optype = OP_OEMETIS; + ctrl.CoarsenTo = amin(100, *nvtxs-1); + ctrl.maxvwgt = 1.5*tvwgt/ctrl.CoarsenTo; + + InitRandom(options[7]); + + AllocateWorkSpace(&ctrl, &graph, 2); + + /*============================================================ + * Perform the bisection + *============================================================*/ + tpwgts[0] = tvwgt/2; + tpwgts[1] = tvwgt-tpwgts[0]; + + MlevelEdgeBisection(&ctrl, &graph, tpwgts, 1.05); + ConstructMinCoverSeparator(&ctrl, &graph, 1.05); + + *sepsize = graph.pwgts[2]; + idxcopy(*nvtxs, graph.where, part); + + GKfree(&graph.gdata, &graph.rdata, &graph.label, LTERM); + + + FreeWorkSpace(&ctrl, &graph); + +} + + +/************************************************************************* +* This function is the entry point for PWMETIS that accepts exact weights +* for the target partitions +**************************************************************************/ +void METIS_mCPartGraphRecursive2(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, + idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, + float *tpwgts, int *options, int *edgecut, idxtype *part) +{ + int i, j; + GraphType graph; + CtrlType ctrl; + float *mytpwgts; + float avgwgt; + + if (*numflag == 1) + Change2CNumbering(*nvtxs, xadj, adjncy); + + SetUpGraph(&graph, OP_PMETIS, *nvtxs, *ncon, xadj, adjncy, vwgt, adjwgt, *wgtflag); + graph.npwgts = NULL; + mytpwgts = fmalloc(*nparts, "mytpwgts"); + scopy(*nparts, tpwgts, mytpwgts); + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = McPMETIS_CTYPE; + ctrl.IType = McPMETIS_ITYPE; + ctrl.RType = McPMETIS_RTYPE; + ctrl.dbglvl = McPMETIS_DBGLVL; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + } + ctrl.optype = OP_PMETIS; + ctrl.CoarsenTo = 100; + + ctrl.nmaxvwgt = 1.5/(1.0*ctrl.CoarsenTo); + + InitRandom(options[7]); + + AllocateWorkSpace(&ctrl, &graph, *nparts); + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + ASSERT(CheckGraph(&graph)); + *edgecut = MCMlevelRecursiveBisection2(&ctrl, &graph, *nparts, mytpwgts, part, 1.000, 0); + +/* +{ +idxtype wgt[2048], minwgt, maxwgt, sumwgt; + +printf("nvtxs: %d, nparts: %d, ncon: %d\n", graph.nvtxs, *nparts, *ncon); +for (i=0; i<(*nparts)*(*ncon); i++) + wgt[i] = 0; +for (i=0; i<graph.nvtxs; i++) + for (j=0; j<*ncon; j++) + wgt[part[i]*(*ncon)+j] += vwgt[i*(*ncon)+j]; + +for (j=0; j<*ncon; j++) { + minwgt = maxwgt = sumwgt = 0; + for (i=0; i<(*nparts); i++) { + minwgt = (wgt[i*(*ncon)+j] < wgt[minwgt*(*ncon)+j]) ? i : minwgt; + maxwgt = (wgt[i*(*ncon)+j] > wgt[maxwgt*(*ncon)+j]) ? i : maxwgt; + sumwgt += wgt[i*(*ncon)+j]; + } + avgwgt = (float)sumwgt / (float)*nparts; + printf("min: %5d, max: %5d, avg: %5.2f, balance: %6.3f\n", wgt[minwgt*(*ncon)+j], wgt[maxwgt*(*ncon)+j], avgwgt, (float)wgt[maxwgt*(*ncon)+j] / avgwgt); +} +printf("\n"); +} +*/ + + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); + + FreeWorkSpace(&ctrl, &graph); + GKfree((void *)&mytpwgts, LTERM); + + if (*numflag == 1) + Change2FNumbering(*nvtxs, xadj, adjncy, part); +} + + + +/************************************************************************* +* This function takes a graph and produces a bisection of it +**************************************************************************/ +int MCMlevelRecursiveBisection2(CtrlType *ctrl, GraphType *graph, int nparts, + float *tpwgts, idxtype *part, float ubfactor, int fpart) +{ + int i, nvtxs, cut; + float wsum, tpwgts2[2]; + idxtype *label, *where; + GraphType lgraph, rgraph; + + nvtxs = graph->nvtxs; + if (nvtxs == 0) + return 0; + + /* Determine the weights of the partitions */ + tpwgts2[0] = ssum(nparts/2, tpwgts); + tpwgts2[1] = 1.0-tpwgts2[0]; + + MCMlevelEdgeBisection(ctrl, graph, tpwgts2, ubfactor); + cut = graph->mincut; + + label = graph->label; + where = graph->where; + for (i=0; i<nvtxs; i++) + part[label[i]] = where[i] + fpart; + + if (nparts > 2) + SplitGraphPart(ctrl, graph, &lgraph, &rgraph); + + /* Free the memory of the top level graph */ + GKfree(&graph->gdata, &graph->nvwgt, &graph->rdata, &graph->label, &graph->npwgts, LTERM); + + /* Scale the fractions in the tpwgts according to the true weight */ + wsum = ssum(nparts/2, tpwgts); + sscale(nparts/2, 1.0/wsum, tpwgts); + sscale(nparts-nparts/2, 1.0/(1.0-wsum), tpwgts+nparts/2); + + /* Do the recursive call */ + if (nparts > 3) { + cut += MCMlevelRecursiveBisection2(ctrl, &lgraph, nparts/2, tpwgts, part, ubfactor, fpart); + cut += MCMlevelRecursiveBisection2(ctrl, &rgraph, nparts-nparts/2, tpwgts+nparts/2, part, ubfactor, fpart+nparts/2); + } + else if (nparts == 3) { + cut += MCMlevelRecursiveBisection2(ctrl, &rgraph, nparts-nparts/2, tpwgts+nparts/2, part, ubfactor, fpart+nparts/2); + GKfree(&lgraph.gdata, &lgraph.nvwgt, &lgraph.label, LTERM); + } + + return cut; + +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/pmetis.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/pmetis.c new file mode 100644 index 0000000..9212cd7 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/pmetis.c @@ -0,0 +1,341 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * pmetis.c + * + * This file contains the top level routines for the multilevel recursive + * bisection algorithm PMETIS. + * + * Started 7/24/97 + * George + * + * $Id: pmetis.c,v 1.1 2003/07/16 15:55:16 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function is the entry point for PMETIS +**************************************************************************/ +void METIS_PartGraphRecursive(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, + int *options, int *edgecut, idxtype *part) +{ + int i; + float *tpwgts; + + tpwgts = fmalloc(*nparts, "KMETIS: tpwgts"); + for (i=0; i<*nparts; i++) + tpwgts[i] = 1.0/(1.0*(*nparts)); + + METIS_WPartGraphRecursive(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, + tpwgts, options, edgecut, part); + + free(tpwgts); +} + + + +/************************************************************************* +* This function is the entry point for PWMETIS that accepts exact weights +* for the target partitions +**************************************************************************/ +void METIS_WPartGraphRecursive(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, + float *tpwgts, int *options, int *edgecut, idxtype *part) +{ + int i, j; + GraphType graph; + CtrlType ctrl; + float *mytpwgts; + + if (*numflag == 1) + Change2CNumbering(*nvtxs, xadj, adjncy); + + SetUpGraph(&graph, OP_PMETIS, *nvtxs, 1, xadj, adjncy, vwgt, adjwgt, *wgtflag); + + if (options[0] == 0) { /* Use the default parameters */ + ctrl.CType = PMETIS_CTYPE; + ctrl.IType = PMETIS_ITYPE; + ctrl.RType = PMETIS_RTYPE; + ctrl.dbglvl = PMETIS_DBGLVL; + } + else { + ctrl.CType = options[OPTION_CTYPE]; + ctrl.IType = options[OPTION_ITYPE]; + ctrl.RType = options[OPTION_RTYPE]; + ctrl.dbglvl = options[OPTION_DBGLVL]; + } + ctrl.optype = OP_PMETIS; + ctrl.CoarsenTo = 20; + ctrl.maxvwgt = 1.5*(idxsum(*nvtxs, graph.vwgt)/ctrl.CoarsenTo); + + mytpwgts = fmalloc(*nparts, "PWMETIS: mytpwgts"); + for (i=0; i<*nparts; i++) + mytpwgts[i] = tpwgts[i]; + + InitRandom(-1); + + AllocateWorkSpace(&ctrl, &graph, *nparts); + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + *edgecut = MlevelRecursiveBisection(&ctrl, &graph, *nparts, part, mytpwgts, 1.000, 0); + + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); + + FreeWorkSpace(&ctrl, &graph); + free(mytpwgts); + + if (*numflag == 1) + Change2FNumbering(*nvtxs, xadj, adjncy, part); +} + + + +/************************************************************************* +* This function takes a graph and produces a bisection of it +**************************************************************************/ +int MlevelRecursiveBisection(CtrlType *ctrl, GraphType *graph, int nparts, idxtype *part, float *tpwgts, float ubfactor, int fpart) +{ + int i, j, nvtxs, cut, tvwgt, tpwgts2[2]; + idxtype *label, *where; + GraphType lgraph, rgraph; + float wsum; + + nvtxs = graph->nvtxs; + if (nvtxs == 0) { + printf("\t***Cannot bisect a graph with 0 vertices!\n\t***You are trying to partition a graph into too many parts!\n"); + return 0; + } + + /* Determine the weights of the partitions */ + tvwgt = idxsum(nvtxs, graph->vwgt); + tpwgts2[0] = tvwgt*ssum(nparts/2, tpwgts); + tpwgts2[1] = tvwgt-tpwgts2[0]; + + MlevelEdgeBisection(ctrl, graph, tpwgts2, ubfactor); + cut = graph->mincut; + + /* printf("%5d %5d %5d [%5d %f]\n", tpwgts2[0], tpwgts2[1], cut, tvwgt, ssum(nparts/2, tpwgts));*/ + + label = graph->label; + where = graph->where; + for (i=0; i<nvtxs; i++) + part[label[i]] = where[i] + fpart; + + if (nparts > 2) { + SplitGraphPart(ctrl, graph, &lgraph, &rgraph); + /* printf("%d %d\n", lgraph.nvtxs, rgraph.nvtxs); */ + } + + + /* Free the memory of the top level graph */ + GKfree(&graph->gdata, &graph->rdata, &graph->label, LTERM); + + /* Scale the fractions in the tpwgts according to the true weight */ + wsum = ssum(nparts/2, tpwgts); + sscale(nparts/2, 1.0/wsum, tpwgts); + sscale(nparts-nparts/2, 1.0/(1.0-wsum), tpwgts+nparts/2); + /* + for (i=0; i<nparts; i++) + printf("%5.3f ", tpwgts[i]); + printf("[%5.3f]\n", wsum); + */ + + /* Do the recursive call */ + if (nparts > 3) { + cut += MlevelRecursiveBisection(ctrl, &lgraph, nparts/2, part, tpwgts, ubfactor, fpart); + cut += MlevelRecursiveBisection(ctrl, &rgraph, nparts-nparts/2, part, tpwgts+nparts/2, ubfactor, fpart+nparts/2); + } + else if (nparts == 3) { + cut += MlevelRecursiveBisection(ctrl, &rgraph, nparts-nparts/2, part, tpwgts+nparts/2, ubfactor, fpart+nparts/2); + GKfree(&lgraph.gdata, &lgraph.label, LTERM); + } + + return cut; + +} + + +/************************************************************************* +* This function performs multilevel bisection +**************************************************************************/ +void MlevelEdgeBisection(CtrlType *ctrl, GraphType *graph, int *tpwgts, float ubfactor) +{ + GraphType *cgraph; + + cgraph = Coarsen2Way(ctrl, graph); + + Init2WayPartition(ctrl, cgraph, tpwgts, ubfactor); + + Refine2Way(ctrl, graph, cgraph, tpwgts, ubfactor); + +/* + IsConnectedSubdomain(ctrl, graph, 0); + IsConnectedSubdomain(ctrl, graph, 1); +*/ +} + + + + +/************************************************************************* +* This function takes a graph and a bisection and splits it into two graphs. +**************************************************************************/ +void SplitGraphPart(CtrlType *ctrl, GraphType *graph, GraphType *lgraph, GraphType *rgraph) +{ + int i, j, k, kk, l, istart, iend, mypart, nvtxs, ncon, snvtxs[2], snedges[2], sum; + idxtype *xadj, *vwgt, *adjncy, *adjwgt, *adjwgtsum, *label, *where, *bndptr; + idxtype *sxadj[2], *svwgt[2], *sadjncy[2], *sadjwgt[2], *sadjwgtsum[2], *slabel[2]; + idxtype *rename; + idxtype *auxadjncy, *auxadjwgt; + float *nvwgt, *snvwgt[2], *npwgts; + + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->SplitTmr)); + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + vwgt = graph->vwgt; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + adjwgtsum = graph->adjwgtsum; + label = graph->label; + where = graph->where; + bndptr = graph->bndptr; + npwgts = graph->npwgts; + + ASSERT(bndptr != NULL); + + rename = idxwspacemalloc(ctrl, nvtxs); + + snvtxs[0] = snvtxs[1] = snedges[0] = snedges[1] = 0; + for (i=0; i<nvtxs; i++) { + k = where[i]; + rename[i] = snvtxs[k]++; + snedges[k] += xadj[i+1]-xadj[i]; + } + + SetUpSplitGraph(graph, lgraph, snvtxs[0], snedges[0]); + sxadj[0] = lgraph->xadj; + svwgt[0] = lgraph->vwgt; + snvwgt[0] = lgraph->nvwgt; + sadjwgtsum[0] = lgraph->adjwgtsum; + sadjncy[0] = lgraph->adjncy; + sadjwgt[0] = lgraph->adjwgt; + slabel[0] = lgraph->label; + + SetUpSplitGraph(graph, rgraph, snvtxs[1], snedges[1]); + sxadj[1] = rgraph->xadj; + svwgt[1] = rgraph->vwgt; + snvwgt[1] = rgraph->nvwgt; + sadjwgtsum[1] = rgraph->adjwgtsum; + sadjncy[1] = rgraph->adjncy; + sadjwgt[1] = rgraph->adjwgt; + slabel[1] = rgraph->label; + + snvtxs[0] = snvtxs[1] = snedges[0] = snedges[1] = 0; + sxadj[0][0] = sxadj[1][0] = 0; + for (i=0; i<nvtxs; i++) { + mypart = where[i]; + sum = adjwgtsum[i]; + + istart = xadj[i]; + iend = xadj[i+1]; + if (bndptr[i] == -1) { /* This is an interior vertex */ + auxadjncy = sadjncy[mypart] + snedges[mypart] - istart; + auxadjwgt = sadjwgt[mypart] + snedges[mypart] - istart; + for(j=istart; j<iend; j++) { + auxadjncy[j] = adjncy[j]; + auxadjwgt[j] = adjwgt[j]; + } + snedges[mypart] += iend-istart; + } + else { + auxadjncy = sadjncy[mypart]; + auxadjwgt = sadjwgt[mypart]; + l = snedges[mypart]; + for (j=istart; j<iend; j++) { + k = adjncy[j]; + if (where[k] == mypart) { + auxadjncy[l] = k; + auxadjwgt[l++] = adjwgt[j]; + } + else { + sum -= adjwgt[j]; + } + } + snedges[mypart] = l; + } + + if (ncon == 1) + svwgt[mypart][snvtxs[mypart]] = vwgt[i]; + else { + for (kk=0; kk<ncon; kk++) + snvwgt[mypart][snvtxs[mypart]*ncon+kk] = nvwgt[i*ncon+kk]/npwgts[mypart*ncon+kk]; + } + + sadjwgtsum[mypart][snvtxs[mypart]] = sum; + slabel[mypart][snvtxs[mypart]] = label[i]; + sxadj[mypart][++snvtxs[mypart]] = snedges[mypart]; + } + + for (mypart=0; mypart<2; mypart++) { + iend = sxadj[mypart][snvtxs[mypart]]; + auxadjncy = sadjncy[mypart]; + for (i=0; i<iend; i++) + auxadjncy[i] = rename[auxadjncy[i]]; + } + + lgraph->nedges = snedges[0]; + rgraph->nedges = snedges[1]; + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->SplitTmr)); + + idxwspacefree(ctrl, nvtxs); +} + + +/************************************************************************* +* Setup the various arrays for the splitted graph +**************************************************************************/ +void SetUpSplitGraph(GraphType *graph, GraphType *sgraph, int snvtxs, int snedges) +{ + InitGraph(sgraph); + sgraph->nvtxs = snvtxs; + sgraph->nedges = snedges; + sgraph->ncon = graph->ncon; + + /* Allocate memory for the splitted graph */ + if (graph->ncon == 1) { + sgraph->gdata = idxmalloc(4*snvtxs+1 + 2*snedges, "SetUpSplitGraph: gdata"); + + sgraph->xadj = sgraph->gdata; + sgraph->vwgt = sgraph->gdata + snvtxs+1; + sgraph->adjwgtsum = sgraph->gdata + 2*snvtxs+1; + sgraph->cmap = sgraph->gdata + 3*snvtxs+1; + sgraph->adjncy = sgraph->gdata + 4*snvtxs+1; + sgraph->adjwgt = sgraph->gdata + 4*snvtxs+1 + snedges; + } + else { + sgraph->gdata = idxmalloc(3*snvtxs+1 + 2*snedges, "SetUpSplitGraph: gdata"); + + sgraph->xadj = sgraph->gdata; + sgraph->adjwgtsum = sgraph->gdata + snvtxs+1; + sgraph->cmap = sgraph->gdata + 2*snvtxs+1; + sgraph->adjncy = sgraph->gdata + 3*snvtxs+1; + sgraph->adjwgt = sgraph->gdata + 3*snvtxs+1 + snedges; + + sgraph->nvwgt = fmalloc(graph->ncon*snvtxs, "SetUpSplitGraph: nvwgt"); + } + + sgraph->label = idxmalloc(snvtxs, "SetUpSplitGraph: sgraph->label"); +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/pqueue.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/pqueue.c new file mode 100644 index 0000000..6a1986f --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/pqueue.c @@ -0,0 +1,579 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * pqueue.c + * + * This file contains functions for manipulating the bucket list + * representation of the gains associated with each vertex in a graph. + * These functions are used by the refinement algorithms + * + * Started 9/2/94 + * George + * + * $Id: pqueue.c,v 1.1 2003/07/16 15:55:16 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function initializes the data structures of the priority queue +**************************************************************************/ +void PQueueInit(CtrlType *ctrl, PQueueType *queue, int maxnodes, int maxgain) +{ + int i, j, ncore; + + queue->nnodes = 0; + queue->maxnodes = maxnodes; + + queue->buckets = NULL; + queue->nodes = NULL; + queue->heap = NULL; + queue->locator = NULL; + + if (maxgain > PLUS_GAINSPAN || maxnodes < 500) + queue->type = 2; + else + queue->type = 1; + + if (queue->type == 1) { + queue->pgainspan = amin(PLUS_GAINSPAN, maxgain); + queue->ngainspan = amin(NEG_GAINSPAN, maxgain); + + j = queue->ngainspan+queue->pgainspan+1; + + ncore = 2 + (sizeof(ListNodeType)/sizeof(idxtype))*maxnodes + (sizeof(ListNodeType *)/sizeof(idxtype))*j; + + if (WspaceAvail(ctrl) > ncore) { + queue->nodes = (ListNodeType *)idxwspacemalloc(ctrl, (sizeof(ListNodeType)/sizeof(idxtype))*maxnodes); + queue->buckets = (ListNodeType **)idxwspacemalloc(ctrl, (sizeof(ListNodeType *)/sizeof(idxtype))*j); + queue->mustfree = 0; + } + else { /* Not enough memory in the wspace, allocate it */ + queue->nodes = (ListNodeType *)idxmalloc((sizeof(ListNodeType)/sizeof(idxtype))*maxnodes, "PQueueInit: queue->nodes"); + queue->buckets = (ListNodeType **)idxmalloc((sizeof(ListNodeType *)/sizeof(idxtype))*j, "PQueueInit: queue->buckets"); + queue->mustfree = 1; + } + + for (i=0; i<maxnodes; i++) + queue->nodes[i].id = i; + + for (i=0; i<j; i++) + queue->buckets[i] = NULL; + + queue->buckets += queue->ngainspan; /* Advance buckets by the ngainspan proper indexing */ + queue->maxgain = -queue->ngainspan; + } + else { + queue->heap = (KeyValueType *)idxwspacemalloc(ctrl, (sizeof(KeyValueType)/sizeof(idxtype))*maxnodes); + queue->locator = idxwspacemalloc(ctrl, maxnodes); + idxset(maxnodes, -1, queue->locator); + } + +} + + +/************************************************************************* +* This function resets the buckets +**************************************************************************/ +void PQueueReset(PQueueType *queue) +{ + int i, j; + queue->nnodes = 0; + + if (queue->type == 1) { + queue->maxgain = -queue->ngainspan; + + j = queue->ngainspan+queue->pgainspan+1; + queue->buckets -= queue->ngainspan; + for (i=0; i<j; i++) + queue->buckets[i] = NULL; + queue->buckets += queue->ngainspan; + } + else { + idxset(queue->maxnodes, -1, queue->locator); + } + +} + + +/************************************************************************* +* This function frees the buckets +**************************************************************************/ +void PQueueFree(CtrlType *ctrl, PQueueType *queue) +{ + + if (queue->type == 1) { + if (queue->mustfree) { + queue->buckets -= queue->ngainspan; + GKfree(&queue->nodes, &queue->buckets, LTERM); + } + else { + idxwspacefree(ctrl, sizeof(ListNodeType *)*(queue->ngainspan+queue->pgainspan+1)/sizeof(idxtype)); + idxwspacefree(ctrl, sizeof(ListNodeType)*queue->maxnodes/sizeof(idxtype)); + } + } + else { + idxwspacefree(ctrl, sizeof(KeyValueType)*queue->maxnodes/sizeof(idxtype)); + idxwspacefree(ctrl, queue->maxnodes); + } + + queue->maxnodes = 0; +} + + +/************************************************************************* +* This function returns the number of nodes in the queue +**************************************************************************/ +int PQueueGetSize(PQueueType *queue) +{ + return queue->nnodes; +} + + +/************************************************************************* +* This function adds a node of certain gain into a partition +**************************************************************************/ +int PQueueInsert(PQueueType *queue, int node, int gain) +{ + int i, j, k; + idxtype *locator; + ListNodeType *newnode; + KeyValueType *heap; + + if (queue->type == 1) { + ASSERT(gain >= -queue->ngainspan && gain <= queue->pgainspan); + + /* Allocate and add the node */ + queue->nnodes++; + newnode = queue->nodes + node; + + /* Attach this node in the doubly-linked list */ + newnode->next = queue->buckets[gain]; + newnode->prev = NULL; + if (newnode->next != NULL) + newnode->next->prev = newnode; + queue->buckets[gain] = newnode; + + if (queue->maxgain < gain) + queue->maxgain = gain; + } + else { + ASSERT(CheckHeap(queue)); + + heap = queue->heap; + locator = queue->locator; + + ASSERT(locator[node] == -1); + + i = queue->nnodes++; + while (i > 0) { + j = (i-1)/2; + if (heap[j].key < gain) { + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else + break; + } + ASSERT(i >= 0); + heap[i].key = gain; + heap[i].val = node; + locator[node] = i; + + ASSERT(CheckHeap(queue)); + } + + return 0; +} + + +/************************************************************************* +* This function deletes a node from a partition and reinserts it with +* an updated gain +**************************************************************************/ +int PQueueDelete(PQueueType *queue, int node, int gain) +{ + int i, j, newgain, oldgain; + idxtype *locator; + ListNodeType *newnode, **buckets; + KeyValueType *heap; + + if (queue->type == 1) { + ASSERT(gain >= -queue->ngainspan && gain <= queue->pgainspan); + ASSERT(queue->nnodes > 0); + + buckets = queue->buckets; + queue->nnodes--; + newnode = queue->nodes+node; + + /* Remove newnode from the doubly-linked list */ + if (newnode->prev != NULL) + newnode->prev->next = newnode->next; + else + buckets[gain] = newnode->next; + if (newnode->next != NULL) + newnode->next->prev = newnode->prev; + + if (buckets[gain] == NULL && gain == queue->maxgain) { + if (queue->nnodes == 0) + queue->maxgain = -queue->ngainspan; + else + for (; buckets[queue->maxgain]==NULL; queue->maxgain--); + } + } + else { /* Heap Priority Queue */ + heap = queue->heap; + locator = queue->locator; + + ASSERT(locator[node] != -1); + ASSERT(heap[locator[node]].val == node); + + ASSERT(CheckHeap(queue)); + + i = locator[node]; + locator[node] = -1; + + if (--queue->nnodes > 0 && heap[queue->nnodes].val != node) { + node = heap[queue->nnodes].val; + newgain = heap[queue->nnodes].key; + oldgain = heap[i].key; + + if (oldgain < newgain) { /* Filter-up */ + while (i > 0) { + j = (i-1)>>1; + if (heap[j].key < newgain) { + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else + break; + } + } + else { /* Filter down */ + while ((j=2*i+1) < queue->nnodes) { + if (heap[j].key > newgain) { + if (j+1 < queue->nnodes && heap[j+1].key > heap[j].key) + j = j+1; + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else if (j+1 < queue->nnodes && heap[j+1].key > newgain) { + j = j+1; + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else + break; + } + } + + heap[i].key = newgain; + heap[i].val = node; + locator[node] = i; + } + + ASSERT(CheckHeap(queue)); + } + + return 0; +} + + + +/************************************************************************* +* This function deletes a node from a partition and reinserts it with +* an updated gain +**************************************************************************/ +int PQueueUpdate(PQueueType *queue, int node, int oldgain, int newgain) +{ + int i, j; + idxtype *locator; + ListNodeType *newnode; + KeyValueType *heap; + + if (oldgain == newgain) + return 0; + + if (queue->type == 1) { + /* First delete the node and then insert it */ + PQueueDelete(queue, node, oldgain); + return PQueueInsert(queue, node, newgain); + } + else { /* Heap Priority Queue */ + heap = queue->heap; + locator = queue->locator; + + ASSERT(locator[node] != -1); + ASSERT(heap[locator[node]].val == node); + ASSERT(heap[locator[node]].key == oldgain); + ASSERT(CheckHeap(queue)); + + i = locator[node]; + + if (oldgain < newgain) { /* Filter-up */ + while (i > 0) { + j = (i-1)>>1; + if (heap[j].key < newgain) { + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else + break; + } + } + else { /* Filter down */ + while ((j=2*i+1) < queue->nnodes) { + if (heap[j].key > newgain) { + if (j+1 < queue->nnodes && heap[j+1].key > heap[j].key) + j = j+1; + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else if (j+1 < queue->nnodes && heap[j+1].key > newgain) { + j = j+1; + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else + break; + } + } + + heap[i].key = newgain; + heap[i].val = node; + locator[node] = i; + + ASSERT(CheckHeap(queue)); + } + + return 0; +} + + + +/************************************************************************* +* This function deletes a node from a partition and reinserts it with +* an updated gain +**************************************************************************/ +void PQueueUpdateUp(PQueueType *queue, int node, int oldgain, int newgain) +{ + int i, j; + idxtype *locator; + ListNodeType *newnode, **buckets; + KeyValueType *heap; + + if (oldgain == newgain) + return; + + if (queue->type == 1) { + ASSERT(oldgain >= -queue->ngainspan && oldgain <= queue->pgainspan); + ASSERT(newgain >= -queue->ngainspan && newgain <= queue->pgainspan); + ASSERT(queue->nnodes > 0); + + buckets = queue->buckets; + newnode = queue->nodes+node; + + /* First delete the node */ + if (newnode->prev != NULL) + newnode->prev->next = newnode->next; + else + buckets[oldgain] = newnode->next; + if (newnode->next != NULL) + newnode->next->prev = newnode->prev; + + /* Attach this node in the doubly-linked list */ + newnode->next = buckets[newgain]; + newnode->prev = NULL; + if (newnode->next != NULL) + newnode->next->prev = newnode; + buckets[newgain] = newnode; + + if (queue->maxgain < newgain) + queue->maxgain = newgain; + } + else { /* Heap Priority Queue */ + heap = queue->heap; + locator = queue->locator; + + ASSERT(locator[node] != -1); + ASSERT(heap[locator[node]].val == node); + ASSERT(heap[locator[node]].key == oldgain); + ASSERT(CheckHeap(queue)); + + + /* Here we are just filtering up since the newgain is greater than the oldgain */ + i = locator[node]; + while (i > 0) { + j = (i-1)>>1; + if (heap[j].key < newgain) { + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else + break; + } + + heap[i].key = newgain; + heap[i].val = node; + locator[node] = i; + + ASSERT(CheckHeap(queue)); + } + +} + + +/************************************************************************* +* This function returns the vertex with the largest gain from a partition +* and removes the node from the bucket list +**************************************************************************/ +int PQueueGetMax(PQueueType *queue) +{ + int vtx, i, j, gain, node; + idxtype *locator; + ListNodeType *tptr; + KeyValueType *heap; + + if (queue->nnodes == 0) + return -1; + + queue->nnodes--; + + if (queue->type == 1) { + tptr = queue->buckets[queue->maxgain]; + queue->buckets[queue->maxgain] = tptr->next; + if (tptr->next != NULL) { + tptr->next->prev = NULL; + } + else { + if (queue->nnodes == 0) { + queue->maxgain = -queue->ngainspan; + } + else + for (; queue->buckets[queue->maxgain]==NULL; queue->maxgain--); + } + + return tptr->id; + } + else { + heap = queue->heap; + locator = queue->locator; + + vtx = heap[0].val; + locator[vtx] = -1; + + if ((i = queue->nnodes) > 0) { + gain = heap[i].key; + node = heap[i].val; + i = 0; + while ((j=2*i+1) < queue->nnodes) { + if (heap[j].key > gain) { + if (j+1 < queue->nnodes && heap[j+1].key > heap[j].key) + j = j+1; + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else if (j+1 < queue->nnodes && heap[j+1].key > gain) { + j = j+1; + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else + break; + } + + heap[i].key = gain; + heap[i].val = node; + locator[node] = i; + } + + ASSERT(CheckHeap(queue)); + return vtx; + } +} + + +/************************************************************************* +* This function returns the vertex with the largest gain from a partition +**************************************************************************/ +int PQueueSeeMax(PQueueType *queue) +{ + int vtx; + + if (queue->nnodes == 0) + return -1; + + if (queue->type == 1) + vtx = queue->buckets[queue->maxgain]->id; + else + vtx = queue->heap[0].val; + + return vtx; +} + + +/************************************************************************* +* This function returns the vertex with the largest gain from a partition +**************************************************************************/ +int PQueueGetKey(PQueueType *queue) +{ + int key; + + if (queue->nnodes == 0) + return -1; + + if (queue->type == 1) + key = queue->maxgain; + else + key = queue->heap[0].key; + + return key; +} + + + + +/************************************************************************* +* This functions checks the consistency of the heap +**************************************************************************/ +int CheckHeap(PQueueType *queue) +{ + int i, j, nnodes; + idxtype *locator; + KeyValueType *heap; + + heap = queue->heap; + locator = queue->locator; + nnodes = queue->nnodes; + + if (nnodes == 0) + return 1; + + ASSERT(locator[heap[0].val] == 0); + for (i=1; i<nnodes; i++) { + ASSERTP(locator[heap[i].val] == i, ("%d %d %d %d\n", nnodes, i, heap[i].val, locator[heap[i].val])); + ASSERTP(heap[i].key <= heap[(i-1)/2].key, ("%d %d %d %d %d\n", i, (i-1)/2, nnodes, heap[i].key, heap[(i-1)/2].key)); + } + for (i=1; i<nnodes; i++) + ASSERT(heap[i].key <= heap[0].key); + + for (j=i=0; i<queue->maxnodes; i++) { + if (locator[i] != -1) + j++; + } + ASSERTP(j == nnodes, ("%d %d\n", j, nnodes)); + + return 1; +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/proto.h b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/proto.h new file mode 100644 index 0000000..3cfadab --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/proto.h @@ -0,0 +1,511 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * proto.h + * + * This file contains header files + * + * Started 10/19/95 + * George + * + * $Id: proto.h,v 1.3 2003/07/24 18:39:11 karypis Exp $ + * + */ + +/* balance.c */ +void Balance2Way(CtrlType *, GraphType *, int *, float); +void Bnd2WayBalance(CtrlType *, GraphType *, int *); +void General2WayBalance(CtrlType *, GraphType *, int *); + +/* bucketsort.c */ +void BucketSortKeysInc(int, int, idxtype *, idxtype *, idxtype *); + +/* ccgraph.c */ +void CreateCoarseGraph(CtrlType *, GraphType *, int, idxtype *, idxtype *); +void CreateCoarseGraphNoMask(CtrlType *, GraphType *, int, idxtype *, idxtype *); +void CreateCoarseGraph_NVW(CtrlType *, GraphType *, int, idxtype *, idxtype *); +GraphType *SetUpCoarseGraph(GraphType *, int, int); +void ReAdjustMemory(GraphType *, GraphType *, int); + +/* checkgraph.c */ +int CheckGraph(GraphType *); + +/* coarsen.c */ +GraphType *Coarsen2Way(CtrlType *, GraphType *); + +/* compress.c */ +void CompressGraph(CtrlType *, GraphType *, int, idxtype *, idxtype *, idxtype *, idxtype *); +void PruneGraph(CtrlType *, GraphType *, int, idxtype *, idxtype *, idxtype *, float); + +/* debug.c */ +int ComputeCut(GraphType *, idxtype *); +int CheckBnd(GraphType *); +int CheckBnd2(GraphType *); +int CheckNodeBnd(GraphType *, int); +int CheckRInfo(RInfoType *); +int CheckNodePartitionParams(GraphType *); +int IsSeparable(GraphType *); + +/* estmem.c */ +void METIS_EstimateMemory(int *, idxtype *, idxtype *, int *, int *, int *); +void EstimateCFraction(int, idxtype *, idxtype *, float *, float *); +int ComputeCoarseGraphSize(int, idxtype *, idxtype *, int, idxtype *, idxtype *, idxtype *); + +/* fm.c */ +void FM_2WayEdgeRefine(CtrlType *, GraphType *, int *, int); + +/* fortran.c */ +void Change2CNumbering(int, idxtype *, idxtype *); +void Change2FNumbering(int, idxtype *, idxtype *, idxtype *); +void Change2FNumbering2(int, idxtype *, idxtype *); +void Change2FNumberingOrder(int, idxtype *, idxtype *, idxtype *, idxtype *); +void ChangeMesh2CNumbering(int, idxtype *); +void ChangeMesh2FNumbering(int, idxtype *, int, idxtype *, idxtype *); +void ChangeMesh2FNumbering2(int, idxtype *, int, int, idxtype *, idxtype *); + +/* frename.c */ +void METIS_PARTGRAPHRECURSIVE(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void metis_partgraphrecursive(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void metis_partgraphrecursive_(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void metis_partgraphrecursive__(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void METIS_WPARTGRAPHRECURSIVE(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void metis_wpartgraphrecursive(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void metis_wpartgraphrecursive_(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void metis_wpartgraphrecursive__(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void METIS_PARTGRAPHKWAY(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void metis_partgraphkway(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void metis_partgraphkway_(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void metis_partgraphkway__(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void METIS_WPARTGRAPHKWAY(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void metis_wpartgraphkway(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void metis_wpartgraphkway_(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void metis_wpartgraphkway__(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void METIS_EDGEND(int *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *); +void metis_edgend(int *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *); +void metis_edgend_(int *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *); +void metis_edgend__(int *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *); +void METIS_NODEND(int *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *); +void metis_nodend(int *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *); +void metis_nodend_(int *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *); +void metis_nodend__(int *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *); +void METIS_NODEWND(int *, idxtype *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *); +void metis_nodewnd(int *, idxtype *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *); +void metis_nodewnd_(int *, idxtype *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *); +void metis_nodewnd__(int *, idxtype *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *); +void METIS_PARTMESHNODAL(int *, int *, idxtype *, int *, int *, int *, int *, idxtype *, idxtype *); +void metis_partmeshnodal(int *, int *, idxtype *, int *, int *, int *, int *, idxtype *, idxtype *); +void metis_partmeshnodal_(int *, int *, idxtype *, int *, int *, int *, int *, idxtype *, idxtype *); +void metis_partmeshnodal__(int *, int *, idxtype *, int *, int *, int *, int *, idxtype *, idxtype *); +void METIS_PARTMESHDUAL(int *, int *, idxtype *, int *, int *, int *, int *, idxtype *, idxtype *); +void metis_partmeshdual(int *, int *, idxtype *, int *, int *, int *, int *, idxtype *, idxtype *); +void metis_partmeshdual_(int *, int *, idxtype *, int *, int *, int *, int *, idxtype *, idxtype *); +void metis_partmeshdual__(int *, int *, idxtype *, int *, int *, int *, int *, idxtype *, idxtype *); +void METIS_MESHTONODAL(int *, int *, idxtype *, int *, int *, idxtype *, idxtype *); +void metis_meshtonodal(int *, int *, idxtype *, int *, int *, idxtype *, idxtype *); +void metis_meshtonodal_(int *, int *, idxtype *, int *, int *, idxtype *, idxtype *); +void metis_meshtonodal__(int *, int *, idxtype *, int *, int *, idxtype *, idxtype *); +void METIS_MESHTODUAL(int *, int *, idxtype *, int *, int *, idxtype *, idxtype *); +void metis_meshtodual(int *, int *, idxtype *, int *, int *, idxtype *, idxtype *); +void metis_meshtodual_(int *, int *, idxtype *, int *, int *, idxtype *, idxtype *); +void metis_meshtodual__(int *, int *, idxtype *, int *, int *, idxtype *, idxtype *); +void METIS_ESTIMATEMEMORY(int *, idxtype *, idxtype *, int *, int *, int *); +void metis_estimatememory(int *, idxtype *, idxtype *, int *, int *, int *); +void metis_estimatememory_(int *, idxtype *, idxtype *, int *, int *, int *); +void metis_estimatememory__(int *, idxtype *, idxtype *, int *, int *, int *); +void METIS_MCPARTGRAPHRECURSIVE(int *, int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void metis_mcpartgraphrecursive(int *, int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void metis_mcpartgraphrecursive_(int *, int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void metis_mcpartgraphrecursive__(int *, int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void METIS_MCPARTGRAPHKWAY(int *, int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void metis_mcpartgraphkway(int *, int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void metis_mcpartgraphkway_(int *, int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void metis_mcpartgraphkway__(int *, int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void METIS_PARTGRAPHVKWAY(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void metis_partgraphvkway(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void metis_partgraphvkway_(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void metis_partgraphvkway__(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void METIS_WPARTGRAPHVKWAY(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void metis_wpartgraphvkway(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void metis_wpartgraphvkway_(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void metis_wpartgraphvkway__(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); + +/* graph.c */ +void SetUpGraph(GraphType *, int, int, int, idxtype *, idxtype *, idxtype *, idxtype *, int); +void SetUpGraphKway(GraphType *, int, idxtype *, idxtype *); +void SetUpGraph2(GraphType *, int, int, idxtype *, idxtype *, float *, idxtype *); +void VolSetUpGraph(GraphType *, int, int, int, idxtype *, idxtype *, idxtype *, idxtype *, int); +void RandomizeGraph(GraphType *); +int IsConnectedSubdomain(CtrlType *, GraphType *, int, int); +int IsConnected(CtrlType *, GraphType *, int); +int IsConnected2(GraphType *, int); +int FindComponents(CtrlType *, GraphType *, idxtype *, idxtype *); + +/* initpart.c */ +void Init2WayPartition(CtrlType *, GraphType *, int *, float); +void InitSeparator(CtrlType *, GraphType *, float); +void GrowBisection(CtrlType *, GraphType *, int *, float); +void GrowBisectionNode(CtrlType *, GraphType *, float); +void RandomBisection(CtrlType *, GraphType *, int *, float); + +/* kmetis.c */ +void METIS_PartGraphKway(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void METIS_WPartGraphKway(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +int MlevelKWayPartitioning(CtrlType *, GraphType *, int, idxtype *, float *, float); + +/* kvmetis.c */ +void METIS_PartGraphVKway(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void METIS_WPartGraphVKway(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +int MlevelVolKWayPartitioning(CtrlType *, GraphType *, int, idxtype *, float *, float); + +/* kwayfm.c */ +void Random_KWayEdgeRefine(CtrlType *, GraphType *, int, float *, float, int, int); +void Greedy_KWayEdgeRefine(CtrlType *, GraphType *, int, float *, float, int); +void Greedy_KWayEdgeBalance(CtrlType *, GraphType *, int, float *, float, int); + +/* kwayrefine.c */ +void RefineKWay(CtrlType *, GraphType *, GraphType *, int, float *, float); +void AllocateKWayPartitionMemory(CtrlType *, GraphType *, int); +void ComputeKWayPartitionParams(CtrlType *, GraphType *, int); +void ProjectKWayPartition(CtrlType *, GraphType *, int); +int IsBalanced(idxtype *, int, float *, float); +void ComputeKWayBoundary(CtrlType *, GraphType *, int); +void ComputeKWayBalanceBoundary(CtrlType *, GraphType *, int); + +/* kwayvolfm.c */ +void Random_KWayVolRefine(CtrlType *, GraphType *, int, float *, float, int, int); +void Random_KWayVolRefineMConn(CtrlType *, GraphType *, int, float *, float, int, int); +void Greedy_KWayVolBalance(CtrlType *, GraphType *, int, float *, float, int); +void Greedy_KWayVolBalanceMConn(CtrlType *, GraphType *, int, float *, float, int); +void KWayVolUpdate(CtrlType *, GraphType *, int, int, int, idxtype *, idxtype *, idxtype *); +void ComputeKWayVolume(GraphType *, int, idxtype *, idxtype *, idxtype *); +int ComputeVolume(GraphType *, idxtype *); +void CheckVolKWayPartitionParams(CtrlType *, GraphType *, int); +void ComputeVolSubDomainGraph(GraphType *, int, idxtype *, idxtype *); +void EliminateVolSubDomainEdges(CtrlType *, GraphType *, int, float *); +void EliminateVolComponents(CtrlType *, GraphType *, int, float *, float); + +/* kwayvolrefine.c */ +void RefineVolKWay(CtrlType *, GraphType *, GraphType *, int, float *, float); +void AllocateVolKWayPartitionMemory(CtrlType *, GraphType *, int); +void ComputeVolKWayPartitionParams(CtrlType *, GraphType *, int); +void ComputeKWayVolGains(CtrlType *, GraphType *, int); +void ProjectVolKWayPartition(CtrlType *, GraphType *, int); +void ComputeVolKWayBoundary(CtrlType *, GraphType *, int); +void ComputeVolKWayBalanceBoundary(CtrlType *, GraphType *, int); + +/* match.c */ +void Match_RM(CtrlType *, GraphType *); +void Match_RM_NVW(CtrlType *, GraphType *); +void Match_HEM(CtrlType *, GraphType *); +void Match_SHEM(CtrlType *, GraphType *); + +/* mbalance.c */ +void MocBalance2Way(CtrlType *, GraphType *, float *, float); +void MocGeneral2WayBalance(CtrlType *, GraphType *, float *, float); + +/* mbalance2.c */ +void MocBalance2Way2(CtrlType *, GraphType *, float *, float *); +void MocGeneral2WayBalance2(CtrlType *, GraphType *, float *, float *); +void SelectQueue3(int, float *, float *, int *, int *, PQueueType [MAXNCON][2], float *); + +/* mcoarsen.c */ +GraphType *MCCoarsen2Way(CtrlType *, GraphType *); + +/* memory.c */ +void AllocateWorkSpace(CtrlType *, GraphType *, int); +void FreeWorkSpace(CtrlType *, GraphType *); +int WspaceAvail(CtrlType *); +idxtype *idxwspacemalloc(CtrlType *, int); +void idxwspacefree(CtrlType *, int); +float *fwspacemalloc(CtrlType *, int); +void fwspacefree(CtrlType *, int); +GraphType *CreateGraph(void); +void InitGraph(GraphType *); +void FreeGraph(GraphType *); + +/* mesh.c */ +void METIS_MeshToDual(int *, int *, idxtype *, int *, int *, idxtype *, idxtype *); +void METIS_MeshToNodal(int *, int *, idxtype *, int *, int *, idxtype *, idxtype *); +void GENDUALMETIS(int, int, int, idxtype *, idxtype *, idxtype *adjncy); +void TRINODALMETIS(int, int, idxtype *, idxtype *, idxtype *adjncy); +void TETNODALMETIS(int, int, idxtype *, idxtype *, idxtype *adjncy); +void HEXNODALMETIS(int, int, idxtype *, idxtype *, idxtype *adjncy); +void QUADNODALMETIS(int, int, idxtype *, idxtype *, idxtype *adjncy); + +/* meshpart.c */ +void METIS_PartMeshNodal(int *, int *, idxtype *, int *, int *, int *, int *, idxtype *, idxtype *); +void METIS_PartMeshDual(int *, int *, idxtype *, int *, int *, int *, int *, idxtype *, idxtype *); + +/* mfm.c */ +void MocFM_2WayEdgeRefine(CtrlType *, GraphType *, float *, int); +void SelectQueue(int, float *, float *, int *, int *, PQueueType [MAXNCON][2]); +int BetterBalance(int, float *, float *, float *); +float Compute2WayHLoadImbalance(int, float *, float *); +void Compute2WayHLoadImbalanceVec(int, float *, float *, float *); + +/* mfm2.c */ +void MocFM_2WayEdgeRefine2(CtrlType *, GraphType *, float *, float *, int); +void SelectQueue2(int, float *, float *, int *, int *, PQueueType [MAXNCON][2], float *); +int IsBetter2wayBalance(int, float *, float *, float *); + +/* mincover.o */ +void MinCover(idxtype *, idxtype *, int, int, idxtype *, int *); +int MinCover_Augment(idxtype *, idxtype *, int, idxtype *, idxtype *, idxtype *, int); +void MinCover_Decompose(idxtype *, idxtype *, int, int, idxtype *, idxtype *, int *); +void MinCover_ColDFS(idxtype *, idxtype *, int, idxtype *, idxtype *, int); +void MinCover_RowDFS(idxtype *, idxtype *, int, idxtype *, idxtype *, int); + +/* minitpart.c */ +void MocInit2WayPartition(CtrlType *, GraphType *, float *, float); +void MocGrowBisection(CtrlType *, GraphType *, float *, float); +void MocRandomBisection(CtrlType *, GraphType *, float *, float); +void MocInit2WayBalance(CtrlType *, GraphType *, float *); +int SelectQueueoneWay(int, float *, float *, int, PQueueType [MAXNCON][2]); + +/* minitpart2.c */ +void MocInit2WayPartition2(CtrlType *, GraphType *, float *, float *); +void MocGrowBisection2(CtrlType *, GraphType *, float *, float *); +void MocGrowBisectionNew2(CtrlType *, GraphType *, float *, float *); +void MocInit2WayBalance2(CtrlType *, GraphType *, float *, float *); +int SelectQueueOneWay2(int, float *, PQueueType [MAXNCON][2], float *); + +/* mkmetis.c */ +void METIS_mCPartGraphKway(int *, int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +int MCMlevelKWayPartitioning(CtrlType *, GraphType *, int, idxtype *, float *); + +/* mkwayfmh.c */ +void MCRandom_KWayEdgeRefineHorizontal(CtrlType *, GraphType *, int, float *, int); +void MCGreedy_KWayEdgeBalanceHorizontal(CtrlType *, GraphType *, int, float *, int); +int AreAllHVwgtsBelow(int, float, float *, float, float *, float *); +int AreAllHVwgtsAbove(int, float, float *, float, float *, float *); +void ComputeHKWayLoadImbalance(int, int, float *, float *); +int MocIsHBalanced(int, int, float *, float *); +int IsHBalanceBetterFT(int, int, float *, float *, float *, float *); +int IsHBalanceBetterTT(int, int, float *, float *, float *, float *); + +/* mkwayrefine.c */ +void MocRefineKWayHorizontal(CtrlType *, GraphType *, GraphType *, int, float *); +void MocAllocateKWayPartitionMemory(CtrlType *, GraphType *, int); +void MocComputeKWayPartitionParams(CtrlType *, GraphType *, int); +void MocProjectKWayPartition(CtrlType *, GraphType *, int); +void MocComputeKWayBalanceBoundary(CtrlType *, GraphType *, int); + +/* mmatch.c */ +void MCMatch_RM(CtrlType *, GraphType *); +void MCMatch_HEM(CtrlType *, GraphType *); +void MCMatch_SHEM(CtrlType *, GraphType *); +void MCMatch_SHEBM(CtrlType *, GraphType *, int); +void MCMatch_SBHEM(CtrlType *, GraphType *, int); +float BetterVBalance(int, int, float *, float *, float *); +int AreAllVwgtsBelowFast(int, float *, float *, float); + +/* mmd.c */ +void genmmd(int, idxtype *, idxtype *, idxtype *, idxtype *, int , idxtype *, idxtype *, idxtype *, idxtype *, int, int *); +void mmdelm(int, idxtype *xadj, idxtype *, idxtype *, idxtype *, idxtype *, idxtype *, idxtype *, idxtype *, int, int); +int mmdint(int, idxtype *xadj, idxtype *, idxtype *, idxtype *, idxtype *, idxtype *, idxtype *, idxtype *); +void mmdnum(int, idxtype *, idxtype *, idxtype *); +void mmdupd(int, int, idxtype *, idxtype *, int, int *, idxtype *, idxtype *, idxtype *, idxtype *, idxtype *, idxtype *, int, int *tag); + +/* mpmetis.c */ +void METIS_mCPartGraphRecursive(int *, int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void METIS_mCHPartGraphRecursive(int *, int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void METIS_mCPartGraphRecursiveInternal(int *, int *, idxtype *, idxtype *, float *, idxtype *, int *, int *, int *, idxtype *); +void METIS_mCHPartGraphRecursiveInternal(int *, int *, idxtype *, idxtype *, float *, idxtype *, int *, float *, int *, int *, idxtype *); +int MCMlevelRecursiveBisection(CtrlType *, GraphType *, int, idxtype *, float, int); +int MCHMlevelRecursiveBisection(CtrlType *, GraphType *, int, idxtype *, float *, int); +void MCMlevelEdgeBisection(CtrlType *, GraphType *, float *, float); +void MCHMlevelEdgeBisection(CtrlType *, GraphType *, float *, float *); + +/* mrefine.c */ +void MocRefine2Way(CtrlType *, GraphType *, GraphType *, float *, float); +void MocAllocate2WayPartitionMemory(CtrlType *, GraphType *); +void MocCompute2WayPartitionParams(CtrlType *, GraphType *); +void MocProject2WayPartition(CtrlType *, GraphType *); + +/* mrefine2.c */ +void MocRefine2Way2(CtrlType *, GraphType *, GraphType *, float *, float *); + +/* mutil.c */ +int AreAllVwgtsBelow(int, float, float *, float, float *, float); +int AreAnyVwgtsBelow(int, float, float *, float, float *, float); +int AreAllVwgtsAbove(int, float, float *, float, float *, float); +float ComputeLoadImbalance(int, int, float *, float *); +int AreAllBelow(int, float *, float *); + +/* myqsort.c */ +void iidxsort(int, idxtype *); +void iintsort(int, int *); +void ikeysort(int, KeyValueType *); +void ikeyvalsort(int, KeyValueType *); + +/* ometis.c */ +void METIS_EdgeND(int *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *); +void METIS_NodeND(int *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *); +void METIS_NodeWND(int *, idxtype *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *); +void MlevelNestedDissection(CtrlType *, GraphType *, idxtype *, float, int); +void MlevelNestedDissectionCC(CtrlType *, GraphType *, idxtype *, float, int); +void MlevelNodeBisectionMultiple(CtrlType *, GraphType *, int *, float); +void MlevelNodeBisection(CtrlType *, GraphType *, int *, float); +void SplitGraphOrder(CtrlType *, GraphType *, GraphType *, GraphType *); +void MMDOrder(CtrlType *, GraphType *, idxtype *, int); +int SplitGraphOrderCC(CtrlType *, GraphType *, GraphType *, int, idxtype *, idxtype *); + +/* parmetis.c */ +void METIS_PartGraphKway2(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void METIS_WPartGraphKway2(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void METIS_NodeNDP(int, idxtype *, idxtype *, int, int *, idxtype *, idxtype *, idxtype *); +void MlevelNestedDissectionP(CtrlType *, GraphType *, idxtype *, int, int, int, idxtype *); +void METIS_NodeComputeSeparator(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, idxtype *); +void METIS_EdgeComputeSeparator(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, idxtype *); +void METIS_mCPartGraphRecursive2(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, float *tpwgts, int *options, int *edgecut, idxtype *part); +int MCMlevelRecursiveBisection2(CtrlType *ctrl, GraphType *graph, int nparts, float *tpwgts, idxtype *part, float ubfactor, int fpart); + + + +/* pmetis.c */ +void METIS_PartGraphRecursive(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void METIS_WPartGraphRecursive(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +int MlevelRecursiveBisection(CtrlType *, GraphType *, int, idxtype *, float *, float, int); +void MlevelEdgeBisection(CtrlType *, GraphType *, int *, float); +void SplitGraphPart(CtrlType *, GraphType *, GraphType *, GraphType *); +void SetUpSplitGraph(GraphType *, GraphType *, int, int); + +/* pqueue.c */ +void PQueueInit(CtrlType *ctrl, PQueueType *, int, int); +void PQueueReset(PQueueType *); +void PQueueFree(CtrlType *ctrl, PQueueType *); +int PQueueGetSize(PQueueType *); +int PQueueInsert(PQueueType *, int, int); +int PQueueDelete(PQueueType *, int, int); +int PQueueUpdate(PQueueType *, int, int, int); +void PQueueUpdateUp(PQueueType *, int, int, int); +int PQueueGetMax(PQueueType *); +int PQueueSeeMax(PQueueType *); +int PQueueGetKey(PQueueType *); +int CheckHeap(PQueueType *); + +/* refine.c */ +void Refine2Way(CtrlType *, GraphType *, GraphType *, int *, float ubfactor); +void Allocate2WayPartitionMemory(CtrlType *, GraphType *); +void Compute2WayPartitionParams(CtrlType *, GraphType *); +void Project2WayPartition(CtrlType *, GraphType *); + +/* separator.c */ +void ConstructSeparator(CtrlType *, GraphType *, float); +void ConstructMinCoverSeparator0(CtrlType *, GraphType *, float); +void ConstructMinCoverSeparator(CtrlType *, GraphType *, float); + +/* sfm.c */ +void FM_2WayNodeRefine(CtrlType *, GraphType *, float, int); +void FM_2WayNodeRefineEqWgt(CtrlType *, GraphType *, int); +void FM_2WayNodeRefine_OneSided(CtrlType *, GraphType *, float, int); +void FM_2WayNodeBalance(CtrlType *, GraphType *, float); +int ComputeMaxNodeGain(int, idxtype *, idxtype *, idxtype *); + +/* srefine.c */ +void Refine2WayNode(CtrlType *, GraphType *, GraphType *, float); +void Allocate2WayNodePartitionMemory(CtrlType *, GraphType *); +void Compute2WayNodePartitionParams(CtrlType *, GraphType *); +void Project2WayNodePartition(CtrlType *, GraphType *); + +/* stat.c */ +void ComputePartitionInfo(GraphType *, int, idxtype *); +void ComputePartitionInfoBipartite(GraphType *, int, idxtype *); +void ComputePartitionBalance(GraphType *, int, idxtype *, float *); +float ComputeElementBalance(int, int, idxtype *); +void Moc_ComputePartitionBalance(GraphType *graph, int nparts, idxtype *where, float *ubvec); + +/* subdomains.c */ +void Random_KWayEdgeRefineMConn(CtrlType *, GraphType *, int, float *, float, int, int); +void Greedy_KWayEdgeBalanceMConn(CtrlType *, GraphType *, int, float *, float, int); +void PrintSubDomainGraph(GraphType *, int, idxtype *); +void ComputeSubDomainGraph(GraphType *, int, idxtype *, idxtype *); +void EliminateSubDomainEdges(CtrlType *, GraphType *, int, float *); +void MoveGroupMConn(CtrlType *, GraphType *, idxtype *, idxtype *, int, int, int, idxtype *); +void EliminateComponents(CtrlType *, GraphType *, int, float *, float); +void MoveGroup(CtrlType *, GraphType *, int, int, int, idxtype *, idxtype *); + +/* timing.c */ +void InitTimers(CtrlType *); +void PrintTimers(CtrlType *); +double seconds(void); + +/* util.c */ +void errexit(char *,...); +#ifndef DMALLOC +int *imalloc(int, char *); +idxtype *idxmalloc(int, char *); +float *fmalloc(int, char *); +int *ismalloc(int, int, char *); +idxtype *idxsmalloc(int, idxtype, char *); +void *GKmalloc(int, char *); +#endif +/*void GKfree(void **,...); */ +int *iset(int n, int val, int *x); +idxtype *idxset(int n, idxtype val, idxtype *x); +float *sset(int n, float val, float *x); +int iamax(int, int *); +int idxamax(int, idxtype *); +int idxamax_strd(int, idxtype *, int); +int samax(int, float *); +int samax2(int, float *); +int idxamin(int, idxtype *); +int samin(int, float *); +int idxsum(int, idxtype *); +int idxsum_strd(int, idxtype *, int); +void idxadd(int, idxtype *, idxtype *); +int charsum(int, char *); +int isum(int, int *); +float ssum(int, float *); +float ssum_strd(int n, float *x, int); +void sscale(int n, float, float *x); +float snorm2(int, float *); +float sdot(int n, float *, float *); +void saxpy(int, float, float *, int, float *, int); +void RandomPermute(int, idxtype *, int); +int ispow2(int); +void InitRandom(int); +int log2Int(int); + + + + + + + + + + +/*************************************************************** +* Programs Directory +****************************************************************/ + +/* io.c */ +void ReadGraph(GraphType *, char *, int *); +void WritePartition(char *, idxtype *, int, int); +void WriteMeshPartition(char *, int, int, idxtype *, int, idxtype *); +void WritePermutation(char *, idxtype *, int); +int CheckGraph(GraphType *); +idxtype *ReadMesh(char *, int *, int *, int *); +void WriteGraph(char *, int, idxtype *, idxtype *); + +/* smbfactor.c */ +void ComputeFillIn(GraphType *, idxtype *); +idxtype ComputeFillIn2(GraphType *, idxtype *); +int smbfct(int, idxtype *, idxtype *, idxtype *, idxtype *, idxtype *, int *, idxtype *, idxtype *, int *); + + +/*************************************************************** +* Test Directory +****************************************************************/ +void Test_PartGraph(int, idxtype *, idxtype *); +int VerifyPart(int, idxtype *, idxtype *, idxtype *, idxtype *, int, int, idxtype *); +int VerifyWPart(int, idxtype *, idxtype *, idxtype *, idxtype *, int, float *, int, idxtype *); +void Test_PartGraphV(int, idxtype *, idxtype *); +int VerifyPartV(int, idxtype *, idxtype *, idxtype *, idxtype *, int, int, idxtype *); +int VerifyWPartV(int, idxtype *, idxtype *, idxtype *, idxtype *, int, float *, int, idxtype *); +void Test_PartGraphmC(int, idxtype *, idxtype *); +int VerifyPartmC(int, int, idxtype *, idxtype *, idxtype *, idxtype *, int, float *, int, idxtype *); +void Test_ND(int, idxtype *, idxtype *); +int VerifyND(int, idxtype *, idxtype *); + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/refine.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/refine.c new file mode 100644 index 0000000..f479298 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/refine.c @@ -0,0 +1,204 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * refine.c + * + * This file contains the driving routines for multilevel refinement + * + * Started 7/24/97 + * George + * + * $Id: refine.c,v 1.1 2003/07/16 15:55:17 karypis Exp $ + */ + +#include <metis.h> + + +/************************************************************************* +* This function is the entry point of refinement +**************************************************************************/ +void Refine2Way(CtrlType *ctrl, GraphType *orggraph, GraphType *graph, int *tpwgts, float ubfactor) +{ + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->UncoarsenTmr)); + + /* Compute the parameters of the coarsest graph */ + Compute2WayPartitionParams(ctrl, graph); + + for (;;) { + ASSERT(CheckBnd(graph)); + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->RefTmr)); + switch (ctrl->RType) { + case 1: + Balance2Way(ctrl, graph, tpwgts, ubfactor); + FM_2WayEdgeRefine(ctrl, graph, tpwgts, 8); + break; + default: + errexit("Unknown refinement type: %d\n", ctrl->RType); + } + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->RefTmr)); + + if (graph == orggraph) + break; + + graph = graph->finer; + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ProjectTmr)); + Project2WayPartition(ctrl, graph); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ProjectTmr)); + } + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->UncoarsenTmr)); +} + + +/************************************************************************* +* This function allocates memory for 2-way edge refinement +**************************************************************************/ +void Allocate2WayPartitionMemory(CtrlType *ctrl, GraphType *graph) +{ + int nvtxs; + + nvtxs = graph->nvtxs; + + graph->rdata = idxmalloc(5*nvtxs+2, "Allocate2WayPartitionMemory: rdata"); + graph->pwgts = graph->rdata; + graph->where = graph->rdata + 2; + graph->id = graph->rdata + nvtxs + 2; + graph->ed = graph->rdata + 2*nvtxs + 2; + graph->bndptr = graph->rdata + 3*nvtxs + 2; + graph->bndind = graph->rdata + 4*nvtxs + 2; +} + + +/************************************************************************* +* This function computes the initial id/ed +**************************************************************************/ +void Compute2WayPartitionParams(CtrlType *ctrl, GraphType *graph) +{ + int i, j, k, l, nvtxs, nbnd, mincut; + idxtype *xadj, *vwgt, *adjncy, *adjwgt, *pwgts; + idxtype *id, *ed, *where; + idxtype *bndptr, *bndind; + int me, other; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + where = graph->where; + pwgts = idxset(2, 0, graph->pwgts); + id = idxset(nvtxs, 0, graph->id); + ed = idxset(nvtxs, 0, graph->ed); + bndptr = idxset(nvtxs, -1, graph->bndptr); + bndind = graph->bndind; + + + /*------------------------------------------------------------ + / Compute now the id/ed degrees + /------------------------------------------------------------*/ + nbnd = mincut = 0; + for (i=0; i<nvtxs; i++) { + ASSERT(where[i] >= 0 && where[i] <= 1); + me = where[i]; + pwgts[me] += vwgt[i]; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (me == where[adjncy[j]]) + id[i] += adjwgt[j]; + else + ed[i] += adjwgt[j]; + } + + if (ed[i] > 0 || xadj[i] == xadj[i+1]) { + mincut += ed[i]; + bndptr[i] = nbnd; + bndind[nbnd++] = i; + } + } + + graph->mincut = mincut/2; + graph->nbnd = nbnd; + + ASSERT(pwgts[0]+pwgts[1] == idxsum(nvtxs, vwgt)); +} + + + +/************************************************************************* +* This function projects a partition, and at the same time computes the +* parameters for refinement. +**************************************************************************/ +void Project2WayPartition(CtrlType *ctrl, GraphType *graph) +{ + int i, j, k, nvtxs, nbnd, me; + idxtype *xadj, *adjncy, *adjwgt, *adjwgtsum; + idxtype *cmap, *where, *id, *ed, *bndptr, *bndind; + idxtype *cwhere, *cid, *ced, *cbndptr; + GraphType *cgraph; + + cgraph = graph->coarser; + cwhere = cgraph->where; + cid = cgraph->id; + ced = cgraph->ed; + cbndptr = cgraph->bndptr; + + nvtxs = graph->nvtxs; + cmap = graph->cmap; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + adjwgtsum = graph->adjwgtsum; + + Allocate2WayPartitionMemory(ctrl, graph); + + where = graph->where; + id = idxset(nvtxs, 0, graph->id); + ed = idxset(nvtxs, 0, graph->ed); + bndptr = idxset(nvtxs, -1, graph->bndptr); + bndind = graph->bndind; + + + /* Go through and project partition and compute id/ed for the nodes */ + for (i=0; i<nvtxs; i++) { + k = cmap[i]; + where[i] = cwhere[k]; + cmap[i] = cbndptr[k]; + } + + for (nbnd=0, i=0; i<nvtxs; i++) { + me = where[i]; + + id[i] = adjwgtsum[i]; + + if (xadj[i] == xadj[i+1]) { + bndptr[i] = nbnd; + bndind[nbnd++] = i; + } + else { + if (cmap[i] != -1) { /* If it is an interface node. Note that cmap[i] = cbndptr[cmap[i]] */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (me != where[adjncy[j]]) + ed[i] += adjwgt[j]; + } + id[i] -= ed[i]; + + if (ed[i] > 0 || xadj[i] == xadj[i+1]) { + bndptr[i] = nbnd; + bndind[nbnd++] = i; + } + } + } + } + + graph->mincut = cgraph->mincut; + graph->nbnd = nbnd; + idxcopy(2, cgraph->pwgts, graph->pwgts); + + FreeGraph(graph->coarser); + graph->coarser = NULL; + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/rename.h b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/rename.h new file mode 100644 index 0000000..ca07dfe --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/rename.h @@ -0,0 +1,424 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * rename.h + * + * This file contains header files + * + * Started 10/2/97 + * George + * + * $Id: rename.h,v 1.2 2003/07/24 18:39:12 karypis Exp $ + * + */ + +/* balance.c */ +#define Balance2Way __Balance2Way +#define Bnd2WayBalance __Bnd2WayBalance +#define General2WayBalance __General2WayBalance + + +/* bucketsort.c */ +#define BucketSortKeysInc __BucketSortKeysInc + + +/* ccgraph.c */ +#define CreateCoarseGraph __CreateCoarseGraph +#define CreateCoarseGraphNoMask __CreateCoarseGraphNoMask +#define CreateCoarseGraph_NVW __CreateCoarseGraph_NVW +#define SetUpCoarseGraph __SetUpCoarseGraph +#define ReAdjustMemory __ReAdjustMemory + + +/* checkgraph.c */ +#define CheckGraph __CheckGraph + + +/* coarsen.c */ +#define Coarsen2Way __Coarsen2Way + + +/* compress.c */ +#define CompressGraph __CompressGraph +#define PruneGraph __PruneGraph + + +/* debug.c */ +#define ComputeCut __ComputeCut +#define CheckBnd __CheckBnd +#define CheckBnd2 __CheckBnd2 +#define CheckNodeBnd __CheckNodeBnd +#define CheckRInfo __CheckRInfo +#define CheckNodePartitionParams __CheckNodePartitionParams +#define IsSeparable __IsSeparable + + +/* estmem.c */ +#define EstimateCFraction __EstimateCFraction +#define ComputeCoarseGraphSize __ComputeCoarseGraphSize + + +/* fm.c */ +#define FM_2WayEdgeRefine __FM_2WayEdgeRefine + + +/* fortran.c */ +#define Change2CNumbering __Change2CNumbering +#define Change2FNumbering __Change2FNumbering +#define Change2FNumbering2 __Change2FNumbering2 +#define Change2FNumberingOrder __Change2FNumberingOrder +#define ChangeMesh2CNumbering __ChangeMesh2CNumbering +#define ChangeMesh2FNumbering __ChangeMesh2FNumbering +#define ChangeMesh2FNumbering2 __ChangeMesh2FNumbering2 + + +/* graph.c */ +#define SetUpGraph __SetUpGraph +#define SetUpGraphKway __SetUpGraphKway +#define SetUpGraph2 __SetUpGraph2 +#define VolSetUpGraph __VolSetUpGraph +#define RandomizeGraph __RandomizeGraph +#define IsConnectedSubdomain __IsConnectedSubdomain +#define IsConnected __IsConnected +#define IsConnected2 __IsConnected2 +#define FindComponents __FindComponents + + +/* initpart.c */ +#define Init2WayPartition __Init2WayPartition +#define InitSeparator __InitSeparator +#define GrowBisection __GrowBisection +#define GrowBisectionNode __GrowBisectionNode +#define RandomBisection __RandomBisection + + +/* kmetis.c */ +#define MlevelKWayPartitioning __MlevelKWayPartitioning + + +/* kvmetis.c */ +#define MlevelVolKWayPartitioning __MlevelVolKWayPartitioning + + +/* kwayfm.c */ +#define Random_KWayEdgeRefine __Random_KWayEdgeRefine +#define Greedy_KWayEdgeRefine __Greedy_KWayEdgeRefine +#define Greedy_KWayEdgeBalance __Greedy_KWayEdgeBalance + + +/* kwayrefine.c */ +#define RefineKWay __RefineKWay +#define AllocateKWayPartitionMemory __AllocateKWayPartitionMemory +#define ComputeKWayPartitionParams __ComputeKWayPartitionParams +#define ProjectKWayPartition __ProjectKWayPartition +#define IsBalanced __IsBalanced +#define ComputeKWayBoundary __ComputeKWayBoundary +#define ComputeKWayBalanceBoundary __ComputeKWayBalanceBoundary + + +/* kwayvolfm.c */ +#define Random_KWayVolRefine __Random_KWayVolRefine +#define Random_KWayVolRefineMConn __Random_KWayVolRefineMConn +#define Greedy_KWayVolBalance __Greedy_KWayVolBalance +#define Greedy_KWayVolBalanceMConn __Greedy_KWayVolBalanceMConn +#define KWayVolUpdate __KWayVolUpdate +#define ComputeKWayVolume __ComputeKWayVolume +#define ComputeVolume __ComputeVolume +#define CheckVolKWayPartitionParams __CheckVolKWayPartitionParams +#define ComputeVolSubDomainGraph __ComputeVolSubDomainGraph +#define EliminateVolSubDomainEdges __EliminateVolSubDomainEdges + + +/* kwayvolrefine.c */ +#define RefineVolKWay __RefineVolKWay +#define AllocateVolKWayPartitionMemory __AllocateVolKWayPartitionMemory +#define ComputeVolKWayPartitionParams __ComputeVolKWayPartitionParams +#define ComputeKWayVolGains __ComputeKWayVolGains +#define ProjectVolKWayPartition __ProjectVolKWayPartition +#define ComputeVolKWayBoundary __ComputeVolKWayBoundary +#define ComputeVolKWayBalanceBoundary __ComputeVolKWayBalanceBoundary + + +/* match.c */ +#define Match_RM __Match_RM +#define Match_RM_NVW __Match_RM_NVW +#define Match_HEM __Match_HEM +#define Match_SHEM __Match_SHEM + + +/* mbalance.c */ +#define MocBalance2Way __MocBalance2Way +#define MocGeneral2WayBalance __MocGeneral2WayBalance + + +/* mbalance2.c */ +#define MocBalance2Way2 __MocBalance2Way2 +#define MocGeneral2WayBalance2 __MocGeneral2WayBalance2 +#define SelectQueue3 __SelectQueue3 + + +/* mcoarsen.c */ +#define MCCoarsen2Way __MCCoarsen2Way + + +/* memory.c */ +#define AllocateWorkSpace __AllocateWorkSpace +#define FreeWorkSpace __FreeWorkSpace +#define WspaceAvail __WspaceAvail +#define idxwspacemalloc __idxwspacemalloc +#define idxwspacefree __idxwspacefree +#define fwspacemalloc __fwspacemalloc +#define CreateGraph __CreateGraph +#define InitGraph __InitGraph +#define FreeGraph __FreeGraph + + +/* mesh.c */ +#define TRIDUALMETIS __TRIDUALMETIS +#define TETDUALMETIS __TETDUALMETIS +#define HEXDUALMETIS __HEXDUALMETIS +#define TRINODALMETIS __TRINODALMETIS +#define TETNODALMETIS __TETNODALMETIS +#define HEXNODALMETIS __HEXNODALMETIS + + +/* mfm.c */ +#define MocFM_2WayEdgeRefine __MocFM_2WayEdgeRefine +#define SelectQueue __SelectQueue +#define BetterBalance __BetterBalance +#define Compute2WayHLoadImbalance __Compute2WayHLoadImbalance +#define Compute2WayHLoadImbalanceVec __Compute2WayHLoadImbalanceVec + + +/* mfm2.c */ +#define MocFM_2WayEdgeRefine2 __MocFM_2WayEdgeRefine2 +#define SelectQueue2 __SelectQueue2 +#define IsBetter2wayBalance __IsBetter2wayBalance + + +/* mincover.c */ +#define MinCover __MinCover +#define MinCover_Augment __MinCover_Augment +#define MinCover_Decompose __MinCover_Decompose +#define MinCover_ColDFS __MinCover_ColDFS +#define MinCover_RowDFS __MinCover_RowDFS + + +/* minitpart.c */ +#define MocInit2WayPartition __MocInit2WayPartition +#define MocGrowBisection __MocGrowBisection +#define MocRandomBisection __MocRandomBisection +#define MocInit2WayBalance __MocInit2WayBalance +#define SelectQueueoneWay __SelectQueueoneWay + + +/* minitpart2.c */ +#define MocInit2WayPartition2 __MocInit2WayPartition2 +#define MocGrowBisection2 __MocGrowBisection2 +#define MocGrowBisectionNew2 __MocGrowBisectionNew2 +#define MocInit2WayBalance2 __MocInit2WayBalance2 +#define SelectQueueOneWay2 __SelectQueueOneWay2 + + +/* mkmetis.c */ +#define MCMlevelKWayPartitioning __MCMlevelKWayPartitioning + + +/* mkwayfmh.c */ +#define MCRandom_KWayEdgeRefineHorizontal __MCRandom_KWayEdgeRefineHorizontal +#define MCGreedy_KWayEdgeBalanceHorizontal __MCGreedy_KWayEdgeBalanceHorizontal +#define AreAllHVwgtsBelow __AreAllHVwgtsBelow +#define AreAllHVwgtsAbove __AreAllHVwgtsAbove +#define ComputeHKWayLoadImbalance __ComputeHKWayLoadImbalance +#define MocIsHBalanced __MocIsHBalanced +#define IsHBalanceBetterFT __IsHBalanceBetterFT +#define IsHBalanceBetterTT __IsHBalanceBetterTT + + +/* mkwayrefine.c */ +#define MocRefineKWayHorizontal __MocRefineKWayHorizontal +#define MocAllocateKWayPartitionMemory __MocAllocateKWayPartitionMemory +#define MocComputeKWayPartitionParams __MocComputeKWayPartitionParams +#define MocProjectKWayPartition __MocProjectKWayPartition +#define MocComputeKWayBalanceBoundary __MocComputeKWayBalanceBoundary + + +/* mmatch.c */ +#define MCMatch_RM __MCMatch_RM +#define MCMatch_HEM __MCMatch_HEM +#define MCMatch_SHEM __MCMatch_SHEM +#define MCMatch_SHEBM __MCMatch_SHEBM +#define MCMatch_SBHEM __MCMatch_SBHEM +#define BetterVBalance __BetterVBalance +#define AreAllVwgtsBelowFast __AreAllVwgtsBelowFast + + +/* mmd.c */ +#define genmmd __genmmd +#define mmdelm __mmdelm +#define mmdint __mmdint +#define mmdnum __mmdnum +#define mmdupd __mmdupd + + +/* mpmetis.c */ +#define MCMlevelRecursiveBisection __MCMlevelRecursiveBisection +#define MCHMlevelRecursiveBisection __MCHMlevelRecursiveBisection +#define MCMlevelEdgeBisection __MCMlevelEdgeBisection +#define MCHMlevelEdgeBisection __MCHMlevelEdgeBisection + + +/* mrefine.c */ +#define MocRefine2Way __MocRefine2Way +#define MocAllocate2WayPartitionMemory __MocAllocate2WayPartitionMemory +#define MocCompute2WayPartitionParams __MocCompute2WayPartitionParams +#define MocProject2WayPartition __MocProject2WayPartition + + +/* mrefine2.c */ +#define MocRefine2Way2 __MocRefine2Way2 + + +/* mutil.c */ +#define AreAllVwgtsBelow __AreAllVwgtsBelow +#define AreAnyVwgtsBelow __AreAnyVwgtsBelow +#define AreAllVwgtsAbove __AreAllVwgtsAbove +#define ComputeLoadImbalance __ComputeLoadImbalance +#define AreAllBelow __AreAllBelow + + +/* myqsort.c */ +#define iidxsort __iidxsort +#define iintsort __iintsort +#define ikeysort __ikeysort +#define ikeyvalsort __ikeyvalsort + + +/* ometis.c */ +#define MlevelNestedDissection __MlevelNestedDissection +#define MlevelNestedDissectionCC __MlevelNestedDissectionCC +#define MlevelNodeBisectionMultiple __MlevelNodeBisectionMultiple +#define MlevelNodeBisection __MlevelNodeBisection +#define SplitGraphOrder __SplitGraphOrder +#define MMDOrder __MMDOrder +#define SplitGraphOrderCC __SplitGraphOrderCC + + +/* parmetis.c */ +#define MlevelNestedDissectionP __MlevelNestedDissectionP +#define MCMlevelRecursiveBisection2 __MCMlevelRecursiveBisection2 + + +/* pmetis.c */ +#define MlevelRecursiveBisection __MlevelRecursiveBisection +#define MlevelEdgeBisection __MlevelEdgeBisection +#define SplitGraphPart __SplitGraphPart +#define SetUpSplitGraph __SetUpSplitGraph + + +/* pqueue.c */ +#define PQueueInit __PQueueInit +#define PQueueReset __PQueueReset +#define PQueueFree __PQueueFree +#define PQueueInsert __PQueueInsert +#define PQueueDelete __PQueueDelete +#define PQueueUpdate __PQueueUpdate +#define PQueueUpdateUp __PQueueUpdateUp +#define PQueueGetMax __PQueueGetMax +#define PQueueSeeMax __PQueueSeeMax +#define CheckHeap __CheckHeap + + +/* refine.c */ +#define Refine2Way __Refine2Way +#define Allocate2WayPartitionMemory __Allocate2WayPartitionMemory +#define Compute2WayPartitionParams __Compute2WayPartitionParams +#define Project2WayPartition __Project2WayPartition + + +/* separator.c */ +#define ConstructSeparator __ConstructSeparator +#define ConstructMinCoverSeparator0 __ConstructMinCoverSeparator0 +#define ConstructMinCoverSeparator __ConstructMinCoverSeparator + + +/* sfm.c */ +#define FM_2WayNodeRefine __FM_2WayNodeRefine +#define FM_2WayNodeRefineEqWgt __FM_2WayNodeRefineEqWgt +#define FM_2WayNodeRefine_OneSided __FM_2WayNodeRefine_OneSided +#define FM_2WayNodeBalance __FM_2WayNodeBalance +#define ComputeMaxNodeGain __ComputeMaxNodeGain + + +/* srefine.c */ +#define Refine2WayNode __Refine2WayNode +#define Allocate2WayNodePartitionMemory __Allocate2WayNodePartitionMemory +#define Compute2WayNodePartitionParams __Compute2WayNodePartitionParams +#define Project2WayNodePartition __Project2WayNodePartition + + +/* stat.c */ +#define ComputePartitionInfo __ComputePartitionInfo +#define ComputePartitionBalance __ComputePartitionBalance +#define ComputeElementBalance __ComputeElementBalance +#define Moc_ComputePartitionBalance __Moc_ComputePartitionBalance + + +/* subdomains.c */ +#define Random_KWayEdgeRefineMConn __Random_KWayEdgeRefineMConn +#define Greedy_KWayEdgeBalanceMConn __Greedy_KWayEdgeBalanceMConn +#define PrintSubDomainGraph __PrintSubDomainGraph +#define ComputeSubDomainGraph __ComputeSubDomainGraph +#define EliminateSubDomainEdges __EliminateSubDomainEdges +#define MoveGroupMConn __MoveGroupMConn +#define EliminateComponents __EliminateComponents +#define MoveGroup __MoveGroup + + +/* timing.c */ +#define InitTimers __InitTimers +#define PrintTimers __PrintTimers +#define seconds __seconds + + +/* util.c */ +#define errexit __errexit +#define GKfree __GKfree +#ifndef DMALLOC +#define imalloc __imalloc +#define idxmalloc __idxmalloc +#define fmalloc __fmalloc +#define ismalloc __ismalloc +#define idxsmalloc __idxsmalloc +#define GKmalloc __GKmalloc +#endif +#define iset __iset +#define idxset __idxset +#define sset __sset +#define iamax __iamax +#define idxamax __idxamax +#define idxamax_strd __idxamax_strd +#define samax __samax +#define samax2 __samax2 +#define idxamin __idxamin +#define samin __samin +#define idxsum __idxsum +#define idxsum_strd __idxsum_strd +#define idxadd __idxadd +#define charsum __charsum +#define isum __isum +#define ssum __ssum +#define ssum_strd __ssum_strd +#define sscale __sscale +#define snorm2 __snorm2 +#define sdot __sdot +#define saxpy __saxpy +#define RandomPermute __RandomPermute +#define ispow2 __ispow2 +#define InitRandom __InitRandom +#define log2Int __log2Int + + + + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/separator.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/separator.c new file mode 100644 index 0000000..380d4f4 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/separator.c @@ -0,0 +1,284 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * separator.c + * + * This file contains code for separator extraction + * + * Started 8/1/97 + * George + * + * $Id: separator.c,v 1.1 2003/07/16 15:55:17 karypis Exp $ + * + */ + +#include <metis.h> + +/************************************************************************* +* This function takes a bisection and constructs a minimum weight vertex +* separator out of it. It uses the node-based separator refinement for it. +**************************************************************************/ +void ConstructSeparator(CtrlType *ctrl, GraphType *graph, float ubfactor) +{ + int i, j, k, nvtxs, nbnd; + idxtype *xadj, *where, *bndind; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + nbnd = graph->nbnd; + bndind = graph->bndind; + + where = idxcopy(nvtxs, graph->where, idxwspacemalloc(ctrl, nvtxs)); + + /* Put the nodes in the boundary into the separator */ + for (i=0; i<nbnd; i++) { + j = bndind[i]; + if (xadj[j+1]-xadj[j] > 0) /* Ignore islands */ + where[j] = 2; + } + + GKfree(&graph->rdata, LTERM); + Allocate2WayNodePartitionMemory(ctrl, graph); + idxcopy(nvtxs, where, graph->where); + idxwspacefree(ctrl, nvtxs); + + ASSERT(IsSeparable(graph)); + + Compute2WayNodePartitionParams(ctrl, graph); + + ASSERT(CheckNodePartitionParams(graph)); + + FM_2WayNodeRefine(ctrl, graph, ubfactor, 8); + + ASSERT(IsSeparable(graph)); +} + + + +/************************************************************************* +* This function takes a bisection and constructs a minimum weight vertex +* separator out of it. It uses an unweighted minimum-cover algorithm +* followed by node-based separator refinement. +**************************************************************************/ +void ConstructMinCoverSeparator0(CtrlType *ctrl, GraphType *graph, float ubfactor) +{ + int i, ii, j, jj, k, l, nvtxs, nbnd, bnvtxs[3], bnedges[2], csize; + idxtype *xadj, *adjncy, *bxadj, *badjncy; + idxtype *where, *bndind, *bndptr, *vmap, *ivmap, *cover; + + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + + nbnd = graph->nbnd; + bndind = graph->bndind; + bndptr = graph->bndptr; + where = graph->where; + + vmap = idxwspacemalloc(ctrl, nvtxs); + ivmap = idxwspacemalloc(ctrl, nbnd); + cover = idxwspacemalloc(ctrl, nbnd); + + if (nbnd > 0) { + /* Go through the boundary and determine the sizes of the bipartite graph */ + bnvtxs[0] = bnvtxs[1] = bnedges[0] = bnedges[1] = 0; + for (i=0; i<nbnd; i++) { + j = bndind[i]; + k = where[j]; + if (xadj[j+1]-xadj[j] > 0) { + bnvtxs[k]++; + bnedges[k] += xadj[j+1]-xadj[j]; + } + } + + bnvtxs[2] = bnvtxs[0]+bnvtxs[1]; + bnvtxs[1] = bnvtxs[0]; + bnvtxs[0] = 0; + + bxadj = idxmalloc(bnvtxs[2]+1, "ConstructMinCoverSeparator: bxadj"); + badjncy = idxmalloc(bnedges[0]+bnedges[1]+1, "ConstructMinCoverSeparator: badjncy"); + + /* Construct the ivmap and vmap */ + ASSERT(idxset(nvtxs, -1, vmap) == vmap); + for (i=0; i<nbnd; i++) { + j = bndind[i]; + k = where[j]; + if (xadj[j+1]-xadj[j] > 0) { + vmap[j] = bnvtxs[k]; + ivmap[bnvtxs[k]++] = j; + } + } + + /* OK, go through and put the vertices of each part starting from 0 */ + bnvtxs[1] = bnvtxs[0]; + bnvtxs[0] = 0; + bxadj[0] = l = 0; + for (k=0; k<2; k++) { + for (ii=0; ii<nbnd; ii++) { + i = bndind[ii]; + if (where[i] == k && xadj[i] < xadj[i+1]) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + jj = adjncy[j]; + if (where[jj] != k) { + ASSERT(bndptr[jj] != -1); + ASSERTP(vmap[jj] != -1, ("%d %d %d\n", jj, vmap[jj], graph->bndptr[jj])); + badjncy[l++] = vmap[jj]; + } + } + bxadj[++bnvtxs[k]] = l; + } + } + } + + ASSERT(l <= bnedges[0]+bnedges[1]); + + MinCover(bxadj, badjncy, bnvtxs[0], bnvtxs[1], cover, &csize); + + IFSET(ctrl->dbglvl, DBG_SEPINFO, + printf("Nvtxs: %6d, [%5d %5d], Cut: %6d, SS: [%6d %6d], Cover: %6d\n", nvtxs, graph->pwgts[0], graph->pwgts[1], graph->mincut, bnvtxs[0], bnvtxs[1]-bnvtxs[0], csize)); + + for (i=0; i<csize; i++) { + j = ivmap[cover[i]]; + where[j] = 2; + } + + GKfree(&bxadj, &badjncy, LTERM); + + for (i=0; i<nbnd; i++) + bndptr[bndind[i]] = -1; + for (nbnd=i=0; i<nvtxs; i++) { + if (where[i] == 2) { + bndind[nbnd] = i; + bndptr[i] = nbnd++; + } + } + } + else { + IFSET(ctrl->dbglvl, DBG_SEPINFO, + printf("Nvtxs: %6d, [%5d %5d], Cut: %6d, SS: [%6d %6d], Cover: %6d\n", nvtxs, graph->pwgts[0], graph->pwgts[1], graph->mincut, 0, 0, 0)); + } + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, graph->nbnd); + idxwspacefree(ctrl, graph->nbnd); + graph->nbnd = nbnd; + + + ASSERT(IsSeparable(graph)); +} + + + +/************************************************************************* +* This function takes a bisection and constructs a minimum weight vertex +* separator out of it. It uses an unweighted minimum-cover algorithm +* followed by node-based separator refinement. +**************************************************************************/ +void ConstructMinCoverSeparator(CtrlType *ctrl, GraphType *graph, float ubfactor) +{ + int i, ii, j, jj, k, l, nvtxs, nbnd, bnvtxs[3], bnedges[2], csize; + idxtype *xadj, *adjncy, *bxadj, *badjncy; + idxtype *where, *bndind, *bndptr, *vmap, *ivmap, *cover; + + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + + nbnd = graph->nbnd; + bndind = graph->bndind; + bndptr = graph->bndptr; + where = graph->where; + + vmap = idxwspacemalloc(ctrl, nvtxs); + ivmap = idxwspacemalloc(ctrl, nbnd); + cover = idxwspacemalloc(ctrl, nbnd); + + if (nbnd > 0) { + /* Go through the boundary and determine the sizes of the bipartite graph */ + bnvtxs[0] = bnvtxs[1] = bnedges[0] = bnedges[1] = 0; + for (i=0; i<nbnd; i++) { + j = bndind[i]; + k = where[j]; + if (xadj[j+1]-xadj[j] > 0) { + bnvtxs[k]++; + bnedges[k] += xadj[j+1]-xadj[j]; + } + } + + bnvtxs[2] = bnvtxs[0]+bnvtxs[1]; + bnvtxs[1] = bnvtxs[0]; + bnvtxs[0] = 0; + + bxadj = idxmalloc(bnvtxs[2]+1, "ConstructMinCoverSeparator: bxadj"); + badjncy = idxmalloc(bnedges[0]+bnedges[1]+1, "ConstructMinCoverSeparator: badjncy"); + + /* Construct the ivmap and vmap */ + ASSERT(idxset(nvtxs, -1, vmap) == vmap); + for (i=0; i<nbnd; i++) { + j = bndind[i]; + k = where[j]; + if (xadj[j+1]-xadj[j] > 0) { + vmap[j] = bnvtxs[k]; + ivmap[bnvtxs[k]++] = j; + } + } + + /* OK, go through and put the vertices of each part starting from 0 */ + bnvtxs[1] = bnvtxs[0]; + bnvtxs[0] = 0; + bxadj[0] = l = 0; + for (k=0; k<2; k++) { + for (ii=0; ii<nbnd; ii++) { + i = bndind[ii]; + if (where[i] == k && xadj[i] < xadj[i+1]) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + jj = adjncy[j]; + if (where[jj] != k) { + ASSERT(bndptr[jj] != -1); + ASSERTP(vmap[jj] != -1, ("%d %d %d\n", jj, vmap[jj], graph->bndptr[jj])); + badjncy[l++] = vmap[jj]; + } + } + bxadj[++bnvtxs[k]] = l; + } + } + } + + ASSERT(l <= bnedges[0]+bnedges[1]); + + MinCover(bxadj, badjncy, bnvtxs[0], bnvtxs[1], cover, &csize); + + IFSET(ctrl->dbglvl, DBG_SEPINFO, + printf("Nvtxs: %6d, [%5d %5d], Cut: %6d, SS: [%6d %6d], Cover: %6d\n", nvtxs, graph->pwgts[0], graph->pwgts[1], graph->mincut, bnvtxs[0], bnvtxs[1]-bnvtxs[0], csize)); + + for (i=0; i<csize; i++) { + j = ivmap[cover[i]]; + where[j] = 2; + } + + GKfree(&bxadj, &badjncy, LTERM); + } + else { + IFSET(ctrl->dbglvl, DBG_SEPINFO, + printf("Nvtxs: %6d, [%5d %5d], Cut: %6d, SS: [%6d %6d], Cover: %6d\n", nvtxs, graph->pwgts[0], graph->pwgts[1], graph->mincut, 0, 0, 0)); + } + + /* Prepare to refine the vertex separator */ + idxcopy(nvtxs, graph->where, vmap); + GKfree(&graph->rdata, LTERM); + + Allocate2WayNodePartitionMemory(ctrl, graph); + idxcopy(nvtxs, vmap, graph->where); + idxwspacefree(ctrl, nvtxs+2*graph->nbnd); + + Compute2WayNodePartitionParams(ctrl, graph); + + ASSERT(CheckNodePartitionParams(graph)); + + FM_2WayNodeRefine_OneSided(ctrl, graph, ubfactor, 6); + + ASSERT(IsSeparable(graph)); +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/sfm.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/sfm.c new file mode 100644 index 0000000..eece33f --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/sfm.c @@ -0,0 +1,1069 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * sfm.c + * + * This file contains code that implementes an FM-based separator refinement + * + * Started 8/1/97 + * George + * + * $Id: sfm.c,v 1.2 2003/07/31 06:14:01 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function performs a node-based FM refinement +**************************************************************************/ +void FM_2WayNodeRefine(CtrlType *ctrl, GraphType *graph, float ubfactor, int npasses) +{ + int i, ii, j, k, jj, kk, nvtxs, nbnd, nswaps, nmind; + idxtype *xadj, *vwgt, *adjncy, *where, *pwgts, *edegrees, *bndind, *bndptr; + idxtype *mptr, *mind, *moved, *swaps, *perm; + PQueueType parts[2]; + NRInfoType *rinfo; + int higain, oldgain, mincut, initcut, mincutorder; + int pass, to, other, limit; + int badmaxpwgt, mindiff, newdiff; + int u[2], g[2]; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + vwgt = graph->vwgt; + + bndind = graph->bndind; + bndptr = graph->bndptr; + where = graph->where; + pwgts = graph->pwgts; + rinfo = graph->nrinfo; + + + i = ComputeMaxNodeGain(nvtxs, xadj, adjncy, vwgt); + PQueueInit(ctrl, &parts[0], nvtxs, i); + PQueueInit(ctrl, &parts[1], nvtxs, i); + + moved = idxwspacemalloc(ctrl, nvtxs); + swaps = idxwspacemalloc(ctrl, nvtxs); + mptr = idxwspacemalloc(ctrl, nvtxs+1); + mind = idxwspacemalloc(ctrl, nvtxs); + perm = idxwspacemalloc(ctrl, nvtxs); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("Partitions: [%6d %6d] Nv-Nb[%6d %6d]. ISep: %6d\n", pwgts[0], pwgts[1], graph->nvtxs, graph->nbnd, graph->mincut)); + + badmaxpwgt = (int)(ubfactor*(pwgts[0]+pwgts[1]+pwgts[2])/2); + + for (pass=0; pass<npasses; pass++) { + idxset(nvtxs, -1, moved); + PQueueReset(&parts[0]); + PQueueReset(&parts[1]); + + mincutorder = -1; + initcut = mincut = graph->mincut; + nbnd = graph->nbnd; + + RandomPermute(nbnd, perm, 1); + for (ii=0; ii<nbnd; ii++) { + i = bndind[perm[ii]]; + ASSERT(where[i] == 2); + PQueueInsert(&parts[0], i, vwgt[i]-rinfo[i].edegrees[1]); + PQueueInsert(&parts[1], i, vwgt[i]-rinfo[i].edegrees[0]); + } + + ASSERT(CheckNodeBnd(graph, nbnd)); + ASSERT(CheckNodePartitionParams(graph)); + + limit = (ctrl->oflags&OFLAG_COMPRESS ? amin(5*nbnd, 400) : amin(2*nbnd, 300)); + + /****************************************************** + * Get into the FM loop + *******************************************************/ + mptr[0] = nmind = 0; + mindiff = abs(pwgts[0]-pwgts[1]); + to = (pwgts[0] < pwgts[1] ? 0 : 1); + for (nswaps=0; nswaps<nvtxs; nswaps++) { + u[0] = PQueueSeeMax(&parts[0]); + u[1] = PQueueSeeMax(&parts[1]); + if (u[0] != -1 && u[1] != -1) { + g[0] = vwgt[u[0]]-rinfo[u[0]].edegrees[1]; + g[1] = vwgt[u[1]]-rinfo[u[1]].edegrees[0]; + + to = (g[0] > g[1] ? 0 : (g[0] < g[1] ? 1 : pass%2)); + /* to = (g[0] > g[1] ? 0 : (g[0] < g[1] ? 1 : (pwgts[0] < pwgts[1] ? 0 : 1))); */ + + if (pwgts[to]+vwgt[u[to]] > badmaxpwgt) + to = (to+1)%2; + } + else if (u[0] == -1 && u[1] == -1) { + break; + } + else if (u[0] != -1 && pwgts[0]+vwgt[u[0]] <= badmaxpwgt) { + to = 0; + } + else if (u[1] != -1 && pwgts[1]+vwgt[u[1]] <= badmaxpwgt) { + to = 1; + } + else + break; + + other = (to+1)%2; + + higain = PQueueGetMax(&parts[to]); + if (moved[higain] == -1) /* Delete if it was in the separator originally */ + PQueueDelete(&parts[other], higain, vwgt[higain]-rinfo[higain].edegrees[to]); + + ASSERT(bndptr[higain] != -1); + + pwgts[2] -= (vwgt[higain]-rinfo[higain].edegrees[other]); + + newdiff = abs(pwgts[to]+vwgt[higain] - (pwgts[other]-rinfo[higain].edegrees[other])); + if (pwgts[2] < mincut || (pwgts[2] == mincut && newdiff < mindiff)) { + mincut = pwgts[2]; + mincutorder = nswaps; + mindiff = newdiff; + } + else { + if (nswaps - mincutorder > limit) { + pwgts[2] += (vwgt[higain]-rinfo[higain].edegrees[other]); + break; /* No further improvement, break out */ + } + } + + BNDDelete(nbnd, bndind, bndptr, higain); + pwgts[to] += vwgt[higain]; + where[higain] = to; + moved[higain] = nswaps; + swaps[nswaps] = higain; + + + /********************************************************** + * Update the degrees of the affected nodes + ***********************************************************/ + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + if (where[k] == 2) { /* For the in-separator vertices modify their edegree[to] */ + oldgain = vwgt[k]-rinfo[k].edegrees[to]; + rinfo[k].edegrees[to] += vwgt[higain]; + if (moved[k] == -1 || moved[k] == -(2+other)) + PQueueUpdate(&parts[other], k, oldgain, oldgain-vwgt[higain]); + } + else if (where[k] == other) { /* This vertex is pulled into the separator */ + ASSERTP(bndptr[k] == -1, ("%d %d %d\n", k, bndptr[k], where[k])); + BNDInsert(nbnd, bndind, bndptr, k); + + mind[nmind++] = k; /* Keep track for rollback */ + where[k] = 2; + pwgts[other] -= vwgt[k]; + + edegrees = rinfo[k].edegrees; + edegrees[0] = edegrees[1] = 0; + for (jj=xadj[k]; jj<xadj[k+1]; jj++) { + kk = adjncy[jj]; + if (where[kk] != 2) + edegrees[where[kk]] += vwgt[kk]; + else { + oldgain = vwgt[kk]-rinfo[kk].edegrees[other]; + rinfo[kk].edegrees[other] -= vwgt[k]; + if (moved[kk] == -1 || moved[kk] == -(2+to)) + PQueueUpdate(&parts[to], kk, oldgain, oldgain+vwgt[k]); + } + } + + /* Insert the new vertex into the priority queue. Only one side! */ + if (moved[k] == -1) { + PQueueInsert(&parts[to], k, vwgt[k]-edegrees[other]); + moved[k] = -(2+to); + } + } + } + mptr[nswaps+1] = nmind; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, + printf("Moved %6d to %3d, Gain: %5d [%5d] [%4d %4d] \t[%5d %5d %5d]\n", higain, to, g[to], g[other], vwgt[u[to]], vwgt[u[other]], pwgts[0], pwgts[1], pwgts[2])); + + } + + + /**************************************************************** + * Roll back computation + *****************************************************************/ + for (nswaps--; nswaps>mincutorder; nswaps--) { + higain = swaps[nswaps]; + + ASSERT(CheckNodePartitionParams(graph)); + + to = where[higain]; + other = (to+1)%2; + INC_DEC(pwgts[2], pwgts[to], vwgt[higain]); + where[higain] = 2; + BNDInsert(nbnd, bndind, bndptr, higain); + + edegrees = rinfo[higain].edegrees; + edegrees[0] = edegrees[1] = 0; + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + if (where[k] == 2) + rinfo[k].edegrees[to] -= vwgt[higain]; + else + edegrees[where[k]] += vwgt[k]; + } + + /* Push nodes out of the separator */ + for (j=mptr[nswaps]; j<mptr[nswaps+1]; j++) { + k = mind[j]; + ASSERT(where[k] == 2); + where[k] = other; + INC_DEC(pwgts[other], pwgts[2], vwgt[k]); + BNDDelete(nbnd, bndind, bndptr, k); + for (jj=xadj[k]; jj<xadj[k+1]; jj++) { + kk = adjncy[jj]; + if (where[kk] == 2) + rinfo[kk].edegrees[other] += vwgt[k]; + } + } + } + + ASSERT(mincut == pwgts[2]); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\tMinimum sep: %6d at %5d, PWGTS: [%6d %6d], NBND: %6d\n", mincut, mincutorder, pwgts[0], pwgts[1], nbnd)); + + graph->mincut = mincut; + graph->nbnd = nbnd; + + if (mincutorder == -1 || mincut >= initcut) + break; + } + + PQueueFree(ctrl, &parts[0]); + PQueueFree(ctrl, &parts[1]); + + idxwspacefree(ctrl, nvtxs+1); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + +/************************************************************************* +* This function performs a node-based FM refinement +**************************************************************************/ +void FM_2WayNodeRefine2(CtrlType *ctrl, GraphType *graph, float ubfactor, int npasses) +{ + int i, ii, j, k, jj, kk, nvtxs, nbnd, nswaps, nmind; + idxtype *xadj, *vwgt, *adjncy, *where, *pwgts, *edegrees, *bndind, *bndptr; + idxtype *mptr, *mind, *moved, *swaps, *perm; + PQueueType parts[2]; + NRInfoType *rinfo; + int higain, oldgain, mincut, initcut, mincutorder; + int pass, to, other, limit; + int badmaxpwgt, mindiff, newdiff; + int u[2], g[2]; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + vwgt = graph->vwgt; + + bndind = graph->bndind; + bndptr = graph->bndptr; + where = graph->where; + pwgts = graph->pwgts; + rinfo = graph->nrinfo; + + + i = ComputeMaxNodeGain(nvtxs, xadj, adjncy, vwgt); + PQueueInit(ctrl, &parts[0], nvtxs, i); + PQueueInit(ctrl, &parts[1], nvtxs, i); + + moved = idxwspacemalloc(ctrl, nvtxs); + swaps = idxwspacemalloc(ctrl, nvtxs); + mptr = idxwspacemalloc(ctrl, nvtxs+1); + mind = idxwspacemalloc(ctrl, nvtxs); + perm = idxwspacemalloc(ctrl, nvtxs); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("Partitions: [%6d %6d] Nv-Nb[%6d %6d]. ISep: %6d\n", pwgts[0], pwgts[1], graph->nvtxs, graph->nbnd, graph->mincut)); + + badmaxpwgt = (int)(ubfactor*(pwgts[0]+pwgts[1]+pwgts[2])/2); + + for (pass=0; pass<npasses; pass++) { + idxset(nvtxs, -1, moved); + PQueueReset(&parts[0]); + PQueueReset(&parts[1]); + + mincutorder = -1; + initcut = mincut = graph->mincut; + nbnd = graph->nbnd; + + RandomPermute(nbnd, perm, 1); + for (ii=0; ii<nbnd; ii++) { + i = bndind[perm[ii]]; + ASSERT(where[i] == 2); + PQueueInsert(&parts[0], i, vwgt[i]-rinfo[i].edegrees[1]); + PQueueInsert(&parts[1], i, vwgt[i]-rinfo[i].edegrees[0]); + } + + ASSERT(CheckNodeBnd(graph, nbnd)); + ASSERT(CheckNodePartitionParams(graph)); + + limit = (ctrl->oflags&OFLAG_COMPRESS ? amin(5*nbnd, 400) : amin(2*nbnd, 300)); + + /****************************************************** + * Get into the FM loop + *******************************************************/ + mptr[0] = nmind = 0; + mindiff = abs(pwgts[0]-pwgts[1]); + to = (pwgts[0] < pwgts[1] ? 0 : 1); + for (nswaps=0; nswaps<nvtxs; nswaps++) { + badmaxpwgt = (int)(ubfactor*(pwgts[0]+pwgts[1]+pwgts[2]/2)/2); + + u[0] = PQueueSeeMax(&parts[0]); + u[1] = PQueueSeeMax(&parts[1]); + if (u[0] != -1 && u[1] != -1) { + g[0] = vwgt[u[0]]-rinfo[u[0]].edegrees[1]; + g[1] = vwgt[u[1]]-rinfo[u[1]].edegrees[0]; + + to = (g[0] > g[1] ? 0 : (g[0] < g[1] ? 1 : pass%2)); + /* to = (g[0] > g[1] ? 0 : (g[0] < g[1] ? 1 : (pwgts[0] < pwgts[1] ? 0 : 1))); */ + + if (pwgts[to]+vwgt[u[to]] > badmaxpwgt) + to = (to+1)%2; + } + else if (u[0] == -1 && u[1] == -1) { + break; + } + else if (u[0] != -1 && pwgts[0]+vwgt[u[0]] <= badmaxpwgt) { + to = 0; + } + else if (u[1] != -1 && pwgts[1]+vwgt[u[1]] <= badmaxpwgt) { + to = 1; + } + else + break; + + other = (to+1)%2; + + higain = PQueueGetMax(&parts[to]); + if (moved[higain] == -1) /* Delete if it was in the separator originally */ + PQueueDelete(&parts[other], higain, vwgt[higain]-rinfo[higain].edegrees[to]); + + ASSERT(bndptr[higain] != -1); + + pwgts[2] -= (vwgt[higain]-rinfo[higain].edegrees[other]); + + newdiff = abs(pwgts[to]+vwgt[higain] - (pwgts[other]-rinfo[higain].edegrees[other])); + if (pwgts[2] < mincut || (pwgts[2] == mincut && newdiff < mindiff)) { + mincut = pwgts[2]; + mincutorder = nswaps; + mindiff = newdiff; + } + else { + if (nswaps - mincutorder > limit) { + pwgts[2] += (vwgt[higain]-rinfo[higain].edegrees[other]); + break; /* No further improvement, break out */ + } + } + + BNDDelete(nbnd, bndind, bndptr, higain); + pwgts[to] += vwgt[higain]; + where[higain] = to; + moved[higain] = nswaps; + swaps[nswaps] = higain; + + + /********************************************************** + * Update the degrees of the affected nodes + ***********************************************************/ + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + if (where[k] == 2) { /* For the in-separator vertices modify their edegree[to] */ + oldgain = vwgt[k]-rinfo[k].edegrees[to]; + rinfo[k].edegrees[to] += vwgt[higain]; + if (moved[k] == -1 || moved[k] == -(2+other)) + PQueueUpdate(&parts[other], k, oldgain, oldgain-vwgt[higain]); + } + else if (where[k] == other) { /* This vertex is pulled into the separator */ + ASSERTP(bndptr[k] == -1, ("%d %d %d\n", k, bndptr[k], where[k])); + BNDInsert(nbnd, bndind, bndptr, k); + + mind[nmind++] = k; /* Keep track for rollback */ + where[k] = 2; + pwgts[other] -= vwgt[k]; + + edegrees = rinfo[k].edegrees; + edegrees[0] = edegrees[1] = 0; + for (jj=xadj[k]; jj<xadj[k+1]; jj++) { + kk = adjncy[jj]; + if (where[kk] != 2) + edegrees[where[kk]] += vwgt[kk]; + else { + oldgain = vwgt[kk]-rinfo[kk].edegrees[other]; + rinfo[kk].edegrees[other] -= vwgt[k]; + if (moved[kk] == -1 || moved[kk] == -(2+to)) + PQueueUpdate(&parts[to], kk, oldgain, oldgain+vwgt[k]); + } + } + + /* Insert the new vertex into the priority queue. Only one side! */ + if (moved[k] == -1) { + PQueueInsert(&parts[to], k, vwgt[k]-edegrees[other]); + moved[k] = -(2+to); + } + } + } + mptr[nswaps+1] = nmind; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, + printf("Moved %6d to %3d, Gain: %5d [%5d] [%4d %4d] \t[%5d %5d %5d]\n", higain, to, g[to], g[other], vwgt[u[to]], vwgt[u[other]], pwgts[0], pwgts[1], pwgts[2])); + + } + + + /**************************************************************** + * Roll back computation + *****************************************************************/ + for (nswaps--; nswaps>mincutorder; nswaps--) { + higain = swaps[nswaps]; + + ASSERT(CheckNodePartitionParams(graph)); + + to = where[higain]; + other = (to+1)%2; + INC_DEC(pwgts[2], pwgts[to], vwgt[higain]); + where[higain] = 2; + BNDInsert(nbnd, bndind, bndptr, higain); + + edegrees = rinfo[higain].edegrees; + edegrees[0] = edegrees[1] = 0; + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + if (where[k] == 2) + rinfo[k].edegrees[to] -= vwgt[higain]; + else + edegrees[where[k]] += vwgt[k]; + } + + /* Push nodes out of the separator */ + for (j=mptr[nswaps]; j<mptr[nswaps+1]; j++) { + k = mind[j]; + ASSERT(where[k] == 2); + where[k] = other; + INC_DEC(pwgts[other], pwgts[2], vwgt[k]); + BNDDelete(nbnd, bndind, bndptr, k); + for (jj=xadj[k]; jj<xadj[k+1]; jj++) { + kk = adjncy[jj]; + if (where[kk] == 2) + rinfo[kk].edegrees[other] += vwgt[k]; + } + } + } + + ASSERT(mincut == pwgts[2]); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\tMinimum sep: %6d at %5d, PWGTS: [%6d %6d], NBND: %6d\n", mincut, mincutorder, pwgts[0], pwgts[1], nbnd)); + + graph->mincut = mincut; + graph->nbnd = nbnd; + + if (mincutorder == -1 || mincut >= initcut) + break; + } + + PQueueFree(ctrl, &parts[0]); + PQueueFree(ctrl, &parts[1]); + + idxwspacefree(ctrl, nvtxs+1); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + +/************************************************************************* +* This function performs a node-based FM refinement +**************************************************************************/ +void FM_2WayNodeRefineEqWgt(CtrlType *ctrl, GraphType *graph, int npasses) +{ + int i, ii, j, k, jj, kk, nvtxs, nbnd, nswaps, nmind; + idxtype *xadj, *vwgt, *adjncy, *where, *pwgts, *edegrees, *bndind, *bndptr; + idxtype *mptr, *mind, *moved, *swaps, *perm; + PQueueType parts[2]; + NRInfoType *rinfo; + int higain, oldgain, mincut, initcut, mincutorder; + int pass, to, other, limit; + int mindiff, newdiff; + int u[2], g[2]; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + vwgt = graph->vwgt; + + bndind = graph->bndind; + bndptr = graph->bndptr; + where = graph->where; + pwgts = graph->pwgts; + rinfo = graph->nrinfo; + + + i = ComputeMaxNodeGain(nvtxs, xadj, adjncy, vwgt); + PQueueInit(ctrl, &parts[0], nvtxs, i); + PQueueInit(ctrl, &parts[1], nvtxs, i); + + moved = idxwspacemalloc(ctrl, nvtxs); + swaps = idxwspacemalloc(ctrl, nvtxs); + mptr = idxwspacemalloc(ctrl, nvtxs+1); + mind = idxwspacemalloc(ctrl, nvtxs); + perm = idxwspacemalloc(ctrl, nvtxs); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("Partitions: [%6d %6d] Nv-Nb[%6d %6d]. ISep: %6d\n", pwgts[0], pwgts[1], graph->nvtxs, graph->nbnd, graph->mincut)); + + for (pass=0; pass<npasses; pass++) { + idxset(nvtxs, -1, moved); + PQueueReset(&parts[0]); + PQueueReset(&parts[1]); + + mincutorder = -1; + initcut = mincut = graph->mincut; + nbnd = graph->nbnd; + + RandomPermute(nbnd, perm, 1); + for (ii=0; ii<nbnd; ii++) { + i = bndind[perm[ii]]; + ASSERT(where[i] == 2); + PQueueInsert(&parts[0], i, vwgt[i]-rinfo[i].edegrees[1]); + PQueueInsert(&parts[1], i, vwgt[i]-rinfo[i].edegrees[0]); + } + + ASSERT(CheckNodeBnd(graph, nbnd)); + ASSERT(CheckNodePartitionParams(graph)); + + limit = (ctrl->oflags&OFLAG_COMPRESS ? amin(5*nbnd, 400) : amin(2*nbnd, 300)); + + /****************************************************** + * Get into the FM loop + *******************************************************/ + mptr[0] = nmind = 0; + mindiff = abs(pwgts[0]-pwgts[1]); + to = (pwgts[0] < pwgts[1] ? 0 : 1); + for (nswaps=0; nswaps<nvtxs; nswaps++) { + to = (pwgts[0] < pwgts[1] ? 0 : 1); + + if (pwgts[0] == pwgts[1]) { + u[0] = PQueueSeeMax(&parts[0]); + u[1] = PQueueSeeMax(&parts[1]); + if (u[0] != -1 && u[1] != -1) { + g[0] = vwgt[u[0]]-rinfo[u[0]].edegrees[1]; + g[1] = vwgt[u[1]]-rinfo[u[1]].edegrees[0]; + + to = (g[0] > g[1] ? 0 : (g[0] < g[1] ? 1 : pass%2)); + } + } + other = (to+1)%2; + + if ((higain = PQueueGetMax(&parts[to])) == -1) + break; + + if (moved[higain] == -1) /* Delete if it was in the separator originally */ + PQueueDelete(&parts[other], higain, vwgt[higain]-rinfo[higain].edegrees[to]); + + ASSERT(bndptr[higain] != -1); + + pwgts[2] -= (vwgt[higain]-rinfo[higain].edegrees[other]); + + newdiff = abs(pwgts[to]+vwgt[higain] - (pwgts[other]-rinfo[higain].edegrees[other])); + if (pwgts[2] < mincut || (pwgts[2] == mincut && newdiff < mindiff)) { + mincut = pwgts[2]; + mincutorder = nswaps; + mindiff = newdiff; + } + else { + if (nswaps - mincutorder > limit) { + pwgts[2] += (vwgt[higain]-rinfo[higain].edegrees[other]); + break; /* No further improvement, break out */ + } + } + + BNDDelete(nbnd, bndind, bndptr, higain); + pwgts[to] += vwgt[higain]; + where[higain] = to; + moved[higain] = nswaps; + swaps[nswaps] = higain; + + + /********************************************************** + * Update the degrees of the affected nodes + ***********************************************************/ + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + if (where[k] == 2) { /* For the in-separator vertices modify their edegree[to] */ + oldgain = vwgt[k]-rinfo[k].edegrees[to]; + rinfo[k].edegrees[to] += vwgt[higain]; + if (moved[k] == -1 || moved[k] == -(2+other)) + PQueueUpdate(&parts[other], k, oldgain, oldgain-vwgt[higain]); + } + else if (where[k] == other) { /* This vertex is pulled into the separator */ + ASSERTP(bndptr[k] == -1, ("%d %d %d\n", k, bndptr[k], where[k])); + BNDInsert(nbnd, bndind, bndptr, k); + + mind[nmind++] = k; /* Keep track for rollback */ + where[k] = 2; + pwgts[other] -= vwgt[k]; + + edegrees = rinfo[k].edegrees; + edegrees[0] = edegrees[1] = 0; + for (jj=xadj[k]; jj<xadj[k+1]; jj++) { + kk = adjncy[jj]; + if (where[kk] != 2) + edegrees[where[kk]] += vwgt[kk]; + else { + oldgain = vwgt[kk]-rinfo[kk].edegrees[other]; + rinfo[kk].edegrees[other] -= vwgt[k]; + if (moved[kk] == -1 || moved[kk] == -(2+to)) + PQueueUpdate(&parts[to], kk, oldgain, oldgain+vwgt[k]); + } + } + + /* Insert the new vertex into the priority queue. Only one side! */ + if (moved[k] == -1) { + PQueueInsert(&parts[to], k, vwgt[k]-edegrees[other]); + moved[k] = -(2+to); + } + } + } + mptr[nswaps+1] = nmind; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, + printf("Moved %6d to %3d, Gain: %5d [%5d] [%4d %4d] \t[%5d %5d %5d]\n", higain, to, g[to], g[other], vwgt[u[to]], vwgt[u[other]], pwgts[0], pwgts[1], pwgts[2])); + + } + + + /**************************************************************** + * Roll back computation + *****************************************************************/ + for (nswaps--; nswaps>mincutorder; nswaps--) { + higain = swaps[nswaps]; + + ASSERT(CheckNodePartitionParams(graph)); + + to = where[higain]; + other = (to+1)%2; + INC_DEC(pwgts[2], pwgts[to], vwgt[higain]); + where[higain] = 2; + BNDInsert(nbnd, bndind, bndptr, higain); + + edegrees = rinfo[higain].edegrees; + edegrees[0] = edegrees[1] = 0; + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + if (where[k] == 2) + rinfo[k].edegrees[to] -= vwgt[higain]; + else + edegrees[where[k]] += vwgt[k]; + } + + /* Push nodes out of the separator */ + for (j=mptr[nswaps]; j<mptr[nswaps+1]; j++) { + k = mind[j]; + ASSERT(where[k] == 2); + where[k] = other; + INC_DEC(pwgts[other], pwgts[2], vwgt[k]); + BNDDelete(nbnd, bndind, bndptr, k); + for (jj=xadj[k]; jj<xadj[k+1]; jj++) { + kk = adjncy[jj]; + if (where[kk] == 2) + rinfo[kk].edegrees[other] += vwgt[k]; + } + } + } + + ASSERT(mincut == pwgts[2]); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\tMinimum sep: %6d at %5d, PWGTS: [%6d %6d], NBND: %6d\n", mincut, mincutorder, pwgts[0], pwgts[1], nbnd)); + + graph->mincut = mincut; + graph->nbnd = nbnd; + + if (mincutorder == -1 || mincut >= initcut) + break; + } + + PQueueFree(ctrl, &parts[0]); + PQueueFree(ctrl, &parts[1]); + + idxwspacefree(ctrl, nvtxs+1); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + +/************************************************************************* +* This function performs a node-based FM refinement. This is the +* one-way version +**************************************************************************/ +void FM_2WayNodeRefine_OneSided(CtrlType *ctrl, GraphType *graph, float ubfactor, int npasses) +{ + int i, ii, j, k, jj, kk, nvtxs, nbnd, nswaps, nmind; + idxtype *xadj, *vwgt, *adjncy, *where, *pwgts, *edegrees, *bndind, *bndptr; + idxtype *mptr, *mind, *swaps, *perm; + PQueueType parts; + NRInfoType *rinfo; + int higain, oldgain, mincut, initcut, mincutorder; + int pass, to, other, limit; + int badmaxpwgt, mindiff, newdiff; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + vwgt = graph->vwgt; + + bndind = graph->bndind; + bndptr = graph->bndptr; + where = graph->where; + pwgts = graph->pwgts; + rinfo = graph->nrinfo; + + PQueueInit(ctrl, &parts, nvtxs, ComputeMaxNodeGain(nvtxs, xadj, adjncy, vwgt)); + + perm = idxwspacemalloc(ctrl, nvtxs); + swaps = idxwspacemalloc(ctrl, nvtxs); + mptr = idxwspacemalloc(ctrl, nvtxs+1); + mind = idxwspacemalloc(ctrl, nvtxs); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("Partitions-N1: [%6d %6d] Nv-Nb[%6d %6d]. ISep: %6d\n", pwgts[0], pwgts[1], graph->nvtxs, graph->nbnd, graph->mincut)); + + badmaxpwgt = (int)(ubfactor*(pwgts[0]+pwgts[1]+pwgts[2])/2); + + to = (pwgts[0] < pwgts[1] ? 1 : 0); + for (pass=0; pass<npasses; pass++) { + other = to; + to = (to+1)%2; + + PQueueReset(&parts); + + mincutorder = -1; + initcut = mincut = graph->mincut; + nbnd = graph->nbnd; + + RandomPermute(nbnd, perm, 1); + for (ii=0; ii<nbnd; ii++) { + i = bndind[perm[ii]]; + ASSERT(where[i] == 2); + PQueueInsert(&parts, i, vwgt[i]-rinfo[i].edegrees[other]); + } + + ASSERT(CheckNodeBnd(graph, nbnd)); + ASSERT(CheckNodePartitionParams(graph)); + + limit = (ctrl->oflags&OFLAG_COMPRESS ? amin(5*nbnd, 400) : amin(2*nbnd, 300)); + + /****************************************************** + * Get into the FM loop + *******************************************************/ + mptr[0] = nmind = 0; + mindiff = abs(pwgts[0]-pwgts[1]); + for (nswaps=0; nswaps<nvtxs; nswaps++) { + + if ((higain = PQueueGetMax(&parts)) == -1) + break; + + ASSERT(bndptr[higain] != -1); + + if (pwgts[to]+vwgt[higain] > badmaxpwgt) + break; /* No point going any further. Balance will be bad */ + + pwgts[2] -= (vwgt[higain]-rinfo[higain].edegrees[other]); + + newdiff = abs(pwgts[to]+vwgt[higain] - (pwgts[other]-rinfo[higain].edegrees[other])); + if (pwgts[2] < mincut || (pwgts[2] == mincut && newdiff < mindiff)) { + mincut = pwgts[2]; + mincutorder = nswaps; + mindiff = newdiff; + } + else { + if (nswaps - mincutorder > limit) { + pwgts[2] += (vwgt[higain]-rinfo[higain].edegrees[other]); + break; /* No further improvement, break out */ + } + } + + BNDDelete(nbnd, bndind, bndptr, higain); + pwgts[to] += vwgt[higain]; + where[higain] = to; + swaps[nswaps] = higain; + + + /********************************************************** + * Update the degrees of the affected nodes + ***********************************************************/ + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + if (where[k] == 2) { /* For the in-separator vertices modify their edegree[to] */ + rinfo[k].edegrees[to] += vwgt[higain]; + } + else if (where[k] == other) { /* This vertex is pulled into the separator */ + ASSERTP(bndptr[k] == -1, ("%d %d %d\n", k, bndptr[k], where[k])); + BNDInsert(nbnd, bndind, bndptr, k); + + mind[nmind++] = k; /* Keep track for rollback */ + where[k] = 2; + pwgts[other] -= vwgt[k]; + + edegrees = rinfo[k].edegrees; + edegrees[0] = edegrees[1] = 0; + for (jj=xadj[k]; jj<xadj[k+1]; jj++) { + kk = adjncy[jj]; + if (where[kk] != 2) + edegrees[where[kk]] += vwgt[kk]; + else { + oldgain = vwgt[kk]-rinfo[kk].edegrees[other]; + rinfo[kk].edegrees[other] -= vwgt[k]; + + /* Since the moves are one-sided this vertex has not been moved yet */ + PQueueUpdateUp(&parts, kk, oldgain, oldgain+vwgt[k]); + } + } + + /* Insert the new vertex into the priority queue. Safe due to one-sided moves */ + PQueueInsert(&parts, k, vwgt[k]-edegrees[other]); + } + } + mptr[nswaps+1] = nmind; + + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, + printf("Moved %6d to %3d, Gain: %5d [%5d] \t[%5d %5d %5d] [%3d %2d]\n", + higain, to, (vwgt[higain]-rinfo[higain].edegrees[other]), vwgt[higain], pwgts[0], pwgts[1], pwgts[2], nswaps, limit)); + + } + + + /**************************************************************** + * Roll back computation + *****************************************************************/ + for (nswaps--; nswaps>mincutorder; nswaps--) { + higain = swaps[nswaps]; + + ASSERT(CheckNodePartitionParams(graph)); + ASSERT(where[higain] == to); + + INC_DEC(pwgts[2], pwgts[to], vwgt[higain]); + where[higain] = 2; + BNDInsert(nbnd, bndind, bndptr, higain); + + edegrees = rinfo[higain].edegrees; + edegrees[0] = edegrees[1] = 0; + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + if (where[k] == 2) + rinfo[k].edegrees[to] -= vwgt[higain]; + else + edegrees[where[k]] += vwgt[k]; + } + + /* Push nodes out of the separator */ + for (j=mptr[nswaps]; j<mptr[nswaps+1]; j++) { + k = mind[j]; + ASSERT(where[k] == 2); + where[k] = other; + INC_DEC(pwgts[other], pwgts[2], vwgt[k]); + BNDDelete(nbnd, bndind, bndptr, k); + for (jj=xadj[k]; jj<xadj[k+1]; jj++) { + kk = adjncy[jj]; + if (where[kk] == 2) + rinfo[kk].edegrees[other] += vwgt[k]; + } + } + } + + ASSERT(mincut == pwgts[2]); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\tMinimum sep: %6d at %5d, PWGTS: [%6d %6d], NBND: %6d\n", mincut, mincutorder, pwgts[0], pwgts[1], nbnd)); + + graph->mincut = mincut; + graph->nbnd = nbnd; + + if (pass%2 == 1 && (mincutorder == -1 || mincut >= initcut)) + break; + } + + PQueueFree(ctrl, &parts); + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs+1); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + + +/************************************************************************* +* This function performs a node-based FM refinement +**************************************************************************/ +void FM_2WayNodeBalance(CtrlType *ctrl, GraphType *graph, float ubfactor) +{ + int i, ii, j, k, jj, kk, nvtxs, nbnd, nswaps; + idxtype *xadj, *vwgt, *adjncy, *where, *pwgts, *edegrees, *bndind, *bndptr; + idxtype *perm, *moved; + PQueueType parts; + NRInfoType *rinfo; + int higain, oldgain; + int pass, to, other; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + vwgt = graph->vwgt; + + bndind = graph->bndind; + bndptr = graph->bndptr; + where = graph->where; + pwgts = graph->pwgts; + rinfo = graph->nrinfo; + + if (abs(pwgts[0]-pwgts[1]) < (int)((ubfactor-1.0)*(pwgts[0]+pwgts[1]))) + return; + if (abs(pwgts[0]-pwgts[1]) < 3*idxsum(nvtxs, vwgt)/nvtxs) + return; + + to = (pwgts[0] < pwgts[1] ? 0 : 1); + other = (to+1)%2; + + PQueueInit(ctrl, &parts, nvtxs, ComputeMaxNodeGain(nvtxs, xadj, adjncy, vwgt)); + + perm = idxwspacemalloc(ctrl, nvtxs); + moved = idxset(nvtxs, -1, idxwspacemalloc(ctrl, nvtxs)); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("Partitions: [%6d %6d] Nv-Nb[%6d %6d]. ISep: %6d [B]\n", pwgts[0], pwgts[1], graph->nvtxs, graph->nbnd, graph->mincut)); + + nbnd = graph->nbnd; + RandomPermute(nbnd, perm, 1); + for (ii=0; ii<nbnd; ii++) { + i = bndind[perm[ii]]; + ASSERT(where[i] == 2); + PQueueInsert(&parts, i, vwgt[i]-rinfo[i].edegrees[other]); + } + + ASSERT(CheckNodeBnd(graph, nbnd)); + ASSERT(CheckNodePartitionParams(graph)); + + /****************************************************** + * Get into the FM loop + *******************************************************/ + for (nswaps=0; nswaps<nvtxs; nswaps++) { + if ((higain = PQueueGetMax(&parts)) == -1) + break; + + moved[higain] = 1; + + if (pwgts[other] - rinfo[higain].edegrees[other] < (pwgts[0]+pwgts[1])/2) + continue; +#ifdef XXX + if (pwgts[other] - rinfo[higain].edegrees[other] < pwgts[to]+vwgt[higain]) + break; +#endif + + ASSERT(bndptr[higain] != -1); + + pwgts[2] -= (vwgt[higain]-rinfo[higain].edegrees[other]); + + BNDDelete(nbnd, bndind, bndptr, higain); + pwgts[to] += vwgt[higain]; + where[higain] = to; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, + printf("Moved %6d to %3d, Gain: %3d, \t[%5d %5d %5d]\n", higain, to, vwgt[higain]-rinfo[higain].edegrees[other], pwgts[0], pwgts[1], pwgts[2])); + + + /********************************************************** + * Update the degrees of the affected nodes + ***********************************************************/ + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + if (where[k] == 2) { /* For the in-separator vertices modify their edegree[to] */ + rinfo[k].edegrees[to] += vwgt[higain]; + } + else if (where[k] == other) { /* This vertex is pulled into the separator */ + ASSERTP(bndptr[k] == -1, ("%d %d %d\n", k, bndptr[k], where[k])); + BNDInsert(nbnd, bndind, bndptr, k); + + where[k] = 2; + pwgts[other] -= vwgt[k]; + + edegrees = rinfo[k].edegrees; + edegrees[0] = edegrees[1] = 0; + for (jj=xadj[k]; jj<xadj[k+1]; jj++) { + kk = adjncy[jj]; + if (where[kk] != 2) + edegrees[where[kk]] += vwgt[kk]; + else { + ASSERT(bndptr[kk] != -1); + oldgain = vwgt[kk]-rinfo[kk].edegrees[other]; + rinfo[kk].edegrees[other] -= vwgt[k]; + + if (moved[kk] == -1) + PQueueUpdateUp(&parts, kk, oldgain, oldgain+vwgt[k]); + } + } + + /* Insert the new vertex into the priority queue */ + PQueueInsert(&parts, k, vwgt[k]-edegrees[other]); + } + } + + if (pwgts[to] > pwgts[other]) + break; + } + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\tBalanced sep: %6d at %4d, PWGTS: [%6d %6d], NBND: %6d\n", pwgts[2], nswaps, pwgts[0], pwgts[1], nbnd)); + + graph->mincut = pwgts[2]; + graph->nbnd = nbnd; + + + PQueueFree(ctrl, &parts); + + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); +} + + +/************************************************************************* +* This function computes the maximum possible gain for a vertex +**************************************************************************/ +int ComputeMaxNodeGain(int nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt) +{ + int i, j, k, max; + + max = 0; + for (j=xadj[0]; j<xadj[1]; j++) + max += vwgt[adjncy[j]]; + + for (i=1; i<nvtxs; i++) { + for (k=0, j=xadj[i]; j<xadj[i+1]; j++) + k += vwgt[adjncy[j]]; + if (max < k) + max = k; + } + + return max; +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/srefine.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/srefine.c new file mode 100644 index 0000000..cd02cb9 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/srefine.c @@ -0,0 +1,169 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * srefine.c + * + * This file contains code for the separator refinement algortihms + * + * Started 8/1/97 + * George + * + * $Id: srefine.c,v 1.1 2003/07/16 15:55:18 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function is the entry point of the separator refinement +**************************************************************************/ +void Refine2WayNode(CtrlType *ctrl, GraphType *orggraph, GraphType *graph, float ubfactor) +{ + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->UncoarsenTmr)); + + for (;;) { + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->RefTmr)); + if (ctrl->RType != 15) + FM_2WayNodeBalance(ctrl, graph, ubfactor); + + switch (ctrl->RType) { + case 1: + FM_2WayNodeRefine(ctrl, graph, ubfactor, 8); + break; + case 2: + FM_2WayNodeRefine_OneSided(ctrl, graph, ubfactor, 8); + break; + case 3: + FM_2WayNodeRefine(ctrl, graph, ubfactor, 8); + FM_2WayNodeRefine_OneSided(ctrl, graph, ubfactor, 8); + break; + case 4: + FM_2WayNodeRefine_OneSided(ctrl, graph, ubfactor, 8); + FM_2WayNodeRefine(ctrl, graph, ubfactor, 8); + break; + case 5: + FM_2WayNodeRefineEqWgt(ctrl, graph, 8); + break; + } + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->RefTmr)); + + if (graph == orggraph) + break; + + graph = graph->finer; + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ProjectTmr)); + Project2WayNodePartition(ctrl, graph); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ProjectTmr)); + } + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->UncoarsenTmr)); +} + + +/************************************************************************* +* This function allocates memory for 2-way edge refinement +**************************************************************************/ +void Allocate2WayNodePartitionMemory(CtrlType *ctrl, GraphType *graph) +{ + int nvtxs, pad64; + + nvtxs = graph->nvtxs; + + pad64 = (3*nvtxs+3)%2; + + graph->rdata = idxmalloc(3*nvtxs+3+(sizeof(NRInfoType)/sizeof(idxtype))*nvtxs+pad64, "Allocate2WayPartitionMemory: rdata"); + graph->pwgts = graph->rdata; + graph->where = graph->rdata + 3; + graph->bndptr = graph->rdata + nvtxs + 3; + graph->bndind = graph->rdata + 2*nvtxs + 3; + graph->nrinfo = (NRInfoType *)(graph->rdata + 3*nvtxs + 3 + pad64); +} + + + +/************************************************************************* +* This function computes the initial id/ed +**************************************************************************/ +void Compute2WayNodePartitionParams(CtrlType *ctrl, GraphType *graph) +{ + int i, j, k, l, nvtxs, nbnd; + idxtype *xadj, *adjncy, *adjwgt, *vwgt; + idxtype *where, *pwgts, *bndind, *bndptr, *edegrees; + NRInfoType *rinfo; + int me, other; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + where = graph->where; + rinfo = graph->nrinfo; + pwgts = idxset(3, 0, graph->pwgts); + bndind = graph->bndind; + bndptr = idxset(nvtxs, -1, graph->bndptr); + + + /*------------------------------------------------------------ + / Compute now the separator external degrees + /------------------------------------------------------------*/ + nbnd = 0; + for (i=0; i<nvtxs; i++) { + me = where[i]; + pwgts[me] += vwgt[i]; + + ASSERT(me >=0 && me <= 2); + + if (me == 2) { /* If it is on the separator do some computations */ + BNDInsert(nbnd, bndind, bndptr, i); + + edegrees = rinfo[i].edegrees; + edegrees[0] = edegrees[1] = 0; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + other = where[adjncy[j]]; + if (other != 2) + edegrees[other] += vwgt[adjncy[j]]; + } + } + } + + ASSERT(CheckNodeBnd(graph, nbnd)); + + graph->mincut = pwgts[2]; + graph->nbnd = nbnd; +} + + +/************************************************************************* +* This function computes the initial id/ed +**************************************************************************/ +void Project2WayNodePartition(CtrlType *ctrl, GraphType *graph) +{ + int i, j, nvtxs; + idxtype *cmap, *where, *cwhere; + GraphType *cgraph; + + cgraph = graph->coarser; + cwhere = cgraph->where; + + nvtxs = graph->nvtxs; + cmap = graph->cmap; + + Allocate2WayNodePartitionMemory(ctrl, graph); + where = graph->where; + + /* Project the partition */ + for (i=0; i<nvtxs; i++) { + where[i] = cwhere[cmap[i]]; + ASSERTP(where[i] >= 0 && where[i] <= 2, ("%d %d %d %d\n", i, cmap[i], where[i], cwhere[cmap[i]])); + } + + FreeGraph(graph->coarser); + graph->coarser = NULL; + + Compute2WayNodePartitionParams(ctrl, graph); +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/stat.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/stat.c new file mode 100644 index 0000000..6156d6d --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/stat.c @@ -0,0 +1,316 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * stat.c + * + * This file computes various statistics + * + * Started 7/25/97 + * George + * + * $Id: stat.c,v 1.2 2003/07/24 18:39:12 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function computes cuts and balance information +**************************************************************************/ +void ComputePartitionInfo(GraphType *graph, int nparts, idxtype *where) +{ + int i, j, k, nvtxs, ncon, mustfree=0; + idxtype *xadj, *adjncy, *vwgt, *adjwgt, *kpwgts, *tmpptr; + idxtype *padjncy, *padjwgt, *padjcut; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + adjncy = graph->adjncy; + vwgt = graph->vwgt; + adjwgt = graph->adjwgt; + + if (vwgt == NULL) { + vwgt = graph->vwgt = idxsmalloc(nvtxs, 1, "vwgt"); + mustfree = 1; + } + if (adjwgt == NULL) { + adjwgt = graph->adjwgt = idxsmalloc(xadj[nvtxs], 1, "adjwgt"); + mustfree += 2; + } + + printf("%d-way Cut: %5d, Vol: %5d, ", nparts, ComputeCut(graph, where), ComputeVolume(graph, where)); + + /* Compute balance information */ + kpwgts = idxsmalloc(ncon*nparts, 0, "ComputePartitionInfo: kpwgts"); + + for (i=0; i<nvtxs; i++) { + for (j=0; j<ncon; j++) + kpwgts[where[i]*ncon+j] += vwgt[i*ncon+j]; + } + + if (ncon == 1) { + printf("\tBalance: %5.3f out of %5.3f\n", + 1.0*nparts*kpwgts[idxamax(nparts, kpwgts)]/(1.0*idxsum(nparts, kpwgts)), + 1.0*nparts*vwgt[idxamax(nvtxs, vwgt)]/(1.0*idxsum(nparts, kpwgts))); + } + else { + printf("\tBalance:"); + for (j=0; j<ncon; j++) + printf(" (%5.3f out of %5.3f)", + 1.0*nparts*kpwgts[ncon*idxamax_strd(nparts, kpwgts+j, ncon)+j]/(1.0*idxsum_strd(nparts, kpwgts+j, ncon)), + 1.0*nparts*vwgt[ncon*idxamax_strd(nvtxs, vwgt+j, ncon)+j]/(1.0*idxsum_strd(nparts, kpwgts+j, ncon))); + printf("\n"); + } + + + /* Compute p-adjncy information */ + padjncy = idxsmalloc(nparts*nparts, 0, "ComputePartitionInfo: padjncy"); + padjwgt = idxsmalloc(nparts*nparts, 0, "ComputePartitionInfo: padjwgt"); + padjcut = idxsmalloc(nparts*nparts, 0, "ComputePartitionInfo: padjwgt"); + + idxset(nparts, 0, kpwgts); + for (i=0; i<nvtxs; i++) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (where[i] != where[adjncy[j]]) { + padjncy[where[i]*nparts+where[adjncy[j]]] = 1; + padjcut[where[i]*nparts+where[adjncy[j]]] += adjwgt[j]; + if (kpwgts[where[adjncy[j]]] == 0) { + padjwgt[where[i]*nparts+where[adjncy[j]]]++; + kpwgts[where[adjncy[j]]] = 1; + } + } + } + for (j=xadj[i]; j<xadj[i+1]; j++) + kpwgts[where[adjncy[j]]] = 0; + } + + for (i=0; i<nparts; i++) + kpwgts[i] = idxsum(nparts, padjncy+i*nparts); + printf("Min/Max/Avg/Bal # of adjacent subdomains: %5d %5d %5.2f %7.3f\n", + kpwgts[idxamin(nparts, kpwgts)], kpwgts[idxamax(nparts, kpwgts)], + 1.0*idxsum(nparts, kpwgts)/(1.0*nparts), + 1.0*nparts*kpwgts[idxamax(nparts, kpwgts)]/(1.0*idxsum(nparts, kpwgts))); + + for (i=0; i<nparts; i++) + kpwgts[i] = idxsum(nparts, padjcut+i*nparts); + printf("Min/Max/Avg/Bal # of adjacent subdomain cuts: %5d %5d %5d %7.3f\n", + kpwgts[idxamin(nparts, kpwgts)], kpwgts[idxamax(nparts, kpwgts)], idxsum(nparts, kpwgts)/nparts, + 1.0*nparts*kpwgts[idxamax(nparts, kpwgts)]/(1.0*idxsum(nparts, kpwgts))); + + for (i=0; i<nparts; i++) + kpwgts[i] = idxsum(nparts, padjwgt+i*nparts); + printf("Min/Max/Avg/Bal/Frac # of interface nodes: %5d %5d %5d %7.3f %7.3f\n", + kpwgts[idxamin(nparts, kpwgts)], kpwgts[idxamax(nparts, kpwgts)], idxsum(nparts, kpwgts)/nparts, + 1.0*nparts*kpwgts[idxamax(nparts, kpwgts)]/(1.0*idxsum(nparts, kpwgts)), 1.0*idxsum(nparts, kpwgts)/(1.0*nvtxs)); + + tmpptr = graph->where; + graph->where = where; + for (i=0; i<nparts; i++) + IsConnectedSubdomain(NULL, graph, i, 1); + graph->where = tmpptr; + + if (mustfree == 1 || mustfree == 3) { + free(vwgt); + graph->vwgt = NULL; + } + if (mustfree == 2 || mustfree == 3) { + free(adjwgt); + graph->adjwgt = NULL; + } + + GKfree(&kpwgts, &padjncy, &padjwgt, &padjcut, LTERM); +} + + +/************************************************************************* +* This function computes cuts and balance information +**************************************************************************/ +void ComputePartitionInfoBipartite(GraphType *graph, int nparts, idxtype *where) +{ + int i, j, k, nvtxs, ncon, mustfree=0; + idxtype *xadj, *adjncy, *vwgt, *vsize, *adjwgt, *kpwgts, *tmpptr; + idxtype *padjncy, *padjwgt, *padjcut; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + adjncy = graph->adjncy; + vwgt = graph->vwgt; + vsize = graph->vsize; + adjwgt = graph->adjwgt; + + if (vwgt == NULL) { + vwgt = graph->vwgt = idxsmalloc(nvtxs, 1, "vwgt"); + mustfree = 1; + } + if (adjwgt == NULL) { + adjwgt = graph->adjwgt = idxsmalloc(xadj[nvtxs], 1, "adjwgt"); + mustfree += 2; + } + + printf("%d-way Cut: %5d, Vol: %5d, ", nparts, ComputeCut(graph, where), ComputeVolume(graph, where)); + + /* Compute balance information */ + kpwgts = idxsmalloc(ncon*nparts, 0, "ComputePartitionInfo: kpwgts"); + + for (i=0; i<nvtxs; i++) { + for (j=0; j<ncon; j++) + kpwgts[where[i]*ncon+j] += vwgt[i*ncon+j]; + } + + if (ncon == 1) { + printf("\tBalance: %5.3f out of %5.3f\n", + 1.0*nparts*kpwgts[idxamax(nparts, kpwgts)]/(1.0*idxsum(nparts, kpwgts)), + 1.0*nparts*vwgt[idxamax(nvtxs, vwgt)]/(1.0*idxsum(nparts, kpwgts))); + } + else { + printf("\tBalance:"); + for (j=0; j<ncon; j++) + printf(" (%5.3f out of %5.3f)", + 1.0*nparts*kpwgts[ncon*idxamax_strd(nparts, kpwgts+j, ncon)+j]/(1.0*idxsum_strd(nparts, kpwgts+j, ncon)), + 1.0*nparts*vwgt[ncon*idxamax_strd(nvtxs, vwgt+j, ncon)+j]/(1.0*idxsum_strd(nparts, kpwgts+j, ncon))); + printf("\n"); + } + + + /* Compute p-adjncy information */ + padjncy = idxsmalloc(nparts*nparts, 0, "ComputePartitionInfo: padjncy"); + padjwgt = idxsmalloc(nparts*nparts, 0, "ComputePartitionInfo: padjwgt"); + padjcut = idxsmalloc(nparts*nparts, 0, "ComputePartitionInfo: padjwgt"); + + idxset(nparts, 0, kpwgts); + for (i=0; i<nvtxs; i++) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (where[i] != where[adjncy[j]]) { + padjncy[where[i]*nparts+where[adjncy[j]]] = 1; + padjcut[where[i]*nparts+where[adjncy[j]]] += adjwgt[j]; + if (kpwgts[where[adjncy[j]]] == 0) { + padjwgt[where[i]*nparts+where[adjncy[j]]] += vsize[i]; + kpwgts[where[adjncy[j]]] = 1; + } + } + } + for (j=xadj[i]; j<xadj[i+1]; j++) + kpwgts[where[adjncy[j]]] = 0; + } + + for (i=0; i<nparts; i++) + kpwgts[i] = idxsum(nparts, padjncy+i*nparts); + printf("Min/Max/Avg/Bal # of adjacent subdomains: %5d %5d %5d %7.3f\n", + kpwgts[idxamin(nparts, kpwgts)], kpwgts[idxamax(nparts, kpwgts)], idxsum(nparts, kpwgts)/nparts, + 1.0*nparts*kpwgts[idxamax(nparts, kpwgts)]/(1.0*idxsum(nparts, kpwgts))); + + for (i=0; i<nparts; i++) + kpwgts[i] = idxsum(nparts, padjcut+i*nparts); + printf("Min/Max/Avg/Bal # of adjacent subdomain cuts: %5d %5d %5d %7.3f\n", + kpwgts[idxamin(nparts, kpwgts)], kpwgts[idxamax(nparts, kpwgts)], idxsum(nparts, kpwgts)/nparts, + 1.0*nparts*kpwgts[idxamax(nparts, kpwgts)]/(1.0*idxsum(nparts, kpwgts))); + + for (i=0; i<nparts; i++) + kpwgts[i] = idxsum(nparts, padjwgt+i*nparts); + printf("Min/Max/Avg/Bal/Frac # of interface nodes: %5d %5d %5d %7.3f %7.3f\n", + kpwgts[idxamin(nparts, kpwgts)], kpwgts[idxamax(nparts, kpwgts)], idxsum(nparts, kpwgts)/nparts, + 1.0*nparts*kpwgts[idxamax(nparts, kpwgts)]/(1.0*idxsum(nparts, kpwgts)), 1.0*idxsum(nparts, kpwgts)/(1.0*nvtxs)); + + + if (mustfree == 1 || mustfree == 3) { + free(vwgt); + graph->vwgt = NULL; + } + if (mustfree == 2 || mustfree == 3) { + free(adjwgt); + graph->adjwgt = NULL; + } + + GKfree(&kpwgts, &padjncy, &padjwgt, &padjcut, LTERM); +} + + + +/************************************************************************* +* This function computes the balance of the partitioning +**************************************************************************/ +void ComputePartitionBalance(GraphType *graph, int nparts, idxtype *where, float *ubvec) +{ + int i, j, nvtxs, ncon; + idxtype *kpwgts, *vwgt; + float balance; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + vwgt = graph->vwgt; + + kpwgts = idxsmalloc(nparts, 0, "ComputePartitionInfo: kpwgts"); + + if (vwgt == NULL && ncon == 1) { + for (i=0; i<nvtxs; i++) + kpwgts[where[i]]++; + ubvec[0] = 1.0*nparts*kpwgts[idxamax(nparts, kpwgts)]/(1.0*nvtxs); + } + else { + for (j=0; j<ncon; j++) { + idxset(nparts, 0, kpwgts); + for (i=0; i<graph->nvtxs; i++) + kpwgts[where[i]] += vwgt[i*ncon+j]; + + ubvec[j] = 1.0*nparts*kpwgts[idxamax(nparts, kpwgts)]/(1.0*idxsum(nparts, kpwgts)); + } + } + + free(kpwgts); + +} + + +/************************************************************************* +* This function computes the balance of the element partitioning +**************************************************************************/ +float ComputeElementBalance(int ne, int nparts, idxtype *where) +{ + int i; + idxtype *kpwgts; + float balance; + + kpwgts = idxsmalloc(nparts, 0, "ComputeElementBalance: kpwgts"); + + for (i=0; i<ne; i++) + kpwgts[where[i]]++; + + balance = 1.0*nparts*kpwgts[idxamax(nparts, kpwgts)]/(1.0*idxsum(nparts, kpwgts)); + + free(kpwgts); + + return balance; + +} + + +/************************************************************************* +* This function computes the balance of the partitioning +**************************************************************************/ +void Moc_ComputePartitionBalance(GraphType *graph, int nparts, idxtype *where, float *ubvec) +{ + int i, j, nvtxs, ncon; + float *kpwgts, *nvwgt; + float balance; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + nvwgt = graph->nvwgt; + + kpwgts = fmalloc(nparts, "ComputePartitionInfo: kpwgts"); + + for (j=0; j<ncon; j++) { + sset(nparts, 0.0, kpwgts); + for (i=0; i<graph->nvtxs; i++) + kpwgts[where[i]] += nvwgt[i*ncon+j]; + + ubvec[j] = (float)nparts*kpwgts[samax(nparts, kpwgts)]/ssum(nparts, kpwgts); + } + + free(kpwgts); + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/stats.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/stats.c new file mode 100644 index 0000000..4f6b548 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/stats.c @@ -0,0 +1,44 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * stat.c + * + * This file computes various statistics + * + * Started 7/25/97 + * George + * + * $Id: stats.c,v 1.1 2003/03/13 06:33:20 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function computes the balance of the partitioning +**************************************************************************/ +void Moc_ComputePartitionBalance(GraphType *graph, int nparts, idxtype *where, float *ubvec) +{ + int i, j, nvtxs, ncon; + float *kpwgts, *nvwgt; + float balance; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + nvwgt = graph->nvwgt; + + kpwgts = fmalloc(nparts, "ComputePartitionInfo: kpwgts"); + + for (j=0; j<ncon; j++) { + sset(nparts, 0.0, kpwgts); + for (i=0; i<graph->nvtxs; i++) + kpwgts[where[i]] += nvwgt[i*ncon+j]; + + ubvec[j] = (float)nparts*kpwgts[samax(nparts, kpwgts)]/ssum(nparts, kpwgts); + } + + free(kpwgts); + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/stdheaders.h b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/stdheaders.h new file mode 100644 index 0000000..f82b0cb --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/stdheaders.h @@ -0,0 +1,26 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * stdheaders.h + * + * This file includes all necessary header files + * + * Started 8/27/94 + * George + * + * $Id: stdheaders.h,v 1.2 2003/07/25 14:31:45 karypis Exp $ + */ + + +#include <stdio.h> +#ifdef __STDC__ +#include <stdlib.h> +#else +#include <malloc.h> +#endif +#include <string.h> +#include <ctype.h> +#include <math.h> +#include <stdarg.h> +#include <time.h> + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/struct.h b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/struct.h new file mode 100644 index 0000000..ff091c6 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/struct.h @@ -0,0 +1,253 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * struct.h + * + * This file contains data structures for ILU routines. + * + * Started 9/26/95 + * George + * + * $Id: struct.h,v 1.2 2003/07/25 13:52:01 karypis Exp $ + */ + +#ifndef __parmetis_h__ +/* Undefine the following #define in order to use short int as the idxtype */ +#define IDXTYPE_INT + +/* Indexes are as long as integers for now */ +#ifdef IDXTYPE_INT +typedef int idxtype; +#else +typedef short idxtype; +#endif +#endif + +#define MAXIDX (1<<8*sizeof(idxtype)-2) + + +/************************************************************************* +* The following data structure stores key-value pair +**************************************************************************/ +struct KeyValueType { + idxtype key; + idxtype val; +}; + +typedef struct KeyValueType KeyValueType; + + +/************************************************************************* +* The following data structure will hold a node of a doubly-linked list. +**************************************************************************/ +struct ListNodeType { + int id; /* The id value of the node */ + struct ListNodeType *prev, *next; /* It's a doubly-linked list */ +}; + +typedef struct ListNodeType ListNodeType; + + + +/************************************************************************* +* The following data structure is used to store the buckets for the +* refinment algorithms +**************************************************************************/ +struct PQueueType { + int type; /* The type of the representation used */ + int nnodes; + int maxnodes; + int mustfree; + + /* Linear array version of the data structures */ + int pgainspan, ngainspan; /* plus and negative gain span */ + int maxgain; + ListNodeType *nodes; + ListNodeType **buckets; + + /* Heap version of the data structure */ + KeyValueType *heap; + idxtype *locator; +}; + +typedef struct PQueueType PQueueType; + + +/************************************************************************* +* The following data structure stores an edge +**************************************************************************/ +struct edegreedef { + idxtype pid; + idxtype ed; +}; +typedef struct edegreedef EDegreeType; + + +/************************************************************************* +* The following data structure stores an edge for vol +**************************************************************************/ +struct vedegreedef { + idxtype pid; + idxtype ed, ned; + idxtype gv; +}; +typedef struct vedegreedef VEDegreeType; + + +/************************************************************************* +* This data structure holds various working space data +**************************************************************************/ +struct workspacedef { + idxtype *core; /* Where pairs, indices, and degrees are coming from */ + int maxcore, ccore; + + EDegreeType *edegrees; + VEDegreeType *vedegrees; + int cdegree; + + idxtype *auxcore; /* This points to the memory of the edegrees */ + + idxtype *pmat; /* An array of k^2 used for eliminating domain + connectivity in k-way refinement */ +}; + +typedef struct workspacedef WorkSpaceType; + + +/************************************************************************* +* The following data structure holds information on degrees for k-way +* partition +**************************************************************************/ +struct rinfodef { + int id, ed; /* ID/ED of nodes */ + int ndegrees; /* The number of different ext-degrees */ + EDegreeType *edegrees; /* List of edges */ +}; + +typedef struct rinfodef RInfoType; + + +/************************************************************************* +* The following data structure holds information on degrees for k-way +* vol-based partition +**************************************************************************/ +struct vrinfodef { + int id, ed, nid; /* ID/ED of nodes */ + int gv; /* IV/EV of nodes */ + int ndegrees; /* The number of different ext-degrees */ + VEDegreeType *edegrees; /* List of edges */ +}; + +typedef struct vrinfodef VRInfoType; + + +/************************************************************************* +* The following data structure holds information on degrees for k-way +* partition +**************************************************************************/ +struct nrinfodef { + idxtype edegrees[2]; +}; + +typedef struct nrinfodef NRInfoType; + + +/************************************************************************* +* This data structure holds the input graph +**************************************************************************/ +struct graphdef { + idxtype *gdata, *rdata; /* Memory pools for graph and refinement data. + This is where memory is allocated and used + the rest of the fields in this structure */ + + int nvtxs, nedges; /* The # of vertices and edges in the graph */ + idxtype *xadj; /* Pointers to the locally stored vertices */ + idxtype *vwgt; /* Vertex weights */ + idxtype *vsize; /* Vertex sizes for min-volume formulation */ + idxtype *adjncy; /* Array that stores the adjacency lists of nvtxs */ + idxtype *adjwgt; /* Array that stores the weights of the adjacency lists */ + + idxtype *adjwgtsum; /* The sum of the adjacency weight of each vertex */ + + idxtype *label; + + idxtype *cmap; + + /* Partition parameters */ + int mincut, minvol; + idxtype *where, *pwgts; + int nbnd; + idxtype *bndptr, *bndind; + + /* Bisection refinement parameters */ + idxtype *id, *ed; + + /* K-way refinement parameters */ + RInfoType *rinfo; + + /* K-way volume refinement parameters */ + VRInfoType *vrinfo; + + /* Node refinement information */ + NRInfoType *nrinfo; + + + /* Additional info needed by the MOC routines */ + int ncon; /* The # of constrains */ + float *nvwgt; /* Normalized vertex weights */ + float *npwgts; /* The normalized partition weights */ + + struct graphdef *coarser, *finer; +}; + +typedef struct graphdef GraphType; + + + +/************************************************************************* +* The following data type implements a timer +**************************************************************************/ +typedef double timer; + + +/************************************************************************* +* The following structure stores information used by Metis +**************************************************************************/ +struct controldef { + int CoarsenTo; /* The # of vertices in the coarsest graph */ + int dbglvl; /* Controls the debuging output of the program */ + int CType; /* The type of coarsening */ + int IType; /* The type of initial partitioning */ + int RType; /* The type of refinement */ + int maxvwgt; /* The maximum allowed weight for a vertex */ + float nmaxvwgt; /* The maximum allowed weight for a vertex for each constrain */ + int optype; /* Type of operation */ + int pfactor; /* .1*prunning factor */ + int nseps; /* The number of separators to be found during multiple bisections */ + int oflags; + + WorkSpaceType wspace; /* Work Space Informations */ + + /* Various Timers */ + timer TotalTmr, InitPartTmr, MatchTmr, ContractTmr, CoarsenTmr, UncoarsenTmr, + SepTmr, RefTmr, ProjectTmr, SplitTmr, AuxTmr1, AuxTmr2, AuxTmr3, AuxTmr4, AuxTmr5, AuxTmr6; + +}; + +typedef struct controldef CtrlType; + + +/************************************************************************* +* The following data structure stores max-partition weight info for +* Vertical MOC k-way refinement +**************************************************************************/ +struct vpwgtdef { + float max[2][MAXNCON]; + int imax[2][MAXNCON]; +}; + +typedef struct vpwgtdef VPInfoType; + + + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/subdomains.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/subdomains.c new file mode 100644 index 0000000..6fc65e7 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/subdomains.c @@ -0,0 +1,1295 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * subdomains.c + * + * This file contains functions that deal with prunning the number of + * adjacent subdomains in KMETIS + * + * Started 7/15/98 + * George + * + * $Id: subdomains.c,v 1.2 2003/07/31 06:14:01 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function performs k-way refinement +**************************************************************************/ +void Random_KWayEdgeRefineMConn(CtrlType *ctrl, GraphType *graph, int nparts, float *tpwgts, float ubfactor, int npasses, int ffactor) +{ + int i, ii, iii, j, jj, k, l, pass, nvtxs, nmoves, nbnd, tvwgt, myndegrees; + int from, me, to, oldcut, vwgt, gain; + int maxndoms, nadd; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *where, *pwgts, *perm, *bndptr, *bndind, *minwgt, *maxwgt, *itpwgts; + idxtype *phtable, *pmat, *pmatptr, *ndoms; + EDegreeType *myedegrees; + RInfoType *myrinfo; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + bndptr = graph->bndptr; + bndind = graph->bndind; + + where = graph->where; + pwgts = graph->pwgts; + + pmat = ctrl->wspace.pmat; + phtable = idxwspacemalloc(ctrl, nparts); + ndoms = idxwspacemalloc(ctrl, nparts); + + ComputeSubDomainGraph(graph, nparts, pmat, ndoms); + + /* Setup the weight intervals of the various subdomains */ + minwgt = idxwspacemalloc(ctrl, nparts); + maxwgt = idxwspacemalloc(ctrl, nparts); + itpwgts = idxwspacemalloc(ctrl, nparts); + tvwgt = idxsum(nparts, pwgts); + ASSERT(tvwgt == idxsum(nvtxs, graph->vwgt)); + + for (i=0; i<nparts; i++) { + itpwgts[i] = tpwgts[i]*tvwgt; + maxwgt[i] = tpwgts[i]*tvwgt*ubfactor; + minwgt[i] = tpwgts[i]*tvwgt*(1.0/ubfactor); + } + + perm = idxwspacemalloc(ctrl, nvtxs); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("Partitions: [%6d %6d]-[%6d %6d], Balance: %5.3f, Nv-Nb[%6d %6d]. Cut: %6d\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], minwgt[0], maxwgt[0], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nvtxs, graph->nbnd, + graph->mincut)); + + for (pass=0; pass<npasses; pass++) { + ASSERT(ComputeCut(graph, where) == graph->mincut); + + maxndoms = ndoms[idxamax(nparts, ndoms)]; + + oldcut = graph->mincut; + nbnd = graph->nbnd; + + RandomPermute(nbnd, perm, 1); + for (nmoves=iii=0; iii<graph->nbnd; iii++) { + ii = perm[iii]; + if (ii >= nbnd) + continue; + i = bndind[ii]; + + myrinfo = graph->rinfo+i; + + if (myrinfo->ed >= myrinfo->id) { /* Total ED is too high */ + from = where[i]; + vwgt = graph->vwgt[i]; + + if (myrinfo->id > 0 && pwgts[from]-vwgt < minwgt[from]) + continue; /* This cannot be moved! */ + + myedegrees = myrinfo->edegrees; + myndegrees = myrinfo->ndegrees; + + /* Determine the valid domains */ + for (j=0; j<myndegrees; j++) { + to = myedegrees[j].pid; + phtable[to] = 1; + pmatptr = pmat + to*nparts; + for (nadd=0, k=0; k<myndegrees; k++) { + if (k == j) + continue; + + l = myedegrees[k].pid; + if (pmatptr[l] == 0) { + if (ndoms[l] > maxndoms-1) { + phtable[to] = 0; + nadd = maxndoms; + break; + } + nadd++; + } + } + if (ndoms[to]+nadd > maxndoms) + phtable[to] = 0; + if (nadd == 0) + phtable[to] = 2; + } + + /* Find the first valid move */ + j = myrinfo->id; + for (k=0; k<myndegrees; k++) { + to = myedegrees[k].pid; + if (!phtable[to]) + continue; + gain = myedegrees[k].ed-j; /* j = myrinfo->id. Allow good nodes to move */ + if (pwgts[to]+vwgt <= maxwgt[to]+ffactor*gain && gain >= 0) + break; + } + if (k == myndegrees) + continue; /* break out if you did not find a candidate */ + + for (j=k+1; j<myndegrees; j++) { + to = myedegrees[j].pid; + if (!phtable[to]) + continue; + if ((myedegrees[j].ed > myedegrees[k].ed && pwgts[to]+vwgt <= maxwgt[to]) || + (myedegrees[j].ed == myedegrees[k].ed && + itpwgts[myedegrees[k].pid]*pwgts[to] < itpwgts[to]*pwgts[myedegrees[k].pid])) + k = j; + } + + to = myedegrees[k].pid; + + j = 0; + if (myedegrees[k].ed-myrinfo->id > 0) + j = 1; + else if (myedegrees[k].ed-myrinfo->id == 0) { + if (/*(iii&7) == 0 ||*/ phtable[myedegrees[k].pid] == 2 || pwgts[from] >= maxwgt[from] || itpwgts[from]*(pwgts[to]+vwgt) < itpwgts[to]*pwgts[from]) + j = 1; + } + if (j == 0) + continue; + + /*===================================================================== + * If we got here, we can now move the vertex from 'from' to 'to' + *======================================================================*/ + graph->mincut -= myedegrees[k].ed-myrinfo->id; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, printf("\t\tMoving %6d to %3d. Gain: %4d. Cut: %6d\n", i, to, myedegrees[k].ed-myrinfo->id, graph->mincut)); + + /* Update pmat to reflect the move of 'i' */ + pmat[from*nparts+to] += (myrinfo->id-myedegrees[k].ed); + pmat[to*nparts+from] += (myrinfo->id-myedegrees[k].ed); + if (pmat[from*nparts+to] == 0) { + ndoms[from]--; + if (ndoms[from]+1 == maxndoms) + maxndoms = ndoms[idxamax(nparts, ndoms)]; + } + if (pmat[to*nparts+from] == 0) { + ndoms[to]--; + if (ndoms[to]+1 == maxndoms) + maxndoms = ndoms[idxamax(nparts, ndoms)]; + } + + /* Update where, weight, and ID/ED information of the vertex you moved */ + where[i] = to; + INC_DEC(pwgts[to], pwgts[from], vwgt); + myrinfo->ed += myrinfo->id-myedegrees[k].ed; + SWAP(myrinfo->id, myedegrees[k].ed, j); + if (myedegrees[k].ed == 0) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].pid = from; + + if (myrinfo->ed-myrinfo->id < 0) + BNDDelete(nbnd, bndind, bndptr, i); + + /* Update the degrees of adjacent vertices */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + ii = adjncy[j]; + me = where[ii]; + + myrinfo = graph->rinfo+ii; + if (myrinfo->edegrees == NULL) { + myrinfo->edegrees = ctrl->wspace.edegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += xadj[ii+1]-xadj[ii]; + } + myedegrees = myrinfo->edegrees; + + ASSERT(CheckRInfo(myrinfo)); + + if (me == from) { + INC_DEC(myrinfo->ed, myrinfo->id, adjwgt[j]); + + if (myrinfo->ed-myrinfo->id >= 0 && bndptr[ii] == -1) + BNDInsert(nbnd, bndind, bndptr, ii); + } + else if (me == to) { + INC_DEC(myrinfo->id, myrinfo->ed, adjwgt[j]); + + if (myrinfo->ed-myrinfo->id < 0 && bndptr[ii] != -1) + BNDDelete(nbnd, bndind, bndptr, ii); + } + + /* Remove contribution from the .ed of 'from' */ + if (me != from) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == from) { + if (myedegrees[k].ed == adjwgt[j]) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].ed -= adjwgt[j]; + break; + } + } + } + + /* Add contribution to the .ed of 'to' */ + if (me != to) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == to) { + myedegrees[k].ed += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + myedegrees[myrinfo->ndegrees].pid = to; + myedegrees[myrinfo->ndegrees++].ed = adjwgt[j]; + } + } + + /* Update pmat to reflect the move of 'i' for domains other than 'from' and 'to' */ + if (me != from && me != to) { + pmat[me*nparts+from] -= adjwgt[j]; + pmat[from*nparts+me] -= adjwgt[j]; + if (pmat[me*nparts+from] == 0) { + ndoms[me]--; + if (ndoms[me]+1 == maxndoms) + maxndoms = ndoms[idxamax(nparts, ndoms)]; + } + if (pmat[from*nparts+me] == 0) { + ndoms[from]--; + if (ndoms[from]+1 == maxndoms) + maxndoms = ndoms[idxamax(nparts, ndoms)]; + } + + if (pmat[me*nparts+to] == 0) { + ndoms[me]++; + if (ndoms[me] > maxndoms) { + IFSET(ctrl->dbglvl, DBG_REFINE, printf("You just increased the maxndoms: %d %d\n", ndoms[me], maxndoms)); + maxndoms = ndoms[me]; + } + } + if (pmat[to*nparts+me] == 0) { + ndoms[to]++; + if (ndoms[to] > maxndoms) { + IFSET(ctrl->dbglvl, DBG_REFINE, printf("You just increased the maxndoms: %d %d\n", ndoms[to], maxndoms)); + maxndoms = ndoms[to]; + } + } + pmat[me*nparts+to] += adjwgt[j]; + pmat[to*nparts+me] += adjwgt[j]; + } + + ASSERT(myrinfo->ndegrees <= xadj[ii+1]-xadj[ii]); + ASSERT(CheckRInfo(myrinfo)); + + } + nmoves++; + } + } + + graph->nbnd = nbnd; + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\t[%6d %6d], Balance: %5.3f, Nb: %6d. Nmoves: %5d, Cut: %5d, Vol: %5d, %d\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nbnd, nmoves, + graph->mincut, ComputeVolume(graph, where), idxsum(nparts, ndoms))); + + if (graph->mincut == oldcut) + break; + } + + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nvtxs); +} + + + +/************************************************************************* +* This function performs k-way refinement +**************************************************************************/ +void Greedy_KWayEdgeBalanceMConn(CtrlType *ctrl, GraphType *graph, int nparts, float *tpwgts, float ubfactor, int npasses) +{ + int i, ii, iii, j, jj, k, l, pass, nvtxs, nbnd, tvwgt, myndegrees, oldgain, gain, nmoves; + int from, me, to, oldcut, vwgt, maxndoms, nadd; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *where, *pwgts, *perm, *bndptr, *bndind, *minwgt, *maxwgt, *moved, *itpwgts; + idxtype *phtable, *pmat, *pmatptr, *ndoms; + EDegreeType *myedegrees; + RInfoType *myrinfo; + PQueueType queue; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + bndind = graph->bndind; + bndptr = graph->bndptr; + + where = graph->where; + pwgts = graph->pwgts; + + pmat = ctrl->wspace.pmat; + phtable = idxwspacemalloc(ctrl, nparts); + ndoms = idxwspacemalloc(ctrl, nparts); + + ComputeSubDomainGraph(graph, nparts, pmat, ndoms); + + + /* Setup the weight intervals of the various subdomains */ + minwgt = idxwspacemalloc(ctrl, nparts); + maxwgt = idxwspacemalloc(ctrl, nparts); + itpwgts = idxwspacemalloc(ctrl, nparts); + tvwgt = idxsum(nparts, pwgts); + ASSERT(tvwgt == idxsum(nvtxs, graph->vwgt)); + + for (i=0; i<nparts; i++) { + itpwgts[i] = tpwgts[i]*tvwgt; + maxwgt[i] = tpwgts[i]*tvwgt*ubfactor; + minwgt[i] = tpwgts[i]*tvwgt*(1.0/ubfactor); + } + + perm = idxwspacemalloc(ctrl, nvtxs); + moved = idxwspacemalloc(ctrl, nvtxs); + + PQueueInit(ctrl, &queue, nvtxs, graph->adjwgtsum[idxamax(nvtxs, graph->adjwgtsum)]); + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("Partitions: [%6d %6d]-[%6d %6d], Balance: %5.3f, Nv-Nb[%6d %6d]. Cut: %6d [B]\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], minwgt[0], maxwgt[0], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nvtxs, graph->nbnd, + graph->mincut)); + + for (pass=0; pass<npasses; pass++) { + ASSERT(ComputeCut(graph, where) == graph->mincut); + + /* Check to see if things are out of balance, given the tolerance */ + for (i=0; i<nparts; i++) { + if (pwgts[i] > maxwgt[i]) + break; + } + if (i == nparts) /* Things are balanced. Return right away */ + break; + + PQueueReset(&queue); + idxset(nvtxs, -1, moved); + + oldcut = graph->mincut; + nbnd = graph->nbnd; + + RandomPermute(nbnd, perm, 1); + for (ii=0; ii<nbnd; ii++) { + i = bndind[perm[ii]]; + PQueueInsert(&queue, i, graph->rinfo[i].ed - graph->rinfo[i].id); + moved[i] = 2; + } + + maxndoms = ndoms[idxamax(nparts, ndoms)]; + + for (nmoves=0;;) { + if ((i = PQueueGetMax(&queue)) == -1) + break; + moved[i] = 1; + + myrinfo = graph->rinfo+i; + from = where[i]; + vwgt = graph->vwgt[i]; + + if (pwgts[from]-vwgt < minwgt[from]) + continue; /* This cannot be moved! */ + + myedegrees = myrinfo->edegrees; + myndegrees = myrinfo->ndegrees; + + /* Determine the valid domains */ + for (j=0; j<myndegrees; j++) { + to = myedegrees[j].pid; + phtable[to] = 1; + pmatptr = pmat + to*nparts; + for (nadd=0, k=0; k<myndegrees; k++) { + if (k == j) + continue; + + l = myedegrees[k].pid; + if (pmatptr[l] == 0) { + if (ndoms[l] > maxndoms-1) { + phtable[to] = 0; + nadd = maxndoms; + break; + } + nadd++; + } + } + if (ndoms[to]+nadd > maxndoms) + phtable[to] = 0; + } + + for (k=0; k<myndegrees; k++) { + to = myedegrees[k].pid; + if (!phtable[to]) + continue; + if (pwgts[to]+vwgt <= maxwgt[to] || itpwgts[from]*(pwgts[to]+vwgt) <= itpwgts[to]*pwgts[from]) + break; + } + if (k == myndegrees) + continue; /* break out if you did not find a candidate */ + + for (j=k+1; j<myndegrees; j++) { + to = myedegrees[j].pid; + if (!phtable[to]) + continue; + if (itpwgts[myedegrees[k].pid]*pwgts[to] < itpwgts[to]*pwgts[myedegrees[k].pid]) + k = j; + } + + to = myedegrees[k].pid; + + if (pwgts[from] < maxwgt[from] && pwgts[to] > minwgt[to] && myedegrees[k].ed-myrinfo->id < 0) + continue; + + /*===================================================================== + * If we got here, we can now move the vertex from 'from' to 'to' + *======================================================================*/ + graph->mincut -= myedegrees[k].ed-myrinfo->id; + + IFSET(ctrl->dbglvl, DBG_MOVEINFO, printf("\t\tMoving %6d to %3d. Gain: %4d. Cut: %6d\n", i, to, myedegrees[k].ed-myrinfo->id, graph->mincut)); + + /* Update pmat to reflect the move of 'i' */ + pmat[from*nparts+to] += (myrinfo->id-myedegrees[k].ed); + pmat[to*nparts+from] += (myrinfo->id-myedegrees[k].ed); + if (pmat[from*nparts+to] == 0) { + ndoms[from]--; + if (ndoms[from]+1 == maxndoms) + maxndoms = ndoms[idxamax(nparts, ndoms)]; + } + if (pmat[to*nparts+from] == 0) { + ndoms[to]--; + if (ndoms[to]+1 == maxndoms) + maxndoms = ndoms[idxamax(nparts, ndoms)]; + } + + + /* Update where, weight, and ID/ED information of the vertex you moved */ + where[i] = to; + INC_DEC(pwgts[to], pwgts[from], vwgt); + myrinfo->ed += myrinfo->id-myedegrees[k].ed; + SWAP(myrinfo->id, myedegrees[k].ed, j); + if (myedegrees[k].ed == 0) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].pid = from; + + if (myrinfo->ed == 0) + BNDDelete(nbnd, bndind, bndptr, i); + + /* Update the degrees of adjacent vertices */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + ii = adjncy[j]; + me = where[ii]; + + myrinfo = graph->rinfo+ii; + if (myrinfo->edegrees == NULL) { + myrinfo->edegrees = ctrl->wspace.edegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += xadj[ii+1]-xadj[ii]; + } + myedegrees = myrinfo->edegrees; + + ASSERT(CheckRInfo(myrinfo)); + + oldgain = (myrinfo->ed-myrinfo->id); + + if (me == from) { + INC_DEC(myrinfo->ed, myrinfo->id, adjwgt[j]); + + if (myrinfo->ed > 0 && bndptr[ii] == -1) + BNDInsert(nbnd, bndind, bndptr, ii); + } + else if (me == to) { + INC_DEC(myrinfo->id, myrinfo->ed, adjwgt[j]); + + if (myrinfo->ed == 0 && bndptr[ii] != -1) + BNDDelete(nbnd, bndind, bndptr, ii); + } + + /* Remove contribution from the .ed of 'from' */ + if (me != from) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == from) { + if (myedegrees[k].ed == adjwgt[j]) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].ed -= adjwgt[j]; + break; + } + } + } + + /* Add contribution to the .ed of 'to' */ + if (me != to) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == to) { + myedegrees[k].ed += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + myedegrees[myrinfo->ndegrees].pid = to; + myedegrees[myrinfo->ndegrees++].ed = adjwgt[j]; + } + } + + /* Update pmat to reflect the move of 'i' for domains other than 'from' and 'to' */ + if (me != from && me != to) { + pmat[me*nparts+from] -= adjwgt[j]; + pmat[from*nparts+me] -= adjwgt[j]; + if (pmat[me*nparts+from] == 0) { + ndoms[me]--; + if (ndoms[me]+1 == maxndoms) + maxndoms = ndoms[idxamax(nparts, ndoms)]; + } + if (pmat[from*nparts+me] == 0) { + ndoms[from]--; + if (ndoms[from]+1 == maxndoms) + maxndoms = ndoms[idxamax(nparts, ndoms)]; + } + + if (pmat[me*nparts+to] == 0) { + ndoms[me]++; + if (ndoms[me] > maxndoms) { + IFSET(ctrl->dbglvl, DBG_REFINE, printf("You just increased the maxndoms: %d %d\n", ndoms[me], maxndoms)); + maxndoms = ndoms[me]; + } + } + if (pmat[to*nparts+me] == 0) { + ndoms[to]++; + if (ndoms[to] > maxndoms) { + IFSET(ctrl->dbglvl, DBG_REFINE, printf("You just increased the maxndoms: %d %d\n", ndoms[to], maxndoms)); + maxndoms = ndoms[to]; + } + } + pmat[me*nparts+to] += adjwgt[j]; + pmat[to*nparts+me] += adjwgt[j]; + } + + /* Update the queue */ + if (me == to || me == from) { + gain = myrinfo->ed-myrinfo->id; + if (moved[ii] == 2) { + if (myrinfo->ed > 0) + PQueueUpdate(&queue, ii, oldgain, gain); + else { + PQueueDelete(&queue, ii, oldgain); + moved[ii] = -1; + } + } + else if (moved[ii] == -1 && myrinfo->ed > 0) { + PQueueInsert(&queue, ii, gain); + moved[ii] = 2; + } + } + + ASSERT(myrinfo->ndegrees <= xadj[ii+1]-xadj[ii]); + ASSERT(CheckRInfo(myrinfo)); + } + nmoves++; + } + + graph->nbnd = nbnd; + + IFSET(ctrl->dbglvl, DBG_REFINE, + printf("\t[%6d %6d], Balance: %5.3f, Nb: %6d. Nmoves: %5d, Cut: %6d, %d\n", + pwgts[idxamin(nparts, pwgts)], pwgts[idxamax(nparts, pwgts)], + 1.0*nparts*pwgts[idxamax(nparts, pwgts)]/tvwgt, graph->nbnd, nmoves, graph->mincut,idxsum(nparts, ndoms))); + } + + PQueueFree(ctrl, &queue); + + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + +} + + + + +/************************************************************************* +* This function computes the subdomain graph +**************************************************************************/ +void PrintSubDomainGraph(GraphType *graph, int nparts, idxtype *where) +{ + int i, j, k, me, nvtxs, total, max; + idxtype *xadj, *adjncy, *adjwgt, *pmat; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + pmat = idxsmalloc(nparts*nparts, 0, "ComputeSubDomainGraph: pmat"); + + for (i=0; i<nvtxs; i++) { + me = where[i]; + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (where[k] != me) + pmat[me*nparts+where[k]] += adjwgt[j]; + } + } + + /* printf("Subdomain Info\n"); */ + total = max = 0; + for (i=0; i<nparts; i++) { + for (k=0, j=0; j<nparts; j++) { + if (pmat[i*nparts+j] > 0) + k++; + } + total += k; + + if (k > max) + max = k; +/* + printf("%2d -> %2d ", i, k); + for (j=0; j<nparts; j++) { + if (pmat[i*nparts+j] > 0) + printf("[%2d %4d] ", j, pmat[i*nparts+j]); + } + printf("\n"); +*/ + } + printf("Total adjacent subdomains: %d, Max: %d\n", total, max); + + free(pmat); +} + + + +/************************************************************************* +* This function computes the subdomain graph +**************************************************************************/ +void ComputeSubDomainGraph(GraphType *graph, int nparts, idxtype *pmat, idxtype *ndoms) +{ + int i, j, k, me, nvtxs, ndegrees; + idxtype *xadj, *adjncy, *adjwgt, *where; + RInfoType *rinfo; + EDegreeType *edegrees; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + rinfo = graph->rinfo; + + idxset(nparts*nparts, 0, pmat); + + for (i=0; i<nvtxs; i++) { + if (rinfo[i].ed > 0) { + me = where[i]; + ndegrees = rinfo[i].ndegrees; + edegrees = rinfo[i].edegrees; + + k = me*nparts; + for (j=0; j<ndegrees; j++) + pmat[k+edegrees[j].pid] += edegrees[j].ed; + } + } + + for (i=0; i<nparts; i++) { + ndoms[i] = 0; + for (j=0; j<nparts; j++) { + if (pmat[i*nparts+j] > 0) + ndoms[i]++; + } + } + +} + + + + + +/************************************************************************* +* This function computes the subdomain graph +**************************************************************************/ +void EliminateSubDomainEdges(CtrlType *ctrl, GraphType *graph, int nparts, float *tpwgts) +{ + int i, ii, j, k, me, other, nvtxs, total, max, avg, totalout, nind, ncand, ncand2, target, target2, nadd; + int min, move, cpwgt, tvwgt; + idxtype *xadj, *adjncy, *vwgt, *adjwgt, *pwgts, *where, *maxpwgt, *pmat, *ndoms, *mypmat, *otherpmat, *ind; + KeyValueType *cand, *cand2; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + vwgt = graph->vwgt; + adjwgt = graph->adjwgt; + + where = graph->where; + pwgts = graph->pwgts; /* We assume that this is properly initialized */ + + maxpwgt = idxwspacemalloc(ctrl, nparts); + ndoms = idxwspacemalloc(ctrl, nparts); + otherpmat = idxwspacemalloc(ctrl, nparts); + ind = idxwspacemalloc(ctrl, nvtxs); + pmat = ctrl->wspace.pmat; + + cand = (KeyValueType *)GKmalloc(nparts*sizeof(KeyValueType), "EliminateSubDomainEdges: cand"); + cand2 = (KeyValueType *)GKmalloc(nparts*sizeof(KeyValueType), "EliminateSubDomainEdges: cand"); + + /* Compute the pmat matrix and ndoms */ + ComputeSubDomainGraph(graph, nparts, pmat, ndoms); + + + /* Compute the maximum allowed weight for each domain */ + tvwgt = idxsum(nparts, pwgts); + for (i=0; i<nparts; i++) + maxpwgt[i] = 1.25*tpwgts[i]*tvwgt; + + + /* Get into the loop eliminating subdomain connections */ + for (;;) { + total = idxsum(nparts, ndoms); + avg = total/nparts; + max = ndoms[idxamax(nparts, ndoms)]; + + /* printf("Adjacent Subdomain Stats: Total: %3d, Max: %3d, Avg: %3d [%5d]\n", total, max, avg, idxsum(nparts*nparts, pmat)); */ + + if (max < 1.4*avg) + break; + + me = idxamax(nparts, ndoms); + mypmat = pmat + me*nparts; + totalout = idxsum(nparts, mypmat); + + /*printf("Me: %d, TotalOut: %d,\n", me, totalout);*/ + + /* Sort the connections according to their cut */ + for (ncand2=0, i=0; i<nparts; i++) { + if (mypmat[i] > 0) { + cand2[ncand2].key = mypmat[i]; + cand2[ncand2++].val = i; + } + } + ikeysort(ncand2, cand2); + + move = 0; + for (min=0; min<ncand2; min++) { + if (cand2[min].key > totalout/(2*ndoms[me])) + break; + + other = cand2[min].val; + + /*printf("\tMinOut: %d to %d\n", mypmat[other], other);*/ + + idxset(nparts, 0, otherpmat); + + /* Go and find the vertices in 'other' that are connected in 'me' */ + for (nind=0, i=0; i<nvtxs; i++) { + if (where[i] == other) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (where[adjncy[j]] == me) { + ind[nind++] = i; + break; + } + } + } + } + + /* Go and construct the otherpmat to see where these nind vertices are connected to */ + for (cpwgt=0, ii=0; ii<nind; ii++) { + i = ind[ii]; + cpwgt += vwgt[i]; + + for (j=xadj[i]; j<xadj[i+1]; j++) + otherpmat[where[adjncy[j]]] += adjwgt[j]; + } + otherpmat[other] = 0; + + for (ncand=0, i=0; i<nparts; i++) { + if (otherpmat[i] > 0) { + cand[ncand].key = -otherpmat[i]; + cand[ncand++].val = i; + } + } + ikeysort(ncand, cand); + + /* + * Go through and the select the first domain that is common with 'me', and + * does not increase the ndoms[target] higher than my ndoms, subject to the + * maxpwgt constraint. Traversal is done from the mostly connected to the least. + */ + target = target2 = -1; + for (i=0; i<ncand; i++) { + k = cand[i].val; + + if (mypmat[k] > 0) { + if (pwgts[k] + cpwgt > maxpwgt[k]) /* Check if balance will go off */ + continue; + + for (j=0; j<nparts; j++) { + if (otherpmat[j] > 0 && ndoms[j] >= ndoms[me]-1 && pmat[nparts*j+k] == 0) + break; + } + if (j == nparts) { /* No bad second level effects */ + for (nadd=0, j=0; j<nparts; j++) { + if (otherpmat[j] > 0 && pmat[nparts*k+j] == 0) + nadd++; + } + + /*printf("\t\tto=%d, nadd=%d, %d\n", k, nadd, ndoms[k]);*/ + if (target2 == -1 && ndoms[k]+nadd < ndoms[me]) { + target2 = k; + } + if (nadd == 0) { + target = k; + break; + } + } + } + } + if (target == -1 && target2 != -1) + target = target2; + + if (target == -1) { + /* printf("\t\tCould not make the move\n");*/ + continue; + } + + /*printf("\t\tMoving to %d\n", target);*/ + + /* Update the partition weights */ + INC_DEC(pwgts[target], pwgts[other], cpwgt); + + MoveGroupMConn(ctrl, graph, ndoms, pmat, nparts, target, nind, ind); + + move = 1; + break; + } + + if (move == 0) + break; + } + + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nvtxs); + + GKfree(&cand, &cand2, LTERM); +} + + +/************************************************************************* +* This function moves a collection of vertices and updates their rinfo +**************************************************************************/ +void MoveGroupMConn(CtrlType *ctrl, GraphType *graph, idxtype *ndoms, idxtype *pmat, + int nparts, int to, int nind, idxtype *ind) +{ + int i, ii, iii, j, jj, k, l, nvtxs, nbnd, myndegrees; + int from, me; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *where, *bndptr, *bndind; + EDegreeType *myedegrees; + RInfoType *myrinfo; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + where = graph->where; + bndptr = graph->bndptr; + bndind = graph->bndind; + + nbnd = graph->nbnd; + + for (iii=0; iii<nind; iii++) { + i = ind[iii]; + from = where[i]; + + myrinfo = graph->rinfo+i; + if (myrinfo->edegrees == NULL) { + myrinfo->edegrees = ctrl->wspace.edegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += xadj[i+1]-xadj[i]; + myrinfo->ndegrees = 0; + } + myedegrees = myrinfo->edegrees; + + /* find the location of 'to' in myrinfo or create it if it is not there */ + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == to) + break; + } + if (k == myrinfo->ndegrees) { + myedegrees[k].pid = to; + myedegrees[k].ed = 0; + myrinfo->ndegrees++; + } + + graph->mincut -= myedegrees[k].ed-myrinfo->id; + + /* Update pmat to reflect the move of 'i' */ + pmat[from*nparts+to] += (myrinfo->id-myedegrees[k].ed); + pmat[to*nparts+from] += (myrinfo->id-myedegrees[k].ed); + if (pmat[from*nparts+to] == 0) + ndoms[from]--; + if (pmat[to*nparts+from] == 0) + ndoms[to]--; + + /* Update where, weight, and ID/ED information of the vertex you moved */ + where[i] = to; + myrinfo->ed += myrinfo->id-myedegrees[k].ed; + SWAP(myrinfo->id, myedegrees[k].ed, j); + if (myedegrees[k].ed == 0) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].pid = from; + + if (myrinfo->ed-myrinfo->id < 0 && bndptr[i] != -1) + BNDDelete(nbnd, bndind, bndptr, i); + + /* Update the degrees of adjacent vertices */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + ii = adjncy[j]; + me = where[ii]; + + myrinfo = graph->rinfo+ii; + if (myrinfo->edegrees == NULL) { + myrinfo->edegrees = ctrl->wspace.edegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += xadj[ii+1]-xadj[ii]; + } + myedegrees = myrinfo->edegrees; + + ASSERT(CheckRInfo(myrinfo)); + + if (me == from) { + INC_DEC(myrinfo->ed, myrinfo->id, adjwgt[j]); + + if (myrinfo->ed-myrinfo->id >= 0 && bndptr[ii] == -1) + BNDInsert(nbnd, bndind, bndptr, ii); + } + else if (me == to) { + INC_DEC(myrinfo->id, myrinfo->ed, adjwgt[j]); + + if (myrinfo->ed-myrinfo->id < 0 && bndptr[ii] != -1) + BNDDelete(nbnd, bndind, bndptr, ii); + } + + /* Remove contribution from the .ed of 'from' */ + if (me != from) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == from) { + if (myedegrees[k].ed == adjwgt[j]) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].ed -= adjwgt[j]; + break; + } + } + } + + /* Add contribution to the .ed of 'to' */ + if (me != to) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == to) { + myedegrees[k].ed += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + myedegrees[myrinfo->ndegrees].pid = to; + myedegrees[myrinfo->ndegrees++].ed = adjwgt[j]; + } + } + + /* Update pmat to reflect the move of 'i' for domains other than 'from' and 'to' */ + if (me != from && me != to) { + pmat[me*nparts+from] -= adjwgt[j]; + pmat[from*nparts+me] -= adjwgt[j]; + if (pmat[me*nparts+from] == 0) + ndoms[me]--; + if (pmat[from*nparts+me] == 0) + ndoms[from]--; + + if (pmat[me*nparts+to] == 0) + ndoms[me]++; + if (pmat[to*nparts+me] == 0) + ndoms[to]++; + + pmat[me*nparts+to] += adjwgt[j]; + pmat[to*nparts+me] += adjwgt[j]; + } + + ASSERT(CheckRInfo(myrinfo)); + } + + ASSERT(CheckRInfo(graph->rinfo+i)); + } + + graph->nbnd = nbnd; + +} + + + + +/************************************************************************* +* This function finds all the connected components induced by the +* partitioning vector in wgraph->where and tries to push them around to +* remove some of them +**************************************************************************/ +void EliminateComponents(CtrlType *ctrl, GraphType *graph, int nparts, float *tpwgts, float ubfactor) +{ + int i, ii, j, jj, k, me, nvtxs, tvwgt, first, last, nleft, ncmps, cwgt, other, target, deltawgt; + idxtype *xadj, *adjncy, *vwgt, *adjwgt, *where, *pwgts, *maxpwgt; + idxtype *cpvec, *touched, *perm, *todo, *cind, *cptr, *npcmps; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + vwgt = graph->vwgt; + adjwgt = graph->adjwgt; + + where = graph->where; + pwgts = graph->pwgts; + + touched = idxset(nvtxs, 0, idxwspacemalloc(ctrl, nvtxs)); + cptr = idxwspacemalloc(ctrl, nvtxs+1); + cind = idxwspacemalloc(ctrl, nvtxs); + perm = idxwspacemalloc(ctrl, nvtxs); + todo = idxwspacemalloc(ctrl, nvtxs); + maxpwgt = idxwspacemalloc(ctrl, nparts); + cpvec = idxwspacemalloc(ctrl, nparts); + npcmps = idxset(nparts, 0, idxwspacemalloc(ctrl, nparts)); + + for (i=0; i<nvtxs; i++) + perm[i] = todo[i] = i; + + /* Find the connected componends induced by the partition */ + ncmps = -1; + first = last = 0; + nleft = nvtxs; + while (nleft > 0) { + if (first == last) { /* Find another starting vertex */ + cptr[++ncmps] = first; + ASSERT(touched[todo[0]] == 0); + i = todo[0]; + cind[last++] = i; + touched[i] = 1; + me = where[i]; + npcmps[me]++; + } + + i = cind[first++]; + k = perm[i]; + j = todo[k] = todo[--nleft]; + perm[j] = k; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (where[k] == me && !touched[k]) { + cind[last++] = k; + touched[k] = 1; + } + } + } + cptr[++ncmps] = first; + + /* printf("I found %d components, for this %d-way partition\n", ncmps, nparts); */ + + if (ncmps > nparts) { /* There are more components than processors */ + /* First determine the max allowed load imbalance */ + tvwgt = idxsum(nparts, pwgts); + for (i=0; i<nparts; i++) + maxpwgt[i] = ubfactor*tpwgts[i]*tvwgt; + + deltawgt = 5; + + for (i=0; i<ncmps; i++) { + me = where[cind[cptr[i]]]; /* Get the domain of this component */ + if (npcmps[me] == 1) + continue; /* Skip it because it is contigous */ + + /*printf("Trying to move %d from %d\n", i, me); */ + + /* Determine the weight of the block to be moved and abort if too high */ + for (cwgt=0, j=cptr[i]; j<cptr[i+1]; j++) + cwgt += vwgt[cind[j]]; + + if (cwgt > .30*pwgts[me]) + continue; /* Skip the component if it is over 30% of the weight */ + + /* Determine the connectivity */ + idxset(nparts, 0, cpvec); + for (j=cptr[i]; j<cptr[i+1]; j++) { + ii = cind[j]; + for (jj=xadj[ii]; jj<xadj[ii+1]; jj++) + cpvec[where[adjncy[jj]]] += adjwgt[jj]; + } + cpvec[me] = 0; + + target = -1; + for (j=0; j<nparts; j++) { + if (cpvec[j] > 0 && (cwgt < deltawgt || pwgts[j] + cwgt < maxpwgt[j])) { + if (target == -1 || cpvec[target] < cpvec[j]) + target = j; + } + } + + /* printf("\tMoving it to %d [%d]\n", target, cpvec[target]);*/ + + if (target != -1) { + /* Assign all the vertices of 'me' to 'target' and update data structures */ + INC_DEC(pwgts[target], pwgts[me], cwgt); + npcmps[me]--; + + MoveGroup(ctrl, graph, nparts, target, i, cptr, cind); + } + } + + } + + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nparts); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs); + idxwspacefree(ctrl, nvtxs+1); + +} + + +/************************************************************************* +* This function moves a collection of vertices and updates their rinfo +**************************************************************************/ +void MoveGroup(CtrlType *ctrl, GraphType *graph, int nparts, int to, int gid, idxtype *ptr, idxtype *ind) +{ + int i, ii, iii, j, jj, k, l, nvtxs, nbnd, myndegrees; + int from, me; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *where, *bndptr, *bndind; + EDegreeType *myedegrees; + RInfoType *myrinfo; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + where = graph->where; + bndptr = graph->bndptr; + bndind = graph->bndind; + + nbnd = graph->nbnd; + + for (iii=ptr[gid]; iii<ptr[gid+1]; iii++) { + i = ind[iii]; + from = where[i]; + + myrinfo = graph->rinfo+i; + if (myrinfo->edegrees == NULL) { + myrinfo->edegrees = ctrl->wspace.edegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += xadj[i+1]-xadj[i]; + myrinfo->ndegrees = 0; + } + myedegrees = myrinfo->edegrees; + + /* find the location of 'to' in myrinfo or create it if it is not there */ + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == to) + break; + } + if (k == myrinfo->ndegrees) { + myedegrees[k].pid = to; + myedegrees[k].ed = 0; + myrinfo->ndegrees++; + } + + graph->mincut -= myedegrees[k].ed-myrinfo->id; + + + /* Update where, weight, and ID/ED information of the vertex you moved */ + where[i] = to; + myrinfo->ed += myrinfo->id-myedegrees[k].ed; + SWAP(myrinfo->id, myedegrees[k].ed, j); + if (myedegrees[k].ed == 0) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].pid = from; + + if (myrinfo->ed-myrinfo->id < 0 && bndptr[i] != -1) + BNDDelete(nbnd, bndind, bndptr, i); + + /* Update the degrees of adjacent vertices */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + ii = adjncy[j]; + me = where[ii]; + + myrinfo = graph->rinfo+ii; + if (myrinfo->edegrees == NULL) { + myrinfo->edegrees = ctrl->wspace.edegrees+ctrl->wspace.cdegree; + ctrl->wspace.cdegree += xadj[ii+1]-xadj[ii]; + } + myedegrees = myrinfo->edegrees; + + ASSERT(CheckRInfo(myrinfo)); + + if (me == from) { + INC_DEC(myrinfo->ed, myrinfo->id, adjwgt[j]); + + if (myrinfo->ed-myrinfo->id >= 0 && bndptr[ii] == -1) + BNDInsert(nbnd, bndind, bndptr, ii); + } + else if (me == to) { + INC_DEC(myrinfo->id, myrinfo->ed, adjwgt[j]); + + if (myrinfo->ed-myrinfo->id < 0 && bndptr[ii] != -1) + BNDDelete(nbnd, bndind, bndptr, ii); + } + + /* Remove contribution from the .ed of 'from' */ + if (me != from) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == from) { + if (myedegrees[k].ed == adjwgt[j]) + myedegrees[k] = myedegrees[--myrinfo->ndegrees]; + else + myedegrees[k].ed -= adjwgt[j]; + break; + } + } + } + + /* Add contribution to the .ed of 'to' */ + if (me != to) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (myedegrees[k].pid == to) { + myedegrees[k].ed += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + myedegrees[myrinfo->ndegrees].pid = to; + myedegrees[myrinfo->ndegrees++].ed = adjwgt[j]; + } + } + + ASSERT(CheckRInfo(myrinfo)); + } + + ASSERT(CheckRInfo(graph->rinfo+i)); + } + + graph->nbnd = nbnd; + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/timing.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/timing.c new file mode 100644 index 0000000..a9d0910 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/timing.c @@ -0,0 +1,74 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * timing.c + * + * This file contains routines that deal with timing Metis + * + * Started 7/24/97 + * George + * + * $Id: timing.c,v 1.1 2003/07/16 15:55:20 karypis Exp $ + * + */ + +#include <metis.h> + + +/************************************************************************* +* This function clears the timers +**************************************************************************/ +void InitTimers(CtrlType *ctrl) +{ + cleartimer(ctrl->TotalTmr); + cleartimer(ctrl->InitPartTmr); + cleartimer(ctrl->MatchTmr); + cleartimer(ctrl->ContractTmr); + cleartimer(ctrl->CoarsenTmr); + cleartimer(ctrl->UncoarsenTmr); + cleartimer(ctrl->RefTmr); + cleartimer(ctrl->ProjectTmr); + cleartimer(ctrl->SplitTmr); + cleartimer(ctrl->SepTmr); + cleartimer(ctrl->AuxTmr1); + cleartimer(ctrl->AuxTmr2); + cleartimer(ctrl->AuxTmr3); + cleartimer(ctrl->AuxTmr4); + cleartimer(ctrl->AuxTmr5); + cleartimer(ctrl->AuxTmr6); +} + + + +/************************************************************************* +* This function prints the various timers +**************************************************************************/ +void PrintTimers(CtrlType *ctrl) +{ + printf("\nTiming Information -------------------------------------------------"); + printf("\n Multilevel: \t\t %7.3f", gettimer(ctrl->TotalTmr)); + printf("\n Coarsening: \t\t %7.3f", gettimer(ctrl->CoarsenTmr)); + printf("\n Matching: \t\t\t %7.3f", gettimer(ctrl->MatchTmr)); + printf("\n Contract: \t\t\t %7.3f", gettimer(ctrl->ContractTmr)); + printf("\n Initial Partition: \t %7.3f", gettimer(ctrl->InitPartTmr)); + printf("\n Construct Separator: \t %7.3f", gettimer(ctrl->SepTmr)); + printf("\n Uncoarsening: \t\t %7.3f", gettimer(ctrl->UncoarsenTmr)); + printf("\n Refinement: \t\t\t %7.3f", gettimer(ctrl->RefTmr)); + printf("\n Projection: \t\t\t %7.3f", gettimer(ctrl->ProjectTmr)); + printf("\n Splitting: \t\t %7.3f", gettimer(ctrl->SplitTmr)); + printf("\n AUX1: \t\t %7.3f", gettimer(ctrl->AuxTmr1)); + printf("\n AUX2: \t\t %7.3f", gettimer(ctrl->AuxTmr2)); + printf("\n AUX3: \t\t %7.3f", gettimer(ctrl->AuxTmr3)); + printf("\n********************************************************************\n"); +} + + +/************************************************************************* +* This function returns the seconds +**************************************************************************/ +double seconds(void) +{ + return((double) clock()/CLOCKS_PER_SEC); +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/util.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/util.c new file mode 100644 index 0000000..5d2e739 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/util.c @@ -0,0 +1,511 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * util.c + * + * This function contains various utility routines + * + * Started 9/28/95 + * George + * + * $Id: util.c,v 1.2 2003/07/21 18:53:41 karypis Exp $ + */ + +#include <metis.h> + + +/************************************************************************* +* This function prints an error message and exits +**************************************************************************/ +void errexit(char *f_str,...) +{ + va_list argp; + char out1[256], out2[256]; + + va_start(argp, f_str); + vsprintf(out1, f_str, argp); + va_end(argp); + + sprintf(out2, "Error! %s", out1); + + fprintf(stdout, out2); + fflush(stdout); + + abort(); +} + + + +#ifndef DMALLOC +/************************************************************************* +* The following function allocates an array of integers +**************************************************************************/ +int *imalloc(int n, char *msg) +{ + if (n == 0) + return NULL; + + return (int *)GKmalloc(sizeof(int)*n, msg); +} + + +/************************************************************************* +* The following function allocates an array of integers +**************************************************************************/ +idxtype *idxmalloc(int n, char *msg) +{ + if (n == 0) + return NULL; + + return (idxtype *)GKmalloc(sizeof(idxtype)*n, msg); +} + + +/************************************************************************* +* The following function allocates an array of float +**************************************************************************/ +float *fmalloc(int n, char *msg) +{ + if (n == 0) + return NULL; + + return (float *)GKmalloc(sizeof(float)*n, msg); +} + + +/************************************************************************* +* The follwoing function allocates an array of integers +**************************************************************************/ +int *ismalloc(int n, int ival, char *msg) +{ + if (n == 0) + return NULL; + + return iset(n, ival, (int *)GKmalloc(sizeof(int)*n, msg)); +} + + + +/************************************************************************* +* The follwoing function allocates an array of integers +**************************************************************************/ +idxtype *idxsmalloc(int n, idxtype ival, char *msg) +{ + if (n == 0) + return NULL; + + return idxset(n, ival, (idxtype *)GKmalloc(sizeof(idxtype)*n, msg)); +} + + +/************************************************************************* +* This function is my wrapper around malloc +**************************************************************************/ +void *GKmalloc(int nbytes, char *msg) +{ + void *ptr; + + if (nbytes == 0) + return NULL; + + ptr = (void *)malloc(nbytes); + if (ptr == NULL) + errexit("***Memory allocation failed for %s. Requested size: %d bytes", msg, nbytes); + + return ptr; +} +#endif + +/************************************************************************* +* This function is my wrapper around free, allows multiple pointers +**************************************************************************/ +void GKfree(void **ptr1,...) +{ + va_list plist; + void **ptr; + + if (*ptr1 != NULL) + free(*ptr1); + *ptr1 = NULL; + + va_start(plist, ptr1); + + /* while ((int)(ptr = va_arg(plist, void **)) != -1) { */ + while ((ptr = va_arg(plist, void **)) != LTERM) { + if (*ptr != NULL) + free(*ptr); + *ptr = NULL; + } + + va_end(plist); +} + + +/************************************************************************* +* These functions set the values of a vector +**************************************************************************/ +int *iset(int n, int val, int *x) +{ + int i; + + for (i=0; i<n; i++) + x[i] = val; + + return x; +} + + +/************************************************************************* +* These functions set the values of a vector +**************************************************************************/ +idxtype *idxset(int n, idxtype val, idxtype *x) +{ + int i; + + for (i=0; i<n; i++) + x[i] = val; + + return x; +} + + +/************************************************************************* +* These functions set the values of a vector +**************************************************************************/ +float *sset(int n, float val, float *x) +{ + int i; + + for (i=0; i<n; i++) + x[i] = val; + + return x; +} + + + +/************************************************************************* +* These functions return the index of the maximum element in a vector +**************************************************************************/ +int iamax(int n, int *x) +{ + int i, max=0; + + for (i=1; i<n; i++) + max = (x[i] > x[max] ? i : max); + + return max; +} + + +/************************************************************************* +* These functions return the index of the maximum element in a vector +**************************************************************************/ +int idxamax(int n, idxtype *x) +{ + int i, max=0; + + for (i=1; i<n; i++) + max = (x[i] > x[max] ? i : max); + + return max; +} + +/************************************************************************* +* These functions return the index of the maximum element in a vector +**************************************************************************/ +int idxamax_strd(int n, idxtype *x, int incx) +{ + int i, max=0; + + n *= incx; + for (i=incx; i<n; i+=incx) + max = (x[i] > x[max] ? i : max); + + return max/incx; +} + + + +/************************************************************************* +* These functions return the index of the maximum element in a vector +**************************************************************************/ +int samax(int n, float *x) +{ + int i, max=0; + + for (i=1; i<n; i++) + max = (x[i] > x[max] ? i : max); + + return max; +} + +/************************************************************************* +* These functions return the index of the almost maximum element in a vector +**************************************************************************/ +int samax2(int n, float *x) +{ + int i, max1, max2; + + if (x[0] > x[1]) { + max1 = 0; + max2 = 1; + } + else { + max1 = 1; + max2 = 0; + } + + for (i=2; i<n; i++) { + if (x[i] > x[max1]) { + max2 = max1; + max1 = i; + } + else if (x[i] > x[max2]) + max2 = i; + } + + return max2; +} + + +/************************************************************************* +* These functions return the index of the minimum element in a vector +**************************************************************************/ +int idxamin(int n, idxtype *x) +{ + int i, min=0; + + for (i=1; i<n; i++) + min = (x[i] < x[min] ? i : min); + + return min; +} + + +/************************************************************************* +* These functions return the index of the minimum element in a vector +**************************************************************************/ +int samin(int n, float *x) +{ + int i, min=0; + + for (i=1; i<n; i++) + min = (x[i] < x[min] ? i : min); + + return min; +} + + +/************************************************************************* +* This function sums the entries in an array +**************************************************************************/ +int idxsum(int n, idxtype *x) +{ + int i, sum = 0; + + for (i=0; i<n; i++) + sum += x[i]; + + return sum; +} + + +/************************************************************************* +* This function sums the entries in an array +**************************************************************************/ +int idxsum_strd(int n, idxtype *x, int incx) +{ + int i, sum = 0; + + for (i=0; i<n; i++, x+=incx) { + sum += *x; + } + + return sum; +} + + +/************************************************************************* +* This function sums the entries in an array +**************************************************************************/ +void idxadd(int n, idxtype *x, idxtype *y) +{ + for (n--; n>=0; n--) + y[n] += x[n]; +} + + +/************************************************************************* +* This function sums the entries in an array +**************************************************************************/ +int charsum(int n, char *x) +{ + int i, sum = 0; + + for (i=0; i<n; i++) + sum += x[i]; + + return sum; +} + +/************************************************************************* +* This function sums the entries in an array +**************************************************************************/ +int isum(int n, int *x) +{ + int i, sum = 0; + + for (i=0; i<n; i++) + sum += x[i]; + + return sum; +} + +/************************************************************************* +* This function sums the entries in an array +**************************************************************************/ +float ssum(int n, float *x) +{ + int i; + float sum = 0.0; + + for (i=0; i<n; i++) + sum += x[i]; + + return sum; +} + +/************************************************************************* +* This function sums the entries in an array +**************************************************************************/ +float ssum_strd(int n, float *x, int incx) +{ + int i; + float sum = 0.0; + + for (i=0; i<n; i++, x+=incx) + sum += *x; + + return sum; +} + +/************************************************************************* +* This function sums the entries in an array +**************************************************************************/ +void sscale(int n, float alpha, float *x) +{ + int i; + + for (i=0; i<n; i++) + x[i] *= alpha; +} + + +/************************************************************************* +* This function computes a 2-norm +**************************************************************************/ +float snorm2(int n, float *v) +{ + int i; + float partial = 0; + + for (i = 0; i<n; i++) + partial += v[i] * v[i]; + + return sqrt(partial); +} + + + +/************************************************************************* +* This function computes a 2-norm +**************************************************************************/ +float sdot(int n, float *x, float *y) +{ + int i; + float partial = 0; + + for (i = 0; i<n; i++) + partial += x[i] * y[i]; + + return partial; +} + + +/************************************************************************* +* This function computes a 2-norm +**************************************************************************/ +void saxpy(int n, float alpha, float *x, int incx, float *y, int incy) +{ + int i; + + for (i=0; i<n; i++, x+=incx, y+=incy) + *y += alpha*(*x); +} + + + + +/************************************************************************* +* This file randomly permutes the contents of an array. +* flag == 0, don't initialize perm +* flag == 1, set p[i] = i +**************************************************************************/ +void RandomPermute(int n, idxtype *p, int flag) +{ + int i, u, v; + idxtype tmp; + + if (flag == 1) { + for (i=0; i<n; i++) + p[i] = i; + } + + if (n <= 4) + return; + + for (i=0; i<n; i+=16) { + u = RandomInRange(n-4); + v = RandomInRange(n-4); + SWAP(p[v], p[u], tmp); + SWAP(p[v+1], p[u+1], tmp); + SWAP(p[v+2], p[u+2], tmp); + SWAP(p[v+3], p[u+3], tmp); + } +} + + + +/************************************************************************* +* This function returns true if the a is a power of 2 +**************************************************************************/ +int ispow2(int a) +{ + for (; a%2 != 1; a = a>>1); + return (a > 1 ? 0 : 1); +} + + +/************************************************************************* +* This function initializes the random number generator +**************************************************************************/ +void InitRandom(int seed) +{ + if (seed == -1) + srand(4321); + else + srand(seed); +} + +/************************************************************************* +* This function returns the log2(x) +**************************************************************************/ +int log2Int(int a) +{ + int i; + + for (i=1; a > 1; i++, a = a>>1); + return i-1; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Makefile b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Makefile new file mode 100644 index 0000000..2d53371 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Makefile @@ -0,0 +1,13 @@ + + +default: + (cd METISLib ; make ) + (cd ParMETISLib ; make ) + (cd Programs ; make ) + +clean: + (cd METISLib ; make realclean ) + (cd ParMETISLib ; make realclean ) + (cd Programs ; make realclean ) + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Makefile.in b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Makefile.in new file mode 100644 index 0000000..af82bb1 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Makefile.in @@ -0,0 +1,32 @@ + +# Which compiler to use +CC = mpicc + + +# What optimization level to use +OPTFLAGS = -O3 + +# Include directories for the compiler +INCDIR = -I/opt/local/include -I/usr/include/malloc + +# What options to be used by the compiler +COPTIONS = + +# Which loader to use +LD = mpicc + +# In which directories to look for any additional libraries +LIBDIR = -L/usr/lib64 -L/usr/lib64/mpi/gcc/openmpi/lib64/ + +# What additional libraries to link the programs with (eg., -lmpi) +#XTRALIBS = -lefence +#XTRALIBS = -ldmalloc + +# What archiving to use +AR = ar rv + +# What to use for indexing the archive +#RANLIB = ranlib +RANLIB = ar -ts + +VERNUM = diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Makefile.osx b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Makefile.osx new file mode 100644 index 0000000..a8a3172 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Makefile.osx @@ -0,0 +1,32 @@ + +# Which compiler to use +CC = mpicc + + +# What optimization level to use +OPTFLAGS = -g + +# Include directories for the compiler +INCDIR = -I/opt/local/include -I/usr/include/malloc + +# What options to be used by the compiler +COPTIONS = + +# Which loader to use +LD = mpicc + +# In which directories to look for any additional libraries +LIBDIR = -L/opt/local/lib -L/usr/lib + +# What additional libraries to link the programs with (eg., -lmpi) +#XTRALIBS = -lefence +#XTRALIBS = -ldmalloc + +# What archiving to use +AR = ar rv + +# What to use for indexing the archive +#RANLIB = ranlib +RANLIB = ar -ts + +VERNUM = diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Makefile.rtc b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Makefile.rtc new file mode 100644 index 0000000..a5626c2 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Makefile.rtc @@ -0,0 +1,33 @@ + +# Which compiler to use +CC = mpicc + + +# What optimization level to use +OPTFLAGS = -g + +# Include directories for the compiler +INCDIR = +# -I/opt/local/include -I/usr/include/malloc + +# What options to be used by the compiler +COPTIONS = + +# Which loader to use +LD = mpicc + +# In which directories to look for any additional libraries +LIBDIR = -L/opt/local/lib -L/usr/lib + +# What additional libraries to link the programs with (eg., -lmpi) +#XTRALIBS = -lefence +#XTRALIBS = -ldmalloc + +# What archiving to use +AR = ar rv + +# What to use for indexing the archive +#RANLIB = ranlib +RANLIB = ar -ts + +VERNUM = diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Manual/manual.pdf b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Manual/manual.pdf Binary files differnew file mode 100644 index 0000000..737e641 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Manual/manual.pdf diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Manual/manual.ps b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Manual/manual.ps new file mode 100644 index 0000000..bfe57d8 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Manual/manual.ps @@ -0,0 +1,6812 @@ +%!PS-Adobe-2.0 +%%Creator: dvips(k) 5.86 Copyright 1999 Radical Eye Software +%%Title: manual.dvi +%%Pages: 29 +%%PageOrder: Ascend +%%BoundingBox: 0 0 612 792 +%%DocumentFonts: Helvetica-Bold MTSYN AvantGarde-Demi Helvetica +%%+ Times-Roman Times-Bold RMTMI Times-Italic Helvetica-Narrow-Bold +%%+ Helvetica-Narrow Times-BoldItalic Courier MTEX +%%EndComments +%DVIPSWebPage: (www.radicaleye.com) +%DVIPSCommandLine: dvips -o manual.ps manual +%DVIPSParameters: dpi=1200, compressed +%DVIPSSource: TeX output 2003.08.15:1401 +%%BeginProcSet: texc.pro +%! +/TeXDict 300 dict def TeXDict begin/N{def}def/B{bind def}N/S{exch}N/X{S +N}B/A{dup}B/TR{translate}N/isls false N/vsize 11 72 mul N/hsize 8.5 72 +mul N/landplus90{false}def/@rigin{isls{[0 landplus90{1 -1}{-1 1}ifelse 0 +0 0]concat}if 72 Resolution div 72 VResolution div neg scale isls{ +landplus90{VResolution 72 div vsize mul 0 exch}{Resolution -72 div hsize +mul 0}ifelse TR}if Resolution VResolution vsize -72 div 1 add mul TR[ +matrix currentmatrix{A A round sub abs 0.00001 lt{round}if}forall round +exch round exch]setmatrix}N/@landscape{/isls true N}B/@manualfeed{ +statusdict/manualfeed true put}B/@copies{/#copies X}B/FMat[1 0 0 -1 0 0] +N/FBB[0 0 0 0]N/nn 0 N/IEn 0 N/ctr 0 N/df-tail{/nn 8 dict N nn begin +/FontType 3 N/FontMatrix fntrx N/FontBBox FBB N string/base X array +/BitMaps X/BuildChar{CharBuilder}N/Encoding IEn N end A{/foo setfont}2 +array copy cvx N load 0 nn put/ctr 0 N[}B/sf 0 N/df{/sf 1 N/fntrx FMat N +df-tail}B/dfs{div/sf X/fntrx[sf 0 0 sf neg 0 0]N df-tail}B/E{pop nn A +definefont setfont}B/Cw{Cd A length 5 sub get}B/Ch{Cd A length 4 sub get +}B/Cx{128 Cd A length 3 sub get sub}B/Cy{Cd A length 2 sub get 127 sub} +B/Cdx{Cd A length 1 sub get}B/Ci{Cd A type/stringtype ne{ctr get/ctr ctr +1 add N}if}B/id 0 N/rw 0 N/rc 0 N/gp 0 N/cp 0 N/G 0 N/CharBuilder{save 3 +1 roll S A/base get 2 index get S/BitMaps get S get/Cd X pop/ctr 0 N Cdx +0 Cx Cy Ch sub Cx Cw add Cy setcachedevice Cw Ch true[1 0 0 -1 -.1 Cx +sub Cy .1 sub]/id Ci N/rw Cw 7 add 8 idiv string N/rc 0 N/gp 0 N/cp 0 N{ +rc 0 ne{rc 1 sub/rc X rw}{G}ifelse}imagemask restore}B/G{{id gp get/gp +gp 1 add N A 18 mod S 18 idiv pl S get exec}loop}B/adv{cp add/cp X}B +/chg{rw cp id gp 4 index getinterval putinterval A gp add/gp X adv}B/nd{ +/cp 0 N rw exit}B/lsh{rw cp 2 copy get A 0 eq{pop 1}{A 255 eq{pop 254}{ +A A add 255 and S 1 and or}ifelse}ifelse put 1 adv}B/rsh{rw cp 2 copy +get A 0 eq{pop 128}{A 255 eq{pop 127}{A 2 idiv S 128 and or}ifelse} +ifelse put 1 adv}B/clr{rw cp 2 index string putinterval adv}B/set{rw cp +fillstr 0 4 index getinterval putinterval adv}B/fillstr 18 string 0 1 17 +{2 copy 255 put pop}for N/pl[{adv 1 chg}{adv 1 chg nd}{1 add chg}{1 add +chg nd}{adv lsh}{adv lsh nd}{adv rsh}{adv rsh nd}{1 add adv}{/rc X nd}{ +1 add set}{1 add clr}{adv 2 chg}{adv 2 chg nd}{pop nd}]A{bind pop} +forall N/D{/cc X A type/stringtype ne{]}if nn/base get cc ctr put nn +/BitMaps get S ctr S sf 1 ne{A A length 1 sub A 2 index S get sf div put +}if put/ctr ctr 1 add N}B/I{cc 1 add D}B/bop{userdict/bop-hook known{ +bop-hook}if/SI save N @rigin 0 0 moveto/V matrix currentmatrix A 1 get A +mul exch 0 get A mul add .99 lt{/QV}{/RV}ifelse load def pop pop}N/eop{ +SI restore userdict/eop-hook known{eop-hook}if showpage}N/@start{ +userdict/start-hook known{start-hook}if pop/VResolution X/Resolution X +1000 div/DVImag X/IEn 256 array N 2 string 0 1 255{IEn S A 360 add 36 4 +index cvrs cvn put}for pop 65781.76 div/vsize X 65781.76 div/hsize X}N +/p{show}N/RMat[1 0 0 -1 0 0]N/BDot 260 string N/Rx 0 N/Ry 0 N/V{}B/RV/v{ +/Ry X/Rx X V}B statusdict begin/product where{pop false[(Display)(NeXT) +(LaserWriter 16/600)]{A length product length le{A length product exch 0 +exch getinterval eq{pop true exit}if}{pop}ifelse}forall}{false}ifelse +end{{gsave TR -.1 .1 TR 1 1 scale Rx Ry false RMat{BDot}imagemask +grestore}}{{gsave TR -.1 .1 TR Rx Ry scale 1 1 false RMat{BDot} +imagemask grestore}}ifelse B/QV{gsave newpath transform round exch round +exch itransform moveto Rx 0 rlineto 0 Ry neg rlineto Rx neg 0 rlineto +fill grestore}B/a{moveto}B/delta 0 N/tail{A/delta X 0 rmoveto}B/M{S p +delta add tail}B/b{S p tail}B/c{-4 M}B/d{-3 M}B/e{-2 M}B/f{-1 M}B/g{0 M} +B/h{1 M}B/i{2 M}B/j{3 M}B/k{4 M}B/w{0 rmoveto}B/l{p -4 w}B/m{p -3 w}B/n{ +p -2 w}B/o{p -1 w}B/q{p 1 w}B/r{p 2 w}B/s{p 3 w}B/t{p 4 w}B/x{0 S +rmoveto}B/y{3 2 roll p a}B/bos{/SS save N}B/eos{SS restore}B end + +%%EndProcSet +%%BeginProcSet: psfrag.pro +%% +%% This is file `psfrag.pro', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% psfrag.dtx (with options: `filepro') +%% +%% Copyright (c) 1996 Craig Barratt, Michael C. Grant, and David Carlisle. +%% All rights reserved. +%% +%% This file is part of the PSfrag package. +%% +userdict begin +/PSfragLib 90 dict def +/PSfragDict 6 dict def +/PSfrag { PSfragLib begin load exec end } bind def +end +PSfragLib begin +/RO /readonly load def +/CP /currentpoint load def +/CM /currentmatrix load def +/B { bind RO def } bind def +/X { exch def } B +/MD { { X } forall } B +/OE { end exec PSfragLib begin } B +/S false def +/tstr 8 string def +/islev2 { languagelevel } stopped { false } { 2 ge } ifelse def +[ /sM /tM /srcM /dstM /dM /idM /srcFM /dstFM ] { matrix def } forall +sM currentmatrix RO pop +dM defaultmatrix RO idM invertmatrix RO pop +srcFM identmatrix pop +/Hide { gsave { CP } stopped not newpath clip { moveto } if } B +/Unhide { { CP } stopped not grestore { moveto } if } B +/setrepl islev2 {{ /glob currentglobal def true setglobal array astore + globaldict exch /PSfrags exch put glob setglobal }} + {{ array astore /PSfrags X }} ifelse B +/getrepl islev2 {{ globaldict /PSfrags get aload length }} + {{ PSfrags aload length }} ifelse B +/convert { + /src X src length string + /c 0 def src length { + dup c src c get dup 32 lt { pop 32 } if put /c c 1 add def + } repeat +} B +/Begin { + /saver save def + srcFM exch 3 exch put + 0 ne /debugMode X 0 setrepl + dup /S exch dict def { S 3 1 roll exch convert exch put } repeat + srcM CM dup invertmatrix pop + mark { currentdict { end } stopped { pop exit } if } loop + PSfragDict counttomark { begin } repeat pop +} B +/End { + mark { currentdict end dup PSfragDict eq { pop exit } if } loop + counttomark { begin } repeat pop + getrepl saver restore + 7 idiv dup /S exch dict def { + 6 array astore /mtrx X tstr cvs /K X + S K [ S K known { S K get aload pop } if mtrx ] put + } repeat +} B +/Place { + tstr cvs /K X + S K known { + bind /proc X tM CM pop + CP /cY X /cX X + 0 0 transform idtransform neg /aY X neg /aX X + S K get dup length /maxiter X + /iter 1 def { + iter maxiter ne { /saver save def } if + tM setmatrix aX aY translate + [ exch aload pop idtransform ] concat + cX neg cY neg translate cX cY moveto + /proc load OE + iter maxiter ne { saver restore /iter iter 1 add def } if + } forall + /noXY { CP /cY X /cX X } stopped def + tM setmatrix noXY { newpath } { cX cY moveto } ifelse + } { + Hide OE Unhide + } ifelse +} B +/normalize { + 2 index dup mul 2 index dup mul add sqrt div + dup 4 -1 roll exch mul 3 1 roll mul +} B +/replace { + aload pop MD + CP /bY X /lX X gsave sM setmatrix + str stringwidth abs exch abs add dup 0 eq + { pop } { 360 exch div dup scale } ifelse + lX neg bY neg translate newpath lX bY moveto + str { /ch X ( ) dup 0 ch put false charpath ch Kproc } forall + flattenpath pathbbox [ /uY /uX /lY /lX ] MD + CP grestore moveto + currentfont /FontMatrix get dstFM copy dup + 0 get 0 lt { uX lX /uX X /lX X } if + 3 get 0 lt { uY lY /uY X /lY X } if + /cX uX lX add 0.5 mul def + /cY uY lY add 0.5 mul def + debugMode { gsave 0 setgray 1 setlinewidth + lX lY moveto lX uY lineto uX uY lineto uX lY lineto closepath + lX bY moveto uX bY lineto lX cY moveto uX cY lineto + cX lY moveto cX uY lineto stroke + grestore } if + dstFM dup invertmatrix dstM CM srcM + 2 { dstM concatmatrix } repeat pop + getrepl /temp X + S str convert get { + aload pop [ /rot /scl /loc /K ] MD + /aX cX def /aY cY def + loc { + dup 66 eq { /aY bY def } { % B + dup 98 eq { /aY lY def } { % b + dup 108 eq { /aX lX def } { % l + dup 114 eq { /aX uX def } { % r + dup 116 eq { /aY uY def } % t + if } ifelse } ifelse } ifelse } ifelse pop + } forall + K srcFM rot tM rotate dstM + 2 { tM concatmatrix } repeat aload pop pop pop + 2 { scl normalize 4 2 roll } repeat + aX aY transform + /temp temp 7 add def + } forall + temp setrepl +} B +/Rif { + S 3 index convert known { pop replace } { exch pop OE } ifelse +} B +/XA { bind [ /Kproc /str } B /XC { ] 2 array astore def } B +/xs { pop } XA XC +/xks { /kern load OE } XA /kern XC +/xas { pop ax ay rmoveto } XA /ay /ax XC +/xws { c eq { cx cy rmoveto } if } XA /c /cy /cx XC +/xaws { ax ay rmoveto c eq { cx cy rmoveto } if } + XA /ay /ax /c /cy /cx XC +/raws { xaws { awidthshow } Rif } B +/rws { xws { widthshow } Rif } B +/rks { xks { kshow } Rif } B +/ras { xas { ashow } Rif } B +/rs { xs { show } Rif } B +/rrs { getrepl dup 2 add -1 roll //restore exec setrepl } B +PSfragDict begin +islev2 not { /restore { /rrs PSfrag } B } if +/show { /rs PSfrag } B +/kshow { /rks PSfrag } B +/ashow { /ras PSfrag } B +/widthshow { /rws PSfrag } B +/awidthshow { /raws PSfrag } B +end PSfragDict RO pop +end + +%%EndProcSet +%%BeginProcSet: 8r.enc +% @@psencodingfile@{ +% author = "S. Rahtz, P. MacKay, Alan Jeffrey, B. Horn, K. Berry", +% version = "0.6", +% date = "1 July 1998", +% filename = "8r.enc", +% email = "tex-fonts@@tug.org", +% docstring = "Encoding for TrueType or Type 1 fonts +% to be used with TeX." +% @} +% +% Idea is to have all the characters normally included in Type 1 fonts +% available for typesetting. This is effectively the characters in Adobe +% Standard Encoding + ISO Latin 1 + extra characters from Lucida. +% +% Character code assignments were made as follows: +% +% (1) the Windows ANSI characters are almost all in their Windows ANSI +% positions, because some Windows users cannot easily reencode the +% fonts, and it makes no difference on other systems. The only Windows +% ANSI characters not available are those that make no sense for +% typesetting -- rubout (127 decimal), nobreakspace (160), softhyphen +% (173). quotesingle and grave are moved just because it's such an +% irritation not having them in TeX positions. +% +% (2) Remaining characters are assigned arbitrarily to the lower part +% of the range, avoiding 0, 10 and 13 in case we meet dumb software. +% +% (3) Y&Y Lucida Bright includes some extra text characters; in the +% hopes that other PostScript fonts, perhaps created for public +% consumption, will include them, they are included starting at 0x12. +% +% (4) Remaining positions left undefined are for use in (hopefully) +% upward-compatible revisions, if someday more characters are generally +% available. +% +% (5) hyphen appears twice for compatibility with both +% ASCII and Windows. +% +/TeXBase1Encoding [ +% 0x00 (encoded characters from Adobe Standard not in Windows 3.1) + /.notdef /dotaccent /fi /fl + /fraction /hungarumlaut /Lslash /lslash + /ogonek /ring /.notdef + /breve /minus /.notdef +% These are the only two remaining unencoded characters, so may as +% well include them. + /Zcaron /zcaron +% 0x10 + /caron /dotlessi +% (unusual TeX characters available in, e.g., Lucida Bright) + /dotlessj /ff /ffi /ffl + /.notdef /.notdef /.notdef /.notdef + /.notdef /.notdef /.notdef /.notdef + % very contentious; it's so painful not having quoteleft and quoteright + % at 96 and 145 that we move the things normally found there to here. + /grave /quotesingle +% 0x20 (ASCII begins) + /space /exclam /quotedbl /numbersign + /dollar /percent /ampersand /quoteright + /parenleft /parenright /asterisk /plus /comma /hyphen /period /slash +% 0x30 + /zero /one /two /three /four /five /six /seven + /eight /nine /colon /semicolon /less /equal /greater /question +% 0x40 + /at /A /B /C /D /E /F /G /H /I /J /K /L /M /N /O +% 0x50 + /P /Q /R /S /T /U /V /W + /X /Y /Z /bracketleft /backslash /bracketright /asciicircum /underscore +% 0x60 + /quoteleft /a /b /c /d /e /f /g /h /i /j /k /l /m /n /o +% 0x70 + /p /q /r /s /t /u /v /w + /x /y /z /braceleft /bar /braceright /asciitilde + /.notdef % rubout; ASCII ends +% 0x80 + /.notdef /.notdef /quotesinglbase /florin + /quotedblbase /ellipsis /dagger /daggerdbl + /circumflex /perthousand /Scaron /guilsinglleft + /OE /.notdef /.notdef /.notdef +% 0x90 + /.notdef /.notdef /.notdef /quotedblleft + /quotedblright /bullet /endash /emdash + /tilde /trademark /scaron /guilsinglright + /oe /.notdef /.notdef /Ydieresis +% 0xA0 + /.notdef % nobreakspace + /exclamdown /cent /sterling + /currency /yen /brokenbar /section + /dieresis /copyright /ordfeminine /guillemotleft + /logicalnot + /hyphen % Y&Y (also at 45); Windows' softhyphen + /registered + /macron +% 0xD0 + /degree /plusminus /twosuperior /threesuperior + /acute /mu /paragraph /periodcentered + /cedilla /onesuperior /ordmasculine /guillemotright + /onequarter /onehalf /threequarters /questiondown +% 0xC0 + /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla + /Egrave /Eacute /Ecircumflex /Edieresis + /Igrave /Iacute /Icircumflex /Idieresis +% 0xD0 + /Eth /Ntilde /Ograve /Oacute + /Ocircumflex /Otilde /Odieresis /multiply + /Oslash /Ugrave /Uacute /Ucircumflex + /Udieresis /Yacute /Thorn /germandbls +% 0xE0 + /agrave /aacute /acircumflex /atilde + /adieresis /aring /ae /ccedilla + /egrave /eacute /ecircumflex /edieresis + /igrave /iacute /icircumflex /idieresis +% 0xF0 + /eth /ntilde /ograve /oacute + /ocircumflex /otilde /odieresis /divide + /oslash /ugrave /uacute /ucircumflex + /udieresis /yacute /thorn /ydieresis +] def + +%%EndProcSet +%%BeginProcSet: texps.pro +%! +TeXDict begin/rf{findfont dup length 1 add dict begin{1 index/FID ne 2 +index/UniqueID ne and{def}{pop pop}ifelse}forall[1 index 0 6 -1 roll +exec 0 exch 5 -1 roll VResolution Resolution div mul neg 0 0]/Metrics +exch def dict begin Encoding{exch dup type/integertype ne{pop pop 1 sub +dup 0 le{pop}{[}ifelse}{FontMatrix 0 get div Metrics 0 get div def} +ifelse}forall Metrics/Metrics currentdict end def[2 index currentdict +end definefont 3 -1 roll makefont/setfont cvx]cvx def}def/ObliqueSlant{ +dup sin S cos div neg}B/SlantFont{4 index mul add}def/ExtendFont{3 -1 +roll mul exch}def/ReEncodeFont{CharStrings rcheck{/Encoding false def +dup[exch{dup CharStrings exch known not{pop/.notdef/Encoding true def} +if}forall Encoding{]exch pop}{cleartomark}ifelse}if/Encoding exch def} +def end + +%%EndProcSet +%%BeginProcSet: special.pro +%! +TeXDict begin/SDict 200 dict N SDict begin/@SpecialDefaults{/hs 612 N +/vs 792 N/ho 0 N/vo 0 N/hsc 1 N/vsc 1 N/ang 0 N/CLIP 0 N/rwiSeen false N +/rhiSeen false N/letter{}N/note{}N/a4{}N/legal{}N}B/@scaleunit 100 N +/@hscale{@scaleunit div/hsc X}B/@vscale{@scaleunit div/vsc X}B/@hsize{ +/hs X/CLIP 1 N}B/@vsize{/vs X/CLIP 1 N}B/@clip{/CLIP 2 N}B/@hoffset{/ho +X}B/@voffset{/vo X}B/@angle{/ang X}B/@rwi{10 div/rwi X/rwiSeen true N}B +/@rhi{10 div/rhi X/rhiSeen true N}B/@llx{/llx X}B/@lly{/lly X}B/@urx{ +/urx X}B/@ury{/ury X}B/magscale true def end/@MacSetUp{userdict/md known +{userdict/md get type/dicttype eq{userdict begin md length 10 add md +maxlength ge{/md md dup length 20 add dict copy def}if end md begin +/letter{}N/note{}N/legal{}N/od{txpose 1 0 mtx defaultmatrix dtransform S +atan/pa X newpath clippath mark{transform{itransform moveto}}{transform{ +itransform lineto}}{6 -2 roll transform 6 -2 roll transform 6 -2 roll +transform{itransform 6 2 roll itransform 6 2 roll itransform 6 2 roll +curveto}}{{closepath}}pathforall newpath counttomark array astore/gc xdf +pop ct 39 0 put 10 fz 0 fs 2 F/|______Courier fnt invertflag{PaintBlack} +if}N/txpose{pxs pys scale ppr aload pop por{noflips{pop S neg S TR pop 1 +-1 scale}if xflip yflip and{pop S neg S TR 180 rotate 1 -1 scale ppr 3 +get ppr 1 get neg sub neg ppr 2 get ppr 0 get neg sub neg TR}if xflip +yflip not and{pop S neg S TR pop 180 rotate ppr 3 get ppr 1 get neg sub +neg 0 TR}if yflip xflip not and{ppr 1 get neg ppr 0 get neg TR}if}{ +noflips{TR pop pop 270 rotate 1 -1 scale}if xflip yflip and{TR pop pop +90 rotate 1 -1 scale ppr 3 get ppr 1 get neg sub neg ppr 2 get ppr 0 get +neg sub neg TR}if xflip yflip not and{TR pop pop 90 rotate ppr 3 get ppr +1 get neg sub neg 0 TR}if yflip xflip not and{TR pop pop 270 rotate ppr +2 get ppr 0 get neg sub neg 0 S TR}if}ifelse scaleby96{ppr aload pop 4 +-1 roll add 2 div 3 1 roll add 2 div 2 copy TR .96 dup scale neg S neg S +TR}if}N/cp{pop pop showpage pm restore}N end}if}if}N/normalscale{ +Resolution 72 div VResolution 72 div neg scale magscale{DVImag dup scale +}if 0 setgray}N/psfts{S 65781.76 div N}N/startTexFig{/psf$SavedState +save N userdict maxlength dict begin/magscale true def normalscale +currentpoint TR/psf$ury psfts/psf$urx psfts/psf$lly psfts/psf$llx psfts +/psf$y psfts/psf$x psfts currentpoint/psf$cy X/psf$cx X/psf$sx psf$x +psf$urx psf$llx sub div N/psf$sy psf$y psf$ury psf$lly sub div N psf$sx +psf$sy scale psf$cx psf$sx div psf$llx sub psf$cy psf$sy div psf$ury sub +TR/showpage{}N/erasepage{}N/copypage{}N/p 3 def @MacSetUp}N/doclip{ +psf$llx psf$lly psf$urx psf$ury currentpoint 6 2 roll newpath 4 copy 4 2 +roll moveto 6 -1 roll S lineto S lineto S lineto closepath clip newpath +moveto}N/endTexFig{end psf$SavedState restore}N/@beginspecial{SDict +begin/SpecialSave save N gsave normalscale currentpoint TR +@SpecialDefaults count/ocount X/dcount countdictstack N}N/@setspecial{ +CLIP 1 eq{newpath 0 0 moveto hs 0 rlineto 0 vs rlineto hs neg 0 rlineto +closepath clip}if ho vo TR hsc vsc scale ang rotate rwiSeen{rwi urx llx +sub div rhiSeen{rhi ury lly sub div}{dup}ifelse scale llx neg lly neg TR +}{rhiSeen{rhi ury lly sub div dup scale llx neg lly neg TR}if}ifelse +CLIP 2 eq{newpath llx lly moveto urx lly lineto urx ury lineto llx ury +lineto closepath clip}if/showpage{}N/erasepage{}N/copypage{}N newpath}N +/@endspecial{count ocount sub{pop}repeat countdictstack dcount sub{end} +repeat grestore SpecialSave restore end}N/@defspecial{SDict begin}N +/@fedspecial{end}B/li{lineto}B/rl{rlineto}B/rc{rcurveto}B/np{/SaveX +currentpoint/SaveY X N 1 setlinecap newpath}N/st{stroke SaveX SaveY +moveto}N/fil{fill SaveX SaveY moveto}N/ellipse{/endangle X/startangle X +/yrad X/xrad X/savematrix matrix currentmatrix N TR xrad yrad scale 0 0 +1 startangle endangle arc savematrix setmatrix}N end + +%%EndProcSet +TeXDict begin @defspecial + + TeXDict begin /box{newpath 2 copy moveto 3 copy pop exch lineto 4 +copy pop pop lineto 4 copy exch pop exch pop lineto closepath } bind +def /min{ 2 copy gt { exch } if pop } bind def/max{ 2 copy lt { exch +} if pop } bind def/roundedbox{/radius exch store 3 2 roll 2 copy min +radius sub /miny exch store max radius add /maxy exch store 2 copy +min radius sub /minx exch store max radius add /maxx exch store newpath +minx radius add miny moveto maxx miny maxx maxy radius arcto maxx maxy +minx maxy radius arcto minx maxy minx miny radius arcto minx miny maxx +miny radius arcto 16 {pop} repeat closepath }bind def /rectcartouche{box +gsave .95 setgray fill grestore 1 setlinewidth stroke }bind def /cartouche{roundedbox +gsave .95 setgray fill grestore 1 setlinewidth stroke }bind def end + +@fedspecial end +%%BeginFont: RMTMI +%!PS-AdobeFont-1.1: RMTMI 1.1 +%%CreationDate: 1993 May 10 16:52:31 + +% Copyright (c) 1992, 1993 The TeXplorators Corporation +% Hinting Copyright (c) 1992, 1993 Y&Y, Inc. + +11 dict begin +/FontInfo 9 dict dup begin +/version (1.1) readonly def +/Notice (Copyright (C) 1992, 1993 The TeXplorators Corporation) readonly def +/FullName (RMTMI) readonly def +/FamilyName (MathTime) readonly def +/Weight (Medium) readonly def +/ItalicAngle -14.036 def +/isFixedPitch false def +/UnderlinePosition -100 def +/UnderlineThickness 50 def +end readonly def +/FontName /RMTMI def +/PaintType 0 def +/FontType 1 def +/FontMatrix [0.001 0 0 0.001 0 0] readonly def +/Encoding 256 array +0 1 255 {1 index exch /.notdef put} for +dup 46 /parenleft put +dup 47 /parenright put +dup 58 /period put +dup 59 /comma put +dup 61 /slash put +dup 118 /v put +readonly def +/FontBBox{0 -213 987 680}readonly def +/UniqueXX 5018946 def +currentdict end +currentfile eexec +80347982ab3942d930e069a70d0d48311d70c1e2528f01045f8caec9829f31d6 +48c8d0a29ea851af41c327a0d569abaafe5afe94dad818c312d3cee72f1acea0 +b701b6a5608521a2866790bdd5776d6cd0c7d971b9a48b96aa970dcbb8b76edc +b90da356dc2529b665eb4bb80ac4f5b0f4c0ed76861e399638ad3db1be4759c7 +8d4f2e81a2ff688d366b91d729d63ab5fc9556fe10a07b81904d879a7446da82 +dc107ff41b0e3b7c2245d57b2ee9bab31eccfe9b79e3ec32cb1f10c622f4bce1 +8df0e5c4b98ec714593d6f127c5cf6d719a79b83c627433d3aa39cb88ef85d27 +4184c4b4c46ca5b496f20460ed75ccfb3d66073b710cc1ad2f2bec4ac64065ed +5e03930ed9ec97810f36845dd5048d90d724a88fd3c814ce17c417c84ba45c43 +f5569a4d73739f71544ed91c657705e131f4d0c61752509fbe0212bde9c02a83 +3910dff28f7c53f64b032c8e3cd2ba95c22177c3e0532f8699d106f119b80549 +c45726d793b9aec38ff4c3120c259083fd13c644dea026e1e7c75dea2ec23419 +83aff4d712c27c024393022797db1500c6543d620f20c9ce973ef7d917e7fb3e +6cfee0999e06c9dfff2d01bac5b3be0c47b2d5abc02e1f0f383588f430fa64bf +d5250e56da323c91f033c8f0f4e0f9cbb36eb8d4d25b127fda1bb032a7088cf6 +fb34b617290de038198297f2af323602e5e96d475e4678e129d88aa15d5ad9cb +58e244028cd8d9a8210fb1aecfc3f29299986c1df1cb3ffa0fc203626e8e2f6f +3a6ab198963acb2b528d6bc06687d59efddb9c88535c1c69da5d81812b911c5e +f9985179796d2b2e4e92beec47a4075e306c8d26431d8e0732768dff70ef2270 +d1fddddd4cca0f209ad05c9af2f26da7ca0acccdac0ea4f479b548c741193594 +d515f614bda3f394c77bd7296981ac947ca0d6d6ccafd9a05547b28f0ce449ff +bde2744249af134a1d3629edfec122c615e4a74067a7f8358519bfac0f31d1a4 +6d260a3db271750d02cd6a12d019ab6c1c2f9955ca205f12d8a03de3203bb5eb +869ed8b66b53d1c29eaa26b4d20f9460891b018031bf81eba788b77ccccc5ff9 +9acb5b025a4dcbafafc1b34bb2adbd17cdd741da586af1b784cf74cf88603b20 +d68afab47d21c1a0c6bee297777db1a8231237a40ec89aa97ce1c848c9da6804 +d3b98c11590b239616e0e6d668fc5b987075d77769eaf4877f1a359217b40731 +293574eae905bd7a5c46719ec7f8a97fac1c46dcd76b0344e8378fd61d02c990 +5b194613df280648e2f86ef15a2dd8e6bec1cac0d90b8302b2846127b2d50d8f +fb7d210c7826fde88f2d165fa6afd755db04910140e070126a663f3d57ea417e +d6d2128bf21a7cc2911f8bf0f2668eadbe8e042a1cdcea38c5c9a71226f6f4ed +bc85ddf8c25d80933a42f5f303e5495c247e973df20e2195b07b60657205de14 +9d86dbd56bb2594fea81688f21573a8210f6fbf48c82425bf58215b3d91d3255 +012f7b2bc17357bfb35cd40b0c1d5536cde7bd0b29dea7674b32bc83cb453bbf +76807cf4a5aeece57fae3d291ae50098b85e357e9606694fcfe15cc48406012b +f12efcea89892d1811b5ef93abad0e929160090fad55766535e605ecb8381777 +df5a2ac4a3e332a7e1b7ab9713a37619293bc7c8a69652ec4be93c6f786fab81 +e636cd8ad1959c266cb622f998c5c8762159cb792e123cb46042a84709054f39 +d5251483de5735331ab02cc31ad384dec4176d48661db17d104c4956474dce80 +2519c973688aa6609a0fcb3128bb928cb1e676def0e4ec52eb0ee05d55e6afa7 +fd22c8f9537de1f8f5fe275f190890ed4ee638b479a8727024d414971b191636 +744ae3a5022bca7b6b8f475aff1e4bb03ee9dbfefdd88aa2cad0d10339a42f6a +342fafa530f9707e723f7a2c90667b94f9764bf334eb294b35e3eef1c8410a28 +7e9cadcd03f3488f317d700b53c348e012ef4d3431b125aea4c7f00f79a3bd4a +d0edd781418b51543364a9e8b40a32b4554ddc0a7f2e1a48a682be1b990d6224 +651dd3dbdeede0555bf6cb4685bcb3b54b22f1d2f27d577f29188d708889f5cb +c45cab82180f3d7ff3a1fda6cd9776d22155e43a43c708cbd680a8e3880d74c1 +bf8db0b07dc626d744fd8b37050ee64faedb57746913c896e0abf7eadaf2c118 +bc1ee6cb292b41b403c365f6658d64c60e3494ab2ba9060425a72d27ca1fea5d +0fb89027036e31dfa311549ccfa914b87ebfea444a601d29276f6752eef4766a +4cf3bc60ccc488e457eb6cc458cde216dc0901e7ea735d9e57a83981fe52da47 +c17d764379cf63998c9ee47a80a87c9179a0238ad6ccb7521ab06487c7985f15 +70f2594db6b852d1ae2960f8d527b1e2f8f1bf54e9014712ad114db6c7844412 +823a8c57fa38ddcd8c6e34db04ded337c9b962ee864e2610ba2ee6fe644d239b +8e94fbc188cd16db10e20a9e93250acbec7756826ac93ff1df9308efd8507f05 +33327021fb1ef1ad82d501080e4f16b75c9b0d7d15cf75e51feb9ecd4a475e56 +51aa688761ace098dfcf96d604030f3428080cfa1efb5fcc97c750ebbe4ceeaf +969b0795eaff4e620dfb144780245a9fa0651eaf137f463bbbdd94fe0dcb754b +7d608d2ad9a92f329fb371ec0804de94c5d92e785a060c719d327a49b6210182 +2dad060c64e48259de0bbb77c269de5715ce9d8d85c6b6c1992f9a008b9c6012 +5f001f20735fa9d9343bc20b03fafb2a08e28d989df8f657071a81c14ffeb49c +dad0b4ddc301c096327836fb58ee41c0ad61e8aad9e0a6658f7f813de254e929 +4d0db0e46c07f6e9fbe9db98d48fdcc6e9c1c32dc043d28239e5b6f2ccff9cde +ec04dadcba1836fbe06cf3a1ba39504ece115764f78d0b8f812b9c0d03e4a2ea +663a4fd20ccc1c4c5465a76889eb987932462cf8cbff87ecc1c3004774f89f9f +f71e895d01a73866b9ae3d0d05776a488bd12a01c5f4c7813fceb413d1ba5f63 +26dc2121cd2fac85ffc91507 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +cleartomark + +%%EndFont +%%BeginFont: MTEX +%!PS-AdobeFont-1.1: MTEX 1.1 +%%CreationDate: 1993 Jun 26 10:30:36 + +% Copyright (c) 1992, 1993 The TeXplorators Corporation +% Hinting Copyright (c) 1992, 1993 Y&Y, Inc. + +11 dict begin +/FontInfo 9 dict dup begin +/version (1.1) readonly def +/Notice (Copyright (C) 1992, 1993 The TeXplorators Corporation) readonly def +/FullName (MTEX) readonly def +/FamilyName (MathTime) readonly def +/Weight (Medium) readonly def +/ItalicAngle 0 def +/isFixedPitch false def +/UnderlinePosition -100 def +/UnderlineThickness 50 def +end readonly def +/FontName /MTEX def +/PaintType 0 def +/FontType 1 def +/FontMatrix [0.001 0 0 0.001 0 0] readonly def +/Encoding 256 array +0 1 255 {1 index exch /.notdef put} for +dup 80 /summationtext put +readonly def +/FontBBox{-23 -2958 1456 766}readonly def +/UniqueXX 5018948 def +currentdict end +currentfile eexec +80347982ab3942d930e069a70d0d48311d70c1e2528f01045f8caec9829f31d6 +48c8d0a29ea851af41c327a0d569abaafe5afe94dad818c312d3cee72f1acea0 +b701b6a5608521a2866790bdd5776d6cd0c7d971b9a48b96aa970dcbb8b76edc +b90da356dc2529b665eb4bb80ac4f5b0f4c0ed76861e399638ad3db1be4759c7 +8d4f2e81a2ff688d366b91d729d63ab5fc9556fe10a07b81904d879a7446da82 +dc107ff41b0e3b7c2245d57b2ee9bab31eccfe9b79e3ec32cb1f10c622f4bce1 +8df0e5c4b98ec714593d6f127c5cf6d719a79b83c627433d3aa39cb88ef85d27 +4184c4b4c46ca5b496f20460ed75ccfb3d66073b710cc1ad2f2bec4ac64065ed +5e03930ed9ec97810f36845dd5048d90d724a88fd3c814ce17c417c84ba45c43 +f5569a4d73739f71544ed91c657705e131f4d0c61752509fbe0212bde9c02a83 +3910dff28f7c53f64b032c8e3cd2ba95c22177c3e0532f8699d106f119b80549 +c45726d793b9aec38ff4c3120c259083fd13c644dea026e1e7c75dea2ec23419 +83aff4d712c27c024393022797db1500c6543d620f20c9ce973ef7d917e7fb3e +6cfee0999e06c9dfff2d01bac5b3be0c47b2d5abc02e1f0f383588f430fa64bf +d5250e56da323c91f033c8f0f4e0f9cbb36eb8d4d25b127fda1bb032a7088cf6 +fb34b617290de038198297f2af323602e5e96d475e4678e129d88aa15d5ad9cb +58e244028cd8d9a8210fb1aecfc3f29299986c1df1cb3ffa0fc203626e8e2f6f +3a6ab198963acb2b528d6bc06687d59efddb9c88535c1c69da5d81812b911c5e +f9985179796d2b2e4e92beec47a4075e306c8d26431d8e0732768dff70ef2270 +d1fddddd4cca0f209ad05c9af2f26da7ca0accc0349d554800072fe70fe3f12f +846085405a3e13764f457e887846db5eca49493fb685acac9e0d4c5ca63c7b16 +408cb7eb5decb4429557acbe97a89d9360f0d29566678e6c2e3569923451905d +8951f729d6e4e166c0150cfade571c25f92820fc6fb202f2d010bdb81e8baa62 +32cd15f94af4804b08cddbc782c1295ed9d18025f1c453a678f58a7e1b7bcfba +4400dda52bd25ccaef380af4b5003dcc06f75960ac763ec42a6ef95eaf46f77b +3aa68bbc3c182d192d602a713f8082af7e531b1282e701d3a39904e4802c94b6 +df379cc5faf66b0fbc4e279ebe2154c755887098745ea0303640d9ecd80ad923 +deda40cca8136f760a6e4eaa342751fef587651a7c6394ed4fe12a07e33fcdc6 +15954ab2599f9a75ccf54e560b978add203d169ad883c855f40ec67c410bf468 +e7ad9a8fe58c601bf464797f492cb9354c0a21deb7e6e0b951770086d598fbd0 +138393a017903ac875192d5da1d671e70f91c6cd9722d168eebb3cffb58e5637 +3712ae6823a0b39fe863ce84e8a867c5d1f5611aefdf25d31c9896dcf5e320b0 +875dd95c3a3f8ba7a6331558180e833af7c1625d0a0efd6266b95ba0a2dc769e +694d43ab27088f81e8a7f25a9207efd5ab98f0390b28d219ac289fa217fa1e67 +d801778da34b6ca048034a044e83294061d64a98e7b5989ea55d9e4b046545c8 +41452c7e8f23ed381387e1ea4e2912922c12ecf8c2822605c9934c37fde6571c +287ae7d66b15afcac9e8a6b39c7b78c44630a58a2c75b90dda031bd6c638f8f2 +b8dfeb6d907570f17c05639011861348bfa5be91bf88b7f55b076e7b13da36d6 +edf2380bc2f78c7d0448611c015f938c51f03e600baf9474b670cc6dd9efe445 +69f2a13ce298af63e248e04bcf843a499cf72865e8e459c55ce949ba387e3931 +17ea030b510ae3abe57838cfd9280d2d51beaf22b4de8bc15d9d8715a0cf9c23 +cbb480ed646f36ffa612a82ad4ea8df8907af82d8d2a8e807dca8291b4c896b6 +929f19e14ef43c78734d823bdc212f879780e62b11b95205c8f19de83b297873 +7d0d7144430ebf265c93c7120ff9a762c2eec171a7ee5e3e19e82d43f9285a2c +4e51e2ed1ec7acb28fa010b27024cbf80c010d1ddcd9942413e033be71494e72 +67f05602dc769a9027fad4b026bf3d92f9fcf25c63ed663d7143a0c371376523 +6a919f21397e9b2e8bf7521e43683a15a1d942fb4d36d07e733db38079cd156d +e644c93c6628a5cbcab46d0a645484bf21aaf042be5f5b8e7e8294597bc5ab29 +478f4b931f7211 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +cleartomark + +%%EndFont +%%BeginFont: MTSYN +%!PS-AdobeFont-1.1: MTSYN 1.000 +%%CreationDate: 1996 Aug 26 20:27:17 + +% MathTime fonts were designed by Michael Spivak. +% Copyright (c) 1996 Publish or Perish, Inc. +% Hinting Copyright (c) 1996 Y&Y, Inc. +% MathTime is a registered trademark of Publish or Perish, Inc. + +11 dict begin +/FontInfo 9 dict dup begin +/version (1.000) readonly def +/Notice (Copyright (c) 1992-1996 Publish or Perish and Y&Y, Inc.) readonly def +/FullName (MTSYN) readonly def +/FamilyName (MathTime) readonly def +/Weight (Medium) readonly def +/ItalicAngle 0 def +/isFixedPitch false def +/UnderlinePosition -100 def +/UnderlineThickness 50 def +end readonly def +/FontName /MTSYN def +/PaintType 0 def +/FontType 1 def +/FontMatrix [0.001 0 0 0.001 0 0] readonly def +/Encoding 256 array +0 1 255 {1 index exch /.notdef put} for +dup 0 /minus put +dup 2 /multiply put +dup 3 /asteriskmath put +dup 15 /bullet put +dup 67 /plus put +dup 68 /equal put +dup 102 /braceleft put +dup 103 /braceright put +readonly def +/FontBBox{0 -954 1043 900}readonly def +/UniqueID 5087393 def +currentdict end +currentfile eexec +80347982ab3942d930e069a70d0d48311e252234d51741e18db3a68e8ad10242 +29e5817a10e796a78d2c7f7c1f50961b9a57aa604c9f821dbf5a9295197bc666 +31678d7d2c7e1f8f2151ce0c29efce46270570f4301c5dad1b38884732e53dad +05dfc36b020e726ca575f71f04abf2b49e1f1d6d2a08a477658ca9a48f1c8cce +14382f0a42201de56e2821ee2b0e91a818b1b753d810ec2428dae5153b66af66 +a6cbcba4db2bf926e909644db41326e327493b2750168d128a100fe56c76b17c +16f9ce939588d19c6e9cda7cb062196e66e38e537670953934ffc63663c7146a +12277d8f7c13b563981d696e0abe4478eabeba753024ebdf3ee17f2613df08c9 +228159906a48ddeed6212332ef96023e5c73ea55aac6a2b938138ec26b4732c1 +1e8fed889257e9d4f2002935585d9aa2265929948e37bab7adf12f1a22b3c68d +09a6b6c4e14b1470ecf0874d92d964cfbb8e2a0e4cbd1a114cc05bbdee4699a5 +76ab8c0bd8499b166e9e60b21f45561279f6474bb497e3d55dd09a26264ffa6e +8d9f228e894c456756d321bb5d5932c5bbcd39eb95f5b7d4dc2da25d6773ea6b +f8b758972bef890ed520777e90b017bb4f0f1a7076da33c972773e8ecfdf76b3 +47fe529109a1ea0d91b80161c32e4dfb08ef07f23680182631baf1bea4a5b9e5 +05311402d9263290e3cf4409b44edfe28038a0f2101424a9aa4ce83a902faaa4 +ee6da88833898cd9efb74a321458332cc9a62c93501cd1eb799c6da44f94c61a +da58024d0ced31cd07ba36a70d986aaad1d3b9c04d6acba7ecae982a8712ba24 +b26bc4bf9b042c6fcc9bf7d3404804e72d2b93fd4f56771495070aa0fd181c35 +cc11cf251be8dea12600643f2b79d09aa1bcf2636f70edf1f7e0e434df83b888 +598ece0100492a48645305b4bb8bf16cc994abdaf88ee7ca62fa459e42158053 +1f5bdfd3bd83467260f184afa17abff39208581863acd6632867c05ec9c11a91 +0e396f09359713c5b37ae855d3a2ff8657fb89cad579eb1baa0979eb227202e4 +4306b7c89d6b32c41795f994b293a6baf7df640c3f68cba7674e695121892c8d +f86d2c12158d6628ba8643af6c51d423799d274aa5cbefb8ead46fe7e2ae9971 +84e8e036793b47aae8a8bfe6fe656b789c232f3761e296dcda097e85b8a63a6e +bb0c07a4c86cd4bdebb8cd50299e1efa106ecfbf361f5787095aaf4bfec3b442 +d91941d799c1260629f7829354981d7c999bb9277533e8f949735eb63c17c620 +64c68743ffb4b7708b0e58fd575a2e0331624bc5867a495f88565ba4779c38ad +cb9e7d8b66d67ba91b48fea71a1ea1ab965a807bf793faddf073934a5a2886db +c9b8d3f807568cb2261038afb4a639b960ae3c2248eb17dace94c4c2460c70b2 +113fdeb93813a5e7ffc9c5808a3d5b381a890a7246f2dd5848357f12e9bee65f +6b7f68055190810b5dcabff800f13ba97650e9100a69f6a40c7b4385e627952d +82eebbbf053d5c0dd068212fc546d222bc888e7b2e6af864d71b3b6bd0d3b0f6 +ff7c72a08fe798e85f5c83f372b14fc206b7d0b67e50d1bd7257ce74872d7736 +79a0237c84f1520102efce483eceb4e8414ef2e50c30e76166166dfc0eec9dbf +f02764d84eaf448d955eabbbae38aa9569ce31e7660e663582d8f6a50afa2c83 +d6ba455efcb9a13945f0ee5ad9bb00381d666e201d9cbf7b90b006d94251a6a8 +2bf32f07415b2919aaa4b9b043842edee3f8322e5d7c3c3ec226398c53e10012 +ee7cdb28b2599a431e7e412630623b8cf22b1e2bb64bd233f675659d35011002 +5b9e1045711592076917e961fce901770dbe0913422334487b11b41e2a4f44a9 +8a80b0177903da131592075162e55d83f841562737e4aacb808c009d4cc20761 +6512621af048858cf8f18b307709712964702144eb218aae8cececc161507a0e +754694dd18367bcc2a3de7581683ab19b9c5a187b9101df51a51df5167a68a31 +f3924bf4ce4d6d2941c84b052a11f7bbb27e6a3c6d8ef978e97c27b085d31a43 +f25e3a768fdaeb8b9a247752dde160c41225db9d487a67b3ddc5d518bdea3052 +5a2f648107f1d3da192ebd26834b5920afe148b8f9fd944e4fd65e5d9ab42e51 +b381feebd3f2a56bc465f801656ae6aaa83df9c9f63bfa89bd7469cdd230fb76 +5090e7d39a462d87b970c7fd1ea098061e3ae156808dec95657b1a8adbeb1eb0 +ed6d2bcefecd4382c64c6a275e962aa83c47b9aab2b832716e713848dcb6ba57 +66cf434bacce548d8eeb33504ec27f1c12af40cd15c28aa0a3396079780e25c4 +9b3cbdaf7d26a03e98d57cf2709e723357ad48df971b28467f77d18d0485e080 +3484a2d94efc2d44aef79dc0b4f944a8d1fc46ee9a07b63c908c36032b3dba0f +07f43333a5584c7132c1c3b739a2b322bbc58b80d9d1297ec5bf8a49bc421b10 +08adf2333646679f1249ea53ece33640033ebe6ed8842d12af51970a6799eb85 +a9bca6b6ff7b31deedc76f03acbf32ca50cb4c29c7437f1d3be13fdb22d7488d +38c025fddc4d33c69b424c9ac2f6852b488371dd39077b8a87e48b51ccc6f03b +eaa95d98baf8e17c38b50a39a47bb07c34876f7c0e2b41afb5f72e3cbce5c87b +3a5bf1b6a5a1c39aca22a96083e7b4d3e8b6c4a39ed923d0c376af7f339d77a3 +e59d45abf26603b95a4fb28612e6a0e5402e08841c7c88ab0df226e5fd93a39d +907aaa96b050ff1e8956ba461c59ab98d95ca6c9ebe9936dfdc84b4d1473945d +8e3f89 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +cleartomark + +%%EndFont +TeXDict begin 40258431 52099146 1000 1200 1200 (manual.dvi) +@start /Fa 171[91 100 5[124 77[{TeXBase1Encoding ReEncodeFont}3 +149.44 /Helvetica rf /Fb 182[33 3[80 69[{TeXBase1Encoding ReEncodeFont} +2 119.552 /Helvetica rf /Fc 143[75 4[66 2[75 104[{}3 +149.44 /Times-Italic rf /Fe 134[66 1[100 66 75 42 58 +58 1[75 75 75 108 42 2[42 75 75 42 66 75 66 75 75 50 +11[83 75 91 1[91 1[100 124 2[66 50 108 2[91 108 100 91 +91 7[75 75 75 4[75 75 75 1[37 50 5[50 36[75 2[{ +TeXBase1Encoding ReEncodeFont}46 149.44 /Times-Italic +rf /Ff 105[75 28[75 75 108 75 75 42 58 50 75 75 75 75 +116 42 75 42 42 75 75 50 66 75 66 75 66 3[50 1[50 1[108 +1[141 108 108 91 83 100 1[83 108 108 133 91 108 58 50 +108 108 83 91 108 100 100 108 6[42 75 75 75 75 75 75 +75 75 75 75 1[37 50 37 2[50 50 37[83 2[{TeXBase1Encoding ReEncodeFont} +68 149.44 /Times-Roman rf /Fg 175[174 80[{}1 166.044 +/MTEX rf /Fh 150[35 105[{}1 126.194 /Times-Italic rf +/Fj 133[100 100 100 100 100 1[100 100 100 1[100 100 100 +100 100 1[100 100 100 100 100 100 100 100 100 100 3[100 +1[100 3[100 1[100 100 100 100 1[100 100 100 100 100 2[100 +1[100 1[100 100 100 1[100 13[100 100 100 2[100 100 1[100 +100 42[{TeXBase1Encoding ReEncodeFont}48 166.044 /Courier +rf /Fk 137[74 92 46 65 65 1[83 83 92 129 3[46 92 83 55 +74 83 74 1[83 12[101 1[111 8[65 2[111 70[{TeXBase1Encoding ReEncodeFont} +21 166.044 /Times-BoldItalic rf /Fl 150[31 105[{}1 112.91 +/Times-Italic rf /Fn 143[66 1[66 2[59 35[96 71[{}4 132.835 +/Times-Italic rf /Fo 194[62 61[{}1 132.835 /RMTMI rf +/Fp 138[66 37 52 52 1[66 66 66 4[37 66 66 2[66 1[66 66 +97[{TeXBase1Encoding ReEncodeFont}13 132.835 /Times-Italic +rf /Fq 203[56 56 56 56 56 48[{TeXBase1Encoding ReEncodeFont}5 +112.91 /Times-Roman rf /Fr 203[63 63 63 63 49[{ +TeXBase1Encoding ReEncodeFont}4 126.194 /Times-Roman +rf /Fs 134[74 74 111 74 83 46 65 65 1[83 83 83 120 46 +1[46 46 83 83 1[74 83 74 83 83 3[65 1[65 26[153 2[112 +11[83 83 1[42 55 41[83 3[{TeXBase1Encoding ReEncodeFont}31 +166.044 /Times-Italic rf /Ft 134[111 111 1[111 122 66 +111 78 1[122 122 122 177 55 2[55 122 122 66 111 122 111 +122 111 10[133 144 122 1[144 1[133 155 144 166 3[55 144 +155 122 1[144 144 1[144 9[111 111 111 111 111 111 111 +2[55 66 42[122 2[{TeXBase1Encoding ReEncodeFont}46 199.253 +/Helvetica-Bold rf /Fu 173[134 8[52 3[124 3[134 65[{ +TeXBase1Encoding ReEncodeFont}4 185.969 /Helvetica-Bold +rf /Fv 133[54 54 54 79 54 61 30 54 36 1[61 61 61 91 24 +54 24 24 61 61 30 61 61 54 61 61 12[67 1[79 8[30 2[67 +73 79 2[73 13[61 4[30 36 30 2[36 36 37[54 2[{ +TeXBase1Encoding ReEncodeFont}39 132.835 /Helvetica-Narrow +rf /Fw 134[68 68 98 68 76 38 68 45 1[76 76 76 113 30 +2[30 76 76 38 76 76 68 76 76 1[76 8[91 98 83 91 2[91 +1[98 113 76 2[38 3[91 98 98 1[91 13[76 4[38 45 38 41[68 +2[{TeXBase1Encoding ReEncodeFont}41 166.044 /Helvetica-Narrow +rf /Fx 138[83 2[53 5[38 2[38 1[83 1[76 2[83 76 12[83 +13[83 15[76 76 76 76 76 76 49[{TeXBase1Encoding ReEncodeFont}16 +166.044 /Helvetica-Narrow-Bold rf /Fy 138[83 4[83 1[83 +120 1[74 46 46 1[83 2[83 74 18[101 80[{}11 166.044 /Times-Italic +rf /Fz 137[81 56[78 1[55 46 10[62 62 46[{}6 166.044 /RMTMI +rf /FA 134[83 1[120 83 92 46 83 55 1[92 92 92 138 37 +2[37 92 1[46 92 92 2[92 10[111 1[101 111 120 1[111 1[120 +138 92 111 1[46 1[129 1[111 120 2[111 13[92 92 47[83 +2[{TeXBase1Encoding ReEncodeFont}35 166.044 /Helvetica +rf /FB 134[92 1[129 92 101 55 92 65 1[101 101 101 148 +46 2[46 101 101 55 92 101 92 101 92 10[111 1[101 111 +120 1[111 1[120 138 1[120 1[46 1[129 101 111 120 120 +1[120 13[92 92 47[101 2[{TeXBase1Encoding ReEncodeFont}39 +166.044 /Helvetica-Bold rf /FC 173[96 8[37 3[89 3[96 +65[{TeXBase1Encoding ReEncodeFont}4 132.835 /Helvetica-Bold +rf /FD 133[74 83 83 120 83 92 55 65 74 92 92 83 92 138 +46 1[55 46 92 83 55 74 92 74 92 83 9[166 120 120 111 +92 120 2[129 120 4[65 129 1[101 2[120 1[120 7[83 2[83 +83 83 83 83 83 4[42 5[138 34[92 3[{TeXBase1Encoding ReEncodeFont}48 +166.044 /Times-Bold rf /FE 134[129 1[181 1[142 77 129 +90 142 142 142 142 207 65 2[65 142 142 77 129 142 129 +142 129 9[219 155 168 142 155 168 1[155 181 168 194 3[65 +168 1[142 2[168 1[168 10[129 129 129 129 129 129 4[65 +5[168 38[{TeXBase1Encoding ReEncodeFont}44 232.462 /Helvetica-Bold +rf /FF 134[66 66 96 66 66 37 52 44 66 66 66 66 103 37 +66 37 37 66 66 44 59 66 59 66 59 3[44 1[44 5[96 81 4[96 +96 118 3[44 96 1[74 4[96 10[66 2[66 1[66 2[33 44 33 2[44 +44 37[74 2[{TeXBase1Encoding ReEncodeFont}45 132.835 +/Times-Roman rf /FG 134[66 1[96 2[37 1[44 2[74 1[111 +7[74 3[74 10[89 1[81 89 96 1[89 2[111 1[89 1[37 1[103 +1[89 3[89 13[74 51[{TeXBase1Encoding ReEncodeFont}20 +132.835 /Helvetica rf /FH 173[77 8[30 3[71 3[71 65[{ +TeXBase1Encoding ReEncodeFont}4 106.268 /Helvetica rf +/FI 188[88 63[59 3[{}2 112.91 /MTSYN rf /FJ 134[100 2[100 +100 55 78 66 1[100 100 100 155 55 2[55 100 100 66 88 +100 88 1[88 11[144 1[111 133 1[111 1[144 177 4[144 2[122 +144 133 1[144 11[100 100 100 100 100 100 3[50 44[{ +TeXBase1Encoding ReEncodeFont}37 199.253 /Times-Roman +rf /FK 133[74 83 83 120 83 83 46 65 55 83 83 83 83 129 +46 83 46 46 83 83 55 74 83 74 83 74 3[55 1[55 101 2[157 +120 120 101 92 111 1[92 120 120 148 101 120 1[55 120 +120 92 101 120 111 111 120 153 74 4[46 83 83 83 83 83 +83 83 83 83 83 46 42 55 42 1[83 55 55 55 1[138 3[55 29[92 +92 2[{TeXBase1Encoding ReEncodeFont}75 166.044 /Times-Roman +rf /FL 152[61 61 33[130 130 51[83 11[87 130 1[130{}8 +166.044 /MTSYN rf /FM 134[120 3[133 1[120 80 1[133 133 +133 199 53 120 1[53 133 133 1[133 133 120 1[133 10[159 +2[159 7[159 3[186 26[66 44[{TeXBase1Encoding ReEncodeFont}22 +239.103 /Helvetica rf /FN 140[105 77 2[153 143 4[57 3[153 +14[167 34[134 1[134 2[67 46[{TeXBase1Encoding ReEncodeFont}10 +239.103 /AvantGarde-Demi rf /FO 134[166 161 3[86 126 +92 1[189 184 172 1[69 2[69 172 189 1[184 189 1[189 189 +13[149 2[161 241 1[258 126 4[241 71[{TeXBase1Encoding ReEncodeFont}22 +286.924 /AvantGarde-Demi rf /FP 252[112 3[{}1 214.527 +/MTSYN rf /FQ 171[252 276 2[276 2[344 77[{TeXBase1Encoding ReEncodeFont} +4 413.118 /Helvetica-Bold rf /FR 173[239 8[92 3[220 3[239 +65[{TeXBase1Encoding ReEncodeFont}4 330.494 /Helvetica-Bold +rf end +%%EndProlog +%%BeginSetup +%%Feature: *Resolution 1200dpi +TeXDict begin + +%%EndSetup +%%Page: 1 1 +1 0 bop 3012 1064 a FQ(P)-17 b FR(A)20 b(R)g FQ(M)-21 +b FR(E)-83 b FQ(T)g FR(I)o FQ(S)4795 962 y FP(\003)147 +1411 y FO(P)-6 b(arallel)80 b(Gra)6 b(ph)81 b(P)-6 b(ar)6 +b(titioning)80 b(and)i(Spar)6 b(se)80 b(Ma)q(tr)6 b(ix)81 +b(Or)n(der)6 b(ing)3432 1758 y(Librar)11 b(y)3281 2105 +y FN(V)-24 b(er)5 b(sion)67 b(3.1)1322 2794 y FM(George)f(Kar)7 +b(ypis)l(,)67 b(Kir)t(k)e(Schloegel)i(and)f(Vipin)h(K)-7 +b(umar)2711 3129 y FL(f)p FK(karypis,)41 b(kirk,)g(kumar)p +FL(g)p FK(@cs.umn.edu)863 3457 y FJ(Uni)-5 b(v)m(ersity)50 +b(of)g(Minnesota,)g(Department)h(of)f(Computer)g(Science)h(and)f +(Engineering)2768 3712 y(Army)g(HPC)f(Research)i(Center)2918 +3968 y(Minneapolis,)e(MN)h(55455)3239 4363 y(August)e(15,)h(2003)p +0 10646 3120 7 v 172 10751 a FI(\003)242 10799 y FG(P)-8 +b FH(A)6 b(R)g FG(M)-7 b FH(E)-27 b FG(T)g FH(I)o FG(S)39 +b FF(is)32 b(cop)o(yrighted)k(by)e(the)f(re)n(gents)h(of)g(the)g(Uni)m +(v)n(ersity)f(of)h(Minnesota.)3858 11298 y FK(1)p eop +%%Page: 2 2 +2 1 bop 0 170 a FE(Contents)0 555 y FD(1)166 b(Intr)m(oduction)6568 +b(3)0 940 y(2)166 b(What)42 b(is)g(New)f(in)h(This)f(V)-17 +b(ersion)5450 b(4)0 1325 y(3)166 b(Algorithms)42 b(Used)f(in)46 +b FB(P)-7 b FC(A)8 b(R)g FB(M)-9 b FC(E)-34 b FB(T)g +FC(I)p FB(S)5337 b FD(5)249 1544 y FK(3.1)174 b(Unstructured)41 +b(Graph)h(P)n(artitioning)129 b(.)82 b(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g +(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.) +f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)286 b(5)249 1764 +y(3.2)174 b(P)n(artitioning)42 b(Meshes)e(Directly)110 +b(.)82 b(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.) +h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h +(.)f(.)h(.)f(.)h(.)286 b(7)249 1983 y(3.3)174 b(P)n(artitioning)42 +b(Adapti)l(v)n(ely)f(Re\002ned)g(Meshes)110 b(.)82 b(.)h(.)f(.)h(.)g(.) +f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f +(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)286 b(7)249 2202 +y(3.4)174 b(P)n(artition)42 b(Re\002nement)151 b(.)82 +b(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f +(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.) +h(.)f(.)h(.)f(.)h(.)f(.)h(.)286 b(8)249 2421 y(3.5)174 +b(P)n(artitioning)42 b(for)g(Multi-phase)f(and)h(Multi-ph)o(ysics)f +(Computations)64 b(.)82 b(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f +(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)286 b(9)249 2640 +y(3.6)174 b(P)n(artitioning)42 b(for)g(Heterogeneous)f(Computing)h +(Architectures)114 b(.)82 b(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h +(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)203 b(10)249 +2860 y(3.7)174 b(Computing)42 b(Fill-Reducing)g(Orderings)107 +b(.)82 b(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.) +h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h +(.)203 b(10)0 3245 y FD(4)166 b(Input)42 b(and)h(Output)g(F)l(ormats)f +(used)f(by)46 b FB(P)-7 b FC(A)8 b(R)g FB(M)-9 b FC(E)-34 +b FB(T)g FC(I)p FB(S)4146 b FD(12)249 3464 y FK(4.1)174 +b(F)n(ormat)42 b(of)g(the)f(Input)h(Graph)151 b(.)83 +b(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h +(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.) +f(.)h(.)f(.)h(.)203 b(12)249 3683 y(4.2)174 b(F)n(ormat)42 +b(of)g(V)-18 b(erte)n(x)40 b(Coordinates)52 b(.)82 b(.)h(.)f(.)h(.)f(.) +h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h +(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)203 +b(14)249 3902 y(4.3)174 b(F)n(ormat)42 b(of)g(the)f(Input)h(Mesh)72 +b(.)82 b(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.) +h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h +(.)f(.)h(.)f(.)h(.)f(.)h(.)203 b(14)249 4121 y(4.4)174 +b(F)n(ormat)42 b(of)g(the)f(Computed)g(P)n(artitionings)h(and)f +(Orderings)136 b(.)82 b(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f +(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)203 +b(14)249 4341 y(4.5)174 b(Numbering)42 b(and)f(Memory)g(Allocation)131 +b(.)82 b(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.) +h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h +(.)203 b(15)0 4726 y FD(5)166 b(Calling)42 b(Sequence)g(of)g(the)g +(Routines)f(in)46 b FB(P)-7 b FC(A)8 b(R)g FB(M)-9 b +FC(E)-34 b FB(T)g FC(I)p FB(S)4115 b FD(16)249 4945 y +FK(5.1)174 b(Graph)41 b(P)n(artitioning)166 b(.)83 b(.)f(.)h(.)f(.)h(.) +f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f +(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.) +h(.)f(.)h(.)203 b(17)1009 5164 y(P)n(arMETIS)p 1735 5164 +50 7 v 61 w(V3)p 1999 5164 V 59 w(P)n(artKw)n(ay)73 b(.)83 +b(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h +(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.) +f(.)h(.)203 b(17)1009 5383 y(P)n(arMETIS)p 1735 5383 +V 61 w(V3)p 1999 5383 V 59 w(P)n(artGeomKw)n(ay)165 b(.)83 +b(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h +(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)203 +b(19)1009 5603 y(P)n(arMETIS)p 1735 5603 V 61 w(V3)p +1999 5603 V 59 w(P)n(artGeom)62 b(.)83 b(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.) +h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h +(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)203 b(21)1009 +5822 y(P)n(arMETIS)p 1735 5822 V 61 w(V3)p 1999 5822 +V 59 w(P)n(artMeshKw)n(ay)77 b(.)82 b(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h +(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.) +f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)203 b(22)249 6041 y(5.2)174 +b(Graph)41 b(Repartitioning)113 b(.)82 b(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.) +f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f +(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)203 +b(24)1009 6260 y(P)n(arMETIS)p 1735 6260 V 61 w(V3)p +1999 6260 V 59 w(Adapti)l(v)n(eRepart)61 b(.)82 b(.)h(.)f(.)h(.)f(.)h +(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.) +g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)203 b(24)249 +6479 y(5.3)174 b(P)n(artitioning)42 b(Re\002nement)63 +b(.)83 b(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.) +f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f +(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)203 b(26)1009 6698 y(P)n(arMETIS)p +1735 6698 V 61 w(V3)p 1999 6698 V 59 w(Re\002neKw)n(ay)153 +b(.)83 b(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.) +f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f +(.)h(.)203 b(26)249 6918 y(5.4)174 b(Fill-reducing)43 +b(Orderings)79 b(.)k(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.) +g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g +(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)203 b(27)1009 +7137 y(P)n(arMETIS)p 1735 7137 V 61 w(V3)p 1999 7137 +V 59 w(NodeND)133 b(.)83 b(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h +(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.) +f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)203 b(27)249 7356 y(5.5)174 +b(Mesh)40 b(to)i(Graph)g(T)-6 b(ranslation)113 b(.)83 +b(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h +(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.) +f(.)h(.)f(.)h(.)203 b(28)1009 7575 y(P)n(arMETIS)p 1735 +7575 V 61 w(V3)p 1999 7575 V 59 w(Mesh2Dual)82 b(.)g(.)h(.)f(.)h(.)f(.) +h(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h +(.)f(.)h(.)g(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)f(.)h(.)203 +b(28)0 7960 y FD(6)166 b(Hard)n(war)m(e)41 b(&)h(Softwar)m(e)f(Requir)m +(ements,)g(and)i(Contact)f(Inf)l(ormation)2914 b(29)3858 +11298 y FK(2)p eop +%%Page: 3 3 +3 2 bop 0 170 a FE(1)233 b(Intr)-5 b(oduction)4 522 y +FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p +FA(S)49 b FK(is)42 b(an)g(MPI-based)g(parallel)h(library)g(that)f +(implements)h(a)f(v)l(ariety)g(of)h(algorithms)g(for)g(partitioning)g +(and)f(repartitioning)0 741 y(unstructured)g(graphs)g(and)g(for)g +(computing)h(\002ll-reducing)g(orderings)f(of)g(sparse)f(matrices.)57 +b FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g +FG(I)p FA(S)48 b FK(is)42 b(particularly)h(suited)e(for)0 +960 y(parallel)k(numerical)h(simulations)f(in)-7 b(v)m(olving)46 +b(lar)m(ge)f(unstructured)g(meshes.)62 b(In)45 b(this)h(type)f(of)h +(computation,)k FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 +b FA(T)g FG(I)p FA(S)51 b FK(dramati-)0 1179 y(cally)40 +b(reduces)f(the)i(time)f(spent)g(in)g(communication)h(by)f(computing)h +(mesh)e(decompositions)h(such)g(that)g(the)g(numbers)g(of)h(interf)n +(ace)0 1398 y(elements)g(are)g(minimized.)199 1617 y(The)g(algorithms)h +(in)j FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g +FG(I)p FA(S)47 b FK(are)41 b(based)f(on)h(the)g(multile)l(v)n(el)g +(partitioning)h(and)e(\002ll-reducing)i(ordering)g(algorithms)f(that)g +(are)0 1837 y(implemented)g(in)h(the)f(widely-used)f(serial)h(package)j +FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)48 b FK([5].)k(Ho)l(we)l(v)n +(er)-7 b(,)43 b FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 +b FA(T)g FG(I)p FA(S)48 b FK(e)n(xtends)40 b(the)h(functionality)h(pro) +n(vided)f(by)4 2056 y FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p +FA(S)45 b FK(and)38 b(includes)g(routines)g(that)g(are)g(especially)g +(suited)g(for)g(parallel)h(computations)f(and)g(lar)m(ge-scale)f +(numerical)i(simulations.)0 2275 y(In)j(particular)-7 +b(,)45 b FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b +FA(T)g FG(I)p FA(S)48 b FK(pro)n(vides)41 b(the)h(follo)l(wing)g +(functionality:)249 2627 y FL(\017)83 b FK(P)n(artition)42 +b(unstructured)g(graphs)f(and)g(meshes.)249 2979 y FL(\017)83 +b FK(Repartition)42 b(graphs)f(that)h(correspond)f(to)g(adapti)l(v)n +(ely)g(re\002ned)h(meshes.)249 3331 y FL(\017)83 b FK(P)n(artition)42 +b(graphs)f(for)h(multi-phase)g(and)f(multi-ph)o(ysics)h(simulations.) +249 3683 y FL(\017)83 b FK(Impro)n(v)n(e)41 b(the)h(quality)f(of)h(e)n +(xisting)f(partitionings.)249 4035 y FL(\017)83 b FK(Compute)41 +b(\002ll-reducing)i(orderings)f(for)g(sparse)e(direct)i(f)n +(actorization.)249 4387 y FL(\017)83 b FK(Construct)41 +b(the)h(dual)f(graphs)g(of)h(meshes)199 4739 y(The)d(rest)g(of)g(this)g +(manual)g(is)g(or)m(g)o(anized)f(as)h(follo)l(ws.)50 +b(Section)39 b(2)g(brie\003y)g(describes)f(the)h(dif)l(ferences)f +(between)g(this)h(v)n(ersion)f(and)0 4958 y(the)46 b(pre)l(vious)g +(major)h(release.)64 b(Section)47 b(3)f(describes)f(the)h(v)l(arious)g +(algorithms)h(that)f(are)g(implemented)h(in)j FA(P)-10 +b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)t +FK(.)49 b(Section)d(4)0 5177 y(describes)53 b(the)g(format)i(of)f(the)f +(basic)g(parameters)h(that)f(need)h(to)g(be)f(supplied)h(to)g(the)f +(routines.)88 b(Section)54 b(5)g(pro)n(vides)f(a)g(detailed)0 +5397 y(description)i(of)g(the)g(calling)g(sequences)f(for)h(the)g +(major)h(routines)f(in)k FA(P)-10 b FG(A)8 b(R)g FA(M)-9 +b FG(E)-34 b FA(T)g FG(I)p FA(S)t FK(.)57 b(Finally)-11 +b(,)59 b(Section)c(6)g(describes)f(softw)n(are)h(and)0 +5616 y(hardw)n(are)42 b(requirements)f(and)g(pro)n(vides)g(contact)g +(information.)3858 11298 y(3)p eop +%%Page: 4 4 +4 3 bop 0 170 a FE(2)233 b(What)65 b(is)g(Ne)m(w)f(in)g(This)h(V)-12 +b(er)m(sion)4 522 y FA(P)i FG(A)8 b(R)g FA(M)-9 b FG(E)-34 +b FA(T)g FG(I)p FA(S)t FK(,)48 b(V)-18 b(ersion)45 b(3.x)g(contains)h +(a)f(number)i(of)f(changes)e(o)n(v)n(er)h(the)h(pre)l(vious)g(major)g +(release)f(\(V)-18 b(ersion)45 b(2.x\).)64 b(Theses)45 +b(changes)0 741 y(include)c(the)h(follo)l(wing:)249 1126 +y FL(\017)83 b FK(The)51 b(names)f(and)h(calling)g(sequence)e(of)i(all) +g(the)g(routines)f(ha)m(v)n(e)g(changed)g(due)g(to)h(e)n(xpanded)f +(functionality)h(that)g(has)g(been)415 1345 y(pro)n(vided)37 +b(in)f(this)h(release.)48 b(T)-13 b(able)37 b(1)f(sho)l(ws)g(ho)l(w)g +(the)h(names)f(of)g(the)h(v)l(arious)f(routines)h(map)f(from)i(v)n +(ersion)e(to)h(v)n(ersion.)48 b(Note)415 1564 y(that)55 +b(V)-18 b(ersion)55 b(3.0)f(is)h(fully)h(backw)n(ards)e(compatible)h +(with)h(all)f(pre)l(vious)f(v)n(ersions)h(of)k FA(P)-10 +b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)t +FK(.)57 b(That)e(is,)j(the)d(old)h(API)415 1784 y(calls)45 +b(ha)m(v)n(e)e(been)i(mapped)g(to)g(the)g(ne)l(w)g(routines.)62 +b(Ho)l(we)l(v)n(er)-7 b(,)44 b(the)h(e)n(xpanded)f(functionality)i(pro) +n(vided)f(with)g(this)g(release)f(is)415 2003 y(only)e(a)m(v)l(ailable) +e(by)i(using)f(the)h(ne)l(w)f(calling)g(sequences.)249 +2355 y FL(\017)83 b FK(The)73 b(four)g(adapti)l(v)n(e)f(repartitioning) +h(routines:)114 b FA(P)-7 b(arMETIS)p 4163 2355 50 7 +v 61 w(Repar)7 b(tLDiffusion)p FK(,)82 b FA(P)-7 b(arMETIS)p +6347 2355 V 61 w(Repar)7 b(tGDiffusion)p FK(,)415 2574 +y FA(P)-7 b(arMETIS)p 1183 2574 V 61 w(Repar)7 b(tRemap)p +FK(,)45 b(and)d FA(P)-7 b(arMETIS)p 3409 2574 V 61 w(Repar)7 +b(tMLRemap)46 b FK(ha)m(v)n(e)41 b(been)h(replaced)g(by)h(a)g +(\(single\))g(implementa-)415 2793 y(tion)36 b(of)h(a)e(uni\002ed)i +(repartitioning)g(algorithm)f([15)q(],)g FA(P)-7 b(arMETIS)p +4235 2793 V 61 w(V3)p 4499 2793 V 60 w(Adaptiv)l(eRepar)7 +b(t)p FK(,)39 b(that)d(combines)f(the)h(best)f(features)415 +3012 y(of)42 b(the)f(pre)l(vious)h(routines.)249 3364 +y FL(\017)83 b FK(Multiple)39 b(v)n(erte)n(x)g(weights/balance)f +(constraints)g(are)h(supported)g(for)h(most)f(of)h(the)f(routines.)50 +b(This)40 b(allo)l(ws)i FA(P)-10 b FG(A)8 b(R)g FA(M)-9 +b FG(E)-34 b FA(T)g FG(I)p FA(S)46 b FK(to)39 b(be)415 +3583 y(used)i(to)h(partition)g(graphs)f(for)h(multi-phase)g(and)f +(multi-ph)o(ysics)h(simulations.)249 3935 y FL(\017)83 +b FK(In)66 b(order)g(to)h(optimize)f(partitionings)g(for)g(speci\002c)f +(heterogeneous)g(computing)i(architectures,)j(it)c(is)g(no)l(w)g +(possible)f(to)415 4155 y(specify)36 b(the)h(tar)m(get)g(sub-domain)f +(weights)h(for)g(each)f(of)h(the)g(sub-domains)f(and)g(for)i(each)e +(balance)f(constraint.)50 b(This)37 b(feature,)415 4374 +y(for)47 b(e)n(xample,)f(allo)l(ws)g(the)h(user)f(to)g(compute)h(a)f +(partitioning)h(in)g(which)f(one)h(of)f(the)h(sub-domains)f(is)g(twice) +g(the)h(size)e(of)i(all)415 4593 y(of)42 b(the)f(others.)249 +4945 y FL(\017)83 b FK(The)63 b(number)g(of)g(sub-domains)g(has)f(been) +g(de-coupled)h(from)g(the)g(number)g(of)g(processors)f(in)h(both)g(the) +f(static)h(and)f(the)415 5164 y(adapti)l(v)n(e)j(partitioning)h +(schemes.)123 b(Hence,)70 b(it)c(is)g(no)l(w)f(possible)g(to)h(use)f +(the)h(parallel)g(partitioning)h(and)e(repartitioning)415 +5383 y(algorithms)51 b(to)g(compute)g(a)g Fy(k)10 b FK(-w)n(ay)50 +b(partitioning)i(independent)f(of)g(the)f(number)i(of)f(processors)e +(that)i(are)g(used.)78 b(Note)51 b(that)415 5603 y(V)-18 +b(ersion)41 b(2.0)g(pro)n(vided)g(this)h(functionality)g(for)g(the)f +(static)g(partitioning)i(schemes)d(only)-11 b(.)249 5955 +y FL(\017)83 b FK(Routines)48 b(are)g(pro)n(vided)h(for)g(both)g +(directly)g(partitioning)g(a)f(\002nite)h(element)g(mesh,)g(and)f(for)h +(constructing)g(the)f(dual)h(graph)415 6174 y(of)42 b(a)f(mesh)g(in)h +(parallel.)51 b(In)42 b(v)n(ersion)f(3.1)g(these)f(routines)i(ha)m(v)n +(e)e(been)h(e)n(xtended)f(to)i(support)g(mix)n(ed)f(element)g(meshes.)p +1040 6714 5721 7 v 1037 6914 7 200 v 1140 6854 a(V)-18 +b(ersion)40 b(1.0)p 2281 6914 V 488 w(V)-18 b(ersion)41 +b(2.0)p 4452 6914 V 1414 w(V)-18 b(ersion)41 b(3.0)p +6757 6914 V 1040 6920 5721 7 v 1040 6927 V 1037 7126 +7 200 v 1140 7066 a(P)-15 b(ARKMETIS)p 2281 7126 V 319 +w(P)n(arMETIS)p 3110 7066 50 7 v 61 w(P)n(artKw)n(ay)p +4452 7126 7 200 v 734 w(P)n(arMETIS)p 5281 7066 50 7 +v 61 w(V3)p 5545 7066 V 60 w(P)n(artKw)n(ay)p 6757 7126 +7 200 v 1040 7133 5721 7 v 1037 7332 7 200 v 1140 7272 +a(P)g(ARGKMETIS)p 2281 7332 V 199 w(P)n(arMETIS)p 3110 +7272 50 7 v 61 w(P)n(artGeomKw)n(ay)p 4452 7332 7 200 +v 328 w(P)n(arMETIS)p 5281 7272 50 7 v 61 w(V3)p 5545 +7272 V 60 w(P)n(artGeomKw)n(ay)p 6757 7332 7 200 v 1040 +7339 5721 7 v 1037 7538 7 200 v 1140 7478 a(P)g(ARGMETIS)p +2281 7538 V 319 w(P)n(arMETIS)p 3110 7478 50 7 v 61 w(P)n(artGeom)p +4452 7538 7 200 v 723 w(P)n(arMETIS)p 5281 7478 50 7 +v 61 w(V3)p 5545 7478 V 60 w(P)n(artGeom)p 6757 7538 +7 200 v 1040 7545 5721 7 v 1037 7744 7 200 v 1140 7684 +a(P)g(ARGRMETIS)p 2281 7744 V 208 w(Not)42 b(a)m(v)l(ailable)p +4452 7744 V 1287 w(Not)g(a)m(v)l(ailable)p 6757 7744 +V 1040 7751 5721 7 v 1037 7950 7 200 v 1140 7890 a(P)-15 +b(ARRMETIS)p 2281 7950 V 328 w(P)n(arMETIS)p 3110 7890 +50 7 v 61 w(Re\002neKw)n(ay)p 4452 7950 7 200 v 565 w(P)n(arMETIS)p +5281 7890 50 7 v 61 w(V3)p 5545 7890 V 60 w(Re\002neKw)n(ay)p +6757 7950 7 200 v 1040 7956 5721 7 v 1037 8156 7 200 +v 1140 8096 a(P)g(AR)-7 b(U)g(AMETIS)p 2281 8156 V 213 +w(P)n(arMETIS)p 3110 8096 50 7 v 61 w(RepartLDif)l(fusion)p +4452 8156 7 200 v 4452 8156 V 6757 8156 V 1037 8355 V +1140 8295 a(P)-15 b(ARD)-7 b(AMETIS)p 2281 8355 V 206 +w(P)n(arMETIS)p 3110 8295 50 7 v 61 w(RepartGDif)l(fusion)p +4452 8355 7 200 v 4452 8355 V 6757 8355 V 1037 8554 V +1140 8494 a(Not)41 b(a)m(v)l(ailable)p 2281 8554 V 361 +w(P)n(arMETIS)p 3110 8494 50 7 v 61 w(RepartRemap)p 4452 +8554 7 200 v 4452 8554 V 4555 8382 a(P)n(arMETIS)p 5281 +8382 50 7 v 61 w(V3)p 5545 8382 V 60 w(Adapti)l(v)n(eRepart)p +6757 8554 7 200 v 1037 8753 V 1140 8694 a(Not)g(a)m(v)l(ailable)p +2281 8753 V 361 w(P)n(arMETIS)p 3110 8694 50 7 v 61 w(RepartMLRemap)p +4452 8753 7 200 v 4452 8753 V 6757 8753 V 1040 8760 5721 +7 v 1037 8959 7 200 v 1140 8900 a(P)-15 b(AR)-7 b(OMETIS)p +2281 8959 V 326 w(P)n(arMETIS)p 3110 8900 50 7 v 61 w(NodeND)p +4452 8959 7 200 v 794 w(P)n(arMETIS)p 5281 8900 50 7 +v 61 w(V3)p 5545 8900 V 60 w(NodeND)p 6757 8959 7 200 +v 1040 8966 5721 7 v 1037 9165 7 200 v 1140 9106 a(Not)41 +b(a)m(v)l(ailable)p 2281 9165 V 361 w(Not)h(a)m(v)l(ailable)p +4452 9165 V 1287 w(P)n(arMETIS)p 5281 9106 50 7 v 61 +w(V3)p 5545 9106 V 60 w(P)n(artMeshKw)n(ay)p 6757 9165 +7 200 v 1040 9172 5721 7 v 1037 9371 7 200 v 1140 9311 +a(Not)f(a)m(v)l(ailable)p 2281 9371 V 361 w(Not)h(a)m(v)l(ailable)p +4452 9371 V 1287 w(P)n(arMETIS)p 5281 9311 50 7 v 61 +w(V3)p 5545 9311 V 60 w(Mesh2Dual)p 6757 9371 7 200 v +1040 9378 5721 7 v 920 9683 a Fx(T)-11 b(ab)o(le)38 b(1)p +FK(:)51 b Fw(The)38 b(relationships)f(betw)o(een)f(the)i(names)f(of)g +(the)h(routines)f(in)h(the)f(diff)l(erent)g(v)m(ersions)g(of)k(P)-6 +b Fv(A)8 b(R)g Fw(M)-9 b Fv(E)-34 b Fw(T)g Fv(I)p Fw(S)t(.)3858 +11298 y FK(4)p eop +%%Page: 5 5 +5 4 bop 0 170 a FE(3)233 b(Algorithms)64 b(Used)h(in)71 +b(P)-9 b Fu(A)12 b(R)g FE(M)-11 b Fu(E)-46 b FE(T)g Fu(I)p +FE(S)4 522 y FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 +b FA(T)g FG(I)p FA(S)40 b FK(pro)n(vides)33 b(a)g(v)l(ariety)g(of)h +(routines)g(that)f(can)g(be)h(used)e(to)i(compute)f(dif)l(ferent)h +(types)f(of)h(partitionings)g(and)f(repartitionings)0 +741 y(as)46 b(well)h(as)f(\002ll-reducing)i(orderings.)67 +b(Figure)47 b(1)g(pro)n(vides)f(an)h(o)n(v)n(ervie)l(w)f(of)h(the)g +(functionality)g(pro)n(vided)g(by)k FA(P)-10 b FG(A)8 +b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)53 b FK(as)46 +b(well)0 960 y(as)41 b(a)g(guide)h(to)f(its)h(use.)300 +5341 y @beginspecial 0 @llx 0 @lly 1182 @urx 686 @ury +4320 @rwi @setspecial +%%BeginDocument: ./figures/usagemap.eps +%!PS-Adobe-2.0 EPSF-2.0 +%%Title: usagemap.eps +%%Creator: fig2dev Version 3.2 Patchlevel 3b +%%CreationDate: Mon Jan 14 18:01:01 2002 +%%For: kirk@lnx08 (Kirk Schloegel) +%%BoundingBox: 0 0 1182 686 +%%Magnification: 1.0000 +%%EndComments +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +newpath 0 686 moveto 0 0 lineto 1182 0 lineto 1182 686 lineto closepath clip newpath +-39.0 775.0 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def +/reencdict 12 dict def /ReEncode { reencdict begin +/newcodesandnames exch def /newfontname exch def /basefontname exch def +/basefontdict basefontname findfont def /newfont basefontdict maxlength dict def +basefontdict { exch dup /FID ne { dup /Encoding eq +{ exch dup length array copy newfont 3 1 roll put } +{ exch newfont 3 1 roll put } ifelse } { pop pop } ifelse } forall +newfont /FontName newfontname put newcodesandnames aload pop +128 1 255 { newfont /Encoding get exch /.notdef put } for +newcodesandnames length 2 idiv { newfont /Encoding get 3 1 roll put } repeat +newfontname newfont definefont pop end } def +/isovec [ +8#055 /minus 8#200 /grave 8#201 /acute 8#202 /circumflex 8#203 /tilde +8#204 /macron 8#205 /breve 8#206 /dotaccent 8#207 /dieresis +8#210 /ring 8#211 /cedilla 8#212 /hungarumlaut 8#213 /ogonek 8#214 /caron +8#220 /dotlessi 8#230 /oe 8#231 /OE +8#240 /space 8#241 /exclamdown 8#242 /cent 8#243 /sterling +8#244 /currency 8#245 /yen 8#246 /brokenbar 8#247 /section 8#250 /dieresis +8#251 /copyright 8#252 /ordfeminine 8#253 /guillemotleft 8#254 /logicalnot +8#255 /hyphen 8#256 /registered 8#257 /macron 8#260 /degree 8#261 /plusminus +8#262 /twosuperior 8#263 /threesuperior 8#264 /acute 8#265 /mu 8#266 /paragraph +8#267 /periodcentered 8#270 /cedilla 8#271 /onesuperior 8#272 /ordmasculine +8#273 /guillemotright 8#274 /onequarter 8#275 /onehalf +8#276 /threequarters 8#277 /questiondown 8#300 /Agrave 8#301 /Aacute +8#302 /Acircumflex 8#303 /Atilde 8#304 /Adieresis 8#305 /Aring +8#306 /AE 8#307 /Ccedilla 8#310 /Egrave 8#311 /Eacute +8#312 /Ecircumflex 8#313 /Edieresis 8#314 /Igrave 8#315 /Iacute +8#316 /Icircumflex 8#317 /Idieresis 8#320 /Eth 8#321 /Ntilde 8#322 /Ograve +8#323 /Oacute 8#324 /Ocircumflex 8#325 /Otilde 8#326 /Odieresis 8#327 /multiply +8#330 /Oslash 8#331 /Ugrave 8#332 /Uacute 8#333 /Ucircumflex +8#334 /Udieresis 8#335 /Yacute 8#336 /Thorn 8#337 /germandbls 8#340 /agrave +8#341 /aacute 8#342 /acircumflex 8#343 /atilde 8#344 /adieresis 8#345 /aring +8#346 /ae 8#347 /ccedilla 8#350 /egrave 8#351 /eacute +8#352 /ecircumflex 8#353 /edieresis 8#354 /igrave 8#355 /iacute +8#356 /icircumflex 8#357 /idieresis 8#360 /eth 8#361 /ntilde 8#362 /ograve +8#363 /oacute 8#364 /ocircumflex 8#365 /otilde 8#366 /odieresis 8#367 /divide +8#370 /oslash 8#371 /ugrave 8#372 /uacute 8#373 /ucircumflex +8#374 /udieresis 8#375 /yacute 8#376 /thorn 8#377 /ydieresis] def +/Helvetica /Helvetica-iso isovec ReEncode +/Helvetica-Bold /Helvetica-Bold-iso isovec ReEncode +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +%%Page: 1 1 +10 setmiterlimit + 0.06000 0.06000 sc +% +% Fig objects follow +% +% Polyline +7.500 slw +n 6705 8400 m 6600 8400 6600 9195 105 arcto 4 {pop} repeat + 6600 9300 10695 9300 105 arcto 4 {pop} repeat + 10800 9300 10800 8505 105 arcto 4 {pop} repeat + 10800 8400 6705 8400 105 arcto 4 {pop} repeat + cp gs col7 0.90 shd ef gr gs col-1 s gr +% Polyline +n 2505 8400 m 2400 8400 2400 9195 105 arcto 4 {pop} repeat + 2400 9300 5595 9300 105 arcto 4 {pop} repeat + 5700 9300 5700 8505 105 arcto 4 {pop} repeat + 5700 8400 2505 8400 105 arcto 4 {pop} repeat + cp gs col7 1.00 shd ef gr gs col-1 s gr +% Polyline +n 6705 10200 m 6600 10200 6600 10995 105 arcto 4 {pop} repeat + 6600 11100 10695 11100 105 arcto 4 {pop} repeat + 10800 11100 10800 10305 105 arcto 4 {pop} repeat + 10800 10200 6705 10200 105 arcto 4 {pop} repeat + cp gs col7 0.90 shd ef gr gs col-1 s gr +% Polyline +n 6705 12000 m 6600 12000 6600 12795 105 arcto 4 {pop} repeat + 6600 12900 10695 12900 105 arcto 4 {pop} repeat + 10800 12900 10800 12105 105 arcto 4 {pop} repeat + 10800 12000 6705 12000 105 arcto 4 {pop} repeat + cp gs col7 0.90 shd ef gr gs col-1 s gr +% Polyline +n 2505 12000 m 2400 12000 2400 12795 105 arcto 4 {pop} repeat + 2400 12900 5595 12900 105 arcto 4 {pop} repeat + 5700 12900 5700 12105 105 arcto 4 {pop} repeat + 5700 12000 2505 12000 105 arcto 4 {pop} repeat + cp gs col7 1.00 shd ef gr gs col-1 s gr +% Polyline +n 2505 10200 m 2400 10200 2400 10995 105 arcto 4 {pop} repeat + 2400 11100 5595 11100 105 arcto 4 {pop} repeat + 5700 11100 5700 10305 105 arcto 4 {pop} repeat + 5700 10200 2505 10200 105 arcto 4 {pop} repeat + cp gs col7 1.00 shd ef gr gs col-1 s gr +% Polyline +n 6705 6600 m 6600 6600 6600 7395 105 arcto 4 {pop} repeat + 6600 7500 10695 7500 105 arcto 4 {pop} repeat + 10800 7500 10800 6705 105 arcto 4 {pop} repeat + 10800 6600 6705 6600 105 arcto 4 {pop} repeat + cp gs col7 0.90 shd ef gr gs col-1 s gr +% Polyline +n 2505 6600 m 2400 6600 2400 7395 105 arcto 4 {pop} repeat + 2400 7500 5595 7500 105 arcto 4 {pop} repeat + 5700 7500 5700 6705 105 arcto 4 {pop} repeat + 5700 6600 2505 6600 105 arcto 4 {pop} repeat + cp gs col7 1.00 shd ef gr gs col-1 s gr +% Polyline +gs clippath +2374 12506 m 2449 12412 l 2238 12244 l 2342 12404 l 2163 12338 l cp +eoclip +n 1275 11550 m + 2400 12450 l gs col7 1.00 shd ef gr gs col-1 s gr gr + +% arrowhead +45.000 slw +n 2163 12338 m 2342 12404 l 2238 12244 l 2163 12338 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +7.500 slw +gs clippath +2415 10710 m 2415 10590 l 2146 10590 l 2326 10650 l 2146 10710 l cp +eoclip +n 1275 10650 m + 2400 10650 l gs col7 1.00 shd ef gr gs col-1 s gr gr + +% arrowhead +45.000 slw +n 2146 10710 m 2326 10650 l 2146 10590 l 2146 10710 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +7.500 slw +gs clippath +2415 8910 m 2415 8790 l 2146 8790 l 2326 8850 l 2146 8910 l cp +eoclip +n 1275 8850 m + 2400 8850 l gs col7 1.00 shd ef gr gs col-1 s gr gr + +% arrowhead +45.000 slw +n 2146 8910 m 2326 8850 l 2146 8790 l 2146 8910 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +7.500 slw +gs clippath +2415 7110 m 2415 6990 l 2146 6990 l 2326 7050 l 2146 7110 l cp +eoclip +n 1275 7050 m + 2400 7050 l gs col7 1.00 shd ef gr gs col-1 s gr gr + +% arrowhead +45.000 slw +n 2146 7110 m 2326 7050 l 2146 6990 l 2146 7110 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +7.500 slw +n 6705 4800 m 6600 4800 6600 5595 105 arcto 4 {pop} repeat + 6600 5700 10695 5700 105 arcto 4 {pop} repeat + 10800 5700 10800 4905 105 arcto 4 {pop} repeat + 10800 4800 6705 4800 105 arcto 4 {pop} repeat + cp gs col7 0.90 shd ef gr gs col-1 s gr +% Polyline +gs clippath +2415 5310 m 2415 5190 l 2146 5190 l 2326 5250 l 2146 5310 l cp +eoclip +n 1275 5250 m + 2400 5250 l gs col7 1.00 shd ef gr gs col-1 s gr gr + +% arrowhead +45.000 slw +n 2146 5310 m 2326 5250 l 2146 5190 l 2146 5310 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +7.500 slw +gs clippath +2455 3176 m 2363 3100 l 2190 3306 l 2352 3207 l 2282 3383 l cp +eoclip +n 1275 4500 m + 2400 3150 l gs col7 1.00 shd ef gr gs col-1 s gr gr + +% arrowhead +45.000 slw +n 2282 3383 m 2352 3207 l 2190 3306 l 2282 3383 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +7.500 slw +gs clippath +6615 3210 m 6615 3090 l 6346 3090 l 6526 3150 l 6346 3210 l cp +eoclip +n 5700 3150 m + 6600 3150 l gs col7 1.00 shd ef gr gs col-1 s gr gr + +% arrowhead +45.000 slw +n 6346 3210 m 6526 3150 l 6346 3090 l 6346 3210 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +7.500 slw +gs clippath +6615 5310 m 6615 5190 l 6346 5190 l 6526 5250 l 6346 5310 l cp +eoclip +n 5700 5250 m + 6600 5250 l gs col7 1.00 shd ef gr gs col-1 s gr gr + +% arrowhead +45.000 slw +n 6346 5310 m 6526 5250 l 6346 5190 l 6346 5310 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +7.500 slw +gs clippath +6615 7110 m 6615 6990 l 6346 6990 l 6526 7050 l 6346 7110 l cp +eoclip +n 5700 7050 m + 6600 7050 l gs col7 1.00 shd ef gr gs col-1 s gr gr + +% arrowhead +45.000 slw +n 6346 7110 m 6526 7050 l 6346 6990 l 6346 7110 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +7.500 slw +gs clippath +6615 8910 m 6615 8790 l 6346 8790 l 6526 8850 l 6346 8910 l cp +eoclip +n 5700 8850 m + 6600 8850 l gs col7 1.00 shd ef gr gs col-1 s gr gr + +% arrowhead +45.000 slw +n 6346 8910 m 6526 8850 l 6346 8790 l 6346 8910 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +7.500 slw +gs clippath +6615 10710 m 6615 10590 l 6346 10590 l 6526 10650 l 6346 10710 l cp +eoclip +n 5700 10650 m + 6600 10650 l gs col7 1.00 shd ef gr gs col-1 s gr gr + +% arrowhead +45.000 slw +n 6346 10710 m 6526 10650 l 6346 10590 l 6346 10710 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +7.500 slw +gs clippath +6615 12510 m 6615 12390 l 6346 12390 l 6526 12450 l 6346 12510 l cp +eoclip +n 5700 12450 m + 6600 12450 l gs col7 1.00 shd ef gr gs col-1 s gr gr + +% arrowhead +45.000 slw +n 6346 12510 m 6526 12450 l 6346 12390 l 6346 12510 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +7.500 slw +gs clippath +11092 3811 m 11135 3699 l 10882 3604 l 11030 3724 l 10840 3716 l cp +eoclip +n 9900 3300 m + 11100 3750 l gs col7 1.00 shd ef gr gs col-1 s gr gr + +% arrowhead +45.000 slw +n 10840 3716 m 11030 3724 l 10882 3604 l 10840 3716 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +7.500 slw +n 16605 2700 m 16500 2700 16500 3495 105 arcto 4 {pop} repeat + 16500 3600 19995 3600 105 arcto 4 {pop} repeat + 20100 3600 20100 2805 105 arcto 4 {pop} repeat + 20100 2700 16605 2700 105 arcto 4 {pop} repeat + cp gs col7 0.90 shd ef gr gs col-1 s gr +% Polyline +n 16305 1500 m 16200 1500 16200 2295 105 arcto 4 {pop} repeat + 16200 2400 20220 2400 105 arcto 4 {pop} repeat + 20325 2400 20325 1605 105 arcto 4 {pop} repeat + 20325 1500 16305 1500 105 arcto 4 {pop} repeat + cp gs col7 0.90 shd ef gr gs col-1 s gr +% Polyline +gs clippath +16224 2006 m 16204 1888 l 15939 1932 l 16127 1962 l 15959 2050 l cp +eoclip +n 14400 2250 m + 16200 1950 l gs col7 1.00 shd ef gr gs col-1 s gr gr + +% arrowhead +45.000 slw +n 15959 2050 m 16127 1962 l 15939 1932 l 15959 2050 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +7.500 slw +gs clippath +16506 3211 m 16523 3092 l 16256 3054 l 16426 3139 l 16239 3172 l cp +eoclip +n 14400 2850 m + 16500 3150 l gs col7 1.00 shd ef gr gs col-1 s gr gr + +% arrowhead +45.000 slw +n 16239 3172 m 16426 3139 l 16256 3054 l 16239 3172 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +7.500 slw +gs clippath +11137 2523 m 11089 2414 l 10843 2522 l 11032 2505 l 10891 2632 l cp +eoclip +n 9900 3000 m + 11100 2475 l gs col7 1.00 shd ef gr gs col-1 s gr gr + +% arrowhead +45.000 slw +n 10891 2632 m 11032 2505 l 10843 2522 l 10891 2632 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +7.500 slw +n 2505 2700 m 2400 2700 2400 3495 105 arcto 4 {pop} repeat + 2400 3600 5595 3600 105 arcto 4 {pop} repeat + 5700 3600 5700 2805 105 arcto 4 {pop} repeat + 5700 2700 2505 2700 105 arcto 4 {pop} repeat + cp gs col7 1.00 shd ef gr gs col-1 s gr +% Polyline +n 2505 4800 m 2400 4800 2400 5595 105 arcto 4 {pop} repeat + 2400 5700 5595 5700 105 arcto 4 {pop} repeat + 5700 5700 5700 4905 105 arcto 4 {pop} repeat + 5700 4800 2505 4800 105 arcto 4 {pop} repeat + cp gs col7 1.00 shd ef gr gs col-1 s gr +% Polyline +n 6705 2700 m 6600 2700 6600 3495 105 arcto 4 {pop} repeat + 6600 3600 9795 3600 105 arcto 4 {pop} repeat + 9900 3600 9900 2805 105 arcto 4 {pop} repeat + 9900 2700 6705 2700 105 arcto 4 {pop} repeat + cp gs col7 1.00 shd ef gr gs col-1 s gr +% Polyline +n 11205 3300 m 11100 3300 11100 4095 105 arcto 4 {pop} repeat + 11100 4200 14295 4200 105 arcto 4 {pop} repeat + 14400 4200 14400 3405 105 arcto 4 {pop} repeat + 14400 3300 11205 3300 105 arcto 4 {pop} repeat + cp gs col7 0.90 shd ef gr gs col-1 s gr +% Polyline +n 11205 2100 m 11100 2100 11100 2895 105 arcto 4 {pop} repeat + 11100 3000 14295 3000 105 arcto 4 {pop} repeat + 14400 3000 14400 2205 105 arcto 4 {pop} repeat + 14400 2100 11205 2100 105 arcto 4 {pop} repeat + cp gs col7 1.00 shd ef gr gs col-1 s gr +/Helvetica-iso ff 240.00 scf sf +10425 2625 m +gs 1 -1 sc 20.0 rot (YES) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-iso ff 210.00 scf sf +10500 3900 m +gs 1 -1 sc 340.0 rot (YES or NO) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-iso ff 240.00 scf sf +15225 1950 m +gs 1 -1 sc 8.0 rot (High quality) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-iso ff 240.00 scf sf +15375 2850 m +gs 1 -1 sc 352.0 rot (Low quality) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-Bold-iso ff 240.00 scf sf +8700 12525 m +gs 1 -1 sc (ParMETIS_V3_NodeND) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-Bold-iso ff 240.00 scf sf +8700 10800 m +gs 1 -1 sc (ParMETIS_V3_RefineKway) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-Bold-iso ff 240.00 scf sf +8700 9000 m +gs 1 -1 sc (ParMETIS_V3_AdaptiveRepart) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-Bold-iso ff 240.00 scf sf +8700 7200 m +gs 1 -1 sc (ParMETIS_V3_Mesh2Dual) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-Bold-iso ff 240.00 scf sf +8700 5400 m +gs 1 -1 sc (ParMETIS_V3_PartMeshKway) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-Bold-iso ff 240.00 scf sf +12750 3900 m +gs 1 -1 sc (ParMETIS_V3_PartKway) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-Bold-iso ff 240.00 scf sf +18262 2100 m +gs 1 -1 sc (ParMETIS_V3_PartGeomKway) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-Bold-iso ff 240.00 scf sf +18300 3225 m +gs 1 -1 sc (ParMETIS_V3_PartGeom) dup sw pop 2 div neg 0 rm col-1 sh gr +% Polyline +n 780 4425 m 675 4425 675 11520 105 arcto 4 {pop} repeat + 675 11625 1170 11625 105 arcto 4 {pop} repeat + 1275 11625 1275 4530 105 arcto 4 {pop} repeat + 1275 4425 780 4425 105 arcto 4 {pop} repeat + cp gs col7 1.00 shd ef gr gs col-1 s gr +/Helvetica-iso ff 360.00 scf sf +1125 8025 m +gs 1 -1 sc 90.0 rot (ParMetis Can Do The Following) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-iso ff 240.00 scf sf +4050 3225 m +gs 1 -1 sc (Partition a graph) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-iso ff 240.00 scf sf +4050 5325 m +gs 1 -1 sc (Partition a mesh) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-iso ff 240.00 scf sf +4050 10575 m +gs 1 -1 sc (Refine the quality) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-iso ff 240.00 scf sf +4050 10875 m +gs 1 -1 sc (of a partitioning) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-iso ff 240.00 scf sf +4050 12375 m +gs 1 -1 sc (Compute a fill-reducing ) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-iso ff 240.00 scf sf +4050 12675 m +gs 1 -1 sc (ordering) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-iso ff 240.00 scf sf +8250 3405 m +gs 1 -1 sc (for the vertices?) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-iso ff 240.00 scf sf +8250 3075 m +gs 1 -1 sc (Do you have coordinates) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-iso ff 240.00 scf sf +12750 2475 m +gs 1 -1 sc (What are your ) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-iso ff 240.00 scf sf +12750 2805 m +gs 1 -1 sc (time/quality tradeoffs?) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-iso ff 210.00 scf sf +4050 8775 m +gs 1 -1 sc (Repartition a graph corresponding) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-iso ff 210.00 scf sf +4050 9075 m +gs 1 -1 sc (to an adaptively refined mesh) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-iso ff 210.00 scf sf +4050 7125 m +gs 1 -1 sc (Construct a graph from a mesh) dup sw pop 2 div neg 0 rm col-1 sh gr +$F2psEnd +rs + +%%EndDocument + @endspecial 0 5706 a Fx(Figure)56 b(1)p FK(:)91 b Fw(A)56 +b(br)r(ief)g(o)n(v)m(er)t(vie)n(w)g(of)f(the)g(functionality)g(pro)n +(vided)h(b)n(y)j(P)-6 b Fv(A)8 b(R)g Fw(M)-9 b Fv(E)-34 +b Fw(T)g Fv(I)p Fw(S)t(.)58 b(The)e(shaded)e(bo)l(x)l(es)i(correspond)f +(to)g(the)g(actual)h(routines)f(in)4 5905 y(P)-6 b Fv(A)8 +b(R)g Fw(M)-9 b Fv(E)-34 b Fw(T)g Fv(I)p Fw(S)44 b(that)37 +b(implement)h(each)f(par)5 b(ticular)38 b(oper)o(ation.)0 +6526 y Ft(3.1)199 b(Unstructured)53 b(Graph)i(P)-6 b(ar)t(titioning)0 +6844 y FA(P)f(arMETIS)p 768 6844 50 7 v 61 w(V3)p 1032 +6844 V 60 w(P)g(ar)7 b(tKw)n(a)-5 b(y)40 b FK(is)g(the)g(routine)h(in)j +FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p +FA(S)47 b FK(that)41 b(is)f(used)f(to)i(partition)g(unstructured)f +(graphs.)50 b(This)41 b(routine)f(tak)n(es)0 7064 y(a)i(graph)g(and)f +(computes)h(a)f Fy(k)10 b FK(-w)n(ay)42 b(partitioning)h(\(where)f +Fy(k)51 b FK(is)42 b(equal)f(to)h(the)g(number)g(of)h(sub-domains)e +(desired\))h(while)g(attempting)0 7283 y(to)e(minimize)f(the)g(number)h +(of)g(edges)e(that)i(are)f(cut)g(by)g(the)h(partitioning)g(\()p +Fs(i.e)p FK(.,)e(the)i Fs(edg)n(e-cut)p FK(\).)50 b FA(P)-7 +b(arMETIS)p 6321 7283 V 61 w(V3)p 6585 7283 V 60 w(P)g(ar)7 +b(tKw)n(a)-5 b(y)39 b FK(mak)n(es)0 7502 y(no)j(assumptions)e(on)i(ho)l +(w)f(the)h(graph)f(is)g(initially)i(distrib)m(uted)e(among)h(the)f +(processors.)50 b(It)42 b(can)f(ef)l(fecti)l(v)n(ely)g(partition)h(a)f +(graph)h(that)0 7721 y(is)i(randomly)h(distrib)m(uted)f(as)f(well)h(as) +g(a)g(graph)g(that)g(is)g(well)g(distrib)m(uted)4307 +7661 y Fr(1)4379 7721 y FK(.)59 b(If)44 b(the)h(graph)f(is)g(initially) +h(well)f(distrib)m(uted)g(among)g(the)0 7940 y(processors,)i +FA(P)-7 b(arMETIS)p 1558 7940 V 61 w(V3)p 1822 7940 V +60 w(P)g(ar)7 b(tKw)n(a)-5 b(y)46 b FK(will)h(tak)n(e)f(less)f(time)i +(to)g(run.)65 b(Ho)l(we)l(v)n(er)-7 b(,)47 b(the)f(quality)g(of)h(the)f +(computed)g(partitionings)0 8160 y(does)41 b(not)h(depend)f(on)g(the)h +(initial)g(distrib)m(ution.)199 8379 y(The)58 b(parallel)f(graph)h +(partitioning)g(algorithm)g(used)f(in)h FA(P)-7 b(arMETIS)p +4358 8379 V 61 w(V3)p 4622 8379 V 60 w(P)g(ar)7 b(tKw)n(a)-5 +b(y)57 b FK(is)g(based)g(on)g(the)h(serial)f(multile)l(v)n(el)g +Fy(k)10 b FK(-)0 8598 y(w)n(ay)49 b(partitioning)g(algorithm)h +(described)e(in)h([6,)f(7])i(and)e(parallelized)g(in)h([4)q(,)f(14].)73 +b(This)49 b(algorithm)g(has)g(been)f(sho)l(wn)g(to)h(quickly)0 +8817 y(produce)g(partitionings)g(that)g(are)g(of)g(v)n(ery)f(high)i +(quality)-11 b(.)73 b(It)50 b(consists)d(of)j(three)e(phases:)66 +b(graph)49 b(coarsening,)g(initial)h(partitioning,)0 +9036 y(and)c(uncoarsening/re\002nement.)66 b(In)46 b(the)h(graph)f +(coarsening)g(phase,)g(a)g(series)g(of)g(graphs)g(is)h(constructed)e +(by)i(collapsing)f(together)p 0 9325 3120 7 v 174 9445 +a Fq(1)239 9494 y FF(The)36 b(reader)g(should)h(note)f(the)f(dif)m +(ference)i(between)e(the)h(terms)f Fp(gr)n(aph)i(distrib)m(ution)g +FF(and)f Fp(gr)n(aph)g(partition)p FF(.)49 b(A)35 b(partitioning)i(is)e +(a)h(mapping)h(of)f(the)f(v)n(ertices)h(to)0 9651 y(the)g(processors)f +(that)h(results)f(in)h(a)f(distrib)m(ution.)49 b(In)36 +b(other)g(w)o(ords,)h(a)e(partitioning)i(speci\002es)e(a)g(distrib)m +(ution.)49 b(In)36 b(order)h(to)e(partition)i(a)e(graph)h(in)g +(parallel,)g(an)g(initial)0 9809 y(distrib)m(ution)i(of)e(the)g(nodes)h +(and)g(edges)f(of)g(the)g(graph)i(among)f(the)f(processors)g(is)g +(required.)50 b(F)n(or)37 b(e)n(xample,)g(consider)g(a)f(graph)h(that)f +(corresponds)i(to)e(the)g(dual)h(of)f(a)0 9967 y(\002nite-element)30 +b(mesh.)40 b(This)30 b(graph)g(could)h(initially)e(be)h(partitioned)g +(simply)g(by)g(mapping)h(groups)g(of)e Fn(n)6 b Fo(=)15 +b Fn(p)35 b FF(consecuti)m(v)n(ely)30 b(numbered)i(elements)d(to)h +(each)f(processor)0 10125 y(where)g Fn(n)35 b FF(is)28 +b(the)h(number)i(of)e(elements)g(and)44 b Fn(p)34 b FF(is)28 +b(the)h(number)h(of)g(processors.)40 b(Of)29 b(course,)h(this)f(nai)m +(v)n(e)g(approach)h(is)f(not)g(lik)o(ely)g(to)g(result)g(in)f(a)h(v)n +(ery)h(good)g(distrib)m(ution)0 10282 y(because)j(elements)h(that)f +(belong)h(to)g(a)f(number)i(of)e(dif)m(ferent)h(re)n(gions)g(of)g(the)f +(mesh)h(may)f(get)h(mapped)g(to)g(the)f(same)g(processor)-7 +b(.)42 b(\(That)34 b(is,)f(each)g(processor)h(may)g(get)0 +10440 y(a)d(number)j(of)e(small)f(sub-domains)j(as)d(opposed)i(to)f(a)f +(single)h(contiguous)i(sub-domain\).)43 b(Hence,)32 b(you)h(w)o(ould)f +(w)o(ant)f(to)h(compute)h(a)f(ne)m(w)f(high-quality)j(partitioning)0 +10598 y(for)h(the)f(graph)i(and)e(then)h(redistrib)m(ute)g(the)g(mesh)f +(accordingly)-9 b(.)46 b(Note)34 b(that)h(it)f(may)g(also)g(be)h(the)f +(case)f(that)i(the)f(initial)g(graph)h(is)f(well)g(distrib)m(uted,)i +(as)d(when)i(meshes)0 10755 y(are)e(adapti)m(v)n(ely)i(re\002ned)f(and) +g(repartitioned.)3858 11298 y FK(5)p eop +%%Page: 6 6 +6 5 bop 1800 3598 a @beginspecial 0 @llx 0 @lly 544 @urx +466 @ury 2520 @rwi @setspecial +%%BeginDocument: figures/mlp.eps +%!PS-Adobe-2.0 EPSF-2.0 +%%Title: kmlevel.fig +%%Creator: fig2dev Version 3.1 Patchlevel 2 +%%CreationDate: Mon Feb 3 14:33:40 1997 +%%For: kirk@peca (Kirk Schloegel) +%Magnification: 1.00 +%%Orientation: Portrait +%%BoundingBox: 0 0 544 466 +%%Pages: 0 +%%BeginSetup +%%IncludeFeature: *PageSize Letter +%%EndSetup +%%EndComments +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +-52.0 485.0 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def + /DrawSplineSection { + /y3 exch def + /x3 exch def + /y2 exch def + /x2 exch def + /y1 exch def + /x1 exch def + /xa x1 x2 x1 sub 0.666667 mul add def + /ya y1 y2 y1 sub 0.666667 mul add def + /xb x3 x2 x3 sub 0.666667 mul add def + /yb y3 y2 y3 sub 0.666667 mul add def + x1 y1 lineto + xa ya xb yb x3 y3 curveto + } def + +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def +%%EndProlog + +$F2psBegin +10 setmiterlimit +n 0 792 m 0 0 l 612 0 l 612 792 l cp clip + 0.06000 0.06000 sc +% Closed spline +gs 7.500 slw +n 2489.0 3150.0 m + 2489.0 3150.0 2399.0 3180.0 2309.0 3210.0 DrawSplineSection + 2309.0 3210.0 2219.0 3240.0 2069.5 3359.5 DrawSplineSection + 2069.5 3359.5 1920.0 3479.0 1860.0 3539.0 DrawSplineSection + 1860.0 3539.0 1800.0 3599.0 1800.0 3689.0 DrawSplineSection + 1800.0 3689.0 1800.0 3779.0 1800.0 3839.0 DrawSplineSection + 1800.0 3839.0 1800.0 3899.0 1860.0 3959.5 DrawSplineSection + 1860.0 3959.5 1920.0 4020.0 1980.0 4079.5 DrawSplineSection + 1980.0 4079.5 2040.0 4139.0 2070.0 4139.0 DrawSplineSection + 2070.0 4139.0 2100.0 4139.0 2219.5 4169.0 DrawSplineSection + 2219.5 4169.0 2339.0 4199.0 2489.5 4229.0 DrawSplineSection + 2489.5 4229.0 2640.0 4259.0 2790.0 4259.0 DrawSplineSection + 2790.0 4259.0 2940.0 4259.0 3089.5 4259.0 DrawSplineSection + 3089.5 4259.0 3239.0 4259.0 3329.0 4349.0 DrawSplineSection + 3329.0 4349.0 3419.0 4439.0 3479.0 4439.0 DrawSplineSection + 3479.0 4439.0 3539.0 4439.0 3599.0 4439.0 DrawSplineSection + 3599.0 4439.0 3659.0 4439.0 3779.0 4379.0 DrawSplineSection + 3779.0 4379.0 3899.0 4319.0 3869.0 4199.0 DrawSplineSection + 3869.0 4199.0 3839.0 4079.0 3869.0 3989.0 DrawSplineSection + 3869.0 3989.0 3899.0 3899.0 4019.0 3809.0 DrawSplineSection + 4019.0 3809.0 4139.0 3719.0 4169.0 3689.0 DrawSplineSection + 4169.0 3689.0 4199.0 3659.0 4199.0 3509.5 DrawSplineSection + 4199.0 3509.5 4199.0 3360.0 4019.0 3240.0 DrawSplineSection + 4019.0 3240.0 3839.0 3120.0 3779.0 3090.0 DrawSplineSection + 3779.0 3090.0 3719.0 3060.0 3539.0 3030.0 DrawSplineSection + 3539.0 3030.0 3359.0 3000.0 3209.0 3000.0 DrawSplineSection + 3209.0 3000.0 3059.0 3000.0 2969.5 3000.0 DrawSplineSection + 2969.5 3000.0 2880.0 3000.0 2820.0 3060.0 DrawSplineSection + 2820.0 3060.0 2760.0 3120.0 2700.0 3120.0 DrawSplineSection + 2700.0 3120.0 2640.0 3120.0 2609.5 3120.0 DrawSplineSection + 2609.5 3120.0 2579.0 3120.0 2489.0 3150.0 DrawSplineSection closepath gs col7 1.00 shd ef gr gs col-1 s gr + gr + +% Closed spline +gs n 6349.5 6331.0 m + 6349.5 6331.0 6304.0 6347.0 6259.0 6361.5 DrawSplineSection + 6259.0 6361.5 6214.0 6376.0 6138.0 6436.5 DrawSplineSection + 6138.0 6436.5 6062.0 6497.0 6033.0 6527.0 DrawSplineSection + 6033.0 6527.0 6004.0 6557.0 6004.0 6602.5 DrawSplineSection + 6004.0 6602.5 6004.0 6648.0 6004.0 6678.0 DrawSplineSection + 6004.0 6678.0 6004.0 6708.0 6033.0 6738.0 DrawSplineSection + 6033.0 6738.0 6062.0 6768.0 6092.5 6798.0 DrawSplineSection + 6092.5 6798.0 6123.0 6828.0 6138.5 6828.0 DrawSplineSection + 6138.5 6828.0 6154.0 6828.0 6214.5 6844.0 DrawSplineSection + 6214.5 6844.0 6275.0 6860.0 6350.0 6874.5 DrawSplineSection + 6350.0 6874.5 6425.0 6889.0 6500.5 6889.0 DrawSplineSection + 6500.5 6889.0 6576.0 6889.0 6651.5 6889.0 DrawSplineSection + 6651.5 6889.0 6727.0 6889.0 6772.0 6934.0 DrawSplineSection + 6772.0 6934.0 6817.0 6979.0 6847.0 6979.0 DrawSplineSection + 6847.0 6979.0 6877.0 6979.0 6907.0 6979.0 DrawSplineSection + 6907.0 6979.0 6937.0 6979.0 6997.5 6949.0 DrawSplineSection + 6997.5 6949.0 7058.0 6919.0 7043.0 6858.5 DrawSplineSection + 7043.0 6858.5 7028.0 6798.0 7043.0 6753.0 DrawSplineSection + 7043.0 6753.0 7058.0 6708.0 7118.5 6663.0 DrawSplineSection + 7118.5 6663.0 7179.0 6618.0 7194.0 6602.0 DrawSplineSection + 7194.0 6602.0 7209.0 6586.0 7209.0 6511.5 DrawSplineSection + 7209.0 6511.5 7209.0 6437.0 7118.5 6376.0 DrawSplineSection + 7118.5 6376.0 7028.0 6315.0 6998.0 6301.0 DrawSplineSection + 6998.0 6301.0 6968.0 6287.0 6877.5 6272.0 DrawSplineSection + 6877.5 6272.0 6787.0 6257.0 6711.5 6257.0 DrawSplineSection + 6711.5 6257.0 6636.0 6257.0 6590.0 6257.0 DrawSplineSection + 6590.0 6257.0 6544.0 6257.0 6514.0 6286.0 DrawSplineSection + 6514.0 6286.0 6484.0 6315.0 6454.5 6315.0 DrawSplineSection + 6454.5 6315.0 6425.0 6315.0 6410.0 6315.0 DrawSplineSection + 6410.0 6315.0 6395.0 6315.0 6349.5 6331.0 DrawSplineSection closepath gs col7 1.00 shd ef gr gs col-1 s gr + gr + +% Closed spline +gs n 6860.0 4878.0 m + 6860.0 4878.0 6795.0 4901.0 6730.0 4922.0 DrawSplineSection + 6730.0 4922.0 6665.0 4943.0 6556.0 5029.5 DrawSplineSection + 6556.0 5029.5 6447.0 5116.0 6405.5 5159.0 DrawSplineSection + 6405.5 5159.0 6364.0 5202.0 6364.0 5267.5 DrawSplineSection + 6364.0 5267.5 6364.0 5333.0 6364.0 5376.0 DrawSplineSection + 6364.0 5376.0 6364.0 5419.0 6405.5 5462.0 DrawSplineSection + 6405.5 5462.0 6447.0 5505.0 6491.0 5548.0 DrawSplineSection + 6491.0 5548.0 6535.0 5591.0 6557.0 5591.0 DrawSplineSection + 6557.0 5591.0 6579.0 5591.0 6666.0 5614.0 DrawSplineSection + 6666.0 5614.0 6753.0 5637.0 6860.5 5658.0 DrawSplineSection + 6860.5 5658.0 6968.0 5679.0 7076.5 5679.0 DrawSplineSection + 7076.5 5679.0 7185.0 5679.0 7293.5 5679.0 DrawSplineSection + 7293.5 5679.0 7402.0 5679.0 7466.5 5743.5 DrawSplineSection + 7466.5 5743.5 7531.0 5808.0 7574.0 5808.0 DrawSplineSection + 7574.0 5808.0 7617.0 5808.0 7660.0 5808.0 DrawSplineSection + 7660.0 5808.0 7703.0 5808.0 7790.0 5765.0 DrawSplineSection + 7790.0 5765.0 7877.0 5722.0 7855.5 5635.0 DrawSplineSection + 7855.5 5635.0 7834.0 5548.0 7855.5 5483.5 DrawSplineSection + 7855.5 5483.5 7877.0 5419.0 7964.0 5354.5 DrawSplineSection + 7964.0 5354.5 8051.0 5290.0 8072.5 5267.0 DrawSplineSection + 8072.5 5267.0 8094.0 5244.0 8094.0 5137.0 DrawSplineSection + 8094.0 5137.0 8094.0 5030.0 7964.0 4942.5 DrawSplineSection + 7964.0 4942.5 7834.0 4855.0 7791.0 4835.0 DrawSplineSection + 7791.0 4835.0 7748.0 4815.0 7618.0 4793.5 DrawSplineSection + 7618.0 4793.5 7488.0 4772.0 7379.5 4772.0 DrawSplineSection + 7379.5 4772.0 7271.0 4772.0 7205.0 4772.0 DrawSplineSection + 7205.0 4772.0 7139.0 4772.0 7096.0 4813.5 DrawSplineSection + 7096.0 4813.5 7053.0 4855.0 7010.5 4855.0 DrawSplineSection + 7010.5 4855.0 6968.0 4855.0 6946.5 4855.0 DrawSplineSection + 6946.5 4855.0 6925.0 4855.0 6860.0 4878.0 DrawSplineSection closepath gs col7 1.00 shd ef gr gs col-1 s gr + gr + +% Closed spline +gs n 3944.0 6299.0 m + 3944.0 6299.0 3899.0 6314.0 3854.0 6329.5 DrawSplineSection + 3854.0 6329.5 3809.0 6345.0 3734.0 6404.5 DrawSplineSection + 3734.0 6404.5 3659.0 6464.0 3629.5 6494.0 DrawSplineSection + 3629.5 6494.0 3600.0 6524.0 3600.0 6569.0 DrawSplineSection + 3600.0 6569.0 3600.0 6614.0 3600.0 6644.0 DrawSplineSection + 3600.0 6644.0 3600.0 6674.0 3629.5 6703.5 DrawSplineSection + 3629.5 6703.5 3659.0 6733.0 3689.5 6763.0 DrawSplineSection + 3689.5 6763.0 3720.0 6793.0 3735.0 6793.0 DrawSplineSection + 3735.0 6793.0 3750.0 6793.0 3810.0 6808.0 DrawSplineSection + 3810.0 6808.0 3870.0 6823.0 3945.0 6838.0 DrawSplineSection + 3945.0 6838.0 4020.0 6853.0 4095.0 6853.0 DrawSplineSection + 4095.0 6853.0 4170.0 6853.0 4245.0 6853.0 DrawSplineSection + 4245.0 6853.0 4320.0 6853.0 4364.5 6898.0 DrawSplineSection + 4364.5 6898.0 4409.0 6943.0 4439.0 6943.0 DrawSplineSection + 4439.0 6943.0 4469.0 6943.0 4499.0 6943.0 DrawSplineSection + 4499.0 6943.0 4529.0 6943.0 4589.0 6913.0 DrawSplineSection + 4589.0 6913.0 4649.0 6883.0 4634.0 6823.0 DrawSplineSection + 4634.0 6823.0 4619.0 6763.0 4634.0 6718.5 DrawSplineSection + 4634.0 6718.5 4649.0 6674.0 4709.0 6629.0 DrawSplineSection + 4709.0 6629.0 4769.0 6584.0 4784.0 6568.5 DrawSplineSection + 4784.0 6568.5 4799.0 6553.0 4799.0 6478.5 DrawSplineSection + 4799.0 6478.5 4799.0 6404.0 4709.0 6344.0 DrawSplineSection + 4709.0 6344.0 4619.0 6284.0 4589.0 6269.0 DrawSplineSection + 4589.0 6269.0 4559.0 6254.0 4469.0 6239.5 DrawSplineSection + 4469.0 6239.5 4379.0 6225.0 4304.0 6225.0 DrawSplineSection + 4304.0 6225.0 4229.0 6225.0 4184.0 6225.0 DrawSplineSection + 4184.0 6225.0 4139.0 6225.0 4109.0 6254.5 DrawSplineSection + 4109.0 6254.5 4079.0 6284.0 4049.5 6284.0 DrawSplineSection + 4049.5 6284.0 4020.0 6284.0 4004.5 6284.0 DrawSplineSection + 4004.5 6284.0 3989.0 6284.0 3944.0 6299.0 DrawSplineSection closepath gs col7 1.00 shd ef gr gs col-1 s gr + gr + +% Closed spline +gs n 1762.5 1087.5 m + 1762.5 1087.5 1650.0 1125.0 1537.5 1162.5 DrawSplineSection + 1537.5 1162.5 1425.0 1200.0 1237.5 1350.0 DrawSplineSection + 1237.5 1350.0 1050.0 1500.0 975.0 1575.0 DrawSplineSection + 975.0 1575.0 900.0 1650.0 900.0 1762.5 DrawSplineSection + 900.0 1762.5 900.0 1875.0 900.0 1950.0 DrawSplineSection + 900.0 1950.0 900.0 2025.0 975.0 2100.0 DrawSplineSection + 975.0 2100.0 1050.0 2175.0 1125.0 2250.0 DrawSplineSection + 1125.0 2250.0 1200.0 2325.0 1237.5 2325.0 DrawSplineSection + 1237.5 2325.0 1275.0 2325.0 1425.0 2362.5 DrawSplineSection + 1425.0 2362.5 1575.0 2400.0 1762.5 2437.5 DrawSplineSection + 1762.5 2437.5 1950.0 2475.0 2137.5 2475.0 DrawSplineSection + 2137.5 2475.0 2325.0 2475.0 2512.5 2475.0 DrawSplineSection + 2512.5 2475.0 2700.0 2475.0 2812.5 2587.5 DrawSplineSection + 2812.5 2587.5 2925.0 2700.0 3000.0 2700.0 DrawSplineSection + 3000.0 2700.0 3075.0 2700.0 3150.0 2700.0 DrawSplineSection + 3150.0 2700.0 3225.0 2700.0 3375.0 2625.0 DrawSplineSection + 3375.0 2625.0 3525.0 2550.0 3487.5 2400.0 DrawSplineSection + 3487.5 2400.0 3450.0 2250.0 3487.5 2137.5 DrawSplineSection + 3487.5 2137.5 3525.0 2025.0 3675.0 1912.5 DrawSplineSection + 3675.0 1912.5 3825.0 1800.0 3862.5 1762.5 DrawSplineSection + 3862.5 1762.5 3900.0 1725.0 3900.0 1537.5 DrawSplineSection + 3900.0 1537.5 3900.0 1350.0 3675.0 1200.0 DrawSplineSection + 3675.0 1200.0 3450.0 1050.0 3375.0 1012.5 DrawSplineSection + 3375.0 1012.5 3300.0 975.0 3075.0 937.5 DrawSplineSection + 3075.0 937.5 2850.0 900.0 2662.5 900.0 DrawSplineSection + 2662.5 900.0 2475.0 900.0 2362.5 900.0 DrawSplineSection + 2362.5 900.0 2250.0 900.0 2175.0 975.0 DrawSplineSection + 2175.0 975.0 2100.0 1050.0 2025.0 1050.0 DrawSplineSection + 2025.0 1050.0 1950.0 1050.0 1912.5 1050.0 DrawSplineSection + 1912.5 1050.0 1875.0 1050.0 1762.5 1087.5 DrawSplineSection closepath gs col7 1.00 shd ef gr gs col-1 s gr + gr + +% Closed spline +gs n 3270.0 4907.5 m + 3270.0 4907.5 3205.0 4929.0 3140.5 4950.5 DrawSplineSection + 3140.5 4950.5 3076.0 4972.0 2968.5 5058.0 DrawSplineSection + 2968.5 5058.0 2861.0 5144.0 2818.0 5187.0 DrawSplineSection + 2818.0 5187.0 2775.0 5230.0 2775.0 5294.5 DrawSplineSection + 2775.0 5294.5 2775.0 5359.0 2775.0 5402.5 DrawSplineSection + 2775.0 5402.5 2775.0 5446.0 2818.0 5489.0 DrawSplineSection + 2818.0 5489.0 2861.0 5532.0 2904.0 5575.0 DrawSplineSection + 2904.0 5575.0 2947.0 5618.0 2969.0 5618.0 DrawSplineSection + 2969.0 5618.0 2991.0 5618.0 3077.0 5639.5 DrawSplineSection + 3077.0 5639.5 3163.0 5661.0 3270.5 5682.5 DrawSplineSection + 3270.5 5682.5 3378.0 5704.0 3486.0 5704.0 DrawSplineSection + 3486.0 5704.0 3594.0 5704.0 3701.5 5704.0 DrawSplineSection + 3701.5 5704.0 3809.0 5704.0 3874.0 5768.5 DrawSplineSection + 3874.0 5768.5 3939.0 5833.0 3982.0 5833.0 DrawSplineSection + 3982.0 5833.0 4025.0 5833.0 4068.0 5833.0 DrawSplineSection + 4068.0 5833.0 4111.0 5833.0 4197.5 5790.0 DrawSplineSection + 4197.5 5790.0 4284.0 5747.0 4262.5 5661.0 DrawSplineSection + 4262.5 5661.0 4241.0 5575.0 4262.5 5510.5 DrawSplineSection + 4262.5 5510.5 4284.0 5446.0 4370.0 5381.5 DrawSplineSection + 4370.0 5381.5 4456.0 5317.0 4477.5 5295.0 DrawSplineSection + 4477.5 5295.0 4499.0 5273.0 4499.0 5165.5 DrawSplineSection + 4499.0 5165.5 4499.0 5058.0 4370.0 4972.0 DrawSplineSection + 4370.0 4972.0 4241.0 4886.0 4197.5 4864.5 DrawSplineSection + 4197.5 4864.5 4154.0 4843.0 4025.0 4821.5 DrawSplineSection + 4025.0 4821.5 3896.0 4800.0 3788.0 4800.0 DrawSplineSection + 3788.0 4800.0 3680.0 4800.0 3615.5 4800.0 DrawSplineSection + 3615.5 4800.0 3551.0 4800.0 3508.0 4843.0 DrawSplineSection + 3508.0 4843.0 3465.0 4886.0 3421.5 4886.0 DrawSplineSection + 3421.5 4886.0 3378.0 4886.0 3356.5 4886.0 DrawSplineSection + 3356.5 4886.0 3335.0 4886.0 3270.0 4907.5 DrawSplineSection closepath gs col7 1.00 shd ef gr gs col-1 s gr + gr + +% Closed spline +gs n 7248.5 3162.0 m + 7248.5 3162.0 7161.0 3193.0 7073.0 3221.5 DrawSplineSection + 7073.0 3221.5 6985.0 3250.0 6838.0 3366.5 DrawSplineSection + 6838.0 3366.5 6691.0 3483.0 6635.0 3541.0 DrawSplineSection + 6635.0 3541.0 6579.0 3599.0 6579.0 3687.5 DrawSplineSection + 6579.0 3687.5 6579.0 3776.0 6579.0 3834.0 DrawSplineSection + 6579.0 3834.0 6579.0 3892.0 6635.0 3950.0 DrawSplineSection + 6635.0 3950.0 6691.0 4008.0 6750.5 4066.0 DrawSplineSection + 6750.5 4066.0 6810.0 4124.0 6839.5 4124.0 DrawSplineSection + 6839.5 4124.0 6869.0 4124.0 6986.5 4155.0 DrawSplineSection + 6986.5 4155.0 7104.0 4186.0 7249.0 4214.5 DrawSplineSection + 7249.0 4214.5 7394.0 4243.0 7540.5 4243.0 DrawSplineSection + 7540.5 4243.0 7687.0 4243.0 7833.5 4243.0 DrawSplineSection + 7833.5 4243.0 7980.0 4243.0 8067.0 4330.0 DrawSplineSection + 8067.0 4330.0 8154.0 4417.0 8212.0 4417.0 DrawSplineSection + 8212.0 4417.0 8270.0 4417.0 8328.0 4417.0 DrawSplineSection + 8328.0 4417.0 8386.0 4417.0 8503.5 4359.0 DrawSplineSection + 8503.5 4359.0 8621.0 4301.0 8592.0 4183.5 DrawSplineSection + 8592.0 4183.5 8563.0 4066.0 8592.0 3979.0 DrawSplineSection + 8592.0 3979.0 8621.0 3892.0 8738.5 3805.0 DrawSplineSection + 8738.5 3805.0 8856.0 3718.0 8885.0 3687.0 DrawSplineSection + 8885.0 3687.0 8914.0 3656.0 8914.0 3511.5 DrawSplineSection + 8914.0 3511.5 8914.0 3367.0 8738.5 3249.0 DrawSplineSection + 8738.5 3249.0 8563.0 3131.0 8505.0 3104.0 DrawSplineSection + 8505.0 3104.0 8447.0 3077.0 8271.5 3048.0 DrawSplineSection + 8271.5 3048.0 8096.0 3019.0 7949.5 3019.0 DrawSplineSection + 7949.5 3019.0 7803.0 3019.0 7714.0 3019.0 DrawSplineSection + 7714.0 3019.0 7625.0 3019.0 7567.0 3075.0 DrawSplineSection + 7567.0 3075.0 7509.0 3131.0 7451.5 3131.0 DrawSplineSection + 7451.5 3131.0 7394.0 3131.0 7365.0 3131.0 DrawSplineSection + 7365.0 3131.0 7336.0 3131.0 7248.5 3162.0 DrawSplineSection closepath gs col7 1.00 shd ef gr gs col-1 s gr + gr + +% Closed spline +gs n 5181.5 7273.5 m + 5181.5 7273.5 5151.0 7284.0 5121.0 7294.0 DrawSplineSection + 5121.0 7294.0 5091.0 7304.0 5040.5 7344.0 DrawSplineSection + 5040.5 7344.0 4990.0 7384.0 4970.5 7404.0 DrawSplineSection + 4970.5 7404.0 4951.0 7424.0 4951.0 7454.5 DrawSplineSection + 4951.0 7454.5 4951.0 7485.0 4951.0 7505.0 DrawSplineSection + 4951.0 7505.0 4951.0 7525.0 4970.5 7545.0 DrawSplineSection + 4970.5 7545.0 4990.0 7565.0 5010.5 7585.0 DrawSplineSection + 5010.5 7585.0 5031.0 7605.0 5041.0 7605.0 DrawSplineSection + 5041.0 7605.0 5051.0 7605.0 5091.5 7615.5 DrawSplineSection + 5091.5 7615.5 5132.0 7626.0 5182.0 7636.0 DrawSplineSection + 5182.0 7636.0 5232.0 7646.0 5282.5 7646.0 DrawSplineSection + 5282.5 7646.0 5333.0 7646.0 5383.5 7646.0 DrawSplineSection + 5383.5 7646.0 5434.0 7646.0 5464.0 7676.0 DrawSplineSection + 5464.0 7676.0 5494.0 7706.0 5514.0 7706.0 DrawSplineSection + 5514.0 7706.0 5534.0 7706.0 5554.0 7706.0 DrawSplineSection + 5554.0 7706.0 5574.0 7706.0 5614.5 7686.0 DrawSplineSection + 5614.5 7686.0 5655.0 7666.0 5645.0 7625.5 DrawSplineSection + 5645.0 7625.5 5635.0 7585.0 5645.0 7555.0 DrawSplineSection + 5645.0 7555.0 5655.0 7525.0 5695.5 7495.0 DrawSplineSection + 5695.5 7495.0 5736.0 7465.0 5746.0 7454.5 DrawSplineSection + 5746.0 7454.5 5756.0 7444.0 5756.0 7394.0 DrawSplineSection + 5756.0 7394.0 5756.0 7344.0 5695.5 7303.5 DrawSplineSection + 5695.5 7303.5 5635.0 7263.0 5615.0 7253.5 DrawSplineSection + 5615.0 7253.5 5595.0 7244.0 5534.5 7234.0 DrawSplineSection + 5534.5 7234.0 5474.0 7224.0 5423.5 7224.0 DrawSplineSection + 5423.5 7224.0 5373.0 7224.0 5342.5 7224.0 DrawSplineSection + 5342.5 7224.0 5312.0 7224.0 5292.0 7243.5 DrawSplineSection + 5292.0 7243.5 5272.0 7263.0 5252.0 7263.0 DrawSplineSection + 5252.0 7263.0 5232.0 7263.0 5222.0 7263.0 DrawSplineSection + 5222.0 7263.0 5212.0 7263.0 5181.5 7273.5 DrawSplineSection closepath gs col7 1.00 shd ef gr gs col-1 s gr + gr + +% Closed spline +gs n 7727.0 1143.0 m + 7727.0 1143.0 7618.0 1182.0 7508.5 1217.5 DrawSplineSection + 7508.5 1217.5 7399.0 1253.0 7216.0 1398.0 DrawSplineSection + 7216.0 1398.0 7033.0 1543.0 6963.5 1615.0 DrawSplineSection + 6963.5 1615.0 6894.0 1687.0 6894.0 1797.0 DrawSplineSection + 6894.0 1797.0 6894.0 1907.0 6894.0 1979.5 DrawSplineSection + 6894.0 1979.5 6894.0 2052.0 6963.5 2124.0 DrawSplineSection + 6963.5 2124.0 7033.0 2196.0 7107.0 2268.0 DrawSplineSection + 7107.0 2268.0 7181.0 2340.0 7218.0 2340.0 DrawSplineSection + 7218.0 2340.0 7255.0 2340.0 7401.0 2378.5 DrawSplineSection + 7401.0 2378.5 7547.0 2417.0 7727.5 2452.5 DrawSplineSection + 7727.5 2452.5 7908.0 2488.0 8090.5 2488.0 DrawSplineSection + 8090.5 2488.0 8273.0 2488.0 8455.5 2488.0 DrawSplineSection + 8455.5 2488.0 8638.0 2488.0 8746.0 2596.5 DrawSplineSection + 8746.0 2596.5 8854.0 2705.0 8926.5 2705.0 DrawSplineSection + 8926.5 2705.0 8999.0 2705.0 9071.0 2705.0 DrawSplineSection + 9071.0 2705.0 9143.0 2705.0 9289.0 2633.0 DrawSplineSection + 9289.0 2633.0 9435.0 2561.0 9399.0 2414.5 DrawSplineSection + 9399.0 2414.5 9363.0 2268.0 9399.0 2160.0 DrawSplineSection + 9399.0 2160.0 9435.0 2052.0 9581.5 1943.5 DrawSplineSection + 9581.5 1943.5 9728.0 1835.0 9764.0 1796.5 DrawSplineSection + 9764.0 1796.5 9800.0 1758.0 9800.0 1578.0 DrawSplineSection + 9800.0 1578.0 9800.0 1398.0 9581.5 1251.0 DrawSplineSection + 9581.5 1251.0 9363.0 1104.0 9291.0 1070.5 DrawSplineSection + 9291.0 1070.5 9219.0 1037.0 9000.5 1001.0 DrawSplineSection + 9000.5 1001.0 8782.0 965.0 8599.5 965.0 DrawSplineSection + 8599.5 965.0 8417.0 965.0 8306.5 965.0 DrawSplineSection + 8306.5 965.0 8196.0 965.0 8123.5 1034.5 DrawSplineSection + 8123.5 1034.5 8051.0 1104.0 7979.5 1104.0 DrawSplineSection + 7979.5 1104.0 7908.0 1104.0 7872.0 1104.0 DrawSplineSection + 7872.0 1104.0 7836.0 1104.0 7727.0 1143.0 DrawSplineSection closepath gs col7 1.00 shd ef gr gs col-1 s gr + gr + +/Times-Italic ff 240.00 scf sf +2085 1605 m +gs 1 -1 sc (G) col-1 sh gr +/Times-Italic ff 240.00 scf sf +7060 1933 m +gs 1 -1 sc (G) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4245 6615 m +gs 1 -1 sc (3) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2265 1650 m +gs 1 -1 sc (O) col-1 sh gr +/Times-Italic ff 240.00 scf sf +4650 7545 m +gs 1 -1 sc (G) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4830 7590 m +gs 1 -1 sc (4) col-1 sh gr +/Times-Italic ff 240.00 scf sf +4065 6570 m +gs 1 -1 sc (G) col-1 sh gr +15.000 slw +% Interp Spline +gs n 5164 7462 m + 5236.3 7457.9 5267.6 7454.1 5289 7447 curveto + 5313.9 7438.7 5365.7 7414.4 5384 7392 curveto + 5405.1 7366.2 5419.2 7301.3 5424 7272 curveto + 5425.3 7264.2 5425.3 7252.9 5424 7227 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 5364 7417 m + 5396.1 7469.8 5408.6 7493.6 5414 7512 curveto + 5421.5 7537.2 5422.9 7596.8 5424 7622 curveto + 5424.2 7627.1 5424.2 7634.6 5424 7652 curveto + gs col2 s gr + gr + +/Times-Roman ff 150.00 scf sf +3690 5355 m +gs 1 -1 sc (2) col-1 sh gr +% Interp Spline +gs n 5419 7512 m + 5497.0 7511.7 5530.8 7513.0 5554 7517 curveto + 5571.1 7520.0 5594.9 7527.5 5649 7547 curveto + gs col2 s gr + gr + +/Times-Roman ff 150.00 scf sf +2925 3735 m +gs 1 -1 sc (1) col-1 sh gr +/Times-Italic ff 240.00 scf sf +3510 5310 m +gs 1 -1 sc (G) col-1 sh gr +% Interp Spline +gs n 6323 6613 m + 6431.2 6607.1 6477.9 6601.6 6510 6591 curveto + 6547.2 6578.6 6625.9 6547.1 6652 6509 curveto + 6679.7 6468.6 6686.4 6381.0 6679 6337 curveto + 6676.3 6320.9 6666.3 6302.1 6639 6262 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 5069 7327 m + 5126.5 7400.3 5149.0 7434.0 5159 7462 curveto + 5167.3 7485.1 5178.5 7535.4 5169 7562 curveto + 5163.0 7578.8 5148.0 7593.8 5109 7622 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 6697 6441 m + 6822.7 6491.2 6878.2 6510.2 6919 6517 curveto + 6960.8 6523.9 7057.0 6524.9 7099 6517 curveto + 7115.9 6513.8 7138.4 6505.1 7189 6482 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 6704 6688 m + 6821.3 6688.0 6871.9 6689.9 6906 6696 curveto + 6932.3 6700.3 6967.8 6711.6 7049 6741 curveto + gs col2 s gr + gr + +/Times-Roman ff 150.00 scf sf +6204 6752 m +gs 1 -1 sc (3) col-1 sh gr +/Times-Italic ff 240.00 scf sf +6024 6707 m +gs 1 -1 sc (G) col-1 sh gr +/Times-Italic ff 240.00 scf sf +2745 3690 m +gs 1 -1 sc (G) col-1 sh gr +% Interp Spline +gs n 5414 7347 m + 5498.1 7392.1 5535.6 7409.6 5564 7417 curveto + 5595.0 7425.1 5667.3 7429.7 5699 7427 curveto + 5709.9 7426.1 5724.9 7422.3 5759 7412 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 6784 5287 m + 6961.1 5277.3 7037.6 5268.3 7090 5251 curveto + 7143.4 5233.4 7256.4 5188.6 7294 5134 curveto + 7334.0 5076.0 7343.5 4950.1 7333 4887 curveto + 7329.2 4863.9 7314.9 4836.9 7276 4779 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 7251 5187 m + 7301.1 5309.2 7320.6 5362.9 7329 5402 curveto + 7338.6 5446.5 7346.2 5551.6 7344 5597 curveto + 7343.3 5612.0 7339.5 5633.3 7329 5682 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 7324 5067 m + 7527.1 5118.7 7615.6 5138.2 7678 5145 curveto + 7737.3 5151.4 7875.9 5156.2 7936 5145 curveto + 7960.2 5140.5 7992.4 5128.0 8065 5095 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 7334 5437 m + 7519.4 5405.0 7600.6 5396.3 7659 5402 curveto + 7697.4 5405.8 7748.6 5421.8 7864 5466 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 6181 6411 m + 6271.0 6516.2 6304.8 6566.7 6316 6613 curveto + 6325.2 6651.1 6311.1 6727.8 6299 6762 curveto + 6292.5 6780.4 6278.0 6803.2 6241 6853 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 6922 3317 m + 7073.0 3532.6 7130.7 3631.8 7153 3714 curveto + 7170.7 3781.6 7171.5 3929.4 7151 3997 curveto + 7140.1 4034.8 7111.8 4078.7 7038 4173 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 7146 3714 m + 7384.9 3700.9 7488.1 3688.7 7559 3665 curveto + 7630.9 3641.6 7783.5 3581.1 7834 3507 curveto + 7888.2 3429.2 7901.0 3259.4 7887 3174 curveto + 7881.7 3143.0 7862.5 3106.6 7810 3028 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 7776 3579 m + 7843.8 3743.9 7870.1 3816.4 7881 3869 curveto + 7894.4 3929.2 7904.7 4071.1 7902 4132 curveto + 7900.7 4152.5 7895.7 4181.2 7881 4247 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 7875 3417 m + 8146.4 3493.1 8266.0 3519.3 8353 3522 curveto + 8437.3 3524.6 8624.4 3497.7 8704 3467 curveto + 8736.2 3454.6 8776.2 3428.3 8864 3362 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 7888 3916 m + 8138.4 3873.2 8248.1 3861.4 8327 3869 curveto + 8378.7 3874.2 8447.8 3895.8 8604 3955 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 6622 6546 m + 6670.2 6625.2 6688.9 6660.8 6697 6688 curveto + 6708.2 6726.2 6710.3 6815.4 6712 6853 curveto + 6712.4 6860.9 6712.4 6872.1 6712 6898 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 7321 1336 m + 7508.8 1604.2 7580.6 1727.7 7608 1830 curveto + 7630.4 1914.2 7631.4 2098.2 7606 2182 curveto + 7592.3 2229.4 7557.1 2283.9 7465 2401 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 7600 1830 m + 7896.9 1813.7 8025.4 1798.6 8114 1769 curveto + 8203.1 1739.9 8393.0 1664.6 8456 1572 curveto + 8523.3 1475.5 8539.3 1264.2 8522 1158 curveto + 8515.2 1119.3 8491.3 1074.0 8426 976 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 8384 1662 m + 8468.1 1867.2 8500.8 1957.5 8514 2023 curveto + 8531.1 2097.9 8543.9 2274.4 8541 2350 curveto + 8538.9 2375.8 8532.6 2411.5 8514 2493 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 8507 1460 m + 8844.8 1555.1 8993.5 1587.8 9102 1591 curveto + 9206.7 1594.2 9439.5 1560.8 9539 1523 curveto + 9578.7 1507.2 9628.5 1474.5 9738 1392 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 8523 2081 m + 8834.7 2028.2 8971.2 2013.5 9069 2023 curveto + 9133.7 2029.4 9219.8 2056.3 9414 2130 curveto + gs col2 s gr + gr + +% Interp Spline +gs n 6618 4993 m + 6730.0 5152.6 6772.7 5226.1 6789 5287 curveto + 6802.4 5337.1 6803.0 5446.7 6788 5497 curveto + 6779.7 5524.8 6758.7 5557.3 6704 5627 curveto + gs col2 s gr + gr + +/Times-Roman ff 150.00 scf sf +7240 1978 m +gs 1 -1 sc (O) col-1 sh gr +/Times-Roman ff 150.00 scf sf +6864 3882 m +gs 1 -1 sc (1) col-1 sh gr +/Times-Italic ff 240.00 scf sf +6684 3837 m +gs 1 -1 sc (G) col-1 sh gr +/Times-Roman ff 150.00 scf sf +6609 5442 m +gs 1 -1 sc (2) col-1 sh gr +/Times-Italic ff 240.00 scf sf +6429 5397 m +gs 1 -1 sc (G) col-1 sh gr +7.500 slw +% Arc +gs clippath +3523 7341 m 3649 7416 l 3504 7398 l 3679 7458 l 3699 7402 l cp clip +n 4758.3 4091.7 3505.0 -155.3 108.0 arcn +gs col-1 s gr + gr + +% arrowhead +n 3523 7341 m 3649 7416 l 3504 7398 l 3536 7377 l 3523 7341 l cp gs 0.00 setgray ef gr col-1 s +% Arc +gs clippath +9389 3098 m 9381 2951 l 9447 3083 l 9400 2903 l 9342 2918 l cp clip +n 5725.6 3971.0 3796.4 68.4 -16.0 arcn +gs col-1 s gr + gr + +% arrowhead +n 9389 3098 m 9381 2951 l 9447 3083 l 9412 3067 l 9389 3098 l cp gs 0.00 setgray ef gr col-1 s +/Helvetica-Bold ff 210.00 scf sf +1050 4200 m +gs 1 -1 sc 90.0 rot (Coarsening Phase) dup sw pop 2 div neg 0 rm col4 sh gr +/Helvetica-Bold ff 210.00 scf sf +9750 4200 m +gs 1 -1 sc 270.0 rot (Uncoarsening Phase) dup sw pop 2 div neg 0 rm col4 sh gr +/Helvetica-Bold ff 210.00 scf sf +5400 8025 m +gs 1 -1 sc (Initial Partitioning Phase) dup sw pop 2 div neg 0 rm col4 sh gr +/Helvetica-Bold ff 240.00 scf sf +5400 525 m +gs 1 -1 sc (Multilevel K-way Partitioning) dup sw pop 2 div neg 0 rm col1 sh gr +$F2psEnd +rs + +%%EndDocument + @endspecial 0 3963 a Fx(Figure)43 b(2)p FK(:)108 b Fv(The)34 +b(three)f(phases)h(of)g(m)o(ultile)m(v)m(el)h Fn(k)8 +b Fv(-w)o(a)m(y)33 b(g)o(r)o(aph)g(par)t(titioning.)50 +b(Dur)r(ing)32 b(the)i(coarsening)f(phase)o(,)h(the)g(siz)o(e)h(of)f +(the)g(g)o(r)o(aph)f(is)i(successiv)m(ely)i(decreased.)49 +b(Dur)r(ing)33 b(the)0 4162 y(initial)e(par)t(titioning)e(phase)o(,)g +(a)h Fn(k)8 b Fv(-w)o(a)m(y)30 b(par)t(titioning)g(is)h(computed,)e +(Dur)r(ing)g(the)h(m)o(ultile)m(v)m(el)g(re\002nement)f(\(or)i +(uncoarsening\))e(phase)o(,)g(the)h(par)t(titioning)f(is)i(successiv)m +(ely)i(re\002ned)d(as)g(it)h(is)0 4362 y(projected)e(to)h(the)g(larger) +g(g)o(r)o(aphs)o(.)39 b Fn(G)1594 4390 y Fq(0)1689 4362 +y Fv(is)31 b(the)f(input)g(g)o(r)o(aph,)f(which)g(is)i(the)f(\002nest)h +(g)o(r)o(aph.)39 b Fn(G)3924 4390 y Fl(i)12 b FI(C)p +Fq(1)4150 4362 y Fv(is)31 b(the)f(ne)m(xt)g(le)m(v)m(el)g(coarser)g(g)o +(r)o(aph)f(of)34 b Fn(G)5850 4389 y Fl(i)5900 4362 y +Fv(.)41 b Fn(G)6075 4390 y Fq(4)6170 4362 y Fv(is)31 +b(the)f(coarsest)h(g)o(r)o(aph.)0 4731 y FK(adjacent)50 +b(v)n(ertices)g(of)h(the)g(input)g(graph)g(in)g(order)h(to)f(form)h(a)e +(related)h(coarser)f(graph.)79 b(Computation)52 b(of)f(the)g(initial)g +(partitioning)0 4950 y(is)46 b(performed)g(on)g(the)g(coarsest)f(\(and) +h(hence)f(smallest\))g(of)h(these)g(graphs,)g(and)f(so)h(is)g(v)n(ery)f +(f)n(ast.)64 b(Finally)-11 b(,)48 b(partition)e(re\002nement)g(is)0 +5170 y(performed)54 b(on)f(each)f(le)l(v)n(el)g(graph,)k(from)e(the)f +(coarsest)f(to)h(the)g(\002nest)g(\()p Fs(i.e)o FK(.,)i(original)f +(graph\))f(using)g(a)g(KL/FM-type)h(re\002nement)0 5389 +y(algorithm)42 b([2)q(,)f(9].)51 b(Figure)42 b(2)f(illustrates)h(the)f +(multile)l(v)n(el)g(graph)h(partitioning)g(paradigm.)199 +5608 y(Comparisons)58 b(performed)g(in)h([7])f(ha)m(v)n(e)f(sho)l(wn)g +(that)h(serial)g(multile)l(v)n(el)g Fy(k)10 b FK(-w)n(ay)58 +b(partitioning)h(is)f(o)n(v)n(er)f(50)h(times)g(f)n(aster)g(than)0 +5827 y(multile)l(v)n(el)39 b(spectral)g(bisection)g([12])h(while)g +(producing)f(partitionings)h(that)g(cut)f(10\045)h(to)f(50\045)h(fe)l +(wer)f(edges.)50 b(Our)39 b(e)n(xperiments)g(on)0 6046 +y(a)j(1024-processor)g(Cray)g(T3E)h(ha)m(v)n(e)e(sho)l(wn)h(that)h +FA(P)-7 b(arMETIS)p 3757 6046 50 7 v 61 w(V3)p 4021 6046 +V 59 w(P)g(ar)7 b(tKw)n(a)-5 b(y)43 b FK(can)f(partition)h(a)f +(500-million)h(element)f(3D)g(mesh)0 6265 y(in)g(well)f(under)h(a)f +(minute!)199 6485 y(Recall)d(that)g(we)f(mentioned)i(that)f(if)g(the)g +(graph)g(is)g(well)g(distrib)m(uted)g(among)g(the)g(processors)f +FA(P)-7 b(arMETIS)p 6459 6485 V 61 w(V3)p 6723 6485 V +60 w(P)g(ar)7 b(tKw)n(a)-5 b(y)38 b FK(runs)0 6704 y(f)n(aster)-9 +b(.)79 b(In)51 b(f)n(act,)i(our)e(e)n(xperiments)f(ha)m(v)n(e)f(sho)l +(wn)h(that)h(when)g(we)f(use)g FA(P)-7 b(arMETIS)p 4975 +6704 V 61 w(V3)p 5239 6704 V 60 w(P)g(ar)7 b(tKw)n(a)-5 +b(y)51 b FK(to)g(partition)g(a)g(graph)f(that)h(is)0 +6923 y(distrib)m(uted)57 b(according)f(to)h(the)g(partitioning)h +(produced)f(by)g(an)f(earlier)h(call)g(to)g FA(P)-7 b(arMETIS)p +5596 6923 V 61 w(V3)p 5860 6923 V 60 w(P)g(ar)7 b(tKw)n(a)-5 +b(y)p FK(,)6715 6863 y Fr(2)6847 6923 y FK(the)57 b(amount)g(of)0 +7142 y(time)40 b(required)f(for)h(this)g(second)e(partitioning)j(is)e +(often)g(reduced)g(by)h(a)f(f)n(actor)h(of)g(tw)n(o)g(to)f(four)-9 +b(.)51 b(The)40 b(reason)f(for)h(this)f(has)g(to)g(do)h(with)0 +7361 y(the)f(inter)m(-processor)g(communication)h(pattern)f(of)h +FA(P)-7 b(arMETIS)p 3793 7361 V 61 w(V3)p 4057 7361 V +59 w(P)g(ar)7 b(tKw)n(a)-5 b(y)p FK(.)51 b(If)40 b(the)f(graph)g(is)g +(initially)h(distrib)m(uted)g(randomly)0 7581 y(\()p +Fs(i.e)p FK(.,)51 b(there)f(are)g(man)n(y)g(interf)n(ace)g(v)n +(ertices\),)h(each)e(processor)h(spends)f(a)h(lot)g(of)h(time)f +(communicating)g(information)i(about)e(these)0 7800 y(interf)n(ace)g(v) +n(ertices)f(to)i(man)n(y)e(other)i(processors.)75 b(On)50 +b(the)g(other)h(hand,)g(if)g(the)f(graph)g(is)g(well)g(distrib)m(uted,) +i(the)e(number)g(of)h(inter)m(-)0 8019 y(f)n(ace)c(v)n(ertices)g(is)g +(much)g(smaller)h(\(as)f(is)g(the)h(number)f(of)h(other)g(processors)e +(with)i(whom)g(each)e(processor)h(has)g(to)h(communicate\),)0 +8238 y(reducing)f(the)f(o)n(v)n(erall)g(runtime)h(of)g(the)g +(partitioner)-9 b(.)67 b(Of)47 b(course,)f(this)h(is)f(the)h(chick)n +(en)f(and)h(e)n(gg)f(problem.)67 b(Ho)l(w)46 b(can)g(we)g(initially)0 +8457 y(distrib)m(ute)53 b(the)g(graph)f(nicely)h(without)g(ha)m(ving)g +(\002rst)g(partitioned)g(it?)86 b(W)-13 b(e)52 b(ha)m(v)n(e)f(de)l(v)n +(eloped)h(one)h(such)f(method)h(for)g(partitioning)0 +8676 y(graphs)h(that)g(correspond)f(to)i(\002nite)f(element)g(meshes.) +87 b(This)54 b(is)g(to)g(quickly)g(compute)g(a)g(f)n(airly)h(good)f +(initial)g(partitioning)h(using)0 8896 y(the)d(coordinate)f(v)l(alues)g +(of)h(the)g(mesh.)82 b(W)-13 b(e)51 b(can)g(then)h(redistrib)m(ute)f +(the)h(graph)g(according)g(to)g(this)f(initial)i(partitioning)f(and)g +(then)0 9115 y(call)46 b FA(P)-7 b(arMETIS)p 1054 9115 +V 60 w(V3)p 1317 9115 V 60 w(P)g(ar)7 b(tKw)n(a)-5 b(y)46 +b FK(on)g(the)g(redistrib)m(uted)f(graph.)68 b FA(P)-10 +b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)52 +b FK(pro)n(vides)45 b(the)h FA(P)-7 b(arMETIS)p 6331 +9115 V 61 w(V3)p 6595 9115 V 60 w(P)g(ar)7 b(tGeomKw)n(a)-5 +b(y)0 9334 y FK(routine)59 b(for)g(doing)f(just)h(this.)101 +b(Gi)l(v)n(en)57 b(a)h(graph)h(that)f(is)g(distrib)m(uted)h(among)f +(the)g(processors)f(and)i(the)f(coordinates)g(of)g(the)g(v)n(er)m(-)0 +9553 y(tices,)347 9493 y Fr(3)467 9553 y FA(P)-7 b(arMETIS)p +1235 9553 V 61 w(V3)p 1499 9553 V 60 w(P)g(ar)7 b(tGeomKw)n(a)-5 +b(y)49 b FK(quickly)g(computes)e(an)h(initial)h(partitioning)g(using)f +(a)g(space-\002lling)g(curv)n(e)f(method,)0 9772 y(redistrib)m(utes)53 +b(the)g(graph)g(according)g(to)g(this)g(partitioning,)k(and)c(then)g +(calls)f FA(P)-7 b(arMETIS)p 5371 9772 V 61 w(V3)p 5635 +9772 V 60 w(P)g(ar)7 b(tKw)n(a)-5 b(y)53 b FK(to)h(compute)f(the)g +(\002nal)0 9992 y(high-quality)38 b(partitioning.)50 +b(Our)37 b(e)n(xperiments)f(ha)m(v)n(e)f(sho)l(wn)i(that)g +FA(P)-7 b(arMETIS)p 4721 9992 V 61 w(V3)p 4985 9992 V +59 w(P)g(ar)7 b(tGeomKw)n(a)-5 b(y)38 b FK(is)f(often)g(tw)n(o)g(times) +g(f)n(aster)p 0 10280 3120 7 v 174 10401 a Fq(2)239 10449 +y FF(That)d(is,)g(we)f(\002rst)g(call)h FG(P)-5 b(arMETIS)p +1943 10449 40 7 v 46 w(V3)p 2152 10449 V 47 w(P)g(ar)5 +b(tKw)n(a)l(y)33 b FF(to)h(\002nd)g(a)g(good)h(partitioning)g(of)g(a)e +(graph.)44 b(Ne)n(xt)34 b(we)f(mo)n(v)n(e)i(the)f(v)n(ertices)f(of)i +(the)e(graph)i(according)h(to)e(the)0 10607 y(computed)h(partitioning,) +g(and)f(then)g(call)f FG(P)-5 b(arMETIS)p 2572 10607 +V 47 w(V3)p 2782 10607 V 47 w(P)g(ar)5 b(tKw)n(a)l(y)32 +b FF(to)i(partition)g(this)g(same,)f(b)m(ut)h(ne)m(wly)g(distrib)m +(uted,)h(graph.)174 10731 y Fq(3)239 10779 y FG(P)-5 +b(arMETIS)p 856 10779 V 46 w(V3)p 1065 10779 V 48 w(P)g(ar)5 +b(tGeomKw)n(a)l(y)32 b FF(requires)i(the)f(coordinates)i(of)f(the)f +(centers)h(of)g(each)f(element.)3858 11298 y FK(6)p eop +%%Page: 7 7 +7 6 bop 0 166 a FK(than)41 b FA(P)-7 b(arMETIS)p 1095 +166 50 7 v 61 w(V3)p 1359 166 V 60 w(P)g(ar)7 b(tKw)n(a)-5 +b(y)p FK(,)41 b(and)h(achie)l(v)n(es)d(identical)i(partition)i(quality) +-11 b(.)203 385 y FA(P)h FG(A)8 b(R)g FA(M)-9 b FG(E)-34 +b FA(T)g FG(I)p FA(S)39 b FK(also)32 b(pro)n(vides)f(the)h +FA(P)-7 b(arMETIS)p 2847 385 V 61 w(P)g(ar)7 b(tGeom)34 +b FK(function)f(for)f(partitioning)i(unstructured)e(graphs)g(when)g +(coordinates)0 604 y(for)53 b(the)f(v)n(ertices)f(are)h(a)m(v)l +(ailable.)82 b FA(P)-7 b(arMETIS)p 2807 604 V 61 w(P)g(ar)7 +b(tGeom)54 b FK(computes)e(a)g(partitioning)h(based)f(only)g(on)g(the)h +(space-\002lling)f(curv)n(e)0 824 y(method.)f(Therefore,)41 +b(it)g(is)g(e)n(xtremely)f(f)n(ast)h(\(often)h(5)f(to)g(10)g(times)g(f) +n(aster)g(than)g FA(P)-7 b(arMETIS)p 5437 824 V 60 w(P)g(ar)7 +b(tGeomKw)n(a)-5 b(y)p FK(\),)42 b(b)m(ut)f(it)h(computes)0 +1043 y(poor)k(quality)g(partitionings)g(\(it)g(may)g(cut)f(2)h(to)g(10) +f(times)h(more)g(edges)e(than)i FA(P)-7 b(arMETIS)p 5346 +1043 V 61 w(P)g(ar)7 b(tGeomKw)n(a)-5 b(y)p FK(\).)65 +b(This)46 b(routine)g(can)0 1262 y(be)53 b(useful)h(for)g(certain)f +(computations)h(in)g(which)f(the)g(use)g(of)h(space-\002lling)g(curv)n +(es)e(is)i(the)f(appropriate)h(partitioning)g(technique)0 +1481 y(\()p Fs(e)n(.g)o FK(.,)41 b Fy(n)7 b FK(-body)42 +b(computations\).)0 1936 y Ft(3.2)199 b(P)-6 b(ar)t(titioning)56 +b(Meshes)e(Directl)m(y)4 2255 y FA(P)-10 b FG(A)8 b(R)g +FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)t FK(,)69 b(V)-18 +b(ersion)67 b(3.0)g(also)g(pro)n(vides)f(ne)l(w)h(routines)h(that)f +(support)h(the)f(computation)g(of)h(partitionings)g(and)f(repartition-) +0 2474 y(ings)57 b(gi)l(v)n(en)g Fs(meshes)g FK(\(and)g(not)h(graphs\)) +g(as)f(inputs.)99 b(In)58 b(particular)-7 b(,)62 b FA(P)-7 +b(arMETIS)p 4910 2474 V 61 w(V3)p 5174 2474 V 60 w(P)g(ar)7 +b(tMeshKw)n(a)-5 b(y)58 b FK(tak)n(e)g(a)f(mesh)h(as)f(input)0 +2693 y(and)71 b(computes)g(a)g(partitioning)i(of)e(the)h(mesh)f +(elements.)140 b(Internally)-11 b(,)79 b FA(P)-7 b(arMETIS)p +5213 2693 V 61 w(V3)p 5477 2693 V 60 w(P)g(ar)7 b(tMeshKw)n(a)-5 +b(y)72 b FK(uses)f(a)g(mesh-to-)0 2912 y(graph)56 b(routine)h(and)e +(then)h(calls)g(the)g(same)f(core)h(partitioning)g(routine)h(that)f(is) +g(used)f(by)h(both)g FA(P)-7 b(arMETIS)p 6487 2912 V +61 w(V3)p 6751 2912 V 60 w(P)g(ar)7 b(tKw)n(a)-5 b(y)56 +b FK(and)0 3132 y FA(P)-7 b(arMETIS)p 768 3132 V 61 w(V3)p +1032 3132 V 60 w(P)g(ar)7 b(tGeomKw)n(a)-5 b(y)p FK(.)203 +3351 y FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g +FG(I)p FA(S)65 b FK(pro)n(vides)57 b(no)h(such)f(routines)h(for)h +(computing)f(adapti)l(v)n(e)f(repartitionings)i(directly)f(from)h +(meshes.)99 b(Ho)l(we)l(v)n(er)-7 b(,)61 b(it)0 3570 +y(does)h(pro)n(vide)h(the)g(routine)g FA(P)-7 b(arMETIS)p +2502 3570 V 61 w(V3)p 2766 3570 V 60 w(Mesh2Dual)64 b +FK(for)g(constructing)f(a)f(dual)h(graph)g(gi)l(v)n(en)f(a)h(mesh,)k +(quickly)c(and)g(in)0 3789 y(parallel.)133 b(Since)68 +b(the)h(construction)f(of)h(the)g(dual)g(graph)g(is)f(in)h(parallel,)75 +b(it)69 b(can)f(be)h(used)f(to)g(construct)h(the)g(input)g(graph)f(for) +0 4008 y FA(P)-7 b(arMETIS)p 768 4008 V 61 w(V3)p 1032 +4008 V 60 w(Adaptiv)l(eRepar)7 b(t)p FK(.)199 4228 y(Essentially)-11 +b(,)50 b(both)e FA(P)-7 b(arMETIS)p 2120 4228 V 61 w(V3)p +2384 4228 V 60 w(P)g(ar)7 b(tMeshKw)n(a)-5 b(y)49 b FK(and)f +FA(P)-7 b(arMETIS)p 4647 4228 V 61 w(V3)p 4911 4228 V +60 w(Mesh2Dual)50 b FK(tak)n(e)e(the)g(b)m(urden)g(of)g(writing)h(an)0 +4447 y(ef)l(\002cient)j(mesh-to-graph)g(routine)g(from)g(the)g(user)-9 +b(.)81 b(Our)52 b(e)n(xperiments)f(ha)m(v)n(e)f(sho)l(wn)h(that)h(this) +g(routine)g(typically)g(runs)f(in)h(about)0 4666 y(half)42 +b(the)f(time)h(that)f(it)h(tak)n(es)f(for)46 b FA(P)-10 +b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)48 +b FK(to)42 b(compute)f(a)h(partitioning.)0 5121 y Ft(3.3)199 +b(P)-6 b(ar)t(titioning)56 b(Adaptivel)m(y)f(Re\002ned)f(Meshes)0 +5440 y FK(F)n(or)35 b(lar)m(ge-scale)e(scienti\002c)h(simulations,)i +(the)e(computational)h(requirements)f(of)h(techniques)e(relying)i(on)g +(globally)g(re\002ned)f(meshes)0 5659 y(become)42 b(v)n(ery)g(high,)g +(especially)f(as)h(the)g(comple)n(xity)g(and)g(size)g(of)g(the)g +(problems)h(increase.)52 b(By)42 b(locally)g(re\002ning)h(and)f +(de-re\002ning)0 5878 y(the)55 b(mesh)h(either)f(to)h(capture)f(\003o)l +(w-\002eld)h(phenomena)g(of)f(interest)h([1])g(or)g(to)g(account)f(for) +h(v)l(ariations)f(in)h(errors)g([11],)j(adapti)l(v)n(e)0 +6097 y(methods)38 b(mak)n(e)g(standard)g(computational)g(methods)g +(more)g(cost)g(ef)l(fecti)l(v)n(e.)49 b(The)38 b(ef)l(\002cient)h(e)n +(x)n(ecution)d(of)j(such)e(adapti)l(v)n(e)g(scienti\002c)0 +6316 y(simulations)59 b(on)h(parallel)g(computers)f(requires)h(a)f +(periodic)h(repartitioning)h(of)f(the)f(underlying)i(computational)e +(mesh.)105 b(These)0 6536 y(repartitionings)39 b(should)f(minimize)g +(both)h(the)f(inter)m(-processor)g(communications)g(incurred)g(in)h +(the)f(iterati)l(v)n(e)g(mesh-based)f(compu-)0 6755 y(tation)j(and)f +(the)g(data)g(redistrib)m(ution)h(costs)e(required)i(to)f(balance)g +(the)g(load.)50 b(Hence,)38 b(adapti)l(v)n(e)h(repartitioning)h(is)f(a) +g(multi-objecti)l(v)n(e)0 6974 y(optimization)i(problem.)55 +b FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g +FG(I)p FA(S)46 b FK(pro)n(vides)40 b(the)g(routine)g +FA(P)-7 b(arMETIS)p 4408 6974 V 61 w(V3)p 4672 6974 V +60 w(Adaptiv)l(eRepar)7 b(t)42 b FK(for)f(repartitioning)g(such)e +(adap-)0 7193 y(ti)l(v)n(ely)50 b(re\002ned)g(meshes.)76 +b(This)50 b(routine)h(assumes)d(that)j(the)f(mesh)f(is)h(well)g +(distrib)m(uted)g(among)h(the)f(processors,)g(b)m(ut)g(that)h(\(due)f +(to)0 7412 y(mesh)41 b(re\002nement)h(and)f(de-re\002nement\))h(this)f +(distrib)m(ution)h(is)g(poorly)g(load)f(balanced.)199 +7631 y(Repartitioning)53 b(algorithms)f(f)n(all)h(into)g(tw)n(o)f +(general)g(cate)n(gories.)81 b(The)53 b(\002rst)f(cate)n(gory)f +(balances)g(the)h(computation)h(by)f(incre-)0 7851 y(mentally)i(dif)l +(fusing)g(load)g(from)g(those)g(sub-domains)f(that)h(ha)m(v)n(e)e(more) +i(w)n(ork)h(to)e(adjacent)g(sub-domains)h(that)g(ha)m(v)n(e)e(less)h(w) +n(ork.)0 8070 y(These)43 b(schemes)g(are)g(referred)h(to)g(as)g +Fk(dif)m(fusiv)n(e)f(sc)n(hemes)p FK(.)57 b(The)44 b(second)f(cate)n +(gory)g(balances)g(the)g(load)h(by)g(computing)g(an)g(entirely)0 +8289 y(ne)l(w)k(partitioning,)i(and)e(then)h(intelligently)g(mapping)f +(the)g(sub-domains)g(of)h(the)f(ne)l(w)g(partitioning)h(to)g(the)f +(processors)f(such)h(that)0 8508 y(the)57 b(redistrib)m(ution)h(cost)f +(is)g(minimized.)99 b(These)57 b(schemes)f(are)i(generally)f(referred)h +(to)f(as)g Fk(remapping)g(sc)n(hemes)p FK(.)98 b(Remapping)0 +8727 y(schemes)47 b(typically)h(lead)f(to)h(repartitionings)h(that)f +(ha)m(v)n(e)f(smaller)g(edge-cuts,)i(while)f(dif)l(fusi)l(v)n(e)f +(schemes)g(lead)g(to)h(repartitionings)0 8946 y(that)55 +b(incur)f(smaller)h(redistrib)m(ution)g(costs.)89 b(Ho)l(we)l(v)n(er)-7 +b(,)56 b(since)e(these)f(results)h(can)g(v)l(ary)h(signi\002cantly)f +(among)h(dif)l(ferent)g(types)f(of)0 9166 y(applications,)41 +b(it)g(can)g(be)h(dif)l(\002cult)g(to)f(select)g(the)g(best)g +(repartitioning)i(scheme)d(for)i(the)g(job)-7 b(.)199 +9385 y(Recently)c(,)43 b(we)f(de)l(v)n(eloped)g(a)g(Uni\002ed)h +(Repartitioning)h(Algorithm)g([15])f(for)h(adapti)l(v)n(e)d +(repartitioning)j(that)f(combines)g(the)g(best)0 9604 +y(characteristics)60 b(of)i(remapping)g(and)f(dif)l(fusion-based)g +(repartitioning)i(schemes.)109 b(A)62 b(k)n(e)n(y)f(parameter)g(used)g +(by)h(this)f(algorithm)0 9823 y(is)54 b(the)g Fk(ITR)f(F)-16 +b(actor)p FK(.)88 b(This)54 b(parameter)g(describes)f(the)g(ratio)i +(between)e(the)h(time)g(required)g(for)h(performing)g(the)e(inter)m +(-processor)0 10042 y(communications)36 b(incurred)h(during)f(parallel) +h(processing)e(compared)h(to)g(the)h(time)f(to)h(perform)g(the)f(data)g +(redistrib)m(ution)h(associated)0 10262 y(with)e(balancing)g(the)g +(load.)48 b(As)35 b(such,)g(it)g(allo)l(ws)g(us)f(to)i(compute)f(a)f +(single)h(metric)g(that)g(describes)f(the)h(quality)g(of)h(the)f +(repartitioning,)0 10481 y(e)l(v)n(en)40 b(though)i(adapti)l(v)n(e)f +(repartitioning)h(is)f(a)g(multi-objecti)l(v)n(e)h(optimization)g +(problem.)199 10700 y FA(P)-7 b(arMETIS)p 967 10700 V +61 w(V3)p 1231 10700 V 60 w(Adaptiv)l(eRepar)7 b(t)52 +b FK(is)f(a)f(parallel)h(implementation)g(of)g(the)f(Uni\002ed)h +(Repartitioning)g(Algorithm.)79 b(This)51 b(is)f(a)3858 +11298 y(7)p eop +%%Page: 8 8 +8 7 bop 0 166 a FK(multile)l(v)n(el)31 b(partitioning)i(algorithm,)h +(and)d(so,)i(is)e(in)h(nature)f(similar)h(to)g(the)f(the)h(algorithm)g +(implemented)f(in)h FA(P)-7 b(arMETIS)p 7096 166 50 7 +v 61 w(V3)p 7360 166 V 60 w(P)g(ar)7 b(tKw)n(a)-5 b(y)p +FK(.)0 385 y(Ho)l(we)l(v)n(er)e(,)40 b(this)h(routine)h(uses)e(a)g +(technique)h(kno)l(wn)g(as)g Fs(local)g(coar)n(sening)p +FK(.)50 b(Here,)40 b(only)i(v)n(ertices)e(that)h(ha)m(v)n(e)f(been)h +(distrib)m(uted)g(onto)0 604 y(the)f(same)g(processor)g(are)g +(coarsened)g(together)-9 b(.)50 b(On)41 b(the)f(coarsest)f(graph,)i(an) +f(initial)h(partitioning)g(need)f(not)h(be)f(computed,)g(as)g(one)0 +824 y(can)45 b(either)g(be)g(deri)l(v)n(ed)f(from)i(the)g(initial)f +(graph)h(distrib)m(ution)f(\(in)h(the)f(case)f(when)h(sub-domains)g +(are)g(coupled)g(to)g(processors\),)g(or)0 1043 y(else)k(one)h(needs)f +(to)i(be)f(supplied)g(as)f(an)h(input)g(to)h(the)f(routine)g(\(in)h +(the)f(case)f(when)h(sub-domains)g(are)g(de-coupled)f(from)i(proces-)0 +1262 y(sors\).)74 b(Ho)l(we)l(v)n(er)-7 b(,)49 b(this)g(partitioning)h +(does)f(need)f(to)i(be)e(balanced.)73 b(The)50 b(balancing)e(phase)g +(is)h(performed)h(on)f(the)g(coarsest)f(graph)0 1481 +y(twice)42 b(by)g(alternati)l(v)n(e)g(methods.)53 b(That)43 +b(is,)f(optimized)g(v)l(ariants)g(of)h(remapping)f(and)g(dif)l(fusion)h +(algorithms)g([16])g(are)f(both)g(used)g(to)0 1700 y(compute)48 +b(ne)l(w)f(partitionings.)71 b(A)48 b(quality)g(metric)g(for)h(each)e +(of)h(these)g(partitionings)g(is)g(then)g(computed)g(\(using)g(the)g +(ITR)g(F)n(actor\))0 1919 y(and)d(the)f(partitioning)i(with)f(the)g +(highest)f(quality)h(is)g(selected.)60 b(This)45 b(technique)f(tends)g +(to)h(gi)l(v)n(e)g(v)n(ery)f(good)h(points)g(from)g(which)g(to)0 +2139 y(start)i(multile)l(v)n(el)g(re\002nement,)h(re)n(g)o(ardless)e +(of)i(the)f(type)g(of)g(repartitioning)h(problem)g(or)g(the)f(v)l(alue) +f(of)i(the)f(ITR)g(F)n(actor)-9 b(.)68 b(Note)47 b(that)0 +2358 y(the)h(f)n(act)g(that)g(the)g(algorithm)h(computes)e(tw)n(o)h +(initial)h(partitionings)f(does)g(not)g(impact)g(its)g(scalability)f +(as)g(long)i(as)e(the)h(size)f(of)h(the)0 2577 y(coarsest)35 +b(graph)i(is)f(suitably)g(small)g([8].)50 b(Finally)-11 +b(,)38 b(multile)l(v)n(el)e(re\002nement)g(is)g(performed)h(on)g(the)f +(balanced)f(partitioning)j(in)e(order)h(to)0 2796 y(further)i(impro)n +(v)n(e)e(its)h(quality)-11 b(.)51 b(Since)38 b FA(P)-7 +b(arMETIS)p 2989 2796 V 61 w(V3)p 3253 2796 V 59 w(Adaptiv)l(eRepar)7 +b(t)40 b FK(starts)e(from)h(a)f(graph)g(that)g(is)g(already)f(well)h +(distrib)m(uted,)0 3015 y(it)i(is)f(e)n(xtremely)g(f)n(ast.)50 +b(Experiments)40 b(on)g(a)f(1024-processor)g(Cray)h(T3E)g(sho)l(w)f +(that)g FA(P)-7 b(arMETIS)p 5704 3015 V 61 w(V3)p 5968 +3015 V 60 w(Adaptiv)l(eRepar)7 b(t)41 b FK(is)f(able)f(to)0 +3235 y(compute)i(partitionings)h(for)g(a)g(billion-element)g(mesh)f(in) +h(under)f(a)g(minute.)199 3454 y(Appropriate)i(v)l(alues)e(to)i(pass)e +(for)i(the)f(ITR)h(F)n(actor)f(parameter)g(can)f(easily)h(be)g +(determined)g(depending)g(on)h(the)f(times)g(required)0 +3673 y(to)59 b(perform)g(\(i\))h(all)e(inter)m(-processor)h +(communications)f(that)h(ha)m(v)n(e)e(occurred)i(since)f(the)g(last)g +(repartitioning,)64 b(and)58 b(\(ii\))i(the)e(data)0 +3892 y(redistrib)m(ution)45 b(associated)d(with)j(the)f(last)f +(repartitioning/load)j(balancing)d(phase.)58 b(Simply)45 +b(di)l(vide)f(the)g(\002rst)h(time)f(by)g(the)g(second.)0 +4111 y(The)53 b(result)f(is)g(the)h(correct)f(ITR)h(F)n(actor)-9 +b(.)84 b(In)53 b(case)e(these)h(times)g(cannot)g(be)h(ascertained)e(\() +p Fs(e)n(.g)o FK(.,)k(for)e(the)f(\002rst)h(repartitioning/load)0 +4330 y(balancing)39 b(phase\),)f(our)h(e)n(xperiments)f(ha)m(v)n(e)g +(sho)l(wn)g(that)i(v)l(alues)e(between)g(100)h(and)g(1000)g(w)n(ork)g +(well)g(for)h(a)f(v)l(ariety)g(of)g(situations.)199 4550 +y FA(P)-7 b(arMETIS)p 967 4550 V 61 w(V3)p 1231 4550 +V 60 w(Adaptiv)l(eRepar)7 b(t)50 b FK(can)d(be)g(used)g(to)h(load)g +(balance)f(the)g(mesh)h(either)f(before)h(or)g(after)g(mesh)f +(adaptation.)70 b(In)0 4769 y(the)41 b(latter)f(case,)g(each)f +(processor)h(\002rst)h(locally)g(adapts)f(its)h(mesh,)e(leading)i(to)g +(dif)l(ferent)g(processors)f(ha)m(ving)g(dif)l(ferent)h(numbers)g(of)0 +4988 y(elements.)58 b FA(P)-7 b(arMETIS)p 1459 4988 V +61 w(V3)p 1723 4988 V 60 w(Adaptiv)l(eRepar)7 b(t)46 +b FK(can)d(then)h(compute)g(a)g(partitioning)h(in)g(which)f(the)g(load) +g(is)f(balanced.)58 b(Ho)l(we)l(v)n(er)-7 b(,)0 5207 +y(load)55 b(balancing)g(can)g(also)g(be)g(done)g(before)h(adaptation)f +(if)h(the)f(de)n(gree)f(of)i(re\002nement)g(for)g(each)e(element)h(can) +g(be)g(estimated)g Fs(a)0 5426 y(priori)p FK(.)70 b(That)49 +b(is,)g(if)f(we)g(kno)l(w)g(ahead)f(of)h(time)g(into)h(ho)l(w)f(man)n +(y)f(ne)l(w)h(elements)f(each)g(old)i(element)e(will)i(subdi)l(vide,)f +(we)g(can)g(use)0 5646 y(these)j(estimations)f(as)h(the)g(weights)g(of) +h(the)f(v)n(ertices)f(for)i(the)f(graph)g(that)h(corresponds)e(to)i +(the)f(dual)g(of)h(the)f(mesh.)80 b(In)52 b(this)f(case,)0 +5865 y(the)45 b(mesh)g(can)f(be)h(redistrib)m(uted)g(before)g(adaption) +g(tak)n(es)g(place.)61 b(This)45 b(technique)g(can)f(signi\002cantly)h +(reduce)g(data)g(redistrib)m(ution)0 6084 y(times)c([10)q(].)0 +6539 y Ft(3.4)199 b(P)-6 b(ar)t(tition)56 b(Re\002nement)0 +6858 y FA(P)-7 b(arMETIS)p 768 6858 V 61 w(V3)p 1032 +6858 V 60 w(Re\002neKw)n(a)i(y)44 b FK(is)g(the)f(routine)i(pro)n +(vided)e(by)48 b FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 +b FA(T)g FG(I)p FA(S)50 b FK(to)44 b(impro)n(v)n(e)g(the)g(quality)g +(of)g(an)f(e)n(xisting)h(partitioning.)0 7077 y(Once)51 +b(a)g(graph)h(is)f(partitioned)i(and)e(it)h(has)f(been)g(redistrib)m +(uted)h(accordingly)-11 b(,)53 b FA(P)-7 b(arMETIS)p +5488 7077 V 61 w(V3)p 5752 7077 V 60 w(Re\002neKw)n(a)i(y)52 +b FK(can)f(be)h(called)f(to)0 7296 y(compute)37 b(a)g(ne)l(w)f +(partitioning)i(that)f(further)h(impro)n(v)n(es)e(the)h(quality)-11 +b(.)50 b(Thus,)38 b(lik)n(e)f FA(P)-7 b(arMETIS)p 5512 +7296 V 61 w(V3)p 5776 7296 V 60 w(Adaptiv)l(eRepar)7 +b(t)p FK(,)40 b(this)d(routine)0 7515 y(assumes)j(that)h(the)h(graph)g +(is)f(already)g(well)g(distrib)m(uted)h(among)f(the)h(processors.)199 +7734 y FA(P)-7 b(arMETIS)p 967 7734 V 61 w(V3)p 1231 +7734 V 60 w(Re\002neKw)n(a)i(y)53 b FK(can)f(be)g(used)g(to)h(impro)n +(v)n(e)f(the)g(quality)h(of)g(partitionings)g(that)g(are)f(produced)h +(by)f(other)h(par)m(-)0 7954 y(titioning)71 b(algorithms)f(\(such)g(as) +f(the)h(technique)g(discussed)e(in)j(Section)f(3.1)f(that)h(is)g(used)g +(in)g FA(P)-7 b(arMETIS)p 6633 7954 V 61 w(V3)p 6897 +7954 V 60 w(P)g(ar)7 b(tGeom)p FK(\).)0 8173 y FA(P)-7 +b(arMETIS)p 768 8173 V 61 w(V3)p 1032 8173 V 60 w(Re\002neKw)n(a)i(y)44 +b FK(can)f(also)h(be)f(used)g(repeatedly)h(to)g(further)h(impro)n(v)n +(e)e(the)h(quality)g(of)g(a)g(partitioning.)58 b(That)45 +b(is,)e(we)0 8392 y(can)135 b(call)h FA(P)-7 b(arMETIS)p +1510 8392 V 61 w(V3)p 1774 8392 V 60 w(Re\002neKw)n(a)i(y)p +FK(,)159 b(mo)n(v)n(e)135 b(the)h(graph)g(according)g(to)g(the)g +(partitioning,)160 b(and)135 b(then)h(call)0 8611 y FA(P)-7 +b(arMETIS)p 768 8611 V 61 w(V3)p 1032 8611 V 60 w(Re\002neKw)n(a)i(y)46 +b FK(ag)o(ain.)65 b(Ho)l(we)l(v)n(er)-7 b(,)46 b(each)g(successi)l(v)n +(e)d(call)j(to)h FA(P)-7 b(arMETIS)p 5473 8611 V 61 w(V3)p +5737 8611 V 60 w(Re\002neKw)n(a)i(y)46 b FK(will)h(tend)f(to)g(pro-)0 +8830 y(duce)41 b(smaller)g(impro)n(v)n(ements)g(in)h(quality)-11 +b(.)199 9049 y(Lik)n(e)54 b FA(P)-7 b(arMETIS)p 1323 +9049 V 61 w(V3)p 1587 9049 V 60 w(Adaptiv)l(eRepar)7 +b(t)p FK(,)58 b FA(P)-7 b(arMETIS)p 3650 9049 V 61 w(V3)p +3914 9049 V 60 w(Re\002neKw)n(a)i(y)53 b FK(performs)h(local)g +(coarsening.)86 b(These)53 b(tw)n(o)g(rou-)0 9269 y(tines)g(also)f(use) +h(the)g(same)f(re\002nement)h(algorithm.)86 b(The)54 +b(dif)l(ference)f(is)f(that)h FA(P)-7 b(arMETIS)p 5415 +9269 V 61 w(V3)p 5679 9269 V 60 w(Re\002neKw)n(a)i(y)54 +b FK(does)e(not)h(initially)0 9488 y(balance)d(the)g(partitioning)h(on) +g(the)f(coarsest)f(graph,)j(as)e FA(P)-7 b(arMETIS)p +4120 9488 V 61 w(V3)p 4384 9488 V 60 w(Adaptiv)l(eRepar)7 +b(t)52 b FK(does.)77 b(Instead,)52 b(the)e(assumption)g(is)0 +9707 y(that)57 b(the)g(graph)g(is)g(well)g(distrib)m(uted)g(and)g(the)g +(initial)g(partitioning)h(is)f(balanced.)96 b(Since)57 +b FA(P)-7 b(arMETIS)p 6200 9707 V 61 w(V3)p 6464 9707 +V 60 w(Re\002neKw)n(a)i(y)57 b FK(starts)0 9926 y(from)42 +b(a)g(graph)f(that)h(is)f(well)g(distrib)m(uted,)g(it)h(is)g(v)n(ery)f +(f)n(ast.)3858 11298 y(8)p eop +%%Page: 9 9 +9 8 bop 1500 2836 a @beginspecial 0 @llx 0 @lly 704 @urx +416 @ury 2880 @rwi @setspecial +%%BeginDocument: figures/multiphase.eps +%!PS-Adobe-2.0 EPSF-2.0 +%%Title: multiphase.eps +%%Creator: fig2dev Version 3.2 Patchlevel 1 +%%CreationDate: Thu Feb 15 08:49:41 2001 +%%For: [email protected] (Kirk Schloegel) +%%Orientation: Portrait +%%BoundingBox: 0 0 704 416 +%%Pages: 0 +%%BeginSetup +%%EndSetup +%%Magnification: 1.0000 +%%EndComments +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +-53.0 469.0 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def + /DrawEllipse { + /endangle exch def + /startangle exch def + /yrad exch def + /xrad exch def + /y exch def + /x exch def + /savematrix mtrx currentmatrix def + x y tr xrad yrad sc 0 0 1 startangle endangle arc + closepath + savematrix setmatrix + } def + +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def +%%EndProlog + +$F2psBegin +10 setmiterlimit +n -1000 8812 m -1000 -1000 l 13612 -1000 l 13612 8812 l cp clip + 0.06000 0.06000 sc +% Polyline +7.500 slw +n 1650 3150 m 2100 2400 l gs col0 s gr +% Polyline +n 2100 2400 m 3300 2100 l gs col0 s gr +% Polyline +n 3300 2100 m 4500 2100 l gs col0 s gr +% Polyline +n 4500 2100 m 5400 3000 l gs col0 s gr +% Polyline +n 5400 3000 m 5700 4200 l gs col0 s gr +% Polyline +n 5700 4200 m 5100 5400 l gs col0 s gr +% Polyline +n 5100 5400 m 3900 5700 l gs col0 s gr +% Polyline +n 3900 5700 m 2700 5700 l gs col0 s gr +% Polyline +n 2700 5700 m 1800 5100 l gs col0 s gr +% Polyline +n 1800 5100 m 2400 3900 l gs col0 s gr +% Polyline +n 2400 3900 m 3525 3300 l gs col0 s gr +% Polyline +n 3525 3300 m 4200 4200 l gs col0 s gr +% Polyline +n 4200 4200 m 3300 4800 l gs col0 s gr +% Polyline +n 3300 4800 m 3300 3900 l gs col0 s gr +% Polyline +n 3300 3900 m 4200 4200 l gs col0 s gr +% Polyline +n 3300 3900 m 3525 3300 l gs col0 s gr +% Polyline +n 3300 4800 m 2700 5700 l gs col0 s gr +% Polyline +n 3300 4800 m 3900 5700 l gs col0 s gr +% Polyline +n 5100 5400 m 4200 4200 l gs col0 s gr +% Polyline +n 4200 4200 m 5700 4200 l gs col0 s gr +% Polyline +n 3900 5700 m 4200 4200 l gs col0 s gr +% Polyline +n 4200 4200 m 5400 3000 l gs col0 s gr +% Polyline +n 3525 3300 m 4500 2100 l gs col0 s gr +% Polyline +n 3525 3300 m 3300 2100 l gs col0 s gr +% Polyline +n 2400 3900 m 1650 3150 l gs col0 s gr +% Polyline +n 2400 3900 m 2100 2400 l gs col0 s gr +% Polyline +n 2100 2400 m 3525 3300 l gs col0 s gr +% Polyline +n 3525 3300 m 5400 3000 l gs col0 s gr +% Polyline +n 3300 3900 m 2400 3900 l gs col0 s gr +% Polyline +n 2400 3900 m 3300 4800 l gs col0 s gr +% Polyline +n 3300 4800 m 1800 5100 l gs col0 s gr +% Polyline +n 1200 4200 m 2400 3900 l gs col0 s gr +% Polyline +n 1800 5100 m 1200 4200 l gs col0 s gr +% Polyline +n 1200 4200 m 1350 3450 l gs col0 s gr +% Polyline +n 1350 3450 m 2400 3900 l gs col0 s gr +% Polyline +n 1350 3450 m 1650 3150 l gs col0 s gr +% Polyline +n 9900 3150 m 9900 2550 l cp gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 9600 2250 m 9300 2250 l cp gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 9900 3150 m 9900 2550 l 9600 2250 l 9300 2250 l 9600 1950 l 10200 2550 l + 10200 2850 l cp gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 6750 m 8100 3450 l 7050 2400 l 6300 3150 l 6300 2850 l 6900 2250 l + 6300 1650 l 6300 1350 l 7500 2550 l 8100 1950 l 7500 1350 l + 7800 1350 l 8400 1950 l 9000 1350 l 9300 1350 l 8100 2550 l + 8550 3000 l 8700 2850 l 8700 2250 l 9000 2250 l 9000 2850 l + 9600 2850 l 9600 3150 l 9000 3150 l 8850 3300 l 9300 3750 l + 10500 2550 l 9900 1950 l 9900 1350 l 10200 1350 l 10200 1950 l + 10800 1350 l 11100 1350 l 10500 1950 l 11100 2550 l 11850 1800 l + 11550 1500 l 11700 1350 l 12000 1650 l 12300 1350 l 12300 1650 l + 11700 2250 l 12300 2850 l 12300 3150 l 11700 2550 l 10500 3750 l + 10500 6750 l cp gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 4650 m 10500 4950 l 10200 4950 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 4950 m 10500 5250 l 10200 5250 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 5250 m 10500 5550 l 10200 5550 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 5550 m 10500 5850 l 10200 5850 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 5850 m 10500 6150 l 10200 6150 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 6150 m 10500 6450 l 10200 6450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 4350 m 10500 4650 l 10200 4650 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 4050 m 10500 4350 l 10200 4350 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 3750 m 10500 4050 l 10200 4050 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 3750 m 8400 4050 l 8400 3750 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 4050 m 8400 4350 l 8400 4050 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 4350 m 8400 4650 l 8400 4350 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 4650 m 8400 4950 l 8400 4650 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 4950 m 8400 5250 l 8400 4950 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 5250 m 8400 5550 l 8400 5250 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 5550 m 8400 5850 l 8400 5550 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 5850 m 8400 6150 l 8400 5850 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 6150 m 8400 6450 l 8400 6150 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 6450 m 8400 6750 l 8400 6450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8400 6450 m 8700 6750 l 8700 6450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8700 6450 m 9000 6750 l 9000 6450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 9000 6450 m 9300 6750 l 9300 6450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 9300 6450 m 9600 6750 l 9600 6450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 9600 6450 m 9900 6750 l 9900 6450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 9900 6450 m 10200 6750 l 10200 6450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8400 3750 m 10200 3750 l 10200 6450 l 8400 6450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8700 3450 m 9000 3750 l 9000 3450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8400 3450 m 8700 3750 l 8700 3450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 9600 3450 m 9900 3750 l 9900 3450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 9900 3150 m 10200 3450 l 10200 3150 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 2850 m 10500 3150 l 10500 2850 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10500 2550 m 10800 2850 l 10800 2550 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10500 2250 m 10800 2550 l 10800 2250 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 1950 m 10500 2250 l 10500 1950 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10800 2550 m 11100 2850 l 11100 2550 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10800 2850 m 11100 3150 l 11100 2850 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10500 3150 m 10800 3450 l 10800 3150 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 3450 m 10500 3750 l 10500 3450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 9900 3450 m 10200 3750 l 9900 3750 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 3150 m 10500 3450 l 10200 3450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10500 2850 m 10800 3150 l 10500 3150 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10800 2550 m 11100 2850 l 10800 2850 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10500 2250 m 10800 2550 l 10500 2550 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 1950 m 10500 2250 l 10200 2250 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 11400 2250 m 11700 2550 l 11400 2550 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 11100 2550 m 11400 2850 l 11100 2850 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8400 3150 m 8700 3450 l 8400 3450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 2850 m 8400 3150 l 8100 3150 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 2850 m 8400 3150 l 8400 2850 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 3150 m 10500 3450 l 10500 3150 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10500 2850 m 10800 3150 l 10800 2850 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 11400 2250 m 11700 2550 l 11700 2250 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10800 2850 m 11100 3150 l 10800 3150 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10500 3150 m 10800 3450 l 10500 3450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 2850 m 10500 3150 l 10200 3150 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10500 2550 m 10800 2850 l 10500 2850 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 9900 3150 m 10200 3450 l 9900 3450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 3450 m 10500 3750 l 10200 3750 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 9900 3450 m 10200 3750 l 10200 3450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 9600 3450 m 9900 3750 l 9600 3750 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10200 2850 m 9900 3150 l 10200 3150 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 3450 m 8400 3150 l 8400 3450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8400 3450 m 8700 3750 l 8400 3750 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8700 3450 m 9000 3750 l 8700 3750 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 3450 m 8400 3750 l 8400 3450 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8400 3150 m 8100 3450 l 8100 3150 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 3150 m 7500 2850 l 7500 2550 l 8100 2550 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8700 3450 m 8850 3300 l 8550 3000 l 8400 3150 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8700 2850 m 9000 3150 l 9000 2850 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 12000 1650 m 12000 1950 l 11850 1800 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 2550 m 8100 1950 l 8400 1950 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 7050 2400 m 6900 2250 l 7200 2250 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 11400 2850 m 11100 2550 l 11400 2550 l cp gs col2 1.00 shd ef gr gs col0 s gr +% Polyline +n 10500 6750 m 10500 3750 l gs col0 s gr +% Polyline +n 7050 2400 m 8100 3450 l gs col0 s gr +% Polyline +n 10500 3750 m 11700 2550 l gs col0 s gr +% Polyline +n 9300 3750 m 10500 2550 l gs col0 s gr +% Polyline +n 10500 2550 m 9900 1950 l gs col0 s gr +% Polyline +n 7500 2550 m 8100 1950 l gs col0 s gr +% Polyline +n 7500 2550 m 6900 1950 l gs col0 s gr +% Polyline +n 11100 2550 m 10500 1950 l gs col0 s gr +% Polyline +n 7050 2400 m 6300 3150 l 6300 2850 l 6900 2250 l 6300 1650 l 6300 1350 l + 6975 2025 l gs col0 s gr +% Polyline +n 8100 1950 m 7500 1350 l 7800 1350 l 8400 1950 l 9000 1350 l 9300 1350 l + 8700 1950 l gs col0 s gr +% Polyline +n 9900 1950 m 9900 1425 l 9900 1350 l 10200 1350 l 10200 1950 l 10800 1350 l + 11100 1350 l 10500 1950 l gs col0 s gr +% Polyline +n 11700 2550 m 12300 3150 l 12300 2850 l 11700 2250 l 12300 1650 l 12300 1350 l + 12000 1650 l 11700 1350 l 11550 1500 l 11850 1800 l gs col0 s gr +% Polyline +n 8700 1950 m 8100 2550 l gs col0 s gr +% Polyline +n 9300 3750 m 8850 3300 l 9000 3150 l 9600 3150 l 9600 2850 l 9000 2850 l + 9000 2250 l 8700 2250 l 8700 2850 l 8550 3000 l 8100 2550 l gs col0 s gr +% Polyline +n 11100 2550 m 11850 1800 l gs col0 s gr +% Polyline +n 6300 1650 m 6600 1650 l 6600 1950 l 6900 1950 l 6900 2550 l 6600 2550 l + 6600 2850 l 6300 2850 l gs col0 s gr +% Polyline +n 6900 2250 m 7200 2250 l 7050 2400 l 6900 2250 l cp gs col0 s gr +% Polyline +n 7200 2250 m 7200 2550 l 8100 2550 l 8100 1950 l gs col0 s gr +% Polyline +n 7800 1350 m 7800 1650 l 8100 1650 l 8100 1950 l 8700 1950 l 8700 1650 l + 9000 1650 l 9000 1350 l gs col0 s gr +% Polyline +n 7500 2550 m 7500 2850 l 8100 2550 l gs col0 s gr +% Polyline +n 9000 2250 m 8700 2550 l 9000 2550 l 8700 2850 l 9000 2850 l 9000 3150 l + 9300 2850 l 9300 3150 l 9600 2850 l gs col0 s gr +% Polyline +n 9000 3150 m 8700 2850 l 8850 3300 l 8550 3000 l 8100 3450 l 8100 2550 l gs col0 s gr +% Polyline +n 8100 6150 m 8100 3450 l gs col0 s gr +% Polyline +n 8100 3750 m 8100 3450 l 8400 3750 l 8100 3750 l cp gs col0 s gr +% Polyline +n 8100 4050 m 8100 3750 l 8400 4050 l 8100 4050 l cp gs col0 s gr +% Polyline +n 8100 4350 m 8100 4050 l 8400 4350 l 8100 4350 l cp gs col0 s gr +% Polyline +n 8100 4650 m 8100 4350 l 8400 4650 l 8100 4650 l cp gs col0 s gr +% Polyline +n 8100 4950 m 8100 4650 l 8400 4950 l 8100 4950 l cp gs col0 s gr +% Polyline +n 8100 5550 m 8100 5250 l 8400 5550 l 8100 5550 l cp gs col0 s gr +% Polyline +n 8400 3750 m 8400 3450 l 8700 3750 l 8400 3750 l cp gs col0 s gr +% Polyline +n 8400 4050 m 8400 3750 l 8700 4050 l 8400 4050 l cp gs col0 s gr +% Polyline +n 8400 4350 m 8400 4050 l 8700 4350 l 8400 4350 l cp gs col0 s gr +% Polyline +n 8400 4650 m 8400 4350 l 8700 4650 l 8400 4650 l cp gs col0 s gr +% Polyline +n 8400 4950 m 8400 4650 l 8700 4950 l 8400 4950 l cp gs col0 s gr +% Polyline +n 8400 5250 m 8400 4950 l 8700 5250 l 8400 5250 l cp gs col0 s gr +% Polyline +n 8400 5550 m 8400 5250 l 8700 5550 l 8400 5550 l cp gs col0 s gr +% Polyline +n 8700 3750 m 8700 3450 l 9000 3750 l 8700 3750 l cp gs col0 s gr +% Polyline +n 8700 4050 m 8700 3750 l 9000 4050 l 8700 4050 l cp gs col0 s gr +% Polyline +n 8700 4350 m 8700 4050 l 9000 4350 l 8700 4350 l cp gs col0 s gr +% Polyline +n 8700 4650 m 8700 4350 l 9000 4650 l 8700 4650 l cp gs col0 s gr +% Polyline +n 8700 4950 m 8700 4650 l 9000 4950 l 8700 4950 l cp gs col0 s gr +% Polyline +n 8700 5250 m 8700 4950 l 9000 5250 l 8700 5250 l cp gs col0 s gr +% Polyline +n 8700 5550 m 8700 5250 l 9000 5550 l 8700 5550 l cp gs col0 s gr +% Polyline +n 9000 3750 m 9000 3450 l 9300 3750 l 9000 3750 l cp gs col0 s gr +% Polyline +n 9000 4050 m 9000 3750 l 9300 4050 l 9000 4050 l cp gs col0 s gr +% Polyline +n 9000 4350 m 9000 4050 l 9300 4350 l 9000 4350 l cp gs col0 s gr +% Polyline +n 9000 4650 m 9000 4350 l 9300 4650 l 9000 4650 l cp gs col0 s gr +% Polyline +n 9000 4950 m 9000 4650 l 9300 4950 l 9000 4950 l cp gs col0 s gr +% Polyline +n 9000 5250 m 9000 4950 l 9300 5250 l 9000 5250 l cp gs col0 s gr +% Polyline +n 9000 5550 m 9000 5250 l 9300 5550 l 9000 5550 l cp gs col0 s gr +% Polyline +n 9300 4050 m 9300 3750 l 9600 4050 l 9300 4050 l cp gs col0 s gr +% Polyline +n 9300 4350 m 9300 4050 l 9600 4350 l 9300 4350 l cp gs col0 s gr +% Polyline +n 9300 4650 m 9300 4350 l 9600 4650 l 9300 4650 l cp gs col0 s gr +% Polyline +n 9300 4950 m 9300 4650 l 9600 4950 l 9300 4950 l cp gs col0 s gr +% Polyline +n 9300 5250 m 9300 4950 l 9600 5250 l 9300 5250 l cp gs col0 s gr +% Polyline +n 9300 5550 m 9300 5250 l 9600 5550 l 9300 5550 l cp gs col0 s gr +% Polyline +n 9600 3750 m 9600 3450 l 9900 3750 l 9600 3750 l cp gs col0 s gr +% Polyline +n 9600 4050 m 9600 3750 l 9900 4050 l 9600 4050 l cp gs col0 s gr +% Polyline +n 9600 4350 m 9600 4050 l 9900 4350 l 9600 4350 l cp gs col0 s gr +% Polyline +n 9600 4650 m 9600 4350 l 9900 4650 l 9600 4650 l cp gs col0 s gr +% Polyline +n 9600 4950 m 9600 4650 l 9900 4950 l 9600 4950 l cp gs col0 s gr +% Polyline +n 9600 5250 m 9600 4950 l 9900 5250 l 9600 5250 l cp gs col0 s gr +% Polyline +n 9600 5550 m 9600 5250 l 9900 5550 l 9600 5550 l cp gs col0 s gr +% Polyline +n 9900 3750 m 9900 3450 l 10200 3750 l 9900 3750 l cp gs col0 s gr +% Polyline +n 9900 4050 m 9900 3750 l 10200 4050 l 9900 4050 l cp gs col0 s gr +% Polyline +n 9900 4350 m 9900 4050 l 10200 4350 l 9900 4350 l cp gs col0 s gr +% Polyline +n 9900 4650 m 9900 4350 l 10200 4650 l 9900 4650 l cp gs col0 s gr +% Polyline +n 9900 4950 m 9900 4650 l 10200 4950 l 9900 4950 l cp gs col0 s gr +% Polyline +n 9900 5250 m 9900 4950 l 10200 5250 l 9900 5250 l cp gs col0 s gr +% Polyline +n 9900 5550 m 9900 5250 l 10200 5550 l 9900 5550 l cp gs col0 s gr +% Polyline +n 10200 3750 m 10200 3450 l 10500 3750 l 10200 3750 l cp gs col0 s gr +% Polyline +n 10200 4050 m 10200 3750 l 10500 4050 l 10200 4050 l cp gs col0 s gr +% Polyline +n 10200 4350 m 10200 4050 l 10500 4350 l 10200 4350 l cp gs col0 s gr +% Polyline +n 10200 4650 m 10200 4350 l 10500 4650 l 10200 4650 l cp gs col0 s gr +% Polyline +n 10200 4950 m 10200 4650 l 10500 4950 l 10200 4950 l cp gs col0 s gr +% Polyline +n 10200 5250 m 10200 4950 l 10500 5250 l 10200 5250 l cp gs col0 s gr +% Polyline +n 10200 5550 m 10200 5250 l 10500 5550 l 10200 5550 l cp gs col0 s gr +% Polyline +n 9900 3450 m 9900 3150 l 10200 3450 l 9900 3450 l cp gs col0 s gr +% Polyline +n 10200 3450 m 10200 3150 l 10500 3450 l 10200 3450 l cp gs col0 s gr +% Polyline +n 10500 3450 m 10500 3150 l 10800 3450 l 10500 3450 l cp gs col0 s gr +% Polyline +n 10200 3150 m 10200 2850 l 10500 3150 l 10200 3150 l cp gs col0 s gr +% Polyline +n 10500 3150 m 10500 2850 l 10800 3150 l 10500 3150 l cp gs col0 s gr +% Polyline +n 10800 3150 m 10800 2850 l 11100 3150 l 10800 3150 l cp gs col0 s gr +% Polyline +n 10500 2850 m 10500 2550 l 10800 2850 l 10500 2850 l cp gs col0 s gr +% Polyline +n 11100 2850 m 11100 2550 l 11400 2850 l 11100 2850 l cp gs col0 s gr +% Polyline +n 10800 2850 m 10800 2550 l 11100 2850 l 10800 2850 l cp gs col0 s gr +% Polyline +n 10500 2550 m 10500 2250 l 10800 2550 l 10500 2550 l cp gs col0 s gr +% Polyline +n 10200 2250 m 10200 1950 l 10500 2250 l 10200 2250 l cp gs col0 s gr +% Polyline +n 9900 1950 m 9900 1650 l 10200 1950 l 9900 1950 l cp gs col0 s gr +% Polyline +n 9900 1650 m 9900 1350 l 10200 1650 l 9900 1650 l cp gs col0 s gr +% Polyline +n 8400 3450 m 8400 3150 l 8700 3450 l 8400 3450 l cp gs col0 s gr +% Polyline +n 8100 3450 m 8400 3450 l gs col0 s gr +% Polyline +n 8400 3150 m 8100 3150 l gs col0 s gr +% Polyline +n 8400 3150 m 8400 2850 l 8100 2850 l 8400 3150 l cp gs col0 s gr +% Polyline +n 8100 3150 m 7500 2850 l gs col0 s gr +% Polyline +n 8100 2850 m 7500 2850 l gs col0 s gr +% Polyline +n 8850 3300 m 8700 3450 l gs col0 s gr +% Polyline +n 9000 3450 m 8700 3450 l gs col0 s gr +% Polyline +n 8400 3150 m 8850 3300 l gs col0 s gr +% Polyline +n 9300 3750 m 9600 3750 l gs col0 s gr +% Polyline +n 9600 3450 m 9900 3450 l gs col0 s gr +% Polyline +n 9900 3150 m 10200 3150 l gs col0 s gr +% Polyline +n 10200 2850 m 10500 2850 l gs col0 s gr +% Polyline +n 10500 3750 m 10500 3450 l gs col0 s gr +% Polyline +n 10800 3450 m 10800 3150 l gs col0 s gr +% Polyline +n 11100 3150 m 11100 2850 l gs col0 s gr +% Polyline +n 11100 2550 m 10800 2550 l 10800 2250 l 10500 2250 l 10500 1950 l 10200 1950 l gs col0 s gr +% Polyline +n 10500 1950 m 10500 1650 l 10800 1650 l 10800 1350 l gs col0 s gr +% Polyline +n 12300 1650 m 11700 1650 l 11700 1350 l gs col0 s gr +% Polyline +n 12000 1950 m 11850 1800 l gs col0 s gr +% Polyline +n 11700 1950 m 12000 1950 l gs col0 s gr +% Polyline +n 11700 1950 m 11700 2550 l 12000 2550 l 12000 2850 l 12300 2850 l gs col0 s gr +% Polyline +n 11700 2250 m 11400 2250 l 11400 2850 l gs col0 s gr +% Polyline +n 11100 2550 m 11700 2550 l gs col0 s gr +% Polyline +n 11700 2550 m 11400 2250 l gs col0 s gr +% Polyline +n 8400 1950 m 8100 2550 l gs col0 s gr +% Polyline +n 12000 1650 m 11850 1800 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 12000 1950 m 12000 1650 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 5250 m 8100 4950 l 8400 5250 l 8100 5250 l cp gs col0 s gr +% Polyline +n 9900 3150 m 9900 2550 l 9600 2250 l 9300 2250 l 9600 1950 l 10200 2550 l + 10200 2850 l gs col0 s gr +% Polyline +n 10200 2850 m 9900 2850 l 10200 2550 l 9900 2550 l 9900 2250 l 9600 2250 l + 9600 1950 l gs col0 s gr +% Polyline +n 8100 6750 m 10500 6750 l gs col0 s gr +% Polyline +n 8100 6450 m 8100 6150 l 8400 6450 l 8100 6450 l cp gs col0 s gr +% Polyline +n 8100 6750 m 8100 6450 l 8400 6750 l 8100 6750 l cp gs col0 s gr +% Polyline +n 8400 6450 m 8400 6150 l 8700 6450 l 8400 6450 l cp gs col0 s gr +% Polyline +n 8400 6750 m 8400 6450 l 8700 6750 l 8400 6750 l cp gs col0 s gr +% Polyline +n 8700 6450 m 8700 6150 l 9000 6450 l 8700 6450 l cp gs col0 s gr +% Polyline +n 8700 6750 m 8700 6450 l 9000 6750 l 8700 6750 l cp gs col0 s gr +% Polyline +n 9000 6450 m 9000 6150 l 9300 6450 l 9000 6450 l cp gs col0 s gr +% Polyline +n 9000 6750 m 9000 6450 l 9300 6750 l 9000 6750 l cp gs col0 s gr +% Polyline +n 9300 6450 m 9300 6150 l 9600 6450 l 9300 6450 l cp gs col0 s gr +% Polyline +n 9300 6750 m 9300 6450 l 9600 6750 l 9300 6750 l cp gs col0 s gr +% Polyline +n 9600 6450 m 9600 6150 l 9900 6450 l 9600 6450 l cp gs col0 s gr +% Polyline +n 9600 6750 m 9600 6450 l 9900 6750 l 9600 6750 l cp gs col0 s gr +% Polyline +n 9900 6450 m 9900 6150 l 10200 6450 l 9900 6450 l cp gs col0 s gr +% Polyline +n 9900 6750 m 9900 6450 l 10200 6750 l 9900 6750 l cp gs col0 s gr +% Polyline +n 10200 6450 m 10200 6150 l 10500 6450 l 10200 6450 l cp gs col0 s gr +% Polyline +n 10200 6750 m 10200 6450 l 10500 6750 l 10200 6750 l cp gs col0 s gr +% Polyline +n 8100 6150 m 10500 6150 l gs col0 s gr +% Polyline +n 8100 5850 m 8100 5550 l 8400 5850 l 8100 5850 l cp gs col0 s gr +% Polyline +n 8100 6150 m 8100 5850 l 8400 6150 l 8100 6150 l cp gs col0 s gr +% Polyline +n 8400 5850 m 8400 5550 l 8700 5850 l 8400 5850 l cp gs col0 s gr +% Polyline +n 8400 6150 m 8400 5850 l 8700 6150 l 8400 6150 l cp gs col0 s gr +% Polyline +n 8700 5850 m 8700 5550 l 9000 5850 l 8700 5850 l cp gs col0 s gr +% Polyline +n 8700 6150 m 8700 5850 l 9000 6150 l 8700 6150 l cp gs col0 s gr +% Polyline +n 9000 5850 m 9000 5550 l 9300 5850 l 9000 5850 l cp gs col0 s gr +% Polyline +n 9000 6150 m 9000 5850 l 9300 6150 l 9000 6150 l cp gs col0 s gr +% Polyline +n 9300 5850 m 9300 5550 l 9600 5850 l 9300 5850 l cp gs col0 s gr +% Polyline +n 9300 6150 m 9300 5850 l 9600 6150 l 9300 6150 l cp gs col0 s gr +% Polyline +n 9600 5850 m 9600 5550 l 9900 5850 l 9600 5850 l cp gs col0 s gr +% Polyline +n 9600 6150 m 9600 5850 l 9900 6150 l 9600 6150 l cp gs col0 s gr +% Polyline +n 9900 5850 m 9900 5550 l 10200 5850 l 9900 5850 l cp gs col0 s gr +% Polyline +n 9900 6150 m 9900 5850 l 10200 6150 l 9900 6150 l cp gs col0 s gr +% Polyline +n 10200 5850 m 10200 5550 l 10500 5850 l 10200 5850 l cp gs col0 s gr +% Polyline +n 10200 6150 m 10200 5850 l 10500 6150 l 10200 6150 l cp gs col0 s gr +% Polyline +n 8100 2550 m 7800 2250 l gs col0 s gr +% Polyline +n 900 900 m 6000 900 l 6000 7800 l 900 7800 l cp gs col0 s gr +% Polyline +n 6000 900 m 12600 900 l 12600 7800 l 6000 7800 l cp gs col0 s gr +/Times-Roman ff 390.00 scf sf +3300 7500 m +gs 1 -1 sc (\(a\)) col0 sh gr +/Times-Roman ff 390.00 scf sf +9150 7500 m +gs 1 -1 sc (\(b\)) col0 sh gr +% Polyline +60.000 slw +n 5100 5400 m 4200 4200 l 3300 4800 l 3300 3900 l 2400 3900 l 2100 2400 l gs col0 s gr +% Polyline +45.000 slw + [112] 0 sd +n 7200 4050 m 11400 4050 l gs col0 s gr [] 0 sd +% Polyline +n 9600 1200 m 9600 1650 l 9150 2100 l 9150 2400 l 9750 2700 l 9750 3150 l + 9300 3600 l 9300 4050 l 9600 4350 l 9600 5250 l 9300 5250 l + 9300 6750 l 9300 7050 l gs col0 s gr +7.500 slw +% Ellipse +n 4500 5400 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 4500 5100 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 4200 5100 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 3750 4950 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 4800 4500 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 5100 3600 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 4200 3600 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 4500 2400 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 3300 5400 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 2700 3300 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 2400 4800 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 3600 4200 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 5100 4800 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 4350 4650 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 3900 4575 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 4800 4725 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +$F2psEnd +rs + +%%EndDocument + @endspecial 0 3202 a Fx(Figure)42 b(3)p FK(:)103 b Fv(A)33 +b(computational)e(mesh)i(f)m(or)g(a)g(par)t(ticle-in-cells)i(sim)o +(ulation)d(\(a\))i(and)e(a)h(computational)e(mesh)i(f)m(or)g(a)g +(contact-impact)g(sim)o(ulation)g(\(b\).)47 b(The)32 +b(par)t(ticle-in-cells)j(mesh)0 3401 y(is)i(par)t(titioned)e(so)h(that) +g(both)g(the)f(n)o(umber)g(of)h(mesh)f(elements)h(and)e(the)i(n)o +(umber)f(of)h(par)t(ticles)h(are)f(balanced)e(across)j(the)f +(sub-domains)o(.)53 b(T)-13 b(w)o(o)35 b(par)t(titionings)h(are)g(sho)o +(wn)e(f)m(or)j(the)0 3600 y(contact-impact)28 b(mesh.)36 +b(The)27 b(dashed)f(par)t(titioning)h(balances)g(only)h(the)f(n)o +(umber)g(of)h(mesh)f(elements)o(.)35 b(The)27 b(solid)h(par)t +(titioning)f(balances)g(both)g(the)g(n)o(umber)f(of)i(mesh)f(elements)g +(and)0 3799 y(the)j(n)o(umber)e(of)i(surf)m(ace)h(\(lightly)g(shaded\)) +e(elements)g(across)i(the)f(sub-domains)o(.)0 4160 y +Ft(3.5)199 b(P)-6 b(ar)t(titioning)56 b(f)l(or)f(Multi-phase)g(and)g +(Multi-ph)l(ysics)g(Computations)0 4479 y FK(The)h(traditional)g(graph) +g(partitioning)h(problem)f(formulation)h(is)f(limited)g(in)g(the)g +(types)f(of)h(applications)g(that)f(it)i(can)e(ef)l(fecti)l(v)n(ely)0 +4698 y(model)33 b(because)f(it)h(speci\002es)g(that)g(only)g(a)g +(single)g(quantity)g(be)g(load)g(balanced.)48 b(Man)n(y)32 +b(important)i(types)e(of)i(multi-phase)f(and)g(multi-)0 +4917 y(ph)o(ysics)e(computations)g(require)h(that)g(multiple)g +(quantities)g(be)f(load)h(balanced)e(simultaneously)-11 +b(.)48 b(This)32 b(is)f(because)f(synchronization)0 5136 +y(steps)46 b(e)n(xist)h(between)f(the)h(dif)l(ferent)h(phases)e(of)i +(the)f(computations,)h(and)f(so,)h(each)e(phase)g(must)h(be)g(indi)l +(vidually)h(load)f(balanced.)0 5355 y(That)i(is,)g(it)g(is)f(not)g(suf) +l(\002cient)h(to)f(simply)h(sum)f(up)g(the)h(relati)l(v)n(e)e(times)h +(required)h(for)g(each)f(phase)f(and)h(to)h(compute)f(a)g(partitioning) +0 5575 y(based)38 b(on)i(this)f(sum.)50 b(Doing)40 b(so)f(may)g(lead)g +(to)h(some)f(processors)f(ha)m(ving)h(too)h(much)f(w)n(ork)h(during)g +(one)f(phase)g(of)g(the)h(computation)0 5794 y(\(and)j(so,)f(these)g +(may)h(still)f(be)h(w)n(orking)g(after)g(other)g(processors)f(are)g +(idle\),)h(and)g(not)g(enough)f(w)n(ork)h(during)h(another)-9 +b(.)54 b(Instead,)42 b(it)h(is)0 6013 y(critical)f(that)f(e)l(v)n(ery)g +(processor)g(ha)m(v)n(e)f(an)h(equal)g(amount)h(of)g(w)n(ork)g(from)g +(each)f(phase)f(of)i(the)g(computation.)199 6232 y(T)-13 +b(w)n(o)47 b(e)n(xamples)e(are)h(particle-in-cells)h([17])g(and)f +(contact-impact)g(simulations)g([3)q(].)65 b(Figure)47 +b(3)g(illustrates)f(the)g(characteristics)0 6451 y(of)h(partitionings)h +(that)f(are)g(needed)g(for)h(these)e(simulations.)68 +b(Figure)47 b(3\(a\))h(sho)l(ws)e(a)h(mesh)g(for)h(a)e +(particles-in-cells)h(computation.)0 6670 y(Assuming)d(that)g(a)f +(synchronization)h(separates)f(the)h(mesh-based)f(computation)h(from)h +(the)f(particle)g(computation,)g(a)g(partitioning)0 6890 +y(is)f(required)h(that)f(balances)f(both)i(the)f(number)h(of)g(mesh)f +(elements)f(and)i(the)f(number)h(of)f(particles)g(across)g(the)g +(sub-domains.)56 b(Fig-)0 7109 y(ure)41 b(3\(b\))h(sho)l(ws)d(a)i(mesh) +g(for)g(a)g(contact-impact)g(simulation.)51 b(During)41 +b(the)g(contact)f(detection)h(phase,)f(computation)h(is)f(performed)0 +7328 y(only)k(on)h(the)f(surf)n(ace)f(\(i.e.,)h(lightly)h(shaded\))e +(elements,)h(while)g(during)h(the)f(impact)g(phase,)f(computation)i(is) +f(performed)g(on)g(all)h(of)0 7547 y(the)50 b(elements.)78 +b(Therefore,)53 b(in)e(order)g(to)f(ensure)g(that)h(both)g(phases)e +(are)h(load)h(balanced,)g(a)g(partitioning)g(must)g(balance)e(both)i +(the)0 7766 y(total)45 b(number)f(of)h(mesh)f(elements)f(and)h(the)g +(number)h(of)g(surf)n(ace)f(elements)f(across)h(the)g(sub-domains.)59 +b(The)44 b(solid)h(partitioning)g(in)0 7986 y(Figure)k(3\(b\))f(does)g +(this.)70 b(The)49 b(dashed)e(partitioning)i(is)f(similar)g(to)g(what)g +(a)g(traditional)h(graph)f(partitioner)h(might)f(compute.)71 +b(This)0 8205 y(partitioning)42 b(balances)f(only)g(the)h(total)g +(number)f(of)h(mesh)f(elements.)50 b(The)42 b(surf)n(ace)f(elements)g +(are)g(imbalanced)g(by)h(o)n(v)n(er)e(50\045.)199 8424 +y(A)65 b(ne)l(w)f(formulation)i(of)f(the)g(graph)g(partitioning)h +(problem)f(is)f(presented)g(in)h([6)q(])g(that)g(is)f(able)h(to)g +(model)g(the)f(problem)i(of)0 8643 y(balancing)43 b(multiple)h +(computational)g(phases)e(simultaneously)-11 b(,)43 b(while)g(also)g +(minimizing)h(the)g(inter)m(-processor)f(communications.)0 +8862 y(In)57 b(this)g(formulation,)k(a)c(weight)g(v)n(ector)f(of)h +(size)f Fy(m)67 b FK(is)56 b(assigned)g(to)h(each)f(v)n(erte)n(x)g(of)h +(the)g(graph.)97 b(The)57 b Fs(multi-constr)n(aint)g(gr)n(aph)0 +9081 y(partitioning)73 b(pr)-7 b(oblem)71 b FK(then)h(is)g(to)h +(compute)f(a)g(partitioning)h(such)e(that)i(the)f(edge-cut)g(is)g +(minimized)g(and)g(that)h(e)l(v)n(ery)e(sub-)0 9301 y(domain)49 +b(has)f(approximately)h(the)g(same)f(amount)h(of)g(each)f(of)h(the)g(v) +n(erte)n(x)e(weights.)73 b(The)49 b(routines)g FA(P)-7 +b(arMETIS)p 6742 9301 50 7 v 61 w(V3)p 7006 9301 V 59 +w(P)g(ar)7 b(tKw)n(a)-5 b(y)p FK(,)0 9520 y FA(P)e(arMETIS)p +768 9520 V 61 w(V3)p 1032 9520 V 60 w(P)g(ar)7 b(tGeomKw)n(a)-5 +b(y)p FK(,)40 b FA(P)-7 b(arMETIS)p 3086 9520 V 61 w(V3)p +3350 9520 V 60 w(Re\002neKw)n(a)i(y)p FK(,)40 b(and)f +FA(P)-7 b(arMETIS)p 5407 9520 V 61 w(V3)p 5671 9520 V +60 w(Adaptiv)l(eRepar)7 b(t)41 b FK(are)e(all)h(able)f(to)0 +9739 y(compute)i(partitionings)h(that)g(satisfy)f(multiple)h(balance)f +(constraints.)199 9958 y(Figure)k(4)f(gi)l(v)n(es)e(the)i(dual)g(graph) +g(for)g(the)g(particles-in-cells)g(mesh)f(sho)l(wn)g(in)i(Figure)f(3.) +58 b(Each)44 b(v)n(erte)n(x)f(has)g(tw)n(o)h(weights)g(here.)0 +10177 y(The)33 b(\002rst)g(represents)f(the)g(w)n(ork)i(associated)d +(with)i(the)f(mesh-based)g(computation)h(for)g(the)g(corresponding)f +(element.)48 b(\(These)33 b(are)f(all)0 10396 y(ones)i(because)g(we)g +(assume)g(in)h(this)f(case)g(that)h(all)g(of)g(the)g(elements)f(ha)m(v) +n(e)f(the)i(same)f(amount)h(of)g(mesh-based)f(w)n(ork)i(associated)d +(with)0 10616 y(them.\))50 b(The)39 b(second)f(weight)g(represents)g +(the)h(w)n(ork)g(associated)e(with)i(the)f(particle-based)g +(computation.)50 b(This)39 b(v)l(alue)f(is)h(estimated)3858 +11298 y(9)p eop +%%Page: 10 10 +10 9 bop 900 2536 a @beginspecial 0 @llx 0 @lly 646 @urx +273 @ury 3600 @rwi @setspecial +%%BeginDocument: figures/particle.eps +%!PS-Adobe-2.0 EPSF-2.0 +%%Title: particle.eps +%%Creator: fig2dev Version 3.2 Patchlevel 3b +%%CreationDate: Wed Jan 23 20:29:48 2002 +%%For: kirk@lnx08 (Kirk Schloegel) +%%BoundingBox: 0 0 646 273 +%%Magnification: 1.0000 +%%EndComments +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +newpath 0 273 moveto 0 0 lineto 646 0 lineto 646 273 lineto closepath clip newpath +-62.0 369.0 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def + /DrawEllipse { + /endangle exch def + /startangle exch def + /yrad exch def + /xrad exch def + /y exch def + /x exch def + /savematrix mtrx currentmatrix def + x y tr xrad yrad sc 0 0 1 startangle endangle arc + closepath + savematrix setmatrix + } def + +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +%%Page: 1 1 +10 setmiterlimit + 0.06000 0.06000 sc +% +% Fig objects follow +% +% Polyline +7.500 slw +n 1500 3300 m + 1950 2550 l gs col0 s gr +% Polyline +n 1950 2550 m + 3150 2250 l gs col0 s gr +% Polyline +n 3150 2250 m + 4350 2250 l gs col0 s gr +% Polyline +n 4350 2250 m + 5250 3150 l gs col0 s gr +% Polyline +n 5250 3150 m + 5550 4350 l gs col0 s gr +% Polyline +n 5550 4350 m + 4950 5550 l gs col0 s gr +% Polyline +n 4950 5550 m + 3750 5850 l gs col0 s gr +% Polyline +n 3750 5850 m + 2550 5850 l gs col0 s gr +% Polyline +n 2550 5850 m + 1650 5250 l gs col0 s gr +% Polyline +n 1650 5250 m + 2250 4050 l gs col0 s gr +% Polyline +n 2250 4050 m + 3375 3450 l gs col0 s gr +% Polyline +n 3375 3450 m + 4050 4350 l gs col0 s gr +% Polyline +n 4050 4350 m + 3150 4950 l gs col0 s gr +% Polyline +n 3150 4950 m + 3150 4050 l gs col0 s gr +% Polyline +n 3150 4050 m + 4050 4350 l gs col0 s gr +% Polyline +n 3150 4050 m + 3375 3450 l gs col0 s gr +% Polyline +n 3150 4950 m + 2550 5850 l gs col0 s gr +% Polyline +n 3150 4950 m + 3750 5850 l gs col0 s gr +% Polyline +n 4950 5550 m + 4050 4350 l gs col0 s gr +% Polyline +n 4050 4350 m + 5550 4350 l gs col0 s gr +% Polyline +n 3750 5850 m + 4050 4350 l gs col0 s gr +% Polyline +n 4050 4350 m + 5250 3150 l gs col0 s gr +% Polyline +n 3375 3450 m + 4350 2250 l gs col0 s gr +% Polyline +n 3375 3450 m + 3150 2250 l gs col0 s gr +% Polyline +n 2250 4050 m + 1500 3300 l gs col0 s gr +% Polyline +n 2250 4050 m + 1950 2550 l gs col0 s gr +% Polyline +n 1950 2550 m + 3375 3450 l gs col0 s gr +% Polyline +n 3375 3450 m + 5250 3150 l gs col0 s gr +% Polyline +n 3150 4050 m + 2250 4050 l gs col0 s gr +% Polyline +n 2250 4050 m + 3150 4950 l gs col0 s gr +% Polyline +n 3150 4950 m + 1650 5250 l gs col0 s gr +% Polyline +n 1050 4350 m + 2250 4050 l gs col0 s gr +% Polyline +n 1650 5250 m + 1050 4350 l gs col0 s gr +% Polyline +n 1050 4350 m + 1200 3600 l gs col0 s gr +% Polyline +n 1200 3600 m + 2250 4050 l gs col0 s gr +% Polyline +n 1200 3600 m + 1500 3300 l gs col0 s gr +% Polyline +60.000 slw +n 4950 5550 m 4050 4350 l 3150 4950 l 3150 4050 l 2250 4050 l + 1950 2550 l gs col0 s gr +7.500 slw +% Ellipse +n 4350 5550 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 4350 5250 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 4050 5250 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 3600 5100 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 4650 4650 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 4950 3750 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 4050 3750 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 4350 2550 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 3150 5550 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 2550 3450 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 2250 4950 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 3450 4350 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 4950 4950 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 4200 4800 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 3750 4725 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 4650 4875 75 75 0 360 DrawEllipse gs col4 1.00 shd ef gr gs col0 s gr + +% Polyline +n 7950 3975 m + 7875 3225 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 7950 3975 m + 8100 4725 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 4725 m + 8400 5325 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 8400 5325 m + 8925 5625 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 8925 5625 m + 9525 5925 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 7875 3225 m + 8175 2775 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 9300 3375 m + 9525 2325 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 9975 3600 m + 11475 3900 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 9900 4350 m + 9525 5925 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 8175 2775 m + 8775 2325 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 8775 2325 m + 9525 2325 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 9525 2325 m + 10050 2325 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 10050 2325 m + 10950 2700 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 10950 2700 m + 11325 3300 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 11325 3300 m + 11475 3900 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 11475 3900 m + 11400 4725 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 11400 4725 m + 11025 5475 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 11025 5475 m + 10350 5850 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 10350 5850 m + 9525 5925 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 9000 4125 m + 9300 3375 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 9000 4125 m + 9900 4350 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 9900 4350 m + 9975 3600 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 9975 3600 m + 9300 3375 l gs col6 1.00 shd ef gr gs col0 s gr +% Polyline +n 8100 4725 m + 9000 4125 l gs col6 1.00 shd ef gr gs col0 s gr +/Times-Roman ff 180.00 scf sf +10275 2325 m +gs 1 -1 sc (\(1, 0\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +8175 4050 m +gs 1 -1 sc (\(1, 0\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +10050 3975 m +gs 1 -1 sc (\(1, 0\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +8250 3075 m +gs 1 -1 sc (\(1, 0\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +8625 2625 m +gs 1 -1 sc (\(1, 0\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +10425 2850 m +gs 1 -1 sc (\(1, 0\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +9300 3750 m +gs 1 -1 sc (\(1, 0\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +8625 5250 m +gs 1 -1 sc (\(1, 0\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +8025 3450 m +gs 1 -1 sc (\(1, 0\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +9525 2625 m +gs 1 -1 sc (\(1, 1\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +10725 3375 m +gs 1 -1 sc (\(1, 1\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +10950 4125 m +gs 1 -1 sc (\(1, 1\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +10800 4875 m +gs 1 -1 sc (\(1, 1\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +10500 5400 m +gs 1 -1 sc (\(1, 3\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +10050 5625 m +gs 1 -1 sc (\(1, 4\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +9975 4650 m +gs 1 -1 sc (\(1, 1\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +9075 5475 m +gs 1 -1 sc (\(1, 1\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +8325 4800 m +gs 1 -1 sc (\(1, 1\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +9675 6150 m +gs 1 -1 sc (\(1, 2\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +8925 4500 m +gs 1 -1 sc (\(1, 0\)) col0 sh gr +/Times-Roman ff 180.00 scf sf +1425 4050 m +gs 1 -1 sc (1) col0 sh gr +/Times-Roman ff 180.00 scf sf +3600 5475 m +gs 1 -1 sc (12) col0 sh gr +/Times-Roman ff 180.00 scf sf +3300 4650 m +gs 1 -1 sc (20) col0 sh gr +/Times-Roman ff 180.00 scf sf +1500 3600 m +gs 1 -1 sc (2) col0 sh gr +/Times-Roman ff 180.00 scf sf +1800 3300 m +gs 1 -1 sc (3) col0 sh gr +/Times-Roman ff 180.00 scf sf +2250 3075 m +gs 1 -1 sc (4) col0 sh gr +/Times-Roman ff 180.00 scf sf +2850 2700 m +gs 1 -1 sc (5) col0 sh gr +/Times-Roman ff 180.00 scf sf +3600 2550 m +gs 1 -1 sc (6) col0 sh gr +/Times-Roman ff 180.00 scf sf +4500 2850 m +gs 1 -1 sc (7) col0 sh gr +/Times-Roman ff 180.00 scf sf +4500 3525 m +gs 1 -1 sc (8) col0 sh gr +/Times-Roman ff 180.00 scf sf +5100 3600 m +gs 1 -1 sc (9) col0 sh gr +/Times-Roman ff 180.00 scf sf +5025 4650 m +gs 1 -1 sc (10) col0 sh gr +/Times-Roman ff 180.00 scf sf +3975 5625 m +gs 1 -1 sc (11) col0 sh gr +/Times-Roman ff 180.00 scf sf +3075 5400 m +gs 1 -1 sc (13) col0 sh gr +/Times-Roman ff 180.00 scf sf +2625 5325 m +gs 1 -1 sc (14) col0 sh gr +/Times-Roman ff 180.00 scf sf +2850 4350 m +gs 1 -1 sc (17) col0 sh gr +/Times-Roman ff 180.00 scf sf +2925 3900 m +gs 1 -1 sc (18) col0 sh gr +/Times-Roman ff 180.00 scf sf +3375 3900 m +gs 1 -1 sc (19) col0 sh gr +/Times-Roman ff 180.00 scf sf +2250 4500 m +gs 1 -1 sc (15) col0 sh gr +/Times-Roman ff 180.00 scf sf +1725 4425 m +gs 1 -1 sc (16) col0 sh gr +% Ellipse +n 8775 2325 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 9525 2325 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 10050 2325 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 10950 2700 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 11475 3900 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 8100 4725 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 7950 3975 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 7875 3225 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 8175 2775 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 9000 4125 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 9300 3375 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 9975 3600 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 9900 4350 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 11400 4725 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 11025 5475 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 10350 5850 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 9525 5925 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 8925 5625 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 8400 5325 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +% Ellipse +n 11305 3347 106 106 0 360 DrawEllipse gs col6 1.00 shd ef gr gs col0 s gr + +/Times-Roman ff 180.00 scf sf +10500 6150 m +gs 1 -1 sc (11) col0 sh gr +/Times-Roman ff 180.00 scf sf +8700 6000 m +gs 1 -1 sc (13) col0 sh gr +/Times-Roman ff 180.00 scf sf +7575 4050 m +gs 1 -1 sc (16) col0 sh gr +/Times-Roman ff 180.00 scf sf +7650 3225 m +gs 1 -1 sc (1) col0 sh gr +/Times-Roman ff 180.00 scf sf +8025 2625 m +gs 1 -1 sc (2) col0 sh gr +/Times-Roman ff 180.00 scf sf +8550 2175 m +gs 1 -1 sc (3) col0 sh gr +/Times-Roman ff 180.00 scf sf +9450 2100 m +gs 1 -1 sc (4) col0 sh gr +/Times-Roman ff 180.00 scf sf +10050 2100 m +gs 1 -1 sc (5) col0 sh gr +/Times-Roman ff 180.00 scf sf +10950 2475 m +gs 1 -1 sc (6) col0 sh gr +/Times-Roman ff 180.00 scf sf +11550 3225 m +gs 1 -1 sc (7) col0 sh gr +/Times-Roman ff 180.00 scf sf +11700 3825 m +gs 1 -1 sc (8) col0 sh gr +/Times-Roman ff 180.00 scf sf +11625 4725 m +gs 1 -1 sc (9) col0 sh gr +/Times-Roman ff 180.00 scf sf +11250 5550 m +gs 1 -1 sc (10) col0 sh gr +/Times-Roman ff 180.00 scf sf +9675 4200 m +gs 1 -1 sc (20) col0 sh gr +/Times-Roman ff 180.00 scf sf +9975 3375 m +gs 1 -1 sc (19) col0 sh gr +/Times-Roman ff 180.00 scf sf +9000 3225 m +gs 1 -1 sc (18) col0 sh gr +/Times-Roman ff 180.00 scf sf +8175 5625 m +gs 1 -1 sc (14) col0 sh gr +/Times-Roman ff 180.00 scf sf +7725 4950 m +gs 1 -1 sc (15) col0 sh gr +/Times-Roman ff 180.00 scf sf +9225 6150 m +gs 1 -1 sc (12) col0 sh gr +/Times-Roman ff 180.00 scf sf +8775 3975 m +gs 1 -1 sc (17) col0 sh gr +% Polyline +2 slj +45.000 slw +n 9000 1650 m 9001 1653 l 9002 1658 l 9005 1669 l 9009 1685 l 9014 1708 l + 9021 1737 l 9029 1772 l 9039 1813 l 9050 1858 l 9061 1907 l + 9073 1959 l 9084 2012 l 9096 2064 l 9107 2117 l 9117 2167 l + 9127 2216 l 9136 2262 l 9144 2306 l 9150 2347 l 9156 2385 l + 9161 2421 l 9164 2454 l 9167 2486 l 9169 2515 l 9169 2542 l + 9169 2568 l 9168 2592 l 9166 2615 l 9163 2638 l 9157 2666 l + 9150 2694 l 9142 2721 l 9132 2747 l 9121 2772 l 9108 2797 l + 9094 2821 l 9080 2844 l 9064 2866 l 9048 2888 l 9031 2909 l + 9013 2930 l 8996 2950 l 8979 2968 l 8962 2987 l 8945 3004 l + 8929 3021 l 8914 3037 l 8900 3053 l 8886 3069 l 8874 3084 l + 8863 3100 l 8853 3114 l 8844 3129 l 8836 3144 l 8829 3160 l + 8822 3176 l 8817 3193 l 8812 3210 l 8808 3228 l 8806 3247 l + 8804 3265 l 8804 3284 l 8804 3303 l 8806 3323 l 8809 3342 l + 8814 3362 l 8819 3381 l 8825 3400 l 8833 3419 l 8842 3437 l + 8851 3455 l 8862 3473 l 8874 3490 l 8886 3508 l 8900 3525 l + 8914 3541 l 8928 3557 l 8944 3573 l 8961 3590 l 8979 3606 l + 8998 3624 l 9017 3641 l 9038 3659 l 9059 3678 l 9081 3697 l + 9103 3716 l 9126 3735 l 9148 3755 l 9171 3775 l 9193 3795 l + 9215 3815 l 9237 3835 l 9257 3855 l 9277 3875 l 9296 3895 l + 9314 3915 l 9331 3934 l 9347 3954 l 9361 3973 l 9375 3993 l + 9388 4013 l 9400 4034 l 9411 4056 l 9421 4079 l 9431 4103 l + 9439 4127 l 9447 4152 l 9455 4178 l 9462 4204 l 9469 4232 l + 9475 4259 l 9481 4288 l 9488 4316 l 9494 4345 l 9500 4373 l + 9506 4402 l 9513 4430 l 9520 4457 l 9528 4485 l 9536 4511 l + 9544 4538 l 9554 4563 l 9564 4588 l 9575 4613 l 9588 4638 l + 9598 4657 l 9610 4676 l 9622 4696 l 9636 4716 l 9650 4736 l + 9666 4756 l 9682 4777 l 9700 4798 l 9718 4819 l 9738 4841 l + 9759 4862 l 9780 4884 l 9802 4907 l 9825 4929 l 9849 4952 l + 9874 4974 l 9899 4997 l 9924 5019 l 9950 5042 l 9976 5064 l + 10002 5086 l 10028 5108 l 10054 5129 l 10081 5151 l 10107 5172 l + 10133 5193 l 10159 5213 l 10185 5234 l 10211 5254 l 10238 5275 l + 10261 5293 l 10284 5312 l 10308 5330 l 10333 5350 l 10358 5369 l + 10384 5389 l 10411 5410 l 10439 5432 l 10468 5455 l 10499 5478 l + 10531 5503 l 10565 5529 l 10600 5557 l 10637 5585 l 10676 5615 l + 10716 5646 l 10757 5677 l 10798 5710 l 10841 5742 l 10883 5775 l + 10924 5807 l 10964 5838 l 11002 5867 l 11037 5894 l 11069 5918 l + 11097 5940 l 11120 5958 l 11139 5972 l 11153 5983 l 11163 5991 l + 11170 5996 l 11173 5999 l + 11175 6000 l gs col0 s gr +% Polyline +0 slj +7.500 slw +n 5850 4275 m 6750 4275 l 6750 4575 l 7350 4125 l 6750 3675 l 6750 3975 l + 5850 3975 l + cp gs col24 1.00 shd ef gr gs col0 s gr +$F2psEnd +rs + +%%EndDocument + @endspecial 0 2901 a Fx(Figure)44 b(4)p FK(:)114 b Fv(A)35 +b(dual)f(g)o(r)o(aph)g(with)h(v)m(er)t(te)m(x)i(w)o(eight)d(v)m(ectors) +j(of)f(siz)o(e)f(tw)o(o)g(is)h(constr)r(ucted)f(from)h(the)f(par)t +(ticle-in-cells)i(mesh)d(from)i(Figure)e(3.)53 b(A)35 +b(m)o(ulti-constr)o(aint)h(par)t(titioning)e(has)0 3100 +y(been)29 b(computed)f(f)m(or)i(this)h(g)o(r)o(aph,)e(and)g(this)i(par) +t(titioning)f(has)g(been)e(projected)h(bac)n(k)i(to)f(the)g(mesh.)0 +3461 y FK(by)39 b(the)f(number)h(of)g(particles)g(that)f(f)n(all)i +(within)f(each)f(element.)49 b(A)39 b(multi-constraint)g(partitioning)h +(is)f(sho)l(wn)f(that)g(balances)g(both)h(of)0 3680 y(these)i(weights.) +199 3899 y(A)46 b(related)g(graph)g(partitioning)h(problem)g +(formulation)g(that)f(is)g(discussed)f(in)h([13],)h(allo)l(ws)f(edges)f +(to)h(ha)m(v)n(e)f(multiple)i(weights.)0 4118 y(W)-13 +b(e)55 b(refer)h(to)f(this)h(as)f(the)g Fs(multi-objective)h(gr)n(aph)e +(partitioning)i(pr)-7 b(oblem)p FK(.)92 b(Multi-objecti)l(v)n(e)55 +b(graph)h(partitioning)g(is)g(applicable)0 4337 y(for)g +(tightly-coupled)g(multi-ph)o(ysics)g(computations)f(in)-7 +b(v)m(olving)56 b(multiple,)j(spatially-o)n(v)n(erlapping)c(meshes.)92 +b(Later)55 b(v)n(ersions)g(of)4 4557 y FA(P)-10 b FG(A)8 +b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)48 b FK(will)42 +b(support)g(multiple)g(edge)f(weights.)0 5011 y Ft(3.6)199 +b(P)-6 b(ar)t(titioning)56 b(f)l(or)f(Heter)l(og)r(eneous)d(Computing)j +(Ar)l(c)n(hitectures)0 5330 y FK(Comple)n(x,)78 b(heterogeneous)71 +b(computing)h(platforms,)79 b(such)71 b(as)g(groups)h(of)g +(tightly-coupled)h(shared-memory)e(nodes)g(that)h(are)0 +5549 y(loosely)48 b(connected)f(via)h(high)h(bandwidth)f(and)g(high)g +(latenc)n(y)f(interconnection)h(netw)n(orks,)i(and/or)e(processing)g +(nodes)f(that)h(ha)m(v)n(e)0 5769 y(comple)n(x)53 b(memory)h +(hierarchies,)i(are)d(becoming)h(more)g(common,)i(as)d(the)n(y)g +(display)h(competiti)l(v)n(e)f(cost-to-performance)h(ratios.)0 +5988 y(The)49 b(same)g(is)f(true)i(of)f(platforms)g(that)h(are)e +(geographically)h(distrib)m(uted.)74 b(Most)48 b(e)n(xisting)h +(parallel)g(simulation)g(codes)f(can)h(easily)0 6207 +y(be)58 b(ported)g(to)g(a)f(wide)h(range)g(of)g(parallel)g +(architectures)f(as)g(the)n(y)g(emplo)n(y)h(a)g(standard)f(messaging)g +(layer)h(such)f(as)g(MPI.)h(Ho)l(w-)0 6426 y(e)l(v)n(er)-7 +b(,)47 b(comple)n(x)f(and)h(heterogeneous)f(architectures)g(present)h +(ne)l(w)f(challenges)g(to)h(the)f(scalable)g(e)n(x)n(ecution)g(of)h +(such)f(codes,)h(since)0 6645 y(man)n(y)h(of)h(the)g(basic)e(parallel)i +(algorithm)g(design)g(assumptions)e(are)i(no)f(longer)h(v)l(alid.)72 +b(One)49 b(w)n(ay)f(of)h(alle)l(viating)g(this)f(problem)h(is)0 +6865 y(to)56 b(de)l(v)n(elop)e(a)i(ne)l(w)f(class)f(of)i +(architecture-a)n(w)n(are)f(graph)g(partitioning)i(algorithms)f(that)f +(optimally)i(decompose)d(computations)0 7084 y(gi)l(v)n(en)43 +b(the)h(architecture)f(of)h(the)g(parallel)f(platform.)58 +b(Ideally)-11 b(,)45 b(this)e(approach)g(will)h(alle)l(viate)f(the)h +(need)f(for)h(major)h(restructuring)f(of)0 7303 y(scienti\002c)d +(codes.)199 7522 y(W)-13 b(e)49 b(ha)m(v)n(e)f(tak)n(en)i(the)f +(\002rst)h(steps)f(to)l(w)n(ard)h(de)l(v)n(eloping)f(architecture-a)n +(w)n(are)g(graph-partitioning)h(algorithms.)76 b(These)49 +b(are)g(able)0 7741 y(to)71 b(compute)h(partitionings)f(that)h(allo)l +(w)f(computations)g(to)g(achie)l(v)n(e)f(the)h(highest)g(le)l(v)n(els)f +(of)i(performance)f(re)n(g)o(ardless)f(of)i(the)0 7960 +y(computing)67 b(platform.)127 b(Speci\002cally)-11 b(,)73 +b(we)66 b(ha)m(v)n(e)f(enabled)h FA(P)-7 b(arMETIS)p +4390 7960 50 7 v 61 w(V3)p 4654 7960 V 60 w(P)g(ar)7 +b(tKw)n(a)-5 b(y)p FK(,)73 b FA(P)-7 b(arMETIS)p 6290 +7960 V 60 w(V3)p 6553 7960 V 60 w(P)g(ar)7 b(tGeomKw)n(a)-5 +b(y)p FK(,)0 8180 y FA(P)e(arMETIS)p 768 8180 V 61 w(V3)p +1032 8180 V 60 w(P)g(ar)7 b(tMeshKw)n(a)-5 b(y)p FK(,)37 +b FA(P)-7 b(arMETIS)p 3037 8180 V 60 w(V3)p 3300 8180 +V 60 w(Re\002neKw)n(a)i(y)p FK(,)36 b(and)f FA(P)-7 b(arMETIS)p +5349 8180 V 61 w(V3)p 5613 8180 V 60 w(Adaptiv)l(eRepar)7 +b(t)37 b FK(to)e(compute)g(ef-)0 8399 y(\002cient)55 +b(partitionings)h(for)g(netw)n(orks)f(of)h(heterogeneous)e(processors.) +92 b(T)-13 b(o)55 b(do)g(so,)j(these)d(routines)g(require)g(an)g +(additional)h(array)0 8618 y(\()p Fj(tpwgts)p FK(\))47 +b(to)h(be)g(passed)g(as)f(a)h(parameter)-9 b(.)72 b(This)48 +b(array)h(describes)e(the)h(fraction)h(of)g(the)f(total)h(v)n(erte)n(x) +e(weight)h(each)g(sub-domain)0 8837 y(should)60 b(contain.)105 +b(F)n(or)60 b(e)n(xample,)j(if)d(you)g(ha)m(v)n(e)e(a)i(netw)n(ork)g +(of)g(four)h(processors,)h(the)e(\002rst)g(three)g(of)g(which)f(are)h +(of)g(equal)f(pro-)0 9056 y(cessing)g(speed,)64 b(and)d(the)f(fourth)i +(of)f(which)f(is)h(twice)f(as)g(f)n(ast)h(as)f(the)g(others,)65 +b(the)60 b(user)h(w)n(ould)g(pass)e(an)i(array)f(containing)h(the)0 +9276 y(v)l(alues)50 b Fz(.)p FK(0)p Fz(:)p FK(2)p Fz(;)28 +b FK(0)p Fz(:)p FK(2)p Fz(;)g FK(0)p Fz(:)p FK(2)p Fz(;)g +FK(0)p Fz(:)p FK(4)p Fz(/)p FK(.)75 b(Note)50 b(that)h(by)f(allo)l +(wing)g(users)g(to)h(specify)f(tar)m(get)g(sub-domain)h(weights)f(as)f +(such,)j(heterogeneous)0 9495 y(processing)47 b(po)l(wer)h(can)g(be)g +(tak)n(en)g(into)h(account)f(when)f(computing)i(a)f(partitioning.)72 +b(Ho)l(we)l(v)n(er)-7 b(,)49 b(this)f(does)f(not)i(allo)l(w)f(us)g(to)g +(tak)n(e)0 9714 y(heterogeneous)e(netw)n(ork)i(bandwidths)f(and)g +(latencies)f(into)h(account.)68 b(Optimizing)47 b(partitionings)h(for)g +(heterogeneous)e(netw)n(orks)0 9933 y(is)41 b(still)h(the)f(focus)h(of) +f(ongoing)h(research.)0 10388 y Ft(3.7)199 b(Computing)55 +b(Fill-Reducing)g(Or)l(derings)0 10707 y FA(P)-7 b(arMETIS)p +768 10707 V 61 w(V3)p 1032 10707 V 60 w(NodeND)70 b FK(is)g(the)g +(routine)h(pro)n(vided)f(by)k FA(P)-10 b FG(A)8 b(R)g +FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)76 b FK(for)71 +b(computing)g(\002ll-reducing)g(orderings,)77 b(suited)69 +b(for)3817 11298 y(10)p eop +%%Page: 11 11 +11 10 bop 0 166 a FK(Cholesk)n(y-based)51 b(direct)j(f)n(actorization)f +(algorithms.)86 b FA(P)-7 b(arMETIS)p 4039 166 50 7 v +61 w(V3)p 4303 166 V 60 w(NodeND)54 b FK(mak)n(es)e(no)i(assumptions)e +(on)h(ho)l(w)g(the)g(graph)0 385 y(is)59 b(initially)g(distrib)m(uted)g +(among)g(the)g(processors.)102 b(It)60 b(can)e(ef)l(fecti)l(v)n(ely)g +(compute)h(\002ll-reducing)h(orderings)f(for)h(graphs)e(that)h(are)0 +604 y(randomly)42 b(distrib)m(uted)f(as)g(well)h(as)f(graphs)g(that)g +(are)h(well)f(distrib)m(uted.)199 824 y(The)36 b(algorithm)h +(implemented)f(by)f FA(P)-7 b(arMETIS)p 3047 824 V 61 +w(V3)p 3311 824 V 60 w(NodeND)37 b FK(is)e(based)g(on)h(a)f(multile)l +(v)n(el)h(nested)f(dissection)g(algorithm.)50 b(This)0 +1043 y(algorithm)h(has)f(been)g(sho)l(wn)g(to)g(produce)g(lo)l(w)h +(\002ll)g(orderings)f(for)h(a)f(wide)h(v)l(ariety)f(of)h(matrices.)77 +b(Furthermore,)53 b(it)e(leads)e(to)i(bal-)0 1262 y(anced)46 +b(elimination)h(trees)f(that)h(are)f(essential)f(for)j(parallel)e +(direct)h(f)n(actorization.)66 b FA(P)-7 b(arMETIS)p +5683 1262 V 61 w(V3)p 5947 1262 V 60 w(NodeND)47 b FK(uses)f(a)g +(multile)l(v)n(el)0 1481 y(node-based)f(re\002nement)i(algorithm)g +(that)f(is)g(particularly)h(suited)f(for)h(directly)f(re\002ning)h(the) +f(size)g(of)g(the)h(separators.)64 b(T)-13 b(o)47 b(achie)l(v)n(e)0 +1700 y(high)63 b(performance,)k FA(P)-7 b(arMETIS)p 2074 +1700 V 61 w(V3)p 2338 1700 V 60 w(NodeND)63 b FK(\002rst)g(uses)e +FA(P)-7 b(arMETIS)p 4524 1700 V 61 w(V3)p 4788 1700 V +60 w(P)g(ar)7 b(tKw)n(a)-5 b(y)63 b FK(to)f(compute)h(a)f(high-quality) +h(parti-)0 1919 y(tioning)52 b(and)e(redistrib)m(utes)h(the)g(graph)g +(accordingly)-11 b(.)79 b(Ne)n(xt)50 b(it)i(proceeds)e(to)h(compute)g +(the)g(log)c Fy(p)56 b FK(le)l(v)n(els)49 b(of)j(the)f(elimination)g +(tree)0 2139 y(concurrently)-11 b(.)92 b(When)54 b(the)h(graph)g(has)g +(been)f(separated)g(into)75 b Fy(p)60 b FK(parts)55 b(\(where)74 +b Fy(p)60 b FK(is)55 b(the)g(number)g(of)g(processors\),)i(the)e(graph) +g(is)0 2358 y(redistrib)m(uted)45 b(among)g(the)h(processor)e(so)h +(that)g(each)g(processor)f(recei)l(v)n(es)g(a)h(single)g(subgraph,)g +(and)g(a)g(multiple)h(minimum)g(de)n(gree)0 2577 y(algorithm)c(is)g +(used)e(to)i(order)g(these)f(smaller)g(subgraphs.)3817 +11298 y(11)p eop +%%Page: 12 12 +12 11 bop 0 170 a FE(4)233 b(Input)64 b(and)h(Output)h(Formats)f(used)h +(b)-5 b(y)71 b(P)-9 b Fu(A)12 b(R)g FE(M)-11 b Fu(E)-46 +b FE(T)g Fu(I)p FE(S)0 558 y Ft(4.1)199 b(Format)55 b(of)g(the)h(Input) +f(Graph)0 877 y FK(All)48 b(of)g(the)g(graph)g(routines)f(in)52 +b FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g +FG(I)p FA(S)55 b FK(tak)n(e)48 b(as)f(input)h(the)g(adjacenc)n(y)e +(structure)h(of)i(the)e(graph,)i(the)f(weights)f(of)h(the)g(v)n +(ertices)0 1096 y(and)h(edges)g(\(if)h(an)n(y\),)h(and)e(an)h(array)f +(describing)h(ho)l(w)f(the)h(graph)f(is)h(distrib)m(uted)f(among)h(the) +f(processors.)74 b(Note)50 b(that)f(depending)0 1315 +y(on)54 b(the)h(application)f(this)g(graph)h(can)f(represent)g(dif)l +(ferent)h(things.)89 b(F)n(or)55 b(e)n(xample,)h(when)i +FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p +FA(S)61 b FK(is)54 b(used)g(to)h(compute)f(\002ll-)0 +1534 y(reducing)44 b(orderings,)h(the)g(graph)f(corresponds)g(to)h(the) +f(non-zero)h(structure)f(of)h(the)g(matrix)g(\(e)n(xcluding)f(the)g +(diagonal)h(entries\).)60 b(In)0 1754 y(the)46 b(case)f(of)i(\002nite)g +(element)e(computations,)i(the)f(v)n(ertices)g(of)g(the)g(graph)h(can)f +(correspond)g(to)g(nodes)g(\(points\))h(in)f(the)g(mesh)g(while)0 +1973 y(edges)c(represent)h(the)f(connections)h(between)f(these)g +(nodes.)55 b(Alternati)l(v)n(ely)-11 b(,)42 b(the)h(graph)g(can)g +(correspond)g(to)g(the)g(dual)f(of)i(the)f(\002nite)0 +2192 y(element)48 b(mesh.)71 b(In)49 b(this)g(case,)f(each)g(v)n(erte)n +(x)f(corresponds)h(to)g(an)h(element)f(and)g(tw)n(o)h(v)n(ertices)e +(are)h(connected)g(via)g(an)g(edge)g(if)h(the)0 2411 +y(corresponding)38 b(elements)f(share)g(an)h(edge)g(\(in)g(2D\))g(or)g +(a)g(f)n(ace)g(\(in)g(3D\).)g(Also,)g(the)g(graph)g(can)f(be)h(similar) +g(to)g(the)g(dual,)g(b)m(ut)g(be)g(more)0 2630 y(or)52 +b(less)e(connected.)79 b(That)52 b(is,)h(instead)d(of)i(limiting)g +(edges)f(to)g(those)g(elements)f(that)i(share)e(a)h(f)n(ace,)i(edges)e +(can)f(connect)h(an)n(y)g(tw)n(o)0 2850 y(elements)43 +b(that)h(share)f(e)l(v)n(en)g(a)g(single)h(node.)58 b(Ho)l(we)l(v)n(er) +42 b(the)i(graph)g(is)g(constructed,)f(it)h(is)g(usually)f(undirected.) +6526 2789 y Fr(4)6656 2850 y FK(That)h(is,)f(for)i(e)l(v)n(ery)0 +3069 y(pair)d(of)g(connected)e(v)n(ertices)h Fz(v)48 +b FK(and)41 b Fy(u)9 b FK(,)41 b(it)h(contains)e(both)i(edges)f +Fz(.v)7 b(;)28 b Fy(u)9 b Fz(/)40 b FK(and)h Fz(.)p Fy(u)9 +b Fz(;)28 b(v)7 b(/)p FK(.)199 3288 y(In)51 b FA(P)-10 +b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)t +FK(,)49 b(the)e(structure)g(of)g(the)g(graph)f(is)h(represented)f(by)h +(the)g(compressed)e(storage)i(format)g(\(CSR\),)g(e)n(xtended)f(for)h +(the)0 3507 y(conte)n(xt)j(of)h(parallel)g(distrib)m(uted-memory)h +(computing.)79 b(W)-13 b(e)50 b(will)h(\002rst)g(describe)f(the)h(CSR)g +(format)g(for)h(serial)e(graphs)g(and)h(then)0 3726 y(describe)41 +b(ho)l(w)g(it)h(has)f(been)g(e)n(xtended)f(for)i(storing)g(graphs)f +(that)h(are)f(distrib)m(uted)h(among)f(processors.)0 +4145 y FB(Serial)66 b(CSR)e(Format)200 b FK(The)59 b(CSR)g(format)h(is) +e(a)h(widely-used)f(scheme)g(for)h(storing)g(sparse)f(graphs.)103 +b(Here,)62 b(the)d(adjacenc)n(y)0 4364 y(structure)45 +b(of)h(a)f(graph)g(is)g(represented)f(by)h(tw)n(o)h(arrays,)f +Fj(xadj)f FK(and)h Fj(adjncy)p FK(.)60 b(W)-13 b(eights)44 +b(on)h(the)g(v)n(ertices)f(and)h(edges)g(\(if)h(an)n(y\))e(are)0 +4583 y(represented)d(by)h(using)f(tw)n(o)h(additional)g(arrays,)f +Fj(vwgt)f FK(and)h Fj(adjwgt)p FK(.)49 b(F)n(or)42 b(e)n(xample,)e +(consider)h(a)h(graph)f(with)h Fy(n)49 b FK(v)n(ertices)41 +b(and)g Fy(m)0 4802 y FK(edges.)50 b(In)42 b(the)f(CSR)h(format,)f +(this)h(graph)f(can)g(be)h(described)e(using)i(arrays)f(of)h(the)f +(follo)l(wing)h(sizes:)1794 5154 y Fj(xadj[)p Fy(n)g +FL(C)37 b FK(1)p Fj(])p FK(,)j Fj(vwgt[)p Fy(n)7 b Fj(])p +FK(,)40 b Fj(adjncy[)p FK(2)p Fy(m)10 b Fj(])p FK(,)37 +b(and)42 b Fj(adjwgt[)p FK(2)p Fy(m)10 b Fj(])0 5506 +y FK(Note)51 b(that)h(the)f(reason)g(both)h Fj(adjncy)d +FK(and)i Fj(adjwgt)e FK(are)j(of)f(size)g(2)p Fy(m)61 +b FK(is)52 b(because)e(e)l(v)n(ery)g(edge)h(is)g(listed)h(twice)f(\()p +Fs(i.e)o FK(.,)i(as)e Fz(.v)7 b(;)28 b Fy(u)9 b Fz(/)0 +5725 y FK(and)45 b Fz(.)p Fy(u)9 b Fz(;)28 b(v)7 b(/)p +FK(\).)63 b(Also)45 b(note)g(that)h(in)g(the)f(case)f(in)i(which)g(the) +f(graph)h(is)f(unweighted)g(\()p Fs(i.e)p FK(.,)h(all)f(v)n(ertices)g +(and/or)g(edges)g(ha)m(v)n(e)f(the)i(same)0 5945 y(weight\),)52 +b(then)e(either)g(or)g(both)g(of)g(the)g(arrays)g Fj(vwgt)e +FK(and)i Fj(adjwgt)e FK(can)h(be)h(set)f(to)h Fj(NULL)p +FK(.)e FA(P)-7 b(arMETIS)p 6339 5945 50 7 v 61 w(V3)p +6603 5945 V 60 w(Adaptiv)l(eRepar)7 b(t)0 6164 y FK(additionally)56 +b(requires)f(a)f Fj(vsize)g FK(array)-11 b(.)92 b(This)56 +b(array)f(is)g(similar)g(to)h(the)f Fj(vwgt)e FK(array)-11 +b(,)59 b(e)n(xcept)54 b(that)h(instead)g(of)g(describing)g(the)0 +6383 y(amount)d(of)g(w)n(ork)g(that)g(is)g(associated)e(with)i(each)f +(v)n(erte)n(x,)i(it)f(describes)e(the)i(amount)g(of)g(memory)g(that)g +(is)g(associated)e(with)i(each)0 6602 y(v)n(erte)n(x.)199 +6821 y(The)44 b(adjacenc)n(y)f(structure)h(of)g(the)g(graph)g(is)f +(stored)h(as)f(follo)l(ws.)59 b(Assuming)43 b(that)h(v)n(erte)n(x)f +(numbering)h(starts)g(from)h(0)f(\(C)g(style\),)0 7041 +y(the)i(adjacenc)n(y)f(list)h(of)h(v)n(erte)n(x)d Fy(i)62 +b FK(is)46 b(stored)g(in)h(array)f Fj(adjncy)e FK(starting)i(at)g(inde) +n(x)g Fj(xadj[)o Fy(i)16 b Fj(])44 b FK(and)i(ending)g(at)h(\(b)m(ut)f +(not)g(including\))0 7260 y(inde)n(x)f Fj(xadj[)o Fy(i)55 +b FL(C)39 b FK(1)p Fj(])46 b FK(\(in)g(other)g(w)n(ords,)h +Fj(adjncy[xadj[)o Fy(i)16 b Fj(]])41 b FK(up)46 b(through)g(and)g +(including)g Fj(adjncy[xadj[)o Fy(i)52 b FL(C)40 b FK(1)p +Fj(]-1])p FK(\).)0 7479 y(Hence,)58 b(the)f(adjacenc)n(y)d(lists)i(for) +h(each)e(v)n(erte)n(x)g(are)h(stored)g(consecuti)l(v)n(ely)f(in)h(the)g +(array)h Fj(adjncy)p FK(.)92 b(The)57 b(array)f Fj(xadj)f +FK(is)h(used)0 7698 y(to)k(point)g(to)h(where)e(the)h(list)g(for)g +(each)g(speci\002c)f(v)n(erte)n(x)g(be)n(gins)g(and)g(ends.)106 +b(Figure)60 b(5\(b\))h(illustrates)e(the)h(CSR)g(format)h(for)f(the)0 +7917 y(15-v)n(erte)n(x)52 b(graph)g(sho)l(wn)g(in)h(Figure)g(5\(a\).)85 +b(If)53 b(the)f(graph)h(w)n(as)f(weights)g(on)h(the)f(v)n(ertices,)i +(then)e Fj(vwgt[)o Fy(i)16 b Fj(])51 b FK(is)h(used)g(to)h(store)f(the) +0 8136 y(weight)43 b(of)g(v)n(erte)n(x)e Fy(i)16 b FK(.)55 +b(Similarly)-11 b(,)44 b(if)g(the)f(graph)f(has)h(weights)f(on)h(the)g +(edges,)f(then)h(the)f(weight)h(of)g(edge)g Fj(adjncy[)27 +b Fy(j)16 b Fj(])40 b FK(is)j(stored)g(in)0 8356 y Fj(adjwgt[)27 +b Fy(j)16 b Fj(])p FK(.)49 b(This)41 b(is)h(the)f(same)g(format)h(that) +g(is)f(used)g(by)g(the)h(\(serial\))j FA(M)-9 b FG(E)-34 +b FA(T)g FG(I)p FA(S)48 b FK(library)43 b(routines.)0 +8774 y FB(Distrib)m(uted)58 b(CSR)d(Format)204 b FA(P)-10 +b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)57 +b FK(uses)49 b(an)h(e)n(xtension)f(of)h(the)g(CSR)g(format)h(that)g +(allo)l(ws)e(the)h(v)n(ertices)f(of)i(the)f(graph)0 8993 +y(and)41 b(their)h(adjacenc)n(y)e(lists)h(to)g(be)h(distrib)m(uted)f +(among)g(the)h(processors.)50 b(In)41 b(particular)-7 +b(,)46 b FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b +FA(T)g FG(I)p FA(S)48 b FK(assumes)40 b(that)h(each)g(processor)15 +9212 y Fy(P)104 9237 y Fh(i)198 9212 y FK(stores)d Fy(n)713 +9237 y Fh(i)808 9212 y FK(consecuti)l(v)n(e)e(v)n(ertices)i(of)g(the)h +(graph)f(and)h(the)f(corresponding)g Fy(m)4647 9237 y +Fh(i)4741 9212 y FK(edges,)g(so)g(that)h Fy(n)53 b FL(D)5986 +9088 y Fg(P)6158 9260 y Fh(i)6242 9212 y Fy(n)6331 9237 +y Fh(i)6387 9212 y FK(,)39 b(and)f(2)26 b FL(\003)g Fy(m)55 +b FL(D)7318 9088 y Fg(P)7491 9260 y Fh(i)7574 9212 y +Fy(m)7703 9237 y Fh(i)7758 9212 y FK(.)0 9432 y(Here,)34 +b(each)f(processor)g(stores)g(its)g(local)h(part)f(of)h(the)g(graph)g +(in)f(the)h(four)g(arrays)f Fj(xadj[)p Fy(n)5224 9457 +y Fh(i)5286 9432 y FL(C)8 b FK(1)p Fj(])p FK(,)33 b Fj(vwgt[)p +Fy(n)6271 9457 y Fh(i)6326 9432 y Fj(])p FK(,)h Fj(adjncy[)p +Fy(m)7331 9457 y Fh(i)7384 9432 y Fj(])p FK(,)g(and)0 +9651 y Fj(adjwgt[)p Fy(m)829 9676 y Fh(i)882 9651 y Fj(])p +FK(,)43 b(using)g(the)g(CSR)g(storage)g(scheme.)55 b(Ag)o(ain,)43 +b(if)h(the)f(graph)h(is)f(unweighted,)g(the)g(arrays)g +Fj(vwgt)e FK(and)i Fj(adjwgt)f FK(can)0 9870 y(be)48 +b(set)f(to)i Fj(NULL)p FK(.)d(The)i(straightforw)n(ard)h(w)n(ay)f(to)h +(distrib)m(ute)f(the)g(graph)g(for)53 b FA(P)-10 b FG(A)8 +b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)54 b FK(is)48 +b(to)g(tak)n(e)g Fy(n)7 b Fz(=)19 b Fy(p)54 b FK(consecuti)l(v)n(e)47 +b(adjacenc)n(y)0 10089 y(lists)39 b(from)h Fj(adjncy)d +FK(and)i(store)g(them)h(on)f(consecuti)l(v)n(e)f(processors)g(\(where) +58 b Fy(p)45 b FK(is)39 b(the)g(number)h(of)f(processors\).)50 +b(In)39 b(addition,)h(each)p 0 10378 3120 7 v 174 10498 +a Fq(4)239 10546 y FF(Multi-constraint)35 b(and)g(multi-objecti)m(v)n +(e)h(graph)f(partitioning)h(formulations)g([6,)e(13)q(])g(can)h(get)f +(around)i(this)e(requirement)h(for)g(some)f(applications.)45 +b(These)34 b(also)0 10704 y(allo)m(w)f(the)h(computation)h(of)f +(partitionings)h(for)f(bipartite)g(graphs,)g(as)f(well)g(as)g(for)h +(graphs)g(corresponding)i(to)e(non-square)h(and)f(non-symmetric)i +(matrices.)3817 11298 y FK(12)p eop +%%Page: 13 13 +13 12 bop 900 5478 a @beginspecial 0 @llx 0 @lly 506 +@urx 462 @ury 3600 @rwi @setspecial +%%BeginDocument: ./figures/dcsr.eps +%!PS-Adobe-2.0 EPSF-2.0 +%%Title: dcsr.eps +%%Creator: fig2dev Version 3.2 Patchlevel 3b +%%CreationDate: Mon Jan 14 18:13:16 2002 +%%For: kirk@lnx08 (Kirk Schloegel) +%%BoundingBox: 0 0 506 462 +%%Magnification: 1.0000 +%%EndComments +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +newpath 0 462 moveto 0 0 lineto 506 0 lineto 506 462 lineto closepath clip newpath +-8.0 477.0 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def + /DrawEllipse { + /endangle exch def + /startangle exch def + /yrad exch def + /xrad exch def + /y exch def + /x exch def + /savematrix mtrx currentmatrix def + x y tr xrad yrad sc 0 0 1 startangle endangle arc + closepath + savematrix setmatrix + } def + +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +%%Page: 1 1 +10 setmiterlimit + 0.06000 0.06000 sc +% +% Fig objects follow +% +7.500 slw +% Ellipse +n 3300 300 38 38 0 360 DrawEllipse gs 0.00 setgray ef gr gs col0 s gr + +% Ellipse +n 3600 300 38 38 0 360 DrawEllipse gs 0.00 setgray ef gr gs col0 s gr + +% Ellipse +n 3900 300 38 38 0 360 DrawEllipse gs 0.00 setgray ef gr gs col0 s gr + +% Ellipse +n 4200 300 38 38 0 360 DrawEllipse gs 0.00 setgray ef gr gs col0 s gr + +% Ellipse +n 4500 300 38 38 0 360 DrawEllipse gs 0.00 setgray ef gr gs col0 s gr + +% Ellipse +n 3300 600 38 38 0 360 DrawEllipse gs 0.00 setgray ef gr gs col0 s gr + +% Ellipse +n 3600 600 38 38 0 360 DrawEllipse gs 0.00 setgray ef gr gs col0 s gr + +% Ellipse +n 3900 600 38 38 0 360 DrawEllipse gs 0.00 setgray ef gr gs col0 s gr + +% Ellipse +n 4200 600 38 38 0 360 DrawEllipse gs 0.00 setgray ef gr gs col0 s gr + +% Ellipse +n 4500 600 38 38 0 360 DrawEllipse gs 0.00 setgray ef gr gs col0 s gr + +% Ellipse +n 4500 900 38 38 0 360 DrawEllipse gs 0.00 setgray ef gr gs col0 s gr + +% Ellipse +n 4200 900 38 38 0 360 DrawEllipse gs 0.00 setgray ef gr gs col0 s gr + +% Ellipse +n 3900 900 38 38 0 360 DrawEllipse gs 0.00 setgray ef gr gs col0 s gr + +% Ellipse +n 3600 900 38 38 0 360 DrawEllipse gs 0.00 setgray ef gr gs col0 s gr + +% Ellipse +n 3300 900 38 38 0 360 DrawEllipse gs 0.00 setgray ef gr gs col0 s gr + +/Times-Roman ff 150.00 scf sf +3600 4350 m +gs 1 -1 sc (0) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3750 4350 m +gs 1 -1 sc (2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3900 4350 m +gs 1 -1 sc (5) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4050 4350 m +gs 1 -1 sc (8) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4200 4350 m +gs 1 -1 sc (11) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4425 4350 m +gs 1 -1 sc (13) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3600 4950 m +gs 1 -1 sc (0) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3750 4950 m +gs 1 -1 sc (5) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3900 4950 m +gs 1 -1 sc (10) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4125 4950 m +gs 1 -1 sc (15) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3300 4950 m +gs 1 -1 sc (vtxdist) dup sw pop neg 0 rm col-1 sh gr +/Times-Roman ff 150.00 scf sf +3600 4650 m +gs 1 -1 sc (1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3900 4650 m +gs 1 -1 sc (0) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4050 4650 m +gs 1 -1 sc (2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4200 4650 m +gs 1 -1 sc (6) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4350 4650 m +gs 1 -1 sc (1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4500 4650 m +gs 1 -1 sc (3) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4650 4650 m +gs 1 -1 sc (7) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3750 4650 m +gs 1 -1 sc (5) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4800 4650 m +gs 1 -1 sc (2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4950 4650 m +gs 1 -1 sc (4) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5400 4650 m +gs 1 -1 sc (9) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5250 4650 m +gs 1 -1 sc (3) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5100 4650 m +gs 1 -1 sc (8) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3600 5550 m +gs 1 -1 sc (0) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3750 5550 m +gs 1 -1 sc (3) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3900 5550 m +gs 1 -1 sc (7) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4050 5550 m +gs 1 -1 sc (11) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4275 5550 m +gs 1 -1 sc (15) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4500 5550 m +gs 1 -1 sc (18) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4125 5850 m +gs 1 -1 sc (1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4275 5850 m +gs 1 -1 sc (5) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4425 5850 m +gs 1 -1 sc (7) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4575 5850 m +gs 1 -1 sc (11) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4800 5850 m +gs 1 -1 sc (2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4950 5850 m +gs 1 -1 sc (6) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5100 5850 m +gs 1 -1 sc (8) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5250 5850 m +gs 1 -1 sc (12) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5475 5850 m +gs 1 -1 sc (3) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5625 5850 m +gs 1 -1 sc (7) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5775 5850 m +gs 1 -1 sc (9) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5925 5850 m +gs 1 -1 sc (13) col-1 sh gr +/Times-Roman ff 150.00 scf sf +6150 5850 m +gs 1 -1 sc (4) col-1 sh gr +/Times-Roman ff 150.00 scf sf +6300 5850 m +gs 1 -1 sc (8) col-1 sh gr +/Times-Roman ff 150.00 scf sf +6450 5850 m +gs 1 -1 sc (14) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3600 5850 m +gs 1 -1 sc (0) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3750 5850 m +gs 1 -1 sc (6) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3900 5850 m +gs 1 -1 sc (10) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3600 6150 m +gs 1 -1 sc (0) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3750 6150 m +gs 1 -1 sc (5) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3900 6150 m +gs 1 -1 sc (10) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4125 6150 m +gs 1 -1 sc (15) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3300 6150 m +gs 1 -1 sc (vtxdist) dup sw pop neg 0 rm col-1 sh gr +/Times-Roman ff 150.00 scf sf +3600 7050 m +gs 1 -1 sc (5) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3750 7050 m +gs 1 -1 sc (11) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3975 7050 m +gs 1 -1 sc (6) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4125 7050 m +gs 1 -1 sc (10) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4350 7050 m +gs 1 -1 sc (12) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4575 7050 m +gs 1 -1 sc (7) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4725 7050 m +gs 1 -1 sc (11) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4950 7050 m +gs 1 -1 sc (13) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5175 7050 m +gs 1 -1 sc (8) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5325 7050 m +gs 1 -1 sc (12) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5550 7050 m +gs 1 -1 sc (14) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5775 7050 m +gs 1 -1 sc (9) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5925 7050 m +gs 1 -1 sc (13) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3600 6750 m +gs 1 -1 sc (0) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3750 6750 m +gs 1 -1 sc (2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3900 6750 m +gs 1 -1 sc (5) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4050 6750 m +gs 1 -1 sc (8) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4200 6750 m +gs 1 -1 sc (11) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4425 6750 m +gs 1 -1 sc (13) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3600 7350 m +gs 1 -1 sc (0) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3750 7350 m +gs 1 -1 sc (5) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3900 7350 m +gs 1 -1 sc (10) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4125 7350 m +gs 1 -1 sc (15) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3300 7350 m +gs 1 -1 sc (vtxdist) dup sw pop neg 0 rm col-1 sh gr +% Polyline +n 1350 4125 m 7200 4125 l 7200 7500 l 1350 7500 l + cp gs col-1 s gr +/Times-Roman ff 180.00 scf sf +1350 4050 m +gs 1 -1 sc (Description of the graph on a parallel computer with 3 processors \(ParMeTiS\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3300 4350 m +gs 1 -1 sc (xadj) dup sw pop neg 0 rm col-1 sh gr +/Times-Roman ff 150.00 scf sf +3300 4650 m +gs 1 -1 sc (adjncy) dup sw pop neg 0 rm col-1 sh gr +/Times-Roman ff 150.00 scf sf +1500 4350 m +gs 1 -1 sc (Processor 0:) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1500 5550 m +gs 1 -1 sc (Processor 1:) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3300 5550 m +gs 1 -1 sc (xadj) dup sw pop neg 0 rm col-1 sh gr +/Times-Roman ff 150.00 scf sf +3300 5850 m +gs 1 -1 sc (adjncy) dup sw pop neg 0 rm col-1 sh gr +/Times-Roman ff 150.00 scf sf +3300 7050 m +gs 1 -1 sc (adjncy) dup sw pop neg 0 rm col-1 sh gr +/Times-Roman ff 150.00 scf sf +3300 6750 m +gs 1 -1 sc (xadj) dup sw pop neg 0 rm col-1 sh gr +/Times-Roman ff 150.00 scf sf +1500 6750 m +gs 1 -1 sc (Processor 2:) col-1 sh gr +/Times-Roman ff 150.00 scf sf +900 2550 m +gs 1 -1 sc (0) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1050 2550 m +gs 1 -1 sc (2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1200 2550 m +gs 1 -1 sc (5) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1350 2550 m +gs 1 -1 sc (8) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1500 2550 m +gs 1 -1 sc (11) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1725 2550 m +gs 1 -1 sc (13) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1950 2550 m +gs 1 -1 sc (16) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2175 2550 m +gs 1 -1 sc (20) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2400 2550 m +gs 1 -1 sc (24) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2625 2550 m +gs 1 -1 sc (28) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2850 2550 m +gs 1 -1 sc (31) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3075 2550 m +gs 1 -1 sc (33) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3300 2550 m +gs 1 -1 sc (36) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3525 2550 m +gs 1 -1 sc (39) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3750 2550 m +gs 1 -1 sc (42) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3975 2550 m +gs 1 -1 sc (44) col-1 sh gr +/Times-Roman ff 150.00 scf sf +900 2850 m +gs 1 -1 sc (1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1200 2850 m +gs 1 -1 sc (0) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1350 2850 m +gs 1 -1 sc (2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1500 2850 m +gs 1 -1 sc (6) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1650 2850 m +gs 1 -1 sc (1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1800 2850 m +gs 1 -1 sc (3) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1950 2850 m +gs 1 -1 sc (7) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1050 2850 m +gs 1 -1 sc (5) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2100 2850 m +gs 1 -1 sc (2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2250 2850 m +gs 1 -1 sc (4) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2700 2850 m +gs 1 -1 sc (9) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2550 2850 m +gs 1 -1 sc (3) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2400 2850 m +gs 1 -1 sc (8) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3375 2850 m +gs 1 -1 sc (1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3525 2850 m +gs 1 -1 sc (5) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3675 2850 m +gs 1 -1 sc (7) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3825 2850 m +gs 1 -1 sc (11) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4050 2850 m +gs 1 -1 sc (2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4200 2850 m +gs 1 -1 sc (6) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4350 2850 m +gs 1 -1 sc (8) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4500 2850 m +gs 1 -1 sc (12) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4725 2850 m +gs 1 -1 sc (3) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4875 2850 m +gs 1 -1 sc (7) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5025 2850 m +gs 1 -1 sc (9) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5175 2850 m +gs 1 -1 sc (13) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5400 2850 m +gs 1 -1 sc (4) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5550 2850 m +gs 1 -1 sc (8) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5700 2850 m +gs 1 -1 sc (14) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2850 2850 m +gs 1 -1 sc (0) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3000 2850 m +gs 1 -1 sc (6) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3150 2850 m +gs 1 -1 sc (10) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5925 2850 m +gs 1 -1 sc (5) col-1 sh gr +/Times-Roman ff 150.00 scf sf +6075 2850 m +gs 1 -1 sc (11) col-1 sh gr +/Times-Roman ff 150.00 scf sf +6300 2850 m +gs 1 -1 sc (6) col-1 sh gr +/Times-Roman ff 150.00 scf sf +6450 2850 m +gs 1 -1 sc (10) col-1 sh gr +/Times-Roman ff 150.00 scf sf +6675 2850 m +gs 1 -1 sc (12) col-1 sh gr +/Times-Roman ff 150.00 scf sf +6900 2850 m +gs 1 -1 sc (7) col-1 sh gr +/Times-Roman ff 150.00 scf sf +7050 2850 m +gs 1 -1 sc (11) col-1 sh gr +/Times-Roman ff 150.00 scf sf +7275 2850 m +gs 1 -1 sc (13) col-1 sh gr +/Times-Roman ff 150.00 scf sf +7500 2850 m +gs 1 -1 sc (8) col-1 sh gr +/Times-Roman ff 150.00 scf sf +7650 2850 m +gs 1 -1 sc (12) col-1 sh gr +/Times-Roman ff 150.00 scf sf +7875 2850 m +gs 1 -1 sc (14) col-1 sh gr +/Times-Roman ff 150.00 scf sf +8100 2850 m +gs 1 -1 sc (9) col-1 sh gr +/Times-Roman ff 150.00 scf sf +8250 2850 m +gs 1 -1 sc (13) col-1 sh gr +% Polyline +n 150 2250 m 8550 2250 l 8550 3000 l 150 3000 l + cp gs col-1 s gr +/Times-Roman ff 150.00 scf sf +600 2550 m +gs 1 -1 sc (xadj) dup sw pop neg 0 rm col-1 sh gr +/Times-Roman ff 150.00 scf sf +600 2850 m +gs 1 -1 sc (adjncy) dup sw pop neg 0 rm col-1 sh gr +/Times-Roman ff 180.00 scf sf +150 2175 m +gs 1 -1 sc (Description of the graph on a serial computer \(serial MeTiS\)) col-1 sh gr +% Polyline +n 3300 600 m + 4500 600 l gs col-1 s gr +% Polyline +n 3600 300 m + 3600 900 l gs col-1 s gr +% Polyline +n 3300 300 m 4500 300 l 4500 900 l 3300 900 l + 3300 300 l cp gs col-1 s gr +% Polyline +n 3900 300 m + 3900 900 l gs col-1 s gr +% Polyline +n 4200 300 m + 4200 900 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3150 450 m +gs 1 -1 sc (0) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3450 450 m +gs 1 -1 sc (1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3750 450 m +gs 1 -1 sc (2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4050 450 m +gs 1 -1 sc (3) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4350 450 m +gs 1 -1 sc (4) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3150 750 m +gs 1 -1 sc (5) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3450 750 m +gs 1 -1 sc (6) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3750 750 m +gs 1 -1 sc (7) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4050 750 m +gs 1 -1 sc (8) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4350 750 m +gs 1 -1 sc (9) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4425 1125 m +gs 1 -1 sc (14) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4125 1125 m +gs 1 -1 sc (13) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3825 1125 m +gs 1 -1 sc (12) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3525 1125 m +gs 1 -1 sc (11) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3225 1125 m +gs 1 -1 sc (10) col-1 sh gr +/Helvetica-Bold ff 210.00 scf sf +3900 1500 m +gs 1 -1 sc (\(a\) A sample graph) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-Bold ff 210.00 scf sf +3900 3375 m +gs 1 -1 sc (\(b\) Serial CSR format) dup sw pop 2 div neg 0 rm col-1 sh gr +/Helvetica-Bold ff 210.00 scf sf +3900 7950 m +gs 1 -1 sc (\(c\) Distributed CSR format) dup sw pop 2 div neg 0 rm col-1 sh gr +$F2psEnd +rs + +%%EndDocument + @endspecial 0 5844 a Fx(Figure)49 b(5)p FK(:)74 b Fw(An)48 +b(e)l(xample)g(of)g(the)g(par)o(ameters)g(passed)f(to)52 +b(P)-6 b Fv(A)8 b(R)g Fw(M)-9 b Fv(E)-34 b Fw(T)g Fv(I)p +Fw(S)55 b(in)48 b(a)g(three)g(processor)g(case)n(.)78 +b(The)48 b(arr)o(a)l(ys)h Fj(vwgt)e Fw(and)g Fj(adjwgt)f +Fw(are)0 6043 y(assumed)37 b(to)h(be)f(NULL.)0 6377 y +FK(processor)f(needs)f(its)h(local)h Fj(xadj)d FK(array)j(to)f(point)h +(to)g(where)f(each)f(of)i(its)f(local)g(v)n(ertices')g(adjacenc)n(y)f +(lists)h(be)n(gin)f(and)i(end.)49 b(Thus,)37 b(if)0 6597 +y(we)i(tak)n(e)h(all)f(the)h(local)f Fj(adjncy)e FK(arrays)j(and)f +(concatenate)f(them,)i(we)f(will)h(get)f(e)n(xactly)g(the)g(same)g +Fj(adjncy)e FK(array)j(that)g(is)f(used)g(in)0 6816 y(the)k(serial)g +(CSR.)g(Ho)l(we)l(v)n(er)-7 b(,)42 b(concatenating)g(the)i(local)f +Fj(xadj)e FK(arrays)i(will)h(not)f(gi)l(v)n(e)g(us)g(the)g(serial)g +Fj(xadj)f FK(array)-11 b(.)56 b(This)43 b(is)g(because)0 +7035 y(the)50 b(entries)f(in)h(each)f(local)h Fj(xadj)e +FK(must)i(point)g(to)g(their)h(local)e Fj(adjncy)f FK(array)-11 +b(,)52 b(and)d(so,)i Fj(xadj[)p FK(0)p Fj(])d FK(is)i(zero)f(for)i(all) +f(processors.)0 7254 y(In)d(addition)f(to)h(these)f(four)h(arrays,)f +(each)g(processor)g(also)f(requires)i(the)f(array)g Fj(vtxdist[)19 +b Fy(p)43 b FL(C)d FK(1)p Fj(])46 b FK(that)h(indicates)e(the)i(range)f +(of)0 7473 y(v)n(ertices)f(that)i(are)f(local)h(to)g(each)e(processor) +-9 b(.)66 b(In)47 b(particular)-7 b(,)48 b(processor)61 +b Fy(P)4428 7498 y Fh(i)4530 7473 y FK(stores)46 b(the)g(v)n(ertices)g +(from)h Fj(vtxdist[)o Fy(i)16 b Fj(])43 b FK(up)k(to)g(\(b)m(ut)0 +7693 y(not)42 b(including\))g(v)n(erte)n(x)e Fj(vtxdist[)o +Fy(i)50 b FL(C)37 b FK(1)p Fj(])p FK(.)199 7912 y(Figure)42 +b(5\(c\))g(illustrates)f(the)g(distrib)m(uted)g(CSR)h(format)g(by)f(an) +g(e)n(xample)f(on)i(a)f(three-processor)g(system.)50 +b(The)41 b(15-v)n(erte)n(x)g(graph)0 8131 y(in)65 b(Figure)g(5\(a\))g +(is)g(distrib)m(uted)g(among)f(the)h(processors)f(so)g(that)h(each)f +(processor)g(gets)g(5)h(v)n(ertices)e(and)i(their)g(corresponding)0 +8350 y(adjacenc)n(y)e(lists.)121 b(That)65 b(is,)70 b(Processor)64 +b(Zero)i(gets)e(v)n(ertices)g(0)g(through)i(4,)k(Processor)64 +b(One)h(gets)f(v)n(ertices)g(5)h(through)g(9,)70 b(and)0 +8569 y(Processor)54 b(T)-13 b(w)n(o)56 b(gets)e(v)n(ertices)g(10)h +(through)h(14.)91 b(This)55 b(\002gure)g(sho)l(ws)f(the)h +Fj(xadj)p FK(,)h Fj(adjncy)p FK(,)g(and)e Fj(vtxdist)f +FK(arrays)h(for)i(each)0 8788 y(processor)-9 b(.)50 b(Note)41 +b(that)h(the)f Fj(vtxdist)e FK(array)j(will)g(al)n(w)n(ays)f(be)g +(identical)h(for)g(e)l(v)n(ery)e(processor)-9 b(.)199 +9008 y(All)33 b(\002)l(v)n(e)f(arrays)h(that)f(describe)g(the)h +(distrib)m(uted)g(CSR)f(format)i(are)e(de\002ned)h(in)j +FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p +FA(S)40 b FK(to)33 b(be)f(of)h(type)g Fj(idxtype)p FK(.)45 +b(By)33 b(def)n(ault)0 9227 y Fj(idxtype)50 b FK(is)i(set)f(to)i(be)f +(equi)l(v)l(alent)f(to)i(type)f Fj(int)f FK(\()p Fs(i.e)p +FK(.,)j(inte)n(gers\).)82 b(Ho)l(we)l(v)n(er)-7 b(,)54 +b Fj(idxtype)49 b FK(can)j(be)g(made)g(to)g(be)g(equi)l(v)l(alent)g(to) +0 9446 y(a)d Fj(short)98 b(int)47 b FK(for)j(certain)f(architectures)f +(that)h(use)g(64-bit)h(inte)n(gers)e(by)h(def)n(ault.)74 +b(\(Note)49 b(that)g(doing)h(so)e(will)i(cut)f(the)g(memory)0 +9665 y(usage)h(and)h(communication)g(time)g(required)h(approximately)f +(in)g(half.\))80 b(The)52 b(con)-7 b(v)n(ersion)50 b(of)h +Fj(idxtype)e FK(from)j Fj(int)e FK(to)h Fj(short)0 9884 +y FK(can)46 b(be)g(done)h(by)f(modifying)i(the)e(\002le)h +Fj(parmetis.h)p FK(.)62 b(\(Instructions)47 b(are)f(included)h +(there.\))66 b(The)47 b(same)e Fj(idxtype)f FK(is)j(used)e(for)0 +10104 y(the)c(arrays)h(that)f(store)g(the)h(computed)f(partitioning)i +(and)e(permutation)h(v)n(ectors.)199 10323 y(When)51 +b(multiple)i(v)n(erte)n(x)d(weights)i(are)f(used)g(for)h +(multi-constraint)h(partitioning,)h(the)e Fy(c)j FK(v)n(erte)n(x)50 +b(weights)i(for)g(each)f(v)n(erte)n(x)f(are)0 10542 y(stored)f +(contiguously)g(in)g(the)g Fj(vwgt)e FK(array)-11 b(.)74 +b(In)49 b(this)g(case,)h(the)e Fj(vwgt)g FK(array)h(is)g(of)g(size)f +Fy(n)7 b(c)s FK(,)51 b(where)e Fy(n)56 b FK(is)49 b(the)g(number)g(of)h +(locally-)0 10761 y(stored)41 b(v)n(ertices)g(and)g Fy(c)k +FK(is)c(the)g(number)h(of)g(v)n(erte)n(x)e(weights)h(\(and)h(also)f +(the)g(number)h(of)g(balance)f(constraints\).)3817 11298 +y(13)p eop +%%Page: 14 14 +14 13 bop 0 166 a Ft(4.2)199 b(Format)55 b(of)g(V)-10 +b(er)t(te)m(x)55 b(Coor)l(dinates)0 485 y FK(As)37 b(discussed)g(in)h +(Section)g(3.1,)k FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 +b FA(T)g FG(I)p FA(S)44 b FK(pro)n(vides)38 b(routines)g(that)g(use)f +(the)h(coordinate)g(information)h(of)f(the)g(v)n(ertices)f(to)h +(quickly)0 704 y(pre-distrib)m(ute)65 b(the)f(graph,)70 +b(and)64 b(so,)70 b(speedup)63 b(the)i(e)n(x)n(ecution)e(of)i(the)f +(parallel)h Fy(k)10 b FK(-w)n(ay)64 b(partitioning.)121 +b(These)64 b(coordinates)g(are)0 923 y(speci\002ed)f(in)g(an)g(array)h +(called)f Fj(xyz)f FK(of)i(single)f(precision)g(\003oating)g(point)h +(numbers)f(\()p Fs(i.e)p FK(.,)68 b Fj(float)p FK(\).)115 +b(If)64 b Fy(d)76 b FK(is)63 b(the)g(number)h(of)0 1142 +y(dimensions)48 b(of)i(the)e(mesh)h(\()p Fs(i.e)o FK(.,)h +Fy(d)72 b FL(D)60 b FK(2)49 b(for)g(2D)g(meshes)e(or)j +Fy(d)72 b FL(D)59 b FK(3)49 b(for)h(3D)e(meshes\),)i(then)e(each)g +(processor)h(requires)f(an)h(array)0 1362 y(of)i(size)g +Fy(d)56 b FL(\003)44 b Fy(n)858 1387 y Fh(i)914 1362 +y FK(,)53 b(where)e Fy(n)1555 1387 y Fh(i)1662 1362 y +FK(is)g(the)g(number)g(of)h(locally-stored)f(v)n(ertices.)79 +b(\(Note)51 b(that)g(the)g(number)g(of)h(dimensions)f(of)g(the)g(mesh,) +0 1581 y Fy(d)12 b FK(,)55 b(is)d(required)g(as)g(a)g(parameter)g(to)h +(the)f(routine.\))84 b(In)52 b(this)h(array)-11 b(,)54 +b(the)e(coordinates)g(of)h(v)n(erte)n(x)d Fy(i)68 b FK(are)52 +b(stored)g(starting)h(at)f(location)0 1800 y Fj(xyz[)o +Fy(i)42 b FL(\003)28 b Fy(d)12 b Fj(])39 b FK(up)g(to)g(\(b)m(ut)g(not) +h(including\))f(location)g Fj(xyz[)o Fy(i)k FL(\003)27 +b Fy(d)40 b FL(C)27 b Fy(d)12 b Fj(])p FK(.)51 b(F)n(or)39 +b(e)n(xample,)f(if)h Fy(d)59 b FL(D)46 b FK(3,)39 b(then)g(the)g(x,)g +(y)-11 b(,)39 b(and)g(z)g(coordinates)0 2019 y(of)j(v)n(erte)n(x)d +Fy(i)58 b FK(are)41 b(stored)g(at)h Fj(xyz[3*i])p FK(,)c +Fj(xyz[3*i+1])p FK(,)f(and)k Fj(xyz[3*i+2])p FK(,)d(respecti)l(v)n(ely) +-11 b(.)0 2474 y Ft(4.3)199 b(Format)55 b(of)g(the)h(Input)f(Mesh)0 +2793 y FK(The)98 b(routine)h FA(P)-7 b(arMETIS)p 1693 +2793 50 7 v 61 w(V3)p 1957 2793 V 60 w(P)g(ar)7 b(tMeshKw)n(a)-5 +b(y)99 b FK(tak)n(es)e(a)h(distrib)m(uted)g(mesh)g(and)g(computes)f +(its)h(partitioning,)113 b(while)0 3012 y FA(P)-7 b(arMETIS)p +768 3012 V 61 w(V3)p 1032 3012 V 60 w(Mesh2Dual)58 b +FK(2dual)f(tak)n(es)g(a)f(distrib)m(uted)h(mesh)f(and)h(constructs)f(a) +h(distrib)m(uted)g(dual)g(graph.)97 b(Both)57 b(of)g(these)0 +3231 y(routines)41 b(require)h(an)f Fj(elmdist)e FK(array)i(that)h +(speci\002es)e(the)h(distrib)m(ution)h(of)g(the)f(mesh)g(elements,)f(b) +m(ut)i(that)f(is)g(otherwise)g(identical)0 3450 y(to)53 +b(the)f Fj(vtxdist)e FK(array)-11 b(.)84 b(The)n(y)52 +b(also)g(require)h(a)f(pair)h(of)f(arrays)g(called)g +Fj(eptr)f FK(and)i Fj(eind)p FK(,)g(as)f(well)g(as)g(the)g(inte)n(ger)g +(parameter)0 3670 y Fj(ncommonnodes)p FK(.)199 3889 y(The)e +Fj(eptr)e FK(and)h Fj(eind)f FK(arrays)h(are)h(similar)g(in)f(nature)h +(to)f(the)h Fj(xadj)e FK(and)h Fj(adjncy)e FK(arrays)j(used)e(to)i +(specify)f(the)h(adjacenc)n(y)0 4108 y(list)44 b(of)f(a)g(graph)h(b)m +(ut)f(no)l(w)g(for)i(each)d(element)h(the)n(y)g(specify)g(the)g(set)g +(of)h(nodes)f(that)g(mak)n(e)h(up)f(each)g(element.)56 +b(Speci\002cally)-11 b(,)44 b(the)g(set)0 4327 y(of)d(nodes)f(that)h +(belong)g(to)g(element)f Fy(i)57 b FK(is)40 b(stored)h(in)g(array)g +Fj(eind)e FK(starting)i(at)g(inde)n(x)f Fj(eptr[)o Fy(i)16 +b Fj(])39 b FK(and)i(ending)g(at)f(\(b)m(ut)h(not)g(including\))0 +4546 y(inde)n(x)e Fj(eptr[)o Fy(i)j FL(C)27 b FK(1)p +Fj(])39 b FK(\(in)g(other)h(w)n(ords,)f Fj(eind[eptr[)o +Fy(i)16 b Fj(]])35 b FK(up)k(through)g(and)g(including)h +Fj(eind[eptr[)o Fy(i)g FL(C)27 b FK(1)p Fj(]-1])p FK(\).)49 +b(Hence,)0 4765 y(the)54 b(node)g(lists)f(for)i(each)e(element)h(are)g +(stored)f(consecuti)l(v)n(ely)g(in)h(the)g(array)g Fj(eind)p +FK(.)87 b(This)54 b(format)h(allo)l(ws)e(the)h(speci\002cation)g(of)0 +4985 y(meshes)40 b(that)i(contain)f(elements)g(of)h(mix)n(ed)f(type.) +199 5204 y(The)58 b Fj(ncommonnodes)53 b FK(parameter)k(speci\002es)g +(the)g(de)n(gree)g(of)g(connecti)l(vity)h(that)f(is)h(desired)f +(between)f(the)i(v)n(ertices)e(of)i(the)0 5423 y(dual)50 +b(graph.)77 b(Speci\002cally)-11 b(,)52 b(an)d(edge)h(is)g(placed)f +(between)g(tw)n(o)i(v)n(ertices)e(if)h(their)h(corresponding)e(mesh)h +(elements)f(share)h(at)g(least)4 5642 y Fy(g)55 b FK(nodes,)50 +b(where)j Fy(g)i FK(is)49 b(the)g Fj(ncommonnodes)c FK(parameter)-9 +b(.)74 b(Hence,)49 b(this)g(parameter)g(can)g(be)g(set)g(to)g(result)g +(in)g(a)g(traditional)h(dual)0 5861 y(graph)57 b(\()p +Fs(e)n(.g)o FK(.,)i(a)d(v)l(alue)g(of)h(tw)n(o)f(for)h(a)g(triangle)f +(mesh)g(or)h(a)f(v)l(alue)g(of)h(four)g(for)g(a)f(he)n(xahedral)f +(mesh\).)96 b(Ho)l(we)l(v)n(er)-7 b(,)59 b(it)d(can)g(also)g(be)0 +6081 y(set)43 b(higher)i(or)f(lo)l(wer)g(for)g(increased)f(or)i +(decreased)d(connecti)l(vity)-11 b(.)58 b FA(P)-7 b(arMETIS)p +4760 6081 V 61 w(V3)p 5024 6081 V 60 w(P)g(ar)7 b(tMeshKw)n(a)-5 +b(y)45 b FK(additionally)f(requires)g(an)0 6300 y Fj(elmwgt)39 +b FK(array)j(that)f(is)h(analogous)e(to)i(the)g Fj(vwgt)e +FK(array)-11 b(.)0 6755 y Ft(4.4)199 b(Format)55 b(of)g(the)h(Computed) +e(P)-6 b(ar)t(titionings)55 b(and)g(Or)l(derings)0 7074 +y FB(Format)45 b(of)h(the)f(P)-5 b(ar)s(titioning)48 +b(Arra)m(y)198 b FK(The)40 b(partitioning)h(and)f(repartitioning)h +(routines)f(require)h(that)f(arrays)f(\(called)h Fj(part)p +FK(\))0 7293 y(of)54 b(sizes)e Fy(n)657 7318 y Fh(i)767 +7293 y FK(\(where)i Fy(n)1371 7318 y Fh(i)1480 7293 y +FK(is)g(the)f(number)h(of)g(local)f(v)n(ertices\))g(be)g(passed)g(as)f +(parameters)h(to)h(each)f(processor)-9 b(.)86 b(Upon)54 +b(completion)0 7512 y(of)h(the)k FA(P)-10 b FG(A)8 b(R)g +FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)62 b FK(routine,)c(for)e(each)e +(v)n(erte)n(x)81 b Fy(j)16 b FK(,)58 b(the)d(sub-domain)g(number)h(\()p +Fs(i.e)o FK(.,)i(the)d(processor)f(label\))h(to)g(which)g(this)g(v)n +(erte)n(x)0 7731 y(belongs)37 b(will)g(ha)m(v)n(e)f(been)h(written)g +(to)h Fj(part[)27 b Fy(j)16 b Fj(])p FK(.)48 b(Note)37 +b(that)k FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b +FA(T)g FG(I)p FA(S)44 b FK(does)36 b(not)i(redistrib)m(ute)f(the)g +(graph)g(according)g(to)g(the)h(ne)l(w)0 7950 y(partitioning,)k(it)g +(simply)f(computes)g(the)h(partitioning)g(and)f(writes)h(it)g(to)f(the) +h Fj(part)e FK(array)-11 b(.)199 8169 y(Additionally)g(,)45 +b(whene)l(v)n(er)d(the)i(number)g(of)f(sub-domains)h(does)f(not)h +(equal)f(the)g(number)h(of)g(processors)f(that)h(are)f(used)g(to)h +(com-)0 8389 y(pute)50 b(a)g(repartitioning,)j FA(P)-7 +b(arMETIS)p 2226 8389 V 61 w(V3)p 2490 8389 V 59 w(Adaptiv)l(eRepar)7 +b(t)52 b FK(requires)e(that)g(the)g(pre)l(viously)g(computed)g +(partitioning)h(be)f(passed)0 8608 y(as)i(a)h(parameter)g(via)g(the)g +Fj(part)e FK(array)-11 b(.)86 b(\(This)53 b(is)g(also)f(required)i +(whene)l(v)n(er)d(the)i(user)g(chooses)f(to)h(de-couple)f(the)h +(sub-domains)0 8827 y(from)44 b(the)g(processors.)56 +b(See)43 b(discussion)g(in)h(Section)f(5.2.\))57 b(This)44 +b(is)g(because)e(the)h(initial)h(partitioning)h(needs)e(to)g(be)h +(obtained)f(from)0 9046 y(the)h(v)l(alues)g(supplied)g(in)g(the)h +Fj(part)d FK(array)-11 b(.)60 b(If)45 b(the)f(numbers)h(of)f +(sub-domains)g(and)g(processors)g(are)g(equal,)g(then)g(the)g(initial)h +(parti-)0 9265 y(tioning)e(can)f(be)g(obtained)g(from)h(the)f(initial)h +(graph)g(distrib)m(ution,)f(and)g(so)g(this)g(information)i(need)e(not) +g(be)g(supplied.)54 b(\(In)42 b(this)h(case,)0 9484 y(for)f(each)f +(processor)f Fy(i)16 b FK(,)41 b(e)l(v)n(ery)f(element)i(of)f +Fj(part)f FK(w)n(ould)i(be)g(set)f(to)f Fy(i)16 b FK(.\))0 +9903 y FB(Format)37 b(of)h(the)g(P)-5 b(erm)m(utation)38 +b(Arra)m(y)198 b FK(Lik)n(e)l(wise,)35 b(each)d(processor)g(running)h +FA(P)-7 b(arMETIS)p 5708 9903 V 61 w(V3)p 5972 9903 V +60 w(NodeND)34 b FK(writes)e(its)h(portion)0 10122 y(of)54 +b(the)g(computed)f(\002ll-reducing)i(ordering)f(to)g(an)f(array)h +(called)f Fj(order)p FK(.)86 b(Similar)55 b(to)f(the)f +Fj(part)f FK(array)-11 b(,)57 b(the)d(size)e(of)i Fj(order)e +FK(is)0 10341 y(equal)47 b(to)g(the)h(number)f(of)h(v)n(ertices)e +(stored)h(at)g(each)g(processor)-9 b(.)68 b(Upon)47 b(completion,)h +(for)g(each)f(v)n(erte)n(x)73 b Fy(j)16 b FK(,)49 b Fj(order[)27 +b Fy(j)16 b Fj(])45 b FK(stores)i(the)0 10560 y(ne)l(w)41 +b(global)h(number)f(of)h(this)g(v)n(erte)n(x)e(in)i(the)f +(\002ll-reducing)i(permutation.)199 10780 y(Besides)63 +b(the)h(ordering)g(v)n(ector)-7 b(,)69 b FA(P)-7 b(arMETIS)p +2958 10780 V 61 w(V3)p 3222 10780 V 60 w(NodeND)64 b +FK(also)g(returns)g(information)h(about)f(the)g(sizes)e(of)j(the)e(dif) +l(ferent)3817 11298 y(14)p eop +%%Page: 15 15 +15 14 bop 1500 2086 a @beginspecial 0 @llx 0 @lly 412 +@urx 179 @ury 2880 @rwi @setspecial +%%BeginDocument: ./figures/stree.eps +%!PS-Adobe-2.0 EPSF-2.0 +%%Title: stree.fig +%%Creator: fig2dev Version 3.1 Patchlevel 1 +%%CreationDate: Thu Jul 17 14:01:58 1997 +%%For: karypis@in19 (George Karypis) +%%Orientation: Portrait +%%BoundingBox: 0 0 412 179 +%%Pages: 0 +%%BeginSetup +%%IncludeFeature: *PageSize Letter +%%EndSetup +%%EndComments +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {} def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +-89.0 218.0 translate +1 -1 scale + +/clp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/l {lineto} bind def +/m {moveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def + /DrawEllipse { + /endangle exch def + /startangle exch def + /yrad exch def + /xrad exch def + /y exch def + /x exch def + /savematrix mtrx currentmatrix def + x y tr xrad yrad sc 0 0 1 startangle endangle arc + closepath + savematrix setmatrix + } def + +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def +%%EndProlog + +$F2psBegin +10 setmiterlimit + 0.06000 0.06000 sc +/Times-Roman findfont 180.00 scalefont setfont +5175 3600 m +gs 1 -1 sc (13) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +5625 3600 m +gs 1 -1 sc (11) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +5850 3600 m +gs 1 -1 sc (2) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +6075 3600 m +gs 1 -1 sc (3) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +7.500 slw +% Polyline +n 6780 675 m 6675 675 6675 2220 105 arcto 4 {pop} repeat 6675 2325 7020 2325 105 arcto 4 {pop} repeat 7125 2325 7125 780 105 arcto 4 {pop} repeat 7125 675 6780 675 105 arcto 4 {pop} repeat clp gs col7 0.90 shd ef gr gs col-1 s gr +/Times-Roman findfont 180.00 scalefont setfont +6825 3600 m +gs 1 -1 sc (9) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +6600 3600 m +gs 1 -1 sc (8) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +6300 3600 m +gs 1 -1 sc (12) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +4950 3600 m +gs 1 -1 sc (5) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +3600 3600 m +gs 1 -1 sc (1) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +% Polyline +n 2880 675 m 2775 675 2775 2220 105 arcto 4 {pop} repeat 2775 2325 3120 2325 105 arcto 4 {pop} repeat 3225 2325 3225 780 105 arcto 4 {pop} repeat 3225 675 2880 675 105 arcto 4 {pop} repeat clp gs col7 0.90 shd ef gr gs col-1 s gr +% Polyline +n 1605 1275 m 1500 1275 1500 1620 105 arcto 4 {pop} repeat 1500 1725 2520 1725 105 arcto 4 {pop} repeat 2625 1725 2625 1380 105 arcto 4 {pop} repeat 2625 1275 1605 1275 105 arcto 4 {pop} repeat clp gs col7 0.90 shd ef gr gs col-1 s gr +% Polyline +n 3480 1275 m 3375 1275 3375 1620 105 arcto 4 {pop} repeat 3375 1725 4320 1725 105 arcto 4 {pop} repeat 4425 1725 4425 1380 105 arcto 4 {pop} repeat 4425 1275 3480 1275 105 arcto 4 {pop} repeat clp gs col7 0.90 shd ef gr gs col-1 s gr +/Times-Roman findfont 180.00 scalefont setfont +3825 3600 m +gs 1 -1 sc (0) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +4725 3600 m +gs 1 -1 sc (4) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +4500 3600 m +gs 1 -1 sc (7) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +4275 3600 m +gs 1 -1 sc (6) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +4050 3600 m +gs 1 -1 sc (14) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +5400 3600 m +gs 1 -1 sc (10) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Courier-Bold findfont 180.00 scalefont setfont +3225 3600 m +gs 1 -1 sc (order) dup stringwidth pop neg 0 rmoveto col-1 show gr +/Courier-Bold findfont 180.00 scalefont setfont +3225 3225 m +gs 1 -1 sc (sizes) dup stringwidth pop neg 0 rmoveto col-1 show gr +% Polyline +n 7380 1275 m 7275 1275 7275 1620 105 arcto 4 {pop} repeat 7275 1725 8220 1725 105 arcto 4 {pop} repeat 8325 1725 8325 1380 105 arcto 4 {pop} repeat 8325 1275 7380 1275 105 arcto 4 {pop} repeat clp gs col7 0.90 shd ef gr gs col-1 s gr +% Polyline +n 5505 1275 m 5400 1275 5400 1620 105 arcto 4 {pop} repeat 5400 1725 6420 1725 105 arcto 4 {pop} repeat 6525 1725 6525 1380 105 arcto 4 {pop} repeat 6525 1275 5505 1275 105 arcto 4 {pop} repeat clp gs col7 0.90 shd ef gr gs col-1 s gr +/Times-Roman findfont 180.00 scalefont setfont +3825 3225 m +gs 1 -1 sc (2) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +4050 3225 m +gs 1 -1 sc (2) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +4500 3225 m +gs 1 -1 sc (2) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +4275 3225 m +gs 1 -1 sc (2) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +5550 825 m +gs 1 -1 sc (1) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +% Polyline +n 8100 900 m 8100 2100 l gs col-1 s gr +% Polyline +n 5700 1500 m 8100 1500 l gs col-1 s gr +% Polyline +n 5700 2100 m 8175 2100 l gs col-1 s gr +% Polyline +n 5700 900 m 5700 2100 l gs col-1 s gr +% Polyline +n 6300 900 m 6300 2100 l gs col-1 s gr +% Polyline +n 6900 900 m 6900 2100 l gs col-1 s gr +% Polyline +n 7500 900 m 7500 2100 l gs col-1 s gr +/Times-Roman findfont 180.00 scalefont setfont +3600 3225 m +gs 1 -1 sc (2) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +4950 3225 m +gs 1 -1 sc (3) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +7350 1425 m +gs 1 -1 sc (10) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +7950 1425 m +gs 1 -1 sc (11) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +5550 2025 m +gs 1 -1 sc (2) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +6150 2025 m +gs 1 -1 sc (3) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +6750 2025 m +gs 1 -1 sc (12) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +7350 2025 m +gs 1 -1 sc (8) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +7950 2025 m +gs 1 -1 sc (9) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +6750 1425 m +gs 1 -1 sc (13) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +4725 3225 m +gs 1 -1 sc (2) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +6150 825 m +gs 1 -1 sc (0) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +6750 825 m +gs 1 -1 sc (14) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +7350 825 m +gs 1 -1 sc (6) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +7950 825 m +gs 1 -1 sc (7) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +5550 1425 m +gs 1 -1 sc (4) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +6150 1425 m +gs 1 -1 sc (5) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +% Polyline +n 5700 900 m 8175 900 l gs col-1 s gr +/Times-Roman findfont 180.00 scalefont setfont +2250 2025 m +gs 1 -1 sc (11) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +1650 2025 m +gs 1 -1 sc (10) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +4050 1425 m +gs 1 -1 sc (9) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +3450 1425 m +gs 1 -1 sc (8) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +3450 825 m +gs 1 -1 sc (3) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +1650 1425 m +gs 1 -1 sc (5) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +2250 1425 m +gs 1 -1 sc (6) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +2850 1425 m +gs 1 -1 sc (7) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +2850 2025 m +gs 1 -1 sc (12) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +% Polyline +n 1800 900 m 1800 2100 l gs col-1 s gr +% Polyline +n 1800 2100 m 4275 2100 l gs col-1 s gr +% Polyline +n 1800 900 m 4275 900 l gs col-1 s gr +% Polyline +n 1800 1500 m 4200 1500 l gs col-1 s gr +% Polyline +n 2400 900 m 2400 2100 l gs col-1 s gr +/Times-Roman findfont 180.00 scalefont setfont +3450 2025 m +gs 1 -1 sc (13) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +4050 2025 m +gs 1 -1 sc (14) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +% Polyline +n 3600 900 m 3600 2100 l gs col-1 s gr +% Polyline +n 3000 900 m 3000 2100 l gs col-1 s gr +/Times-Roman findfont 180.00 scalefont setfont +4050 825 m +gs 1 -1 sc (4) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +% Polyline +n 4200 900 m 4200 2100 l gs col-1 s gr +/Times-Roman findfont 180.00 scalefont setfont +1650 825 m +gs 1 -1 sc (0) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +2850 825 m +gs 1 -1 sc (2) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +/Times-Roman findfont 180.00 scalefont setfont +2250 825 m +gs 1 -1 sc (1) dup stringwidth pop 2 div neg 0 rmoveto col-1 show gr +% Ellipse +n 4200 1500 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 4200 2100 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 3600 2100 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 3600 900 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 3000 900 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 3000 1500 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 3000 2100 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 1800 900 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 1800 1500 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 1800 2100 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 2400 2100 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 2400 1500 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 2400 900 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 4200 900 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 3600 1500 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 5700 2100 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 7500 900 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 7500 1500 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 8100 1500 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 8100 2100 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 8100 900 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 5700 1500 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 5700 900 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 6300 2100 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 6300 1500 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 6300 900 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 7500 2100 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 6900 1500 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 6900 900 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Ellipse +n 6900 2100 106 106 0 360 DrawEllipse gs col7 1.00 shd ef gr gs col-1 s gr + +% Polyline +n 3825 3075 m 5550 2250 l gs col7 0.90 shd ef gr gs col-1 s gr +n 5428.80 2274.71 m 5550.00 2250.00 l 5454.69 2328.84 l gs col-1 s gr +% Polyline +n 4275 3075 m 7350 2250 l gs col7 0.90 shd ef gr gs col-1 s gr +n 7226.33 2252.12 m 7350.00 2250.00 l 7241.87 2310.07 l gs col-1 s gr +% Polyline +n 4050 3075 m 7350 1050 l gs col7 0.90 shd ef gr gs col-1 s gr +n 7232.03 1087.19 m 7350.00 1050.00 l 7263.41 1138.33 l gs col-1 s gr +% Polyline +n 4500 3000 m 5400 1800 l gs col7 0.90 shd ef gr gs col-1 s gr +n 5304.00 1878.00 m 5400.00 1800.00 l 5352.00 1914.00 l gs col-1 s gr +% Polyline +n 3600 3000 m 5550 1050 l gs col7 0.90 shd ef gr gs col-1 s gr +n 5443.93 1113.64 m 5550.00 1050.00 l 5486.36 1156.07 l gs col-1 s gr +% Polyline +n 4725 3000 m 7275 1725 l gs col7 0.90 shd ef gr gs col-1 s gr +n 7154.25 1751.83 m 7275.00 1725.00 l 7181.09 1805.50 l gs col-1 s gr +% Polyline +n 4950 3075 m 6600 2325 l gs col7 0.90 shd ef gr gs col-1 s gr +n 6478.34 2347.35 m 6600.00 2325.00 l 6503.17 2401.97 l gs col-1 s gr +$F2psEnd +restore + +%%EndDocument + @endspecial 0 2451 a Fx(Figure)51 b(6)p FK(:)80 b Fw(An)50 +b(e)l(xample)h(of)f(the)g(order)r(ing)h(produced)e(b)n(y)h(P)-5 +b(arMETIS_V3_NodeND.)50 b(Consider)g(the)g(simple)i FK(3)47 +b FL(\002)h FK(5)j Fw(g)o(r)r(id)f(and)g(assume)h(that)0 +2650 y(w)o(e)45 b(ha)n(v)m(e)e(f)l(our)h(processors)n(.)67 +b(P)-5 b(arMETIS_V3_NodeND)44 b(\002nds)g(the)g(three)g(separ)o(ators)g +(that)g(are)g(shaded.)66 b(It)44 b(\002rst)h(\002nds)g(the)f(big)g +(separ)o(ator)g(and)0 2849 y(then)39 b(f)l(or)h(each)f(of)g(the)h(tw)o +(o)f(sub-domains)h(it)g(\002nds)f(the)g(smaller)-7 b(.)54 +b(At)40 b(the)f(end)g(of)h(the)f(order)r(ing,)h(the)f +Fj(order)f Fw(v)m(ector)h(concatenated)f(o)n(v)m(er)i(all)g(the)0 +3049 y(processors)d(will)i(be)e(the)g(one)g(sho)n(wn.)46 +b(Similar)r(ly)-13 b(,)38 b(the)f Fj(sizes)f Fw(arr)o(a)l(ys)i(will)g +(all)g(be)f(identical)g(to)g(the)g(one)g(sho)n(wn,)g(corresponding)f +(to)i(the)f(regions)0 3248 y(pointed)g(to)g(b)n(y)g(the)g(arro)n(ws)n +(.)0 3615 y FK(sub-domains)53 b(as)f(well)h(as)f(the)h(separators)f(at) +h(dif)l(ferent)g(le)l(v)n(els.)84 b(This)54 b(array)f(is)f(called)h +Fj(sizes)e FK(and)i(is)f(of)i(size)e(2)19 b Fy(p)58 b +FK(\(where)72 b Fy(p)58 b FK(is)0 3835 y(the)c(number)h(of)f +(processors\).)89 b(Ev)n(ery)54 b(processor)f(must)i(supply)f(this)g +(array)g(and)g(upon)g(return,)k(each)53 b(of)i(the)f +Fj(sizes)e FK(arrays)i(are)0 4054 y(identical.)199 4273 +y(The)49 b(format)g(of)f(this)g(array)h(is)f(as)f(follo)l(ws.)71 +b(The)49 b(\002rst)68 b Fy(p)53 b FK(entries)48 b(of)h +Fj(sizes)d FK(starting)i(from)h(0)g(to)67 b Fy(p)47 b +FL(\000)42 b FK(1)48 b(store)g(the)g(number)h(of)0 4492 +y(nodes)h(in)g(each)f(one)h(of)h(the)69 b Fy(p)55 b FK(sub-domains.)77 +b(The)50 b(remaining)69 b Fy(p)49 b FL(\000)43 b FK(1)50 +b(entries)g(of)g(this)g(array)h(starting)f(from)h Fj(sizes[)19 +b Fy(p)5 b Fj(])48 b FK(up)i(to)0 4711 y Fj(sizes[)p +FK(2)19 b Fy(p)c FL(\000)c FK(2)p Fj(])32 b FK(store)i(the)g(sizes)f +(of)i(the)f(separators)g(at)g(the)g(log)47 b Fy(p)40 +b FK(le)l(v)n(els)33 b(of)i(nested)e(dissection.)48 b(In)35 +b(particular)-7 b(,)36 b Fj(sizes[)p FK(2)19 b Fy(p)c +FL(\000)c FK(2)p Fj(])0 4930 y FK(stores)37 b(the)h(size)e(of)i(the)g +(top)g(le)l(v)n(el)e(separator)-7 b(,)38 b Fj(sizes[)p +FK(2)19 b Fy(p)28 b FL(\000)23 b FK(4)p Fj(])34 b FK(and)k +Fj(sizes[)p FK(2)19 b Fy(p)28 b FL(\000)23 b FK(3)p Fj(])33 +b FK(store)38 b(the)f(sizes)g(of)h(the)f(tw)n(o)h(separators)f(at)0 +5150 y(the)43 b(second)f(le)l(v)n(el)f(\(from)j(left)f(to)g(right\).)56 +b(Similarly)-11 b(,)44 b Fj(sizes[)p FK(2)19 b Fy(p)41 +b FL(\000)c FK(8)p Fj(])43 b FK(through)g Fj(sizes[)p +FK(2)19 b Fy(p)41 b FL(\000)c FK(5)p Fj(])43 b FK(store)f(the)h(sizes)f +(of)h(the)f(four)0 5369 y(separators)35 b(of)h(the)f(third)h(le)l(v)n +(el)f(\(from)i(left)f(to)f(right\),)j(and)d(so)g(on.)49 +b(This)36 b(array)g(can)f(be)g(used)g(to)h(quickly)f(construct)h(the)f +(separator)g(tree)0 5588 y(\(a)44 b(form)g(of)g(an)g(elimination)g +(tree\))g(for)g(direct)g(f)n(actorization.)58 b(Gi)l(v)n(en)43 +b(this)h(separator)f(tree)g(and)h(the)g(sizes)e(of)i(the)g +(sub-domains,)f(the)0 5807 y(nodes)e(in)g(the)g(ordering)h(produced)f +(by)g FA(P)-7 b(arMETIS)p 3081 5807 50 7 v 61 w(V3)p +3345 5807 V 60 w(NodeND)42 b FK(are)f(numbered)g(in)g(a)g(postorder)g +(f)n(ashion.)51 b(Figure)42 b(6)f(illustrates)0 6026 +y(the)g Fj(sizes)f FK(array)i(and)f(the)g(postorder)h(ordering.)0 +6481 y Ft(4.5)199 b(Numbering)54 b(and)h(Memor)r(y)f(Allocation)4 +6800 y FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g +FG(I)p FA(S)55 b FK(allo)l(ws)48 b(the)g(user)g(to)h(specify)f(a)g +(graph)g(whose)g(numbering)h(starts)f(either)g(at)g(0)h(\(C)f(style\))h +(or)f(at)h(1)f(\(F)n(ortran)h(style\).)72 b(Of)0 7019 +y(course,)62 b FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 +b FA(T)g FG(I)p FA(S)62 b FK(requires)56 b(that)g(same)f(numbering)h +(scheme)f(be)g(used)g(consistently)g(for)i(all)f(the)f(arrays)h(passed) +e(to)i(it,)j(and)d(it)0 7238 y(writes)41 b(to)h(the)f +Fj(part)f FK(and)i Fj(order)d FK(arrays)j(similarly)-11 +b(.)203 7458 y FA(P)h FG(A)8 b(R)g FA(M)-9 b FG(E)-34 +b FA(T)g FG(I)p FA(S)46 b FK(allocates)38 b(all)h(the)g(memory)h(that)f +(it)h(requires)f(dynamically)-11 b(.)50 b(This)39 b(has)g(the)g(adv)l +(antage)f(that)h(the)h(user)e(does)h(not)g(ha)m(v)n(e)0 +7677 y(to)k(pro)n(vide)g(w)n(orkspace.)56 b(Ho)l(we)l(v)n(er)-7 +b(,)42 b(if)i(there)f(is)g(not)g(enough)g(memory)h(on)f(the)g(machine,) +g(the)g(routines)h(in)j FA(P)-10 b FG(A)8 b(R)g FA(M)-9 +b FG(E)-34 b FA(T)g FG(I)p FA(S)50 b FK(will)43 b(abort.)0 +7896 y(Note)52 b(that)g(the)g(routines)g(in)57 b FA(P)-10 +b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)58 +b FK(do)52 b(not)h(modify)g(the)f(arrays)f(that)i(store)f(the)g(graph)g +(\()p Fs(e)n(.g)o FK(.,)i Fj(xadj)c FK(and)i Fj(adjncy)p +FK(\).)81 b(The)n(y)0 8115 y(only)42 b(modify)g(the)f +Fj(part)f FK(and)i Fj(order)d FK(arrays.)3817 11298 y(15)p +eop +%%Page: 16 16 +16 15 bop 0 170 a FE(5)233 b(Calling)63 b(Sequence)j(of)f(the)g +(Routines)h(in)k(P)-9 b Fu(A)12 b(R)g FE(M)-11 b Fu(E)-46 +b FE(T)g Fu(I)p FE(S)0 522 y FK(The)42 b(calling)f(sequences)f(of)i +(the)j FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g +FG(I)p FA(S)48 b FK(routines)42 b(are)f(described)g(in)g(this)h +(section.)3817 11298 y(16)p eop +%%Page: 17 17 +17 16 bop 0 166 a Ft(5.1)199 b(Graph)54 b(P)-6 b(ar)t(titioning)0 +476 y FB(P)h(arMETIS)p 780 476 50 7 v 60 w(V3)p 1043 +476 V 60 w(P)g(ar)s(tKwa)m(y)42 b FK(\(idxtype)g(*vtxdist,)f(idxtype)h +(*xadj,)f(idxtype)g(*adjnc)n(y)-11 b(,)41 b(idxtype)g(*vwgt,)g(idxtype) +h(*adjwgt,)1886 695 y(int)g(*wgt\003ag,)f(int)h(*num\003ag,)f(int)h +(*ncon,)f(int)h(*nparts,)e(\003oat)i(*tpwgts,)f(\003oat)h(*ub)n(v)n +(ec,)1886 914 y(int)g(*options,)f(int)h(*edgecut,)e(idxtype)i(*part,)f +(MPI)p 4926 914 V 60 w(Comm)h(*comm\))0 1351 y FB(Description)415 +1570 y FK(This)58 b(routine)f(is)h(used)e(to)i(compute)f(a)g +Fy(k)10 b FK(-w)n(ay)58 b(partitioning)g(of)g(a)f(graph)g(on)77 +b Fy(p)62 b FK(processors)56 b(using)i(the)f(multile)l(v)n(el)g +Fy(k)10 b FK(-w)n(ay)415 1789 y(multi-constraint)42 b(partitioning)h +(algorithm.)0 2123 y FB(P)-5 b(arameter)n(s)415 2344 +y FD(vtxdist)268 b FK(This)39 b(array)g(describes)f(ho)l(w)g(the)h(v)n +(ertices)f(of)h(the)f(graph)h(are)g(distrib)m(uted)f(among)h(the)g +(processors.)49 b(\(See)39 b(discus-)1162 2563 y(sion)j(in)f(Section)h +(4.1\).)51 b(Its)41 b(contents)g(are)g(identical)h(for)g(e)l(v)n(ery)f +(processor)-9 b(.)415 2778 y FD(xadj,)42 b(adjncy)1162 +2998 y FK(These)52 b(store)g(the)h(\(local\))f(adjacenc)n(y)f +(structure)h(of)h(the)f(graph)g(at)h(each)e(processor)-9 +b(.)83 b(\(See)52 b(discussion)f(in)i(Sec-)1162 3217 +y(tion)42 b(4.1\).)415 3426 y FD(vwgt,)f(adjwgt)1162 +3645 y FK(These)g(store)h(the)f(weights)g(of)h(the)f(v)n(ertices)g(and) +g(edges.)50 b(\(See)42 b(discussion)e(in)i(Section)f(4.1\).)415 +3912 y FD(wgt\003ag)231 b FK(This)42 b(is)f(used)g(to)h(indicate)f(if)h +(the)f(graph)h(is)f(weighted.)51 b Fs(wgt\003a)n(g)42 +b FK(can)f(tak)n(e)g(one)h(of)f(four)i(v)l(alues:)1162 +4180 y(0)166 b(No)42 b(weights)f(\(vwgt)h(and)f(adjwgt)h(are)f(both)g +(NULL\).)1162 4423 y(1)166 b(W)-13 b(eights)41 b(on)h(the)f(edges)g +(only)g(\(vwgt)h(is)f(NULL\).)1162 4666 y(2)166 b(W)-13 +b(eights)41 b(on)h(the)f(v)n(ertices)f(only)i(\(adjwgt)g(is)f(NULL\).) +1162 4910 y(3)166 b(W)-13 b(eights)41 b(on)h(both)f(the)h(v)n(ertices)e +(and)h(edges.)415 5177 y FD(num\003ag)167 b FK(This)58 +b(is)f(used)g(to)h(indicate)f(the)g(numbering)h(scheme)e(that)i(is)f +(used)g(for)h(the)f Fs(vtxdist)p FK(,)k Fs(xadj)p FK(,)f +Fs(adjncy)p FK(,)h(and)c Fs(part)1162 5397 y FK(arrays.)51 +b Fs(num\003a)n(g)42 b FK(can)f(tak)n(e)g(one)h(of)f(tw)n(o)h(v)l +(alues:)1162 5664 y(0)166 b(C-style)42 b(numbering)g(that)f(starts)g +(from)h(0.)1162 5907 y(1)166 b(F)n(ortran-style)42 b(numbering)g(that)g +(starts)f(from)h(1.)415 6175 y FD(ncon)406 b FK(This)47 +b(is)e(used)h(to)g(specify)f(the)h(number)g(of)h(weights)e(that)h(each) +f(v)n(erte)n(x)g(has.)64 b(It)46 b(is)g(also)g(the)f(number)i(of)f +(balance)1162 6394 y(constraints)41 b(that)h(must)f(be)h(satis\002ed.) +415 6662 y FD(nparts)286 b FK(This)54 b(is)f(used)g(to)h(specify)f(the) +g(number)h(of)f(sub-domains)g(that)h(are)f(desired.)87 +b(Note)53 b(that)g(the)h(number)f(of)h(sub-)1162 6881 +y(domains)42 b(is)f(independent)g(of)h(the)f(number)h(of)g(processors)e +(that)i(call)f(this)g(routine.)415 7148 y FD(tpwgts)277 +b FK(An)52 b(array)g(of)g(size)f Fj(ncon)g FK(x)h Fj(nparts)d +FK(that)j(is)g(used)f(to)h(specify)f(the)h(fraction)g(of)h(v)n(erte)n +(x)d(weight)i(that)g(should)1162 7367 y(be)44 b(distrib)m(uted)g(to)g +(each)f(sub-domain)h(for)h(each)e(balance)g(constraint.)58 +b(If)45 b(all)f(of)g(the)g(sub-domains)f(are)h(to)g(be)g(of)1162 +7587 y(the)e(same)e(size)h(for)h(e)l(v)n(ery)f(v)n(erte)n(x)f(weight,)h +(then)h(each)e(of)i(the)g Fj(ncon)e FK(x)h Fj(nparts)e +FK(elements)i(should)g(be)h(set)f(to)g(a)1162 7806 y(v)l(alue)c(of)g +(1/)p Fj(nparts)p FK(.)47 b(If)38 b Fj(ncon)d FK(is)i(greater)f(than)h +(one,)g(the)g(tar)m(get)g(sub-domain)g(weights)f(for)i(each)e +(sub-domain)1162 8025 y(are)50 b(stored)g(contiguously)f(\(similar)i +(to)f(the)g Fj(vwgt)e FK(array\).)76 b(Note)50 b(that)g(the)g(sum)f(of) +h(all)g(of)g(the)g Fj(tpwgts)e FK(for)i(a)1162 8244 y(gi)l(v)n(e)41 +b(v)n(erte)n(x)g(weight)g(should)g(be)h(one.)415 8512 +y FD(ub)n(v)n(ec)336 b FK(An)42 b(array)g(of)g(size)f +Fj(ncon)f FK(that)i(is)g(used)f(to)h(specify)f(the)h(imbalance)f +(tolerance)g(for)i(each)e(v)n(erte)n(x)g(weight,)g(with)h(1)1162 +8731 y(being)47 b(perfect)g(balance)e(and)i Fj(nparts)d +FK(being)j(perfect)g(imbalance.)66 b(A)46 b(v)l(alue)g(of)h(1.05)g(for) +g(each)f(of)h(the)f Fj(ncon)1162 8950 y FK(weights)41 +b(is)h(recommended.)415 9217 y FD(options)231 b FK(This)38 +b(is)e(an)h(array)h(of)f(inte)n(gers)f(that)h(is)g(used)g(to)g(pass)f +(additional)h(parameters)g(for)h(the)f(routine.)49 b(If)38 +b Fs(options[0]=0)p FK(,)1162 9437 y(then)54 b(the)f(def)n(ault)i(v)l +(alues)d(are)i(used.)87 b(If)54 b Fs(options[0]=1)p FK(,)h(then)f(the)g +(remaining)g(tw)n(o)g(elements)f(of)h Fs(options)f FK(are)1162 +9656 y(interpreted)42 b(as)f(follo)l(ws:)1162 9923 y(options[1])222 +b(This)45 b(speci\002es)f(the)h(le)l(v)n(el)f(of)h(information)g(to)g +(be)g(returned)g(during)g(the)g(e)n(x)n(ecution)e(of)i(the)g(algo-)2066 +10142 y(rithm.)61 b(T)-6 b(iming)46 b(information)f(can)f(be)h +(obtained)f(by)h(setting)f(this)g(to)h(1.)60 b(Additional)45 +b(options)f(for)2066 10362 y(this)i(parameter)f(can)f(be)h(obtained)g +(by)h(looking)f(at)g(the)g(the)g(\002le)h Fj(defs.h)d +FK(in)i(the)g Fj(ParMETIS-)2066 10581 y(Lib)39 b FK(directory)-11 +b(.)51 b(The)40 b(numerical)g(v)l(alues)f(there)h(should)f(be)h(added)f +(to)h(obtain)g(the)g(correct)g(v)l(alue.)2066 10800 y(The)i(def)n(ault) +g(v)l(alue)f(is)g(0.)3817 11298 y(17)p eop +%%Page: 18 18 +18 17 bop 1162 166 a FK(options[2])222 b(This)42 b(is)f(the)h(random)g +(number)f(seed)g(for)h(the)f(routine.)52 b(The)42 b(def)n(ault)f(v)l +(alue)h(is)f(15.)415 452 y FD(edgecut)203 b FK(Upon)51 +b(successful)f(completion,)k(the)d(number)g(of)h(edges)e(that)h(are)g +(cut)g(by)h(the)f(partitioning)h(is)f(written)h(to)f(this)1162 +671 y(parameter)-9 b(.)415 956 y FD(part)443 b FK(This)33 +b(is)f(an)f(array)i(of)f(size)f(equal)h(to)g(the)g(number)h(of)f +(locally-stored)g(v)n(ertices.)47 b(Upon)32 b(successful)f(completion)h +(the)1162 1176 y(partition)43 b(v)n(ector)d(of)i(the)g(locally-stored)f +(v)n(ertices)g(is)g(written)h(to)g(this)f(array)-11 b(.)51 +b(\(See)42 b(discussion)e(in)i(Section)g(4.4\).)415 1461 +y FD(comm)314 b FK(This)45 b(is)e(a)h(pointer)g(to)g(the)g(MPI)g +(communicator)h(of)f(the)g(processes)e(that)i(call)k +FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p +FA(S)t FK(.)46 b(F)n(or)e(most)g(programs)1162 1680 y(this)e(will)g +(point)g(to)f Fj(MPI)p 2607 1680 50 7 v 59 w(COMM)p 3066 +1680 V 58 w(WORLD)p FK(.)3817 11298 y(18)p eop +%%Page: 19 19 +19 18 bop 0 166 a FB(P)-5 b(arMETIS)p 780 166 50 7 v +60 w(V3)p 1043 166 V 60 w(P)g(ar)s(tGeomKwa)m(y)42 b +FK(\(idxtype)g(*vtxdist,)g(idxtype)f(*xadj,)g(idxtype)h(*adjnc)n(y)-11 +b(,)40 b(idxtype)i(*vwgt,)f(idxtype)h(*adjwgt,)2356 385 +y(int)g(*wgt\003ag,)f(int)h(*num\003ag,)g(int)g(*ndims,)f(\003oat)g +(*xyz,)g(int)h(*ncon,)f(int)h(*nparts,)2356 604 y(\003oat)g(*tpwgts,)f +(\003oat)h(*ub)n(v)n(ec,)d(int)j(*options,)f(int)h(*edgecut,)f(idxtype) +g(*part,)2356 824 y(MPI)p 2661 824 V 60 w(Comm)h(*comm\))0 +1342 y FB(Description)415 1561 y FK(This)47 b(routine)g(is)g(used)f(to) +h(compute)f(a)h Fy(k)10 b FK(-w)n(ay)46 b(partitioning)i(of)f(a)f +(graph)h(on)66 b Fy(p)52 b FK(processors)45 b(by)i(combining)g(the)g +(coordinate-)415 1780 y(based)41 b(and)g(multi-constraint)h +Fy(k)10 b FK(-w)n(ay)42 b(partitioning)g(schemes.)0 2132 +y FB(P)-5 b(arameter)n(s)415 2371 y FD(vtxdist)268 b +FK(This)39 b(array)g(describes)f(ho)l(w)g(the)h(v)n(ertices)f(of)h(the) +f(graph)h(are)g(distrib)m(uted)f(among)h(the)g(processors.)49 +b(\(See)39 b(discus-)1162 2590 y(sion)j(in)f(Section)h(4.1\).)51 +b(Its)41 b(contents)g(are)g(identical)h(for)g(e)l(v)n(ery)f(processor) +-9 b(.)415 2824 y FD(xadj,)42 b(adjncy)1162 3043 y FK(These)52 +b(store)g(the)h(\(local\))f(adjacenc)n(y)f(structure)h(of)h(the)f +(graph)g(at)h(each)e(processor)-9 b(.)83 b(\(See)52 b(discussion)f(in)i +(Sec-)1162 3262 y(tion)42 b(4.1\).)415 3489 y FD(vwgt,)f(adjwgt)1162 +3708 y FK(These)g(store)h(the)f(weights)g(of)h(the)f(v)n(ertices)g(and) +g(edges.)50 b(\(See)42 b(discussion)e(in)i(Section)f(4.1\).)415 +3994 y FD(wgt\003ag)231 b FK(This)42 b(is)f(used)g(to)h(indicate)f(if)h +(the)f(graph)h(is)f(weighted.)51 b Fs(wgt\003a)n(g)42 +b FK(can)f(tak)n(e)g(one)h(of)f(four)i(v)l(alues:)1162 +4279 y(0)166 b(No)42 b(weights)f(\(vwgt)h(and)f(adjwgt)h(are)f(both)g +(NULL\).)1162 4532 y(1)166 b(W)-13 b(eights)41 b(on)h(the)f(edges)g +(only)g(\(vwgt)h(is)f(NULL\).)1162 4784 y(2)166 b(W)-13 +b(eights)41 b(on)h(the)f(v)n(ertices)f(only)i(\(adjwgt)g(is)f(NULL\).) +1162 5036 y(3)166 b(W)-13 b(eights)41 b(on)h(both)f(the)h(v)n(ertices)e +(and)h(edges.)415 5322 y FD(num\003ag)167 b FK(This)58 +b(is)f(used)g(to)h(indicate)f(the)g(numbering)h(scheme)e(that)i(is)f +(used)g(for)h(the)f Fs(vtxdist)p FK(,)k Fs(xadj)p FK(,)f +Fs(adjncy)p FK(,)h(and)c Fs(part)1162 5541 y FK(arrays.)51 +b Fs(num\003a)n(g)42 b FK(can)f(tak)n(e)g(one)h(of)f(tw)n(o)h(v)l +(alues:)1162 5827 y(0)166 b(C-style)42 b(numbering)g(that)f(starts)g +(from)h(0.)1162 6079 y(1)166 b(F)n(ortran-style)42 b(numbering)g(that)g +(starts)f(from)h(1.)415 6365 y FD(ndims)314 b FK(The)42 +b(number)g(of)g(dimensions)f(of)g(the)h(space)e(in)i(which)f(the)h +(graph)f(is)g(embedded.)415 6650 y FD(xyz)507 b FK(The)42 +b(array)g(storing)f(the)h(coordinates)f(of)h(the)f(v)n(ertices)f +(\(described)h(in)h(Section)g(4.2\).)415 6936 y FD(ncon)406 +b FK(This)47 b(is)e(used)h(to)g(specify)f(the)h(number)g(of)h(weights)e +(that)h(each)f(v)n(erte)n(x)g(has.)64 b(It)46 b(is)g(also)g(the)f +(number)i(of)f(balance)1162 7155 y(constraints)41 b(that)h(must)f(be)h +(satis\002ed.)415 7441 y FD(nparts)286 b FK(This)54 b(is)f(used)g(to)h +(specify)f(the)g(number)h(of)f(sub-domains)g(that)h(are)f(desired.)87 +b(Note)53 b(that)g(the)h(number)f(of)h(sub-)1162 7660 +y(domains)42 b(is)f(independent)g(of)h(the)f(number)h(of)g(processors)e +(that)i(call)f(this)g(routine.)415 7946 y FD(tpwgts)277 +b FK(An)52 b(array)g(of)g(size)f Fj(ncon)g FK(x)h Fj(nparts)d +FK(that)j(is)g(used)f(to)h(specify)f(the)h(fraction)g(of)h(v)n(erte)n +(x)d(weight)i(that)g(should)1162 8165 y(be)44 b(distrib)m(uted)g(to)g +(each)f(sub-domain)h(for)h(each)e(balance)g(constraint.)58 +b(If)45 b(all)f(of)g(the)g(sub-domains)f(are)h(to)g(be)g(of)1162 +8384 y(the)e(same)e(size)h(for)h(e)l(v)n(ery)f(v)n(erte)n(x)f(weight,)h +(then)h(each)e(of)i(the)g Fj(ncon)e FK(x)h Fj(nparts)e +FK(elements)i(should)g(be)h(set)f(to)g(a)1162 8603 y(v)l(alue)c(of)g +(1/)p Fj(nparts)p FK(.)47 b(If)38 b Fj(ncon)d FK(is)i(greater)f(than)h +(one,)g(the)g(tar)m(get)g(sub-domain)g(weights)f(for)i(each)e +(sub-domain)1162 8822 y(are)50 b(stored)g(contiguously)f(\(similar)i +(to)f(the)g Fj(vwgt)e FK(array\).)76 b(Note)50 b(that)g(the)g(sum)f(of) +h(all)g(of)g(the)g Fj(tpwgts)e FK(for)i(a)1162 9041 y(gi)l(v)n(e)41 +b(v)n(erte)n(x)g(weight)g(should)g(be)h(one.)415 9327 +y FD(ub)n(v)n(ec)336 b FK(An)42 b(array)g(of)g(size)f +Fj(ncon)f FK(that)i(is)g(used)f(to)h(specify)f(the)h(imbalance)f +(tolerance)g(for)i(each)e(v)n(erte)n(x)g(weight,)g(with)h(1)1162 +9546 y(being)47 b(perfect)g(balance)e(and)i Fj(nparts)d +FK(being)j(perfect)g(imbalance.)66 b(A)46 b(v)l(alue)g(of)h(1.05)g(for) +g(each)f(of)h(the)f Fj(ncon)1162 9765 y FK(weights)41 +b(is)h(recommended.)415 10051 y FD(options)231 b FK(This)36 +b(is)f(an)g(array)g(of)h(inte)n(gers)f(that)g(is)g(used)g(to)g(pass)g +(parameters)f(to)i(the)f(routine.)49 b(Their)36 b(meanings)f(are)g +(identical)1162 10270 y(to)42 b(those)f(of)h FA(P)-7 +b(arMETIS)p 2673 10270 V 61 w(V3)p 2937 10270 V 60 w(P)g(ar)7 +b(tKw)n(a)-5 b(y)p FK(.)415 10556 y FD(edgecut)203 b +FK(Upon)51 b(successful)f(completion,)k(the)d(number)g(of)h(edges)e +(that)h(are)g(cut)g(by)h(the)f(partitioning)h(is)f(written)h(to)f(this) +1162 10775 y(parameter)-9 b(.)3817 11298 y(19)p eop +%%Page: 20 20 +20 19 bop 415 166 a FD(part)443 b FK(This)33 b(is)f(an)f(array)i(of)f +(size)f(equal)h(to)g(the)g(number)h(of)f(locally-stored)g(v)n(ertices.) +47 b(Upon)32 b(successful)f(completion)h(the)1162 385 +y(partition)43 b(v)n(ector)d(of)i(the)g(locally-stored)f(v)n(ertices)g +(is)g(written)h(to)g(this)f(array)-11 b(.)51 b(\(See)42 +b(discussion)e(in)i(Section)g(4.4\).)415 671 y FD(comm)314 +b FK(This)45 b(is)e(a)h(pointer)g(to)g(the)g(MPI)g(communicator)h(of)f +(the)g(processes)e(that)i(call)k FA(P)-10 b FG(A)8 b(R)g +FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)t FK(.)46 b(F)n(or)e(most)g +(programs)1162 890 y(this)e(will)g(point)g(to)f Fj(MPI)p +2607 890 50 7 v 59 w(COMM)p 3066 890 V 58 w(WORLD)p FK(.)0 +1242 y FB(Note)415 1461 y FK(The)58 b(quality)g(of)g(the)g +(partitionings)g(computed)g(by)g FA(P)-7 b(arMETIS)p +4309 1461 V 61 w(V3)p 4573 1461 V 59 w(P)g(ar)7 b(tGeomKw)n(a)-5 +b(y)59 b FK(are)f(comparable)f(to)h(those)f(pro-)415 +1680 y(duced)41 b(by)h FA(P)-7 b(arMETIS)p 1829 1680 +V 61 w(V3)p 2093 1680 V 59 w(P)g(ar)7 b(tKw)n(a)-5 b(y)p +FK(.)51 b(Ho)l(we)l(v)n(er)-7 b(,)41 b(the)g(run)h(time)g(of)f(the)h +(routine)g(may)f(be)g(up)h(to)g(twice)f(as)g(f)n(ast.)3817 +11298 y(20)p eop +%%Page: 21 21 +21 20 bop 0 166 a FB(P)-5 b(arMETIS)p 780 166 50 7 v +60 w(V3)p 1043 166 V 60 w(P)g(ar)s(tGeom)42 b FK(\(idxtype)g(*vtxdist,) +f(int)h(*ndims,)f(\003oat)h(*xyz,)f(idxtype)g(*part,)g(MPI)p +5939 166 V 60 w(Comm)h(*comm\))0 684 y FB(Description)415 +903 y FK(This)64 b(routine)g(is)g(used)f(to)h(compute)g(a)82 +b Fy(p)5 b FK(-w)n(ay)65 b(partitioning)f(of)h(a)e(graph)h(on)83 +b Fy(p)69 b FK(processors)63 b(using)g(a)h(coordinate-based)415 +1122 y(space-\002lling)42 b(curv)n(es)e(method.)0 1474 +y FB(P)-5 b(arameter)n(s)415 1714 y FD(vtxdist)268 b +FK(This)39 b(array)g(describes)f(ho)l(w)g(the)h(v)n(ertices)f(of)h(the) +f(graph)h(are)g(distrib)m(uted)f(among)h(the)g(processors.)49 +b(\(See)39 b(discus-)1162 1933 y(sion)j(in)f(Section)h(4.1\).)51 +b(Its)41 b(contents)g(are)g(identical)h(for)g(e)l(v)n(ery)f(processor) +-9 b(.)415 2218 y FD(ndims)314 b FK(The)42 b(number)g(of)g(dimensions)f +(of)g(the)h(space)e(in)i(which)f(the)h(graph)f(is)g(embedded.)415 +2504 y FD(xyz)507 b FK(The)42 b(array)g(storing)f(the)h(coordinates)f +(of)h(the)f(v)n(ertices)f(\(described)h(in)h(Section)g(4.2\).)415 +2790 y FD(part)443 b FK(This)48 b(is)g(an)g(array)g(of)g(size)f(equal)g +(to)h(the)g(number)g(of)g(locally)g(stored)g(v)n(ertices.)69 +b(Upon)48 b(successful)e(completion)1162 3009 y(stores)41 +b(the)h(partition)g(v)n(ector)f(of)h(the)f(locally)h(stored)f(graph)g +(\(described)g(in)h(Section)g(4.4\).)415 3294 y FD(comm)314 +b FK(This)45 b(is)e(a)h(pointer)g(to)g(the)g(MPI)g(communicator)h(of)f +(the)g(processes)e(that)i(call)k FA(P)-10 b FG(A)8 b(R)g +FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)t FK(.)46 b(F)n(or)e(most)g +(programs)1162 3514 y(this)e(will)g(point)g(to)f Fj(MPI)p +2607 3514 V 59 w(COMM)p 3066 3514 V 58 w(WORLD)p FK(.)0 +3866 y FB(Note)415 4085 y FK(The)64 b(quality)h(of)f(the)h +(partitionings)f(computed)g(by)h FA(P)-7 b(arMETIS)p +4354 4085 V 60 w(V3)p 4617 4085 V 60 w(P)g(ar)7 b(tGeom)66 +b FK(are)e(signi\002cantly)g(w)n(orse)g(than)g(those)415 +4304 y(produced)41 b(by)h FA(P)-7 b(arMETIS)p 2050 4304 +V 61 w(V3)p 2314 4304 V 60 w(P)g(ar)7 b(tKw)n(a)-5 b(y)41 +b FK(and)h FA(P)-7 b(arMETIS)p 4158 4304 V 61 w(V3)p +4422 4304 V 59 w(P)g(ar)7 b(tGeomKw)n(a)-5 b(y)p FK(.)3817 +11298 y(21)p eop +%%Page: 22 22 +22 21 bop 0 166 a FB(P)-5 b(arMETIS)p 780 166 50 7 v +60 w(V3)p 1043 166 V 60 w(P)g(ar)s(tMeshKwa)m(y)43 b +FK(\(idxtype)f(*elmdist,)f(idxtype)h(*eptr)-7 b(,)42 +b(idxtype)f(*eind,)g(idxtype)h(*elmwgt,)2310 385 y(int)g(*wgt\003ag,)f +(int)h(*num\003ag,)g(int)f(*ncon,)g(int)h(*ncommonnodes,)f(int)g +(*nparts,)2310 604 y(\003oat)h(*tpwgts,)f(\003oat)h(*ub)n(v)n(ec,)d +(int)j(*options,)f(int)h(*edgecut,)e(idxtype)i(*part,)2310 +824 y(MPI)p 2615 824 V 60 w(Comm)g(*comm\))0 1342 y FB(Description)415 +1561 y FK(This)d(routine)h(is)f(used)f(to)h(compute)g(a)g +Fy(k)10 b FK(-w)n(ay)39 b(partitioning)h(of)f(a)g Fs(mesh)f +FK(on)58 b Fy(p)45 b FK(processors.)k(The)39 b(mesh)f(can)h(contain)g +(elements)415 1780 y(of)j(dif)l(ferent)g(types.)0 2132 +y FB(P)-5 b(arameter)n(s)415 2371 y FD(elmdist)231 b +FK(This)47 b(array)g(describes)e(ho)l(w)i(the)f(elements)g(of)h(the)f +(mesh)h(are)f(distrib)m(uted)g(among)h(the)g(processors.)65 +b(It)47 b(is)f(anal-)1162 2590 y(ogous)64 b(to)g(the)g +Fj(vtxdist)d FK(array)-11 b(.)119 b(Its)64 b(contents)f(are)h +(identical)g(for)g(e)l(v)n(ery)f(processor)-9 b(.)118 +b(\(See)64 b(discussion)f(in)1162 2809 y(Section)42 b(4.3\).)415 +3036 y FD(eptr)-15 b(,)41 b(eind)1162 3256 y FK(These)64 +b(arrays)g(speci\002es)f(the)g(elements)h(that)g(are)g(stored)g +(locally)g(at)g(each)f(processor)-9 b(.)118 b(\(See)64 +b(discussion)f(in)1162 3475 y(Section)42 b(4.3\).)415 +3760 y FD(elmwgt)231 b FK(This)42 b(array)g(stores)e(the)i(weights)f +(of)h(the)f(elements.)50 b(\(See)42 b(discussion)e(in)i(Section)g +(4.3\).)415 4046 y FD(wgt\003ag)231 b FK(This)42 b(is)f(used)g(to)h +(indicate)f(if)h(the)f(graph)h(is)f(weighted.)51 b Fs(wgt\003a)n(g)42 +b FK(can)f(tak)n(e)g(one)h(of)f(four)i(v)l(alues:)1162 +4332 y(0)166 b(No)42 b(weights)f(\(vwgt)h(and)f(adjwgt)h(are)f(both)g +(NULL\).)1162 4584 y(1)166 b(W)-13 b(eights)41 b(on)h(the)f(edges)g +(only)g(\(vwgt)h(is)f(NULL\).)1162 4836 y(2)166 b(W)-13 +b(eights)41 b(on)h(the)f(v)n(ertices)f(only)i(\(adjwgt)g(is)f(NULL\).) +1162 5089 y(3)166 b(W)-13 b(eights)41 b(on)h(both)f(the)h(v)n(ertices)e +(and)h(edges.)415 5374 y FD(num\003ag)167 b FK(This)41 +b(is)f(used)f(to)i(indicate)f(the)g(numbering)g(scheme)g(that)g(is)g +(used)f(for)i(the)f Fs(elmdist)p FK(,)g Fs(elements)p +FK(,)f(and)h Fs(part)g FK(arrays.)1162 5593 y Fs(num\003a)n(g)i +FK(can)f(tak)n(e)h(one)f(of)h(tw)n(o)g(v)l(alues:)1162 +5879 y(0)166 b(C-style)42 b(numbering)g(that)f(starts)g(from)h(0.)1162 +6131 y(1)166 b(F)n(ortran-style)42 b(numbering)g(that)g(starts)f(from)h +(1.)415 6417 y FD(ncon)406 b FK(This)47 b(is)e(used)h(to)g(specify)f +(the)h(number)g(of)h(weights)e(that)h(each)f(v)n(erte)n(x)g(has.)64 +b(It)46 b(is)g(also)g(the)f(number)i(of)f(balance)1162 +6636 y(constraints)41 b(that)h(must)f(be)h(satis\002ed.)415 +6833 y FD(ncommonnodes)1162 7052 y FK(This)i(parameter)g(determines)g +(the)f(de)n(gree)g(of)i(connecti)l(vity)e(among)h(the)g(v)n(ertices)f +(in)h(the)f(dual)h(graph.)58 b(Speci\002-)1162 7271 y(cally)-11 +b(,)43 b(an)f(edge)g(is)h(placed)f(between)g(an)n(y)f(tw)n(o)j +(elements)d(if)j(and)e(only)h(if)g(the)n(y)f(share)g(at)g(least)g(this) +h(man)n(y)f(nodes.)1162 7490 y(This)53 b(v)l(alue)e(should)h(be)g +(greater)g(than)g(zero,)i(and)e(for)h(most)f(meshes)f(a)h(v)l(alue)f +(of)i(tw)n(o)f(will)h(create)e(reasonable)1162 7710 y(dual)45 +b(graphs.)61 b(Ho)l(we)l(v)n(er)-7 b(,)44 b(depending)g(on)h(the)g +(type)g(of)g(elements)f(in)h(the)g(mesh,)f(v)l(alues)g(greater)h(than)g +(tw)n(o)g(may)1162 7929 y(also)50 b(be)g(v)l(alid)g(choices.)77 +b(F)n(or)50 b(e)n(xample,)h(for)g(meshes)f(containing)g(only)h +(triangular)-7 b(,)53 b(tetrahedral,)f(he)n(xahedral,)1162 +8148 y(or)42 b(rectangular)g(elements,)e(this)h(parameter)h(can)f(be)g +(set)g(to)g(tw)n(o,)h(three,)f(four)-7 b(,)42 b(or)g(tw)n(o,)f +(respecti)l(v)n(ely)-11 b(.)1162 8400 y(Note)51 b(that)f(setting)h +(this)f(parameter)g(to)h(a)f(small)h(v)l(alue)f(will)h(increase)e(the)h +(number)h(of)g(edges)f(in)g(the)h(resulting)1162 8620 +y(dual)42 b(graph)f(and)h(the)f(corresponding)g(partitioning)i(time.) +415 8905 y FD(nparts)286 b FK(This)54 b(is)f(used)g(to)h(specify)f(the) +g(number)h(of)f(sub-domains)g(that)h(are)f(desired.)87 +b(Note)53 b(that)g(the)h(number)f(of)h(sub-)1162 9124 +y(domains)42 b(is)f(independent)g(of)h(the)f(number)h(of)g(processors)e +(that)i(call)f(this)g(routine.)415 9410 y FD(tpwgts)277 +b FK(An)52 b(array)g(of)g(size)f Fj(ncon)g FK(x)h Fj(nparts)d +FK(that)j(is)g(used)f(to)h(specify)f(the)h(fraction)g(of)h(v)n(erte)n +(x)d(weight)i(that)g(should)1162 9629 y(be)44 b(distrib)m(uted)g(to)g +(each)f(sub-domain)h(for)h(each)e(balance)g(constraint.)58 +b(If)45 b(all)f(of)g(the)g(sub-domains)f(are)h(to)g(be)g(of)1162 +9848 y(the)e(same)e(size)h(for)h(e)l(v)n(ery)f(v)n(erte)n(x)f(weight,)h +(then)h(each)e(of)i(the)g Fj(ncon)e FK(x)h Fj(nparts)e +FK(elements)i(should)g(be)h(set)f(to)g(a)1162 10067 y(v)l(alue)c(of)g +(1/)p Fj(nparts)p FK(.)47 b(If)38 b Fj(ncon)d FK(is)i(greater)f(than)h +(one,)g(the)g(tar)m(get)g(sub-domain)g(weights)f(for)i(each)e +(sub-domain)1162 10287 y(are)50 b(stored)g(contiguously)f(\(similar)i +(to)f(the)g Fj(vwgt)e FK(array\).)76 b(Note)50 b(that)g(the)g(sum)f(of) +h(all)g(of)g(the)g Fj(tpwgts)e FK(for)i(a)1162 10506 +y(gi)l(v)n(e)41 b(v)n(erte)n(x)g(weight)g(should)g(be)h(one.)3817 +11298 y(22)p eop +%%Page: 23 23 +23 22 bop 415 166 a FD(ub)n(v)n(ec)336 b FK(An)42 b(array)g(of)g(size)f +Fj(ncon)f FK(that)i(is)g(used)f(to)h(specify)f(the)h(imbalance)f +(tolerance)g(for)i(each)e(v)n(erte)n(x)g(weight,)g(with)h(1)1162 +385 y(being)47 b(perfect)g(balance)e(and)i Fj(nparts)d +FK(being)j(perfect)g(imbalance.)66 b(A)46 b(v)l(alue)g(of)h(1.05)g(for) +g(each)f(of)h(the)f Fj(ncon)1162 604 y FK(weights)41 +b(is)h(recommended.)415 890 y FD(options)231 b FK(This)36 +b(is)f(an)g(array)g(of)h(inte)n(gers)f(that)g(is)g(used)g(to)g(pass)g +(parameters)f(to)i(the)f(routine.)49 b(Their)36 b(meanings)f(are)g +(identical)1162 1109 y(to)42 b(those)f(of)h FA(P)-7 b(arMETIS)p +2673 1109 50 7 v 61 w(V3)p 2937 1109 V 60 w(P)g(ar)7 +b(tKw)n(a)-5 b(y)p FK(.)415 1395 y FD(edgecut)203 b FK(Upon)51 +b(successful)f(completion,)k(the)d(number)g(of)h(edges)e(that)h(are)g +(cut)g(by)h(the)f(partitioning)h(is)f(written)h(to)f(this)1162 +1614 y(parameter)-9 b(.)415 1900 y FD(part)443 b FK(This)33 +b(is)f(an)f(array)i(of)f(size)f(equal)h(to)g(the)g(number)h(of)f +(locally-stored)g(v)n(ertices.)47 b(Upon)32 b(successful)f(completion)h +(the)1162 2119 y(partition)43 b(v)n(ector)d(of)i(the)g(locally-stored)f +(v)n(ertices)g(is)g(written)h(to)g(this)f(array)-11 b(.)51 +b(\(See)42 b(discussion)e(in)i(Section)g(4.4\).)415 2404 +y FD(comm)314 b FK(This)45 b(is)e(a)h(pointer)g(to)g(the)g(MPI)g +(communicator)h(of)f(the)g(processes)e(that)i(call)k +FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p +FA(S)t FK(.)46 b(F)n(or)e(most)g(programs)1162 2624 y(this)e(will)g +(point)g(to)f Fj(MPI)p 2607 2624 V 59 w(COMM)p 3066 2624 +V 58 w(WORLD)p FK(.)3817 11298 y(23)p eop +%%Page: 24 24 +24 23 bop 0 166 a Ft(5.2)199 b(Graph)54 b(Repar)t(titioning)0 +476 y FB(P)-5 b(arMETIS)p 780 476 50 7 v 60 w(V3)p 1043 +476 V 60 w(AdaptiveRepar)s(t)45 b FK(\(idxtype)d(*vtxdist,)f(idxtype)g +(*xadj,)g(idxtype)h(*adjnc)n(y)-11 b(,)40 b(idxtype)i(*vwgt,)f(idxtype) +h(*vsize,)2365 695 y(idxtype)f(*adjwgt,)g(int)h(*wgt\003ag,)f(int)h +(*num\003ag,)f(int)h(*ncon,)f(int)h(*nparts,)f(\003oat)h(*tpwgts,)2365 +914 y(\003oat)f(*ub)n(v)n(ec,)f(\003oat)i(*itr)-7 b(,)42 +b(int)g(*options,)f(int)g(*edgecut,)g(idxtype)g(*part,)2365 +1133 y(MPI)p 2670 1133 V 60 w(Comm)g(*comm\))0 1570 y +FB(Description)415 1789 y FK(This)h(routine)g(is)f(used)g(to)h(balance) +e(the)i(w)n(ork)g(load)f(of)h(a)f(graph)h(that)f(corresponds)g(to)h(an) +f(adapti)l(v)n(ely)g(re\002ned)g(mesh.)0 2123 y FB(P)-5 +b(arameter)n(s)415 2344 y FD(vtxdist)268 b FK(This)39 +b(array)g(describes)f(ho)l(w)g(the)h(v)n(ertices)f(of)h(the)f(graph)h +(are)g(distrib)m(uted)f(among)h(the)g(processors.)49 +b(\(See)39 b(discus-)1162 2563 y(sion)j(in)f(Section)h(4.1\).)51 +b(Its)41 b(contents)g(are)g(identical)h(for)g(e)l(v)n(ery)f(processor) +-9 b(.)415 2778 y FD(xadj,)42 b(adjncy)1162 2998 y FK(These)52 +b(store)g(the)h(\(local\))f(adjacenc)n(y)f(structure)h(of)h(the)f +(graph)g(at)h(each)e(processor)-9 b(.)83 b(\(See)52 b(discussion)f(in)i +(Sec-)1162 3217 y(tion)42 b(4.1\).)415 3426 y FD(vwgt,)f(adjwgt)1162 +3645 y FK(These)g(store)h(the)f(weights)g(of)h(the)f(v)n(ertices)g(and) +g(edges.)50 b(\(See)42 b(discussion)e(in)i(Section)f(4.1\).)415 +3912 y FD(vsize)405 b FK(This)46 b(array)f(stores)g(the)g(size)f(of)i +(the)f(v)n(ertices)f(with)i(respect)e(to)i(redistrib)m(ution)g(costs.) +61 b(Hence,)45 b(v)n(ertices)f(associ-)1162 4131 y(ated)j(with)g(mesh)g +(elements)f(that)h(require)h(a)e(lot)i(of)f(memory)h(will)f(ha)m(v)n(e) +f(lar)m(ger)h(corresponding)g(entries)g(in)g(this)1162 +4351 y(array)-11 b(.)52 b(Otherwise,)40 b(this)h(array)h(is)f(similar)h +(to)g(the)f Fj(vwgt)f FK(array)-11 b(.)51 b(\(See)42 +b(discussion)e(in)i(Section)g(4.1\).)415 4618 y FD(wgt\003ag)231 +b FK(This)42 b(is)f(used)g(to)h(indicate)f(if)h(the)f(graph)h(is)f +(weighted.)51 b Fs(wgt\003a)n(g)42 b FK(can)f(tak)n(e)g(one)h(of)f +(four)i(v)l(alues:)1162 4886 y(0)166 b(No)42 b(weights)f(\(vwgt)h(and)f +(adjwgt)h(are)f(both)g(NULL\).)1162 5129 y(1)166 b(W)-13 +b(eights)41 b(on)h(the)f(edges)g(only)g(\(vwgt)h(is)f(NULL\).)1162 +5372 y(2)166 b(W)-13 b(eights)41 b(on)h(the)f(v)n(ertices)f(only)i +(\(adjwgt)g(is)f(NULL\).)1162 5616 y(3)166 b(W)-13 b(eights)41 +b(on)h(both)f(the)h(v)n(ertices)e(and)h(edges.)415 5883 +y FD(num\003ag)167 b FK(This)58 b(is)f(used)g(to)h(indicate)f(the)g +(numbering)h(scheme)e(that)i(is)f(used)g(for)h(the)f +Fs(vtxdist)p FK(,)k Fs(xadj)p FK(,)f Fs(adjncy)p FK(,)h(and)c +Fs(part)1162 6102 y FK(arrays.)51 b Fs(num\003a)n(g)42 +b FK(can)f(tak)n(e)g(the)h(follo)l(wing)g(tw)n(o)g(v)l(alues:)1162 +6370 y(0)166 b(C-style)42 b(numbering)g(is)f(assumed)f(that)i(starts)f +(from)h(0)1162 6613 y(1)166 b(F)n(ortran-style)42 b(numbering)g(is)f +(assumed)g(that)g(starts)g(from)i(1)415 6881 y FD(ncon)406 +b FK(This)47 b(is)e(used)h(to)g(specify)f(the)h(number)g(of)h(weights)e +(that)h(each)f(v)n(erte)n(x)g(has.)64 b(It)46 b(is)g(also)g(the)f +(number)i(of)f(balance)1162 7100 y(constraints)41 b(that)h(must)f(be)h +(satis\002ed.)415 7367 y FD(nparts)286 b FK(This)54 b(is)f(used)g(to)h +(specify)f(the)g(number)h(of)f(sub-domains)g(that)h(are)f(desired.)87 +b(Note)53 b(that)g(the)h(number)f(of)h(sub-)1162 7587 +y(domains)42 b(is)f(independent)g(of)h(the)f(number)h(of)g(processors)e +(that)i(call)f(this)g(routine.)415 7854 y FD(tpwgts)277 +b FK(An)52 b(array)g(of)g(size)f Fj(ncon)g FK(x)h Fj(nparts)d +FK(that)j(is)g(used)f(to)h(specify)f(the)h(fraction)g(of)h(v)n(erte)n +(x)d(weight)i(that)g(should)1162 8073 y(be)44 b(distrib)m(uted)g(to)g +(each)f(sub-domain)h(for)h(each)e(balance)g(constraint.)58 +b(If)45 b(all)f(of)g(the)g(sub-domains)f(are)h(to)g(be)g(of)1162 +8292 y(the)e(same)e(size)h(for)h(e)l(v)n(ery)f(v)n(erte)n(x)f(weight,)h +(then)h(each)e(of)i(the)g Fj(ncon)e FK(x)h Fj(nparts)e +FK(elements)i(should)g(be)h(set)f(to)g(a)1162 8512 y(v)l(alue)c(of)g +(1/)p Fj(nparts)p FK(.)47 b(If)38 b Fj(ncon)d FK(is)i(greater)f(than)h +(one,)g(the)g(tar)m(get)g(sub-domain)g(weights)f(for)i(each)e +(sub-domain)1162 8731 y(are)50 b(stored)g(contiguously)f(\(similar)i +(to)f(the)g Fj(vwgt)e FK(array\).)76 b(Note)50 b(that)g(the)g(sum)f(of) +h(all)g(of)g(the)g Fj(tpwgts)e FK(for)i(a)1162 8950 y(gi)l(v)n(e)41 +b(v)n(erte)n(x)g(weight)g(should)g(be)h(one.)415 9217 +y FD(ub)n(v)n(ec)336 b FK(An)42 b(array)g(of)g(size)f +Fj(ncon)f FK(that)i(is)g(used)f(to)h(specify)f(the)h(imbalance)f +(tolerance)g(for)i(each)e(v)n(erte)n(x)g(weight,)g(with)h(1)1162 +9437 y(being)47 b(perfect)g(balance)e(and)i Fj(nparts)d +FK(being)j(perfect)g(imbalance.)66 b(A)46 b(v)l(alue)g(of)h(1.05)g(for) +g(each)f(of)h(the)f Fj(ncon)1162 9656 y FK(weights)41 +b(is)h(recommended.)415 9923 y FD(itr)572 b FK(This)43 +b(parameter)f(describes)f(the)h(ratio)h(of)g(inter)m(-processor)f +(communication)g(time)h(compared)f(to)g(data)g(redistri-)1162 +10142 y(b)m(ution)50 b(time.)75 b(It)50 b(should)f(be)g(set)g(between)f +(0.000001)h(and)h(1000000.0.)74 b(If)50 b(ITR)g(is)f(set)g(high,)i(a)e +(repartitioning)1162 10362 y(with)39 b(a)e(lo)l(w)h(edge-cut)g(will)h +(be)e(computed.)50 b(If)39 b(it)f(is)g(set)g(lo)l(w)-11 +b(,)38 b(a)g(repartitioning)h(that)f(requires)g(little)h(data)e +(redistri-)1162 10581 y(b)m(ution)i(will)g(be)f(computed.)50 +b(Good)38 b(v)l(alues)g(for)h(this)g(parameter)f(can)g(be)g(obtained)h +(by)f(di)l(viding)h(inter)m(-processor)1162 10800 y(communication)j +(time)g(by)f(data)g(redistrib)m(ution)h(time.)52 b(Otherwise,)40 +b(a)h(v)l(alue)g(of)h(1000.0)f(is)g(recommended.)3817 +11298 y(24)p eop +%%Page: 25 25 +25 24 bop 415 166 a FD(options)231 b FK(This)38 b(is)e(an)h(array)h(of) +f(inte)n(gers)f(that)h(is)g(used)g(to)g(pass)f(additional)h(parameters) +g(for)h(the)f(routine.)49 b(If)38 b Fs(options[0]=0)p +FK(,)1162 385 y(then)49 b(the)g(def)n(ault)g(v)l(alues)f(are)g(used.)72 +b(If)50 b Fs(options[0]=1)p FK(,)f(then)g(the)g(remaining)g(three)f +(elements)g(of)h Fs(options)g FK(are)1162 604 y(interpreted)42 +b(as)f(follo)l(ws:)1162 890 y(options[1])222 b(This)45 +b(speci\002es)f(the)h(le)l(v)n(el)f(of)h(information)g(to)g(be)g +(returned)g(during)g(the)g(e)n(x)n(ecution)e(of)i(the)g(algo-)2066 +1109 y(rithm.)61 b(T)-6 b(iming)46 b(information)f(can)f(be)h(obtained) +f(by)h(setting)f(this)g(to)h(1.)60 b(Additional)45 b(options)f(for)2066 +1328 y(this)i(parameter)f(can)f(be)h(obtained)g(by)h(looking)f(at)g +(the)g(the)g(\002le)h Fj(defs.h)d FK(in)i(the)g Fj(ParMETIS-)2066 +1548 y(Lib)39 b FK(directory)-11 b(.)51 b(The)40 b(numerical)g(v)l +(alues)f(there)h(should)f(be)h(added)f(to)h(obtain)g(the)g(correct)g(v) +l(alue.)2066 1767 y(The)i(def)n(ault)g(v)l(alue)f(is)g(0.)1162 +2019 y(options[2])222 b(This)42 b(is)f(the)h(random)g(number)f(seed)g +(for)h(the)f(routine.)52 b(The)42 b(def)n(ault)f(v)l(alue)h(is)f(15.) +1162 2271 y(options[3])222 b(This)51 b(speci\002es)e(whether)i(the)f +(sub-domains)g(and)g(processors)g(are)g(coupled)g(or)h(de-coupled.)77 +b(If)2066 2491 y(the)47 b(number)h(of)f(sub-domains)g(desired)f(\()p +Fs(i.e)p FK(.,)h Fj(nparts)p FK(\))f(and)g(the)h(number)h(of)f +(processors)f(that)2066 2710 y(are)k(being)g(used)f(is)h(not)g(the)g +(same,)h(then)f(these)f(must)h(be)g(de-coupled.)76 b(Ho)l(we)l(v)n(er) +-7 b(,)51 b(if)f Fj(nparts)2066 2929 y FK(equals)56 b(the)g(number)g +(of)h(processors,)h(these)d(can)h(either)g(be)g(coupled)f(or)i +(de-coupled.)94 b(If)57 b(sub-)2066 3148 y(domains)49 +b(and)g(processors)f(are)h(coupled,)h(then)f(the)g(initial)h +(partitioning)g(will)g(be)e(obtained)h(im-)2066 3367 +y(plicitly)66 b(from)f(the)g(graph)g(distrib)m(ution.)121 +b(Ho)l(we)l(v)n(er)-7 b(,)69 b(if)c(sub-domains)f(are)h(de-coupled)f +(from)2066 3587 y(processors,)44 b(then)g(the)g(initial)h(partitioning) +g(needs)f(to)g(be)h(obtained)f(from)h(the)f(initial)h(v)l(alues)e(as-) +2066 3806 y(signed)j(to)h(the)f Fj(part)f FK(array)-11 +b(.)66 b(A)46 b(v)l(alue)g(of)h(1)g(indicates)e(that)i(sub-domains)f +(and)g(processors)f(are)2066 4025 y(coupled)50 b(and)f(2)g(indicates)g +(that)g(these)g(are)g(de-coupled.)75 b(The)49 b(def)n(ault)h(v)l(alue)f +(is)g(1)h(\(coupled\))g(if)2066 4244 y Fj(nparts)40 b +FK(equals)g(the)i(number)g(of)f(processors)g(and)g(2)h(\(de-coupled\))f +(otherwise.)415 4530 y FD(edgecut)203 b FK(Upon)51 b(successful)f +(completion,)k(the)d(number)g(of)h(edges)e(that)h(are)g(cut)g(by)h(the) +f(partitioning)h(is)f(written)h(to)f(this)1162 4749 y(parameter)-9 +b(.)415 5034 y FD(part)443 b FK(This)33 b(is)f(an)f(array)i(of)f(size)f +(equal)h(to)g(the)g(number)h(of)f(locally-stored)g(v)n(ertices.)47 +b(Upon)32 b(successful)f(completion)h(the)1162 5254 y(partition)44 +b(v)n(ector)e(of)h(the)g(locally-stored)g(v)n(ertices)e(is)i(written)g +(to)g(this)f(array)-11 b(.)55 b(\(See)43 b(discussion)f(in)h(Section)g +(4.4\).)1162 5473 y(If)i(the)f(number)g(of)h(processors)d(does)i(not)g +(equal)g(the)g(number)g(of)g(sub-domains)g(and/or)g(options[3])h(is)f +(set)f(to)h(2,)1162 5692 y(then)38 b(the)g(pre)l(viously)g(computed)g +(partitioning)g(must)g(be)g(passed)f(to)h(the)g(routine)g(as)f(a)h +(parameter)g(via)f(this)h(array)-11 b(.)415 5978 y FD(comm)314 +b FK(This)45 b(is)e(a)h(pointer)g(to)g(the)g(MPI)g(communicator)h(of)f +(the)g(processes)e(that)i(call)k FA(P)-10 b FG(A)8 b(R)g +FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)t FK(.)46 b(F)n(or)e(most)g +(programs)1162 6197 y(this)e(will)g(point)g(to)f Fj(MPI)p +2607 6197 50 7 v 59 w(COMM)p 3066 6197 V 58 w(WORLD)p +FK(.)3817 11298 y(25)p eop +%%Page: 26 26 +26 25 bop 0 166 a Ft(5.3)199 b(P)-6 b(ar)t(titioning)56 +b(Re\002nement)0 471 y FB(P)-5 b(arMETIS)p 780 471 50 +7 v 60 w(V3)p 1043 471 V 60 w(Re\002neKwa)m(y)43 b FK(\(idxtype)f +(*vtxdist,)f(idxtype)h(*xadj,)f(idxtype)g(*adjnc)n(y)-11 +b(,)41 b(idxtype)g(*vwgt,)h(idxtype)f(*adjwgt,)2072 690 +y(int)h(*wgt\003ag,)f(int)h(*num\003ag,)f(int)h(*ncon,)f(int)h +(*nparts,)f(\003oat)g(*tpwgts,)g(\003oat)h(*ub)n(v)n(ec,)2072 +909 y(int)g(*options,)f(int)h(*edgecut,)e(idxtype)i(*part,)f(MPI)p +5112 909 V 60 w(Comm)h(*comm\))0 1299 y FB(Description)415 +1518 y FK(This)i(routine)h(is)f(used)f(to)i(impro)n(v)n(e)e(the)h +(quality)h(of)f(an)g(e)n(xisting)g(a)f Fy(k)10 b FK(-w)n(ay)44 +b(partitioning)h(on)64 b Fy(p)49 b FK(processors)43 b(using)h(the)g +(multi-)415 1738 y(le)l(v)n(el)d Fy(k)10 b FK(-w)n(ay)41 +b(re\002nement)h(algorithm.)0 2061 y FB(P)-5 b(arameter)n(s)415 +2272 y FD(vtxdist)268 b FK(This)39 b(array)g(describes)f(ho)l(w)g(the)h +(v)n(ertices)f(of)h(the)f(graph)h(are)g(distrib)m(uted)f(among)h(the)g +(processors.)49 b(\(See)39 b(discus-)1162 2491 y(sion)j(in)f(Section)h +(4.1\).)51 b(Its)41 b(contents)g(are)g(identical)h(for)g(e)l(v)n(ery)f +(processor)-9 b(.)415 2696 y FD(xadj,)42 b(adjncy)1162 +2915 y FK(These)52 b(store)g(the)h(\(local\))f(adjacenc)n(y)f +(structure)h(of)h(the)f(graph)g(at)h(each)e(processor)-9 +b(.)83 b(\(See)52 b(discussion)f(in)i(Sec-)1162 3134 +y(tion)42 b(4.1\).)415 3333 y FD(vwgt,)f(adjwgt)1162 +3552 y FK(These)g(store)h(the)f(weights)g(of)h(the)f(v)n(ertices)g(and) +g(edges.)50 b(\(See)42 b(discussion)e(in)i(Section)f(4.1\).)415 +3809 y FD(ncon)406 b FK(This)47 b(is)e(used)h(to)g(specify)f(the)h +(number)g(of)h(weights)e(that)h(each)f(v)n(erte)n(x)g(has.)64 +b(It)46 b(is)g(also)g(the)f(number)i(of)f(balance)1162 +4028 y(constraints)41 b(that)h(must)f(be)h(satis\002ed.)415 +4286 y FD(nparts)286 b FK(This)54 b(is)f(used)g(to)h(specify)f(the)g +(number)h(of)f(sub-domains)g(that)h(are)f(desired.)87 +b(Note)53 b(that)g(the)h(number)f(of)h(sub-)1162 4505 +y(domains)42 b(is)f(independent)g(of)h(the)f(number)h(of)g(processors)e +(that)i(call)f(this)g(routine.)415 4762 y FD(wgt\003ag)231 +b FK(This)42 b(is)f(used)g(to)h(indicate)f(if)h(the)f(graph)h(is)f +(weighted.)51 b Fs(wgt\003a)n(g)42 b FK(can)f(tak)n(e)g(one)h(of)f +(four)i(v)l(alues:)1162 5019 y(0)166 b(No)42 b(weights)f(\(vwgt)h(and)f +(adjwgt)h(are)f(both)g(NULL\).)1162 5257 y(1)166 b(W)-13 +b(eights)41 b(on)h(the)f(edges)g(only)g(\(vwgt)h(is)f(NULL\).)1162 +5496 y(2)166 b(W)-13 b(eights)41 b(on)h(the)f(v)n(ertices)f(only)i +(\(adjwgt)g(is)f(NULL\).)1162 5734 y(3)166 b(W)-13 b(eights)41 +b(on)h(both)f(the)h(v)n(ertices)e(and)h(edges.)415 5991 +y FD(num\003ag)167 b FK(This)58 b(is)f(used)g(to)h(indicate)f(the)g +(numbering)h(scheme)e(that)i(is)f(used)g(for)h(the)f +Fs(vtxdist)p FK(,)k Fs(xadj)p FK(,)f Fs(adjncy)p FK(,)h(and)c +Fs(part)1162 6210 y FK(arrays.)51 b Fs(num\003a)n(g)42 +b FK(can)f(tak)n(e)g(the)h(follo)l(wing)g(tw)n(o)g(v)l(alues:)1162 +6467 y(0)166 b(C-style)42 b(numbering)g(is)f(assumed)f(that)i(starts)f +(from)h(0)1162 6706 y(1)166 b(F)n(ortran-style)42 b(numbering)g(is)f +(assumed)g(that)g(starts)g(from)i(1)415 6963 y FD(tpwgts)277 +b FK(An)52 b(array)g(of)g(size)f Fj(ncon)g FK(x)h Fj(nparts)d +FK(that)j(is)g(used)f(to)h(specify)f(the)h(fraction)g(of)h(v)n(erte)n +(x)d(weight)i(that)g(should)1162 7182 y(be)44 b(distrib)m(uted)g(to)g +(each)f(sub-domain)h(for)h(each)e(balance)g(constraint.)58 +b(If)45 b(all)f(of)g(the)g(sub-domains)f(are)h(to)g(be)g(of)1162 +7401 y(the)e(same)e(size)h(for)h(e)l(v)n(ery)f(v)n(erte)n(x)f(weight,)h +(then)h(each)e(of)i(the)g Fj(ncon)e FK(x)h Fj(nparts)e +FK(elements)i(should)g(be)h(set)f(to)g(a)1162 7620 y(v)l(alue)c(of)g +(1/)p Fj(nparts)p FK(.)47 b(If)38 b Fj(ncon)d FK(is)i(greater)f(than)h +(one,)g(the)g(tar)m(get)g(sub-domain)g(weights)f(for)i(each)e +(sub-domain)1162 7839 y(are)50 b(stored)g(contiguously)f(\(similar)i +(to)f(the)g Fj(vwgt)e FK(array\).)76 b(Note)50 b(that)g(the)g(sum)f(of) +h(all)g(of)g(the)g Fj(tpwgts)e FK(for)i(a)1162 8059 y(gi)l(v)n(e)41 +b(v)n(erte)n(x)g(weight)g(should)g(be)h(one.)415 8316 +y FD(ub)n(v)n(ec)336 b FK(An)42 b(array)g(of)g(size)f +Fj(ncon)f FK(that)i(is)g(used)f(to)h(specify)f(the)h(imbalance)f +(tolerance)g(for)i(each)e(v)n(erte)n(x)g(weight,)g(with)h(1)1162 +8535 y(being)47 b(perfect)g(balance)e(and)i Fj(nparts)d +FK(being)j(perfect)g(imbalance.)66 b(A)46 b(v)l(alue)g(of)h(1.05)g(for) +g(each)f(of)h(the)f Fj(ncon)1162 8754 y FK(weights)41 +b(is)h(recommended.)415 9011 y FD(options)231 b FK(This)36 +b(is)f(an)g(array)g(of)h(inte)n(gers)f(that)g(is)g(used)g(to)g(pass)g +(parameters)f(to)i(the)f(routine.)49 b(Their)36 b(meanings)f(are)g +(identical)1162 9231 y(to)42 b(those)f(of)h FA(P)-7 b(arMETIS)p +2673 9231 V 61 w(V3)p 2937 9231 V 60 w(P)g(ar)7 b(tKw)n(a)-5 +b(y)p FK(.)415 9488 y FD(edgecut)203 b FK(Upon)51 b(successful)f +(completion,)k(the)d(number)g(of)h(edges)e(that)h(are)g(cut)g(by)h(the) +f(partitioning)h(is)f(written)h(to)f(this)1162 9707 y(parameter)-9 +b(.)415 9964 y FD(part)443 b FK(This)33 b(is)f(an)f(array)i(of)f(size)f +(equal)h(to)g(the)g(number)h(of)f(locally-stored)g(v)n(ertices.)47 +b(Upon)32 b(successful)f(completion)h(the)1162 10183 +y(partition)43 b(v)n(ector)d(of)i(the)g(locally-stored)f(v)n(ertices)g +(is)g(written)h(to)g(this)f(array)-11 b(.)51 b(\(See)42 +b(discussion)e(in)i(Section)g(4.4\).)415 10440 y FD(comm)314 +b FK(This)45 b(is)e(a)h(pointer)g(to)g(the)g(MPI)g(communicator)h(of)f +(the)g(processes)e(that)i(call)k FA(P)-10 b FG(A)8 b(R)g +FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)t FK(.)46 b(F)n(or)e(most)g +(programs)1162 10660 y(this)e(will)g(point)g(to)f Fj(MPI)p +2607 10660 V 59 w(COMM)p 3066 10660 V 58 w(WORLD)p FK(.)3817 +11298 y(26)p eop +%%Page: 27 27 +27 26 bop 0 166 a Ft(5.4)199 b(Fill-reducing)55 b(Or)l(derings)0 +485 y FB(P)-5 b(arMETIS)p 780 485 50 7 v 60 w(V3)p 1043 +485 V 60 w(NodeND)42 b FK(\(idxtype)g(*vtxdist,)f(idxtype)h(*xadj,)f +(idxtype)g(*adjnc)n(y)-11 b(,)41 b(int)h(*num\003ag,)f(int)h(*options,) +1789 704 y(idxtype)g(*order)-7 b(,)42 b(idxtype)f(*sizes,)f(MPI)p +4172 704 V 60 w(Comm)i(*comm\))0 1222 y FB(Description)415 +1441 y FK(This)g(routine)g(is)f(used)g(to)h(compute)f(a)g +(\002ll-reducing)i(ordering)f(of)f(a)h(sparse)e(matrix)i(using)g +(multile)l(v)n(el)f(nested)g(dissection.)0 1793 y FB(P)-5 +b(arameter)n(s)415 2032 y FD(vtxdist)268 b FK(This)39 +b(array)g(describes)f(ho)l(w)g(the)h(v)n(ertices)f(of)h(the)f(graph)h +(are)g(distrib)m(uted)f(among)h(the)g(processors.)49 +b(\(See)39 b(discus-)1162 2252 y(sion)j(in)f(Section)h(4.1\).)51 +b(Its)41 b(contents)g(are)g(identical)h(for)g(e)l(v)n(ery)f(processor) +-9 b(.)415 2485 y FD(xadj,)42 b(adjncy)1162 2704 y FK(These)56 +b(store)h(the)f(\(local\))h(adjacenc)n(y)e(structure)i(of)g(the)f +(graph)h(at)f(each)g(processor)g(\(See)h(discussion)e(in)i(Sec-)1162 +2923 y(tion)42 b(4.1\).)415 3209 y FD(num\003ag)167 b +FK(This)53 b(is)f(used)g(to)h(indicate)f(the)h(numbering)g(scheme)f +(that)g(is)g(used)g(for)i(the)e Fs(vtxdist)p FK(,)j Fs(xadj)p +FK(,)f Fs(adjncy)p FK(,)h(and)d Fs(or)-6 b(der)1162 3428 +y FK(arrays.)51 b Fs(num\003a)n(g)42 b FK(can)f(tak)n(e)g(the)h(follo)l +(wing)g(tw)n(o)g(v)l(alues:)1162 3714 y(0)166 b(C-style)42 +b(numbering)g(is)f(assumed)f(that)i(starts)f(from)h(0)1162 +3966 y(1)166 b(F)n(ortran-style)42 b(numbering)g(is)f(assumed)g(that)g +(starts)g(from)i(1)415 4252 y FD(options)231 b FK(This)36 +b(is)f(an)g(array)g(of)h(inte)n(gers)f(that)g(is)g(used)g(to)g(pass)g +(parameters)f(to)i(the)f(routine.)49 b(Their)36 b(meanings)f(are)g +(identical)1162 4471 y(to)42 b(those)f(of)h FA(P)-7 b(arMETIS)p +2673 4471 V 61 w(V3)p 2937 4471 V 60 w(P)g(ar)7 b(tKw)n(a)-5 +b(y)p FK(.)415 4756 y FD(order)350 b FK(This)42 b(array)g(returns)f +(the)h(result)f(of)h(the)f(ordering)h(\(described)f(in)h(Section)g +(4.4\).)415 5042 y FD(sizes)423 b FK(This)51 b(array)f(returns)h(the)f +(number)g(of)h(nodes)f(for)g(each)g(sub-domain)g(and)g(each)g +(separator)g(\(described)f(in)i(Sec-)1162 5261 y(tion)42 +b(4.4\).)415 5547 y FD(comm)314 b FK(This)45 b(is)e(a)h(pointer)g(to)g +(the)g(MPI)g(communicator)h(of)f(the)g(processes)e(that)i(call)k +FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p +FA(S)t FK(.)46 b(F)n(or)e(most)g(programs)1162 5766 y(this)e(will)g +(point)g(to)f Fj(MPI)p 2607 5766 V 59 w(COMM)p 3066 5766 +V 58 w(WORLD)p FK(.)0 6118 y FB(Note)415 6337 y FA(P)-7 +b(arMETIS)p 1183 6337 V 61 w(V3)p 1447 6337 V 60 w(NodeND)42 +b FK(requires)f(that)h(the)f(number)h(of)g(processors)e(be)i(a)f(po)l +(wer)g(of)h(2.)3817 11298 y(27)p eop +%%Page: 28 28 +28 27 bop 0 166 a Ft(5.5)199 b(Mesh)55 b(to)g(Graph)g(T)-16 +b(ranslation)0 485 y FB(P)-5 b(arMETIS)p 780 485 50 7 +v 60 w(V3)p 1043 485 V 60 w(Mesh2Dual)44 b FK(\(idxtype)e(*elmdist,)f +(idxtype)g(*eptr)-7 b(,)42 b(idxtype)g(*eind,)f(int)g(*num\003ag,)2011 +704 y(int)h(*ncommonnodes,)e(idxtype)i(**xadj,)f(idxtype)g(**adjnc)n(y) +-11 b(,)41 b(MPI)p 6043 704 V 60 w(Comm)h(*comm\))0 1222 +y FB(Description)415 1441 y FK(This)e(routine)h(is)e(used)h(to)g +(construct)g(a)f(distrib)m(uted)h(graph)h(gi)l(v)n(en)e(a)h(distrib)m +(uted)g(mesh.)50 b(It)40 b(can)f(be)h(used)g(in)g(conjunction)g(with) +415 1660 y(other)i(routines)f(in)h(the)j FA(P)-10 b FG(A)8 +b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)48 b FK(library)-11 +b(.)52 b(The)42 b(mesh)f(can)g(contain)g(elements)g(of)h(dif)l(ferent)g +(types.)0 2012 y FB(P)-5 b(arameter)n(s)415 2252 y FD(elmdist)231 +b FK(This)47 b(array)g(describes)e(ho)l(w)i(the)f(elements)g(of)h(the)f +(mesh)h(are)f(distrib)m(uted)g(among)h(the)g(processors.)65 +b(It)47 b(is)f(anal-)1162 2471 y(ogous)64 b(to)g(the)g +Fj(vtxdist)d FK(array)-11 b(.)119 b(Its)64 b(contents)f(are)h +(identical)g(for)g(e)l(v)n(ery)f(processor)-9 b(.)118 +b(\(See)64 b(discussion)f(in)1162 2690 y(Section)42 b(4.3\).)415 +2917 y FD(eptr)-15 b(,)41 b(eind)1162 3136 y FK(These)64 +b(arrays)g(speci\002es)f(the)g(elements)h(that)g(are)g(stored)g +(locally)g(at)g(each)f(processor)-9 b(.)118 b(\(See)64 +b(discussion)f(in)1162 3355 y(Section)42 b(4.3\).)415 +3641 y FD(num\003ag)167 b FK(This)52 b(is)g(used)f(to)h(indicate)f(the) +h(numbering)g(scheme)f(that)h(is)f(used)h(for)g(the)g +Fs(elmdist)p FK(,)h Fs(elements)p FK(,)g Fs(xadj)p FK(,)h +Fs(adjncy)p FK(,)1162 3860 y(and)42 b Fs(part)f FK(arrays.)51 +b Fs(num\003a)n(g)41 b FK(can)g(tak)n(e)h(one)f(of)h(tw)n(o)g(v)l +(alues:)1162 4146 y(0)166 b(C-style)42 b(numbering)g(that)f(starts)g +(from)h(0.)1162 4398 y(1)166 b(F)n(ortran-style)42 b(numbering)g(that)g +(starts)f(from)h(1.)415 4629 y FD(ncommonnodes)1162 4848 +y FK(This)i(parameter)g(determines)g(the)f(de)n(gree)g(of)i(connecti)l +(vity)e(among)h(the)g(v)n(ertices)f(in)h(the)f(dual)h(graph.)58 +b(Speci\002-)1162 5067 y(cally)-11 b(,)43 b(an)f(edge)g(is)h(placed)f +(between)g(an)n(y)f(tw)n(o)j(elements)d(if)j(and)e(only)h(if)g(the)n(y) +f(share)g(at)g(least)g(this)h(man)n(y)f(nodes.)1162 5286 +y(This)53 b(v)l(alue)e(should)h(be)g(greater)g(than)g(zero,)i(and)e +(for)h(most)f(meshes)f(a)h(v)l(alue)f(of)i(tw)n(o)f(will)h(create)e +(reasonable)1162 5505 y(dual)45 b(graphs.)61 b(Ho)l(we)l(v)n(er)-7 +b(,)44 b(depending)g(on)h(the)g(type)g(of)g(elements)f(in)h(the)g +(mesh,)f(v)l(alues)g(greater)h(than)g(tw)n(o)g(may)1162 +5724 y(also)50 b(be)g(v)l(alid)g(choices.)77 b(F)n(or)50 +b(e)n(xample,)h(for)g(meshes)f(containing)g(only)h(triangular)-7 +b(,)53 b(tetrahedral,)f(he)n(xahedral,)1162 5944 y(or)42 +b(rectangular)g(elements,)e(this)h(parameter)h(can)f(be)g(set)g(to)g +(tw)n(o,)h(three,)f(four)-7 b(,)42 b(or)g(tw)n(o,)f(respecti)l(v)n(ely) +-11 b(.)1162 6196 y(Note)51 b(that)f(setting)h(this)f(parameter)g(to)h +(a)f(small)h(v)l(alue)f(will)h(increase)e(the)h(number)h(of)g(edges)f +(in)g(the)h(resulting)1162 6415 y(dual)42 b(graph)f(and)h(the)f +(corresponding)g(partitioning)i(time.)415 6649 y FD(xadj,)f(adjncy)1162 +6868 y FK(Upon)37 b(the)f(successful)e(completion)j(of)f(the)h +(routine,)g(pointers)f(to)h(the)f(constructed)g Fj(xadj)e +FK(and)i Fj(adjncy)e FK(arrays)1162 7087 y(will)42 b(be)f(written)h(to) +g(these)f(parameters.)50 b(\(See)42 b(discussion)e(in)i(Section)f +(4.1\).)415 7373 y FD(comm)314 b FK(This)45 b(is)e(a)h(pointer)g(to)g +(the)g(MPI)g(communicator)h(of)f(the)g(processes)e(that)i(call)k +FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p +FA(S)t FK(.)46 b(F)n(or)e(most)g(programs)1162 7592 y(this)e(will)g +(point)g(to)f Fj(MPI)p 2607 7592 V 59 w(COMM)p 3066 7592 +V 58 w(WORLD)p FK(.)0 7944 y FB(Note)415 8163 y FK(This)48 +b(routine)f(can)g(be)g(used)g(in)g(conjunction)h(with)f +FA(P)-7 b(arMETIS)p 4227 8163 V 61 w(V3)p 4491 8163 V +60 w(P)g(ar)7 b(tKw)n(a)-5 b(y)p FK(,)48 b FA(P)-7 b(arMETIS)p +6102 8163 V 61 w(V3)p 6366 8163 V 60 w(P)g(ar)7 b(tGeomKw)n(a)-5 +b(y)p FK(,)50 b(or)415 8382 y FA(P)-7 b(arMETIS)p 1183 +8382 V 61 w(V3)p 1447 8382 V 60 w(Adaptiv)l(eRepar)7 +b(t)p FK(.)53 b(It)42 b(typically)f(runs)h(in)f(half)h(the)g(time)f +(required)h(by)g FA(P)-7 b(arMETIS)p 6452 8382 V 61 w(V3)p +6716 8382 V 59 w(P)g(ar)7 b(tKw)n(a)-5 b(y)p FK(.)3817 +11298 y(28)p eop +%%Page: 29 29 +29 28 bop 0 170 a FE(6)233 b(Har)-5 b(d)m(ware)66 b(&)e(Software)i +(Requirements,)g(and)e(Contact)i(Inf)-5 b(ormation)4 +522 y FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g +FG(I)p FA(S)72 b FK(is)64 b(written)i(in)f(ANSI)h(C)f(and)g(uses)f(MPI) +h(for)h(inter)m(-processor)e(communication.)122 b(Instructions)66 +b(on)f(ho)l(w)g(to)g(b)m(uild)4 741 y FA(P)-10 b FG(A)8 +b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)60 b FK(are)53 +b(a)m(v)l(ailable)f(in)h(the)h Fj(INSTALL)c FK(\002le.)87 +b(In)53 b(the)h(directory)f(called)g Fj(Graphs)p FK(,)h(you)f(will)h +(\002nd)f(programs)h(that)f(tests)g(if)4 960 y FA(P)-10 +b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)57 +b FK(w)n(as)50 b(b)m(uilt)g(correctly)-11 b(.)78 b(Also,)52 +b(a)e(header)g(\002le)g(called)g Fj(parmetis.h)c FK(is)51 +b(pro)n(vided)f(that)g(contains)g(prototypes)g(for)h(the)0 +1179 y(functions)42 b(in)j FA(P)-10 b FG(A)8 b(R)g FA(M)-9 +b FG(E)-34 b FA(T)g FG(I)p FA(S)t FK(.)199 1398 y(In)54 +b(order)g(to)g(use)j FA(P)-10 b FG(A)8 b(R)g FA(M)-9 +b FG(E)-34 b FA(T)g FG(I)p FA(S)61 b FK(in)54 b(your)g(application)f +(you)h(need)f(to)h(ha)m(v)n(e)f(a)g(cop)n(y)h(of)g(the)g(serial)j +FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)61 b FK(library)54 +b(and)g(link)g(your)0 1617 y(program)49 b(with)g(both)g(libraries)f(\() +p Fs(i.e)p FK(.,)h Fj(libparmetis.a)44 b FK(and)k Fj(libmetis.a)p +FK(\).)69 b(Note)48 b(that)g(the)53 b FA(P)-10 b FG(A)8 +b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)55 b FK(package)47 +b(already)0 1837 y(contains)41 b(the)g(source)g(code)g(for)h(the)k +FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)48 b FK(library)-11 +b(.)52 b(The)41 b(included)h(Mak)n(e\002les)e(automatically)i +(construct)f(both)h(libraries.)203 2056 y FA(P)-10 b +FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g FG(I)p FA(S)76 +b FK(ha)m(v)n(e)69 b(been)g(e)n(xtensi)l(v)n(ely)f(tested)h(on)h(a)f +(number)h(of)g(dif)l(ferent)g(parallel)g(computers.)135 +b(Ho)l(we)l(v)n(er)-7 b(,)75 b(e)l(v)n(en)69 b(though)4 +2275 y FA(P)-10 b FG(A)8 b(R)g FA(M)-9 b FG(E)-34 b FA(T)g +FG(I)p FA(S)47 b FK(contains)41 b(no)f(kno)l(wn)h(b)m(ugs,)f(this)h +(does)f(not)h(mean)f(that)h(all)g(of)g(its)g(b)m(ugs)f(ha)m(v)n(e)f +(been)i(found)g(and)g(\002x)n(ed.)50 b(If)41 b(you)g(ha)m(v)n(e)f(an)n +(y)0 2494 y(problems,)h(please)f(send)h(email)h(to)f +Fs([email protected])e FK(with)j(a)f(brief)h(description)g(of)f(the)h +(problem.)0 2986 y FE(Ref)n(erences)75 3319 y Ff([1])82 +b(R.)33 b(Bisw)o(as)f(and)h(R.)g(Stra)n(wn.)45 b(A)33 +b(ne)l(w)g(procedure)f(for)h(dynamic)g(adaption)e(of)i +(three-dimensional)e(unstructured)g(grids.)44 b Fe(Applied)32 +b(Numerical)332 3520 y(Mathematics)p Ff(,)37 b(13:437\226452,)d(1994.) +75 3754 y([2])82 b(C.)53 b(Fiduccia)f(and)h(R.)g(Matthe)n(yses.)103 +b(A)52 b(linear)h(time)f(heuristic)g(for)g(impro)n(ving)e(netw)o(ork)h +(partitions.)101 b(In)52 b Fe(In)h(Pr)-7 b(oc.)54 b(19th)d(IEEE)j +(Design)332 3955 y(A)m(utomation)35 b(Confer)-6 b(ence)p +Ff(,)38 b(pages)g(175\226181,)d(1982.)75 4190 y([3])82 +b(J.)40 b(Fingber)m(g,)f(A.)h(Basermann,)h(G.)f(Lonsdale,)g(J.)g +(Clinck)o(emaillie,)e(J.)i(Gratien,)g(and)f(R.)h(Ducloux.)60 +b(Dynamic)39 b(load-balancing)f(for)h(parallel)332 4390 +y(structural)d(mechanics)i(simulations)d(with)i(DRAMA.)53 +b Fe(ECT2000)p Ff(,)37 b(2000.)75 4625 y([4])82 b(G.)43 +b(Karypis)f(and)h(V)-19 b(.)43 b(K)n(umar)-8 b(.)72 b(A)42 +b(coarse-grain)h(parallel)f(multile)l(v)n(el)f Fc(k)9 +b Ff(-w)o(ay)43 b(partitioning)c(algorithm.)70 b(In)43 +b Fe(Pr)-7 b(oceedings)43 b(of)f(the)h(8th)f(SIAM)332 +4825 y(confer)-6 b(ence)38 b(on)f(P)-12 b(ar)n(allel)36 +b(Pr)-7 b(ocessing)38 b(for)f(Scienti\002c)f(Computing)p +Ff(,)f(1997.)75 5060 y([5])82 b(G.)37 b(Karypis)f(and)g(V)-19 +b(.)37 b(K)n(umar)-8 b(.)56 b Fa(M)-7 b Fb(E)-29 b Fa(T)g +Fb(I)q Fa(S)t Ff(:)33 b(A)j(softw)o(are)g(package)h(for)f(partitioning) +d(unstructured)i(graphs,)h(partitioning)d(meshes,)38 +b(and)f(comput-)332 5261 y(ing)h(\002ll-reducing)f(orderings)g(of)h +(sparse)i(matrices,)g(v)n(ersion)d(4.0.)59 b(T)-10 b(echnical)39 +b(report,)f(Uni)l(v)-10 b(.)39 b(of)f(MN,)h(Dept.)g(of)f(Computer)g +(Sci.)h(and)g(Engr)-8 b(.,)332 5461 y(1998.)75 5696 y([6])82 +b(G.)38 b(Karypis)e(and)h(V)-19 b(.)38 b(K)n(umar)-8 +b(.)53 b(Multile)l(v)n(el)35 b(algorithms)h(for)h(multi-constraint)d +(graph)i(partitioning.)51 b(In)37 b Fe(Pr)-7 b(oc.)38 +b(Super)-6 b(computing)36 b('98)p Ff(,)h(1998.)75 5930 +y([7])82 b(G.)49 b(Karypis)e(and)h(V)-19 b(.)48 b(K)n(umar)-8 +b(.)89 b(Multile)l(v)n(el)46 b Fc(k)9 b Ff(-w)o(ay)48 +b(partitioning)d(scheme)k(for)f(irre)n(gular)e(graphs.)89 +b Fe(J)l(ournal)47 b(of)h(P)-12 b(ar)n(allel)47 b(and)g(Distrib)m(uted) +332 6131 y(Computing)p Ff(,)35 b(48\(1\),)h(1998.)75 +6365 y([8])82 b(G.)42 b(Karypis)f(and)h(V)-19 b(.)42 +b(K)n(umar)-8 b(.)68 b(P)n(arallel)41 b(multile)l(v)n(el)f +Fc(k)9 b Ff(-w)o(ay)41 b(partitioning)e(scheme)k(for)e(irre)n(gular)f +(graphs.)68 b Fe(Siam)41 b(Re)n(vie)n(w)p Ff(,)i(41\(2\):278\226300,) +332 6566 y(1999.)75 6800 y([9])82 b(B.)60 b(K)l(ernighan)e(and)h(S.)h +(Lin.)125 b(An)59 b(ef)l(\002cient)h(heuristic)e(procedure)h(for)g +(partitioning)d(graphs.)124 b Fe(The)60 b(Bell)f(System)h(T)-14 +b(ec)n(hnical)58 b(J)l(ournal)p Ff(,)332 7001 y(49\(2\):291\226307,)34 +b(1970.)0 7235 y([10])82 b(L.)31 b(Olik)o(er)e(and)h(R.)h(Bisw)o(as.)38 +b(PLUM:)30 b(P)n(arallel)g(load)g(balancing)g(for)f(adapti)l(v)n(e)h +(unstructured)f(meshes.)40 b Fe(J)l(ournal)30 b(of)f(P)-12 +b(ar)n(allel)29 b(and)h(Distrib)m(uted)332 7436 y(Computing)p +Ff(,)35 b(52\(2\):150\226177,)f(1998.)0 7670 y([11])82 +b(A.)47 b(P)n(atra)h(and)f(D.)g(Kim.)85 b(Ef)l(\002cient)47 +b(mesh)h(partitioning)c(for)i(adapti)l(v)n(e)i Fc(h)11 +b(p)51 b Ff(\002nite)c(element)g(meshes.)87 b(T)-10 b(echnical)47 +b(report,)i(Dept.)e(of)f(Mech.)332 7871 y(Engr)-8 b(.,)37 +b(SUNY)g(at)h(Buf)l(f)o(alo,)e(1999.)0 8105 y([12])82 +b(A.)43 b(Pothen,)h(H.)f(Simon,)h(L.)g(W)-12 b(ang,)44 +b(and)f(S.)h(Bernard.)71 b(T)-12 b(o)l(w)o(ards)43 b(a)g(f)o(ast)f +(implementation)f(of)i(spectral)f(nested)h(dissection.)71 +b(In)42 b Fe(Super)-6 b(com-)332 8306 y(puting)35 b('92)i(Pr)-7 +b(oceedings)p Ff(,)38 b(pages)g(42\22651,)e(1992.)0 8540 +y([13])82 b(K.)34 b(Schloe)n(gel,)h(G.)f(Karypis,)g(and)g(V)-19 +b(.)34 b(K)n(umar)-8 b(.)47 b(A)34 b(ne)l(w)g(algorithm)e(for)i +(multi-objecti)l(v)n(e)d(graph)j(partitioning.)43 b(In)34 +b Fe(Pr)-7 b(oc.)35 b(Eur)-7 b(oP)-12 b(ar)34 b('99)p +Ff(,)h(pages)332 8741 y(322\226331,)h(1999.)0 8975 y([14])82 +b(K.)54 b(Schloe)n(gel,)j(G.)d(Karypis,)j(and)c(V)-19 +b(.)54 b(K)n(umar)-8 b(.)105 b(P)n(arallel)53 b(multile)l(v)n(el)f +(algorithms)g(for)g(multi-constraint)f(graph)h(partitioning.)103 +b(In)53 b Fe(Pr)-7 b(oc.)332 9176 y(Eur)g(oP)-12 b(ar)m(-2000)p +Ff(,)37 b(2000.)53 b(Accepted)37 b(as)h(a)g(Distinguished)d(P)n(aper)-8 +b(.)0 9410 y([15])82 b(K.)50 b(Schloe)n(gel,)h(G.)f(Karypis,)i(and)d(V) +-19 b(.)49 b(K)n(umar)-8 b(.)92 b(A)49 b(uni\002ed)g(algorithm)e(for)i +(load-balancing)e(adapti)l(v)n(e)i(scienti\002c)g(simulations.)90 +b(In)49 b Fe(Pr)-7 b(oc.)332 9611 y(Super)h(computing)35 +b(2000)p Ff(,)i(2000.)0 9845 y([16])82 b(K.)38 b(Schloe)n(gel,)g(G.)h +(Karypis,)e(and)h(V)-19 b(.)38 b(K)n(umar)-8 b(.)57 b(W)-12 +b(a)m(v)n(efront)37 b(dif)l(fusion)f(and)i(LMSR:)f(Algorithms)f(for)i +(dynamic)f(repartitioning)e(of)j(adapti)l(v)n(e)332 10046 +y(meshes.)55 b Fe(IEEE)38 b(T)-8 b(r)n(ansactions)36 +b(on)g(P)-12 b(ar)n(allel)36 b(and)h(Distrib)m(uted)e(Systems)p +Ff(,)j(12\(5\):451\226466,)c(2001.)0 10280 y([17])82 +b(J.)47 b(W)-12 b(atts,)49 b(M.)e(Rief)l(fel,)i(and)e(S.)g(T)-12 +b(aylor)k(.)83 b(A)47 b(load)f(balancing)g(technique)f(for)h +(multi-phase)g(computations.)82 b Fe(Pr)-7 b(oc.)48 b(of)e(High)g(P)-12 +b(erformance)332 10481 y(Computing)35 b(`97)p Ff(,)i(pages)g(15\22620,) +f(1997.)3817 11298 y FK(29)p eop +%%Trailer +end +userdict /end-hook known{end-hook}if +%%EOF diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/Makefile b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/Makefile new file mode 100644 index 0000000..3281a07 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/Makefile @@ -0,0 +1,48 @@ +include ../Makefile.in + + +CFLAGS = $(COPTIONS) $(OPTFLAGS) -I. $(INCDIR) + + +OBJS = comm.o util.o debug.o setup.o grsetup.o timer.o \ + node_refine.o initmsection.o order.o \ + xyzpart.o pspases.o frename.o \ + iintsort.o iidxsort.o ikeysort.o ikeyvalsort.o \ + kmetis.o gkmetis.o ometis.o \ + initpart.o match.o coarsen.o \ + kwayfm.o kwayrefine.o kwaybalance.o \ + remap.o stat.o fpqueue.o \ + ametis.o rmetis.o lmatch.o initbalance.o \ + mdiffusion.o diffutil.o wave.o \ + csrmatch.o redomylink.o balancemylink.o \ + selectq.o akwayfm.o serial.o move.o \ + mmetis.o mesh.o memory.o weird.o backcompat.o + +.c.o: + $(CC) $(CFLAGS) -c $*.c + + +../libparmetis.a: $(OBJS) + $(AR) $@ $(OBJS) + $(RANLIB) $@ + +clean: + rm -f *.o + +realclean: + rm -f *.o ; rm -f ../libparmetis.a + + +checkin: + @for file in *.[c,h]; \ + do \ + ci -u -m'Maintance' $$file;\ + done + +checkin2: + @for file in *.[c,h]; \ + do \ + ci $$file;\ + rcs -U $$file;\ + co $$file;\ + done diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/adrivers.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/adrivers.c new file mode 100644 index 0000000..e9c5fe0 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/adrivers.c @@ -0,0 +1,117 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * adrivers.c + * + * This file contains the driving routines for the various parallel + * multilevel partitioning and repartitioning algorithms + * + * Started 11/19/96 + * George + * + * $Id: adrivers.c,v 1.5 2003/07/30 18:37:58 karypis Exp $ + * + */ + +#include <parmetislib.h> + + + +/************************************************************************* +* This function is the driver for the adaptive refinement mode of ParMETIS +**************************************************************************/ +void Adaptive_Partition(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int i; + int tewgt, tvsize; + float gtewgt, gtvsize; + float ubavg, lbavg, lbvec[MAXNCON]; + + /************************************/ + /* Set up important data structures */ + /************************************/ + SetUp(ctrl, graph, wspace); + + ubavg = savg(graph->ncon, ctrl->ubvec); + tewgt = idxsum(graph->nedges, graph->adjwgt); + tvsize = idxsum(graph->nvtxs, graph->vsize); + gtewgt = (float) GlobalSESum(ctrl, tewgt) + 1.0; /* The +1 were added to remove any FPE */ + gtvsize = (float) GlobalSESum(ctrl, tvsize) + 1.0; + ctrl->redist_factor = ctrl->redist_base * ((gtewgt/gtvsize)/ ctrl->edge_size_ratio); + + IFSET(ctrl->dbglvl, DBG_PROGRESS, rprintf(ctrl, "[%6d %8d %5d %5d][%d]\n", + graph->gnvtxs, GlobalSESum(ctrl, graph->nedges), GlobalSEMin(ctrl, graph->nvtxs), GlobalSEMax(ctrl, graph->nvtxs), ctrl->CoarsenTo)); + + if (graph->gnvtxs < 1.3*ctrl->CoarsenTo || + (graph->finer != NULL && graph->gnvtxs > graph->finer->gnvtxs*COARSEN_FRACTION)) { + + /***********************************************/ + /* Balance the partition on the coarsest graph */ + /***********************************************/ + graph->where = idxsmalloc(graph->nvtxs+graph->nrecv, -1, "graph->where"); + idxcopy(graph->nvtxs, graph->home, graph->where); + + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + lbavg = savg(graph->ncon, lbvec); + + if (lbavg > ubavg + 0.035 && ctrl->partType != REFINE_PARTITION) + Balance_Partition(ctrl, graph, wspace); + + if (ctrl->dbglvl&DBG_PROGRESS) { + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + rprintf(ctrl, "nvtxs: %10d, balance: ", graph->gnvtxs); + for (i=0; i<graph->ncon; i++) + rprintf(ctrl, "%.3f ", lbvec[i]); + rprintf(ctrl, "\n"); + } + + /* check if no coarsening took place */ + if (graph->finer == NULL) { + Moc_ComputePartitionParams(ctrl, graph, wspace); + Moc_KWayBalance(ctrl, graph, wspace, graph->ncon); + Moc_KWayAdaptiveRefine(ctrl, graph, wspace, NGR_PASSES); + } + } + else { + /*******************************/ + /* Coarsen it and partition it */ + /*******************************/ + switch (ctrl->ps_relation) { + case COUPLED: + Mc_LocalMatch_HEM(ctrl, graph, wspace); + break; + case DISCOUPLED: + default: + Moc_GlobalMatch_Balance(ctrl, graph, wspace); + break; + } + + Adaptive_Partition(ctrl, graph->coarser, wspace); + + /********************************/ + /* project partition and refine */ + /********************************/ + Moc_ProjectPartition(ctrl, graph, wspace); + Moc_ComputePartitionParams(ctrl, graph, wspace); + + if (graph->ncon > 1 && graph->level < 4) { + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + lbavg = savg(graph->ncon, lbvec); + + if (lbavg > ubavg + 0.025) { + Moc_KWayBalance(ctrl, graph, wspace, graph->ncon); + } + } + + Moc_KWayAdaptiveRefine(ctrl, graph, wspace, NGR_PASSES); + + if (ctrl->dbglvl&DBG_PROGRESS) { + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + rprintf(ctrl, "nvtxs: %10d, cut: %8d, balance: ", graph->gnvtxs, graph->mincut); + for (i=0; i<graph->ncon; i++) + rprintf(ctrl, "%.3f ", lbvec[i]); + rprintf(ctrl, "\n"); + } + } +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/akwayfm.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/akwayfm.c new file mode 100644 index 0000000..7579d8b --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/akwayfm.c @@ -0,0 +1,629 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * makwayfm.c + * + * This file contains code that performs the k-way refinement + * + * Started 3/1/96 + * George + * + * $Id: akwayfm.c,v 1.3 2003/07/22 22:58:18 karypis Exp $ + */ + +#include <parmetislib.h> + +#define ProperSide(c, from, other) \ + (((c) == 0 && (from)-(other) < 0) || ((c) == 1 && (from)-(other) > 0)) + + +/************************************************************************* +* This function performs k-way refinement +**************************************************************************/ +void Moc_KWayAdaptiveRefine(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace, int npasses) +{ + int h, i, ii, iii, j, k, c; + int pass, nvtxs, nedges, ncon; + int nmoves, nmoved; + int me, firstvtx, lastvtx, yourlastvtx; + int from, to = -1, oldto, oldcut, mydomain, yourdomain, imbalanced, overweight; + int npes = ctrl->npes, mype = ctrl->mype, nparts = ctrl->nparts; + int nlupd, nsupd, nnbrs, nchanged; + idxtype *xadj, *ladjncy, *adjwgt, *vtxdist; + idxtype *where, *tmp_where, *moved; + float *lnpwgts, *gnpwgts, *ognpwgts, *pgnpwgts, *movewgts, *overfill; + idxtype *update, *supdate, *rupdate, *pe_updates; + idxtype *changed, *perm, *pperm, *htable; + idxtype *peind, *recvptr, *sendptr; + KeyValueType *swchanges, *rwchanges; + RInfoType *rinfo, *myrinfo, *tmp_myrinfo, *tmp_rinfo; + EdgeType *tmp_edegrees, *my_edegrees, *your_edegrees; + float lbvec[MAXNCON], *nvwgt, *badmaxpwgt, *ubvec, *tpwgts, lbavg, ubavg; + float oldgain, gain; + float ipc_factor, redist_factor, vsize; + int *nupds_pe, ndirty, nclean, dptr; + int better, worse; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->KWayTmr)); + + /*************************/ + /* set up common aliases */ + /*************************/ + nvtxs = graph->nvtxs; + nedges = graph->nedges; + ncon = graph->ncon; + + vtxdist = graph->vtxdist; + xadj = graph->xadj; + ladjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + firstvtx = vtxdist[mype]; + lastvtx = vtxdist[mype+1]; + + where = graph->where; + rinfo = graph->rinfo; + lnpwgts = graph->lnpwgts; + gnpwgts = graph->gnpwgts; + ubvec = ctrl->ubvec; + tpwgts = ctrl->tpwgts; + ipc_factor = ctrl->ipc_factor; + redist_factor = ctrl->redist_factor; + + nnbrs = graph->nnbrs; + peind = graph->peind; + recvptr = graph->recvptr; + sendptr = graph->sendptr; + + changed = idxmalloc(nvtxs, "AKWR: changed"); + rwchanges = wspace->pairs; + swchanges = rwchanges + recvptr[nnbrs]; + + /************************************/ + /* set up important data structures */ + /************************************/ + perm = idxmalloc(nvtxs, "AKWR: perm"); + pperm = idxmalloc(nparts, "AKWR: pperm"); + + update = idxmalloc(nvtxs, "AKWR: update"); + supdate = wspace->indices; + rupdate = supdate + recvptr[nnbrs]; + nupds_pe = imalloc(npes, "AKWR: nupds_pe"); + htable = idxsmalloc(nvtxs+graph->nrecv, 0, "AKWR: lhtable"); + badmaxpwgt = fmalloc(nparts*ncon, "badmaxpwgt"); + + for (i=0; i<nparts; i++) { + for (h=0; h<ncon; h++) { + badmaxpwgt[i*ncon+h] = ubvec[h]*tpwgts[i*ncon+h]; + } + } + + movewgts = fmalloc(ncon*nparts, "AKWR: movewgts"); + ognpwgts = fmalloc(nparts*ncon, "AKWR: ognpwgts"); + pgnpwgts = fmalloc(nparts*ncon, "AKWR: pgnpwgts"); + overfill = fmalloc(nparts*ncon, "AKWR: overfill"); + moved = idxmalloc(nvtxs, "AKWR: moved"); + tmp_where = idxmalloc(nvtxs+graph->nrecv, "AKWR: tmp_where"); + tmp_rinfo = (RInfoType *)GKmalloc(sizeof(RInfoType)*nvtxs, "AKWR: tmp_rinfo"); + tmp_edegrees = (EdgeType *)GKmalloc(sizeof(EdgeType)*nedges, "AKWR: tmp_edegrees"); + + idxcopy(nvtxs+graph->nrecv, where, tmp_where); + for (i=0; i<nvtxs; i++) { + tmp_rinfo[i].id = rinfo[i].id; + tmp_rinfo[i].ed = rinfo[i].ed; + tmp_rinfo[i].ndegrees = rinfo[i].ndegrees; + tmp_rinfo[i].degrees = tmp_edegrees+xadj[i]; + + for (j=0; j<rinfo[i].ndegrees; j++) { + tmp_rinfo[i].degrees[j].edge = rinfo[i].degrees[j].edge; + tmp_rinfo[i].degrees[j].ewgt = rinfo[i].degrees[j].ewgt; + } + } + + /*********************************************************/ + /* perform a small number of passes through the vertices */ + /*********************************************************/ + for (pass=0; pass<npasses; pass++) { + oldcut = graph->mincut; + if (mype == 0) + RandomPermute(nparts, pperm, 1); + MPI_Bcast((void *)pperm, nparts, IDX_DATATYPE, 0, ctrl->comm); +/* FastRandomPermute(nvtxs, perm, 1); */ + + /*****************************/ + /* move dirty vertices first */ + /*****************************/ + ndirty = 0; + for (i=0; i<nvtxs; i++) + if (where[i] != mype) + ndirty++; + + dptr = 0; + for (i=0; i<nvtxs; i++) + if (where[i] != mype) + perm[dptr++] = i; + else + perm[ndirty++] = i; + + ASSERT(ctrl, ndirty == nvtxs); + ndirty = dptr; + nclean = nvtxs-dptr; + FastRandomPermute(ndirty, perm, 0); + FastRandomPermute(nclean, perm+ndirty, 0); + + /* check to see if the partitioning is imbalanced */ + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + ubavg = savg(ncon, ubvec); + lbavg = savg(ncon, lbvec); + imbalanced = (lbavg > ubavg) ? 1 : 0; + + for (c=0; c<2; c++) { + scopy(ncon*nparts, gnpwgts, ognpwgts); + sset(ncon*nparts, 0.0, movewgts); + nmoved = 0; + + /**********************************************/ + /* PASS ONE -- record stats for desired moves */ + /**********************************************/ + for (iii=0; iii<nvtxs; iii++) { + i = perm[iii]; + from = tmp_where[i]; + nvwgt = graph->nvwgt+i*ncon; + vsize = (float)(graph->vsize[i]); + + for (h=0; h<ncon; h++) { + if (fabs(nvwgt[h]-gnpwgts[from*ncon+h]) < SMALLFLOAT) + break; + } + if (h < ncon) + continue; + + /* only check border vertices */ + if (tmp_rinfo[i].ed <= 0) + continue; + + my_edegrees = tmp_rinfo[i].degrees; + + for (k=0; k<tmp_rinfo[i].ndegrees; k++) { + to = my_edegrees[k].edge; + if (ProperSide(c, pperm[from], pperm[to])) { + for (h=0; h<ncon; h++) { + if (gnpwgts[to*ncon+h]+nvwgt[h] > badmaxpwgt[to*ncon+h] && nvwgt[h] > 0.0) + break; + } + if (h == ncon) + break; + } + } + oldto = to; + + /* check if a subdomain was found that fits */ + if (k < tmp_rinfo[i].ndegrees) { + /**************************/ + /**************************/ + switch (ctrl->ps_relation) { + case COUPLED: + better = (oldto == mype) ? 1 : 0; + worse = (from == mype) ? 1 : 0; + break; + case DISCOUPLED: + default: + better = (oldto == graph->home[i]) ? 1 : 0; + worse = (from == graph->home[i]) ? 1 : 0; + break; + } + /**************************/ + /**************************/ + + oldgain = ipc_factor * (float)(my_edegrees[k].ewgt-tmp_rinfo[i].id); + if (better) oldgain += redist_factor * vsize; + if (worse) oldgain -= redist_factor * vsize; + + for (j=k+1; j<tmp_rinfo[i].ndegrees; j++) { + to = my_edegrees[j].edge; + if (ProperSide(c, pperm[from], pperm[to])) { + /**************************/ + /**************************/ + switch (ctrl->ps_relation) { + case COUPLED: + better = (to == mype) ? 1 : 0; + break; + case DISCOUPLED: + default: + better = (to == graph->home[i]) ? 1 : 0; + break; + } + /**************************/ + /**************************/ + + gain = ipc_factor * (float)(my_edegrees[j].ewgt-tmp_rinfo[i].id); + if (better) gain += redist_factor * vsize; + if (worse) gain -= redist_factor * vsize; + + for (h=0; h<ncon; h++) + if (gnpwgts[to*ncon+h]+nvwgt[h] > badmaxpwgt[to*ncon+h] && nvwgt[h] > 0.0) + break; + + if (h == ncon) { + if (gain > oldgain || + (fabs(gain-oldgain) < SMALLFLOAT && + IsHBalanceBetterTT(ncon,gnpwgts+oldto*ncon,gnpwgts+to*ncon,nvwgt,ubvec))){ + oldgain = gain; + oldto = to; + k = j; + } + } + } + } + to = oldto; + gain = oldgain; + + if (gain > 0.0 || + (gain > -1.0*SMALLFLOAT && + (imbalanced || graph->level > 3 || iii % 8 == 0) && + IsHBalanceBetterFT(ncon,gnpwgts+from*ncon,gnpwgts+to*ncon,nvwgt,ubvec))){ + + /****************************************/ + /* Update tmp arrays of the moved vertex */ + /****************************************/ + tmp_where[i] = to; + moved[nmoved++] = i; + for (h=0; h<ncon; h++) { + INC_DEC(lnpwgts[to*ncon+h], lnpwgts[from*ncon+h], nvwgt[h]); + INC_DEC(gnpwgts[to*ncon+h], gnpwgts[from*ncon+h], nvwgt[h]); + INC_DEC(movewgts[to*ncon+h], movewgts[from*ncon+h], nvwgt[h]); + } + + tmp_rinfo[i].ed += tmp_rinfo[i].id-my_edegrees[k].ewgt; + SWAP(tmp_rinfo[i].id, my_edegrees[k].ewgt, j); + if (my_edegrees[k].ewgt == 0) { + tmp_rinfo[i].ndegrees--; + my_edegrees[k].edge = my_edegrees[tmp_rinfo[i].ndegrees].edge; + my_edegrees[k].ewgt = my_edegrees[tmp_rinfo[i].ndegrees].ewgt; + } + else { + my_edegrees[k].edge = from; + } + + /* Update the degrees of adjacent vertices */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + /* no need to bother about vertices on different pe's */ + if (ladjncy[j] >= nvtxs) + continue; + + me = ladjncy[j]; + mydomain = tmp_where[me]; + + myrinfo = tmp_rinfo+me; + your_edegrees = myrinfo->degrees; + + if (mydomain == from) { + INC_DEC(myrinfo->ed, myrinfo->id, adjwgt[j]); + } + else { + if (mydomain == to) { + INC_DEC(myrinfo->id, myrinfo->ed, adjwgt[j]); + } + } + + /* Remove contribution from the .ed of 'from' */ + if (mydomain != from) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (your_edegrees[k].edge == from) { + if (your_edegrees[k].ewgt == adjwgt[j]) { + myrinfo->ndegrees--; + your_edegrees[k].edge = your_edegrees[myrinfo->ndegrees].edge; + your_edegrees[k].ewgt = your_edegrees[myrinfo->ndegrees].ewgt; + } + else { + your_edegrees[k].ewgt -= adjwgt[j]; + } + break; + } + } + } + + /* Add contribution to the .ed of 'to' */ + if (mydomain != to) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (your_edegrees[k].edge == to) { + your_edegrees[k].ewgt += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + your_edegrees[myrinfo->ndegrees].edge = to; + your_edegrees[myrinfo->ndegrees++].ewgt = adjwgt[j]; + } + } + } + } + } + } + + /******************************************/ + /* Let processors know the subdomain wgts */ + /* if all proposed moves commit. */ + /******************************************/ + MPI_Allreduce((void *)lnpwgts, (void *)pgnpwgts, nparts*ncon, MPI_FLOAT, MPI_SUM, ctrl->comm); + + /**************************/ + /* compute overfill array */ + /**************************/ + overweight = 0; + for (j=0; j<nparts; j++) { + for (h=0; h<ncon; h++) { + if (pgnpwgts[j*ncon+h] > ognpwgts[j*ncon+h]) + overfill[j*ncon+h] = (pgnpwgts[j*ncon+h]-badmaxpwgt[j*ncon+h]) / (pgnpwgts[j*ncon+h]-ognpwgts[j*ncon+h]); + else + overfill[j*ncon+h] = 0.0; + + overfill[j*ncon+h] = amax(overfill[j*ncon+h], 0.0); + overfill[j*ncon+h] *= movewgts[j*ncon+h]; + + if (overfill[j*ncon+h] > 0.0) + overweight = 1; + + ASSERTP(ctrl, ognpwgts[j*ncon+h] <= badmaxpwgt[j*ncon+h] || pgnpwgts[j*ncon+h] <= ognpwgts[j*ncon+h], + (ctrl, "%.4f %.4f %.4f\n", ognpwgts[j*ncon+h], badmaxpwgt[j*ncon+h], pgnpwgts[j*ncon+h])); + } + } + + /****************************************************/ + /* select moves to undo according to overfill array */ + /****************************************************/ + if (overweight == 1) { + for (iii=0; iii<nmoved; iii++) { + i = moved[iii]; + oldto = tmp_where[i]; + nvwgt = graph->nvwgt+i*ncon; + my_edegrees = tmp_rinfo[i].degrees; + + for (k=0; k<tmp_rinfo[i].ndegrees; k++) + if (my_edegrees[k].edge == where[i]) + break; + + for (h=0; h<ncon; h++) + if (nvwgt[h] > 0.0 && overfill[oldto*ncon+h] > nvwgt[h]/4.0) + break; + + /**********************************/ + /* nullify this move if necessary */ + /**********************************/ + if (k != tmp_rinfo[i].ndegrees && h != ncon) { + moved[iii] = -1; + from = oldto; + to = where[i]; + + for (h=0; h<ncon; h++) + overfill[oldto*ncon+h] = amax(overfill[oldto*ncon+h]-nvwgt[h], 0.0); + + tmp_where[i] = to; + tmp_rinfo[i].ed += tmp_rinfo[i].id-my_edegrees[k].ewgt; + SWAP(tmp_rinfo[i].id, my_edegrees[k].ewgt, j); + if (my_edegrees[k].ewgt == 0) { + tmp_rinfo[i].ndegrees--; + my_edegrees[k].edge = my_edegrees[tmp_rinfo[i].ndegrees].edge; + my_edegrees[k].ewgt = my_edegrees[tmp_rinfo[i].ndegrees].ewgt; + } + else { + my_edegrees[k].edge = from; + } + + for (h=0; h<ncon; h++) + INC_DEC(lnpwgts[to*ncon+h], lnpwgts[from*ncon+h], nvwgt[h]); + + /* Update the degrees of adjacent vertices */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + /* no need to bother about vertices on different pe's */ + if (ladjncy[j] >= nvtxs) + continue; + + me = ladjncy[j]; + mydomain = tmp_where[me]; + + myrinfo = tmp_rinfo+me; + your_edegrees = myrinfo->degrees; + + if (mydomain == from) { + INC_DEC(myrinfo->ed, myrinfo->id, adjwgt[j]); + } + else { + if (mydomain == to) { + INC_DEC(myrinfo->id, myrinfo->ed, adjwgt[j]); + } + } + + /* Remove contribution from the .ed of 'from' */ + if (mydomain != from) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (your_edegrees[k].edge == from) { + if (your_edegrees[k].ewgt == adjwgt[j]) { + myrinfo->ndegrees--; + your_edegrees[k].edge = your_edegrees[myrinfo->ndegrees].edge; + your_edegrees[k].ewgt = your_edegrees[myrinfo->ndegrees].ewgt; + } + else { + your_edegrees[k].ewgt -= adjwgt[j]; + } + break; + } + } + } + + /* Add contribution to the .ed of 'to' */ + if (mydomain != to) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (your_edegrees[k].edge == to) { + your_edegrees[k].ewgt += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + your_edegrees[myrinfo->ndegrees].edge = to; + your_edegrees[myrinfo->ndegrees++].ewgt = adjwgt[j]; + } + } + } + } + } + } + + /*************************************************/ + /* PASS TWO -- commit the remainder of the moves */ + /*************************************************/ + nlupd = nsupd = nmoves = nchanged = 0; + for (iii=0; iii<nmoved; iii++) { + i = moved[iii]; + if (i == -1) + continue; + + where[i] = tmp_where[i]; + + /* Make sure to update the vertex information */ + if (htable[i] == 0) { + /* make sure you do the update */ + htable[i] = 1; + update[nlupd++] = i; + } + + /* Put the vertices adjacent to i into the update array */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = ladjncy[j]; + if (htable[k] == 0) { + htable[k] = 1; + if (k<nvtxs) + update[nlupd++] = k; + else + supdate[nsupd++] = k; + } + } + nmoves++; + + if (graph->pexadj[i+1]-graph->pexadj[i] > 0) + changed[nchanged++] = i; + } + + /* Tell interested pe's the new where[] info for the interface vertices */ + CommChangedInterfaceData(ctrl, graph, nchanged, changed, where, swchanges, rwchanges, wspace->pv4); + + + IFSET(ctrl->dbglvl, DBG_RMOVEINFO, rprintf(ctrl, "\t[%d %d], [%.4f], [%d %d %d]\n", + pass, c, badmaxpwgt[0], GlobalSESum(ctrl, nmoves), GlobalSESum(ctrl, nsupd), GlobalSESum(ctrl, nlupd))); + + /*------------------------------------------------------------- + / Time to communicate with processors to send the vertices + / whose degrees need to be update. + /-------------------------------------------------------------*/ + /* Issue the receives first */ + for (i=0; i<nnbrs; i++) + MPI_Irecv((void *)(rupdate+sendptr[i]), sendptr[i+1]-sendptr[i], IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->rreq+i); + + /* Issue the sends next. This needs some preporcessing */ + for (i=0; i<nsupd; i++) { + htable[supdate[i]] = 0; + supdate[i] = graph->imap[supdate[i]]; + } + iidxsort(nsupd, supdate); + + for (j=i=0; i<nnbrs; i++) { + yourlastvtx = vtxdist[peind[i]+1]; + for (k=j; k<nsupd && supdate[k] < yourlastvtx; k++); + MPI_Isend((void *)(supdate+j), k-j, IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->sreq+i); + j = k; + } + + /* OK, now get into the loop waiting for the send/recv operations to finish */ + MPI_Waitall(nnbrs, ctrl->rreq, ctrl->statuses); + for (i=0; i<nnbrs; i++) + MPI_Get_count(ctrl->statuses+i, IDX_DATATYPE, nupds_pe+i); + MPI_Waitall(nnbrs, ctrl->sreq, ctrl->statuses); + + + /*------------------------------------------------------------- + / Place the recieved to-be updated vertices into update[] + /-------------------------------------------------------------*/ + for (i=0; i<nnbrs; i++) { + pe_updates = rupdate+sendptr[i]; + for (j=0; j<nupds_pe[i]; j++) { + k = pe_updates[j]; + if (htable[k-firstvtx] == 0) { + htable[k-firstvtx] = 1; + update[nlupd++] = k-firstvtx; + } + } + } + + + /*------------------------------------------------------------- + / Update the rinfo of the vertices in the update[] array + /-------------------------------------------------------------*/ + for (ii=0; ii<nlupd; ii++) { + i = update[ii]; + ASSERT(ctrl, htable[i] == 1); + + htable[i] = 0; + + mydomain = where[i]; + myrinfo = rinfo+i; + tmp_myrinfo = tmp_rinfo+i; + my_edegrees = myrinfo->degrees; + your_edegrees = tmp_myrinfo->degrees; + + graph->lmincut -= myrinfo->ed; + myrinfo->ndegrees = 0; + myrinfo->id = 0; + myrinfo->ed = 0; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + yourdomain = where[ladjncy[j]]; + if (mydomain != yourdomain) { + myrinfo->ed += adjwgt[j]; + + for (k=0; k<myrinfo->ndegrees; k++) { + if (my_edegrees[k].edge == yourdomain) { + my_edegrees[k].ewgt += adjwgt[j]; + your_edegrees[k].ewgt += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + my_edegrees[k].edge = yourdomain; + my_edegrees[k].ewgt = adjwgt[j]; + your_edegrees[k].edge = yourdomain; + your_edegrees[k].ewgt = adjwgt[j]; + myrinfo->ndegrees++; + } + ASSERT(ctrl, myrinfo->ndegrees <= xadj[i+1]-xadj[i]); + ASSERT(ctrl, tmp_myrinfo->ndegrees <= xadj[i+1]-xadj[i]); + + } + else { + myrinfo->id += adjwgt[j]; + } + } + graph->lmincut += myrinfo->ed; + + tmp_myrinfo->id = myrinfo->id; + tmp_myrinfo->ed = myrinfo->ed; + tmp_myrinfo->ndegrees = myrinfo->ndegrees; + } + + /* finally, sum-up the partition weights */ + MPI_Allreduce((void *)lnpwgts, (void *)gnpwgts, nparts*ncon, MPI_FLOAT, MPI_SUM, ctrl->comm); + } + graph->mincut = GlobalSESum(ctrl, graph->lmincut)/2; + + if (graph->mincut == oldcut) + break; + } + + GKfree((void **)&badmaxpwgt, (void **)&update, (void **)&nupds_pe, (void **)&htable, LTERM); + GKfree((void **)&changed, (void **)&pperm, (void **)&perm, (void **)&moved, LTERM); + GKfree((void **)&pgnpwgts, (void **)&ognpwgts, (void **)&overfill, (void **)&movewgts, LTERM); + GKfree((void **)&tmp_where, (void **)&tmp_rinfo, (void **)&tmp_edegrees, LTERM); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->KWayTmr)); +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/ametis.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/ametis.c new file mode 100644 index 0000000..6fac271 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/ametis.c @@ -0,0 +1,272 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * ametis.c + * + * This is the entry point of parallel difussive repartitioning routines + * + * Started 10/19/96 + * George + * + * $Id: ametis.c,v 1.6 2003/07/25 04:01:03 karypis Exp $ + * + */ + +#include <parmetislib.h> + + + +/*********************************************************************************** +* This function is the entry point of the parallel multilevel local diffusion +* algorithm. It uses parallel undirected diffusion followed by adaptive k-way +* refinement. This function utilizes local coarsening. +************************************************************************************/ +void ParMETIS_V3_AdaptiveRepart(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, + idxtype *vwgt, idxtype *vsize, idxtype *adjwgt, int *wgtflag, int *numflag, + int *ncon, int *nparts, float *tpwgts, float *ubvec, float *ipc2redist, + int *options, int *edgecut, idxtype *part, MPI_Comm *comm) +{ + int h, i; + int npes, mype; + CtrlType ctrl; + WorkSpaceType wspace; + GraphType *graph; + int tewgt, tvsize, nmoved, maxin, maxout, vtx_factor; + float gtewgt, gtvsize, avg, maximb; + int ps_relation, seed, dbglvl = 0; + int iwgtflag, inumflag, incon, inparts, ioptions[10]; + float iipc2redist, *itpwgts, iubvec[MAXNCON]; + + MPI_Comm_size(*comm, &npes); + MPI_Comm_rank(*comm, &mype); + + /********************************/ + /* Try and take care bad inputs */ + /********************************/ + if (options != NULL && options[0] == 1) + dbglvl = options[PMV3_OPTION_DBGLVL]; + CheckInputs(ADAPTIVE_PARTITION, npes, dbglvl, wgtflag, &iwgtflag, numflag, &inumflag, + ncon, &incon, nparts, &inparts, tpwgts, &itpwgts, ubvec, iubvec, + ipc2redist, &iipc2redist, options, ioptions, part, comm); + + /* ADD: take care of disconnected graph */ + /* ADD: take care of highly unbalanced vtxdist */ + /*********************************/ + /* Take care the nparts = 1 case */ + /*********************************/ + if (inparts == 1) { + idxset(vtxdist[mype+1]-vtxdist[mype], 0, part); + *edgecut = 0; + return; + } + + /**************************/ + /* Set up data structures */ + /**************************/ + if (inumflag == 1) + ChangeNumbering(vtxdist, xadj, adjncy, part, npes, mype, 1); + + /*****************************/ + /* Set up control structures */ + /*****************************/ + if (ioptions[0] == 1) { + dbglvl = ioptions[PMV3_OPTION_DBGLVL]; + seed = ioptions[PMV3_OPTION_SEED]; + ps_relation = (npes == inparts ? ioptions[PMV3_OPTION_PSR] : DISCOUPLED); + } + else { + dbglvl = GLOBAL_DBGLVL; + seed = GLOBAL_SEED; + ps_relation = (npes == inparts ? COUPLED : DISCOUPLED); + } + + SetUpCtrl(&ctrl, inparts, dbglvl, *comm); + vtx_factor = (amax(npes, inparts) > 256) ? 20 : 50; + ctrl.CoarsenTo = amin(vtxdist[npes]+1, vtx_factor*incon*amax(npes, inparts)); + ctrl.ipc_factor = iipc2redist; + ctrl.redist_factor = 1.0; + ctrl.redist_base = 1.0; + ctrl.seed = (seed == 0 ? mype : seed*mype); + ctrl.sync = GlobalSEMax(&ctrl, seed); + ctrl.partType = ADAPTIVE_PARTITION; + ctrl.ps_relation = ps_relation; + ctrl.tpwgts = itpwgts; + + graph = Moc_SetUpGraph(&ctrl, incon, vtxdist, xadj, vwgt, adjncy, adjwgt, &iwgtflag); + graph->vsize = (vsize == NULL ? idxsmalloc(graph->nvtxs, 1, "vsize") : vsize); + + graph->home = idxmalloc(graph->nvtxs, "home"); + if (ctrl.ps_relation == COUPLED) + idxset(graph->nvtxs, mype, graph->home); + else { + /* Downgrade the partition numbers if part[] has more partitions that nparts */ + for (i=0; i<graph->nvtxs; i++) + part[i] = (part[i] >= ctrl.nparts ? 0 : part[i]); + + idxcopy(graph->nvtxs, part, graph->home); + } + + tewgt = idxsum(graph->nedges, graph->adjwgt); + tvsize = idxsum(graph->nvtxs, graph->vsize); + gtewgt = (float) GlobalSESum(&ctrl, tewgt) + 1.0/graph->gnvtxs; /* The +1/graph->gnvtxs were added to remove any FPE */ + gtvsize = (float) GlobalSESum(&ctrl, tvsize) + 1.0/graph->gnvtxs; + ctrl.edge_size_ratio = gtewgt/gtvsize; + scopy(incon, iubvec, ctrl.ubvec); + + PreAllocateMemory(&ctrl, graph, &wspace); + + /***********************/ + /* Partition and Remap */ + /***********************/ + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + Adaptive_Partition(&ctrl, graph, &wspace); + ParallelReMapGraph(&ctrl, graph, &wspace); + + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + + idxcopy(graph->nvtxs, graph->where, part); + if (edgecut != NULL) + *edgecut = graph->mincut; + + /***********************/ + /* Take care of output */ + /***********************/ + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimingInfo(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + + if (ctrl.dbglvl&DBG_INFO) { + Mc_ComputeMoveStatistics(&ctrl, graph, &nmoved, &maxin, &maxout); + rprintf(&ctrl, "Final %3d-way Cut: %6d \tBalance: ", inparts, graph->mincut); + avg = 0.0; + for (h=0; h<incon; h++) { + maximb = 0.0; + for (i=0; i<inparts; i++) + maximb = amax(maximb, graph->gnpwgts[i*incon+h]/itpwgts[i*incon+h]); + avg += maximb; + rprintf(&ctrl, "%.3f ", maximb); + } + rprintf(&ctrl, "\nNMoved: %d %d %d %d\n", nmoved, maxin, maxout, maxin+maxout); + } + + /*************************************/ + /* Free memory, renumber, and return */ + /*************************************/ + GKfree((void **)&graph->lnpwgts, (void **)&graph->gnpwgts, (void **)&graph->nvwgt, (void **)(&graph->home), LTERM); + if (vsize == NULL) + GKfree((void **)(&graph->vsize), LTERM); + GKfree((void **)&itpwgts, LTERM); + FreeInitialGraphAndRemap(graph, iwgtflag); + FreeWSpace(&wspace); + FreeCtrl(&ctrl); + + if (inumflag == 1) + ChangeNumbering(vtxdist, xadj, adjncy, part, npes, mype, 0); + + return; +} + + + + +/************************************************************************* +* This function is the driver for the adaptive refinement mode of ParMETIS +**************************************************************************/ +void Adaptive_Partition(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int i; + int tewgt, tvsize; + float gtewgt, gtvsize; + float ubavg, lbavg, lbvec[MAXNCON]; + + /************************************/ + /* Set up important data structures */ + /************************************/ + SetUp(ctrl, graph, wspace); + + ubavg = savg(graph->ncon, ctrl->ubvec); + tewgt = idxsum(graph->nedges, graph->adjwgt); + tvsize = idxsum(graph->nvtxs, graph->vsize); + gtewgt = (float) GlobalSESum(ctrl, tewgt) + 1.0/graph->gnvtxs; /* The +1/graph->gnvtxs were added to remove any FPE */ + gtvsize = (float) GlobalSESum(ctrl, tvsize) + 1.0/graph->gnvtxs; + ctrl->redist_factor = ctrl->redist_base * ((gtewgt/gtvsize)/ ctrl->edge_size_ratio); + + IFSET(ctrl->dbglvl, DBG_PROGRESS, rprintf(ctrl, "[%6d %8d %5d %5d][%d]\n", + graph->gnvtxs, GlobalSESum(ctrl, graph->nedges), GlobalSEMin(ctrl, graph->nvtxs), GlobalSEMax(ctrl, graph->nvtxs), ctrl->CoarsenTo)); + + if (graph->gnvtxs < 1.3*ctrl->CoarsenTo || + (graph->finer != NULL && graph->gnvtxs > graph->finer->gnvtxs*COARSEN_FRACTION)) { + + /***********************************************/ + /* Balance the partition on the coarsest graph */ + /***********************************************/ + graph->where = idxsmalloc(graph->nvtxs+graph->nrecv, -1, "graph->where"); + idxcopy(graph->nvtxs, graph->home, graph->where); + + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + lbavg = savg(graph->ncon, lbvec); + + if (lbavg > ubavg + 0.035 && ctrl->partType != REFINE_PARTITION) + Balance_Partition(ctrl, graph, wspace); + + if (ctrl->dbglvl&DBG_PROGRESS) { + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + rprintf(ctrl, "nvtxs: %10d, balance: ", graph->gnvtxs); + for (i=0; i<graph->ncon; i++) + rprintf(ctrl, "%.3f ", lbvec[i]); + rprintf(ctrl, "\n"); + } + + /* check if no coarsening took place */ + if (graph->finer == NULL) { + Moc_ComputePartitionParams(ctrl, graph, wspace); + Moc_KWayBalance(ctrl, graph, wspace, graph->ncon); + Moc_KWayAdaptiveRefine(ctrl, graph, wspace, NGR_PASSES); + } + } + else { + /*******************************/ + /* Coarsen it and partition it */ + /*******************************/ + switch (ctrl->ps_relation) { + case COUPLED: + Mc_LocalMatch_HEM(ctrl, graph, wspace); + break; + case DISCOUPLED: + default: + Moc_GlobalMatch_Balance(ctrl, graph, wspace); + break; + } + + Adaptive_Partition(ctrl, graph->coarser, wspace); + + /********************************/ + /* project partition and refine */ + /********************************/ + Moc_ProjectPartition(ctrl, graph, wspace); + Moc_ComputePartitionParams(ctrl, graph, wspace); + + if (graph->ncon > 1 && graph->level < 4) { + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + lbavg = savg(graph->ncon, lbvec); + + if (lbavg > ubavg + 0.025) { + Moc_KWayBalance(ctrl, graph, wspace, graph->ncon); + } + } + + Moc_KWayAdaptiveRefine(ctrl, graph, wspace, NGR_PASSES); + + if (ctrl->dbglvl&DBG_PROGRESS) { + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + rprintf(ctrl, "nvtxs: %10d, cut: %8d, balance: ", graph->gnvtxs, graph->mincut); + for (i=0; i<graph->ncon; i++) + rprintf(ctrl, "%.3f ", lbvec[i]); + rprintf(ctrl, "\n"); + } + } +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/backcompat.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/backcompat.c new file mode 100644 index 0000000..b62d4bb --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/backcompat.c @@ -0,0 +1,517 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * backcompat.c + * + * This file ensures backwards compatability with previous ParMETIS releases + * + * Started 10/19/96 + * George + * + * $Id: backcompat.c,v 1.2 2003/07/21 17:18:48 karypis Exp $ + * + */ + +#include <parmetislib.h> + +/***************************************************************************** +* This function computes a partitioning. +*****************************************************************************/ +void ParMETIS_PartKway(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, + idxtype *part, MPI_Comm *comm) +{ + int i; + int ncon = 1; + float *tpwgts, ubvec[MAXNCON]; + int myoptions[10]; + + tpwgts = fmalloc(*nparts*ncon, "tpwgts"); + for (i=0; i<*nparts*ncon; i++) + tpwgts[i] = 1.0/(float)(*nparts); + for (i=0; i<ncon; i++) + ubvec[i] = UNBALANCE_FRACTION; + + if (options[0] == 0) { + myoptions[0] = 0; + } + else { + myoptions[0] = 1; + myoptions[PMV3_OPTION_DBGLVL] = options[OPTION_DBGLVL]; + myoptions[PMV3_OPTION_SEED] = GLOBAL_SEED; + } + + ParMETIS_V3_PartKway(vtxdist, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, + &ncon, nparts, tpwgts, ubvec, myoptions, edgecut, part, comm); + + free(tpwgts); +} + + + +/*********************************************************************************** + * * This function is the entry point of the parallel k-way multilevel partitionioner. + * * This function assumes nothing about the graph distribution. + * * It is the general case. + * ************************************************************************************/ +void PARKMETIS(idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + idxtype *part, int *options, MPI_Comm comm) +{ + int wgtflag, numflag, edgecut, newoptions[5]; + int npes; + + MPI_Comm_size(comm, &npes); + + newoptions[0] = 1; + newoptions[OPTION_IPART] = options[2]; + newoptions[OPTION_FOLDF] = options[1]; + newoptions[OPTION_DBGLVL] = options[4]; + + numflag = options[3]; + wgtflag = (vwgt == NULL ? 0 : 2) + (adjwgt == NULL ? 0 : 1); + + ParMETIS_PartKway(vtxdist, xadj, adjncy, vwgt, adjwgt, &wgtflag, &numflag, &npes, + newoptions, &edgecut, part, &comm); + + options[0] = edgecut; + +} + + + +/***************************************************************************** +* This function computes a partitioning using coordinate data. +*****************************************************************************/ +void ParMETIS_PartGeomKway(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *ndims, float *xyz, int *nparts, + int *options, int *edgecut, idxtype *part, MPI_Comm *comm) +{ + int i; + int ncon = 1; + float *tpwgts, ubvec[MAXNCON]; + int myoptions[10]; + + tpwgts = fmalloc(*nparts*ncon, "tpwgts"); + for (i=0; i<*nparts*ncon; i++) + tpwgts[i] = 1.0/(float)(*nparts); + for (i=0; i<ncon; i++) + ubvec[i] = UNBALANCE_FRACTION; + + if (options[0] == 0) { + myoptions[0] = 0; + } + else { + myoptions[0] = 1; + myoptions[PMV3_OPTION_DBGLVL] = options[OPTION_DBGLVL]; + myoptions[PMV3_OPTION_SEED] = GLOBAL_SEED; + } + + ParMETIS_V3_PartGeomKway(vtxdist, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, ndims, xyz, + &ncon, nparts, tpwgts, ubvec, myoptions, edgecut, part, comm); + + free(tpwgts); + return; +} + + +/*********************************************************************************** +* This function is the entry point of the parallel ordering algorithm. +* This function assumes that the graph is already nice partitioned among the +* processors and then proceeds to perform recursive bisection. +************************************************************************************/ +void ParMETIS_PartGeom(idxtype *vtxdist, int *ndims, float *xyz, idxtype *part, MPI_Comm *comm) +{ + ParMETIS_V3_PartGeom(vtxdist, ndims, xyz, part, comm); +} + + +/***************************************************************************** +* This function computes a partitioning using coordinate data. +*****************************************************************************/ +void ParMETIS_PartGeomRefine(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, + idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *ndims, + float *xyz, int *options, int *edgecut, idxtype *part, MPI_Comm *comm) +{ + int i; + int npes, nparts, ncon = 1; + float *tpwgts, ubvec[MAXNCON]; + int myoptions[10]; + + MPI_Comm_size(*comm, &npes); + nparts = npes; + + tpwgts = fmalloc(nparts*ncon, "tpwgts"); + for (i=0; i<nparts*ncon; i++) + tpwgts[i] = 1.0/(float)(nparts); + for (i=0; i<ncon; i++) + ubvec[i] = UNBALANCE_FRACTION; + + if (options[0] == 0) { + myoptions[0] = 0; + } + else { + myoptions[0] = 1; + myoptions[PMV3_OPTION_DBGLVL] = options[OPTION_DBGLVL]; + myoptions[PMV3_OPTION_SEED] = GLOBAL_SEED; + } + + ParMETIS_V3_PartGeomKway(vtxdist, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, ndims, xyz, + &ncon, &nparts, tpwgts, ubvec, myoptions, edgecut, part, comm); + + free(tpwgts); + return; +} + + +/*********************************************************************************** +* This function is the entry point of the parallel kmetis algorithm that uses +* coordinates to compute an initial graph distribution. +************************************************************************************/ +void PARGKMETIS(idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + int ndims, float *xyz, idxtype *part, int *options, MPI_Comm comm) +{ + int npes, wgtflag, numflag, edgecut, newoptions[5]; + + MPI_Comm_size(comm, &npes); + + newoptions[0] = 1; + newoptions[OPTION_IPART] = options[2]; + newoptions[OPTION_FOLDF] = options[1]; + newoptions[OPTION_DBGLVL] = options[4]; + + numflag = options[3]; + wgtflag = (vwgt == NULL ? 0 : 2) + (adjwgt == NULL ? 0 : 1); + + ParMETIS_PartGeomKway(vtxdist, xadj, adjncy, vwgt, adjwgt, &wgtflag, &numflag, + &ndims, xyz, &npes, newoptions, &edgecut, part, &comm); + + options[0] = edgecut; + +} + + +/*********************************************************************************** +* This function is the entry point of the parallel rmetis algorithm that uses +* coordinates to compute an initial graph distribution. +************************************************************************************/ +void PARGRMETIS(idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + int ndims, float *xyz, idxtype *part, int *options, MPI_Comm comm) +{ + int wgtflag, numflag, edgecut, newoptions[5]; + + newoptions[0] = 1; + newoptions[OPTION_IPART] = options[2]; + newoptions[OPTION_FOLDF] = options[1]; + newoptions[OPTION_DBGLVL] = options[4]; + + numflag = options[3]; + wgtflag = (vwgt == NULL ? 0 : 2) + (adjwgt == NULL ? 0 : 1); + + ParMETIS_PartGeomRefine(vtxdist, xadj, adjncy, vwgt, adjwgt, &wgtflag, &numflag, + &ndims, xyz, newoptions, &edgecut, part, &comm); + + options[0] = edgecut; + +} + +/*********************************************************************************** +* This function is the entry point of the parallel ordering algorithm. +* This function assumes that the graph is already nice partitioned among the +* processors and then proceeds to perform recursive bisection. +************************************************************************************/ +void PARGMETIS(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, int ndims, float *xyz, + idxtype *part, int *options, MPI_Comm comm) +{ + + ParMETIS_PartGeom(vtxdist, &ndims, xyz, part, &comm); + + options[0] = -1; + +} + +/***************************************************************************** +* This function performs refinement on a partitioning. +*****************************************************************************/ +void ParMETIS_RefineKway(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, + idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *options, + int *edgecut, idxtype *part, MPI_Comm *comm) +{ + int i; + int nparts; + int ncon = 1; + float *tpwgts, ubvec[MAXNCON]; + int myoptions[10]; + + MPI_Comm_size(*comm, &nparts); + tpwgts = fmalloc(nparts*ncon, "tpwgts"); + for (i=0; i<nparts*ncon; i++) + tpwgts[i] = 1.0/(float)(nparts); + for (i=0; i<ncon; i++) + ubvec[i] = UNBALANCE_FRACTION; + + if (options[0] == 0) { + myoptions[0] = 0; + } + else { + myoptions[0] = 1; + myoptions[PMV3_OPTION_DBGLVL] = options[OPTION_DBGLVL]; + myoptions[PMV3_OPTION_SEED] = GLOBAL_SEED; + myoptions[PMV3_OPTION_PSR] = COUPLED; + } + + ParMETIS_V3_RefineKway(vtxdist, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, + &ncon, &nparts, tpwgts, ubvec, myoptions, edgecut, part, comm); + + free(tpwgts); +} + + +/*********************************************************************************** +* This function is the entry point of the parallel k-way multilevel partitionioner. +* This function assumes nothing about the graph distribution. +* It is the general case. +************************************************************************************/ +void PARRMETIS(idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + idxtype *part, int *options, MPI_Comm comm) +{ + int wgtflag, numflag, edgecut, newoptions[5]; + + newoptions[0] = 1; + newoptions[OPTION_IPART] = options[2]; + newoptions[OPTION_FOLDF] = options[1]; + newoptions[OPTION_DBGLVL] = options[4]; + + numflag = options[3]; + wgtflag = (vwgt == NULL ? 0 : 2) + (adjwgt == NULL ? 0 : 1); + + ParMETIS_RefineKway(vtxdist, xadj, adjncy, vwgt, adjwgt, &wgtflag, &numflag, + newoptions, &edgecut, part, &comm); + + options[0] = edgecut; + +} + + +/***************************************************************************** +* This function computes a repartitioning by local diffusion. +*****************************************************************************/ +void ParMETIS_RepartLDiffusion(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, + idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *options, + int *edgecut, idxtype *part, MPI_Comm *comm) +{ + int i; + int nparts; + int ncon = 1; + float *tpwgts, ubvec[MAXNCON]; + float ipc_factor = 1.0; + int myoptions[10]; + + MPI_Comm_size(*comm, &nparts); + tpwgts = fmalloc(nparts*ncon, "tpwgts"); + for (i=0; i<nparts*ncon; i++) + tpwgts[i] = 1.0/(float)(nparts); + for (i=0; i<ncon; i++) + ubvec[i] = UNBALANCE_FRACTION; + + if (options[0] == 0) { + myoptions[0] = 0; + } + else { + myoptions[0] = 1; + myoptions[PMV3_OPTION_DBGLVL] = options[OPTION_DBGLVL]; + myoptions[PMV3_OPTION_SEED] = GLOBAL_SEED; + myoptions[PMV3_OPTION_PSR] = COUPLED; + } + + ParMETIS_V3_AdaptiveRepart(vtxdist, xadj, adjncy, vwgt, NULL, adjwgt, wgtflag, numflag, + &ncon, &nparts, tpwgts, ubvec, &ipc_factor, myoptions, edgecut, part, comm); + + free(tpwgts); +} + + +/*********************************************************************************** +* This function is the entry point of the parallel multilevel undirected diffusion +* algorithm. It uses parallel undirected diffusion followed by adaptive k-way +* refinement. This function utilizes local coarsening. +************************************************************************************/ +void PARUAMETIS(idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + idxtype *part, int *options, MPI_Comm comm) +{ + int wgtflag, numflag, edgecut, newoptions[5]; + + newoptions[0] = 1; + newoptions[OPTION_IPART] = options[2]; + newoptions[OPTION_FOLDF] = options[1]; + newoptions[OPTION_DBGLVL] = options[4]; + + numflag = options[3]; + wgtflag = (vwgt == NULL ? 0 : 2) + (adjwgt == NULL ? 0 : 1); + + ParMETIS_RepartLDiffusion(vtxdist, xadj, adjncy, vwgt, adjwgt, &wgtflag, &numflag, + newoptions, &edgecut, part, &comm); + + options[0] = edgecut; + +} + +/***************************************************************************** +* This function computes a repartitioning by global diffusion. +*****************************************************************************/ +void ParMETIS_RepartGDiffusion(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, + idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *options, + int *edgecut, idxtype *part, MPI_Comm *comm) +{ + int i; + int nparts; + int ncon = 1; + float *tpwgts, ubvec[MAXNCON]; + float ipc_factor = 100.0; + int myoptions[10]; + + MPI_Comm_size(*comm, &nparts); + tpwgts = fmalloc(nparts*ncon, "tpwgts"); + for (i=0; i<nparts*ncon; i++) + tpwgts[i] = 1.0/(float)(nparts); + for (i=0; i<ncon; i++) + ubvec[i] = UNBALANCE_FRACTION; + + if (options[0] == 0) { + myoptions[0] = 0; + } + else { + myoptions[0] = 1; + myoptions[PMV3_OPTION_DBGLVL] = options[OPTION_DBGLVL]; + myoptions[PMV3_OPTION_SEED] = GLOBAL_SEED; + myoptions[PMV3_OPTION_PSR] = COUPLED; + } + + ParMETIS_V3_AdaptiveRepart(vtxdist, xadj, adjncy, vwgt, NULL, adjwgt, wgtflag, numflag, + &ncon, &nparts, tpwgts, ubvec, &ipc_factor, myoptions, edgecut, part, comm); + + free(tpwgts); +} + +/*********************************************************************************** +* This function is the entry point of the parallel multilevel directed diffusion +* algorithm. It uses parallel undirected diffusion followed by adaptive k-way +* refinement. This function utilizes local coarsening. +************************************************************************************/ +void PARDAMETIS(idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + idxtype *part, int *options, MPI_Comm comm) +{ + int wgtflag, numflag, edgecut, newoptions[5]; + + newoptions[0] = 1; + newoptions[OPTION_IPART] = options[2]; + newoptions[OPTION_FOLDF] = options[1]; + newoptions[OPTION_DBGLVL] = options[4]; + + numflag = options[3]; + wgtflag = (vwgt == NULL ? 0 : 2) + (adjwgt == NULL ? 0 : 1); + + ParMETIS_RepartGDiffusion(vtxdist, xadj, adjncy, vwgt, adjwgt, &wgtflag, &numflag, + newoptions, &edgecut, part, &comm); + + options[0] = edgecut; + +} + +/***************************************************************************** +* This function computes a repartitioning by scratch-remap. +*****************************************************************************/ +void ParMETIS_RepartRemap(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, + idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *options, + int *edgecut, idxtype *part, MPI_Comm *comm) +{ + int i; + int nparts; + int ncon = 1; + float *tpwgts, ubvec[MAXNCON]; + float ipc_factor = 1000.0; + int myoptions[10]; + + MPI_Comm_size(*comm, &nparts); + tpwgts = fmalloc(nparts*ncon, "tpwgts"); + for (i=0; i<nparts*ncon; i++) + tpwgts[i] = 1.0/(float)(nparts); + for (i=0; i<ncon; i++) + ubvec[i] = UNBALANCE_FRACTION; + + if (options[0] == 0) { + myoptions[0] = 0; + } + else { + myoptions[0] = 1; + myoptions[PMV3_OPTION_DBGLVL] = options[OPTION_DBGLVL]; + myoptions[PMV3_OPTION_SEED] = GLOBAL_SEED; + myoptions[PMV3_OPTION_PSR] = COUPLED; + } + + ParMETIS_V3_AdaptiveRepart(vtxdist, xadj, adjncy, vwgt, NULL, adjwgt, wgtflag, numflag, + &ncon, &nparts, tpwgts, ubvec, &ipc_factor, myoptions, edgecut, part, comm); + + free(tpwgts); +} + + +/***************************************************************************** +* This function computes a repartitioning by LMSR scratch-remap. +*****************************************************************************/ +void ParMETIS_RepartMLRemap(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, + idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *options, + int *edgecut, idxtype *part, MPI_Comm *comm) +{ + int i; + int nparts; + int ncon = 1; + float *tpwgts, ubvec[MAXNCON]; + float ipc_factor = 1000.0; + int myoptions[10]; + + MPI_Comm_size(*comm, &nparts); + tpwgts = fmalloc(nparts*ncon, "tpwgts"); + for (i=0; i<nparts*ncon; i++) + tpwgts[i] = 1.0/(float)(nparts); + for (i=0; i<ncon; i++) + ubvec[i] = UNBALANCE_FRACTION; + + if (options[0] == 0) { + myoptions[0] = 0; + } + else { + myoptions[0] = 1; + myoptions[PMV3_OPTION_DBGLVL] = options[OPTION_DBGLVL]; + myoptions[PMV3_OPTION_SEED] = GLOBAL_SEED; + myoptions[PMV3_OPTION_PSR] = COUPLED; + } + + ParMETIS_V3_AdaptiveRepart(vtxdist, xadj, adjncy, vwgt, NULL, adjwgt, wgtflag, numflag, + &ncon, &nparts, tpwgts, ubvec, &ipc_factor, myoptions, edgecut, part, comm); + + free(tpwgts); +} + +/*********************************************************************************** +* This function is the entry point of the parallel ordering algorithm. +* This function assumes that the graph is already nice partitioned among the +* processors and then proceeds to perform recursive bisection. +************************************************************************************/ +void ParMETIS_NodeND(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, int *numflag, + int *options, idxtype *order, idxtype *sizes, MPI_Comm *comm) +{ + int myoptions[10]; + + if (options[0] == 0) { + myoptions[0] = 0; + } + else { + myoptions[0] = 1; + myoptions[PMV3_OPTION_DBGLVL] = options[OPTION_DBGLVL]; + myoptions[PMV3_OPTION_SEED] = GLOBAL_SEED; + myoptions[PMV3_OPTION_IPART] = options[OPTION_IPART]; + } + + ParMETIS_V3_NodeND(vtxdist, xadj, adjncy, numflag, myoptions, order, sizes, comm); +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/balancemylink.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/balancemylink.c new file mode 100644 index 0000000..dd944d1 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/balancemylink.c @@ -0,0 +1,342 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * balancemylink.c + * + * This file contains code that implements the edge-based FM refinement + * + * Started 7/23/97 + * George + * + * $Id: balancemylink.c,v 1.2 2003/07/21 17:18:48 karypis Exp $ + */ + +#include <parmetislib.h> +#define PE 0 + +/************************************************************************* +* This function performs an edge-based FM refinement +**************************************************************************/ +int BalanceMyLink(CtrlType *ctrl, GraphType *graph, idxtype *home, int me, + int you, float *flows, float maxdiff, float *diff_cost, float *diff_lbavg, + float avgvwgt) +{ + int h, i, ii, j, k; + int nvtxs, ncon; + int nqueues, minval, maxval, higain, vtx, edge, totalv; + int from, to, qnum, index, nchanges, cut, tmp; + int pass, nswaps, nmoves, multiplier; + idxtype *xadj, *vsize, *adjncy, *adjwgt, *where, *ed, *id; + idxtype *hval, *nvpq, *inq, *map, *rmap, *ptr, *myqueue, *changes; + float *nvwgt, lbvec[MAXNCON], pwgts[MAXNCON*2], tpwgts[MAXNCON*2], my_wgt[MAXNCON]; + float newgain, oldgain = 0.0; + float lbavg, bestflow, mycost; + float ipc_factor, redist_factor, ftmp; + FPQueueType *queues; +int mype; +MPI_Comm_rank(MPI_COMM_WORLD, &mype); + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + vsize = graph->vsize; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + ipc_factor = ctrl->ipc_factor; + redist_factor = ctrl->redist_factor; + + hval = idxmalloc(nvtxs*7, "hval"); + id = hval + nvtxs; + ed = hval + nvtxs*2; + map = hval + nvtxs*3; + rmap = hval + nvtxs*4; + myqueue = hval + nvtxs*5; + changes = hval + nvtxs*6; + + sset(ncon*2, 0.0, pwgts); + for (h=0; h<ncon; h++) { + tpwgts[h] = -1.0 * flows[h]; + tpwgts[ncon+h] = flows[h]; + } + + for (i=0; i<nvtxs; i++) { + if (where[i] == me) { + for (h=0; h<ncon; h++) { + tpwgts[h] += nvwgt[i*ncon+h]; + pwgts[h] += nvwgt[i*ncon+h]; + } + } + else { + ASSERTS(where[i] == you); + for (h=0; h<ncon; h++) { + tpwgts[ncon+h] += nvwgt[i*ncon+h]; + pwgts[ncon+h] += nvwgt[i*ncon+h]; + } + } + } + + /* we don't want any tpwgts to be less than zero */ + for (h=0; h<ncon; h++) { + if (tpwgts[h] < 0.0) { + tpwgts[ncon+h] += tpwgts[h]; + tpwgts[h] = 0.0; + } + + if (tpwgts[ncon+h] < 0.0) { + tpwgts[h] += tpwgts[ncon+h]; + tpwgts[ncon+h] = 0.0; + } + } + + /*******************************/ + /* insert vertices into queues */ + /*******************************/ + minval = maxval = 0; + multiplier = 1; + for (i=0; i<ncon; i++) { + multiplier *= (i+1); + maxval += i*multiplier; + minval += (ncon-1-i)*multiplier; + } + + nqueues = maxval-minval+1; + nvpq = idxsmalloc(nqueues, 0, "nvpq"); + ptr = idxmalloc(nqueues+1, "ptr"); + inq = idxmalloc(nqueues*2, "inq"); + queues = (FPQueueType *)(GKmalloc(sizeof(FPQueueType)*nqueues*2, "queues")); + + for (i=0; i<nvtxs; i++) + hval[i] = Moc_HashVwgts(ncon, nvwgt+i*ncon) - minval; + + for (i=0; i<nvtxs; i++) + nvpq[hval[i]]++; + + ptr[0] = 0; + for (i=0; i<nqueues; i++) + ptr[i+1] = ptr[i] + nvpq[i]; + + for (i=0; i<nvtxs; i++) { + map[i] = ptr[hval[i]]; + rmap[ptr[hval[i]]++] = i; + } + + for (i=nqueues-1; i>0; i--) + ptr[i] = ptr[i-1]; + ptr[0] = 0; + + /* initialize queues */ + for (i=0; i<nqueues; i++) + if (nvpq[i] > 0) { + FPQueueInit(queues+i, nvpq[i]); + FPQueueInit(queues+i+nqueues, nvpq[i]); + } + + /* compute internal/external degrees */ + idxset(nvtxs, 0, id); + idxset(nvtxs, 0, ed); + for (j=0; j<nvtxs; j++) + for (k=xadj[j]; k<xadj[j+1]; k++) + if (where[adjncy[k]] == where[j]) + id[j] += adjwgt[k]; + else + ed[j] += adjwgt[k]; + + nswaps = 0; + for (pass=0; pass<N_MOC_BAL_PASSES; pass++) { + idxset(nvtxs, -1, myqueue); + idxset(nqueues*2, 0, inq); + + /* insert vertices into correct queues */ + for (j=0; j<nvtxs; j++) { + index = (where[j] == me) ? 0 : nqueues; + + newgain = ipc_factor*(float)(ed[j]-id[j]); + if (home[j] == me || home[j] == you) { + if (where[j] == home[j]) + newgain -= redist_factor*(float)vsize[j]; + else + newgain += redist_factor*(float)vsize[j]; + } + + FPQueueInsert(queues+hval[j]+index, map[j]-ptr[hval[j]], newgain); + myqueue[j] = (where[j] == me) ? 0 : 1; + inq[hval[j]+index]++; + } + +/* bestflow = sfavg(ncon, flows); */ + for (j=0, h=0; h<ncon; h++) + if (fabs(flows[h]) > fabs(flows[j])) j = h; + bestflow = fabs(flows[j]); + + nchanges = nmoves = 0; + for (ii=0; ii<nvtxs/2; ii++) { + from = -1; + Moc_DynamicSelectQueue(nqueues, ncon, me, you, inq, flows, &from, + &qnum, minval, avgvwgt, maxdiff); + + /* can't find a vertex in one subdomain, try the other */ + if (from != -1 && qnum == -1) { + from = (from == me) ? you : me; + + if (from == me) { + for (j=0; j<ncon; j++) + if (flows[j] > avgvwgt) + break; + } + else { + for (j=0; j<ncon; j++) + if (flows[j] < -1.0*avgvwgt) + break; + } + + if (j != ncon) + Moc_DynamicSelectQueue(nqueues, ncon, me, you, inq, flows, &from, + &qnum, minval, avgvwgt, maxdiff); + } + + if (qnum == -1) + break; + + to = (from == me) ? you : me; + index = (from == me) ? 0 : nqueues; + higain = FPQueueGetMax(queues+qnum+index); + inq[qnum+index]--; + ASSERTS(higain != -1); + + /*****************/ + /* make the swap */ + /*****************/ + vtx = rmap[higain+ptr[qnum]]; + myqueue[vtx] = -1; + where[vtx] = to; + nswaps++; + nmoves++; + + /* update the flows */ + for (j=0; j<ncon; j++) + flows[j] += (to == me) ? nvwgt[vtx*ncon+j] : -1.0*nvwgt[vtx*ncon+j]; + +/* ftmp = sfavg(ncon, flows); */ + for (j=0, h=0; h<ncon; h++) + if (fabs(flows[h]) > fabs(flows[j])) j = h; + ftmp = fabs(flows[j]); + + if (ftmp < bestflow) { + bestflow = ftmp; + nchanges = 0; + } + else { + changes[nchanges++] = vtx; + } + + SWAP(id[vtx], ed[vtx], tmp); + + for (j=xadj[vtx]; j<xadj[vtx+1]; j++) { + edge = adjncy[j]; + + /* must compute oldgain before changing id/ed */ + if (myqueue[edge] != -1) { + oldgain = ipc_factor*(float)(ed[edge]-id[edge]); + if (home[edge] == me || home[edge] == you) { + if (where[edge] == home[edge]) + oldgain -= redist_factor*(float)vsize[edge]; + else + oldgain += redist_factor*(float)vsize[edge]; + } + } + + tmp = (to == where[edge] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[edge], ed[edge], tmp); + + if (myqueue[edge] != -1) { + newgain = ipc_factor*(float)(ed[edge]-id[edge]); + if (home[edge] == me || home[edge] == you) { + if (where[edge] == home[edge]) + newgain -= redist_factor*(float)vsize[edge]; + else + newgain += redist_factor*(float)vsize[edge]; + } + + FPQueueUpdate(queues+hval[edge]+(nqueues*myqueue[edge]), + map[edge]-ptr[hval[edge]], oldgain, newgain); + } + } + } + + /****************************/ + /* now go back to best flow */ + /****************************/ + nswaps -= nchanges; + nmoves -= nchanges; + for (i=0; i<nchanges; i++) { + vtx = changes[i]; + from = where[vtx]; + where[vtx] = to = (from == me) ? you : me; + + SWAP(id[vtx], ed[vtx], tmp); + for (j=xadj[vtx]; j<xadj[vtx+1]; j++) { + edge = adjncy[j]; + tmp = (to == where[edge] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[edge], ed[edge], tmp); + } + } + + for (i=0; i<nqueues; i++) { + if (nvpq[i] > 0) { + FPQueueReset(queues+i); + FPQueueReset(queues+i+nqueues); + } + } + + if (nmoves == 0) + break; + } + + /***************************/ + /* compute 2-way imbalance */ + /***************************/ + sset(ncon, 0.0, my_wgt); + for (i=0; i<nvtxs; i++) + if (where[i] == me) + for (h=0; h<ncon; h++) + my_wgt[h] += nvwgt[i*ncon+h]; + + for (i=0; i<ncon; i++) { + ftmp = (pwgts[i]+pwgts[ncon+i])/2.0; + if (ftmp != 0.0) + lbvec[i] = fabs(my_wgt[i]-tpwgts[i]) / ftmp; + else + lbvec[i] = 0.0; + } + lbavg = savg(ncon, lbvec); + *diff_lbavg = lbavg; + + /****************/ + /* compute cost */ + /****************/ + cut = totalv = 0; + for (i=0; i<nvtxs; i++) { + if (where[i] != home[i]) + totalv += vsize[i]; + + for (j=xadj[i]; j<xadj[i+1]; j++) + if (where[adjncy[j]] != where[i]) + cut += adjwgt[j]; + } + cut /= 2; + mycost = cut*ipc_factor + totalv*redist_factor; + *diff_cost = mycost; + + /* free memory */ + for (i=0; i<nqueues; i++) + if (nvpq[i] > 0) { + FPQueueFree(queues+i); + FPQueueFree(queues+i+nqueues); + } + + GKfree((void **)&hval, (void **)&nvpq, (void **)&ptr, (void **)&inq, (void **)&queues, LTERM); + return nswaps; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/coarsen.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/coarsen.c new file mode 100644 index 0000000..70f48c2 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/coarsen.c @@ -0,0 +1,485 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mcoarsen.c + * + * This file contains code that performs graph coarsening + * + * Started 2/22/96 + * George + * + * $Id: coarsen.c,v 1.2 2003/07/21 17:18:48 karypis Exp $ + * + */ + +#include <parmetislib.h> + + +/************************************************************************* +* This function creates the coarser graph +**************************************************************************/ +void Moc_Global_CreateCoarseGraph(CtrlType *ctrl, GraphType *graph, + WorkSpaceType *wspace, int cnvtxs) +{ + int h, i, j, k, l, ii, jj, ll, nnbrs, nvtxs, nedges, ncon; + int firstvtx, lastvtx, cfirstvtx, clastvtx, otherlastvtx; + int npes=ctrl->npes, mype=ctrl->mype; + int cnedges, nsend, nrecv, nkeepsize, nrecvsize, nsendsize, v, u; + idxtype *xadj, *ladjncy, *adjwgt, *vwgt, *vsize, *vtxdist, *home; + idxtype *match, *cmap, *rcmap, *scmap; + idxtype *cxadj, *cadjncy, *cadjwgt, *cvwgt, *cvsize = NULL, *chome = NULL, *cvtxdist; + idxtype *rsizes, *ssizes, *rlens, *slens, *rgraph, *sgraph, *perm; + idxtype *peind, *recvptr, *recvind; + float *nvwgt, *cnvwgt; + GraphType *cgraph; + KeyValueType *scand, *rcand; + int mask=(1<<13)-1, htable[8192], htableidx[8192]; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + + vtxdist = graph->vtxdist; + xadj = graph->xadj; + vwgt = graph->vwgt; + vsize = graph->vsize; + nvwgt = graph->nvwgt; + home = graph->home; + ladjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + match = graph->match; + + firstvtx = vtxdist[mype]; + lastvtx = vtxdist[mype+1]; + + cmap = graph->cmap = idxmalloc(nvtxs+graph->nrecv, "CreateCoarseGraph: cmap"); + + nnbrs = graph->nnbrs; + peind = graph->peind; + recvind = graph->recvind; + recvptr = graph->recvptr; + + /* Use wspace->indices as the tmp space for map of the boundary + * vertices that are sent and received */ + scmap = wspace->indices; + rcmap = cmap + nvtxs; + + + /* Initialize the coarser graph */ + cgraph = CreateGraph(); + cgraph->nvtxs = cnvtxs; + cgraph->ncon = ncon; + cgraph->level = graph->level+1; + cgraph->finer = graph; + graph->coarser = cgraph; + + + + /************************************************************* + * Obtain the vtxdist of the coarser graph + **************************************************************/ + cvtxdist = cgraph->vtxdist = idxmalloc(npes+1, "CreateCoarseGraph: cvtxdist"); + cvtxdist[npes] = cnvtxs; /* Use last position in the cvtxdist as a temp buffer */ + + MPI_Allgather((void *)(cvtxdist+npes), 1, IDX_DATATYPE, (void *)cvtxdist, 1, IDX_DATATYPE, ctrl->comm); + + MAKECSR(i, npes, cvtxdist); + + cgraph->gnvtxs = cvtxdist[npes]; + +#ifdef DEBUG_CONTRACT + PrintVector(ctrl, npes+1, 0, cvtxdist, "cvtxdist"); +#endif + + + /************************************************************* + * Construct the cmap vector + **************************************************************/ + cfirstvtx = cvtxdist[mype]; + clastvtx = cvtxdist[mype+1]; + + /* Create the cmap of what you know so far locally */ + cnvtxs = 0; + for (i=0; i<nvtxs; i++) { + if (match[i] >= KEEP_BIT) { + k = match[i] - KEEP_BIT; + if (k>=firstvtx && k<firstvtx+i) + continue; /* Both (i,k) are local and i has been matched via the (k,i) side */ + + cmap[i] = cfirstvtx + cnvtxs++; + if (k != firstvtx+i && (k>=firstvtx && k<lastvtx)) { /* I'm matched locally */ + cmap[k-firstvtx] = cmap[i]; + match[k-firstvtx] += KEEP_BIT; /* Add the KEEP_BIT to simplify coding */ + } + } + } + ASSERT(ctrl, cnvtxs == clastvtx-cfirstvtx); + + CommInterfaceData(ctrl, graph, cmap, scmap, rcmap); + + /* Update the cmap of the locally stored vertices that will go away. + * The remote processor assigned cmap for them */ + for (i=0; i<nvtxs; i++) { + if (match[i] < KEEP_BIT) { /* Only vertices that go away satisfy this*/ + cmap[i] = rcmap[BSearch(graph->nrecv, recvind, match[i])]; + } + } + + CommInterfaceData(ctrl, graph, cmap, scmap, rcmap); + + +#ifdef DEBUG_CONTRACT + PrintVector(ctrl, nvtxs, firstvtx, cmap, "Cmap"); +#endif + + + /************************************************************* + * Determine how many adjcency lists you need to send/receive. + **************************************************************/ + /* Use wspace->pairs as the tmp space for the boundary vertices that are sent and received */ + scand = wspace->pairs; + rcand = graph->rcand = (KeyValueType *)GKmalloc(recvptr[nnbrs]*sizeof(KeyValueType), "CreateCoarseGraph: rcand"); + + nkeepsize = nsend = nrecv = 0; + for (i=0; i<nvtxs; i++) { + if (match[i] < KEEP_BIT) { /* This is going away */ + scand[nsend].key = match[i]; + scand[nsend].val = i; + nsend++; + } + else { + nkeepsize += (xadj[i+1]-xadj[i]); + + k = match[i]-KEEP_BIT; + if (k<firstvtx || k>=lastvtx) { /* This is comming from afar */ + rcand[nrecv].key = k; + rcand[nrecv].val = cmap[i] - cfirstvtx; /* Set it for use during the partition projection */ + ASSERT(ctrl, rcand[nrecv].val>=0 && rcand[nrecv].val<cnvtxs); + nrecv++; + } + } + } + + +#ifdef DEBUG_CONTRACT + PrintPairs(ctrl, nsend, scand, "scand"); + PrintPairs(ctrl, nrecv, rcand, "rcand"); +#endif + + /*************************************************************** + * Determine how many lists and their sizes you will send and + * received for each of the neighboring PEs + ****************************************************************/ + rsizes = wspace->pv1; + ssizes = wspace->pv2; + idxset(nnbrs, 0, ssizes); + idxset(nnbrs, 0, rsizes); + rlens = graph->rlens = idxmalloc(nnbrs+1, "CreateCoarseGraph: graph->rlens"); + slens = graph->slens = idxmalloc(nnbrs+1, "CreateCoarseGraph: graph->slens"); + + /* Take care the sending data first */ + ikeyvalsort(nsend, scand); + slens[0] = 0; + for (k=i=0; i<nnbrs; i++) { + otherlastvtx = vtxdist[peind[i]+1]; + for (; k<nsend && scand[k].key < otherlastvtx; k++) + ssizes[i] += (xadj[scand[k].val+1]-xadj[scand[k].val]); + slens[i+1] = k; + } + + /* Take care the receiving data next. You cannot yet determine the rsizes[] */ + ikeyvalsort(nrecv, rcand); + rlens[0] = 0; + for (k=i=0; i<nnbrs; i++) { + otherlastvtx = vtxdist[peind[i]+1]; + for (; k<nrecv && rcand[k].key < otherlastvtx; k++); + rlens[i+1] = k; + } + +#ifdef DEBUG_CONTRACT + PrintVector(ctrl, nnbrs+1, 0, slens, "slens"); + PrintVector(ctrl, nnbrs+1, 0, rlens, "rlens"); +#endif + + /*************************************************************** + * Exchange size information + ****************************************************************/ + /* Issue the receives first. */ + for (i=0; i<nnbrs; i++) { + if (rlens[i+1]-rlens[i] > 0) /* Issue a receive only if you are getting something */ + MPI_Irecv((void *)(rsizes+i), 1, IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->rreq+i); + } + + /* Take care the sending data next */ + for (i=0; i<nnbrs; i++) { + if (slens[i+1]-slens[i] > 0) /* Issue a send only if you are sending something */ + MPI_Isend((void *)(ssizes+i), 1, IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->sreq+i); + } + + /* OK, now get into the loop waiting for the operations to finish */ + for (i=0; i<nnbrs; i++) { + if (rlens[i+1]-rlens[i] > 0) + MPI_Wait(ctrl->rreq+i, &ctrl->status); + } + for (i=0; i<nnbrs; i++) { + if (slens[i+1]-slens[i] > 0) + MPI_Wait(ctrl->sreq+i, &ctrl->status); + } + + +#ifdef DEBUG_CONTRACT + PrintVector(ctrl, nnbrs, 0, rsizes, "rsizes"); + PrintVector(ctrl, nnbrs, 0, ssizes, "ssizes"); +#endif + + /************************************************************* + * Allocate memory for received/sent graphs and start sending + * and receiving data. + * rgraph and sgraph is a different data structure than CSR + * to facilitate single message exchange. + **************************************************************/ + nrecvsize = idxsum(nnbrs, rsizes); + nsendsize = idxsum(nnbrs, ssizes); + if ((4+ncon)*(nrecv+nsend) + 2*(nrecvsize+nsendsize) <= wspace->nlarge) { + rgraph = (idxtype *)wspace->degrees; + sgraph = rgraph + (4+ncon)*nrecv+2*nrecvsize; + } + else { + rgraph = idxmalloc((4+ncon)*nrecv+2*nrecvsize, "CreateCoarseGraph: rgraph"); + sgraph = idxmalloc((4+ncon)*nsend+2*nsendsize, "CreateCoarseGraph: sgraph"); + } + + /* Deal with the received portion first */ + for (l=i=0; i<nnbrs; i++) { + /* Issue a receive only if you are getting something */ + if (rlens[i+1]-rlens[i] > 0) { + MPI_Irecv((void *)(rgraph+l), (4+ncon)*(rlens[i+1]-rlens[i])+2*rsizes[i], IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->rreq+i); + l += (4+ncon)*(rlens[i+1]-rlens[i])+2*rsizes[i]; + } + } + + + /* Deal with the sent portion now */ + for (ll=l=i=0; i<nnbrs; i++) { + if (slens[i+1]-slens[i] > 0) { /* Issue a send only if you are sending something */ + for (k=slens[i]; k<slens[i+1]; k++) { + ii = scand[k].val; + sgraph[ll++] = firstvtx+ii; + sgraph[ll++] = xadj[ii+1]-xadj[ii]; + for (h=0; h<ncon; h++) + sgraph[ll++] = vwgt[ii*ncon+h]; + sgraph[ll++] = (ctrl->partType == STATIC_PARTITION) ? -1 : vsize[ii]; + sgraph[ll++] = (ctrl->partType == STATIC_PARTITION) ? -1 : home[ii]; + for (jj=xadj[ii]; jj<xadj[ii+1]; jj++) { + sgraph[ll++] = cmap[ladjncy[jj]]; + sgraph[ll++] = adjwgt[jj]; + } + } + + ASSERT(ctrl, ll-l == (4+ncon)*(slens[i+1]-slens[i])+2*ssizes[i]); + + /* myprintf(ctrl, "Sending to pe:%d, %d lists of size %d\n", peind[i], slens[i+1]-slens[i], ssizes[i]); */ + MPI_Isend((void *)(sgraph+l), ll-l, IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->sreq+i); + l = ll; + } + } + + /* OK, now get into the loop waiting for the operations to finish */ + for (i=0; i<nnbrs; i++) { + if (rlens[i+1]-rlens[i] > 0) + MPI_Wait(ctrl->rreq+i, &ctrl->status); + } + for (i=0; i<nnbrs; i++) { + if (slens[i+1]-slens[i] > 0) + MPI_Wait(ctrl->sreq+i, &ctrl->status); + } + + +#ifdef DEBUG_CONTRACT + rprintf(ctrl, "Graphs were sent!\n"); + PrintTransferedGraphs(ctrl, nnbrs, peind, slens, rlens, sgraph, rgraph); +#endif + + /************************************************************* + * Setup the mapping from indices returned by BSearch to + * those that are actually stored + **************************************************************/ + perm = idxsmalloc(recvptr[nnbrs], -1, "CreateCoarseGraph: perm"); + for (j=i=0; i<nrecv; i++) { + /* myprintf(ctrl, "For received vertex %d, set perm[%d]=%d\n", rgraph[j], BSearch(graph->nrecv, recvind, rgraph[j]), j+ncon); */ + perm[BSearch(graph->nrecv, recvind, rgraph[j])] = j+1; + j += (4+ncon)+2*rgraph[j+1]; + } + + /************************************************************* + * Finally, create the coarser graph + **************************************************************/ + /* Allocate memory for the coarser graph, and fire up coarsening */ + cxadj = cgraph->xadj = idxmalloc(cnvtxs+1, "CreateCoarserGraph: cxadj"); + cvwgt = cgraph->vwgt = idxmalloc(cnvtxs*ncon, "CreateCoarserGraph: cvwgt"); + if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) { + cvsize = cgraph->vsize = idxmalloc(cnvtxs, "CreateCoarserGraph: cvsize"); + chome = cgraph->home = idxmalloc(cnvtxs, "CreateCoarserGraph: chome"); + } + cnvwgt = cgraph->nvwgt = fmalloc(cnvtxs*ncon, "CreateCoarserGraph: cnvwgt"); + cadjncy = idxmalloc(2*(nkeepsize+nrecvsize), "CreateCoarserGraph: cadjncy"); + cadjwgt = cadjncy + nkeepsize+nrecvsize; + + iset(8192, -1, htable); + + cxadj[0] = cnvtxs = cnedges = 0; + for (i=0; i<nvtxs; i++) { + if (match[i] >= KEEP_BIT) { + v = firstvtx+i; + u = match[i]-KEEP_BIT; + + if (u>=firstvtx && u<lastvtx && v > u) + continue; /* I have already collapsed it as (u,v) */ + + /* Collapse the v vertex first, which you know is local */ + for (h=0; h<ncon; h++) + cvwgt[cnvtxs*ncon+h] = vwgt[i*ncon+h]; + if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) { + cvsize[cnvtxs] = vsize[i]; + chome[cnvtxs] = home[i]; + } + nedges = 0; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = cmap[ladjncy[j]]; + if (k != cfirstvtx+cnvtxs) { /* If this is not an internal edge */ + l = k&mask; + if (htable[l] == -1) { /* Seeing this for first time */ + htable[l] = k; + htableidx[l] = cnedges+nedges; + cadjncy[cnedges+nedges] = k; + cadjwgt[cnedges+nedges++] = adjwgt[j]; + } + else if (htable[l] == k) { + cadjwgt[htableidx[l]] += adjwgt[j]; + } + else { /* Now you have to go and do a search. Expensive case */ + for (l=0; l<nedges; l++) { + if (cadjncy[cnedges+l] == k) + break; + } + if (l < nedges) { + cadjwgt[cnedges+l] += adjwgt[j]; + } + else { + cadjncy[cnedges+nedges] = k; + cadjwgt[cnedges+nedges++] = adjwgt[j]; + } + } + } + } + + /* Collapse the u vertex next */ + if (v != u) { + if (u>=firstvtx && u<lastvtx) { /* Local vertex */ + u -= firstvtx; + for (h=0; h<ncon; h++) + cvwgt[cnvtxs*ncon+h] += vwgt[u*ncon+h]; + if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) { + cvsize[cnvtxs] += vsize[u]; + /* chome[cnvtxs] = home[u]; */ + } + + for (j=xadj[u]; j<xadj[u+1]; j++) { + k = cmap[ladjncy[j]]; + if (k != cfirstvtx+cnvtxs) { /* If this is not an internal edge */ + l = k&mask; + if (htable[l] == -1) { /* Seeing this for first time */ + htable[l] = k; + htableidx[l] = cnedges+nedges; + cadjncy[cnedges+nedges] = k; + cadjwgt[cnedges+nedges++] = adjwgt[j]; + } + else if (htable[l] == k) { + cadjwgt[htableidx[l]] += adjwgt[j]; + } + else { /* Now you have to go and do a search. Expensive case */ + for (l=0; l<nedges; l++) { + if (cadjncy[cnedges+l] == k) + break; + } + if (l < nedges) { + cadjwgt[cnedges+l] += adjwgt[j]; + } + else { + cadjncy[cnedges+nedges] = k; + cadjwgt[cnedges+nedges++] = adjwgt[j]; + } + } + } + } + } + else { /* Remote vertex */ + u = perm[BSearch(graph->nrecv, recvind, u)]; + for (h=0; h<ncon; h++) + /* Remember that the +1 stores the vertex weight */ + cvwgt[cnvtxs*ncon+h] += rgraph[(u+1)+h]; + if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) { + cvsize[cnvtxs] += rgraph[u+1+ncon]; + chome[cnvtxs] = rgraph[u+2+ncon]; + } + for (j=0; j<rgraph[u]; j++) { + k = rgraph[u+3+ncon+2*j]; + if (k != cfirstvtx+cnvtxs) { /* If this is not an internal edge */ + l = k&mask; + if (htable[l] == -1) { /* Seeing this for first time */ + htable[l] = k; + htableidx[l] = cnedges+nedges; + cadjncy[cnedges+nedges] = k; + cadjwgt[cnedges+nedges++] = rgraph[u+3+ncon+2*j+1]; + } + else if (htable[l] == k) { + cadjwgt[htableidx[l]] += rgraph[u+3+ncon+2*j+1]; + } + else { /* Now you have to go and do a search. Expensive case */ + for (l=0; l<nedges; l++) { + if (cadjncy[cnedges+l] == k) + break; + } + if (l < nedges) { + cadjwgt[cnedges+l] += rgraph[u+3+ncon+2*j+1]; + } + else { + cadjncy[cnedges+nedges] = k; + cadjwgt[cnedges+nedges++] = rgraph[u+3+ncon+2*j+1]; + } + } + } + } + } + } + + cnedges += nedges; + for (j=cxadj[cnvtxs]; j<cnedges; j++) + htable[cadjncy[j]&mask] = -1; /* reset the htable */ + cxadj[++cnvtxs] = cnedges; + } + } + + cgraph->nedges = cnedges; + + /* ADD: In order to keep from having to change this too much */ + /* ADD: I kept vwgt array and recomputed nvwgt for each coarser graph */ + for (j=0; j<cnvtxs; j++) + for (h=0; h<ncon; h++) + cgraph->nvwgt[j*ncon+h] = (float)(cvwgt[j*ncon+h])/(float)(ctrl->tvwgts[h]); + + cgraph->adjncy = idxmalloc(cnedges, "CreateCoarserGraph: cadjncy"); + cgraph->adjwgt = idxmalloc(cnedges, "CreateCoarserGraph: cadjwgt"); + idxcopy(cnedges, cadjncy, cgraph->adjncy); + idxcopy(cnedges, cadjwgt, cgraph->adjwgt); + free(cadjncy); + + free(perm); + + if (rgraph != (idxtype *)wspace->degrees) + GKfree((void **)&rgraph, (void **)&sgraph, LTERM); + +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/comm.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/comm.c new file mode 100644 index 0000000..fb18789 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/comm.c @@ -0,0 +1,213 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * comm.c + * + * This function provides various high level communication functions + * + * $Id: comm.c,v 1.2 2003/07/21 17:18:48 karypis Exp $ + */ + +#include <parmetislib.h> + + + +/************************************************************************* +* This function performs the gather/scatter for the boundary vertices +**************************************************************************/ +void CommInterfaceData(CtrlType *ctrl, GraphType *graph, idxtype *data, + idxtype *sendvector, idxtype *recvvector) +{ + int i, k, nnbrs, firstvtx; + idxtype *peind, *sendptr, *sendind, *recvptr, *recvind; + + firstvtx = graph->vtxdist[ctrl->mype]; + nnbrs = graph->nnbrs; + peind = graph->peind; + sendptr = graph->sendptr; + sendind = graph->sendind; + recvptr = graph->recvptr; + recvind = graph->recvind; + + /* Issue the receives first */ + for (i=0; i<nnbrs; i++) { + MPI_Irecv((void *)(recvvector+recvptr[i]), recvptr[i+1]-recvptr[i], IDX_DATATYPE, + peind[i], 1, ctrl->comm, ctrl->rreq+i); + } + + /* Issue the sends next */ + k = sendptr[nnbrs]; + for (i=0; i<k; i++) + sendvector[i] = data[sendind[i]-firstvtx]; + + for (i=0; i<nnbrs; i++) { + MPI_Isend((void *)(sendvector+sendptr[i]), sendptr[i+1]-sendptr[i], IDX_DATATYPE, + peind[i], 1, ctrl->comm, ctrl->sreq+i); + } + + /* OK, now get into the loop waiting for the operations to finish */ + MPI_Waitall(nnbrs, ctrl->rreq, ctrl->statuses); + MPI_Waitall(nnbrs, ctrl->sreq, ctrl->statuses); + +} + + + +/************************************************************************* +* This function performs the gather/scatter for the boundary vertices +**************************************************************************/ +void CommChangedInterfaceData(CtrlType *ctrl, GraphType *graph, + int nchanged, idxtype *changed, idxtype *data, + KeyValueType *sendpairs, KeyValueType *recvpairs, idxtype *psendptr) +{ + int i, j, k, n, penum, nnbrs, firstvtx, nrecv; + idxtype *peind, *sendptr, *recvptr, *recvind, *pexadj, *peadjncy, *peadjloc; + KeyValueType *pairs; + + firstvtx = graph->vtxdist[ctrl->mype]; + nnbrs = graph->nnbrs; + nrecv = graph->nrecv; + peind = graph->peind; + sendptr = graph->sendptr; + recvptr = graph->recvptr; + recvind = graph->recvind; + pexadj = graph->pexadj; + peadjncy = graph->peadjncy; + peadjloc = graph->peadjloc; + + /* Issue the receives first */ + for (i=0; i<nnbrs; i++) { + MPI_Irecv((void *)(recvpairs+recvptr[i]), 2*(recvptr[i+1]-recvptr[i]), IDX_DATATYPE, + peind[i], 1, ctrl->comm, ctrl->rreq+i); + } + + if (nchanged != 0) { + idxcopy(ctrl->npes, sendptr, psendptr); + + /* Copy the changed values into the sendvector */ + for (i=0; i<nchanged; i++) { + j = changed[i]; + for (k=pexadj[j]; k<pexadj[j+1]; k++) { + penum = peadjncy[k]; + sendpairs[psendptr[penum]].key = peadjloc[k]; + sendpairs[psendptr[penum]].val = data[j]; + psendptr[penum]++; + } + } + + for (i=0; i<nnbrs; i++) { + MPI_Isend((void *)(sendpairs+sendptr[i]), 2*(psendptr[i]-sendptr[i]), IDX_DATATYPE, + peind[i], 1, ctrl->comm, ctrl->sreq+i); + } + } + else { + for (i=0; i<nnbrs; i++) + MPI_Isend((void *)(sendpairs), 0, IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->sreq+i); + } + + /* OK, now get into the loop waiting for the operations to finish */ + for (i=0; i<nnbrs; i++) { + MPI_Wait(ctrl->rreq+i, &(ctrl->status)); + MPI_Get_count(&ctrl->status, IDX_DATATYPE, &n); + if (n != 0) { + n = n/2; + pairs = recvpairs+graph->recvptr[i]; + for (k=0; k<n; k++) + data[pairs[k].key] = pairs[k].val; + } + } + + MPI_Waitall(nnbrs, ctrl->sreq, ctrl->statuses); +} + + + +/************************************************************************* +* This function computes the max of a single element +**************************************************************************/ +int GlobalSEMax(CtrlType *ctrl, int value) +{ + int max; + + MPI_Allreduce((void *)&value, (void *)&max, 1, MPI_INT, MPI_MAX, ctrl->comm); + + return max; +} + +/************************************************************************* +* This function computes the max of a single element +**************************************************************************/ +double GlobalSEMaxDouble(CtrlType *ctrl, double value) +{ + double max; + + MPI_Allreduce((void *)&value, (void *)&max, 1, MPI_DOUBLE, MPI_MAX, ctrl->comm); + + return max; +} + + + +/************************************************************************* +* This function computes the max of a single element +**************************************************************************/ +int GlobalSEMin(CtrlType *ctrl, int value) +{ + int min; + + MPI_Allreduce((void *)&value, (void *)&min, 1, MPI_INT, MPI_MIN, ctrl->comm); + + return min; +} + +/************************************************************************* +* This function computes the max of a single element +**************************************************************************/ +int GlobalSESum(CtrlType *ctrl, int value) +{ + int sum; + + MPI_Allreduce((void *)&value, (void *)&sum, 1, MPI_INT, MPI_SUM, ctrl->comm); + + return sum; +} + + +/************************************************************************* +* This function computes the max of a single element +**************************************************************************/ +float GlobalSEMaxFloat(CtrlType *ctrl, float value) +{ + float max; + + MPI_Allreduce((void *)&value, (void *)&max, 1, MPI_FLOAT, MPI_MAX, ctrl->comm); + + return max; +} + + + +/************************************************************************* +* This function computes the max of a single element +**************************************************************************/ +float GlobalSEMinFloat(CtrlType *ctrl, float value) +{ + float min; + + MPI_Allreduce((void *)&value, (void *)&min, 1, MPI_FLOAT, MPI_MIN, ctrl->comm); + + return min; +} + +/************************************************************************* +* This function computes the max of a single element +**************************************************************************/ +float GlobalSESumFloat(CtrlType *ctrl, float value) +{ + float sum; + + MPI_Allreduce((void *)&value, (void *)&sum, 1, MPI_FLOAT, MPI_SUM, ctrl->comm); + + return sum; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/csrmatch.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/csrmatch.c new file mode 100644 index 0000000..ace7998 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/csrmatch.c @@ -0,0 +1,88 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * csrmatch.c + * + * This file contains the code that computes matchings + * + * Started 7/23/97 + * George + * + * $Id: csrmatch.c,v 1.2 2003/07/21 17:18:48 karypis Exp $ + * + */ + +#include <parmetislib.h> + + + + +/************************************************************************* +* This function finds a matching using the HEM heuristic +**************************************************************************/ +void CSR_Match_SHEM(MatrixType *matrix, idxtype *match, idxtype *mlist, + idxtype *skip, int ncon) +{ + int h, i, ii, j; + int nrows, edge, maxidx, count; + float maxwgt; + idxtype *rowptr, *colind; + float *transfer; + KVType *links; + + nrows = matrix->nrows; + rowptr = matrix->rowptr; + colind = matrix->colind; + transfer = matrix->transfer; + + idxset(nrows, UNMATCHED, match); + + links = (KVType *)GKmalloc(sizeof(KVType)*nrows, "links"); + for (i=0; i<nrows; i++) { + links[i].key = i; + links[i].val = 0.0; + } + + for (i=0; i<nrows; i++) + for (j=rowptr[i]; j<rowptr[i+1]; j++) + for (h=0; h<ncon; h++) + if (links[i].val < fabs(transfer[j*ncon+h])) + links[i].val = fabs(transfer[j*ncon+h]); + + qsort(links, nrows, sizeof(KVType), myvalkeycompare); + + count = 0; + for (ii=0; ii<nrows; ii++) { + i = links[ii].key; + + if (match[i] == UNMATCHED) { + maxidx = i; + maxwgt = 0.0; + + /* Find a heavy-edge matching */ + for (j=rowptr[i]; j<rowptr[i+1]; j++) { + edge = colind[j]; + if (match[edge] == UNMATCHED && edge != i && skip[j] == 0) { + for (h=0; h<ncon; h++) + if (maxwgt < fabs(transfer[j*ncon+h])) + break; + + if (h != ncon) { + maxwgt = fabs(transfer[j*ncon+h]); + maxidx = edge; + } + } + } + + if (maxidx != i) { + match[i] = maxidx; + match[maxidx] = i; + mlist[count++] = amax(i, maxidx); + mlist[count++] = amin(i, maxidx); + } + } + } + + GKfree((void **)&links, LTERM); +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/debug.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/debug.c new file mode 100644 index 0000000..ebdf69c --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/debug.c @@ -0,0 +1,247 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * debug.c + * + * This file contains various functions that are used to display debuging + * information + * + * Started 10/20/96 + * George + * + * $Id: debug.c,v 1.2 2003/07/21 17:18:48 karypis Exp $ + * + */ + +#include <parmetislib.h> + + +/************************************************************************* +* This function prints a vector stored in each processor +**************************************************************************/ +void PrintVector(CtrlType *ctrl, int n, int first, idxtype *vec, char *title) +{ + int i, penum; + + for (penum=0; penum<ctrl->npes; penum++) { + if (ctrl->mype == penum) { + if (ctrl->mype == 0) + printf("%s\n", title); + printf("\t%3d. ", ctrl->mype); + for (i=0; i<n; i++) + printf("[%d %hd] ", first+i, vec[i]); + printf("\n"); + fflush(stdout); + } + MPI_Barrier(ctrl->comm); + } +} + + +/************************************************************************* +* This function prints a vector stored in each processor +**************************************************************************/ +void PrintVector2(CtrlType *ctrl, int n, int first, idxtype *vec, char *title) +{ + int i, penum; + + for (penum=0; penum<ctrl->npes; penum++) { + if (ctrl->mype == penum) { + if (ctrl->mype == 0) + printf("%s\n", title); + printf("\t%3d. ", ctrl->mype); + for (i=0; i<n; i++) + printf("[%d %d.%hd] ", first+i, (vec[i]>=KEEP_BIT ? 1 : 0), (vec[i]>=KEEP_BIT ? vec[i]-KEEP_BIT : vec[i])); + printf("\n"); + fflush(stdout); + } + MPI_Barrier(ctrl->comm); + } +} + + +/************************************************************************* +* This function prints a vector stored in each processor +**************************************************************************/ +void PrintPairs(CtrlType *ctrl, int n, KeyValueType *pairs, char *title) +{ + int i, penum; + + for (penum=0; penum<ctrl->npes; penum++) { + if (ctrl->mype == penum) { + if (ctrl->mype == 0) + printf("%s\n", title); + printf("\t%3d. ", ctrl->mype); + for (i=0; i<n; i++) + printf("[%d %hd,%hd] ", i, pairs[i].key, pairs[i].val); + printf("\n"); + fflush(stdout); + } + MPI_Barrier(ctrl->comm); + } +} + + + +/************************************************************************* +* This function prints the local portion of the graph stored at each +* processor +**************************************************************************/ +void PrintGraph(CtrlType *ctrl, GraphType *graph) +{ + int i, j, penum; + int firstvtx; + + MPI_Barrier(ctrl->comm); + + firstvtx = graph->vtxdist[ctrl->mype]; + + for (penum=0; penum<ctrl->npes; penum++) { + if (ctrl->mype == penum) { + printf("\t%d", penum); + for (i=0; i<graph->nvtxs; i++) { + if (i==0) + printf("\t%2d %2d\t", firstvtx+i, graph->vwgt[i]); + else + printf("\t\t%2d %2d\t", firstvtx+i, graph->vwgt[i]); + for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++) + printf("[%d %d] ", graph->adjncy[j], graph->adjwgt[j]); + printf("\n"); + } + fflush(stdout); + } + MPI_Barrier(ctrl->comm); + } +} + + +/************************************************************************* +* This function prints the local portion of the graph stored at each +* processor along with degree information during refinement +**************************************************************************/ +void PrintGraph2(CtrlType *ctrl, GraphType *graph) +{ + int i, j, penum; + int firstvtx; + + MPI_Barrier(ctrl->comm); + + firstvtx = graph->vtxdist[ctrl->mype]; + + for (penum=0; penum<ctrl->npes; penum++) { + if (ctrl->mype == penum) { + printf("\t%d", penum); + for (i=0; i<graph->nvtxs; i++) { + if (i==0) + printf("\t%2d %2d [%d %d %d]\t", firstvtx+i, graph->vwgt[i], graph->where[i], graph->rinfo[i].id, graph->rinfo[i].ed); + else + printf("\t\t%2d %2d [%d %d %d]\t", firstvtx+i, graph->vwgt[i], graph->where[i], graph->rinfo[i].id, graph->rinfo[i].ed); + for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++) + printf("[%d %d] ", graph->adjncy[j], graph->adjwgt[j]); + printf("\n"); + } + fflush(stdout); + } + MPI_Barrier(ctrl->comm); + } +} + + +/************************************************************************* +* This function prints the information computed during setup +**************************************************************************/ +void PrintSetUpInfo(CtrlType *ctrl, GraphType *graph) +{ + int i, j, penum; + + MPI_Barrier(ctrl->comm); + + for (penum=0; penum<ctrl->npes; penum++) { + if (ctrl->mype == penum) { + printf("PE: %d, nnbrs: %d\n", ctrl->mype, graph->nnbrs); + printf("\tSending...\n"); + for (i=0; i<graph->nnbrs; i++) { + printf("\t\tTo: %d: ", graph->peind[i]); + for (j=graph->sendptr[i]; j<graph->sendptr[i+1]; j++) + printf("%d ", graph->sendind[j]); + printf("\n"); + } + printf("\tReceiving...\n"); + for (i=0; i<graph->nnbrs; i++) { + printf("\t\tFrom: %d: ", graph->peind[i]); + for (j=graph->recvptr[i]; j<graph->recvptr[i+1]; j++) + printf("%d ", graph->recvind[j]); + printf("\n"); + } + printf("\n"); + } + MPI_Barrier(ctrl->comm); + } + +} + + +/************************************************************************* +* This function prints information about the graphs that were sent/received +**************************************************************************/ +void PrintTransferedGraphs(CtrlType *ctrl, int nnbrs, idxtype *peind, idxtype *slens, + idxtype *rlens, idxtype *sgraph, idxtype *rgraph) +{ + int i, ii, jj, ll, penum; + + MPI_Barrier(ctrl->comm); + for (penum=0; penum<ctrl->npes; penum++) { + if (ctrl->mype == penum) { + printf("PE: %d, nnbrs: %d", ctrl->mype, nnbrs); + for (ll=i=0; i<nnbrs; i++) { + if (slens[i+1]-slens[i] > 0) { + printf("\n\tTo %d\t", peind[i]); + for (ii=slens[i]; ii<slens[i+1]; ii++) { + printf("%d %d %d, ", sgraph[ll], sgraph[ll+1], sgraph[ll+2]); + for (jj=0; jj<sgraph[ll+1]; jj++) + printf("[%d %d] ", sgraph[ll+3+2*jj], sgraph[ll+3+2*jj+1]); + printf("\n\t\t"); + ll += 3+2*sgraph[ll+1]; + } + } + } + + for (ll=i=0; i<nnbrs; i++) { + if (rlens[i+1]-rlens[i] > 0) { + printf("\n\tFrom %d\t", peind[i]); + for (ii=rlens[i]; ii<rlens[i+1]; ii++) { + printf("%d %d %d, ", rgraph[ll], rgraph[ll+1], rgraph[ll+2]); + for (jj=0; jj<rgraph[ll+1]; jj++) + printf("[%d %d] ", rgraph[ll+3+2*jj], rgraph[ll+3+2*jj+1]); + printf("\n\t\t"); + ll += 3+2*rgraph[ll+1]; + } + } + } + printf("\n"); + } + MPI_Barrier(ctrl->comm); + } + +} + + +/************************************************************************* +* This function writes a graph in the format used by serial METIS +**************************************************************************/ +void WriteMetisGraph(int nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt) +{ + int i, j; + FILE *fp; + + fp = fopen("test.graph", "w"); + + fprintf(fp, "%d %d 11", nvtxs, xadj[nvtxs]/2); + for (i=0; i<nvtxs; i++) { + fprintf(fp, "\n%d ", vwgt[i]); + for (j=xadj[i]; j<xadj[i+1]; j++) + fprintf(fp, " %d %d", adjncy[j]+1, adjwgt[j]); + } + fclose(fp); +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/defs.h b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/defs.h new file mode 100644 index 0000000..3d47f1d --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/defs.h @@ -0,0 +1,102 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * defs.h + * + * This file contains constant definitions + * + * Started 8/27/94 + * George + * + * $Id: defs.h,v 1.4 2003/07/22 20:29:05 karypis Exp $ + * + */ + + +#define GLOBAL_DBGLVL 0 +#define GLOBAL_SEED 15 + +#define MC_FLOW_BALANCE_THRESHOLD 0.2 +#define MOC_GD_GRANULARITY_FACTOR 1.0 +#define RIP_SPLIT_FACTOR 8 +#define MAX_NPARTS_MULTIPLIER 20 + +#define STATIC_PARTITION 1 +#define ADAPTIVE_PARTITION 2 +#define REFINE_PARTITION 3 +#define MESH_PARTITION 4 + +#define REDIST_WGT 2.0 +#define MAXNVWGT_FACTOR 2.0 + +#define MAXNCON 12 +#define MAXNOBJ 12 +#define N_MOC_REDO_PASSES 10 +#define N_MOC_GR_PASSES 8 +#define NREMAP_PASSES 8 +#define N_MOC_GD_PASSES 6 +#define N_MOC_BAL_PASSES 4 +#define NMATCH_PASSES 4 + +#define COUPLED 1 +#define DISCOUPLED 2 + +#define MAX_NCON_FOR_DIFFUSION 2 +#define SMALLGRAPH 10000 + +#define LTERM (void **) 0 /* List terminator for GKfree() */ + +#define NGD_PASSES 20 + +#define OPTION_IPART 1 +#define OPTION_FOLDF 2 +#define OPTION_DBGLVL 3 + +#define PMV3_OPTION_DBGLVL 1 +#define PMV3_OPTION_SEED 2 +#define PMV3_OPTION_IPART 3 +#define PMV3_OPTION_PSR 3 + +#define XYZ_XCOORD 1 +#define XYZ_SPFILL 2 + +/* Type of initial vertex separator algorithms */ +#define ISEP_EDGE 1 +#define ISEP_NODE 2 + +#define UNMATCHED -1 +#define MAYBE_MATCHED -2 +#define TOO_HEAVY -3 + + +#define HTABLE_EMPTY -1 + +#define NGR_PASSES 4 /* Number of greedy refinement passes */ +#define NIPARTS 8 /* Number of random initial partitions */ +#define NLGR_PASSES 5 /* Number of GR refinement during IPartition */ + +#define SMALLFLOAT 0.00001 +/* #define KEEP_BIT (idxtype)536870912 */ /* 1<<29 */ +#define KEEP_BIT ((idxtype)(1<<((sizeof(idxtype)*8)-2))) + +#define MAX_PES 8192 +#define MAX_NPARTS 67108864 + +#define COARSEN_FRACTION 0.75 /* Node reduction between succesive coarsening levels */ +#define COARSEN_FRACTION2 0.55 /* Node reduction between succesive coarsening levels */ +#define UNBALANCE_FRACTION 1.05 +#define ORDER_UNBALANCE_FRACTION 1.05 + +#define MAXVWGT_FACTOR 1.4 + +#define MATCH_LOCAL 1 +#define MATCH_GLOBAL 2 + +/* Debug Levels */ +#define DBG_TIME 1 /* Perform timing analysis */ +#define DBG_INFO 2 /* Perform timing analysis */ +#define DBG_PROGRESS 4 /* Show the coarsening progress */ +#define DBG_REFINEINFO 8 /* Show info on communication during folding */ +#define DBG_MATCHINFO 16 /* Show info on matching */ +#define DBG_RMOVEINFO 32 /* Show info on communication during folding */ +#define DBG_REMAP 64 /* Determines if remapping will take place */ diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/diffutil.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/diffutil.c new file mode 100644 index 0000000..f31da64 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/diffutil.c @@ -0,0 +1,298 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * wavefrontK.c + * + * This file contains code for the initial directed diffusion at the coarsest + * graph + * + * Started 5/19/97, Kirk, George + * + * $Id: diffutil.c,v 1.2 2003/07/21 17:18:48 karypis Exp $ + * + */ + +#include <parmetislib.h> + + +/************************************************************************* +* This function computes the load for each subdomain +**************************************************************************/ +void SetUpConnectGraph(GraphType *graph, MatrixType *matrix, idxtype *workspace) +{ + int i, ii, j, jj, k, l; + int nvtxs, nrows; + idxtype *xadj, *adjncy, *where; + idxtype *rowptr, *colind; + idxtype *pcounts, *perm, *marker; + float *values; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + where = graph->where; + + nrows = matrix->nrows; + rowptr = matrix->rowptr; + colind = matrix->colind; + values = matrix->values; + + perm = workspace; + marker = idxset(nrows, -1, workspace+nvtxs); + pcounts = idxset(nrows+1, 0, workspace+nvtxs+nrows); + + for (i=0; i<nvtxs; i++) + pcounts[where[i]]++; + MAKECSR(i, nrows, pcounts); + + for (i=0; i<nvtxs; i++) + perm[pcounts[where[i]]++] = i; + + for (i=nrows; i>0; i--) + pcounts[i] = pcounts[i-1]; + pcounts[0] = 0; + + /************************/ + /* Construct the matrix */ + /************************/ + rowptr[0] = k = 0; + for (ii=0; ii<nrows; ii++) { + colind[k++] = ii; + marker[ii] = ii; + + for (jj=pcounts[ii]; jj<pcounts[ii+1]; jj++) { + i = perm[jj]; + for (j=xadj[i]; j<xadj[i+1]; j++) { + l = where[adjncy[j]]; + if (marker[l] != ii) { + colind[k] = l; + values[k++] = -1.0; + marker[l] = ii; + } + } + } + values[rowptr[ii]] = (float)(k-rowptr[ii]-1); + rowptr[ii+1] = k; + } + matrix->nnzs = rowptr[nrows]; + + return; +} + + +/************************************************************************* +* This function computes movement statistics for adaptive refinement +* schemes +**************************************************************************/ +void Mc_ComputeMoveStatistics(CtrlType *ctrl, GraphType *graph, int *nmoved, int *maxin, int *maxout) +{ + int i, nvtxs, nparts, myhome; + idxtype *vwgt, *where; + idxtype *lend, *gend, *lleft, *gleft, *lstart, *gstart; + + nvtxs = graph->nvtxs; + vwgt = graph->vwgt; + where = graph->where; + nparts = ctrl->nparts; + + lstart = idxsmalloc(nparts, 0, "ComputeMoveStatistics: lstart"); + gstart = idxsmalloc(nparts, 0, "ComputeMoveStatistics: gstart"); + lleft = idxsmalloc(nparts, 0, "ComputeMoveStatistics: lleft"); + gleft = idxsmalloc(nparts, 0, "ComputeMoveStatistics: gleft"); + lend = idxsmalloc(nparts, 0, "ComputeMoveStatistics: lend"); + gend = idxsmalloc(nparts, 0, "ComputeMoveStatistics: gend"); + + for (i=0; i<nvtxs; i++) { + myhome = (ctrl->ps_relation == COUPLED) ? ctrl->mype : graph->home[i]; + lstart[myhome] += (graph->vsize == NULL) ? 1 : graph->vsize[i]; + lend[where[i]] += (graph->vsize == NULL) ? 1 : graph->vsize[i]; + if (where[i] != myhome) + lleft[myhome] += (graph->vsize == NULL) ? 1 : graph->vsize[i]; + } + + /* PrintVector(ctrl, ctrl->npes, 0, lend, "Lend: "); */ + + MPI_Allreduce((void *)lstart, (void *)gstart, nparts, IDX_DATATYPE, MPI_SUM, ctrl->comm); + MPI_Allreduce((void *)lleft, (void *)gleft, nparts, IDX_DATATYPE, MPI_SUM, ctrl->comm); + MPI_Allreduce((void *)lend, (void *)gend, nparts, IDX_DATATYPE, MPI_SUM, ctrl->comm); + + *nmoved = idxsum(nparts, gleft); + *maxout = gleft[idxamax(nparts, gleft)]; + for (i=0; i<nparts; i++) + lstart[i] = gend[i]+gleft[i]-gstart[i]; + *maxin = lstart[idxamax(nparts, lstart)]; + + GKfree((void **)&lstart, (void **)&gstart, (void **)&lleft, (void **)&gleft, (void **)&lend, (void **)&gend, LTERM); +} + +/************************************************************************* +* This function computes the TotalV of a serial graph. +**************************************************************************/ +int Mc_ComputeSerialTotalV(GraphType *graph, idxtype *home) +{ + int i; + int totalv = 0; + + for (i=0; i<graph->nvtxs; i++) { + if (graph->where[i] != home[i]) + totalv += (graph->vsize == NULL) ? graph->vwgt[i*graph->ncon] : graph->vsize[i]; + } + + return totalv; +} + + + +/************************************************************************* +* This function computes the load for each subdomain +**************************************************************************/ +void ComputeLoad(GraphType *graph, int nparts, float *load, float *tpwgts, int index) +{ + int i; + int nvtxs, ncon; + idxtype *where; + float *nvwgt; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + where = graph->where; + nvwgt = graph->nvwgt; + + sset(nparts, 0.0, load); + + for (i=0; i<nvtxs; i++) + load[where[i]] += nvwgt[i*ncon+index]; + + ASSERTS(fabs(ssum(nparts, load)-1.0) < 0.001); + + for (i=0; i<nparts; i++) { + load[i] -= tpwgts[i*ncon+index]; + } + + return; +} + + +/************************************************************************* +* This function implements the CG solver used during the directed diffusion +**************************************************************************/ +void ConjGrad2(MatrixType *A, float *b, float *x, float tol, float *workspace) +{ + int i, k, n; + float *p, *r, *q, *z, *M; + float alpha, beta, rho, rho_1 = -1.0, error, bnrm2, tmp; + idxtype *rowptr, *colind; + float *values; + + n = A->nrows; + rowptr = A->rowptr; + colind = A->colind; + values = A->values; + + /* Initial Setup */ + p = workspace; + r = workspace + n; + q = workspace + 2*n; + z = workspace + 3*n; + M = workspace + 4*n; + + for (i=0; i<n; i++) { + x[i] = 0.0; + if (values[rowptr[i]] != 0.0) + M[i] = 1.0/values[rowptr[i]]; + else + M[i] = 0.0; + } + + /* r = b - Ax */ + mvMult2(A, x, r); + for (i=0; i<n; i++) + r[i] = b[i]-r[i]; + + bnrm2 = snorm2(n, b); + if (bnrm2 > 0.0) { + error = snorm2(n, r) / bnrm2; + + if (error > tol) { + /* Begin Iterations */ + for (k=0; k<n; k++) { + for (i=0; i<n; i++) + z[i] = r[i]*M[i]; + + rho = sdot(n, r, z); + + if (k == 0) + scopy(n, z, p); + else { + if (rho_1 != 0.0) + beta = rho/rho_1; + else + beta = 0.0; + for (i=0; i<n; i++) + p[i] = z[i] + beta*p[i]; + } + + mvMult2(A, p, q); /* q = A*p */ + + tmp = sdot(n, p, q); + if (tmp != 0.0) + alpha = rho/tmp; + else + alpha = 0.0; + saxpy(n, alpha, p, x); /* x = x + alpha*p */ + saxpy(n, -alpha, q, r); /* r = r - alpha*q */ + error = snorm2(n, r) / bnrm2; + if (error < tol) + break; + + rho_1 = rho; + } + } + } +} + + +/************************************************************************* +* This function performs Matrix-Vector multiplication +**************************************************************************/ +void mvMult2(MatrixType *A, float *v, float *w) +{ + int i, j; + + for (i = 0; i < A->nrows; i++) + w[i] = 0.0; + + for (i = 0; i < A->nrows; i++) + for (j = A->rowptr[i]; j < A->rowptr[i+1]; j++) + w[i] += A->values[j] * v[A->colind[j]]; + + return; + } + + +/************************************************************************* +* This function sets up the transfer vectors +**************************************************************************/ +void ComputeTransferVector(int ncon, MatrixType *matrix, float *solution, + float *transfer, int index) +{ + int j, k; + int nrows; + idxtype *rowptr, *colind; + + nrows = matrix->nrows; + rowptr = matrix->rowptr; + colind = matrix->colind; + + for (j=0; j<nrows; j++) { + for (k=rowptr[j]+1; k<rowptr[j+1]; k++) { + if (solution[j] > solution[colind[k]]) { + transfer[k*ncon+index] = solution[j] - solution[colind[k]]; + } + else { + transfer[k*ncon+index] = 0.0; + } + } + } +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/fpqueue.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/fpqueue.c new file mode 100644 index 0000000..11c617f --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/fpqueue.c @@ -0,0 +1,440 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * fpqueue.c + * + * This file contains functions for manipulating the bucket list + * representation of the gains associated with each vertex in a graph. + * These functions are used by the refinement algorithms + * + * Started 9/2/94 + * George + * + * $Id: fpqueue.c,v 1.2 2003/07/21 17:18:48 karypis Exp $ + * + */ + +#include <parmetislib.h> + + +/************************************************************************* +* This function initializes the data structures of the priority queue +**************************************************************************/ +void FPQueueInit(FPQueueType *queue, int maxnodes) +{ + queue->nnodes = 0; + queue->maxnodes = maxnodes; + queue->heap = NULL; + queue->locator = NULL; + + queue->heap = (FKeyValueType *) malloc(sizeof(FKeyValueType)*maxnodes); + queue->locator = (idxtype *) malloc(sizeof(idxtype)*maxnodes); + + idxset(maxnodes, -1, queue->locator); + +} + + +/************************************************************************* +* This function resets the buckets +**************************************************************************/ +void FPQueueReset(FPQueueType *queue) +{ + queue->nnodes = 0; + + idxset(queue->maxnodes, -1, queue->locator); + +} + + +/************************************************************************* +* This function frees the buckets +**************************************************************************/ +void FPQueueFree(FPQueueType *queue) +{ + + free(queue->heap); + free(queue->locator); + + queue->maxnodes = 0; +} + + +/************************************************************************* +* This function returns the number of nodes in the queue +**************************************************************************/ +int FPQueueGetSize(FPQueueType *queue) +{ + return queue->nnodes; +} + + +/************************************************************************* +* This function adds a node of certain gain into a partition +**************************************************************************/ +int FPQueueInsert(FPQueueType *queue, int node, float gain) +{ + int i, j; + idxtype *locator; + FKeyValueType *heap; + + ASSERTS(CheckHeapFloat(queue)); + + heap = queue->heap; + locator = queue->locator; + + ASSERTS(locator[node] == -1); + + i = queue->nnodes++; + while (i > 0) { + j = (i-1)/2; + if (heap[j].key < gain) { + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else + break; + } + ASSERTS(i >= 0); + heap[i].key = gain; + heap[i].val = node; + locator[node] = i; + + ASSERTS(CheckHeapFloat(queue)); + + return 0; +} + + +/************************************************************************* +* This function deletes a node from a partition and reinserts it with +* an updated gain +**************************************************************************/ +int FPQueueDelete(FPQueueType *queue, int node) +{ + int i, j; + float newgain, oldgain; + idxtype *locator; + FKeyValueType *heap; + + heap = queue->heap; + locator = queue->locator; + + ASSERTS(locator[node] != -1); + ASSERTS(heap[locator[node]].val == node); + + ASSERTS(CheckHeapFloat(queue)); + + i = locator[node]; + locator[node] = -1; + + if (--queue->nnodes > 0 && heap[queue->nnodes].val != node) { + node = heap[queue->nnodes].val; + newgain = heap[queue->nnodes].key; + oldgain = heap[i].key; + + if (oldgain < newgain) { + /* Filter-up */ + while (i > 0) { + j = (i-1)>>1; + if (heap[j].key < newgain) { + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else + break; + } + } + else { + /* Filter down */ + while ((j=2*i+1) < queue->nnodes) { + if (heap[j].key > newgain) { + if (j+1 < queue->nnodes && heap[j+1].key > heap[j].key) + j = j+1; + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else if (j+1 < queue->nnodes && heap[j+1].key > newgain) { + j = j+1; + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else + break; + } + } + + heap[i].key = newgain; + heap[i].val = node; + locator[node] = i; + } + + ASSERTS(CheckHeapFloat(queue)); + + return 0; +} + + + +/************************************************************************* +* This function deletes a node from a partition and reinserts it with +* an updated gain +**************************************************************************/ +int FPQueueUpdate(FPQueueType *queue, int node, float oldgain, float newgain) +{ + int i, j; + idxtype *locator; + FKeyValueType *heap; + + if (oldgain == newgain) + return 0; + + heap = queue->heap; + locator = queue->locator; + + ASSERTS(locator[node] != -1); + ASSERTS(heap[locator[node]].val == node); + ASSERTS(fabs(heap[locator[node]].key - oldgain) < SMALLFLOAT); + ASSERTS(CheckHeapFloat(queue)); + + i = locator[node]; + + if (oldgain < newgain) { + /* Filter-up */ + while (i > 0) { + j = (i-1)>>1; + if (heap[j].key < newgain) { + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else + break; + } + } + else { + /* Filter down */ + while ((j=2*i+1) < queue->nnodes) { + if (heap[j].key > newgain) { + if (j+1 < queue->nnodes && heap[j+1].key > heap[j].key) + j = j+1; + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else if (j+1 < queue->nnodes && heap[j+1].key > newgain) { + j = j+1; + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else + break; + } + } + + heap[i].key = newgain; + heap[i].val = node; + locator[node] = i; + + ASSERTS(CheckHeapFloat(queue)); + + return 0; +} + + + +/************************************************************************* +* This function deletes a node from a partition and reinserts it with +* an updated gain +**************************************************************************/ +void FPQueueUpdateUp(FPQueueType *queue, int node, float oldgain, float newgain) +{ + int i, j; + idxtype *locator; + FKeyValueType *heap; + + if (oldgain == newgain) + return; + + heap = queue->heap; + locator = queue->locator; + + ASSERTS(locator[node] != -1); + ASSERTS(heap[locator[node]].val == node); + ASSERTS(heap[locator[node]].key == oldgain); + ASSERTS(CheckHeapFloat(queue)); + + + /* Here we are just filtering up since the newgain is greater than the oldgain */ + i = locator[node]; + while (i > 0) { + j = (i-1)>>1; + if (heap[j].key < newgain) { + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else + break; + } + + heap[i].key = newgain; + heap[i].val = node; + locator[node] = i; + + ASSERTS(CheckHeapFloat(queue)); + +} + + +/************************************************************************* +* This function returns the vertex with the largest gain from a partition +* and removes the node from the bucket list +**************************************************************************/ +int FPQueueGetMax(FPQueueType *queue) +{ + int vtx, i, j, node; + float gain; + idxtype *locator; + FKeyValueType *heap; + + if (queue->nnodes == 0) + return -1; + + queue->nnodes--; + + heap = queue->heap; + locator = queue->locator; + + vtx = heap[0].val; + locator[vtx] = -1; + + if ((i = queue->nnodes) > 0) { + gain = heap[i].key; + node = heap[i].val; + i = 0; + while ((j=2*i+1) < queue->nnodes) { + if (heap[j].key > gain) { + if (j+1 < queue->nnodes && heap[j+1].key > heap[j].key) + j = j+1; + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else if (j+1 < queue->nnodes && heap[j+1].key > gain) { + j = j+1; + heap[i] = heap[j]; + locator[heap[i].val] = i; + i = j; + } + else + break; + } + + heap[i].key = gain; + heap[i].val = node; + locator[node] = i; + } + + ASSERTS(CheckHeapFloat(queue)); + return vtx; +} + + +/************************************************************************* +* This function returns the vertex with the largest gain from a partition +**************************************************************************/ +int FPQueueSeeMaxVtx(FPQueueType *queue) +{ + int vtx; + + if (queue->nnodes == 0) + return -1; + + vtx = queue->heap[0].val; + + return vtx; +} + + +/************************************************************************* +* This function returns the vertex with the largest gain from a partition +**************************************************************************/ +float FPQueueSeeMaxGain(FPQueueType *queue) +{ + float gain; + + if (queue->nnodes == 0) + return 0.0; + + gain = queue->heap[0].key; + + return gain; +} + + +/************************************************************************* +* This function returns the vertex with the largest gain from a partition +**************************************************************************/ +float FPQueueGetKey(FPQueueType *queue) +{ + int key; + + if (queue->nnodes == 0) + return -1; + + key = queue->heap[0].key; + + return key; +} + +/************************************************************************* +* This function returns the number of nodes in the queue +**************************************************************************/ +int FPQueueGetQSize(FPQueueType *queue) +{ + return queue->nnodes; +} + + + + + + +/************************************************************************* +* This functions checks the consistency of the heap +**************************************************************************/ +int CheckHeapFloat(FPQueueType *queue) +{ + int i, j, nnodes; + idxtype *locator; + FKeyValueType *heap; + + heap = queue->heap; + locator = queue->locator; + nnodes = queue->nnodes; + + if (nnodes == 0) + return 1; + + ASSERTS(locator[heap[0].val] == 0); + for (i=1; i<nnodes; i++) { + ASSERTS(locator[heap[i].val] == i); + ASSERTS(heap[i].key <= heap[(i-1)/2].key); + } + for (i=1; i<nnodes; i++) + ASSERTS(heap[i].key <= heap[0].key); + + for (j=i=0; i<queue->maxnodes; i++) { + if (locator[i] != -1) + j++; + } + ASSERTS(j == nnodes); + + return 1; +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/frename.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/frename.c new file mode 100644 index 0000000..551dd59 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/frename.c @@ -0,0 +1,322 @@ +/* + * frename.c + * + * This file contains some renaming routines to deal with different + * Fortran compilers. + * + * Started 6/1/98 + * George + * + * $Id: frename.c,v 1.4 2003/07/30 18:37:58 karypis Exp $ + * + */ + +#include <parmetislib.h> + + + +/************************************************************************* +* Renaming macro (at least to save some typing :)) +**************************************************************************/ +#define FRENAME(name0, name1, name2, name3, name4, dargs, cargs) \ + void name1 dargs { name0 cargs; } \ + void name2 dargs { name0 cargs; } \ + void name3 dargs { name0 cargs; } \ + void name4 dargs { name0 cargs; } + + + + + + + + +/************************************************************************* +* Renames for Release 3.0 API +**************************************************************************/ +FRENAME(ParMETIS_V3_AdaptiveRepart, + PARMETIS_V3_ADAPTIVEREPART, + parmetis_v3_adaptiverepart, + parmetis_v3_adaptiverepart_, + parmetis_v3_adaptiverepart__, + (idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *vsize, idxtype *adjwgt, int *wgtflag, int *numflag, int *ncon, + int *nparts, float *tpwgts, float *ubvec, float *ipc2redist, + int *options, int *edgecut, idxtype *part, MPI_Comm *comm), + (vtxdist, xadj, adjncy, vwgt, vsize, adjwgt, wgtflag, numflag, ncon, + nparts, tpwgts, ubvec, ipc2redist, options, edgecut, part, comm) +) + +FRENAME(ParMETIS_V3_PartGeomKway, + PARMETIS_V3_PARTGEOMKWAY, + parmetis_v3_partgeomkway, + parmetis_v3_partgeomkway_, + parmetis_v3_partgeomkway__, + (idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *ndims, float *xyz, + int *ncon, int *nparts, float *tpwgts, float *ubvec, int *options, + int *edgecut, idxtype *part, MPI_Comm *comm), + (vtxdist, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, ndims, xyz, + ncon, nparts, tpwgts, ubvec, options, edgecut, part, comm) +) + +FRENAME(ParMETIS_V3_PartGeom, + PARMETIS_V3_PARTGEOM, + parmetis_v3_partgeom, + parmetis_v3_partgeom_, + parmetis_v3_partgeom__, + (idxtype *vtxdist, int *ndims, float *xyz, idxtype *part, MPI_Comm *comm), + (vtxdist, ndims, xyz, part, comm) +) + +FRENAME(ParMETIS_V3_PartKway, + PARMETIS_V3_PARTKWAY, + parmetis_v3_partkway, + parmetis_v3_partkway_, + parmetis_v3_partkway__, + (idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, + int *wgtflag, int *numflag, int *ncon, int *nparts, float *tpwgts, float *ubvec, + int *options, int *edgecut, idxtype *part, MPI_Comm *comm), + (vtxdist, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, ncon, nparts, tpwgts, + ubvec, options, edgecut, part, comm) +) + +FRENAME(ParMETIS_V3_Mesh2Dual, + PARMETIS_V3_MESH2DUAL, + parmetis_v3_mesh2dual, + parmetis_v3_mesh2dual_, + parmetis_v3_mesh2dual__, + (idxtype *elmdist, idxtype *eptr, idxtype *eind, int *numflag, int *ncommonnodes, + idxtype **xadj, idxtype **adjncy, MPI_Comm *comm), + (elmdist, eptr, eind, numflag, ncommonnodes, xadj, adjncy, comm) +) + +FRENAME(ParMETIS_V3_PartMeshKway, + PARMETIS_V3_PARTMESHKWAY, + parmetis_v3_partmeshkway, + parmetis_v3_partmeshkway_, + parmetis_v3_partmeshkway__, + (idxtype *elmdist, idxtype *eptr, idxtype *eind, idxtype *elmwgt, int *wgtflag, + int *numflag, int *ncon, int *ncommonnodes, int *nparts, float *tpwgts, + float *ubvec, int *options, int *edgecut, idxtype *part, MPI_Comm *comm), + (elmdist, eptr, eind, elmwgt, wgtflag, numflag, ncon, ncommonnodes, nparts, tpwgts, + ubvec, options, edgecut, part, comm) +) + +FRENAME(ParMETIS_V3_NodeND, + PARMETIS_V3_NODEND, + parmetis_v3_nodend, + parmetis_v3_nodend_, + parmetis_v3_nodend__, + (idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, int *numflag, int *options, + idxtype *order, idxtype *sizes, MPI_Comm *comm), + (vtxdist, xadj, adjncy, numflag, options, order, sizes, comm) +) + +FRENAME(ParMETIS_V3_RefineKway, + PARMETIS_V3_REFINEKWAY, + parmetis_v3_refinekway, + parmetis_v3_refinekway_, + parmetis_v3_refinekway__, + (idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, + int *wgtflag, int *numflag, int *ncon, int *nparts, float *tpwgts, float *ubvec, + int *options, int *edgecut, idxtype *part, MPI_Comm *comm), + (vtxdist, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, ncon, nparts, tpwgts, + ubvec, options, edgecut, part, comm) +) + + +/************************************************************************* +* Renames for Release 2.0 API +**************************************************************************/ +FRENAME(ParMETIS_PartKway, + PARMETIS_PARTKWAY, + parmetis_partkway, + parmetis_partkway_, + parmetis_partkway__, + (idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, + int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, idxtype *part, + MPI_Comm *comm), + (vtxdist, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts, options, edgecut, + part, comm) +) + +FRENAME(ParMETIS_PartGeomKway, + PARMETIS_PARTGEOMKWAY, + parmetis_partgeomkway, + parmetis_partgeomkway_, + parmetis_partgeomkway__, + (idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, + int *wgtflag, int *numflag, int *ndims, float *xyz, int *nparts, int *options, + int *edgecut, idxtype *part, MPI_Comm *comm), + (vtxdist, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, ndims, xyz, nparts, options, + edgecut, part, comm) +) + +FRENAME(ParMETIS_PartGeom, + PARMETIS_PARTGEOM, + parmetis_partgeom, + parmetis_partgeom_, + parmetis_partgeom__, + (idxtype *vtxdist, int *ndims, float *xyz, idxtype *part, MPI_Comm *comm), + (vtxdist, ndims, xyz, part, comm) +) + +FRENAME(ParMETIS_PartGeomRefine, + PARMETIS_PARTGEOMREFINE, + parmetis_partgeomrefine, + parmetis_partgeomrefine_, + parmetis_partgeomrefine__, + (idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, + int *wgtflag, int *numflag, int *ndims, float *xyz, int *options, int *edgecut, + idxtype *part, MPI_Comm *comm), + (vtxdist, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, ndims, xyz, options, + edgecut, part, comm) +) + +FRENAME(ParMETIS_RefineKway, + PARMETIS_REFINEKWAY, + parmetis_refinekway, + parmetis_refinekway_, + parmetis_refinekway__, + (idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, + int *wgtflag, int *numflag, int *options, int *edgecut, idxtype *part, MPI_Comm *comm), + (vtxdist, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, options, edgecut, part, comm) +) + +FRENAME(ParMETIS_RepartLDiffusion, + PARMETIS_REPARTLDIFUSSION, + parmetis_repartldiffusion, + parmetis_repartldiffusion_, + parmetis_repartldiffusion__, + (idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, + int *wgtflag, int *numflag, int *options, int *edgecut, idxtype *part, MPI_Comm *comm), + (vtxdist, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, options, edgecut, part, comm) +) + +FRENAME(ParMETIS_RepartGDiffusion, + PARMETIS_REPARTGDIFFUSION, + parmetis_repartgdiffusion, + parmetis_repartgdiffusion_, + parmetis_repartgdiffusion__, + (idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, + int *wgtflag, int *numflag, int *options, int *edgecut, idxtype *part, MPI_Comm *comm), + (vtxdist, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, options, edgecut, part, comm) +) + +FRENAME(ParMETIS_RepartRemap, + PARMETIS_REPARTREMAP, + parmetis_repartremap, + parmetis_repartremap_, + parmetis_repartremap__, + (idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, + int *wgtflag, int *numflag, int *options, int *edgecut, idxtype *part, MPI_Comm *comm), + (vtxdist, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, options, edgecut, part, comm) +) + +FRENAME(ParMETIS_RepartMLRemap, + PARMETIS_REPARTMLREMAP, + parmetis_repartmlremap, + parmetis_repartmlremap_, + parmetis_repartmlremap__, + (idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, + int *wgtflag, int *numflag, int *options, int *edgecut, idxtype *part, MPI_Comm *comm), + (vtxdist, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, options, edgecut, part, comm) +) + +FRENAME(ParMETIS_NodeND, + PARMETIS_NODEND, + parmetis_nodend, + parmetis_nodend_, + parmetis_nodend__, + (idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, int *numflag, int *options, + idxtype *order, idxtype *sizes, MPI_Comm *comm), + (vtxdist, xadj, adjncy, numflag, options, order, sizes, comm) +) + +FRENAME(ParMETIS_SerialNodeND, + PARMETIS_SERIALNODEND, + parmetis_serialnodend, + parmetis_serialnodend_, + parmetis_serialnodend__, + (idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, int *numflag, int *options, + idxtype *order, idxtype *sizes, MPI_Comm *comm), + (vtxdist, xadj, adjncy, numflag, options, order, sizes, comm) +) + + + + +/************************************************************************* +* Renames for Release 1.0 API +**************************************************************************/ +FRENAME(PARKMETIS, + PARKMETIS_, + parkmetis, + parkmetis_, + parkmetis__, + (idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + idxtype *part, int *options, MPI_Comm comm), + (vtxdist, xadj, vwgt, adjncy, adjwgt, part, options, comm) +) + +FRENAME(PARGKMETIS, + PARGKMETIS_, + pargkmetis, + pargkmetis_, + pargkmetis__, + (idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + int ndims, float *xyz, idxtype *part, int *options, MPI_Comm comm), + (vtxdist, xadj, vwgt, adjncy, adjwgt, ndims, xyz, part, options, comm) +) + +FRENAME(PARGRMETIS, + PARGRMETIS_, + pargrmetis, + pargrmetis_, + pargrmetis__, + (idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + int ndims, float *xyz, idxtype *part, int *options, MPI_Comm comm), + (vtxdist, xadj, vwgt, adjncy, adjwgt, ndims, xyz, part, options, comm) +) + +FRENAME(PARGMETIS, + PARGMETIS_, + pargmetis, + pargmetis_, + pargmetis__, + (idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, int ndims, float *xyz, + idxtype *part, int *options, MPI_Comm comm), + (vtxdist, xadj, adjncy, ndims, xyz, part, options, comm) +) + +FRENAME(PARRMETIS, + PARRMETIS_, + parrmetis, + parrmetis_, + parrmetis__, + (idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + idxtype *part, int *options, MPI_Comm comm), + (vtxdist, xadj, vwgt, adjncy, adjwgt, part, options, comm) +) + +FRENAME(PARUAMETIS, + PARUAMETIS_, + paruametis, + paruametis_, + paruametis__, + (idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + idxtype *part, int *options, MPI_Comm comm), + (vtxdist, xadj, vwgt, adjncy, adjwgt, part, options, comm) +) + +FRENAME(PARDAMETIS, + PARDAMETIS_, + pardametis, + pardametis_, + pardametis__, + (idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + idxtype *part, int *options, MPI_Comm comm), + (vtxdist, xadj, vwgt, adjncy, adjwgt, part, options, comm) +) + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/gkmetis.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/gkmetis.c new file mode 100644 index 0000000..8eb2382 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/gkmetis.c @@ -0,0 +1,331 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * gkmetis.c + * + * This is the entry point of parallel geometry based partitioning + * routines + * + * Started 10/19/96 + * George + * + * $Id: gkmetis.c,v 1.8 2003/07/31 16:23:30 karypis Exp $ + * + */ + +#include <parmetislib.h> + + + + +/*********************************************************************************** +* This function is the entry point of the parallel kmetis algorithm that uses +* coordinates to compute an initial graph distribution. +************************************************************************************/ +void ParMETIS_V3_PartGeomKway(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, + idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *ndims, + float *xyz, int *ncon, int *nparts, float *tpwgts, float *ubvec, + int *options, int *edgecut, idxtype *part, MPI_Comm *comm) +{ + int h, i, j; + int nvtxs = -1, npes, mype; + int uwgtflag, cut, gcut, maxnvtxs; + int ltvwgts[MAXNCON]; + int moptions[10]; + CtrlType ctrl; + idxtype *uvwgt; + WorkSpaceType wspace; + GraphType *graph, *mgraph; + float avg, maximb, balance, *mytpwgts; + int seed, dbglvl = 0; + int iwgtflag, inumflag, incon, inparts, ioptions[10]; + float *itpwgts, iubvec[MAXNCON]; + + MPI_Comm_size(*comm, &npes); + MPI_Comm_rank(*comm, &mype); + + /********************************/ + /* Try and take care bad inputs */ + /********************************/ + if (options != NULL && options[0] == 1) + dbglvl = options[PMV3_OPTION_DBGLVL]; + + CheckInputs(STATIC_PARTITION, npes, dbglvl, wgtflag, &iwgtflag, numflag, &inumflag, + ncon, &incon, nparts, &inparts, tpwgts, &itpwgts, ubvec, iubvec, + NULL, NULL, options, ioptions, part, comm); + + + /*********************************/ + /* Take care the nparts = 1 case */ + /*********************************/ + if (inparts <= 1) { + idxset(vtxdist[mype+1]-vtxdist[mype], 0, part); + *edgecut = 0; + return; + } + + /******************************/ + /* Take care of npes = 1 case */ + /******************************/ + if (npes == 1 && inparts > 1) { + moptions[0] = 0; + nvtxs = vtxdist[1]; + + if (incon == 1) { + METIS_WPartGraphKway(&nvtxs, xadj, adjncy, vwgt, adjwgt, &iwgtflag, &inumflag, + &inparts, itpwgts, moptions, edgecut, part); + } + else { + /* ADD: this is because METIS does not support tpwgts for all constraints */ + mytpwgts = fmalloc(inparts, "mytpwgts"); + for (i=0; i<inparts; i++) + mytpwgts[i] = itpwgts[i*incon]; + + moptions[7] = -1; + METIS_mCPartGraphRecursive2(&nvtxs, &incon, xadj, adjncy, vwgt, adjwgt, &iwgtflag, + &inumflag, &inparts, mytpwgts, moptions, edgecut, part); + + free(mytpwgts); + } + + return; + } + + + if (inumflag == 1) + ChangeNumbering(vtxdist, xadj, adjncy, part, npes, mype, 1); + + /*****************************/ + /* Set up control structures */ + /*****************************/ + if (ioptions[0] == 1) { + dbglvl = ioptions[PMV3_OPTION_DBGLVL]; + seed = ioptions[PMV3_OPTION_SEED]; + } + else { + dbglvl = GLOBAL_DBGLVL; + seed = GLOBAL_SEED; + } + SetUpCtrl(&ctrl, npes, dbglvl, *comm); + ctrl.CoarsenTo = amin(vtxdist[npes]+1, 25*incon*amax(npes, inparts)); + ctrl.seed = (seed == 0) ? mype : seed*mype; + ctrl.sync = GlobalSEMax(&ctrl, seed); + ctrl.partType = STATIC_PARTITION; + ctrl.ps_relation = -1; + ctrl.tpwgts = itpwgts; + scopy(incon, iubvec, ctrl.ubvec); + + uwgtflag = iwgtflag|2; + uvwgt = idxsmalloc(vtxdist[mype+1]-vtxdist[mype], 1, "uvwgt"); + graph = Moc_SetUpGraph(&ctrl, 1, vtxdist, xadj, uvwgt, adjncy, adjwgt, &uwgtflag); + free(graph->nvwgt); graph->nvwgt = NULL; + + PreAllocateMemory(&ctrl, graph, &wspace); + + /*================================================================= + * Compute the initial npes-way partitioning geometric partitioning + =================================================================*/ + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + Coordinate_Partition(&ctrl, graph, *ndims, xyz, 1, &wspace); + + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimingInfo(&ctrl)); + + /*================================================================= + * Move the graph according to the partitioning + =================================================================*/ + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.MoveTmr)); + + free(uvwgt); + graph->vwgt = ((iwgtflag&2) != 0) ? vwgt : idxsmalloc(graph->nvtxs*incon, 1, "vwgt"); + graph->ncon = incon; + j = ctrl.nparts; + ctrl.nparts = ctrl.npes; + mgraph = Moc_MoveGraph(&ctrl, graph, &wspace); + ctrl.nparts = j; + + /**********************************************************/ + /* Do the same functionality as Moc_SetUpGraph for mgraph */ + /**********************************************************/ + /* compute tvwgts */ + for (j=0; j<incon; j++) + ltvwgts[j] = 0; + + for (i=0; i<graph->nvtxs; i++) + for (j=0; j<incon; j++) + ltvwgts[j] += mgraph->vwgt[i*incon+j]; + + for (j=0; j<incon; j++) + ctrl.tvwgts[j] = GlobalSESum(&ctrl, ltvwgts[j]); + + /* check for zero wgt constraints */ + for (i=0; i<incon; i++) { + /* ADD: take care of the case in which tvwgts is zero */ + if (ctrl.tvwgts[i] == 0) { + if (ctrl.mype == 0) printf("ERROR: sum weight for constraint %d is zero\n", i); + MPI_Finalize(); + exit(-1); + } + } + + /* compute nvwgt */ + mgraph->nvwgt = fmalloc(mgraph->nvtxs*incon, "mgraph->nvwgt"); + for (i=0; i<mgraph->nvtxs; i++) + for (j=0; j<incon; j++) + mgraph->nvwgt[i*incon+j] = (float)(mgraph->vwgt[i*incon+j]) / (float)(ctrl.tvwgts[j]); + + + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.MoveTmr)); + + if (ctrl.dbglvl&DBG_INFO) { + cut = 0; + for (i=0; i<graph->nvtxs; i++) + for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++) + if (graph->where[i] != graph->where[graph->adjncy[j]]) + cut += graph->adjwgt[j]; + gcut = GlobalSESum(&ctrl, cut)/2; + maxnvtxs = GlobalSEMax(&ctrl, mgraph->nvtxs); + balance = (float)(maxnvtxs)/((float)(graph->gnvtxs)/(float)(npes)); + rprintf(&ctrl, "XYZ Cut: %6d \tBalance: %6.3f [%d %d %d]\n", + gcut, balance, maxnvtxs, graph->gnvtxs, npes); + + } + + /*================================================================= + * Set up the newly moved graph + =================================================================*/ + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + ctrl.nparts = inparts; + FreeWSpace(&wspace); + PreAllocateMemory(&ctrl, mgraph, &wspace); + + /*======================================================= + * Now compute the partition of the moved graph + =======================================================*/ + if (vtxdist[npes] < SMALLGRAPH || vtxdist[npes] < npes*20 || GlobalSESum(&ctrl, mgraph->nedges) == 0) { + IFSET(ctrl.dbglvl, DBG_INFO, rprintf(&ctrl, "Partitioning a graph of size %d serially\n", vtxdist[npes])); + PartitionSmallGraph(&ctrl, mgraph, &wspace); + } + else { + Moc_Global_Partition(&ctrl, mgraph, &wspace); + } + ParallelReMapGraph(&ctrl, mgraph, &wspace); + + /* Invert the ordering back to the original graph */ + ctrl.nparts = npes; + ProjectInfoBack(&ctrl, graph, part, mgraph->where, &wspace); + + *edgecut = mgraph->mincut; + + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + + /*******************/ + /* Print out stats */ + /*******************/ + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimingInfo(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + + if (ctrl.dbglvl&DBG_INFO) { + rprintf(&ctrl, "Final %d-way CUT: %6d \tBalance: ", inparts, mgraph->mincut); + avg = 0.0; + for (h=0; h<incon; h++) { + maximb = 0.0; + for (i=0; i<inparts; i++) + maximb = amax(maximb, mgraph->gnpwgts[i*incon+h]/itpwgts[i*incon+h]); + avg += maximb; + rprintf(&ctrl, "%.3f ", maximb); + } + rprintf(&ctrl, " avg: %.3f\n", avg/(float)incon); + } + + GKfree((void **)&itpwgts, LTERM); + FreeGraph(mgraph); + FreeInitialGraphAndRemap(graph, iwgtflag); + FreeWSpace(&wspace); + FreeCtrl(&ctrl); + + if (inumflag == 1) + ChangeNumbering(vtxdist, xadj, adjncy, part, npes, mype, 0); + +} + + + +/*********************************************************************************** +* This function is the entry point of the parallel ordering algorithm. +* This function assumes that the graph is already nice partitioned among the +* processors and then proceeds to perform recursive bisection. +************************************************************************************/ +void ParMETIS_V3_PartGeom(idxtype *vtxdist, int *ndims, float *xyz, idxtype *part, MPI_Comm *comm) +{ + int i, npes, mype, nvtxs, firstvtx, dbglvl; + idxtype *xadj, *adjncy; + CtrlType ctrl; + WorkSpaceType wspace; + GraphType *graph; + int zeroflg = 0; + + MPI_Comm_size(*comm, &npes); + MPI_Comm_rank(*comm, &mype); + + if (npes == 1) { + idxset(vtxdist[mype+1]-vtxdist[mype], 0, part); + return; + } + + /* Setup a fake graph to allow the rest of the code to work unchanged */ + dbglvl = 0; + + nvtxs = vtxdist[mype+1]-vtxdist[mype]; + firstvtx = vtxdist[mype]; + xadj = idxmalloc(nvtxs+1, "ParMETIS_PartGeom: xadj"); + adjncy = idxmalloc(nvtxs, "ParMETIS_PartGeom: adjncy"); + for (i=0; i<nvtxs; i++) { + xadj[i] = i; + adjncy[i] = firstvtx + (i+1)%nvtxs; + } + xadj[nvtxs] = nvtxs; + + /* Proceed with the rest of the code */ + SetUpCtrl(&ctrl, npes, dbglvl, *comm); + ctrl.seed = mype; + ctrl.CoarsenTo = amin(vtxdist[npes]+1, 25*npes); + + graph = Moc_SetUpGraph(&ctrl, 1, vtxdist, xadj, NULL, adjncy, NULL, &zeroflg); + + PreAllocateMemory(&ctrl, graph, &wspace); + + /*======================================================= + * Compute the initial geometric partitioning + =======================================================*/ + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + Coordinate_Partition(&ctrl, graph, *ndims, xyz, 0, &wspace); + + idxcopy(graph->nvtxs, graph->where, part); + + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimingInfo(&ctrl)); + + FreeInitialGraphAndRemap(graph, 0); + FreeWSpace(&wspace); + FreeCtrl(&ctrl); + + GKfree((void **)&xadj, (void **)&adjncy, LTERM); +} + + + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/grsetup.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/grsetup.c new file mode 100644 index 0000000..7f10a8f --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/grsetup.c @@ -0,0 +1,274 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mgrsetup.c + * + * This file contain various graph setting up routines + * + * Started 10/19/96 + * George + * + * $Id: grsetup.c,v 1.7 2003/07/23 00:54:55 karypis Exp $ + * + */ + +#include <parmetislib.h> + + + +/************************************************************************* +* This function setsup the CtrlType structure +**************************************************************************/ +GraphType *Moc_SetUpGraph(CtrlType *ctrl, int ncon, idxtype *vtxdist, idxtype *xadj, + idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, int *wgtflag) +{ + int i, j; + GraphType *graph; + int ltvwgts[MAXNCON]; + + graph = CreateGraph(); + graph->level = 0; + graph->gnvtxs = vtxdist[ctrl->npes]; + graph->nvtxs = vtxdist[ctrl->mype+1]-vtxdist[ctrl->mype]; + graph->ncon = ncon; + graph->nedges = xadj[graph->nvtxs]; + graph->xadj = xadj; + graph->vwgt = vwgt; + graph->adjncy = adjncy; + graph->adjwgt = adjwgt; + graph->vtxdist = vtxdist; + + + if (((*wgtflag)&2) == 0) + graph->vwgt = idxsmalloc(graph->nvtxs*ncon, 1, "Par_KMetis: vwgt"); + + if (((*wgtflag)&1) == 0) + graph->adjwgt = idxsmalloc(graph->nedges, 1, "Par_KMetis: adjwgt"); + + /* compute tvwgts */ + for (j=0; j<ncon; j++) + ltvwgts[j] = 0; + + for (i=0; i<graph->nvtxs; i++) + for (j=0; j<ncon; j++) + ltvwgts[j] += graph->vwgt[i*ncon+j]; + + for (j=0; j<ncon; j++) + ctrl->tvwgts[j] = GlobalSESum(ctrl, ltvwgts[j]); + + /* check for zero wgt constraints */ + for (i=0; i<ncon; i++) { + /* ADD: take care of the case in which tvwgts is zero */ + if (ctrl->tvwgts[i] == 0) { + rprintf(ctrl, "ERROR: sum weight for constraint %d is zero\n", i); + MPI_Finalize(); + exit(-1); + } + } + + /* compute nvwgts */ + graph->nvwgt = fmalloc(graph->nvtxs*ncon, "graph->nvwgt"); + for (i=0; i<graph->nvtxs; i++) { + for (j=0; j<ncon; j++) + graph->nvwgt[i*ncon+j] = (float)(graph->vwgt[i*ncon+j]) / (float)(ctrl->tvwgts[j]); + } + + srand(ctrl->seed); + + return graph; +} + + +/************************************************************************* +* This function setsup the CtrlType structure +**************************************************************************/ +void SetUpCtrl(CtrlType *ctrl, int nparts, int dbglvl, MPI_Comm comm) +{ + + MPI_Comm_dup(comm, &(ctrl->gcomm)); + MPI_Comm_rank(ctrl->gcomm, &ctrl->mype); + MPI_Comm_size(ctrl->gcomm, &ctrl->npes); + + ctrl->dbglvl = dbglvl; + ctrl->nparts = nparts; /* Set the # of partitions is de-coupled from the # of domains */ + ctrl->comm = ctrl->gcomm; + ctrl->xyztype = XYZ_SPFILL; + + srand(ctrl->mype); +} + + +/************************************************************************* +* This function changes the numbering from 1 to 0 or 0 to 1 +**************************************************************************/ +void ChangeNumbering(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *part, int npes, int mype, int from) +{ + int i, nvtxs, nedges; + + if (from == 1) { /* Change it from 1 to 0 */ + for (i=0; i<npes+1; i++) + vtxdist[i]--; + + nvtxs = vtxdist[mype+1]-vtxdist[mype]; + for (i=0; i<nvtxs+1; i++) + xadj[i]--; + + nedges = xadj[nvtxs]; + for (i=0; i<nedges; i++) + adjncy[i]--; + } + else { /* Change it from 0 to 1 */ + nvtxs = vtxdist[mype+1]-vtxdist[mype]; + nedges = xadj[nvtxs]; + + for (i=0; i<npes+1; i++) + vtxdist[i]++; + + for (i=0; i<nvtxs+1; i++) + xadj[i]++; + + for (i=0; i<nedges; i++) + adjncy[i]++; + + for (i=0; i<nvtxs; i++) + part[i]++; + + } +} + + +/************************************************************************* +* This function changes the numbering from 1 to 0 or 0 to 1 +**************************************************************************/ +void ChangeNumberingMesh(idxtype *elmdist, idxtype *elements, idxtype *xadj, + idxtype *adjncy, idxtype *part, int npes, int mype, + int elmntlen, int from) +{ + int i, nelms, nedges; + + if (from == 1) { /* Change it from 1 to 0 */ + for (i=0; i<npes+1; i++) + elmdist[i]--; + + for (i=0; i<elmntlen; i++) + elements[i]--; + } + else { /* Change it from 0 to 1 */ + nelms = elmdist[mype+1]-elmdist[mype]; + nedges = xadj[nelms]; + + for (i=0; i<npes+1; i++) + elmdist[i]++; + + for (i=0; i<elmntlen; i++) + elements[i]++; + + for (i=0; i<nelms+1; i++) + xadj[i]++; + + for (i=0; i<nedges; i++) + adjncy[i]++; + + if (part != NULL) + for (i=0; i<nelms; i++) + part[i]++; + } +} + + +/************************************************************************* +* This function changes the numbering from 1 to 0 or 0 to 1 +**************************************************************************/ +void ChangeNumberingMesh2(idxtype *elmdist, idxtype *eptr, idxtype *eind, + idxtype *xadj, idxtype *adjncy, idxtype *part, + int npes, int mype, int from) +{ + int i, nelms; + + nelms = elmdist[mype+1]-elmdist[mype]; + + if (from == 1) { /* Change it from 1 to 0 */ + for (i=0; i<npes+1; i++) + elmdist[i]--; + + for (i=0; i<nelms+1; i++) + eptr[i]--; + + for (i=0; i<eptr[nelms]; i++) + eind[i]--; + } + else { /* Change it from 0 to 1 */ + for (i=0; i<npes+1; i++) + elmdist[i]++; + + for (i=0; i<nelms+1; i++) + eptr[i]++; + + for (i=0; i<eptr[nelms]; i++) + eind[i]++; + + for (i=0; i<nelms+1; i++) + xadj[i]++; + + for (i=0; i<xadj[nelms]; i++) + adjncy[i]++; + + if (part != NULL) + for (i=0; i<nelms; i++) + part[i]++; + } +} + + + + +/************************************************************************* +* This function randomly permutes the locally stored adjacency lists +**************************************************************************/ +void GraphRandomPermute(GraphType *graph) +{ + int i, j, k, tmp; + + for (i=0; i<graph->nvtxs; i++) { + for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++) { + k = graph->xadj[i] + RandomInRange(graph->xadj[i+1]-graph->xadj[i]); + SWAP(graph->adjncy[j], graph->adjncy[k], tmp); + SWAP(graph->adjwgt[j], graph->adjwgt[k], tmp); + } + } +} + + +/************************************************************************* +* This function computes movement statistics for adaptive refinement +* schemes +**************************************************************************/ +void ComputeMoveStatistics(CtrlType *ctrl, GraphType *graph, int *nmoved, int *maxin, int *maxout) +{ + int i, j, nvtxs; + idxtype *vwgt, *where; + idxtype *lpvtxs, *gpvtxs; + + nvtxs = graph->nvtxs; + vwgt = graph->vwgt; + where = graph->where; + + lpvtxs = idxsmalloc(ctrl->nparts, 0, "ComputeMoveStatistics: lpvtxs"); + gpvtxs = idxsmalloc(ctrl->nparts, 0, "ComputeMoveStatistics: gpvtxs"); + + for (j=i=0; i<nvtxs; i++) { + lpvtxs[where[i]]++; + if (where[i] != ctrl->mype) + j++; + } + + /* PrintVector(ctrl, ctrl->npes, 0, lpvtxs, "Lpvtxs: "); */ + + MPI_Allreduce((void *)lpvtxs, (void *)gpvtxs, ctrl->nparts, IDX_DATATYPE, MPI_SUM, ctrl->comm); + + *nmoved = GlobalSESum(ctrl, j); + *maxout = GlobalSEMax(ctrl, j); + *maxin = GlobalSEMax(ctrl, gpvtxs[ctrl->mype]-(nvtxs-j)); + + GKfree((void **)&lpvtxs, (void **)&gpvtxs, LTERM); +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/iidxsort.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/iidxsort.c new file mode 100644 index 0000000..869748c --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/iidxsort.c @@ -0,0 +1,152 @@ +#include <parmetislib.h> + + +/* Byte-wise swap two items of size SIZE. */ +#define QSSWAP(a, b, stmp) do { stmp = (a); (a) = (b); (b) = stmp; } while (0) + +/* Discontinue quicksort algorithm when partition gets below this size. + This particular magic number was chosen to work best on a Sun 4/260. */ +#define MAX_THRESH 20 + +/* Stack node declarations used to store unfulfilled partition obligations. */ +typedef struct { + idxtype *lo; + idxtype *hi; +} stack_node; + + +/* The next 4 #defines implement a very fast in-line stack abstraction. */ +#define STACK_SIZE (8 * sizeof(unsigned long int)) +#define PUSH(low, high) ((void) ((top->lo = (low)), (top->hi = (high)), ++top)) +#define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi))) +#define STACK_NOT_EMPTY (stack < top) + + +void iidxsort(int total_elems, idxtype *pbase) +{ + idxtype pivot, stmp; + + if (total_elems == 0) + /* Avoid lossage with unsigned arithmetic below. */ + return; + + if (total_elems > MAX_THRESH) { + idxtype *lo = pbase; + idxtype *hi = &lo[total_elems - 1]; + stack_node stack[STACK_SIZE]; /* Largest size needed for 32-bit int!!! */ + stack_node *top = stack + 1; + + while (STACK_NOT_EMPTY) { + idxtype *left_ptr; + idxtype *right_ptr; + idxtype *mid = lo + ((hi - lo) >> 1); + + + if (*mid < *lo) + QSSWAP(*mid, *lo, stmp); + if (*hi < *mid) + QSSWAP(*mid, *hi, stmp); + else + goto jump_over; + if (*mid < *lo) + QSSWAP(*mid, *lo, stmp); + +jump_over:; + pivot = *mid; + left_ptr = lo + 1; + right_ptr = hi - 1; + + /* Here's the famous ``collapse the walls'' section of quicksort. + Gotta like those tight inner loops! They are the main reason + that this algorithm runs much faster than others. */ + do { + while (*left_ptr < pivot) + left_ptr++; + + while (pivot < *right_ptr) + right_ptr--; + + if (left_ptr < right_ptr) { + QSSWAP (*left_ptr, *right_ptr, stmp); + left_ptr++; + right_ptr--; + } + else if (left_ptr == right_ptr) { + left_ptr++; + right_ptr--; + break; + } + } while (left_ptr <= right_ptr); + + /* Set up pointers for next iteration. First determine whether + left and right partitions are below the threshold size. If so, + ignore one or both. Otherwise, push the larger partition's + bounds on the stack and continue sorting the smaller one. */ + + if ((size_t) (right_ptr - lo) <= MAX_THRESH) { + if ((size_t) (hi - left_ptr) <= MAX_THRESH) + /* Ignore both small partitions. */ + POP (lo, hi); + else + /* Ignore small left partition. */ + lo = left_ptr; + } + else if ((size_t) (hi - left_ptr) <= MAX_THRESH) + /* Ignore small right partition. */ + hi = right_ptr; + else if ((right_ptr - lo) > (hi - left_ptr)) { + /* Push larger left partition indices. */ + PUSH (lo, right_ptr); + lo = left_ptr; + } + else { + /* Push larger right partition indices. */ + PUSH (left_ptr, hi); + hi = right_ptr; + } + } + } + + /* Once the BASE_PTR array is partially sorted by quicksort the rest + is completely sorted using insertion sort, since this is efficient + for partitions below MAX_THRESH size. BASE_PTR points to the beginning + of the array to sort, and END_PTR points at the very last element in + the array (*not* one beyond it!). */ + + { + idxtype *end_ptr = &pbase[total_elems - 1]; + idxtype *tmp_ptr = pbase; + idxtype *thresh = (end_ptr < pbase + MAX_THRESH ? end_ptr : pbase + MAX_THRESH); + register idxtype *run_ptr; + + /* Find smallest element in first threshold and place it at the + array's beginning. This is the smallest array element, + and the operation speeds up insertion sort's inner loop. */ + + + for (run_ptr = tmp_ptr + 1; run_ptr <= thresh; run_ptr++) + if (*run_ptr < *tmp_ptr) + tmp_ptr = run_ptr; + + if (tmp_ptr != pbase) + QSSWAP(*tmp_ptr, *pbase, stmp); + + /* Insertion sort, running from left-hand-side up to right-hand-side. */ + run_ptr = pbase + 1; + while (++run_ptr <= end_ptr) { + tmp_ptr = run_ptr - 1; + while (*run_ptr < *tmp_ptr) + tmp_ptr--; + + tmp_ptr++; + if (tmp_ptr != run_ptr) { + idxtype elmnt = *run_ptr; + idxtype *mptr; + + for (mptr=run_ptr; mptr>tmp_ptr; mptr--) + *mptr = *(mptr-1); + *mptr = elmnt; + } + } + } +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/iintsort.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/iintsort.c new file mode 100644 index 0000000..fb0e840 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/iintsort.c @@ -0,0 +1,157 @@ +#include <parmetislib.h> + + +/* Byte-wise swap two items of size SIZE. */ +#define QSSWAP(a, b, stmp) do { stmp = (a); (a) = (b); (b) = stmp; } while (0) + +/* Discontinue quicksort algorithm when partition gets below this size. + This particular magic number was chosen to work best on a Sun 4/260. */ +#define MAX_THRESH 20 + +/* Stack node declarations used to store unfulfilled partition obligations. */ +typedef struct { + int *lo; + int *hi; +} stack_node; + + +/* The next 4 #defines implement a very fast in-line stack abstraction. */ +#define STACK_SIZE (8 * sizeof(unsigned long int)) +#define PUSH(low, high) ((void) ((top->lo = (low)), (top->hi = (high)), ++top)) +#define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi))) +#define STACK_NOT_EMPTY (stack < top) + + +void iintsort(int total_elems, int *pbase) +{ + int pivot, stmp; + + if (total_elems == 0) + /* Avoid lossage with unsigned arithmetic below. */ + return; + + if (total_elems > MAX_THRESH) { + int *lo = pbase; + int *hi = &lo[total_elems - 1]; + stack_node stack[STACK_SIZE]; /* Largest size needed for 32-bit int!!! */ + stack_node *top = stack + 1; + + while (STACK_NOT_EMPTY) { + int *left_ptr; + int *right_ptr; + + /* Select median value from among LO, MID, and HI. Rearrange + LO and HI so the three values are sorted. This lowers the + probability of picking a pathological pivot value and + skips a comparison for both the LEFT_PTR and RIGHT_PTR. */ + + int *mid = lo + ((hi - lo) >> 1); + + if (*mid < *lo) + QSSWAP(*mid, *lo, stmp); + if (*hi < *mid) + QSSWAP(*mid, *hi, stmp); + else + goto jump_over; + if (*mid < *lo) + QSSWAP(*mid, *lo, stmp); + +jump_over:; + pivot = *mid; + left_ptr = lo + 1; + right_ptr = hi - 1; + + /* Here's the famous ``collapse the walls'' section of quicksort. + Gotta like those tight inner loops! They are the main reason + that this algorithm runs much faster than others. */ + do { + while (*left_ptr < pivot) + left_ptr++; + + while (pivot < *right_ptr) + right_ptr--; + + if (left_ptr < right_ptr) { + QSSWAP (*left_ptr, *right_ptr, stmp); + left_ptr++; + right_ptr--; + } + else if (left_ptr == right_ptr) { + left_ptr++; + right_ptr--; + break; + } + } while (left_ptr <= right_ptr); + + /* Set up pointers for next iteration. First determine whether + left and right partitions are below the threshold size. If so, + ignore one or both. Otherwise, push the larger partition's + bounds on the stack and continue sorting the smaller one. */ + + if ((size_t) (right_ptr - lo) <= MAX_THRESH) { + if ((size_t) (hi - left_ptr) <= MAX_THRESH) + /* Ignore both small partitions. */ + POP (lo, hi); + else + /* Ignore small left partition. */ + lo = left_ptr; + } + else if ((size_t) (hi - left_ptr) <= MAX_THRESH) + /* Ignore small right partition. */ + hi = right_ptr; + else if ((right_ptr - lo) > (hi - left_ptr)) { + /* Push larger left partition indices. */ + PUSH (lo, right_ptr); + lo = left_ptr; + } + else { + /* Push larger right partition indices. */ + PUSH (left_ptr, hi); + hi = right_ptr; + } + } + } + + /* Once the BASE_PTR array is partially sorted by quicksort the rest + is completely sorted using insertion sort, since this is efficient + for partitions below MAX_THRESH size. BASE_PTR points to the beginning + of the array to sort, and END_PTR points at the very last element in + the array (*not* one beyond it!). */ + + { + int *end_ptr = &pbase[total_elems - 1]; + int *tmp_ptr = pbase; + int *thresh = (end_ptr < pbase + MAX_THRESH ? end_ptr : pbase + MAX_THRESH); + register int *run_ptr; + + /* Find smallest element in first threshold and place it at the + array's beginning. This is the smallest array element, + and the operation speeds up insertion sort's inner loop. */ + + + for (run_ptr = tmp_ptr + 1; run_ptr <= thresh; run_ptr++) + if (*run_ptr < *tmp_ptr) + tmp_ptr = run_ptr; + + if (tmp_ptr != pbase) + QSSWAP(*tmp_ptr, *pbase, stmp); + + /* Insertion sort, running from left-hand-side up to right-hand-side. */ + run_ptr = pbase + 1; + while (++run_ptr <= end_ptr) { + tmp_ptr = run_ptr - 1; + while (*run_ptr < *tmp_ptr) + tmp_ptr--; + + tmp_ptr++; + if (tmp_ptr != run_ptr) { + int elmnt = *run_ptr; + int *mptr; + + for (mptr=run_ptr; mptr>tmp_ptr; mptr--) + *mptr = *(mptr-1); + *mptr = elmnt; + } + } + } +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/ikeysort.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/ikeysort.c new file mode 100644 index 0000000..14b4241 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/ikeysort.c @@ -0,0 +1,151 @@ +#include <parmetislib.h> + + +/* Byte-wise swap two items of size SIZE. */ +#define QSSWAP(a, b, stmp) do { stmp = (a); (a) = (b); (b) = stmp; } while (0) + +/* Discontinue quicksort algorithm when partition gets below this size. + This particular magic number was chosen to work best on a Sun 4/260. */ +#define MAX_THRESH 20 + +/* Stack node declarations used to store unfulfilled partition obligations. */ +typedef struct { + KeyValueType *lo; + KeyValueType *hi; +} stack_node; + + +/* The next 4 #defines implement a very fast in-line stack abstraction. */ +#define STACK_SIZE (8 * sizeof(unsigned long int)) +#define PUSH(low, high) ((void) ((top->lo = (low)), (top->hi = (high)), ++top)) +#define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi))) +#define STACK_NOT_EMPTY (stack < top) + + +void ikeysort(int total_elems, KeyValueType *pbase) +{ + KeyValueType pivot, stmp; + + if (total_elems == 0) + /* Avoid lossage with unsigned arithmetic below. */ + return; + + if (total_elems > MAX_THRESH) { + KeyValueType *lo = pbase; + KeyValueType *hi = &lo[total_elems - 1]; + stack_node stack[STACK_SIZE]; /* Largest size needed for 32-bit int!!! */ + stack_node *top = stack + 1; + + while (STACK_NOT_EMPTY) { + KeyValueType *left_ptr; + KeyValueType *right_ptr; + KeyValueType *mid = lo + ((hi - lo) >> 1); + + if (mid->key < lo->key) + QSSWAP(*mid, *lo, stmp); + if (hi->key < mid->key) + QSSWAP(*mid, *hi, stmp); + else + goto jump_over; + if (mid->key < lo->key) + QSSWAP(*mid, *lo, stmp); + +jump_over:; + pivot = *mid; + left_ptr = lo + 1; + right_ptr = hi - 1; + + /* Here's the famous ``collapse the walls'' section of quicksort. + Gotta like those tight inner loops! They are the main reason + that this algorithm runs much faster than others. */ + do { + while (left_ptr->key < pivot.key) + left_ptr++; + + while (pivot.key < right_ptr->key) + right_ptr--; + + if (left_ptr < right_ptr) { + QSSWAP (*left_ptr, *right_ptr, stmp); + left_ptr++; + right_ptr--; + } + else if (left_ptr == right_ptr) { + left_ptr++; + right_ptr--; + break; + } + } while (left_ptr <= right_ptr); + + /* Set up pointers for next iteration. First determine whether + left and right partitions are below the threshold size. If so, + ignore one or both. Otherwise, push the larger partition's + bounds on the stack and continue sorting the smaller one. */ + + if ((size_t) (right_ptr - lo) <= MAX_THRESH) { + if ((size_t) (hi - left_ptr) <= MAX_THRESH) + /* Ignore both small partitions. */ + POP (lo, hi); + else + /* Ignore small left partition. */ + lo = left_ptr; + } + else if ((size_t) (hi - left_ptr) <= MAX_THRESH) + /* Ignore small right partition. */ + hi = right_ptr; + else if ((right_ptr - lo) > (hi - left_ptr)) { + /* Push larger left partition indices. */ + PUSH (lo, right_ptr); + lo = left_ptr; + } + else { + /* Push larger right partition indices. */ + PUSH (left_ptr, hi); + hi = right_ptr; + } + } + } + + /* Once the BASE_PTR array is partially sorted by quicksort the rest + is completely sorted using insertion sort, since this is efficient + for partitions below MAX_THRESH size. BASE_PTR points to the beginning + of the array to sort, and END_PTR points at the very last element in + the array (*not* one beyond it!). */ + + { + KeyValueType *end_ptr = &pbase[total_elems - 1]; + KeyValueType *tmp_ptr = pbase; + KeyValueType *thresh = (end_ptr < pbase + MAX_THRESH ? end_ptr : pbase + MAX_THRESH); + register KeyValueType *run_ptr; + + /* Find smallest element in first threshold and place it at the + array's beginning. This is the smallest array element, + and the operation speeds up insertion sort's inner loop. */ + + for (run_ptr = tmp_ptr + 1; run_ptr <= thresh; run_ptr++) + if (run_ptr->key < tmp_ptr->key) + tmp_ptr = run_ptr; + + if (tmp_ptr != pbase) + QSSWAP(*tmp_ptr, *pbase, stmp); + + /* Insertion sort, running from left-hand-side up to right-hand-side. */ + run_ptr = pbase + 1; + while (++run_ptr <= end_ptr) { + tmp_ptr = run_ptr - 1; + while (run_ptr->key < tmp_ptr->key) + tmp_ptr--; + + tmp_ptr++; + if (tmp_ptr != run_ptr) { + KeyValueType elmnt = *run_ptr; + KeyValueType *mptr; + + for (mptr=run_ptr; mptr>tmp_ptr; mptr--) + *mptr = *(mptr-1); + *mptr = elmnt; + } + } + } +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/ikeyvalsort.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/ikeyvalsort.c new file mode 100644 index 0000000..59dce52 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/ikeyvalsort.c @@ -0,0 +1,151 @@ +#include <parmetislib.h> + + +/* Byte-wise swap two items of size SIZE. */ +#define QSSWAP(a, b, stmp) do { stmp = (a); (a) = (b); (b) = stmp; } while (0) + +/* Discontinue quicksort algorithm when partition gets below this size. + This particular magic number was chosen to work best on a Sun 4/260. */ +#define MAX_THRESH 20 + +/* Stack node declarations used to store unfulfilled partition obligations. */ +typedef struct { + KeyValueType *lo; + KeyValueType *hi; +} stack_node; + + +/* The next 4 #defines implement a very fast in-line stack abstraction. */ +#define STACK_SIZE (8 * sizeof(unsigned long int)) +#define PUSH(low, high) ((void) ((top->lo = (low)), (top->hi = (high)), ++top)) +#define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi))) +#define STACK_NOT_EMPTY (stack < top) + + +void ikeyvalsort(int total_elems, KeyValueType *pbase) +{ + KeyValueType pivot, stmp; + + if (total_elems == 0) + /* Avoid lossage with unsigned arithmetic below. */ + return; + + if (total_elems > MAX_THRESH) { + KeyValueType *lo = pbase; + KeyValueType *hi = &lo[total_elems - 1]; + stack_node stack[STACK_SIZE]; /* Largest size needed for 32-bit int!!! */ + stack_node *top = stack + 1; + + while (STACK_NOT_EMPTY) { + KeyValueType *left_ptr; + KeyValueType *right_ptr; + KeyValueType *mid = lo + ((hi - lo) >> 1); + + if (mid->key < lo->key || (mid->key == lo->key && mid->val < lo->val)) + QSSWAP(*mid, *lo, stmp); + if (hi->key < mid->key || (hi->key == mid->key && hi->val < mid->val)) + QSSWAP(*mid, *hi, stmp); + else + goto jump_over; + if (mid->key < lo->key || (mid->key == lo->key && mid->val < lo->val)) + QSSWAP(*mid, *lo, stmp); + +jump_over:; + pivot = *mid; + left_ptr = lo + 1; + right_ptr = hi - 1; + + /* Here's the famous ``collapse the walls'' section of quicksort. + Gotta like those tight inner loops! They are the main reason + that this algorithm runs much faster than others. */ + do { + while (left_ptr->key < pivot.key || (left_ptr->key == pivot.key && left_ptr->val < pivot.val)) + left_ptr++; + + while (pivot.key < right_ptr->key || (pivot.key == right_ptr->key && pivot.val < right_ptr->val)) + right_ptr--; + + if (left_ptr < right_ptr) { + QSSWAP (*left_ptr, *right_ptr, stmp); + left_ptr++; + right_ptr--; + } + else if (left_ptr == right_ptr) { + left_ptr++; + right_ptr--; + break; + } + } while (left_ptr <= right_ptr); + + /* Set up pointers for next iteration. First determine whether + left and right partitions are below the threshold size. If so, + ignore one or both. Otherwise, push the larger partition's + bounds on the stack and continue sorting the smaller one. */ + + if ((size_t) (right_ptr - lo) <= MAX_THRESH) { + if ((size_t) (hi - left_ptr) <= MAX_THRESH) + /* Ignore both small partitions. */ + POP (lo, hi); + else + /* Ignore small left partition. */ + lo = left_ptr; + } + else if ((size_t) (hi - left_ptr) <= MAX_THRESH) + /* Ignore small right partition. */ + hi = right_ptr; + else if ((right_ptr - lo) > (hi - left_ptr)) { + /* Push larger left partition indices. */ + PUSH (lo, right_ptr); + lo = left_ptr; + } + else { + /* Push larger right partition indices. */ + PUSH (left_ptr, hi); + hi = right_ptr; + } + } + } + + /* Once the BASE_PTR array is partially sorted by quicksort the rest + is completely sorted using insertion sort, since this is efficient + for partitions below MAX_THRESH size. BASE_PTR points to the beginning + of the array to sort, and END_PTR points at the very last element in + the array (*not* one beyond it!). */ + + { + KeyValueType *end_ptr = &pbase[total_elems - 1]; + KeyValueType *tmp_ptr = pbase; + KeyValueType *thresh = (end_ptr < pbase + MAX_THRESH ? end_ptr : pbase + MAX_THRESH); + register KeyValueType *run_ptr; + + /* Find smallest element in first threshold and place it at the + array's beginning. This is the smallest array element, + and the operation speeds up insertion sort's inner loop. */ + + for (run_ptr = tmp_ptr + 1; run_ptr <= thresh; run_ptr++) + if (run_ptr->key < tmp_ptr->key || (run_ptr->key == tmp_ptr->key && run_ptr->val < tmp_ptr->val)) + tmp_ptr = run_ptr; + + if (tmp_ptr != pbase) + QSSWAP(*tmp_ptr, *pbase, stmp); + + /* Insertion sort, running from left-hand-side up to right-hand-side. */ + run_ptr = pbase + 1; + while (++run_ptr <= end_ptr) { + tmp_ptr = run_ptr - 1; + while (run_ptr->key < tmp_ptr->key || (run_ptr->key == tmp_ptr->key && run_ptr->val < tmp_ptr->val)) + tmp_ptr--; + + tmp_ptr++; + if (tmp_ptr != run_ptr) { + KeyValueType elmnt = *run_ptr; + KeyValueType *mptr; + + for (mptr=run_ptr; mptr>tmp_ptr; mptr--) + *mptr = *(mptr-1); + *mptr = elmnt; + } + } + } +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/initbalance.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/initbalance.c new file mode 100644 index 0000000..9ec7a31 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/initbalance.c @@ -0,0 +1,498 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * initbalance.c + * + * This file contains code that computes an initial partitioning + * + * Started 3/4/96 + * George + * + * $Id: initbalance.c,v 1.4 2003/07/30 21:18:52 karypis Exp $ + */ + +#include <parmetislib.h> + + +/************************************************************************* +* This function is the entry point of the initial balancing algorithm. +* This algorithm assembles the graph to all the processors and preceeds +* with the balancing step. +**************************************************************************/ +void Balance_Partition(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int i, j, mype, npes, nvtxs, nedges, ncon; + idxtype *vtxdist, *xadj, *adjncy, *adjwgt, *vwgt, *vsize; + idxtype *part, *lwhere, *home; + GraphType *agraph, cgraph; + CtrlType myctrl; + int lnparts, fpart, fpe, lnpes, ngroups, srnpes, srmype; + int twoparts=2, numflag = 0, wgtflag = 3, moptions[10], edgecut, max_cut; + int sr_pe, gd_pe, sr, gd, who_wins, *rcounts, *rdispls; + float my_cut, my_totalv, my_cost = -1.0, my_balance = -1.0, wsum; + float rating, max_rating, your_cost = -1.0, your_balance = -1.0; + float lbvec[MAXNCON], lbsum, min_lbsum, *mytpwgts, mytpwgts2[2], buffer[2]; + MPI_Status status; + MPI_Comm ipcomm, srcomm; + struct { + float cost; + int rank; + } lpecost, gpecost; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->InitPartTmr)); + + vtxdist = graph->vtxdist; + agraph = Moc_AssembleAdaptiveGraph(ctrl, graph, wspace); + nvtxs = cgraph.nvtxs = agraph->nvtxs; + nedges = cgraph.nedges = agraph->nedges; + ncon = cgraph.ncon = agraph->ncon; + + xadj = cgraph.xadj = idxmalloc(nvtxs*(5+ncon)+1+nedges*2, "U_IP: xadj"); + vwgt = cgraph.vwgt = xadj + nvtxs+1; + vsize = cgraph.vsize = xadj + nvtxs*(1+ncon)+1; + cgraph.where = agraph->where = part = xadj + nvtxs*(2+ncon)+1; + lwhere = xadj + nvtxs*(3+ncon)+1; + home = xadj + nvtxs*(4+ncon)+1; + adjncy = cgraph.adjncy = xadj + nvtxs*(5+ncon)+1; + adjwgt = cgraph.adjwgt = xadj + nvtxs*(5+ncon)+1 + nedges; + + /* ADD: this assumes that tpwgts for all constraints is the same */ + /* ADD: this is necessary because serial metis does not support the general case */ + mytpwgts = fsmalloc(ctrl->nparts, 0.0, "mytpwgts"); + for (i=0; i<ctrl->nparts; i++) + for (j=0; j<ncon; j++) + mytpwgts[i] += ctrl->tpwgts[i*ncon+j]; + for (i=0; i<ctrl->nparts; i++) + mytpwgts[i] /= (float)ncon; + + idxcopy(nvtxs+1, agraph->xadj, xadj); + idxcopy(nvtxs*ncon, agraph->vwgt, vwgt); + idxcopy(nvtxs, agraph->vsize, vsize); + idxcopy(nedges, agraph->adjncy, adjncy); + idxcopy(nedges, agraph->adjwgt, adjwgt); + + /****************************************/ + /****************************************/ + if (ctrl->ps_relation == DISCOUPLED) { + rcounts = imalloc(ctrl->npes, "rcounts"); + rdispls = imalloc(ctrl->npes+1, "rdispls"); + + for (i=0; i<ctrl->npes; i++) { + rdispls[i] = rcounts[i] = vtxdist[i+1]-vtxdist[i]; + } + MAKECSR(i, ctrl->npes, rdispls); + + MPI_Allgatherv((void *)graph->home, graph->nvtxs, IDX_DATATYPE, + (void *)part, rcounts, rdispls, IDX_DATATYPE, ctrl->comm); + + for (i=0; i<agraph->nvtxs; i++) + home[i] = part[i]; + + GKfree((void **)&rcounts, (void **)&rdispls, LTERM); + } + else { + for (i=0; i<ctrl->npes; i++) + for (j=vtxdist[i]; j<vtxdist[i+1]; j++) + part[j] = home[j] = i; + } + + /* Ensure that the initial partitioning is legal */ + for (i=0; i<agraph->nvtxs; i++) { + if (part[i] >= ctrl->nparts) + part[i] = home[i] = part[i] % ctrl->nparts; + if (part[i] < 0) + part[i] = home[i] = (-1*part[i]) % ctrl->nparts; + } + /****************************************/ + /****************************************/ + + IFSET(ctrl->dbglvl, DBG_REFINEINFO, Moc_ComputeSerialBalance(ctrl, agraph, agraph->where, lbvec)); + IFSET(ctrl->dbglvl, DBG_REFINEINFO, rprintf(ctrl, "input cut: %d, balance: ", ComputeSerialEdgeCut(agraph))); + for (i=0; i<agraph->ncon; i++) + IFSET(ctrl->dbglvl, DBG_REFINEINFO, rprintf(ctrl, "%.3f ", lbvec[i])); + IFSET(ctrl->dbglvl, DBG_REFINEINFO, rprintf(ctrl, "\n")); + + /****************************************/ + /* Split the processors into two groups */ + /****************************************/ + sr = (ctrl->mype % 2 == 0) ? 1 : 0; + gd = (ctrl->mype % 2 == 1) ? 1 : 0; + + if (graph->ncon > MAX_NCON_FOR_DIFFUSION || ctrl->npes == 1) { + sr = 1; + gd = 0; + } + + sr_pe = 0; + gd_pe = 1; + + MPI_Comm_split(ctrl->gcomm, sr, 0, &ipcomm); + MPI_Comm_rank(ipcomm, &mype); + MPI_Comm_size(ipcomm, &npes); + + myctrl.dbglvl = 0; + myctrl.mype = mype; + myctrl.npes = npes; + myctrl.comm = ipcomm; + myctrl.sync = ctrl->sync; + myctrl.seed = ctrl->seed; + myctrl.nparts = ctrl->nparts; + myctrl.ipc_factor = ctrl->ipc_factor; + myctrl.redist_factor = ctrl->redist_base; + myctrl.partType = ADAPTIVE_PARTITION; + myctrl.ps_relation = DISCOUPLED; + myctrl.tpwgts = ctrl->tpwgts; + icopy(ncon, ctrl->tvwgts, myctrl.tvwgts); + icopy(ncon, ctrl->ubvec, myctrl.ubvec); + + if (sr == 1) { + /*******************************************/ + /* Half of the processors do scratch-remap */ + /*******************************************/ + ngroups = amax(amin(RIP_SPLIT_FACTOR, npes), 1); + MPI_Comm_split(ipcomm, mype % ngroups, 0, &srcomm); + MPI_Comm_rank(srcomm, &srmype); + MPI_Comm_size(srcomm, &srnpes); + + moptions[0] = 0; + moptions[7] = ctrl->sync + (mype % ngroups) + 1; + + idxset(nvtxs, 0, lwhere); + lnparts = ctrl->nparts; + fpart = fpe = 0; + lnpes = srnpes; + while (lnpes > 1 && lnparts > 1) { + ASSERT(ctrl, agraph->nvtxs > 1); + /* Determine the weights of the partitions */ + mytpwgts2[0] = ssum(lnparts/2, mytpwgts+fpart); + mytpwgts2[1] = 1.0-mytpwgts2[0]; + + + if (agraph->ncon == 1) { + METIS_WPartGraphKway2(&agraph->nvtxs, agraph->xadj, agraph->adjncy, agraph->vwgt, + agraph->adjwgt, &wgtflag, &numflag, &twoparts, mytpwgts2, moptions, &edgecut, + part); + } + else { + METIS_mCPartGraphRecursive2(&agraph->nvtxs, &ncon, agraph->xadj, agraph->adjncy, + agraph->vwgt, agraph->adjwgt, &wgtflag, &numflag, &twoparts, mytpwgts2, + moptions, &edgecut, part); + } + + wsum = ssum(lnparts/2, mytpwgts+fpart); + sscale(lnparts/2, 1.0/wsum, mytpwgts+fpart); + sscale(lnparts-lnparts/2, 1.0/(1.0-wsum), mytpwgts+fpart+lnparts/2); + + /* I'm picking the left branch */ + if (srmype < fpe+lnpes/2) { + Moc_KeepPart(agraph, wspace, part, 0); + lnpes = lnpes/2; + lnparts = lnparts/2; + } + else { + Moc_KeepPart(agraph, wspace, part, 1); + fpart = fpart + lnparts/2; + fpe = fpe + lnpes/2; + lnpes = lnpes - lnpes/2; + lnparts = lnparts - lnparts/2; + } + } + + /* In case srnpes is greater than or equal to nparts */ + if (lnparts == 1) { + /* Only the first process will assign labels (for the reduction to work) */ + if (srmype == fpe) { + for (i=0; i<agraph->nvtxs; i++) + lwhere[agraph->label[i]] = fpart; + } + } + /* In case srnpes is smaller than nparts */ + else { + if (ncon == 1) + METIS_WPartGraphKway2(&agraph->nvtxs, agraph->xadj, agraph->adjncy, agraph->vwgt, + agraph->adjwgt, &wgtflag, &numflag, &lnparts, mytpwgts+fpart, moptions, + &edgecut, part); + else + METIS_mCPartGraphRecursive2(&agraph->nvtxs, &ncon, agraph->xadj, agraph->adjncy, + agraph->vwgt, agraph->adjwgt, &wgtflag, &numflag, &lnparts, mytpwgts+fpart, + moptions, &edgecut, part); + + for (i=0; i<agraph->nvtxs; i++) + lwhere[agraph->label[i]] = fpart + part[i]; + } + + MPI_Allreduce((void *)lwhere, (void *)part, nvtxs, IDX_DATATYPE, MPI_SUM, srcomm); + + edgecut = ComputeSerialEdgeCut(&cgraph); + Moc_ComputeSerialBalance(ctrl, &cgraph, part, lbvec); + lbsum = ssum(ncon, lbvec); + MPI_Allreduce((void *)&edgecut, (void *)&max_cut, 1, MPI_INT, MPI_MAX, ipcomm); + MPI_Allreduce((void *)&lbsum, (void *)&min_lbsum, 1, MPI_FLOAT, MPI_MIN, ipcomm); + lpecost.rank = ctrl->mype; + lpecost.cost = lbsum; + if (min_lbsum < UNBALANCE_FRACTION * (float)(ncon)) { + if (lbsum < UNBALANCE_FRACTION * (float)(ncon)) + lpecost.cost = (float)edgecut; + else + lpecost.cost = (float)max_cut + lbsum; + } + MPI_Allreduce((void *)&lpecost, (void *)&gpecost, 1, MPI_FLOAT_INT, MPI_MINLOC, ipcomm); + + if (ctrl->mype == gpecost.rank && ctrl->mype != sr_pe) { + MPI_Send((void *)part, nvtxs, IDX_DATATYPE, sr_pe, 1, ctrl->comm); + } + + if (ctrl->mype != gpecost.rank && ctrl->mype == sr_pe) { + MPI_Recv((void *)part, nvtxs, IDX_DATATYPE, gpecost.rank, 1, ctrl->comm, &status); + } + + if (ctrl->mype == sr_pe) { + idxcopy(nvtxs, part, lwhere); + SerialRemap(&cgraph, ctrl->nparts, home, lwhere, part, ctrl->tpwgts); + } + + MPI_Comm_free(&srcomm); + } + /**************************************/ + /* The other half do global diffusion */ + /**************************************/ + else { + /******************************************************************/ + /* The next stmt is required to balance out the sr MPI_Comm_split */ + /******************************************************************/ + MPI_Comm_split(ipcomm, MPI_UNDEFINED, 0, &srcomm); + + if (ncon == 1) { + rating = WavefrontDiffusion(&myctrl, agraph, home); + Moc_ComputeSerialBalance(ctrl, &cgraph, part, lbvec); + lbsum = ssum(ncon, lbvec); + + /* Determine which PE computed the best partitioning */ + MPI_Allreduce((void *)&rating, (void *)&max_rating, 1, MPI_FLOAT, MPI_MAX, ipcomm); + MPI_Allreduce((void *)&lbsum, (void *)&min_lbsum, 1, MPI_FLOAT, MPI_MIN, ipcomm); + + lpecost.rank = ctrl->mype; + lpecost.cost = lbsum; + if (min_lbsum < UNBALANCE_FRACTION * (float)(ncon)) { + if (lbsum < UNBALANCE_FRACTION * (float)(ncon)) + lpecost.cost = rating; + else + lpecost.cost = max_rating + lbsum; + } + + MPI_Allreduce((void *)&lpecost, (void *)&gpecost, 1, MPI_FLOAT_INT, MPI_MINLOC, ipcomm); + + /* Now send this to the coordinating processor */ + if (ctrl->mype == gpecost.rank && ctrl->mype != gd_pe) + MPI_Send((void *)part, nvtxs, IDX_DATATYPE, gd_pe, 1, ctrl->comm); + + if (ctrl->mype != gpecost.rank && ctrl->mype == gd_pe) + MPI_Recv((void *)part, nvtxs, IDX_DATATYPE, gpecost.rank, 1, ctrl->comm, &status); + + if (ctrl->mype == gd_pe) { + idxcopy(nvtxs, part, lwhere); + SerialRemap(&cgraph, ctrl->nparts, home, lwhere, part, ctrl->tpwgts); + } + } + else { + Moc_Diffusion(&myctrl, agraph, graph->vtxdist, agraph->where, home, wspace, N_MOC_GD_PASSES); + } + } + + if (graph->ncon <= MAX_NCON_FOR_DIFFUSION) { + if (ctrl->mype == sr_pe || ctrl->mype == gd_pe) { + /********************************************************************/ + /* The coordinators from each group decide on the best partitioning */ + /********************************************************************/ + my_cut = (float) ComputeSerialEdgeCut(&cgraph); + my_totalv = (float) Mc_ComputeSerialTotalV(&cgraph, home); + Moc_ComputeSerialBalance(ctrl, &cgraph, part, lbvec); + my_balance = ssum(cgraph.ncon, lbvec); + my_balance /= (float) cgraph.ncon; + my_cost = ctrl->ipc_factor * my_cut + REDIST_WGT * ctrl->redist_base * my_totalv; + + IFSET(ctrl->dbglvl, DBG_REFINEINFO, printf("%s initial cut: %.1f, totalv: %.1f, balance: %.3f\n", + (ctrl->mype == sr_pe ? "scratch-remap" : "diffusion"), my_cut, my_totalv, my_balance)); + + if (ctrl->mype == gd_pe) { + buffer[0] = my_cost; + buffer[1] = my_balance; + MPI_Send((void *)buffer, 2, MPI_FLOAT, sr_pe, 1, ctrl->comm); + } + else { + MPI_Recv((void *)buffer, 2, MPI_FLOAT, gd_pe, 1, ctrl->comm, &status); + your_cost = buffer[0]; + your_balance = buffer[1]; + } + } + + if (ctrl->mype == sr_pe) { + who_wins = gd_pe; + if ((my_balance < 1.1 && your_balance > 1.1) || + (my_balance < 1.1 && your_balance < 1.1 && my_cost < your_cost) || + (my_balance > 1.1 && your_balance > 1.1 && my_balance < your_balance)) { + who_wins = sr_pe; + } + } + + MPI_Bcast((void *)&who_wins, 1, MPI_INT, sr_pe, ctrl->comm); + } + else { + who_wins = sr_pe; + } + + MPI_Bcast((void *)part, nvtxs, IDX_DATATYPE, who_wins, ctrl->comm); + idxcopy(graph->nvtxs, part+vtxdist[ctrl->mype], graph->where); + + MPI_Comm_free(&ipcomm); + GKfree((void **)&xadj, (void **)&mytpwgts, LTERM); + +/* For whatever reason, FreeGraph crashes here...so explicitly free the memory. + FreeGraph(agraph); +*/ + GKfree((void **)&agraph->xadj, (void **)&agraph->adjncy, (void **)&agraph->vwgt, (void **)&agraph->nvwgt, LTERM); + GKfree((void **)&agraph->vsize, (void **)&agraph->adjwgt, (void **)&agraph->label, LTERM); + GKfree((void **)&agraph, LTERM); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->InitPartTmr)); + +} + + +/* NOTE: this subroutine should work for static, adaptive, single-, and multi-contraint */ +/************************************************************************* +* This function assembles the graph into a single processor +**************************************************************************/ +GraphType *Moc_AssembleAdaptiveGraph(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int i, j, k, l, gnvtxs, nvtxs, ncon, gnedges, nedges, gsize; + idxtype *xadj, *vwgt, *vsize, *adjncy, *adjwgt, *vtxdist, *imap; + idxtype *axadj, *aadjncy, *aadjwgt, *avwgt, *avsize = NULL, *alabel; + idxtype *mygraph, *ggraph; + int *rcounts, *rdispls, mysize; + float *anvwgt; + GraphType *agraph; + + gnvtxs = graph->gnvtxs; + nvtxs = graph->nvtxs; + ncon = graph->ncon; + nedges = graph->xadj[nvtxs]; + xadj = graph->xadj; + vwgt = graph->vwgt; + vsize = graph->vsize; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + vtxdist = graph->vtxdist; + imap = graph->imap; + + /*************************************************************/ + /* Determine the # of idxtype to receive from each processor */ + /*************************************************************/ + rcounts = imalloc(ctrl->npes, "AssembleGraph: rcounts"); + switch (ctrl->partType) { + case STATIC_PARTITION: + mysize = (1+ncon)*nvtxs + 2*nedges; + break; + case ADAPTIVE_PARTITION: + case REFINE_PARTITION: + mysize = (2+ncon)*nvtxs + 2*nedges; + break; + default: + printf("WARNING: bad value for ctrl->partType %d\n", ctrl->partType); + break; + } + MPI_Allgather((void *)(&mysize), 1, MPI_INT, (void *)rcounts, 1, MPI_INT, ctrl->comm); + + rdispls = imalloc(ctrl->npes+1, "AssembleGraph: rdispls"); + rdispls[0] = 0; + for (i=1; i<ctrl->npes+1; i++) + rdispls[i] = rdispls[i-1] + rcounts[i-1]; + + /* Construct the one-array storage format of the assembled graph */ + mygraph = (mysize <= wspace->maxcore ? wspace->core : idxmalloc(mysize, "AssembleGraph: mygraph")); + for (k=i=0; i<nvtxs; i++) { + mygraph[k++] = xadj[i+1]-xadj[i]; + for (j=0; j<ncon; j++) + mygraph[k++] = vwgt[i*ncon+j]; + if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) + mygraph[k++] = vsize[i]; + for (j=xadj[i]; j<xadj[i+1]; j++) { + mygraph[k++] = imap[adjncy[j]]; + mygraph[k++] = adjwgt[j]; + } + } + ASSERT(ctrl, mysize == k); + + /**************************************/ + /* Assemble and send the entire graph */ + /**************************************/ + gsize = rdispls[ctrl->npes]; + ggraph = (gsize <= wspace->maxcore-mysize ? wspace->core+mysize : idxmalloc(gsize, "AssembleGraph: ggraph")); + MPI_Allgatherv((void *)mygraph, mysize, IDX_DATATYPE, (void *)ggraph, rcounts, rdispls, IDX_DATATYPE, ctrl->comm); + + GKfree((void **)&rcounts, (void **)&rdispls, LTERM); + if (mysize > wspace->maxcore) + free(mygraph); + + agraph = CreateGraph(); + agraph->nvtxs = gnvtxs; + switch (ctrl->partType) { + case STATIC_PARTITION: + agraph->nedges = gnedges = (gsize-(1+ncon)*gnvtxs)/2; + break; + case ADAPTIVE_PARTITION: + case REFINE_PARTITION: + agraph->nedges = gnedges = (gsize-(2+ncon)*gnvtxs)/2; + break; + default: + printf("WARNING: bad value for ctrl->partType %d\n", ctrl->partType); + agraph->nedges = gnedges = -1; + break; + } + + agraph->ncon = ncon; + + /*******************************************/ + /* Allocate memory for the assembled graph */ + /*******************************************/ + axadj = agraph->xadj = idxmalloc(gnvtxs+1, "AssembleGraph: axadj"); + avwgt = agraph->vwgt = idxmalloc(gnvtxs*ncon, "AssembleGraph: avwgt"); + anvwgt = agraph->nvwgt = fmalloc(gnvtxs*ncon, "AssembleGraph: anvwgt"); + aadjncy = agraph->adjncy = idxmalloc(gnedges, "AssembleGraph: adjncy"); + aadjwgt = agraph->adjwgt = idxmalloc(gnedges, "AssembleGraph: adjwgt"); + alabel = agraph->label = idxmalloc(gnvtxs, "AssembleGraph: alabel"); + if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) + avsize = agraph->vsize = idxmalloc(gnvtxs, "AssembleGraph: avsize"); + + for (k=j=i=0; i<gnvtxs; i++) { + axadj[i] = ggraph[k++]; + for (l=0; l<ncon; l++) + avwgt[i*ncon+l] = ggraph[k++]; + if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) + avsize[i] = ggraph[k++]; + for (l=0; l<axadj[i]; l++) { + aadjncy[j] = ggraph[k++]; + aadjwgt[j] = ggraph[k++]; + j++; + } + } + + /*********************************/ + /* Now fix up the received graph */ + /*********************************/ + MAKECSR(i, gnvtxs, axadj); + + for (i=0; i<gnvtxs; i++) + for (j=0; j<ncon; j++) + anvwgt[i*ncon+j] = (float)(agraph->vwgt[i*ncon+j]) / (float)(ctrl->tvwgts[j]); + + for (i=0; i<gnvtxs; i++) + alabel[i] = i; + + if (gsize > wspace->maxcore-mysize) + free(ggraph); + + return agraph; +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/initmsection.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/initmsection.c new file mode 100644 index 0000000..63c7c35 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/initmsection.c @@ -0,0 +1,242 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * initmsection.c + * + * This file contains code that performs the k-way multisection + * + * Started 6/3/97 + * George + * + * $Id: initmsection.c,v 1.2 2003/07/21 17:18:49 karypis Exp $ + */ + +#include <parmetislib.h> + + +#define DEBUG_IPART_ + + + +/************************************************************************* +* This function is the entry point of the initial partitioning algorithm. +* This algorithm assembles the graph to all the processors and preceed +* serially. +**************************************************************************/ +void InitMultisection(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int i, lpecut[2], gpecut[2], mypart, moptions[10]; + idxtype *vtxdist, *gwhere = NULL, *part, *label; + GraphType *agraph; + int *sendcounts, *displs; + MPI_Comm newcomm, labelcomm; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->InitPartTmr)); + + /* Assemble the graph and do the necessary pre-processing */ + agraph = AssembleMultisectedGraph(ctrl, graph, wspace); + part = agraph->where; + agraph->where = NULL; + + /* Split the processors into groups so that each one can do a bisection */ + mypart = ctrl->mype%(ctrl->nparts/2); + MPI_Comm_split(ctrl->comm, mypart, 0, &newcomm); + + /* Each processor keeps the graphs that it only needs and bisects it */ + agraph->ncon = 1; /* needed for Moc_KeepPart */ + Moc_KeepPart(agraph, wspace, part, mypart); + label = agraph->label; /* Save this because ipart may need it */ + agraph->label = NULL; + + /* Bisect the graph and construct the separator */ + switch (ctrl->ipart) { + case ISEP_EDGE: + moptions[0] = 1; + moptions[1] = 3; + moptions[2] = 1; + moptions[3] = 1; + moptions[4] = 0; + moptions[7] = ctrl->mype; + + agraph->where = idxmalloc(agraph->nvtxs, "InitMultisection: agraph->where"); + + METIS_EdgeComputeSeparator(&agraph->nvtxs, agraph->xadj, agraph->adjncy, + agraph->vwgt, agraph->adjwgt, moptions, &agraph->mincut, agraph->where); + break; + case ISEP_NODE: + moptions[0] = 1; + moptions[1] = 3; + moptions[2] = 1; + moptions[3] = 2; + moptions[4] = 0; + moptions[7] = ctrl->mype; + + agraph->where = idxmalloc(agraph->nvtxs, "InitMultisection: agraph->where"); + + METIS_NodeComputeSeparator(&agraph->nvtxs, agraph->xadj, agraph->adjncy, agraph->vwgt, + agraph->adjwgt, moptions, &agraph->mincut, agraph->where); + break; + default: + errexit("Unknown ISEP type!\n"); + } + + for (i=0; i<agraph->nvtxs; i++) { + ASSERT(ctrl, agraph->where[i]>=0 && agraph->where[i]<=2); + if (agraph->where[i] == 2) + agraph->where[i] = ctrl->nparts+2*mypart; + else + agraph->where[i] += 2*mypart; + } + + /* Determine which PE got the minimum cut */ + lpecut[0] = agraph->mincut; + MPI_Comm_rank(newcomm, lpecut+1); + MPI_Allreduce(lpecut, gpecut, 1, MPI_2INT, MPI_MINLOC, newcomm); + + /* myprintf(ctrl, "Nvtxs: %d, Mincut: %d, GMincut: %d, %d\n", agraph->nvtxs, agraph->mincut, gpecut[0], gpecut[1]); */ + + /* Send the best where to the root processor of this partition */ + if (lpecut[1] == gpecut[1] && gpecut[1] != 0) + MPI_Send((void *)agraph->where, agraph->nvtxs, IDX_DATATYPE, 0, 1, newcomm); + if (lpecut[1] == 0 && gpecut[1] != 0) + MPI_Recv((void *)agraph->where, agraph->nvtxs, IDX_DATATYPE, gpecut[1], 1, newcomm, &ctrl->status); + + /* Create a communicator that stores all the i-th processors of the newcomm */ + MPI_Comm_split(ctrl->comm, lpecut[1], 0, &labelcomm); + + /* Map the separator back to agraph. This is inefficient! */ + if (lpecut[1] == 0) { + gwhere = idxsmalloc(graph->gnvtxs, 0, "InitMultisection: gwhere"); + for (i=0; i<agraph->nvtxs; i++) + gwhere[label[i]] = agraph->where[i]; + } + + free(agraph->where); + agraph->where = part; + + if (lpecut[1] == 0) { + MPI_Reduce((void *)gwhere, (void *)agraph->where, graph->gnvtxs, IDX_DATATYPE, MPI_SUM, 0, labelcomm); + free(gwhere); + } + + /* The minimum PE performs the Scatter */ + vtxdist = graph->vtxdist; + ASSERT(ctrl, graph->where != NULL); + free(graph->where); /* Remove the propagated down where info */ + graph->where = idxmalloc(graph->nvtxs+graph->nrecv, "InitPartition: where"); + + sendcounts = imalloc(ctrl->npes, "InitPartitionNew: sendcounts"); + displs = imalloc(ctrl->npes, "InitPartitionNew: displs"); + + for (i=0; i<ctrl->npes; i++) { + sendcounts[i] = vtxdist[i+1]-vtxdist[i]; + displs[i] = vtxdist[i]; + } + + MPI_Scatterv((void *)agraph->where, sendcounts, displs, IDX_DATATYPE, + (void *)graph->where, graph->nvtxs, IDX_DATATYPE, 0, ctrl->comm); + + GKfree((void **)&sendcounts, (void **)&displs, (void **)&label, LTERM); + + FreeGraph(agraph); + + MPI_Comm_free(&newcomm); + MPI_Comm_free(&labelcomm); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->InitPartTmr)); + +} + + + + +/************************************************************************* +* This function assembles the graph into a single processor +**************************************************************************/ +GraphType *AssembleMultisectedGraph(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int i, j, k, l, gnvtxs, nvtxs, gnedges, nedges, gsize; + idxtype *xadj, *vwgt, *where, *adjncy, *adjwgt, *vtxdist, *imap; + idxtype *axadj, *aadjncy, *aadjwgt, *avwgt, *awhere, *alabel; + idxtype *mygraph, *ggraph; + int *recvcounts, *displs, mysize; + GraphType *agraph; + + gnvtxs = graph->gnvtxs; + nvtxs = graph->nvtxs; + nedges = graph->xadj[nvtxs]; + xadj = graph->xadj; + vwgt = graph->vwgt; + where = graph->where; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + vtxdist = graph->vtxdist; + imap = graph->imap; + + /* Determine the # of idxtype to receive from each processor */ + recvcounts = imalloc(ctrl->npes, "AssembleGraph: recvcounts"); + mysize = 3*nvtxs + 2*nedges; + MPI_Allgather((void *)(&mysize), 1, MPI_INT, (void *)recvcounts, 1, MPI_INT, ctrl->comm); + + displs = imalloc(ctrl->npes+1, "AssembleGraph: displs"); + displs[0] = 0; + for (i=1; i<ctrl->npes+1; i++) + displs[i] = displs[i-1] + recvcounts[i-1]; + + /* Construct the one-array storage format of the assembled graph */ + mygraph = (mysize <= wspace->maxcore ? wspace->core : idxmalloc(mysize, "AssembleGraph: mygraph")); + for (k=i=0; i<nvtxs; i++) { + mygraph[k++] = xadj[i+1]-xadj[i]; + mygraph[k++] = vwgt[i]; + mygraph[k++] = where[i]; + for (j=xadj[i]; j<xadj[i+1]; j++) { + mygraph[k++] = imap[adjncy[j]]; + mygraph[k++] = adjwgt[j]; + } + } + ASSERT(ctrl, mysize == k); + + /* Assemble the entire graph */ + gsize = displs[ctrl->npes]; + ggraph = (gsize <= wspace->maxcore-mysize ? wspace->core+mysize : idxmalloc(gsize, "AssembleGraph: ggraph")); + MPI_Allgatherv((void *)mygraph, mysize, IDX_DATATYPE, (void *)ggraph, recvcounts, displs, IDX_DATATYPE, ctrl->comm); + + GKfree((void **)&recvcounts, (void **)&displs, LTERM); + if (mysize > wspace->maxcore) + free(mygraph); + + agraph = CreateGraph(); + agraph->nvtxs = gnvtxs; + agraph->nedges = gnedges = (gsize-3*gnvtxs)/2; + + /* Allocate memory for the assembled graph */ + axadj = agraph->xadj = idxmalloc(gnvtxs+1, "AssembleGraph: axadj"); + avwgt = agraph->vwgt = idxmalloc(gnvtxs, "AssembleGraph: avwgt"); + awhere = agraph->where = idxmalloc(gnvtxs, "AssembleGraph: awhere"); + aadjncy = agraph->adjncy = idxmalloc(gnedges, "AssembleGraph: adjncy"); + aadjwgt = agraph->adjwgt = idxmalloc(gnedges, "AssembleGraph: adjwgt"); + alabel = agraph->label = idxmalloc(gnvtxs, "AssembleGraph: alabel"); + + for (k=j=i=0; i<gnvtxs; i++) { + axadj[i] = ggraph[k++]; + avwgt[i] = ggraph[k++]; + awhere[i] = ggraph[k++]; + for (l=0; l<axadj[i]; l++) { + aadjncy[j] = ggraph[k++]; + aadjwgt[j] = ggraph[k++]; + j++; + } + } + + /* Now fix up the received graph */ + MAKECSR(i, gnvtxs, axadj); + + for (i=0; i<gnvtxs; i++) + alabel[i] = i; + + if (gsize > wspace->maxcore-mysize) + free(ggraph); + + return agraph; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/initpart.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/initpart.c new file mode 100644 index 0000000..40b8d95 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/initpart.c @@ -0,0 +1,252 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * initpart.c + * + * This file contains code that performs log(p) parallel multilevel + * recursive bissection + * + * Started 3/4/96 + * George + * + * $Id: initpart.c,v 1.2 2003/07/21 17:18:49 karypis Exp $ + */ + +#include <parmetislib.h> + + +#define DEBUG_IPART_ + + + +/************************************************************************* +* This function is the entry point of the initial partition algorithm +* that does recursive bissection. +* This algorithm assembles the graph to all the processors and preceeds +* by parallelizing the recursive bisection step. +**************************************************************************/ +void Moc_InitPartition_RB(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int i, j; + int ncon, mype, npes, gnvtxs, ngroups; + idxtype *xadj, *adjncy, *adjwgt, *vwgt; + idxtype *part, *gwhere0, *gwhere1; + idxtype *tmpwhere, *tmpvwgt, *tmpxadj, *tmpadjncy, *tmpadjwgt; + GraphType *agraph; + int lnparts, fpart, fpe, lnpes; + int twoparts=2, numflag = 0, wgtflag = 3, moptions[10], edgecut, max_cut; + float *mytpwgts, mytpwgts2[2], lbvec[MAXNCON], lbsum, min_lbsum, wsum; + MPI_Comm ipcomm; + struct { + float sum; + int rank; + } lpesum, gpesum; + + ncon = graph->ncon; + ngroups = amax(amin(RIP_SPLIT_FACTOR, ctrl->npes), 1); + + IFSET(ctrl->dbglvl, DBG_TIME, MPI_Barrier(ctrl->comm)); + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->InitPartTmr)); + + agraph = Moc_AssembleAdaptiveGraph(ctrl, graph, wspace); + part = idxmalloc(agraph->nvtxs, "Moc_IP_RB: part"); + xadj = idxmalloc(agraph->nvtxs+1, "Moc_IP_RB: xadj"); + adjncy = idxmalloc(agraph->nedges, "Moc_IP_RB: adjncy"); + adjwgt = idxmalloc(agraph->nedges, "Moc_IP_RB: adjwgt"); + vwgt = idxmalloc(agraph->nvtxs*ncon, "Moc_IP_RB: vwgt"); + + idxcopy(agraph->nvtxs*ncon, agraph->vwgt, vwgt); + idxcopy(agraph->nvtxs+1, agraph->xadj, xadj); + idxcopy(agraph->nedges, agraph->adjncy, adjncy); + idxcopy(agraph->nedges, agraph->adjwgt, adjwgt); + + MPI_Comm_split(ctrl->gcomm, ctrl->mype % ngroups, 0, &ipcomm); + MPI_Comm_rank(ipcomm, &mype); + MPI_Comm_size(ipcomm, &npes); + + gnvtxs = agraph->nvtxs; + + gwhere0 = idxsmalloc(gnvtxs, 0, "Moc_IP_RB: gwhere0"); + gwhere1 = idxmalloc(gnvtxs, "Moc_IP_RB: gwhere1"); + + /* ADD: this assumes that tpwgts for all constraints is the same */ + /* ADD: this is necessary because serial metis does not support the general case */ + mytpwgts = fsmalloc(ctrl->nparts, 0.0, "mytpwgts"); + for (i=0; i<ctrl->nparts; i++) + for (j=0; j<ncon; j++) + mytpwgts[i] += ctrl->tpwgts[i*ncon+j]; + for (i=0; i<ctrl->nparts; i++) + mytpwgts[i] /= (float)ncon; + + /* Go into the recursive bisection */ + /* ADD: consider changing this to breadth-first type bisection */ + moptions[0] = 0; + moptions[7] = ctrl->sync + (ctrl->mype % ngroups) + 1; + + lnparts = ctrl->nparts; + fpart = fpe = 0; + lnpes = npes; + while (lnpes > 1 && lnparts > 1) { + /* Determine the weights of the partitions */ + mytpwgts2[0] = ssum(lnparts/2, mytpwgts+fpart); + mytpwgts2[1] = 1.0-mytpwgts2[0]; + + if (ncon == 1) + METIS_WPartGraphKway2(&agraph->nvtxs, agraph->xadj, agraph->adjncy, + agraph->vwgt, agraph->adjwgt, &wgtflag, &numflag, &twoparts, mytpwgts2, + moptions, &edgecut, part); + else { + METIS_mCPartGraphRecursive2(&agraph->nvtxs, &ncon, agraph->xadj, + agraph->adjncy, agraph->vwgt, agraph->adjwgt, &wgtflag, &numflag, + &twoparts, mytpwgts2, moptions, &edgecut, part); + } + + wsum = ssum(lnparts/2, mytpwgts+fpart); + sscale(lnparts/2, 1.0/wsum, mytpwgts+fpart); + sscale(lnparts-lnparts/2, 1.0/(1.0-wsum), mytpwgts+fpart+lnparts/2); + + /* I'm picking the left branch */ + if (mype < fpe+lnpes/2) { + Moc_KeepPart(agraph, wspace, part, 0); + lnpes = lnpes/2; + lnparts = lnparts/2; + } + else { + Moc_KeepPart(agraph, wspace, part, 1); + fpart = fpart + lnparts/2; + fpe = fpe + lnpes/2; + lnpes = lnpes - lnpes/2; + lnparts = lnparts - lnparts/2; + } + } + + /* In case npes is greater than or equal to nparts */ + if (lnparts == 1) { + /* Only the first process will assign labels (for the reduction to work) */ + if (mype == fpe) { + for (i=0; i<agraph->nvtxs; i++) + gwhere0[agraph->label[i]] = fpart; + } + } + /* In case npes is smaller than nparts */ + else { + if (ncon == 1) + METIS_WPartGraphKway2(&agraph->nvtxs, agraph->xadj, agraph->adjncy, + agraph->vwgt, agraph->adjwgt, &wgtflag, &numflag, &lnparts, mytpwgts+fpart, + moptions, &edgecut, part); + else + METIS_mCPartGraphRecursive2(&agraph->nvtxs, &ncon, agraph->xadj, + agraph->adjncy, agraph->vwgt, agraph->adjwgt, &wgtflag, &numflag, + &lnparts, mytpwgts+fpart, moptions, &edgecut, part); + + for (i=0; i<agraph->nvtxs; i++) + gwhere0[agraph->label[i]] = fpart + part[i]; + } + + MPI_Allreduce((void *)gwhere0, (void *)gwhere1, gnvtxs, IDX_DATATYPE, MPI_SUM, ipcomm); + + if (ngroups > 1) { + tmpxadj = agraph->xadj; + tmpadjncy = agraph->adjncy; + tmpadjwgt = agraph->adjwgt; + tmpvwgt = agraph->vwgt; + tmpwhere = agraph->where; + agraph->xadj = xadj; + agraph->adjncy = adjncy; + agraph->adjwgt = adjwgt; + agraph->vwgt = vwgt; + agraph->where = gwhere1; + agraph->vwgt = vwgt; + agraph->nvtxs = gnvtxs; + Moc_ComputeSerialBalance(ctrl, agraph, gwhere1, lbvec); + lbsum = ssum(ncon, lbvec); + + edgecut = ComputeSerialEdgeCut(agraph); + MPI_Allreduce((void *)&edgecut, (void *)&max_cut, 1, MPI_INT, MPI_MAX, ctrl->gcomm); + MPI_Allreduce((void *)&lbsum, (void *)&min_lbsum, 1, MPI_FLOAT, MPI_MIN, ctrl->gcomm); + + lpesum.sum = lbsum; + if (min_lbsum < UNBALANCE_FRACTION * (float)(ncon)) { + if (lbsum < UNBALANCE_FRACTION * (float)(ncon)) + lpesum.sum = (float) (edgecut); + else + lpesum.sum = (float) (max_cut); + } + + MPI_Comm_rank(ctrl->gcomm, &(lpesum.rank)); + MPI_Allreduce((void *)&lpesum, (void *)&gpesum, 1, MPI_FLOAT_INT, MPI_MINLOC, ctrl->gcomm); + MPI_Bcast((void *)gwhere1, gnvtxs, IDX_DATATYPE, gpesum.rank, ctrl->gcomm); + + agraph->xadj = tmpxadj; + agraph->adjncy = tmpadjncy; + agraph->adjwgt = tmpadjwgt; + agraph->vwgt = tmpvwgt; + agraph->where = tmpwhere; + } + + idxcopy(graph->nvtxs, gwhere1+graph->vtxdist[ctrl->mype], graph->where); + + FreeGraph(agraph); + MPI_Comm_free(&ipcomm); + GKfree((void **)&gwhere0, (void **)&gwhere1, (void **)&mytpwgts, (void **)&part, (void **)&xadj, (void **)&adjncy, (void **)&adjwgt, (void **)&vwgt, LTERM); + + IFSET(ctrl->dbglvl, DBG_TIME, MPI_Barrier(ctrl->comm)); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->InitPartTmr)); + +} + + +/************************************************************************* +* This function keeps one parts +**************************************************************************/ +void Moc_KeepPart(GraphType *graph, WorkSpaceType *wspace, idxtype *part, int mypart) +{ + int h, i, j, k; + int nvtxs, ncon, mynvtxs, mynedges; + idxtype *xadj, *vwgt, *adjncy, *adjwgt, *label; + idxtype *rename; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + label = graph->label; + + rename = idxmalloc(nvtxs, "Moc_KeepPart: rename"); + + for (mynvtxs=0, i=0; i<nvtxs; i++) { + if (part[i] == mypart) + rename[i] = mynvtxs++; + } + + for (mynvtxs=0, mynedges=0, j=xadj[0], i=0; i<nvtxs; i++) { + if (part[i] == mypart) { + for (; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (part[k] == mypart) { + adjncy[mynedges] = rename[k]; + adjwgt[mynedges++] = adjwgt[j]; + } + } + j = xadj[i+1]; /* Save xadj[i+1] for later use */ + + for (h=0; h<ncon; h++) + vwgt[mynvtxs*ncon+h] = vwgt[i*ncon+h]; + label[mynvtxs] = label[i]; + xadj[++mynvtxs] = mynedges; + + } + else { + j = xadj[i+1]; /* Save xadj[i+1] for later use */ + } + } + + graph->nvtxs = mynvtxs; + graph->nedges = mynedges; + + free(rename); +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/kmetis.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/kmetis.c new file mode 100644 index 0000000..2ad20e3 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/kmetis.c @@ -0,0 +1,274 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * kmetis.c + * + * This is the entry point of Moc_PARMETIS_PartGraphKway + * + * Started 10/19/96 + * George + * + * $Id: kmetis.c,v 1.9 2003/07/31 16:27:27 karypis Exp $ + * + */ + +#include <parmetislib.h> + + +/*********************************************************************************** +* This function is the entry point of the parallel k-way multilevel partitionioner. +* This function assumes nothing about the graph distribution. +* It is the general case. +************************************************************************************/ +void ParMETIS_V3_PartKway(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *ncon, int *nparts, + float *tpwgts, float *ubvec, int *options, int *edgecut, idxtype *part, + MPI_Comm *comm) +{ + int h, i; + int nvtxs = -1, npes, mype; + CtrlType ctrl; + WorkSpaceType wspace; + GraphType *graph; + float avg, maximb, *mytpwgts; + int moptions[10]; + int seed, dbglvl = 0; + int iwgtflag, inumflag, incon, inparts, ioptions[10]; + float *itpwgts, iubvec[MAXNCON]; + + MPI_Comm_size(*comm, &npes); + MPI_Comm_rank(*comm, &mype); + + + /********************************/ + /* Try and take care bad inputs */ + /********************************/ + if (options != NULL && options[0] == 1) + dbglvl = options[PMV3_OPTION_DBGLVL]; + + CheckInputs(STATIC_PARTITION, npes, dbglvl, wgtflag, &iwgtflag, numflag, &inumflag, ncon, + &incon, nparts, &inparts, tpwgts, &itpwgts, ubvec, iubvec, NULL, NULL, + options, ioptions, part, comm); + + + /*********************************/ + /* Take care the nparts = 1 case */ + /*********************************/ + if (inparts <= 1) { + idxset(vtxdist[mype+1]-vtxdist[mype], 0, part); + *edgecut = 0; + return; + } + + /******************************/ + /* Take care of npes = 1 case */ + /******************************/ + if (npes == 1 && inparts > 1) { + moptions[0] = 0; + nvtxs = vtxdist[1]; + + if (incon == 1) { + METIS_WPartGraphKway(&nvtxs, xadj, adjncy, vwgt, adjwgt, &iwgtflag, &inumflag, + &inparts, itpwgts, moptions, edgecut, part); + } + else { + /* ADD: this is because METIS does not support tpwgts for all constraints */ + mytpwgts = fmalloc(inparts, "mytpwgts"); + for (i=0; i<inparts; i++) + mytpwgts[i] = itpwgts[i*incon]; + + moptions[7] = -1; + METIS_mCPartGraphRecursive2(&nvtxs, &incon, xadj, adjncy, vwgt, adjwgt, &iwgtflag, + &inumflag, &inparts, mytpwgts, moptions, edgecut, part); + + free(mytpwgts); + } + + return; + } + + + if (inumflag == 1) + ChangeNumbering(vtxdist, xadj, adjncy, part, npes, mype, 1); + + /*****************************/ + /* Set up control structures */ + /*****************************/ + if (ioptions[0] == 1) { + dbglvl = ioptions[PMV3_OPTION_DBGLVL]; + seed = ioptions[PMV3_OPTION_SEED]; + } + else { + dbglvl = GLOBAL_DBGLVL; + seed = GLOBAL_SEED; + } + SetUpCtrl(&ctrl, inparts, dbglvl, *comm); + ctrl.CoarsenTo = amin(vtxdist[npes]+1, 25*incon*amax(npes, inparts)); + ctrl.seed = (seed == 0) ? mype : seed*mype; + ctrl.sync = GlobalSEMax(&ctrl, seed); + ctrl.partType = STATIC_PARTITION; + ctrl.ps_relation = -1; + ctrl.tpwgts = itpwgts; + scopy(incon, iubvec, ctrl.ubvec); + + graph = Moc_SetUpGraph(&ctrl, incon, vtxdist, xadj, vwgt, adjncy, adjwgt, &iwgtflag); + + PreAllocateMemory(&ctrl, graph, &wspace); + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + /*******************************************/ + /* Check for funny cases */ + /* -graph with no edges */ + /* -graph with self edges */ + /* -graph with poor vertex distribution */ + /* -graph with less than 2*npe nodes */ + /*******************************************/ + if (vtxdist[npes] < SMALLGRAPH || vtxdist[npes] < npes*20 || GlobalSESum(&ctrl, graph->nedges) == 0) { + IFSET(ctrl.dbglvl, DBG_INFO, rprintf(&ctrl, "Partitioning a graph of size %d serially\n", vtxdist[npes])); + PartitionSmallGraph(&ctrl, graph, &wspace); + } + else { + /***********************/ + /* Partition the graph */ + /***********************/ + Moc_Global_Partition(&ctrl, graph, &wspace); + ParallelReMapGraph(&ctrl, graph, &wspace); + } + + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + + idxcopy(graph->nvtxs, graph->where, part); + *edgecut = graph->mincut; + + /*******************/ + /* Print out stats */ + /*******************/ + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimingInfo(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + + if (ctrl.dbglvl&DBG_INFO) { + rprintf(&ctrl, "Final %d-way CUT: %6d \tBalance: ", inparts, graph->mincut); + avg = 0.0; + for (h=0; h<incon; h++) { + maximb = 0.0; + for (i=0; i<inparts; i++) + maximb = amax(maximb, graph->gnpwgts[i*incon+h]/itpwgts[i*incon+h]); + avg += maximb; + rprintf(&ctrl, "%.3f ", maximb); + } + rprintf(&ctrl, " avg: %.3f\n", avg/(float)incon); + } + + GKfree((void **)&itpwgts, (void **)&graph->lnpwgts, (void **)&graph->gnpwgts, (void **)&graph->nvwgt, LTERM); + FreeInitialGraphAndRemap(graph, iwgtflag); + FreeWSpace(&wspace); + FreeCtrl(&ctrl); + + if (inumflag == 1) + ChangeNumbering(vtxdist, xadj, adjncy, part, npes, mype, 0); + +} + + + +/************************************************************************* +* This function is the driver to the multi-constraint partitioning algorithm. +**************************************************************************/ +void Moc_Global_Partition(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int i, ncon, nparts; + float ftmp, ubavg, lbavg, lbvec[MAXNCON]; + + ncon = graph->ncon; + nparts = ctrl->nparts; + ubavg = savg(graph->ncon, ctrl->ubvec); + + SetUp(ctrl, graph, wspace); + + if (ctrl->dbglvl&DBG_PROGRESS) { + rprintf(ctrl, "[%6d %8d %5d %5d] [%d] [", graph->gnvtxs, GlobalSESum(ctrl, graph->nedges), + GlobalSEMin(ctrl, graph->nvtxs), GlobalSEMax(ctrl, graph->nvtxs), ctrl->CoarsenTo); + for (i=0; i<ncon; i++) + rprintf(ctrl, " %.3f", GlobalSEMinFloat(ctrl,graph->nvwgt[samin_strd(graph->nvtxs, graph->nvwgt+i, ncon)*ncon+i])); + rprintf(ctrl, "] ["); + for (i=0; i<ncon; i++) + rprintf(ctrl, " %.3f", GlobalSEMaxFloat(ctrl, graph->nvwgt[samax_strd(graph->nvtxs, graph->nvwgt+i, ncon)*ncon+i])); + rprintf(ctrl, "]\n"); + } + + if (graph->gnvtxs < 1.3*ctrl->CoarsenTo || + (graph->finer != NULL && + graph->gnvtxs > graph->finer->gnvtxs*COARSEN_FRACTION)) { + + /* Done with coarsening. Find a partition */ + graph->where = idxmalloc(graph->nvtxs+graph->nrecv, "graph->where"); + Moc_InitPartition_RB(ctrl, graph, wspace); + + if (ctrl->dbglvl&DBG_PROGRESS) { + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + rprintf(ctrl, "nvtxs: %10d, balance: ", graph->gnvtxs); + for (i=0; i<graph->ncon; i++) + rprintf(ctrl, "%.3f ", lbvec[i]); + rprintf(ctrl, "\n"); + } + + /* In case no coarsening took place */ + if (graph->finer == NULL) { + Moc_ComputePartitionParams(ctrl, graph, wspace); + Moc_KWayFM(ctrl, graph, wspace, NGR_PASSES); + } + } + else { + Moc_GlobalMatch_Balance(ctrl, graph, wspace); + + Moc_Global_Partition(ctrl, graph->coarser, wspace); + + Moc_ProjectPartition(ctrl, graph, wspace); + Moc_ComputePartitionParams(ctrl, graph, wspace); + + if (graph->ncon > 1 && graph->level < 3) { + for (i=0; i<ncon; i++) { + ftmp = ssum_strd(nparts, graph->gnpwgts+i, ncon); + if (ftmp != 0.0) + lbvec[i] = (float)(nparts) * + graph->gnpwgts[samax_strd(nparts, graph->gnpwgts+i, ncon)*ncon+i]/ftmp; + else + lbvec[i] = 1.0; + } + lbavg = savg(graph->ncon, lbvec); + + if (lbavg > ubavg + 0.035) { + if (ctrl->dbglvl&DBG_PROGRESS) { + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + rprintf(ctrl, "nvtxs: %10d, cut: %8d, balance: ", graph->gnvtxs, graph->mincut); + for (i=0; i<graph->ncon; i++) + rprintf(ctrl, "%.3f ", lbvec[i]); + rprintf(ctrl, "\n"); + } + + Moc_KWayBalance(ctrl, graph, wspace, graph->ncon); + } + } + + Moc_KWayFM(ctrl, graph, wspace, NGR_PASSES); + + if (ctrl->dbglvl&DBG_PROGRESS) { + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + rprintf(ctrl, "nvtxs: %10d, cut: %8d, balance: ", graph->gnvtxs, graph->mincut); + for (i=0; i<graph->ncon; i++) + rprintf(ctrl, "%.3f ", lbvec[i]); + rprintf(ctrl, "\n"); + } + + if (graph->level != 0) + GKfree((void **)&graph->lnpwgts, (void **)&graph->gnpwgts, LTERM); + } + + return; +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/kwaybalance.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/kwaybalance.c new file mode 100644 index 0000000..003ec7c --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/kwaybalance.c @@ -0,0 +1,456 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mkwaybalance.c + * + * This file contains code that performs the k-way refinement + * + * Started 3/1/96 + * George + * + * $Id: kwaybalance.c,v 1.2 2003/07/21 17:18:49 karypis Exp $ + */ + +#include <parmetislib.h> + +#define ProperSide(c, from, other) \ + (((c) == 0 && (from)-(other) < 0) || ((c) == 1 && (from)-(other) > 0)) + +/************************************************************************* +* This function performs k-way refinement +**************************************************************************/ +void Moc_KWayBalance(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace, int npasses) +{ + int h, i, ii, iii, j, k, c; + int pass, nvtxs, nedges, ncon; + int nmoves, nmoved, nswaps; +/* int gnswaps; */ + int me, firstvtx, lastvtx, yourlastvtx; + int from, to = -1, oldto, oldcut, mydomain, yourdomain, imbalanced; + int npes = ctrl->npes, mype = ctrl->mype, nparts = ctrl->nparts; + int nlupd, nsupd, nnbrs, nchanged; + idxtype *xadj, *ladjncy, *adjwgt, *vtxdist; + idxtype *where, *tmp_where, *moved; + float *lnpwgts, *gnpwgts; + idxtype *update, *supdate, *rupdate, *pe_updates; + idxtype *changed, *perm, *pperm, *htable; + idxtype *peind, *recvptr, *sendptr; + KeyValueType *swchanges, *rwchanges; + RInfoType *rinfo, *myrinfo, *tmp_myrinfo, *tmp_rinfo; + EdgeType *tmp_edegrees, *my_edegrees, *your_edegrees; + float lbvec[MAXNCON], *nvwgt, *badmaxpwgt, *ubvec, *tpwgts, lbavg, ubavg; + int *nupds_pe; +/* int ndirty, nclean, dptr; */ + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->KWayTmr)); + + /*************************/ + /* set up common aliases */ + /*************************/ + nvtxs = graph->nvtxs; + nedges = graph->nedges; + ncon = graph->ncon; + + vtxdist = graph->vtxdist; + xadj = graph->xadj; + ladjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + firstvtx = vtxdist[mype]; + lastvtx = vtxdist[mype+1]; + + where = graph->where; + rinfo = graph->rinfo; + lnpwgts = graph->lnpwgts; + gnpwgts = graph->gnpwgts; + ubvec = ctrl->ubvec; + tpwgts = ctrl->tpwgts; + + nnbrs = graph->nnbrs; + peind = graph->peind; + recvptr = graph->recvptr; + sendptr = graph->sendptr; + + changed = idxmalloc(nvtxs, "KWR: changed"); + rwchanges = wspace->pairs; + swchanges = rwchanges + recvptr[nnbrs]; + + /************************************/ + /* set up important data structures */ + /************************************/ + perm = idxmalloc(nvtxs, "KWR: perm"); + pperm = idxmalloc(nparts, "KWR: pperm"); + + update = idxmalloc(nvtxs, "KWR: update"); + supdate = wspace->indices; + rupdate = supdate + recvptr[nnbrs]; + nupds_pe = imalloc(npes, "KWR: nupds_pe"); + htable = idxsmalloc(nvtxs+graph->nrecv, 0, "KWR: lhtable"); + badmaxpwgt = fmalloc(nparts*ncon, "badmaxpwgt"); + + for (i=0; i<nparts; i++) { + for (h=0; h<ncon; h++) { + badmaxpwgt[i*ncon+h] = ubvec[h]*tpwgts[i*ncon+h]; + } + } + + moved = idxmalloc(nvtxs, "KWR: moved"); + tmp_where = idxmalloc(nvtxs+graph->nrecv, "KWR: tmp_where"); + tmp_rinfo = (RInfoType *)GKmalloc(sizeof(RInfoType)*nvtxs, "KWR: tmp_rinfo"); + tmp_edegrees = (EdgeType *)GKmalloc(sizeof(EdgeType)*nedges, "KWR: tmp_edegrees"); + + idxcopy(nvtxs+graph->nrecv, where, tmp_where); + for (i=0; i<nvtxs; i++) { + tmp_rinfo[i].id = rinfo[i].id; + tmp_rinfo[i].ed = rinfo[i].ed; + tmp_rinfo[i].ndegrees = rinfo[i].ndegrees; + tmp_rinfo[i].degrees = tmp_edegrees+xadj[i]; + + for (j=0; j<rinfo[i].ndegrees; j++) { + tmp_rinfo[i].degrees[j].edge = rinfo[i].degrees[j].edge; + tmp_rinfo[i].degrees[j].ewgt = rinfo[i].degrees[j].ewgt; + } + } + + nswaps = 0; + /*********************************************************/ + /* perform a small number of passes through the vertices */ + /*********************************************************/ + for (pass=0; pass<npasses; pass++) { + oldcut = graph->mincut; + if (mype == 0) + RandomPermute(nparts, pperm, 1); + MPI_Bcast((void *)pperm, nparts, IDX_DATATYPE, 0, ctrl->comm); + FastRandomPermute(nvtxs, perm, 1); + + /*****************************/ + /* move dirty vertices first */ + /*****************************/ +/* + ndirty = 0; + for (i=0; i<nvtxs; i++) + if (where[i] != mype) + ndirty++; + + dptr = 0; + for (i=0; i<nvtxs; i++) + if (where[i] != mype) + perm[dptr++] = i; + else + perm[ndirty++] = i; + + ASSERT(ctrl, ndirty == nvtxs); + ndirty = dptr; + nclean = nvtxs-dptr; + FastRandomPermute(ndirty, perm, 0); + FastRandomPermute(nclean, perm+ndirty, 0); +*/ + + /* check to see if the partitioning is imbalanced */ + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + ubavg = savg(ncon, ubvec); + lbavg = savg(ncon, lbvec); + imbalanced = (lbavg > ubavg) ? 1 : 0; + + for (c=0; c<2; c++) { + nmoved = 0; + + /**********************************************/ + /* PASS ONE -- record stats for desired moves */ + /**********************************************/ + for (iii=0; iii<nvtxs; iii++) { + i = perm[iii]; + from = tmp_where[i]; + nvwgt = graph->nvwgt+i*ncon; + + for (h=0; h<ncon; h++) + if (fabs(nvwgt[h]-gnpwgts[from*ncon+h]) < SMALLFLOAT) + break; + + if (h < ncon) { + continue; + } + + /* check for a potential improvement */ + if (tmp_rinfo[i].ed >= tmp_rinfo[i].id) { + my_edegrees = tmp_rinfo[i].degrees; + + for (k=0; k<tmp_rinfo[i].ndegrees; k++) { + to = my_edegrees[k].edge; + if (ProperSide(c, pperm[from], pperm[to]) && + IsHBalanceBetterFT(ncon, gnpwgts+from*ncon, gnpwgts+to*ncon, nvwgt, ubvec)) { + break; + } + } + oldto = to; + + /* check if a subdomain was found that fits */ + if (k < tmp_rinfo[i].ndegrees) { + for (j=k+1; j<tmp_rinfo[i].ndegrees; j++) { + to = my_edegrees[j].edge; + if (ProperSide(c, pperm[from], pperm[to]) && + IsHBalanceBetterTT(ncon, gnpwgts+oldto*ncon, gnpwgts+to*ncon, nvwgt, ubvec)){ + k = j; + oldto = my_edegrees[k].edge; + } + } + to = oldto; + + if (iii % npes == 0) { + /****************************************/ + /* Update tmp arrays of the moved vertex */ + /****************************************/ + tmp_where[i] = to; + moved[nmoved++] = i; + for (h=0; h<ncon; h++) { + lnpwgts[to*ncon+h] += nvwgt[h]; + lnpwgts[from*ncon+h] -= nvwgt[h]; + gnpwgts[to*ncon+h] += nvwgt[h]; + gnpwgts[from*ncon+h] -= nvwgt[h]; + } + + tmp_rinfo[i].ed += tmp_rinfo[i].id-my_edegrees[k].ewgt; + SWAP(tmp_rinfo[i].id, my_edegrees[k].ewgt, j); + if (my_edegrees[k].ewgt == 0) { + tmp_rinfo[i].ndegrees--; + my_edegrees[k].edge = my_edegrees[tmp_rinfo[i].ndegrees].edge; + my_edegrees[k].ewgt = my_edegrees[tmp_rinfo[i].ndegrees].ewgt; + } + else { + my_edegrees[k].edge = from; + } + + /* Update the degrees of adjacent vertices */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + /* no need to bother about vertices on different pe's */ + if (ladjncy[j] >= nvtxs) + continue; + + me = ladjncy[j]; + mydomain = tmp_where[me]; + + myrinfo = tmp_rinfo+me; + your_edegrees = myrinfo->degrees; + + if (mydomain == from) { + INC_DEC(myrinfo->ed, myrinfo->id, adjwgt[j]); + } + else { + if (mydomain == to) { + INC_DEC(myrinfo->id, myrinfo->ed, adjwgt[j]); + } + } + + /* Remove contribution from the .ed of 'from' */ + if (mydomain != from) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (your_edegrees[k].edge == from) { + if (your_edegrees[k].ewgt == adjwgt[j]) { + myrinfo->ndegrees--; + your_edegrees[k].edge = your_edegrees[myrinfo->ndegrees].edge; + your_edegrees[k].ewgt = your_edegrees[myrinfo->ndegrees].ewgt; + } + else { + your_edegrees[k].ewgt -= adjwgt[j]; + } + break; + } + } + } + + /* Add contribution to the .ed of 'to' */ + if (mydomain != to) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (your_edegrees[k].edge == to) { + your_edegrees[k].ewgt += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + your_edegrees[myrinfo->ndegrees].edge = to; + your_edegrees[myrinfo->ndegrees++].ewgt = adjwgt[j]; + } + } + } + } + } + } + } + + /*************************************************/ + /* PASS TWO -- commit the remainder of the moves */ + /*************************************************/ + nlupd = nsupd = nmoves = nchanged = 0; + for (iii=0; iii<nmoved; iii++) { + i = moved[iii]; + if (i == -1) + continue; + + where[i] = tmp_where[i]; + + /* Make sure to update the vertex information */ + if (htable[i] == 0) { + /* make sure you do the update */ + htable[i] = 1; + update[nlupd++] = i; + } + + /* Put the vertices adjacent to i into the update array */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = ladjncy[j]; + if (htable[k] == 0) { + htable[k] = 1; + if (k<nvtxs) + update[nlupd++] = k; + else + supdate[nsupd++] = k; + } + } + nmoves++; + nswaps++; + + /* check number of zero-gain moves */ + for (k=0; k<rinfo[i].ndegrees; k++) + if (rinfo[i].degrees[k].edge == to) + break; + + if (graph->pexadj[i+1]-graph->pexadj[i] > 0) + changed[nchanged++] = i; + } + + /* Tell interested pe's the new where[] info for the interface vertices */ + CommChangedInterfaceData(ctrl, graph, nchanged, changed, where, + swchanges, rwchanges, wspace->pv4); + + + IFSET(ctrl->dbglvl, DBG_RMOVEINFO, + rprintf(ctrl, "\t[%d %d], [%.4f], [%d %d %d]\n", + pass, c, badmaxpwgt[0], + GlobalSESum(ctrl, nmoves), + GlobalSESum(ctrl, nsupd), + GlobalSESum(ctrl, nlupd))); + + /*------------------------------------------------------------- + / Time to communicate with processors to send the vertices + / whose degrees need to be update. + /-------------------------------------------------------------*/ + /* Issue the receives first */ + for (i=0; i<nnbrs; i++) { + MPI_Irecv((void *)(rupdate+sendptr[i]), sendptr[i+1]-sendptr[i], IDX_DATATYPE, + peind[i], 1, ctrl->comm, ctrl->rreq+i); + } + + /* Issue the sends next. This needs some preporcessing */ + for (i=0; i<nsupd; i++) { + htable[supdate[i]] = 0; + supdate[i] = graph->imap[supdate[i]]; + } + iidxsort(nsupd, supdate); + + for (j=i=0; i<nnbrs; i++) { + yourlastvtx = vtxdist[peind[i]+1]; + for (k=j; k<nsupd && supdate[k] < yourlastvtx; k++); + MPI_Isend((void *)(supdate+j), k-j, IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->sreq+i); + j = k; + } + + /* OK, now get into the loop waiting for the send/recv operations to finish */ + MPI_Waitall(nnbrs, ctrl->rreq, ctrl->statuses); + for (i=0; i<nnbrs; i++) + MPI_Get_count(ctrl->statuses+i, IDX_DATATYPE, nupds_pe+i); + MPI_Waitall(nnbrs, ctrl->sreq, ctrl->statuses); + + + /*------------------------------------------------------------- + / Place the recieved to-be updated vertices into update[] + /-------------------------------------------------------------*/ + for (i=0; i<nnbrs; i++) { + pe_updates = rupdate+sendptr[i]; + for (j=0; j<nupds_pe[i]; j++) { + k = pe_updates[j]; + if (htable[k-firstvtx] == 0) { + htable[k-firstvtx] = 1; + update[nlupd++] = k-firstvtx; + } + } + } + + + /*------------------------------------------------------------- + / Update the rinfo of the vertices in the update[] array + /-------------------------------------------------------------*/ + for (ii=0; ii<nlupd; ii++) { + i = update[ii]; + ASSERT(ctrl, htable[i] == 1); + + htable[i] = 0; + + mydomain = where[i]; + myrinfo = rinfo+i; + tmp_myrinfo = tmp_rinfo+i; + my_edegrees = myrinfo->degrees; + your_edegrees = tmp_myrinfo->degrees; + + graph->lmincut -= myrinfo->ed; + myrinfo->ndegrees = 0; + myrinfo->id = 0; + myrinfo->ed = 0; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + yourdomain = where[ladjncy[j]]; + if (mydomain != yourdomain) { + myrinfo->ed += adjwgt[j]; + + for (k=0; k<myrinfo->ndegrees; k++) { + if (my_edegrees[k].edge == yourdomain) { + my_edegrees[k].ewgt += adjwgt[j]; + your_edegrees[k].ewgt += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + my_edegrees[k].edge = yourdomain; + my_edegrees[k].ewgt = adjwgt[j]; + your_edegrees[k].edge = yourdomain; + your_edegrees[k].ewgt = adjwgt[j]; + myrinfo->ndegrees++; + } + ASSERT(ctrl, myrinfo->ndegrees <= xadj[i+1]-xadj[i]); + ASSERT(ctrl, tmp_myrinfo->ndegrees <= xadj[i+1]-xadj[i]); + + } + else { + myrinfo->id += adjwgt[j]; + } + } + graph->lmincut += myrinfo->ed; + + tmp_myrinfo->id = myrinfo->id; + tmp_myrinfo->ed = myrinfo->ed; + tmp_myrinfo->ndegrees = myrinfo->ndegrees; + } + + /* finally, sum-up the partition weights */ + MPI_Allreduce((void *)lnpwgts, (void *)gnpwgts, nparts*ncon, + MPI_FLOAT, MPI_SUM, ctrl->comm); + } + graph->mincut = GlobalSESum(ctrl, graph->lmincut)/2; + + if (graph->mincut == oldcut) + break; + } + +/* + gnswaps = GlobalSESum(ctrl, nswaps); + if (mype == 0) + printf("niters: %d, nswaps: %d\n", pass+1, gnswaps); +*/ + + GKfree((void **)&badmaxpwgt, (void **)&update, (void **)&nupds_pe, (void **)&htable, LTERM); + GKfree((void **)&changed, (void **)&pperm, (void **)&perm, (void **)&moved, LTERM); + GKfree((void **)&tmp_where, (void **)&tmp_rinfo, (void **)&tmp_edegrees, LTERM); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->KWayTmr)); +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/kwayfm.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/kwayfm.c new file mode 100644 index 0000000..4d0849b --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/kwayfm.c @@ -0,0 +1,599 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mkwayfm.c + * + * This file contains code that performs the k-way refinement + * + * Started 3/1/96 + * George + * + * $Id: kwayfm.c,v 1.3 2003/07/22 20:29:05 karypis Exp $ + */ + +#include <parmetislib.h> + +#define ProperSide(c, from, other) \ + (((c) == 0 && (from)-(other) < 0) || ((c) == 1 && (from)-(other) > 0)) + +/************************************************************************* +* This function performs k-way refinement +**************************************************************************/ +void Moc_KWayFM(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace, int npasses) +{ + int h, i, ii, iii, j, k, c; + int pass, nvtxs, nedges, ncon; + int nmoves, nmoved, nswaps, nzgswaps; +/* int gnswaps, gnzgswaps; */ + int me, firstvtx, lastvtx, yourlastvtx; + int from, to = -1, oldto, oldcut, mydomain, yourdomain, imbalanced, overweight; + int npes = ctrl->npes, mype = ctrl->mype, nparts = ctrl->nparts; + int nlupd, nsupd, nnbrs, nchanged; + idxtype *xadj, *ladjncy, *adjwgt, *vtxdist; + idxtype *where, *tmp_where, *moved; + float *lnpwgts, *gnpwgts, *ognpwgts, *pgnpwgts, *movewgts, *overfill; + idxtype *update, *supdate, *rupdate, *pe_updates; + idxtype *changed, *perm, *pperm, *htable; + idxtype *peind, *recvptr, *sendptr; + KeyValueType *swchanges, *rwchanges; + RInfoType *rinfo, *myrinfo, *tmp_myrinfo, *tmp_rinfo; + EdgeType *tmp_edegrees, *my_edegrees, *your_edegrees; + float lbvec[MAXNCON], *nvwgt, *badmaxpwgt, *ubvec, *tpwgts, lbavg, ubavg; + int *nupds_pe; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->KWayTmr)); + + /*************************/ + /* set up common aliases */ + /*************************/ + nvtxs = graph->nvtxs; + nedges = graph->nedges; + ncon = graph->ncon; + + vtxdist = graph->vtxdist; + xadj = graph->xadj; + ladjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + firstvtx = vtxdist[mype]; + lastvtx = vtxdist[mype+1]; + + where = graph->where; + rinfo = graph->rinfo; + lnpwgts = graph->lnpwgts; + gnpwgts = graph->gnpwgts; + ubvec = ctrl->ubvec; + tpwgts = ctrl->tpwgts; + + nnbrs = graph->nnbrs; + peind = graph->peind; + recvptr = graph->recvptr; + sendptr = graph->sendptr; + + changed = idxmalloc(nvtxs, "KWR: changed"); + rwchanges = wspace->pairs; + swchanges = rwchanges + recvptr[nnbrs]; + + /************************************/ + /* set up important data structures */ + /************************************/ + perm = idxmalloc(nvtxs, "KWR: perm"); + pperm = idxmalloc(nparts, "KWR: pperm"); + + update = idxmalloc(nvtxs, "KWR: update"); + supdate = wspace->indices; + rupdate = supdate + recvptr[nnbrs]; + nupds_pe = imalloc(npes, "KWR: nupds_pe"); + htable = idxsmalloc(nvtxs+graph->nrecv, 0, "KWR: lhtable"); + badmaxpwgt = fmalloc(nparts*ncon, "badmaxpwgt"); + + for (i=0; i<nparts; i++) { + for (h=0; h<ncon; h++) { + badmaxpwgt[i*ncon+h] = ubvec[h]*tpwgts[i*ncon+h]; + } + } + + movewgts = fmalloc(nparts*ncon, "KWR: movewgts"); + ognpwgts = fmalloc(nparts*ncon, "KWR: ognpwgts"); + pgnpwgts = fmalloc(nparts*ncon, "KWR: pgnpwgts"); + overfill = fmalloc(nparts*ncon, "KWR: overfill"); + moved = idxmalloc(nvtxs, "KWR: moved"); + tmp_where = idxmalloc(nvtxs+graph->nrecv, "KWR: tmp_where"); + tmp_rinfo = (RInfoType *)GKmalloc(sizeof(RInfoType)*nvtxs, "KWR: tmp_rinfo"); + tmp_edegrees = (EdgeType *)GKmalloc(sizeof(EdgeType)*nedges, "KWR: tmp_edegrees"); + + idxcopy(nvtxs+graph->nrecv, where, tmp_where); + for (i=0; i<nvtxs; i++) { + tmp_rinfo[i].id = rinfo[i].id; + tmp_rinfo[i].ed = rinfo[i].ed; + tmp_rinfo[i].ndegrees = rinfo[i].ndegrees; + tmp_rinfo[i].degrees = tmp_edegrees+xadj[i]; + + for (j=0; j<rinfo[i].ndegrees; j++) { + tmp_rinfo[i].degrees[j].edge = rinfo[i].degrees[j].edge; + tmp_rinfo[i].degrees[j].ewgt = rinfo[i].degrees[j].ewgt; + } + } + + nswaps = nzgswaps = 0; + /*********************************************************/ + /* perform a small number of passes through the vertices */ + /*********************************************************/ + for (pass=0; pass<npasses; pass++) { + if (mype == 0) + RandomPermute(nparts, pperm, 1); + MPI_Bcast((void *)pperm, nparts, IDX_DATATYPE, 0, ctrl->comm); + FastRandomPermute(nvtxs, perm, 1); + oldcut = graph->mincut; + + /* check to see if the partitioning is imbalanced */ + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + ubavg = savg(ncon, ubvec); + lbavg = savg(ncon, lbvec); + imbalanced = (lbavg > ubavg) ? 1 : 0; + + for (c=0; c<2; c++) { + scopy(ncon*nparts, gnpwgts, ognpwgts); + sset(ncon*nparts, 0.0, movewgts); + nmoved = 0; + + /**********************************************/ + /* PASS ONE -- record stats for desired moves */ + /**********************************************/ + for (iii=0; iii<nvtxs; iii++) { + i = perm[iii]; + from = tmp_where[i]; + nvwgt = graph->nvwgt+i*ncon; + + for (h=0; h<ncon; h++) + if (fabs(nvwgt[h]-gnpwgts[from*ncon+h]) < SMALLFLOAT) + break; + + if (h < ncon) { + continue; + } + + /* check for a potential improvement */ + if (tmp_rinfo[i].ed >= tmp_rinfo[i].id) { + my_edegrees = tmp_rinfo[i].degrees; + + for (k=0; k<tmp_rinfo[i].ndegrees; k++) { + to = my_edegrees[k].edge; + if (ProperSide(c, pperm[from], pperm[to])) { + for (h=0; h<ncon; h++) + if (gnpwgts[to*ncon+h]+nvwgt[h] > badmaxpwgt[to*ncon+h] && nvwgt[h] > 0.0) + break; + + if (h == ncon) + break; + } + } + oldto = to; + + /* check if a subdomain was found that fits */ + if (k < tmp_rinfo[i].ndegrees) { + for (j=k+1; j<tmp_rinfo[i].ndegrees; j++) { + to = my_edegrees[j].edge; + if (ProperSide(c, pperm[from], pperm[to])) { + for (h=0; h<ncon; h++) + if (gnpwgts[to*ncon+h]+nvwgt[h] > badmaxpwgt[to*ncon+h] && nvwgt[h] > 0.0) + break; + + if (h == ncon) { + if (my_edegrees[j].ewgt > my_edegrees[k].ewgt || + (my_edegrees[j].ewgt == my_edegrees[k].ewgt && + IsHBalanceBetterTT(ncon,gnpwgts+oldto*ncon,gnpwgts+to*ncon,nvwgt,ubvec))){ + k = j; + oldto = my_edegrees[k].edge; + } + } + } + } + to = oldto; + + if (my_edegrees[k].ewgt > tmp_rinfo[i].id || + (my_edegrees[k].ewgt == tmp_rinfo[i].id && + (imbalanced || graph->level > 3 || iii % 8 == 0) && + IsHBalanceBetterFT(ncon,gnpwgts+from*ncon,gnpwgts+to*ncon,nvwgt,ubvec))){ + + /****************************************/ + /* Update tmp arrays of the moved vertex */ + /****************************************/ + tmp_where[i] = to; + moved[nmoved++] = i; + for (h=0; h<ncon; h++) { + lnpwgts[to*ncon+h] += nvwgt[h]; + lnpwgts[from*ncon+h] -= nvwgt[h]; + gnpwgts[to*ncon+h] += nvwgt[h]; + gnpwgts[from*ncon+h] -= nvwgt[h]; + movewgts[to*ncon+h] += nvwgt[h]; + movewgts[from*ncon+h] -= nvwgt[h]; + } + + tmp_rinfo[i].ed += tmp_rinfo[i].id-my_edegrees[k].ewgt; + SWAP(tmp_rinfo[i].id, my_edegrees[k].ewgt, j); + if (my_edegrees[k].ewgt == 0) { + tmp_rinfo[i].ndegrees--; + my_edegrees[k].edge = my_edegrees[tmp_rinfo[i].ndegrees].edge; + my_edegrees[k].ewgt = my_edegrees[tmp_rinfo[i].ndegrees].ewgt; + } + else { + my_edegrees[k].edge = from; + } + + /* Update the degrees of adjacent vertices */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + /* no need to bother about vertices on different pe's */ + if (ladjncy[j] >= nvtxs) + continue; + + me = ladjncy[j]; + mydomain = tmp_where[me]; + + myrinfo = tmp_rinfo+me; + your_edegrees = myrinfo->degrees; + + if (mydomain == from) { + INC_DEC(myrinfo->ed, myrinfo->id, adjwgt[j]); + } + else { + if (mydomain == to) { + INC_DEC(myrinfo->id, myrinfo->ed, adjwgt[j]); + } + } + + /* Remove contribution from the .ed of 'from' */ + if (mydomain != from) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (your_edegrees[k].edge == from) { + if (your_edegrees[k].ewgt == adjwgt[j]) { + myrinfo->ndegrees--; + your_edegrees[k].edge = your_edegrees[myrinfo->ndegrees].edge; + your_edegrees[k].ewgt = your_edegrees[myrinfo->ndegrees].ewgt; + } + else { + your_edegrees[k].ewgt -= adjwgt[j]; + } + break; + } + } + } + + /* Add contribution to the .ed of 'to' */ + if (mydomain != to) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (your_edegrees[k].edge == to) { + your_edegrees[k].ewgt += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + your_edegrees[myrinfo->ndegrees].edge = to; + your_edegrees[myrinfo->ndegrees++].ewgt = adjwgt[j]; + } + } + } + } + } + } + } + + /******************************************/ + /* Let processors know the subdomain wgts */ + /* if all proposed moves commit. */ + /******************************************/ + MPI_Allreduce((void *)lnpwgts, (void *)pgnpwgts, nparts*ncon, + MPI_FLOAT, MPI_SUM, ctrl->comm); + + /**************************/ + /* compute overfill array */ + /**************************/ + overweight = 0; + for (j=0; j<nparts; j++) { + for (h=0; h<ncon; h++) { + if (pgnpwgts[j*ncon+h] > ognpwgts[j*ncon+h]) { + overfill[j*ncon+h] = + (pgnpwgts[j*ncon+h]-badmaxpwgt[j*ncon+h]) / + (pgnpwgts[j*ncon+h]-ognpwgts[j*ncon+h]); + } + else { + overfill[j*ncon+h] = 0.0; + } + + overfill[j*ncon+h] = amax(overfill[j*ncon+h], 0.0); + overfill[j*ncon+h] *= movewgts[j*ncon+h]; + + if (overfill[j*ncon+h] > 0.0) + overweight = 1; + + ASSERTP(ctrl, ognpwgts[j*ncon+h] <= badmaxpwgt[j*ncon+h] || + pgnpwgts[j*ncon+h] <= ognpwgts[j*ncon+h], + (ctrl, "%.4f %.4f %.4f\n", ognpwgts[j*ncon+h], + badmaxpwgt[j*ncon+h], pgnpwgts[j*ncon+h])); + } + } + + /****************************************************/ + /* select moves to undo according to overfill array */ + /****************************************************/ + if (overweight == 1) { + for (iii=0; iii<nmoved; iii++) { + i = moved[iii]; + oldto = tmp_where[i]; + nvwgt = graph->nvwgt+i*ncon; + my_edegrees = tmp_rinfo[i].degrees; + + for (k=0; k<tmp_rinfo[i].ndegrees; k++) + if (my_edegrees[k].edge == where[i]) + break; + + for (h=0; h<ncon; h++) + if (nvwgt[h] > 0.0 && overfill[oldto*ncon+h] > nvwgt[h]/4.0) + break; + + /**********************************/ + /* nullify this move if necessary */ + /**********************************/ + if (k != tmp_rinfo[i].ndegrees && h != ncon) { + moved[iii] = -1; + from = oldto; + to = where[i]; + + for (h=0; h<ncon; h++) { + overfill[oldto*ncon+h] = amax(overfill[oldto*ncon+h]-nvwgt[h], 0.0); + } + + tmp_where[i] = to; + tmp_rinfo[i].ed += tmp_rinfo[i].id-my_edegrees[k].ewgt; + SWAP(tmp_rinfo[i].id, my_edegrees[k].ewgt, j); + if (my_edegrees[k].ewgt == 0) { + tmp_rinfo[i].ndegrees--; + my_edegrees[k].edge = my_edegrees[tmp_rinfo[i].ndegrees].edge; + my_edegrees[k].ewgt = my_edegrees[tmp_rinfo[i].ndegrees].ewgt; + } + else { + my_edegrees[k].edge = from; + } + + for (h=0; h<ncon; h++) { + lnpwgts[to*ncon+h] += nvwgt[h]; + lnpwgts[from*ncon+h] -= nvwgt[h]; + } + + /* Update the degrees of adjacent vertices */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + /* no need to bother about vertices on different pe's */ + if (ladjncy[j] >= nvtxs) + continue; + + me = ladjncy[j]; + mydomain = tmp_where[me]; + + myrinfo = tmp_rinfo+me; + your_edegrees = myrinfo->degrees; + + if (mydomain == from) { + INC_DEC(myrinfo->ed, myrinfo->id, adjwgt[j]); + } + else { + if (mydomain == to) { + INC_DEC(myrinfo->id, myrinfo->ed, adjwgt[j]); + } + } + + /* Remove contribution from the .ed of 'from' */ + if (mydomain != from) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (your_edegrees[k].edge == from) { + if (your_edegrees[k].ewgt == adjwgt[j]) { + myrinfo->ndegrees--; + your_edegrees[k].edge = your_edegrees[myrinfo->ndegrees].edge; + your_edegrees[k].ewgt = your_edegrees[myrinfo->ndegrees].ewgt; + } + else { + your_edegrees[k].ewgt -= adjwgt[j]; + } + break; + } + } + } + + /* Add contribution to the .ed of 'to' */ + if (mydomain != to) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (your_edegrees[k].edge == to) { + your_edegrees[k].ewgt += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + your_edegrees[myrinfo->ndegrees].edge = to; + your_edegrees[myrinfo->ndegrees++].ewgt = adjwgt[j]; + } + } + } + } + } + } + + /*************************************************/ + /* PASS TWO -- commit the remainder of the moves */ + /*************************************************/ + nlupd = nsupd = nmoves = nchanged = 0; + for (iii=0; iii<nmoved; iii++) { + i = moved[iii]; + if (i == -1) + continue; + + where[i] = tmp_where[i]; + + /* Make sure to update the vertex information */ + if (htable[i] == 0) { + /* make sure you do the update */ + htable[i] = 1; + update[nlupd++] = i; + } + + /* Put the vertices adjacent to i into the update array */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = ladjncy[j]; + if (htable[k] == 0) { + htable[k] = 1; + if (k<nvtxs) + update[nlupd++] = k; + else + supdate[nsupd++] = k; + } + } + nmoves++; + nswaps++; + + /* check number of zero-gain moves */ + for (k=0; k<rinfo[i].ndegrees; k++) + if (rinfo[i].degrees[k].edge == to) + break; + if (rinfo[i].id == rinfo[i].degrees[k].ewgt) + nzgswaps++; + + if (graph->pexadj[i+1]-graph->pexadj[i] > 0) + changed[nchanged++] = i; + } + + /* Tell interested pe's the new where[] info for the interface vertices */ + CommChangedInterfaceData(ctrl, graph, nchanged, changed, where, + swchanges, rwchanges, wspace->pv4); + + + IFSET(ctrl->dbglvl, DBG_RMOVEINFO, + rprintf(ctrl, "\t[%d %d], [%.4f], [%d %d %d]\n", + pass, c, badmaxpwgt[0], + GlobalSESum(ctrl, nmoves), + GlobalSESum(ctrl, nsupd), + GlobalSESum(ctrl, nlupd))); + + /*------------------------------------------------------------- + / Time to communicate with processors to send the vertices + / whose degrees need to be update. + /-------------------------------------------------------------*/ + /* Issue the receives first */ + for (i=0; i<nnbrs; i++) { + MPI_Irecv((void *)(rupdate+sendptr[i]), sendptr[i+1]-sendptr[i], IDX_DATATYPE, + peind[i], 1, ctrl->comm, ctrl->rreq+i); + } + + /* Issue the sends next. This needs some preporcessing */ + for (i=0; i<nsupd; i++) { + htable[supdate[i]] = 0; + supdate[i] = graph->imap[supdate[i]]; + } + iidxsort(nsupd, supdate); + + for (j=i=0; i<nnbrs; i++) { + yourlastvtx = vtxdist[peind[i]+1]; + for (k=j; k<nsupd && supdate[k] < yourlastvtx; k++); + MPI_Isend((void *)(supdate+j), k-j, IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->sreq+i); + j = k; + } + + /* OK, now get into the loop waiting for the send/recv operations to finish */ + MPI_Waitall(nnbrs, ctrl->rreq, ctrl->statuses); + for (i=0; i<nnbrs; i++) + MPI_Get_count(ctrl->statuses+i, IDX_DATATYPE, nupds_pe+i); + MPI_Waitall(nnbrs, ctrl->sreq, ctrl->statuses); + + + /*------------------------------------------------------------- + / Place the recieved to-be updated vertices into update[] + /-------------------------------------------------------------*/ + for (i=0; i<nnbrs; i++) { + pe_updates = rupdate+sendptr[i]; + for (j=0; j<nupds_pe[i]; j++) { + k = pe_updates[j]; + if (htable[k-firstvtx] == 0) { + htable[k-firstvtx] = 1; + update[nlupd++] = k-firstvtx; + } + } + } + + + /*------------------------------------------------------------- + / Update the rinfo of the vertices in the update[] array + /-------------------------------------------------------------*/ + for (ii=0; ii<nlupd; ii++) { + i = update[ii]; + ASSERT(ctrl, htable[i] == 1); + + htable[i] = 0; + + mydomain = where[i]; + myrinfo = rinfo+i; + tmp_myrinfo = tmp_rinfo+i; + my_edegrees = myrinfo->degrees; + your_edegrees = tmp_myrinfo->degrees; + + graph->lmincut -= myrinfo->ed; + myrinfo->ndegrees = 0; + myrinfo->id = 0; + myrinfo->ed = 0; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + yourdomain = where[ladjncy[j]]; + if (mydomain != yourdomain) { + myrinfo->ed += adjwgt[j]; + + for (k=0; k<myrinfo->ndegrees; k++) { + if (my_edegrees[k].edge == yourdomain) { + my_edegrees[k].ewgt += adjwgt[j]; + your_edegrees[k].ewgt += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + my_edegrees[k].edge = yourdomain; + my_edegrees[k].ewgt = adjwgt[j]; + your_edegrees[k].edge = yourdomain; + your_edegrees[k].ewgt = adjwgt[j]; + myrinfo->ndegrees++; + } + ASSERT(ctrl, myrinfo->ndegrees <= xadj[i+1]-xadj[i]); + ASSERT(ctrl, tmp_myrinfo->ndegrees <= xadj[i+1]-xadj[i]); + + } + else { + myrinfo->id += adjwgt[j]; + } + } + graph->lmincut += myrinfo->ed; + + tmp_myrinfo->id = myrinfo->id; + tmp_myrinfo->ed = myrinfo->ed; + tmp_myrinfo->ndegrees = myrinfo->ndegrees; + } + + /* finally, sum-up the partition weights */ + MPI_Allreduce((void *)lnpwgts, (void *)gnpwgts, nparts*ncon, + MPI_FLOAT, MPI_SUM, ctrl->comm); + } + graph->mincut = GlobalSESum(ctrl, graph->lmincut)/2; + + if (graph->mincut == oldcut) + break; + } + +/* + gnswaps = GlobalSESum(ctrl, nswaps); + gnzgswaps = GlobalSESum(ctrl, nzgswaps); + if (mype == 0) + printf("niters: %d, nswaps: %d, nzgswaps: %d\n", pass+1, gnswaps, gnzgswaps); +*/ + + GKfree((void **)&badmaxpwgt, (void **)&update, (void **)&nupds_pe, (void **)&htable, LTERM); + GKfree((void **)&changed, (void **)&pperm, (void **)&perm, (void **)&moved, LTERM); + GKfree((void **)&pgnpwgts, (void **)&ognpwgts, (void **)&overfill, (void **)&movewgts, LTERM); + GKfree((void **)&tmp_where, (void **)&tmp_rinfo, (void **)&tmp_edegrees, LTERM); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->KWayTmr)); +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/kwayrefine.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/kwayrefine.c new file mode 100644 index 0000000..e4b776e --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/kwayrefine.c @@ -0,0 +1,239 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * medge_refine.c + * + * This file contains code that performs the k-way refinement + * + * Started 3/1/96 + * George + * + * $Id: kwayrefine.c,v 1.2 2003/07/21 17:18:49 karypis Exp $ + */ + +#include <parmetislib.h> + +#define ProperSide(c, from, other) \ + (((c) == 0 && (from)-(other) < 0) || ((c) == 1 && (from)-(other) > 0)) + +/************************************************************************* +* This function projects a partition. +**************************************************************************/ +void Moc_ProjectPartition(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int i, nvtxs, nnbrs = -1, firstvtx, cfirstvtx; + idxtype *match, *cmap, *where, *cwhere; + idxtype *peind, *slens = NULL, *rlens = NULL; + KeyValueType *rcand, *scand = NULL; + GraphType *cgraph; + + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ProjectTmr)); + + cgraph = graph->coarser; + cwhere = cgraph->where; + cfirstvtx = cgraph->vtxdist[ctrl->mype]; + + nvtxs = graph->nvtxs; + match = graph->match; + cmap = graph->cmap; + where = graph->where = idxmalloc(nvtxs+graph->nrecv, "ProjectPartition: graph->where"); + firstvtx = graph->vtxdist[ctrl->mype]; + + + if (graph->match_type == MATCH_GLOBAL) { /* Only if global matching is on */ + /*------------------------------------------------------------ + / Start the transmission of the remote where information + /------------------------------------------------------------*/ + scand = wspace->pairs; + nnbrs = graph->nnbrs; + peind = graph->peind; + slens = graph->slens; + rlens = graph->rlens; + rcand = graph->rcand; + + /* Issue the receives first */ + for (i=0; i<nnbrs; i++) { + if (slens[i+1]-slens[i] > 0) /* Issue a receive only if you are getting something */ + MPI_Irecv((void *)(scand+slens[i]), 2*(slens[i+1]-slens[i]), IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->rreq+i); + } + +#ifdef DEBUG_PROJECT + PrintPairs(ctrl, rlens[nnbrs], rcand, "rcand"); +#endif + + /* Put the where[rcand[].key] into the val field */ + for (i=0; i<rlens[nnbrs]; i++) { + ASSERT(ctrl, rcand[i].val >= 0 && rcand[i].val < cgraph->nvtxs); + rcand[i].val = cwhere[rcand[i].val]; + } + +#ifdef DEBUG_PROJECT + PrintPairs(ctrl, rlens[nnbrs], rcand, "rcand"); + PrintVector(ctrl, nvtxs, firstvtx, cmap, "cmap"); +#endif + + /* Issue the sends next */ + for (i=0; i<nnbrs; i++) { + if (rlens[i+1]-rlens[i] > 0) /* Issue a send only if you are sending something */ + MPI_Isend((void *)(rcand+rlens[i]), 2*(rlens[i+1]-rlens[i]), IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->sreq+i); + } + } + + /*------------------------------------------------------------ + / Project local vertices first + /------------------------------------------------------------*/ + for (i=0; i<nvtxs; i++) { + if (match[i] >= KEEP_BIT) { + ASSERT(ctrl, cmap[i]-cfirstvtx>=0 && cmap[i]-cfirstvtx<cgraph->nvtxs); + where[i] = cwhere[cmap[i]-cfirstvtx]; + } + } + + if (graph->match_type == MATCH_GLOBAL) { /* Only if global matching is on */ + /*------------------------------------------------------------ + / Wait for the nonblocking operations to finish + /------------------------------------------------------------*/ + for (i=0; i<nnbrs; i++) { + if (rlens[i+1]-rlens[i] > 0) + MPI_Wait(ctrl->sreq+i, &ctrl->status); + } + for (i=0; i<nnbrs; i++) { + if (slens[i+1]-slens[i] > 0) + MPI_Wait(ctrl->rreq+i, &ctrl->status); + } + +#ifdef DEBUG_PROJECT + PrintPairs(ctrl, slens[nnbrs], scand, "scand"); +#endif + + /*------------------------------------------------------------ + / Project received vertices now + /------------------------------------------------------------*/ + for (i=0; i<slens[nnbrs]; i++) { + ASSERTP(ctrl, scand[i].key-firstvtx>=0 && scand[i].key-firstvtx<graph->nvtxs, (ctrl, "%d %d %d\n", scand[i].key, firstvtx, graph->nvtxs)); + where[scand[i].key-firstvtx] = scand[i].val; + } + } + + + FreeGraph(graph->coarser); + graph->coarser = NULL; + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ProjectTmr)); +} + + + +/************************************************************************* +* This function computes the initial id/ed +**************************************************************************/ +void Moc_ComputePartitionParams(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int h, i, j, k; + int nvtxs, ncon; + int firstvtx, lastvtx; + idxtype *xadj, *ladjncy, *adjwgt, *vtxdist; + float *lnpwgts, *gnpwgts; + idxtype *where, *swhere, *rwhere; + RInfoType *rinfo, *myrinfo; + EdgeType *edegrees; + int me, other; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->KWayInitTmr)); + + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + + vtxdist = graph->vtxdist; + xadj = graph->xadj; + ladjncy = graph->adjncy; + adjwgt = graph->adjwgt; + + where = graph->where; + rinfo = graph->rinfo = (RInfoType *)GKmalloc(sizeof(RInfoType)*nvtxs, "CPP: rinfo"); + lnpwgts = graph->lnpwgts = fmalloc(ctrl->nparts*ncon, "CPP: lnpwgts"); + gnpwgts = graph->gnpwgts = fmalloc(ctrl->nparts*ncon, "CPP: gnpwgts"); + + sset(ctrl->nparts*ncon, 0, lnpwgts); + + firstvtx = vtxdist[ctrl->mype]; + lastvtx = vtxdist[ctrl->mype+1]; + + /*------------------------------------------------------------ + / Send/Receive the where information of interface vertices + /------------------------------------------------------------*/ + swhere = wspace->indices; + rwhere = where + nvtxs; + + CommInterfaceData(ctrl, graph, where, swhere, rwhere); + +#ifdef DEBUG_COMPUTEPPARAM + PrintVector(ctrl, nvtxs, firstvtx, where, "where"); +#endif + + ASSERT(ctrl, wspace->nlarge >= xadj[nvtxs]); + + /*------------------------------------------------------------ + / Compute now the id/ed degrees + /------------------------------------------------------------*/ + graph->lmincut = 0; + for (i=0; i<nvtxs; i++) { + me = where[i]; + myrinfo = rinfo+i; + + for (h=0; h<ncon; h++) + lnpwgts[me*ncon+h] += graph->nvwgt[i*ncon+h]; + + myrinfo->degrees = wspace->degrees + xadj[i]; + myrinfo->ndegrees = myrinfo->id = myrinfo->ed = 0; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (me == where[ladjncy[j]]) + myrinfo->id += adjwgt[j]; + else + myrinfo->ed += adjwgt[j]; + } + + + if (myrinfo->ed > 0) { /* Time to do some serious work */ + graph->lmincut += myrinfo->ed; + edegrees = myrinfo->degrees; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + other = where[ladjncy[j]]; + if (me != other) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (edegrees[k].edge == other) { + edegrees[k].ewgt += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + edegrees[k].edge = other; + edegrees[k].ewgt = adjwgt[j]; + myrinfo->ndegrees++; + } + ASSERT(ctrl, myrinfo->ndegrees <= xadj[i+1]-xadj[i]); + } + } + } + } + +#ifdef DEBUG_COMPUTEPPARAM + PrintVector(ctrl, ctrl->nparts*ncon, 0, lnpwgts, "lnpwgts"); +#endif + + /* Finally, sum-up the partition weights */ + MPI_Allreduce((void *)lnpwgts, (void *)gnpwgts, ctrl->nparts*ncon, MPI_FLOAT, MPI_SUM, ctrl->comm); + + graph->mincut = GlobalSESum(ctrl, graph->lmincut)/2; + +#ifdef DEBUG_COMPUTEPPARAM + PrintVector(ctrl, ctrl->nparts*ncon, 0, gnpwgts, "gnpwgts"); +#endif + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->KWayInitTmr)); +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/lmatch.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/lmatch.c new file mode 100644 index 0000000..d8601ef --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/lmatch.c @@ -0,0 +1,364 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * coarsen.c + * + * This file contains code that finds a matching and performs the coarsening + * + * Started 2/22/96 + * George + * + * $Id: lmatch.c,v 1.2 2003/07/21 17:18:50 karypis Exp $ + * + */ + +#include <parmetislib.h> + + +/************************************************************************* +* This function finds a HEM matching between local vertices only +**************************************************************************/ +void Mc_LocalMatch_HEM(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int h, i, ii, j, k; + int nvtxs, ncon, cnvtxs, firstvtx, maxi, maxidx, edge; + idxtype *xadj, *ladjncy, *adjwgt, *vtxdist, *home, *myhome, *shome, *rhome; + idxtype *perm, *match; + float maxnvwgt, *nvwgt; + + graph->match_type = MATCH_LOCAL; + maxnvwgt = 1.0/((float)(ctrl->nparts)*MAXVWGT_FACTOR); + + IFSET(ctrl->dbglvl, DBG_TIME, MPI_Barrier(ctrl->comm)); + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->MatchTmr)); + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + ladjncy = graph->adjncy; + adjwgt = graph->adjwgt; + home = graph->home; + + vtxdist = graph->vtxdist; + firstvtx = vtxdist[ctrl->mype]; + + match = graph->match = idxmalloc(nvtxs+graph->nrecv, "HEM_Match: match"); + myhome = idxsmalloc(nvtxs+graph->nrecv, UNMATCHED, "HEM_Match: myhome"); + + idxset(nvtxs, UNMATCHED, match); + idxset(graph->nrecv, 0, match+nvtxs); /* Easy way to handle remote vertices */ + + /*------------------------------------------------------------ + / Send/Receive the home information of interface vertices + /------------------------------------------------------------*/ + if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) { + idxcopy(nvtxs, home, myhome); + shome = wspace->indices; + rhome = myhome + nvtxs; + CommInterfaceData(ctrl, graph, myhome, shome, rhome); + } + + /************************************************************* + * Go now and find a local matching + *************************************************************/ + perm = wspace->indices; + FastRandomPermute(nvtxs, perm, 1); + cnvtxs = 0; + for (ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + if (match[i] == UNMATCHED) { + maxidx = maxi = -1; + + /* Find a heavy-edge matching, if the weight of the vertex is OK */ + for (h=0; h<ncon; h++) + if (nvwgt[i*ncon+h] > maxnvwgt) + break; + + if (h == ncon) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + edge = ladjncy[j]; + + /* match only with local vertices */ + if (myhome[edge] != myhome[i] || edge >= nvtxs) + continue; + + for (h=0; h<ncon; h++) + if (nvwgt[edge*ncon+h] > maxnvwgt) + break; + + if (h == ncon) { + if (match[edge] == UNMATCHED && + (maxi == -1 || + adjwgt[maxi] < adjwgt[j] || + (adjwgt[maxi] == adjwgt[j] && + BetterVBalance(ncon,nvwgt+i*ncon,nvwgt+maxidx*ncon,nvwgt+edge*ncon) >= 0))) { + maxi = j; + maxidx = edge; + } + } + } + } + + if (maxi != -1) { + k = ladjncy[maxi]; + if (i <= k) { + match[i] = firstvtx+k + KEEP_BIT; + match[k] = firstvtx+i; + } + else { + match[i] = firstvtx+k; + match[k] = firstvtx+i + KEEP_BIT; + } + } + else { + match[i] = (firstvtx+i) + KEEP_BIT; + } + cnvtxs++; + } + } + + CommInterfaceData(ctrl, graph, match, wspace->indices, match+nvtxs); + GKfree((void **)(&myhome), LTERM); + +#ifdef DEBUG_MATCH + PrintVector2(ctrl, nvtxs, firstvtx, match, "Match1"); +#endif + + + if (ctrl->dbglvl&DBG_MATCHINFO) { + PrintVector2(ctrl, nvtxs, firstvtx, match, "Match"); + myprintf(ctrl, "Cnvtxs: %d\n", cnvtxs); + rprintf(ctrl, "Done with matching...\n"); + } + + IFSET(ctrl->dbglvl, DBG_TIME, MPI_Barrier(ctrl->comm)); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->MatchTmr)); + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ContractTmr)); + Mc_Local_CreateCoarseGraph(ctrl, graph, wspace, cnvtxs); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ContractTmr)); + +} + + + + + +/************************************************************************* +* This function creates the coarser graph +**************************************************************************/ +void Mc_Local_CreateCoarseGraph(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace, int cnvtxs) +{ + int h, i, j, k, l; + int nvtxs, ncon, nedges, firstvtx, cfirstvtx; + int npes=ctrl->npes, mype=ctrl->mype; + int cnedges, v, u; + idxtype *xadj, *vwgt, *vsize, *ladjncy, *adjwgt, *vtxdist, *where, *home; + idxtype *match, *cmap; + idxtype *cxadj, *cvwgt, *cvsize = NULL, *cadjncy, *cadjwgt, *cvtxdist, *chome = NULL, *cwhere = NULL; + float *cnvwgt; + GraphType *cgraph; + int mask=(1<<13)-1, htable[8192], htableidx[8192]; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + + vtxdist = graph->vtxdist; + xadj = graph->xadj; + vwgt = graph->vwgt; + home = graph->home; + vsize = graph->vsize; + ladjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + match = graph->match; + + firstvtx = vtxdist[mype]; + + cmap = graph->cmap = idxmalloc(nvtxs+graph->nrecv, "CreateCoarseGraph: cmap"); + + /* Initialize the coarser graph */ + cgraph = CreateGraph(); + cgraph->nvtxs = cnvtxs; + cgraph->level = graph->level+1; + cgraph->ncon = ncon; + + cgraph->finer = graph; + graph->coarser = cgraph; + + + /************************************************************* + * Obtain the vtxdist of the coarser graph + **************************************************************/ + cvtxdist = cgraph->vtxdist = idxmalloc(npes+1, "CreateCoarseGraph: cvtxdist"); + cvtxdist[npes] = cnvtxs; /* Use last position in the cvtxdist as a temp buffer */ + + MPI_Allgather((void *)(cvtxdist+npes), 1, IDX_DATATYPE, (void *)cvtxdist, 1, IDX_DATATYPE, ctrl->comm); + + MAKECSR(i, npes, cvtxdist); + + cgraph->gnvtxs = cvtxdist[npes]; + +#ifdef DEBUG_CONTRACT + PrintVector(ctrl, npes+1, 0, cvtxdist, "cvtxdist"); +#endif + + + /************************************************************* + * Construct the cmap vector + **************************************************************/ + cfirstvtx = cvtxdist[mype]; + + /* Create the cmap of what you know so far locally */ + cnvtxs = 0; + for (i=0; i<nvtxs; i++) { + if (match[i] >= KEEP_BIT) { + k = match[i] - KEEP_BIT; + if (k<firstvtx+i) + continue; /* i has been matched via the (k,i) side */ + + cmap[i] = cfirstvtx + cnvtxs++; + if (k != firstvtx+i) { + cmap[k-firstvtx] = cmap[i]; + match[k-firstvtx] += KEEP_BIT; /* Add the KEEP_BIT to simplify coding */ + } + } + } + + CommInterfaceData(ctrl, graph, cmap, wspace->indices, cmap+nvtxs); + + +#ifdef DEBUG_CONTRACT + PrintVector(ctrl, nvtxs, firstvtx, cmap, "Cmap"); +#endif + + + + /************************************************************* + * Finally, create the coarser graph + **************************************************************/ + /* Allocate memory for the coarser graph, and fire up coarsening */ + cxadj = cgraph->xadj = idxmalloc(cnvtxs+1, "CreateCoarserGraph: cxadj"); + cvwgt = cgraph->vwgt = idxmalloc(cnvtxs*ncon, "CreateCoarserGraph: cvwgt"); + cnvwgt = cgraph->nvwgt = fmalloc(cnvtxs*ncon, "CreateCoarserGraph: cnvwgt"); + if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) + chome = cgraph->home = idxmalloc(cnvtxs, "CreateCoarserGraph: chome"); + if (vsize != NULL) + cvsize = cgraph->vsize = idxmalloc(cnvtxs, "CreateCoarserGraph: cvsize"); + if (where != NULL) + cwhere = cgraph->where = idxmalloc(cnvtxs, "CreateCoarserGraph: cwhere"); + cadjncy = idxmalloc(2*graph->nedges, "CreateCoarserGraph: cadjncy"); + cadjwgt = cadjncy+graph->nedges; + + iset(8192, -1, htable); + + cxadj[0] = cnvtxs = cnedges = 0; + for (i=0; i<nvtxs; i++) { + v = firstvtx+i; + u = match[i]-KEEP_BIT; + + if (v > u) + continue; /* I have already collapsed it as (u,v) */ + + /* Collapse the v vertex first, which you know that is local */ + for (h=0; h<ncon; h++) + cvwgt[cnvtxs*ncon+h] = vwgt[i*ncon+h]; + if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) + chome[cnvtxs] = home[i]; + if (vsize != NULL) + cvsize[cnvtxs] = vsize[i]; + if (where != NULL) + cwhere[cnvtxs] = where[i]; + nedges = 0; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = cmap[ladjncy[j]]; + if (k != cfirstvtx+cnvtxs) { /* If this is not an internal edge */ + l = k&mask; + if (htable[l] == -1) { /* Seeing this for first time */ + htable[l] = k; + htableidx[l] = cnedges+nedges; + cadjncy[cnedges+nedges] = k; + cadjwgt[cnedges+nedges++] = adjwgt[j]; + } + else if (htable[l] == k) { + cadjwgt[htableidx[l]] += adjwgt[j]; + } + else { /* Now you have to go and do a search. Expensive case */ + for (l=0; l<nedges; l++) { + if (cadjncy[cnedges+l] == k) + break; + } + if (l < nedges) { + cadjwgt[cnedges+l] += adjwgt[j]; + } + else { + cadjncy[cnedges+nedges] = k; + cadjwgt[cnedges+nedges++] = adjwgt[j]; + } + } + } + } + + /* Collapse the u vertex next */ + if (v != u) { + u -= firstvtx; + for (h=0; h<ncon; h++) + cvwgt[cnvtxs*ncon+h] += vwgt[u*ncon+h]; + if (vsize != NULL) + cvsize[cnvtxs] += vsize[u]; + if (where != NULL && cwhere[cnvtxs] != where[u]) + myprintf(ctrl, "Something went wrong with the where local matching! %d %d\n", cwhere[cnvtxs], where[u]); + + for (j=xadj[u]; j<xadj[u+1]; j++) { + k = cmap[ladjncy[j]]; + if (k != cfirstvtx+cnvtxs) { /* If this is not an internal edge */ + l = k&mask; + if (htable[l] == -1) { /* Seeing this for first time */ + htable[l] = k; + htableidx[l] = cnedges+nedges; + cadjncy[cnedges+nedges] = k; + cadjwgt[cnedges+nedges++] = adjwgt[j]; + } + else if (htable[l] == k) { + cadjwgt[htableidx[l]] += adjwgt[j]; + } + else { /* Now you have to go and do a search. Expensive case */ + for (l=0; l<nedges; l++) { + if (cadjncy[cnedges+l] == k) + break; + } + if (l < nedges) { + cadjwgt[cnedges+l] += adjwgt[j]; + } + else { + cadjncy[cnedges+nedges] = k; + cadjwgt[cnedges+nedges++] = adjwgt[j]; + } + } + } + } + } + + cnedges += nedges; + for (j=cxadj[cnvtxs]; j<cnedges; j++) + htable[cadjncy[j]&mask] = -1; /* reset the htable */ + cxadj[++cnvtxs] = cnedges; + } + + cgraph->nedges = cnedges; + + for (j=0; j<cnvtxs; j++) + for (h=0; h<ncon; h++) + cgraph->nvwgt[j*ncon+h] = (float)(cvwgt[j*ncon+h])/(float)(ctrl->tvwgts[h]); + + cgraph->adjncy = idxmalloc(cnedges, "CreateCoarserGraph: cadjncy"); + cgraph->adjwgt = idxmalloc(cnedges, "CreateCoarserGraph: cadjwgt"); + idxcopy(cnedges, cadjncy, cgraph->adjncy); + idxcopy(cnedges, cadjwgt, cgraph->adjwgt); + GKfree((void **)&cadjncy, (void **)&graph->where, LTERM); /* Note that graph->where works fine even if it is NULL */ + +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/macros.h b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/macros.h new file mode 100644 index 0000000..31861f7 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/macros.h @@ -0,0 +1,163 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * macros.h + * + * This file contains macros used in multilevel + * + * Started 9/25/94 + * George + * + * $Id: macros.h,v 1.8 2003/07/21 19:11:46 karypis Exp $ + * + */ + + +/************************************************************************* +* The following macro returns a random number in the specified range +**************************************************************************/ +#define RandomInRange(u) ((int)(1.0*(u)*rand()/(RAND_MAX+1.0))) + +#define amax(a, b) ((a) >= (b) ? (a) : (b)) +#define amin(a, b) ((a) >= (b) ? (b) : (a)) + +#define AND(a, b) ((a) < 0 ? ((-(a))&(b)) : ((a)&(b))) +#define OR(a, b) ((a) < 0 ? -((-(a))|(b)) : ((a)|(b))) +#define XOR(a, b) ((a) < 0 ? -((-(a))^(b)) : ((a)^(b))) + +#define SWAP(a, b, tmp) \ + do {(tmp) = (a); (a) = (b); (b) = (tmp);} while(0) + +#define INC_DEC(a, b, val) \ + do {(a) += (val); (b) -= (val);} while(0) + + +#define icopy(n, a, b) memcpy((b), (a), sizeof(int)*(n)) +#define scopy(n, a, b) memcpy((b), (a), sizeof(float)*(n)) +#define idxcopy(n, a, b) memcpy((b), (a), sizeof(idxtype)*(n)) + +#define HASHFCT(key, size) ((key)%(size)) + + +/************************************************************************* +* Timer macros +**************************************************************************/ +#define cleartimer(tmr) (tmr = 0.0) +#define starttimer(tmr) (tmr -= MPI_Wtime()) +#define stoptimer(tmr) (tmr += MPI_Wtime()) +#define gettimer(tmr) (tmr) + + +/************************************************************************* +* This macro is used to handle dbglvl +**************************************************************************/ +#define IFSET(a, flag, cmd) if ((a)&(flag)) (cmd); + +/************************************************************************* +* These macros are used for debuging memory leaks +**************************************************************************/ +#ifdef DMALLOC +#define imalloc(n, msg) (malloc(sizeof(int)*(n))) +#define fmalloc(n, msg) (malloc(sizeof(float)*(n))) +#define idxmalloc(n, msg) (malloc(sizeof(idxtype)*(n))) +#define ismalloc(n, val, msg) (iset((n), (val), malloc(sizeof(int)*(n)))) +#define idxsmalloc(n, val, msg) (idxset((n), (val), malloc(sizeof(idxtype)*(n)))) +#define GKmalloc(a, b) (malloc(a)) +#endif + +#ifdef DMALLOC +# define MALLOC_CHECK(ptr); +/* +# define MALLOC_CHECK(ptr) \ + if (malloc_verify((ptr)) == DMALLOC_VERIFY_ERROR) { \ + printf("***MALLOC_CHECK failed on line %d of file %s: " #ptr "\n", \ + __LINE__, __FILE__); \ + abort(); \ + } +*/ +#else +# define MALLOC_CHECK(ptr) ; +#endif + +/************************************************************************* +* This macro converts a length array in a CSR one +**************************************************************************/ +#define MAKECSR(i, n, a) \ + do { \ + for (i=1; i<n; i++) a[i] += a[i-1]; \ + for (i=n; i>0; i--) a[i] = a[i-1]; \ + a[0] = 0; \ + } while(0) + + +#define SHIFTCSR(i, n, a) \ + do { \ + for (i=n; i>0; i--) a[i] = a[i-1]; \ + a[0] = 0; \ + } while(0) + + + +#ifdef DEBUG +# define ASSERT(ctrl, expr) \ + if (!(expr)) { \ + myprintf(ctrl, "***ASSERTION failed on line %d of file %s: " #expr "\n", \ + __LINE__, __FILE__); \ + abort(); \ + } +#else +# define ASSERT(ctrl, expr) ; +#endif + +#ifdef DEBUG +# define ASSERTP(ctrl, expr, msg) \ + if (!(expr)) { \ + myprintf(ctrl, "***ASSERTION failed on line %d of file %s:" #expr "\n", \ + __LINE__, __FILE__); \ + myprintf msg ; \ + abort(); \ + } +#else +# define ASSERTP(ctrl, expr,msg) ; +#endif + +#ifdef DEBUGS +# define ASSERTS(expr) \ + if (!(expr)) { \ + printf("***ASSERTION failed on line %d of file %s: " #expr "\n", \ + __LINE__, __FILE__); \ + abort(); \ + } +#else +# define ASSERTS(expr) ; +#endif + +#ifdef DEBUGS +# define ASSERTSP(expr, msg) \ + if (!(expr)) { \ + printf("***ASSERTION failed on line %d of file %s: " #expr "\n", \ + __LINE__, __FILE__); \ + printf msg ; \ + abort(); \ + } +#else +# define ASSERTSP(expr, msg) ; +#endif + +/************************************************************************* + * * These macros insert and remove nodes from the boundary list + * **************************************************************************/ +#define BNDInsert(nbnd, bndind, bndptr, vtx) \ + do { \ + bndind[nbnd] = vtx; \ + bndptr[vtx] = nbnd++;\ + } while(0) + +#define BNDDelete(nbnd, bndind, bndptr, vtx) \ + do { \ + bndind[bndptr[vtx]] = bndind[--nbnd]; \ + bndptr[bndind[nbnd]] = bndptr[vtx]; \ + bndptr[vtx] = -1; \ + } while(0) + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/match.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/match.c new file mode 100644 index 0000000..89bfa62 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/match.c @@ -0,0 +1,320 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mmatch.c + * + * This file contains code that finds a matching + * + * Started 2/22/96 + * George + * + * $Id: match.c,v 1.2 2003/07/21 17:18:50 karypis Exp $ + * + */ + +#include <parmetislib.h> + + +/************************************************************************* +* This function finds a matching +**************************************************************************/ +void Moc_GlobalMatch_Balance(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int h, i, ii, j, k; + int nnbrs, nvtxs, ncon, cnvtxs, firstvtx, lastvtx, maxi, maxidx, nkept; + int otherlastvtx, nrequests, nchanged, pass, nmatched, wside; + idxtype *xadj, *ladjncy, *adjwgt, *vtxdist, *home, *myhome, *shome, *rhome; + idxtype *match, *rmatch, *smatch; + idxtype *peind, *sendptr, *recvptr; + idxtype *perm, *iperm, *nperm, *changed; + float *nvwgt, maxnvwgt; + int *nreqs_pe; + KeyValueType *match_requests, *match_granted, *pe_requests; + + maxnvwgt = 1.0/((float)(ctrl->nparts)*MAXNVWGT_FACTOR); + + graph->match_type = MATCH_GLOBAL; + + IFSET(ctrl->dbglvl, DBG_TIME, MPI_Barrier(ctrl->comm)); + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->MatchTmr)); + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + ladjncy = graph->adjncy; + adjwgt = graph->adjwgt; + home = graph->home; + nvwgt = graph->nvwgt; + + vtxdist = graph->vtxdist; + firstvtx = vtxdist[ctrl->mype]; + lastvtx = vtxdist[ctrl->mype+1]; + + match = graph->match = idxsmalloc(nvtxs+graph->nrecv, UNMATCHED, "HEM_Match: match"); + myhome = idxsmalloc(nvtxs+graph->nrecv, UNMATCHED, "HEM_Match: myhome"); + + /*------------------------------------------------------------ + / Send/Receive the home information of interface vertices + /------------------------------------------------------------*/ + if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) { + idxcopy(nvtxs, home, myhome); + shome = wspace->indices; + rhome = myhome + nvtxs; + CommInterfaceData(ctrl, graph, myhome, shome, rhome); + } + + nnbrs = graph->nnbrs; + peind = graph->peind; + sendptr = graph->sendptr; + recvptr = graph->recvptr; + + /* Use wspace->indices as the tmp space for matching info of the boundary + * vertices that are sent and received */ + rmatch = match + nvtxs; + smatch = wspace->indices; + changed = smatch+graph->nsend; + + /* Use wspace->indices as the tmp space for match requests of the boundary + * vertices that are sent and received */ + match_requests = wspace->pairs; + match_granted = match_requests + graph->nsend; + + nreqs_pe = ismalloc(nnbrs, 0, "Match_HEM: nreqs_pe"); + + nkept = graph->gnvtxs/ctrl->npes - nvtxs; + + perm = (idxtype *)wspace->degrees; + iperm = perm + nvtxs; + FastRandomPermute(nvtxs, perm, 1); + for (i=0; i<nvtxs; i++) + iperm[perm[i]] = i; + + nperm = iperm + nvtxs; + for (i=0; i<nnbrs; i++) + nperm[i] = i; + + /************************************************************* + * Go now and find a matching by doing multiple iterations + *************************************************************/ + /* First nullify the heavy vertices */ + for (nchanged=i=0; i<nvtxs; i++) { + for (h=0; h<ncon; h++) + if (nvwgt[i*ncon+h] > maxnvwgt) { + break; + } + + if (h != ncon) { + match[i] = TOO_HEAVY; + nchanged++; + } + } + if (GlobalSESum(ctrl, nchanged) > 0) { + IFSET(ctrl->dbglvl, DBG_PROGRESS, + rprintf(ctrl, "We found %d heavy vertices!\n", GlobalSESum(ctrl, nchanged))); + CommInterfaceData(ctrl, graph, match, smatch, rmatch); + } + + + for (nmatched=pass=0; pass<NMATCH_PASSES; pass++) { + wside = (graph->level+pass)%2; + nchanged = nrequests = 0; + for (ii=nmatched; ii<nvtxs; ii++) { + i = perm[ii]; + if (match[i] == UNMATCHED) { /* Unmatched */ + maxidx = i; + maxi = -1; + + /* Find a heavy-edge matching */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = ladjncy[j]; + if (match[k] == UNMATCHED && + myhome[k] == myhome[i] && + (maxi == -1 || + adjwgt[maxi] < adjwgt[j] || + (maxidx < nvtxs && + k < nvtxs && + adjwgt[maxi] == adjwgt[j] && + BetterVBalance(ncon,nvwgt+i*ncon,nvwgt+maxidx*ncon,nvwgt+k*ncon) >= 0))) { + maxi = j; + maxidx = k; + } + } + + if (maxi != -1) { + k = ladjncy[maxi]; + if (k < nvtxs) { /* Take care the local vertices first */ + /* Here we give preference the local matching by granting it right away */ + if (i <= k) { + match[i] = firstvtx+k + KEEP_BIT; + match[k] = firstvtx+i; + } + else { + match[i] = firstvtx+k; + match[k] = firstvtx+i + KEEP_BIT; + } + changed[nchanged++] = i; + changed[nchanged++] = k; + } + else { /* Take care any remote boundary vertices */ + match[k] = MAYBE_MATCHED; + /* Alternate among which vertices will issue the requests */ + if ((wside ==0 && firstvtx+i < graph->imap[k]) || (wside == 1 && firstvtx+i > graph->imap[k])) { + match[i] = MAYBE_MATCHED; + match_requests[nrequests].key = graph->imap[k]; + match_requests[nrequests].val = firstvtx+i; + nrequests++; + } + } + } + } + } + + +#ifdef DEBUG_MATCH + PrintVector2(ctrl, nvtxs, firstvtx, match, "Match1"); + myprintf(ctrl, "[c: %2d] Nlocal: %d, Nrequests: %d\n", c, nlocal, nrequests); +#endif + + + /*********************************************************** + * Exchange the match_requests, requests for me are stored in + * match_granted + ************************************************************/ + /* Issue the receives first. Note that from each PE can receive a maximum + of the interface node that it needs to send it in the case of a mat-vec */ + for (i=0; i<nnbrs; i++) { + MPI_Irecv((void *)(match_granted+recvptr[i]), 2*(recvptr[i+1]-recvptr[i]), IDX_DATATYPE, + peind[i], 1, ctrl->comm, ctrl->rreq+i); + } + + /* Issue the sends next. This needs some work */ + ikeysort(nrequests, match_requests); + for (j=i=0; i<nnbrs; i++) { + otherlastvtx = vtxdist[peind[i]+1]; + for (k=j; k<nrequests && match_requests[k].key < otherlastvtx; k++); + MPI_Isend((void *)(match_requests+j), 2*(k-j), IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->sreq+i); + j = k; + } + + /* OK, now get into the loop waiting for the operations to finish */ + MPI_Waitall(nnbrs, ctrl->rreq, ctrl->statuses); + for (i=0; i<nnbrs; i++) { + MPI_Get_count(ctrl->statuses+i, IDX_DATATYPE, nreqs_pe+i); + nreqs_pe[i] = nreqs_pe[i]/2; /* Adjust for pairs of IDX_DATATYPE */ + } + MPI_Waitall(nnbrs, ctrl->sreq, ctrl->statuses); + + + /*********************************************************** + * Now, go and service the requests that you received in + * match_granted + ************************************************************/ + RandomPermute(nnbrs, nperm, 0); + for (ii=0; ii<nnbrs; ii++) { + i = nperm[ii]; + pe_requests = match_granted+recvptr[i]; + for (j=0; j<nreqs_pe[i]; j++) { + k = pe_requests[j].key; + ASSERTP(ctrl, k >= firstvtx && k < lastvtx, (ctrl, "%d %d %d %d %d\n", firstvtx, lastvtx, k, j, peind[i])); + /* myprintf(ctrl, "Requesting a match %d %d\n", pe_requests[j].key, pe_requests[j].val); */ + if (match[k-firstvtx] == UNMATCHED) { /* Bingo, lets grant this request */ + changed[nchanged++] = k-firstvtx; + if (nkept >= 0) { /* Flip a coin for who gets it */ + match[k-firstvtx] = pe_requests[j].val + KEEP_BIT; + nkept--; + } + else { + match[k-firstvtx] = pe_requests[j].val; + pe_requests[j].key += KEEP_BIT; + nkept++; + } + /* myprintf(ctrl, "Request from pe:%d (%d %d) granted!\n", peind[i], pe_requests[j].val, pe_requests[j].key); */ + } + else { /* We are not granting the request */ + /* myprintf(ctrl, "Request from pe:%d (%d %d) not granted!\n", peind[i], pe_requests[j].val, pe_requests[j].key); */ + pe_requests[j].key = UNMATCHED; + } + } + } + + + /*********************************************************** + * Exchange the match_granted information. It is stored in + * match_requests + ************************************************************/ + /* Issue the receives first. Note that from each PE can receive a maximum + of the interface node that it needs to send during the case of a mat-vec */ + for (i=0; i<nnbrs; i++) { + MPI_Irecv((void *)(match_requests+sendptr[i]), 2*(sendptr[i+1]-sendptr[i]), IDX_DATATYPE, + peind[i], 1, ctrl->comm, ctrl->rreq+i); + } + + /* Issue the sends next. */ + for (i=0; i<nnbrs; i++) { + MPI_Isend((void *)(match_granted+recvptr[i]), 2*nreqs_pe[i], IDX_DATATYPE, + peind[i], 1, ctrl->comm, ctrl->sreq+i); + } + + /* OK, now get into the loop waiting for the operations to finish */ + MPI_Waitall(nnbrs, ctrl->rreq, ctrl->statuses); + for (i=0; i<nnbrs; i++) { + MPI_Get_count(ctrl->statuses+i, IDX_DATATYPE, nreqs_pe+i); + nreqs_pe[i] = nreqs_pe[i]/2; /* Adjust for pairs of IDX_DATATYPE */ + } + MPI_Waitall(nnbrs, ctrl->sreq, ctrl->statuses); + + + /*********************************************************** + * Now, go and through the match_requests and update local + * match information for the matchings that were granted. + ************************************************************/ + for (i=0; i<nnbrs; i++) { + pe_requests = match_requests+sendptr[i]; + for (j=0; j<nreqs_pe[i]; j++) { + match[pe_requests[j].val-firstvtx] = pe_requests[j].key; + if (pe_requests[j].key != UNMATCHED) + changed[nchanged++] = pe_requests[j].val-firstvtx; + } + } + + for (i=0; i<nchanged; i++) { + ii = iperm[changed[i]]; + perm[ii] = perm[nmatched]; + iperm[perm[nmatched]] = ii; + nmatched++; + } + + CommChangedInterfaceData(ctrl, graph, nchanged, changed, match, match_requests, match_granted, wspace->pv4); + } + + /* Traverse the vertices and those that were unmatched, match them with themselves */ + cnvtxs = 0; + for (i=0; i<nvtxs; i++) { + if (match[i] == UNMATCHED || match[i] == TOO_HEAVY) { + match[i] = (firstvtx+i) + KEEP_BIT; + cnvtxs++; + } + else if (match[i] >= KEEP_BIT) { /* A matched vertex which I get to keep */ + cnvtxs++; + } + } + + if (ctrl->dbglvl&DBG_MATCHINFO) { + PrintVector2(ctrl, nvtxs, firstvtx, match, "Match"); + myprintf(ctrl, "Cnvtxs: %d\n", cnvtxs); + rprintf(ctrl, "Done with matching...\n"); + } + + GKfree((void **)(&myhome), (void **)(&nreqs_pe), LTERM); + + IFSET(ctrl->dbglvl, DBG_TIME, MPI_Barrier(ctrl->comm)); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->MatchTmr)); + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ContractTmr)); + + Moc_Global_CreateCoarseGraph(ctrl, graph, wspace, cnvtxs); + + IFSET(ctrl->dbglvl, DBG_TIME, MPI_Barrier(ctrl->comm)); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ContractTmr)); + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/mdiffusion.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/mdiffusion.c new file mode 100644 index 0000000..6c02138 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/mdiffusion.c @@ -0,0 +1,455 @@ +/* * Copyright 1997, Regents of the University of Minnesota + * + * mdiffusion.c + * + * This file contains code that performs mc-diffusion + * + * Started 9/16/99 + * George + * + * $Id: mdiffusion.c,v 1.2 2003/07/21 17:18:50 karypis Exp $ + */ + +#include <parmetislib.h> + +#define PE -1 + +/************************************************************************* +* This function is the entry point of the initial partitioning algorithm. +* This algorithm assembles the graph to all the processors and preceed +* serially. +**************************************************************************/ +int Moc_Diffusion(CtrlType *ctrl, GraphType *graph, idxtype *vtxdist, + idxtype *where, idxtype *home, WorkSpaceType *wspace, int npasses) +{ + int h, i, j; + int nvtxs, nedges, ncon, pass, iter, domain, processor; + int nparts, mype, npes, nlinks, me, you, wsize; + int nvisited, nswaps = -1, tnswaps, done, alldone = -1; + idxtype *rowptr, *colind, *diff_where, *sr_where, *ehome, *map, *rmap; + idxtype *pack, *unpack, *match, *proc2sub, *sub2proc; + idxtype *visited, *gvisited; + float *transfer, *npwgts, maxdiff, minflow, maxflow; + float lbavg, oldlbavg, ubavg, lbvec[MAXNCON]; + float diff_flows[MAXNCON], sr_flows[MAXNCON]; + float diff_lbavg, sr_lbavg, diff_cost, sr_cost; + idxtype *rbuffer, *sbuffer; + int *rcount, *rdispl; + float *solution, *load, *workspace; + EdgeType *degrees; + MatrixType matrix; + GraphType *egraph; + RInfoType *rinfo; + + if (graph->ncon > 3) + return 0; + + nvtxs = graph->nvtxs; + nedges = graph->nedges; + ncon = graph->ncon; + + nparts = ctrl->nparts; + mype = ctrl->mype; + npes = ctrl->npes; + ubavg = savg(ncon, ctrl->ubvec); + + /********************************************/ + /* initialize variables and allocate memory */ + /********************************************/ + load = fmalloc(nparts*(2+ncon)+nedges*(1+ncon), "load"); + solution = load + nparts; + npwgts = graph->gnpwgts = load + 2*nparts; + matrix.values = load + (2+ncon)*nparts; + transfer = matrix.transfer = load + (2+ncon)*nparts + nedges; + + proc2sub = idxmalloc(amax(nparts, npes*2), "Mc_Diffusion: proc2sub"); + sub2proc = idxmalloc(nparts*3+nedges+1, "Mc_Diffusion: match"); + match = sub2proc + nparts; + rowptr = matrix.rowptr = sub2proc + 2*nparts; + colind = matrix.colind = sub2proc + 3*nparts + 1; + + rcount = imalloc(2*npes+1, "Mc_Diffusion: rcount"); + rdispl = rcount + npes; + + pack = idxmalloc(nvtxs*8, "Mc_Diffusion: pack"); + unpack = pack + nvtxs; + rbuffer = pack + 2*nvtxs; + sbuffer = pack + 3*nvtxs; + map = pack + 4*nvtxs; + rmap = pack + 5*nvtxs; + diff_where = pack + 6*nvtxs; + ehome = pack + 7*nvtxs; + + wsize = amax(sizeof(float)*nparts*6, sizeof(idxtype)*(nvtxs+nparts*2+1)); + workspace = (float *)GKmalloc(wsize, "Moc_Diffusion: workspace"); + degrees = GKmalloc(nedges*sizeof(EdgeType), "Mc_Diffusion: degrees"); + rinfo = graph->rinfo = GKmalloc(nvtxs*sizeof(RInfoType), "Mc_Diffusion: rinfo"); + + /******************************************/ + /* construct subdomain connectivity graph */ + /******************************************/ + matrix.nrows = nparts; + SetUpConnectGraph(graph, &matrix, (idxtype *)workspace); + nlinks = (matrix.nnzs-nparts) / 2; + + visited = idxmalloc(matrix.nnzs*2, "visited"); + gvisited = visited + matrix.nnzs; + + for (pass=0; pass<npasses; pass++) { + sset(matrix.nnzs*ncon, 0.0, transfer); + idxset(matrix.nnzs, 0, gvisited); + idxset(matrix.nnzs, 0, visited); + iter = nvisited = 0; + + /*******************************/ + /* compute ncon flow solutions */ + /*******************************/ + for (h=0; h<ncon; h++) { + sset(nparts, 0.0, solution); + ComputeLoad(graph, nparts, load, ctrl->tpwgts, h); + + lbvec[h] = (load[samax(nparts, load)]+1.0/(float)nparts) * (float)nparts; + + ConjGrad2(&matrix, load, solution, 0.001, workspace); + ComputeTransferVector(ncon, &matrix, solution, transfer, h); + } + + oldlbavg = savg(ncon, lbvec); + tnswaps = 0; + maxdiff = 0.0; + for (i=0; i<nparts; i++) { + for (j=rowptr[i]; j<rowptr[i+1]; j++) { + minflow = transfer[j*ncon+samin(ncon, transfer+j*ncon)]; + maxflow = transfer[j*ncon+samax(ncon, transfer+j*ncon)]; + maxdiff = (maxflow - minflow > maxdiff) ? maxflow - minflow : maxdiff; + } + } + + while (nvisited < nlinks) { + + /******************************************/ + /* compute independent sets of subdomains */ + /******************************************/ + idxset(amax(nparts, npes*2), UNMATCHED, proc2sub); + CSR_Match_SHEM(&matrix, match, proc2sub, gvisited, ncon); + + /*****************************/ + /* Set up the packing arrays */ + /*****************************/ + idxset(nparts, UNMATCHED, sub2proc); + for (i=0; i<npes*2; i++) { + if (proc2sub[i] == UNMATCHED) + break; + + sub2proc[proc2sub[i]] = i/2; + } + + iset(npes, 0, rcount); + for (i=0; i<nvtxs; i++) { + domain = where[i]; + processor = sub2proc[domain]; + if (processor != UNMATCHED) { + rcount[processor]++; + } + } + + rdispl[0] = 0; + for (i=1; i<npes+1; i++) + rdispl[i] = rdispl[i-1] + rcount[i-1]; + + idxset(nvtxs, UNMATCHED, unpack); + for (i=0; i<nvtxs; i++) { + domain = where[i]; + processor = sub2proc[domain]; + if (processor != UNMATCHED) { + unpack[rdispl[processor]++] = i; + } + } + + for (i=npes; i>0; i--) + rdispl[i] = rdispl[i-1]; + rdispl[0] = 0; + + idxset(nvtxs, UNMATCHED, pack); + for (i=0; i<rdispl[npes]; i++) { + ASSERTS(unpack[i] != UNMATCHED); + domain = where[unpack[i]]; + processor = sub2proc[domain]; + if (processor != UNMATCHED) { + pack[unpack[i]] = i; + } + } + + /*********************/ + /* Compute the flows */ + /*********************/ + if (proc2sub[mype*2] != UNMATCHED) { + me = proc2sub[mype*2]; + you = proc2sub[mype*2+1]; + ASSERTS(me != you); + + for (j=rowptr[me]; j<rowptr[me+1]; j++) { + if (colind[j] == you) { + visited[j] = 1; + scopy(ncon, transfer+j*ncon, diff_flows); + break; + } + } + + for (j=rowptr[you]; j<rowptr[you+1]; j++) { + if (colind[j] == me) { + visited[j] = 1; + for (h=0; h<ncon; h++) + if (transfer[j*ncon+h] > 0.0) + diff_flows[h] = -1.0 * transfer[j*ncon+h]; + break; + } + } + + nswaps = 1; + scopy(ncon, diff_flows, sr_flows); + + idxset(nvtxs, 0, sbuffer); + for (i=0; i<nvtxs; i++) + if (where[i] == me || where[i] == you) + sbuffer[i] = 1; + + egraph = ExtractGraph(ctrl, graph, sbuffer, map, rmap); + + if (egraph != NULL) { + idxcopy(egraph->nvtxs, egraph->where, diff_where); + for (j=0; j<egraph->nvtxs; j++) + ehome[j] = home[map[j]]; + + RedoMyLink(ctrl, egraph, ehome, me, you, sr_flows, &sr_cost, &sr_lbavg); + + if (ncon <= 4) { + sr_where = egraph->where; + egraph->where = diff_where; + + nswaps = BalanceMyLink(ctrl, egraph, ehome, me, you, diff_flows, maxdiff, &diff_cost, &diff_lbavg, 1.0/(float)nvtxs); + + if ((sr_lbavg < diff_lbavg && + (diff_lbavg >= ubavg-1.0 || sr_cost == diff_cost)) || + (sr_lbavg < ubavg-1.0 && sr_cost < diff_cost)) { + for (i=0; i<egraph->nvtxs; i++) + where[map[i]] = sr_where[i]; + } + else { + for (i=0; i<egraph->nvtxs; i++) + where[map[i]] = diff_where[i]; + } + } + else { + for (i=0; i<egraph->nvtxs; i++) + where[map[i]] = egraph->where[i]; + } + + GKfree((void **)&egraph->xadj, (void **)&egraph->nvwgt, (void **)&egraph->adjncy, LTERM); + GKfree((void **)&egraph, LTERM); + } + + /**********************/ + /* Pack the flow data */ + /**********************/ + idxset(nvtxs, UNMATCHED, sbuffer); + for (i=0; i<nvtxs; i++) { + domain = where[i]; + if (domain == you || domain == me) { + sbuffer[pack[i]] = where[i]; + } + } + } + + /***************************/ + /* Broadcast the flow data */ + /***************************/ + MPI_Allgatherv((void *)&sbuffer[rdispl[mype]], rcount[mype], IDX_DATATYPE, (void *)rbuffer, rcount, rdispl, IDX_DATATYPE, ctrl->comm); + + + /************************/ + /* Unpack the flow data */ + /************************/ + for (i=0; i<rdispl[npes]; i++) { + if (rbuffer[i] != UNMATCHED) { + where[unpack[i]] = rbuffer[i]; + } + } + + + /******************/ + /* Do other stuff */ + /******************/ + MPI_Allreduce((void *)visited, (void *)gvisited, matrix.nnzs, + IDX_DATATYPE, MPI_MAX, ctrl->comm); + nvisited = idxsum(matrix.nnzs, gvisited)/2; + tnswaps += GlobalSESum(ctrl, nswaps); + + if (iter++ == NGD_PASSES) + break; + } + + /*****************************/ + /* perform serial refinement */ + /*****************************/ + Moc_ComputeSerialPartitionParams(graph, nparts, degrees); + Moc_SerialKWayAdaptRefine(graph, nparts, home, ctrl->ubvec, 10); + + + /****************************/ + /* check for early breakout */ + /****************************/ + for (h=0; h<ncon; h++) { + lbvec[h] = (float)(nparts) * + npwgts[samax_strd(nparts,npwgts+h,ncon)*ncon+h]; + } + lbavg = savg(ncon, lbvec); + + done = 0; + if ( + tnswaps == 0 || + lbavg >= oldlbavg || + lbavg <= ubavg + 0.035 + ) + done = 1; + + alldone = GlobalSEMax(ctrl, done); + if (alldone == 1) + break; + } + + /*******************************************************/ + /* ensure that all subdomains have at least one vertex */ + /*******************************************************/ +/* + idxset(nparts, 0, match); + for (i=0; i<nvtxs; i++) + match[where[i]]++; + + done = 0; + while (done == 0) { + done = 1; + + me = idxamin(nparts, match); + if (match[me] == 0) { +if (ctrl->mype == PE) printf("WARNING: empty subdomain %d in Moc_Diffusion\n", me); + you = idxamax(nparts, match); + for (i=0; i<nvtxs; i++) { + if (where[i] == you) { + where[i] = me; + match[you]--; + match[me]++; + done = 0; + break; + } + } + } + } +*/ + + /******************************/ + /* now free memory and return */ + /******************************/ + GKfree((void **)&load, (void **)&proc2sub, (void **)&sub2proc, (void **)&rcount, LTERM); + GKfree((void **)&pack, (void **)&workspace, (void **)°rees, (void **)&rinfo, LTERM); + GKfree((void **)&visited, LTERM); + graph->gnpwgts = NULL; + graph->rinfo = NULL; + + return 0; +} + + +/************************************************************************* +* This function extracts a subgraph from a graph given an indicator array. +**************************************************************************/ +GraphType *ExtractGraph(CtrlType *ctrl, GraphType *graph, idxtype *indicator, + idxtype *map, idxtype *rmap) +{ + int h, i, j; + int nvtxs, envtxs, enedges, ncon; + int vtx, count; + idxtype *xadj, *vsize, *adjncy, *adjwgt, *where; + idxtype *exadj, *evsize, *eadjncy, *eadjwgt, *ewhere; + float *nvwgt, *envwgt; + GraphType *egraph; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + vsize = graph->vsize; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + + count = 0; + for (i=0; i<nvtxs; i++) { + if (indicator[i] == 1) { + map[count] = i; + rmap[i] = count; + count++; + } + } + + if (count == 0) { + return NULL; + } + + /*******************/ + /* allocate memory */ + /*******************/ + egraph = CreateGraph(); + envtxs = egraph->nvtxs = count; + egraph->ncon = graph->ncon; + + exadj = egraph->xadj = idxmalloc(envtxs*3+1, "exadj"); + ewhere = egraph->where = exadj + envtxs + 1; + evsize = egraph->vsize = exadj + 2*envtxs + 1; + + envwgt = egraph->nvwgt = fmalloc(envtxs*ncon, "envwgt"); + + /************************************************/ + /* compute xadj, where, nvwgt, and vsize arrays */ + /************************************************/ + idxset(envtxs+1, 0, exadj); + for (i=0; i<envtxs; i++) { + vtx = map[i]; + + ewhere[i] = where[vtx]; + for (h=0; h<ncon; h++) + envwgt[i*ncon+h] = nvwgt[vtx*ncon+h]; + + if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) + evsize[i] = vsize[vtx]; + + for (j=xadj[vtx]; j<xadj[vtx+1]; j++) + if (indicator[adjncy[j]] == 1) + exadj[i]++; + + } + MAKECSR(i, envtxs, exadj); + + /************************************/ + /* compute adjncy and adjwgt arrays */ + /************************************/ + enedges = egraph->nedges = exadj[envtxs]; + eadjncy = egraph->adjncy = idxmalloc(enedges*2, "eadjncy"); + eadjwgt = egraph->adjwgt = eadjncy + enedges; + + for (i=0; i<envtxs; i++) { + vtx = map[i]; + for (j=xadj[vtx]; j<xadj[vtx+1]; j++) { + if (indicator[adjncy[j]] == 1) { + eadjncy[exadj[i]] = rmap[adjncy[j]]; + eadjwgt[exadj[i]++] = adjwgt[j]; + } + } + } + + for (i=envtxs; i>0; i--) + exadj[i] = exadj[i-1]; + exadj[0] = 0; + + return egraph; +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/mdrivers.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/mdrivers.c new file mode 100644 index 0000000..467df79 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/mdrivers.c @@ -0,0 +1,116 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mdrivers.c + * + * This file contains the driving routines for the various parallel + * multilevel partitioning and repartitioning algorithms + * + * Started 11/19/96 + * George + * + * $Id: mdrivers.c,v 1.3 2003/07/22 20:29:06 karypis Exp $ + * + */ + +#include <parmetislib.h> + + + +/************************************************************************* +* This function is the driver to the multi-constraint partitioning algorithm. +**************************************************************************/ +void Moc_Global_Partition(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int i, ncon, nparts; + float ftmp, ubavg, lbavg, lbvec[MAXNCON]; + + ncon = graph->ncon; + nparts = ctrl->nparts; + ubavg = savg(graph->ncon, ctrl->ubvec); + + SetUp(ctrl, graph, wspace); + + if (ctrl->dbglvl&DBG_PROGRESS) { + rprintf(ctrl, "[%6d %8d %5d %5d] [%d] [", graph->gnvtxs, GlobalSESum(ctrl, graph->nedges), + GlobalSEMin(ctrl, graph->nvtxs), GlobalSEMax(ctrl, graph->nvtxs), ctrl->CoarsenTo); + for (i=0; i<ncon; i++) + rprintf(ctrl, " %.3f", GlobalSEMinFloat(ctrl,graph->nvwgt[samin_strd(graph->nvtxs, graph->nvwgt+i, ncon)*ncon+i])); + rprintf(ctrl, "] ["); + for (i=0; i<ncon; i++) + rprintf(ctrl, " %.3f", GlobalSEMaxFloat(ctrl, graph->nvwgt[samax_strd(graph->nvtxs, graph->nvwgt+i, ncon)*ncon+i])); + rprintf(ctrl, "]\n"); + } + + if (graph->gnvtxs < 1.3*ctrl->CoarsenTo || + (graph->finer != NULL && + graph->gnvtxs > graph->finer->gnvtxs*COARSEN_FRACTION)) { + + /* Done with coarsening. Find a partition */ + graph->where = idxmalloc(graph->nvtxs+graph->nrecv, "graph->where"); + Moc_InitPartition_RB(ctrl, graph, wspace); + + if (ctrl->dbglvl&DBG_PROGRESS) { + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + rprintf(ctrl, "nvtxs: %10d, balance: ", graph->gnvtxs); + for (i=0; i<graph->ncon; i++) + rprintf(ctrl, "%.3f ", lbvec[i]); + rprintf(ctrl, "\n"); + } + + /* In case no coarsening took place */ + if (graph->finer == NULL) { + Moc_ComputePartitionParams(ctrl, graph, wspace); + Moc_KWayFM(ctrl, graph, wspace, NGR_PASSES); + } + } + else { + Moc_GlobalMatch_Balance(ctrl, graph, wspace); + + Moc_Global_Partition(ctrl, graph->coarser, wspace); + + Moc_ProjectPartition(ctrl, graph, wspace); + Moc_ComputePartitionParams(ctrl, graph, wspace); + + if (graph->ncon > 1 && graph->level < 3) { + for (i=0; i<ncon; i++) { + ftmp = ssum_strd(nparts, graph->gnpwgts+i, ncon); + if (ftmp != 0.0) + lbvec[i] = (float)(nparts) * + graph->gnpwgts[samax_strd(nparts, graph->gnpwgts+i, ncon)*ncon+i]/ftmp; + else + lbvec[i] = 1.0; + } + lbavg = savg(graph->ncon, lbvec); + + if (lbavg > ubavg + 0.035) { + if (ctrl->dbglvl&DBG_PROGRESS) { + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + rprintf(ctrl, "nvtxs: %10d, cut: %8d, balance: ", graph->gnvtxs, graph->mincut); + for (i=0; i<graph->ncon; i++) + rprintf(ctrl, "%.3f ", lbvec[i]); + rprintf(ctrl, "\n"); + } + + Moc_KWayBalance(ctrl, graph, wspace, graph->ncon); + } + } + + Moc_KWayFM(ctrl, graph, wspace, NGR_PASSES); + + if (ctrl->dbglvl&DBG_PROGRESS) { + Moc_ComputeParallelBalance(ctrl, graph, graph->where, lbvec); + rprintf(ctrl, "nvtxs: %10d, cut: %8d, balance: ", graph->gnvtxs, graph->mincut); + for (i=0; i<graph->ncon; i++) + rprintf(ctrl, "%.3f ", lbvec[i]); + rprintf(ctrl, "\n"); + } + + if (graph->level != 0) + GKfree((void **)&graph->lnpwgts, (void **)&graph->gnpwgts, LTERM); + } + + return; +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/memory.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/memory.c new file mode 100644 index 0000000..a8eeaff --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/memory.c @@ -0,0 +1,216 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * memory.c + * + * This file contains routines that deal with memory allocation + * + * Started 2/24/96 + * George + * + * $Id: memory.c,v 1.3 2003/07/30 18:37:59 karypis Exp $ + * + */ + +#include <parmetislib.h> + + +/************************************************************************* +* This function allocate various pools of memory +**************************************************************************/ +void PreAllocateMemory(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + wspace->nlarge = 2*graph->nedges; + + wspace->maxcore = 8*graph->nedges+1; + wspace->core = idxmalloc(wspace->maxcore, "PreAllocateMemory: wspace->core"); + + wspace->pairs = (KeyValueType *)wspace->core; + wspace->indices = (idxtype *)(wspace->pairs + wspace->nlarge); + wspace->degrees = (EdgeType *)(wspace->indices + wspace->nlarge); + + + wspace->pv1 = idxmalloc(ctrl->nparts+ctrl->npes+1, "PreAllocateMemory: wspace->pv?"); + wspace->pv2 = idxmalloc(ctrl->nparts+ctrl->npes+1, "PreAllocateMemory: wspace->pv?"); + wspace->pv3 = idxmalloc(ctrl->nparts+ctrl->npes+1, "PreAllocateMemory: wspace->pv?"); + wspace->pv4 = idxmalloc(ctrl->nparts+ctrl->npes+1, "PreAllocateMemory: wspace->pv?"); + + wspace->pepairs1 = (KeyValueType *)GKmalloc(sizeof(KeyValueType)*(ctrl->nparts+ctrl->npes+1), "PreAllocateMemory: wspace->pepairs?"); + wspace->pepairs2 = (KeyValueType *)GKmalloc(sizeof(KeyValueType)*(ctrl->nparts+ctrl->npes+1), "PreAllocateMemory: wspace->pepairs?"); + +} + + +/************************************************************************* +* This function de-allocate various pools of memory +**************************************************************************/ +void FreeWSpace(WorkSpaceType *wspace) +{ + + GKfree((void **)&wspace->core, + (void **)&wspace->pv1, + (void **)&wspace->pv2, + (void **)&wspace->pv3, + (void **)&wspace->pv4, + (void **)&wspace->pepairs1, + (void **)&wspace->pepairs2, + LTERM); +} + + +/************************************************************************* +* This function de-allocates memory allocated for the control structures +**************************************************************************/ +void FreeCtrl(CtrlType *ctrl) +{ + MPI_Comm_free(&(ctrl->gcomm)); +} + + +/************************************************************************* +* This function creates a CoarseGraphType data structure and initializes +* the various fields +**************************************************************************/ +GraphType *CreateGraph(void) +{ + GraphType *graph; + + graph = (GraphType *)GKmalloc(sizeof(GraphType), "CreateCoarseGraph: graph"); + + InitGraph(graph); + + return graph; +} + + +/************************************************************************* +* This function creates a CoarseGraphType data structure and initializes +* the various fields +**************************************************************************/ +void InitGraph(GraphType *graph) +{ + graph->gnvtxs = graph->nvtxs = graph->nedges = graph->nsep = -1; + graph->nnbrs = graph->nrecv = graph->nsend = graph->nlocal = -1; + graph->xadj = graph->vwgt = graph->vsize = graph->adjncy = graph->adjwgt = NULL; + graph->nvwgt = NULL; + graph->vtxdist = NULL; + graph->match = graph->cmap = NULL; + graph->label = NULL; + + graph->peind = NULL; + graph->sendptr = graph->sendind = graph->recvptr = graph->recvind = NULL; + graph->imap = NULL; + graph->pexadj = graph->peadjncy = graph->peadjloc = NULL; + graph->lperm = NULL; + + graph->slens = graph->rlens = NULL; + graph->rcand = NULL; + + graph->where = graph->home = graph->lpwgts = graph->gpwgts = NULL; + graph->lnpwgts = graph->gnpwgts = NULL; + graph->rinfo = NULL; + + graph->nrinfo = NULL; + graph->sepind = NULL; + + graph->coarser = graph->finer = NULL; + +} + +/************************************************************************* +* This function deallocates any memory stored in a graph +**************************************************************************/ +void FreeGraph(GraphType *graph) +{ + + GKfree((void **)&graph->xadj, + (void **)&graph->vwgt, + (void **)&graph->nvwgt, + (void **)&graph->vsize, + (void **)&graph->adjncy, + (void **)&graph->adjwgt, + (void **)&graph->vtxdist, + (void **)&graph->match, + (void **)&graph->cmap, + (void **)&graph->lperm, + (void **)&graph->label, + (void **)&graph->where, + (void **)&graph->home, + (void **)&graph->rinfo, + (void **)&graph->nrinfo, + (void **)&graph->sepind, + (void **)&graph->lpwgts, + (void **)&graph->gpwgts, + (void **)&graph->lnpwgts, + (void **)&graph->gnpwgts, + (void **)&graph->peind, + (void **)&graph->sendptr, + (void **)&graph->sendind, + (void **)&graph->recvptr, + (void **)&graph->recvind, + (void **)&graph->imap, + (void **)&graph->rlens, + (void **)&graph->slens, + (void **)&graph->rcand, + (void **)&graph->pexadj, + (void **)&graph->peadjncy, + (void **)&graph->peadjloc, + LTERM); + + free(graph); +} + + + +/************************************************************************* +* This function deallocates any memory stored in a graph +**************************************************************************/ +void FreeInitialGraphAndRemap(GraphType *graph, int wgtflag) +{ + int i, nedges; + idxtype *adjncy, *imap; + + nedges = graph->nedges; + adjncy = graph->adjncy; + imap = graph->imap; + + if (imap != NULL) { + for (i=0; i<nedges; i++) + adjncy[i] = imap[adjncy[i]]; /* Apply local to global transformation */ + } + + /* Free Metis's things */ + GKfree((void **)&graph->match, + (void **)&graph->cmap, + (void **)&graph->lperm, + (void **)&graph->where, + (void **)&graph->label, + (void **)&graph->rinfo, + (void **)&graph->nrinfo, + (void **)&graph->nvwgt, + (void **)&graph->lpwgts, + (void **)&graph->gpwgts, + (void **)&graph->lnpwgts, + (void **)&graph->gnpwgts, + (void **)&graph->sepind, + (void **)&graph->peind, + (void **)&graph->sendptr, + (void **)&graph->sendind, + (void **)&graph->recvptr, + (void **)&graph->recvind, + (void **)&graph->imap, + (void **)&graph->rlens, + (void **)&graph->slens, + (void **)&graph->rcand, + (void **)&graph->pexadj, + (void **)&graph->peadjncy, + (void **)&graph->peadjloc, + LTERM); + + if ((wgtflag&2) == 0) + GKfree((void **)&graph->vwgt, (void **)&graph->vsize, LTERM); + if ((wgtflag&1) == 0) + GKfree((void **)&graph->adjwgt, LTERM); + + free(graph); +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/mesh.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/mesh.c new file mode 100644 index 0000000..57a80c0 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/mesh.c @@ -0,0 +1,335 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mesh.c + * + * This file contains routines for constructing the dual graph of a mesh. + * Assumes that each processor has at least one mesh element. + * + * Started 10/19/94 + * George + * + * $Id: mesh.c,v 1.11 2003/07/25 04:01:04 karypis Exp $ + * + */ + +#include <parmetislib.h> + + +/************************************************************************* +* This function converts a mesh into a dual graph +**************************************************************************/ +void ParMETIS_V3_Mesh2Dual(idxtype *elmdist, idxtype *eptr, idxtype *eind, + int *numflag, int *ncommonnodes, idxtype **xadj, + idxtype **adjncy, MPI_Comm *comm) +{ + int i, j, jj, k, kk, m; + int npes, mype, pe, count, mask, pass; + int nelms, lnns, my_nns, node; + int firstelm, firstnode, lnode, nrecv, nsend; + int *scounts, *rcounts, *sdispl, *rdispl; + idxtype *nodedist, *nmap, *auxarray; + idxtype *gnptr, *gnind, *nptr, *nind, *myxadj, *myadjncy = NULL; + idxtype *sbuffer, *rbuffer, *htable; + KeyValueType *nodelist, *recvbuffer; + idxtype ind[200], wgt[200]; + int gmaxnode, gminnode; + CtrlType ctrl; + + + SetUpCtrl(&ctrl, -1, 0, *comm); + + npes = ctrl.npes; + mype = ctrl.mype; + + nelms = elmdist[mype+1]-elmdist[mype]; + + if (*numflag == 1) + ChangeNumberingMesh2(elmdist, eptr, eind, NULL, NULL, NULL, npes, mype, 1); + + mask = (1<<11)-1; + + /*****************************/ + /* Determine number of nodes */ + /*****************************/ + gminnode = GlobalSEMin(&ctrl, eind[idxamin(eptr[nelms], eind)]); + for (i=0; i<eptr[nelms]; i++) + eind[i] -= gminnode; + + gmaxnode = GlobalSEMax(&ctrl, eind[idxamax(eptr[nelms], eind)]); + + + /**************************/ + /* Check for input errors */ + /**************************/ + ASSERTS(nelms > 0); + + /* construct node distribution array */ + nodedist = idxsmalloc(npes+1, 0, "nodedist"); + for (nodedist[0]=0, i=0,j=gmaxnode+1; i<npes; i++) { + k = j/(npes-i); + nodedist[i+1] = nodedist[i]+k; + j -= k; + } + my_nns = nodedist[mype+1]-nodedist[mype]; + firstnode = nodedist[mype]; + + nodelist = (KeyValueType *)GKmalloc(eptr[nelms]*sizeof(KeyValueType), "nodelist"); + auxarray = idxmalloc(eptr[nelms], "auxarray"); + htable = idxsmalloc(amax(my_nns, mask+1), -1, "htable"); + scounts = imalloc(4*npes+2, "scounts"); + rcounts = scounts+npes; + sdispl = scounts+2*npes; + rdispl = scounts+3*npes+1; + + + /*********************************************/ + /* first find a local numbering of the nodes */ + /*********************************************/ + for (i=0; i<nelms; i++) { + for (j=eptr[i]; j<eptr[i+1]; j++) { + nodelist[j].key = eind[j]; + nodelist[j].val = j; + auxarray[j] = i; /* remember the local element ID that uses this node */ + } + } + ikeysort(eptr[nelms], nodelist); + + for (count=1, i=1; i<eptr[nelms]; i++) { + if (nodelist[i].key > nodelist[i-1].key) + count++; + } + + lnns = count; + nmap = idxmalloc(lnns, "nmap"); + + /* renumber the nodes of the elements array */ + count = 1; + nmap[0] = nodelist[0].key; + eind[nodelist[0].val] = 0; + nodelist[0].val = auxarray[nodelist[0].val]; /* Store the local element ID */ + for (i=1; i<eptr[nelms]; i++) { + if (nodelist[i].key > nodelist[i-1].key) { + nmap[count] = nodelist[i].key; + count++; + } + eind[nodelist[i].val] = count-1; + nodelist[i].val = auxarray[nodelist[i].val]; /* Store the local element ID */ + } + MPI_Barrier(*comm); + + /**********************************************************/ + /* perform comms necessary to construct node-element list */ + /**********************************************************/ + iset(npes, 0, scounts); + for (pe=i=0; i<eptr[nelms]; i++) { + while (nodelist[i].key >= nodedist[pe+1]) + pe++; + scounts[pe] += 2; + } + ASSERTS(pe < npes); + + MPI_Alltoall((void *)scounts, 1, MPI_INT, (void *)rcounts, 1, MPI_INT, *comm); + + icopy(npes, scounts, sdispl); + MAKECSR(i, npes, sdispl); + + icopy(npes, rcounts, rdispl); + MAKECSR(i, npes, rdispl); + + ASSERTS(sdispl[npes] == eptr[nelms]*2); + + nrecv = rdispl[npes]/2; + recvbuffer = (KeyValueType *)GKmalloc(amax(1, nrecv)*sizeof(KeyValueType), "recvbuffer"); + + MPI_Alltoallv((void *)nodelist, scounts, sdispl, IDX_DATATYPE, (void *)recvbuffer, + rcounts, rdispl, IDX_DATATYPE, *comm); + + /**************************************/ + /* construct global node-element list */ + /**************************************/ + gnptr = idxsmalloc(my_nns+1, 0, "gnptr"); + + for (i=0; i<npes; i++) { + for (j=rdispl[i]/2; j<rdispl[i+1]/2; j++) { + lnode = recvbuffer[j].key-firstnode; + ASSERTS(lnode >= 0 && lnode < my_nns) + + gnptr[lnode]++; + } + } + MAKECSR(i, my_nns, gnptr); + + gnind = idxmalloc(amax(1, gnptr[my_nns]), "gnind"); + for (pe=0; pe<npes; pe++) { + firstelm = elmdist[pe]; + for (j=rdispl[pe]/2; j<rdispl[pe+1]/2; j++) { + lnode = recvbuffer[j].key-firstnode; + gnind[gnptr[lnode]++] = recvbuffer[j].val+firstelm; + } + } + SHIFTCSR(i, my_nns, gnptr); + + + /*********************************************************/ + /* send the node-element info to the relevant processors */ + /*********************************************************/ + iset(npes, 0, scounts); + + /* use a hash table to ensure that each node is sent to a proc only once */ + for (pe=0; pe<npes; pe++) { + for (j=rdispl[pe]/2; j<rdispl[pe+1]/2; j++) { + lnode = recvbuffer[j].key-firstnode; + if (htable[lnode] == -1) { + scounts[pe] += gnptr[lnode+1]-gnptr[lnode]; + htable[lnode] = 1; + } + } + + /* now reset the hash table */ + for (j=rdispl[pe]/2; j<rdispl[pe+1]/2; j++) { + lnode = recvbuffer[j].key-firstnode; + htable[lnode] = -1; + } + } + + + MPI_Alltoall((void *)scounts, 1, MPI_INT, (void *)rcounts, 1, MPI_INT, *comm); + + icopy(npes, scounts, sdispl); + MAKECSR(i, npes, sdispl); + + /* create the send buffer */ + nsend = sdispl[npes]; + sbuffer = (idxtype *)realloc(nodelist, sizeof(idxtype)*amax(1, nsend)); + + count = 0; + for (pe=0; pe<npes; pe++) { + for (j=rdispl[pe]/2; j<rdispl[pe+1]/2; j++) { + lnode = recvbuffer[j].key-firstnode; + if (htable[lnode] == -1) { + for (k=gnptr[lnode]; k<gnptr[lnode+1]; k++) { + if (k == gnptr[lnode]) + sbuffer[count++] = -1*(gnind[k]+1); + else + sbuffer[count++] = gnind[k]; + } + htable[lnode] = 1; + } + } + ASSERTS(count == sdispl[pe+1]); + + /* now reset the hash table */ + for (j=rdispl[pe]/2; j<rdispl[pe+1]/2; j++) { + lnode = recvbuffer[j].key-firstnode; + htable[lnode] = -1; + } + } + + icopy(npes, rcounts, rdispl); + MAKECSR(i, npes, rdispl); + + nrecv = rdispl[npes]; + rbuffer = (idxtype *)realloc(recvbuffer, sizeof(idxtype)*amax(1, nrecv)); + + MPI_Alltoallv((void *)sbuffer, scounts, sdispl, IDX_DATATYPE, (void *)rbuffer, + rcounts, rdispl, IDX_DATATYPE, *comm); + + k = -1; + nptr = idxsmalloc(lnns+1, 0, "nptr"); + nind = rbuffer; + for (pe=0; pe<npes; pe++) { + for (j=rdispl[pe]; j<rdispl[pe+1]; j++) { + if (nind[j] < 0) { + k++; + nind[j] = (-1*nind[j])-1; + } + nptr[k]++; + } + } + MAKECSR(i, lnns, nptr); + + ASSERTS(k+1 == lnns); + ASSERTS(nptr[lnns] == nrecv) + + myxadj = *xadj = idxsmalloc(nelms+1, 0, "xadj"); + idxset(mask+1, -1, htable); + + firstelm = elmdist[mype]; + + /* Two passes -- in first pass, simply find out the memory requirements */ + for (pass=0; pass<2; pass++) { + for (i=0; i<nelms; i++) { + for (count=0, j=eptr[i]; j<eptr[i+1]; j++) { + node = eind[j]; + + for (k=nptr[node]; k<nptr[node+1]; k++) { + if ((kk=nind[k]) == firstelm+i) + continue; + + m = htable[(kk&mask)]; + + if (m == -1) { + ind[count] = kk; + wgt[count] = 1; + htable[(kk&mask)] = count++; + } + else { + if (ind[m] == kk) { + wgt[m]++; + } + else { + for (jj=0; jj<count; jj++) { + if (ind[jj] == kk) { + wgt[jj]++; + break; + } + } + if (jj == count) { + ind[count] = kk; + wgt[count++] = 1; + } + } + } + } + } + + for (j=0; j<count; j++) { + htable[(ind[j]&mask)] = -1; + if (wgt[j] >= *ncommonnodes) { + if (pass == 0) + myxadj[i]++; + else + myadjncy[myxadj[i]++] = ind[j]; + } + } + } + + if (pass == 0) { + MAKECSR(i, nelms, myxadj); + myadjncy = *adjncy = idxmalloc(myxadj[nelms], "adjncy"); + } + else { + SHIFTCSR(i, nelms, myxadj); + } + } + + /*****************************************/ + /* correctly renumber the elements array */ + /*****************************************/ + for (i=0; i<eptr[nelms]; i++) + eind[i] = nmap[eind[i]] + gminnode; + + if (*numflag == 1) + ChangeNumberingMesh2(elmdist, eptr, eind, myxadj, myadjncy, NULL, npes, mype, 0); + + /* do not free nodelist, recvbuffer, rbuffer */ + GKfree((void **)&scounts, (void **)&nodedist, (void **)&nmap, (void **)&sbuffer, + (void **)&htable, (void **)&nptr, (void **)&nind, (void **)&gnptr, + (void **)&gnind, (void **)&auxarray, LTERM); + + FreeCtrl(&ctrl); + + return; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/mmetis.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/mmetis.c new file mode 100644 index 0000000..b262ed1 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/mmetis.c @@ -0,0 +1,95 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mmetis.c + * + * This is the entry point of ParMETIS_V3_PartMeshKway + * + * Started 10/19/96 + * George + * + * $Id: mmetis.c,v 1.8 2003/07/25 04:01:04 karypis Exp $ + * + */ + +#include <parmetislib.h> + + +/*********************************************************************************** +* This function is the entry point of the parallel k-way multilevel mesh partitionioner. +* This function assumes nothing about the mesh distribution. +* It is the general case. +************************************************************************************/ +void ParMETIS_V3_PartMeshKway(idxtype *elmdist, idxtype *eptr, idxtype *eind, idxtype *elmwgt, + int *wgtflag, int *numflag, int *ncon, int *ncommonnodes, int *nparts, + float *tpwgts, float *ubvec, int *options, int *edgecut, idxtype *part, + MPI_Comm *comm) +{ + int i, nvtxs, nedges, gnedges, npes, mype; + idxtype *xadj, *adjncy; + timer TotalTmr, Mesh2DualTmr, ParMETISTmr; + CtrlType ctrl; + + /********************************/ + /* Try and take care bad inputs */ + /********************************/ + if (elmdist == NULL || eptr == NULL || eind == NULL || wgtflag == NULL || + numflag == NULL || ncon == NULL || ncommonnodes == NULL || nparts == NULL || + tpwgts == NULL || ubvec == NULL || options == NULL || edgecut == NULL || + part == NULL || comm == NULL) { + printf("ERROR: One or more required parameters is NULL. Aborting.\n"); + abort(); + } + if (((*wgtflag)&2) && elmwgt == NULL) { + printf("ERROR: elmwgt == NULL when vertex weights were specified. Aborting.\n"); + abort(); + } + + + SetUpCtrl(&ctrl, *nparts, (options[0] == 1 ? options[PMV3_OPTION_DBGLVL] : 0), *comm); + npes = ctrl.npes; + mype = ctrl.mype; + + cleartimer(TotalTmr); + cleartimer(Mesh2DualTmr); + cleartimer(ParMETISTmr); + + MPI_Barrier(ctrl.comm); + starttimer(TotalTmr); + starttimer(Mesh2DualTmr); + + ParMETIS_V3_Mesh2Dual(elmdist, eptr, eind, numflag, ncommonnodes, &xadj, &adjncy, &(ctrl.comm)); + + if (ctrl.dbglvl&DBG_INFO) { + nvtxs = elmdist[mype+1]-elmdist[mype]; + nedges = xadj[nvtxs] + (*numflag == 0 ? 0 : -1); + rprintf(&ctrl, "Completed Dual Graph -- Nvtxs: %d, Nedges: %d \n", + elmdist[npes], GlobalSESum(&ctrl, nedges)); + } + + MPI_Barrier(ctrl.comm); + stoptimer(Mesh2DualTmr); + + + /***********************/ + /* Partition the graph */ + /***********************/ + starttimer(ParMETISTmr); + + ParMETIS_V3_PartKway(elmdist, xadj, adjncy, elmwgt, NULL, wgtflag, numflag, ncon, + nparts, tpwgts, ubvec, options, edgecut, part, &(ctrl.comm)); + + MPI_Barrier(ctrl.comm); + stoptimer(ParMETISTmr); + stoptimer(TotalTmr); + + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimer(&ctrl, Mesh2DualTmr, " Mesh2Dual")); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimer(&ctrl, ParMETISTmr, " ParMETIS")); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimer(&ctrl, TotalTmr, " Total")); + + GKfree((void **)&xadj, (void **)&adjncy, LTERM); + + FreeCtrl(&ctrl); + + return; +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/move.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/move.c new file mode 100644 index 0000000..06a8e5c --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/move.c @@ -0,0 +1,338 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mmove.c + * + * This file contains functions that move the graph given a partition + * + * Started 11/22/96 + * George + * + * $Id: move.c,v 1.3 2003/07/31 16:23:30 karypis Exp $ + * + */ + +#include <parmetislib.h> + +/************************************************************************* +* This function moves the graph, and returns a new graph. +* This routine can be called with or without performing refinement. +* In the latter case it allocates and computes lpwgts itself. +**************************************************************************/ +GraphType *Moc_MoveGraph(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int h, i, ii, j, jj, nvtxs, ncon, nparts; + idxtype *xadj, *vwgt, *adjncy, *adjwgt, *mvtxdist; + idxtype *where, *newlabel, *lpwgts, *gpwgts; + idxtype *sgraph, *rgraph; + KeyValueType *sinfo, *rinfo; + GraphType *mgraph; + + nparts = ctrl->nparts; + ASSERT(ctrl, nparts == ctrl->npes); + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + vwgt = graph->vwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + + mvtxdist = idxmalloc(nparts+1, "MoveGraph: mvtxdist"); + + /* Let's do a prefix scan to determine the labeling of the nodes given */ + lpwgts = wspace->pv1; + gpwgts = wspace->pv2; + sinfo = wspace->pepairs1; + rinfo = wspace->pepairs2; + for (i=0; i<nparts; i++) + sinfo[i].key = sinfo[i].val = 0; + + for (i=0; i<nvtxs; i++) { + sinfo[where[i]].key++; + sinfo[where[i]].val += xadj[i+1]-xadj[i]; + } + for (i=0; i<nparts; i++) + lpwgts[i] = sinfo[i].key; + + MPI_Scan((void *)lpwgts, (void *)gpwgts, nparts, IDX_DATATYPE, MPI_SUM, ctrl->comm); + MPI_Allreduce((void *)lpwgts, (void *)mvtxdist, nparts, IDX_DATATYPE, MPI_SUM, ctrl->comm); + + MAKECSR(i, nparts, mvtxdist); + + /* gpwgts[i] will store the label of the first vertex for each domain in each processor */ + for (i=0; i<nparts; i++) + /* We were interested in an exclusive Scan */ + gpwgts[i] = mvtxdist[i] + gpwgts[i] - lpwgts[i]; + + newlabel = idxmalloc(nvtxs+graph->nrecv, "MoveGraph: newlabel"); + + for (i=0; i<nvtxs; i++) + newlabel[i] = gpwgts[where[i]]++; + + /* OK, now send the newlabel info to processors storing adjacent interface nodes */ + CommInterfaceData(ctrl, graph, newlabel, wspace->indices, newlabel+nvtxs); + + /* Now lets tell everybody what and from where he will get it. Assume nparts == npes */ + MPI_Alltoall((void *)sinfo, 2, IDX_DATATYPE, (void *)rinfo, 2, IDX_DATATYPE, ctrl->comm); + + /* Use lpwgts and gpwgts as pointers to where data will be received and send */ + lpwgts[0] = 0; /* Send part */ + gpwgts[0] = 0; /* Received part */ + for (i=0; i<nparts; i++) { + lpwgts[i+1] = lpwgts[i] + (1+ncon)*sinfo[i].key + 2*sinfo[i].val; + gpwgts[i+1] = gpwgts[i] + (1+ncon)*rinfo[i].key + 2*rinfo[i].val; + } + + + if (lpwgts[nparts]+gpwgts[nparts] > wspace->maxcore) { + /* Adjust core memory, incase the graph was originally very memory unbalanced */ + free(wspace->core); + wspace->maxcore = lpwgts[nparts]+4*gpwgts[nparts]; /* In spirit of the 8*nedges */ + wspace->core = idxmalloc(wspace->maxcore, "Moc_MoveGraph: wspace->core"); + } + + sgraph = wspace->core; + rgraph = wspace->core + lpwgts[nparts]; + + /* Issue the receives first */ + for (i=0; i<nparts; i++) { + if (rinfo[i].key > 0) + MPI_Irecv((void *)(rgraph+gpwgts[i]), gpwgts[i+1]-gpwgts[i], IDX_DATATYPE, i, 1, ctrl->comm, ctrl->rreq+i); + else + ASSERT(ctrl, gpwgts[i+1]-gpwgts[i] == 0); + } + + /* Assemble the graph to be sent and send it */ + for (i=0; i<nvtxs; i++) { + ii = lpwgts[where[i]]; + sgraph[ii++] = xadj[i+1]-xadj[i]; + for (h=0; h<ncon; h++) + sgraph[ii++] = vwgt[i*ncon+h]; + for (j=xadj[i]; j<xadj[i+1]; j++) { + sgraph[ii++] = newlabel[adjncy[j]]; + sgraph[ii++] = adjwgt[j]; + } + lpwgts[where[i]] = ii; + } + + for (i=nparts; i>0; i--) + lpwgts[i] = lpwgts[i-1]; + lpwgts[0] = 0; + + for (i=0; i<nparts; i++) { + if (sinfo[i].key > 0) + MPI_Isend((void *)(sgraph+lpwgts[i]), lpwgts[i+1]-lpwgts[i], IDX_DATATYPE, i, 1, ctrl->comm, ctrl->sreq+i); + else + ASSERT(ctrl, lpwgts[i+1]-lpwgts[i] == 0); + } + +/* +#ifdef DMALLOC + ASSERT(ctrl, dmalloc_verify(NULL) == DMALLOC_VERIFY_NOERROR); +#endif +*/ + + /* Wait for the send/recv to finish */ + for (i=0; i<nparts; i++) { + if (sinfo[i].key > 0) + MPI_Wait(ctrl->sreq+i, &ctrl->status); + } + for (i=0; i<nparts; i++) { + if (rinfo[i].key > 0) + MPI_Wait(ctrl->rreq+i, &ctrl->status); + } + + /* OK, now go and put the graph into GraphType Format */ + mgraph = CreateGraph(); + mgraph->gnvtxs = graph->gnvtxs; + mgraph->ncon = ncon; + mgraph->level = 0; + mgraph->nvtxs = mgraph->nedges = 0; + for (i=0; i<nparts; i++) { + mgraph->nvtxs += rinfo[i].key; + mgraph->nedges += rinfo[i].val; + } + nvtxs = mgraph->nvtxs; + xadj = mgraph->xadj = idxmalloc(nvtxs+1, "MMG: mgraph->xadj"); + vwgt = mgraph->vwgt = idxmalloc(nvtxs*ncon, "MMG: mgraph->vwgt"); + adjncy = mgraph->adjncy = idxmalloc(mgraph->nedges, "MMG: mgraph->adjncy"); + adjwgt = mgraph->adjwgt = idxmalloc(mgraph->nedges, "MMG: mgraph->adjwgt"); + mgraph->vtxdist = mvtxdist; + + for (jj=ii=i=0; i<nvtxs; i++) { + xadj[i] = rgraph[ii++]; + for (h=0; h<ncon; h++) + vwgt[i*ncon+h] = rgraph[ii++]; + for (j=0; j<xadj[i]; j++) { + adjncy[jj] = rgraph[ii++]; + adjwgt[jj++] = rgraph[ii++]; + } + } + MAKECSR(i, nvtxs, xadj); + + ASSERTP(ctrl, jj == mgraph->nedges, (ctrl, "%d %d\n", jj, mgraph->nedges)); + ASSERTP(ctrl, ii == gpwgts[nparts], (ctrl, "%d %d %d %d %d\n", ii, gpwgts[nparts], jj, mgraph->nedges, nvtxs)); + + free(newlabel); + +#ifdef DEBUG + IFSET(ctrl->dbglvl, DBG_INFO, rprintf(ctrl, "Checking moved graph...\n")); + CheckMGraph(ctrl, mgraph); + IFSET(ctrl->dbglvl, DBG_INFO, rprintf(ctrl, "Moved graph is consistent.\n")); +#endif + + return mgraph; +} + + +/************************************************************************* +* This function is used to transfer information from the moved graph +* back to the original graph. The information is transfered from array +* minfo to array info. The routine assumes that graph->where is left intact +* and it is used to get the inverse mapping information. +* The routine assumes that graph->where corresponds to a npes-way partition. +**************************************************************************/ +void ProjectInfoBack(CtrlType *ctrl, GraphType *graph, idxtype *info, idxtype *minfo, + WorkSpaceType *wspace) +{ + int i, nvtxs, nparts; + idxtype *where, *auxinfo, *sinfo, *rinfo; + + nparts = ctrl->npes; + + nvtxs = graph->nvtxs; + where = graph->where; + + sinfo = wspace->pv1; + rinfo = wspace->pv2; + + /* Find out in rinfo how many entries are received per partition */ + idxset(nparts, 0, rinfo); + for (i=0; i<nvtxs; i++) + rinfo[where[i]]++; + + /* The rinfo are transposed and become the sinfo for the back-projection */ + MPI_Alltoall((void *)rinfo, 1, IDX_DATATYPE, (void *)sinfo, 1, IDX_DATATYPE, ctrl->comm); + + MAKECSR(i, nparts, sinfo); + MAKECSR(i, nparts, rinfo); + + /* allocate memory for auxinfo */ + auxinfo = idxmalloc(rinfo[nparts], "ProjectInfoBack: auxinfo"); + + /*----------------------------------------------------------------- + * Now, go and send back the minfo + -----------------------------------------------------------------*/ + for (i=0; i<nparts; i++) { + if (rinfo[i+1]-rinfo[i] > 0) + MPI_Irecv((void *)(auxinfo+rinfo[i]), rinfo[i+1]-rinfo[i], IDX_DATATYPE, i, 1, ctrl->comm, ctrl->rreq+i); + } + + for (i=0; i<nparts; i++) { + if (sinfo[i+1]-sinfo[i] > 0) + MPI_Isend((void *)(minfo+sinfo[i]), sinfo[i+1]-sinfo[i], IDX_DATATYPE, i, 1, ctrl->comm, ctrl->sreq+i); + } + + /* Wait for the send/recv to finish */ + for (i=0; i<nparts; i++) { + if (rinfo[i+1]-rinfo[i] > 0) + MPI_Wait(ctrl->rreq+i, &ctrl->status); + } + for (i=0; i<nparts; i++) { + if (sinfo[i+1]-sinfo[i] > 0) + MPI_Wait(ctrl->sreq+i, &ctrl->status); + } + + /* Scatter the info received in auxinfo back to info. */ + for (i=0; i<nvtxs; i++) + info[i] = auxinfo[rinfo[where[i]]++]; + + free(auxinfo); +} + + + +/************************************************************************* +* This function is used to convert a partition vector to a permutation +* vector. +**************************************************************************/ +void FindVtxPerm(CtrlType *ctrl, GraphType *graph, idxtype *perm, WorkSpaceType *wspace) +{ + int i, nvtxs, nparts; + idxtype *xadj, *adjncy, *adjwgt, *mvtxdist; + idxtype *where, *lpwgts, *gpwgts; + + nparts = ctrl->nparts; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + + mvtxdist = idxmalloc(nparts+1, "MoveGraph: mvtxdist"); + + /* Let's do a prefix scan to determine the labeling of the nodes given */ + lpwgts = wspace->pv1; + gpwgts = wspace->pv2; + + /* Here we care about the count and not total weight (diff since graph may be weighted */ + idxset(nparts, 0, lpwgts); + for (i=0; i<nvtxs; i++) + lpwgts[where[i]]++; + + MPI_Scan((void *)lpwgts, (void *)gpwgts, nparts, IDX_DATATYPE, MPI_SUM, ctrl->comm); + MPI_Allreduce((void *)lpwgts, (void *)mvtxdist, nparts, IDX_DATATYPE, MPI_SUM, ctrl->comm); + + MAKECSR(i, nparts, mvtxdist); + + for (i=0; i<nparts; i++) + gpwgts[i] = mvtxdist[i] + gpwgts[i] - lpwgts[i]; /* We were interested in an exclusive Scan */ + + for (i=0; i<nvtxs; i++) + perm[i] = gpwgts[where[i]]++; + + free(mvtxdist); + +} + + + + +/************************************************************************* +* This function quickly performs a check on the consistency of moved graph. +**************************************************************************/ +void CheckMGraph(CtrlType *ctrl, GraphType *graph) +{ + int i, j, jj, k, nvtxs, firstvtx, lastvtx; + idxtype *xadj, *adjncy, *vtxdist; + + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + vtxdist = graph->vtxdist; + + firstvtx = vtxdist[ctrl->mype]; + lastvtx = vtxdist[ctrl->mype+1]; + + for (i=0; i<nvtxs; i++) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + ASSERT(ctrl, firstvtx+i != adjncy[j]); + if (adjncy[j] >= firstvtx && adjncy[j] < lastvtx) { + k = adjncy[j]-firstvtx; + for (jj=xadj[k]; jj<xadj[k+1]; jj++) { + if (adjncy[jj] == firstvtx+i) + break; + } + if (jj == xadj[k+1]) + myprintf(ctrl, "(%d %d) but not (%d %d)\n", firstvtx+i, k, k, firstvtx+i); + } + } + } +} + + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/msetup.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/msetup.c new file mode 100644 index 0000000..decfc65 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/msetup.c @@ -0,0 +1,95 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * msetup.c + * + * This file contain various routines for setting up a mesh + * + * Started 10/19/96 + * George + * + * $Id: msetup.c,v 1.3 2003/07/31 06:14:01 karypis Exp $ + * + */ + +#include <parmetis.h> + + + +/************************************************************************* +* This function setsup the CtrlType structure +**************************************************************************/ +MeshType *SetUpMesh(int *etype, int *ncon, idxtype *elmdist, idxtype *elements, + idxtype *elmwgt, int *wgtflag, MPI_Comm *comm) +{ + MeshType *mesh; + int i, npes, mype; + int esizes[5] = {-1, 3, 4, 8, 4}; + int maxnode, gmaxnode, minnode, gminnode; + + MPI_Comm_size(*comm, &npes); + MPI_Comm_rank(*comm, &mype); + + mesh = CreateMesh(); + mesh->elmdist = elmdist; + mesh->gnelms = elmdist[npes]; + mesh->nelms = elmdist[mype+1]-elmdist[mype]; + mesh->elements = elements; + mesh->elmwgt = elmwgt; + mesh->etype = *etype; + mesh->ncon = *ncon; + mesh->esize = esizes[*etype]; + + if (((*wgtflag)&1) == 0) { + mesh->elmwgt = idxsmalloc(mesh->nelms*mesh->ncon, 1, "SetUpMesh: elmwgt"); + } + + minnode = elements[idxamin(mesh->nelms*mesh->esize, elements)]; + MPI_Allreduce((void *)&minnode, (void *)&gminnode, 1, MPI_INT, MPI_MIN, *comm); + for (i=0; i<mesh->nelms*mesh->esize; i++) + elements[i] -= gminnode; + mesh->gminnode = gminnode; + + maxnode = elements[idxamax(mesh->nelms*mesh->esize, elements)]; + MPI_Allreduce((void *)&maxnode, (void *)&gmaxnode, 1, MPI_INT, MPI_MAX, *comm); + mesh->gnns = gmaxnode+1; + + return mesh; +} + +/************************************************************************* +* This function creates a MeshType data structure and initializes +* the various fields +**************************************************************************/ +MeshType *CreateMesh(void) +{ + MeshType *mesh; + + mesh = (MeshType *)GKmalloc(sizeof(MeshType), "CreateMesh: mesh"); + + InitMesh(mesh); + + return mesh; +} + +/************************************************************************* +* This function initializes the various fields of a MeshType. +**************************************************************************/ +void InitMesh(MeshType *mesh) +{ + + mesh->etype = -1; + mesh->gnelms = -1; + mesh->gnns = -1; + mesh->nelms = -1; + mesh->nns = -1; + mesh->ncon = -1; + mesh->esize = -1; + mesh->gminnode = 0; + mesh->elmdist = NULL; + mesh->elements = NULL; + mesh->elmwgt = NULL; + + return; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/node_refine.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/node_refine.c new file mode 100644 index 0000000..3f57aa7 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/node_refine.c @@ -0,0 +1,383 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * node_refine.c + * + * This file contains code that performs the k-way refinement + * + * Started 3/1/96 + * George + * + * $Id: node_refine.c,v 1.2 2003/07/21 17:18:50 karypis Exp $ + */ + +#include <parmetislib.h> + +#define PackWeightWhereInfo(a, b) (((a)<<10) + (b)) +#define SelectWhere(a) ((a)%1024) +#define SelectWeight(a) (((a)>>10)) + + + +/************************************************************************* +* This function computes the initial id/ed +**************************************************************************/ +void ComputeNodePartitionParams(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int i, j, nparts, nvtxs, nsep, firstvtx, lastvtx; + idxtype *xadj, *ladjncy, *adjwgt, *vtxdist, *vwgt, *lpwgts, *gpwgts, *sepind; + idxtype *where, *swhere, *rwhere; + NRInfoType *rinfo, *myrinfo; + int me, other, otherwgt; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->KWayInitTmr)); + + nvtxs = graph->nvtxs; + nparts = ctrl->nparts; + + vtxdist = graph->vtxdist; + xadj = graph->xadj; + ladjncy = graph->adjncy; + adjwgt = graph->adjwgt; + vwgt = graph->vwgt; + + where = graph->where; + rinfo = graph->nrinfo = (NRInfoType *)GKmalloc(sizeof(NRInfoType)*nvtxs, "ComputeNodePartitionParams: rinfo"); + lpwgts = graph->lpwgts = idxsmalloc(2*nparts, 0, "ComputePartitionParams: lpwgts"); + gpwgts = graph->gpwgts = idxmalloc(2*nparts, "ComputePartitionParams: gpwgts"); + sepind = graph->sepind = idxmalloc(nvtxs, "ComputePartitionParams: sepind"); + + firstvtx = vtxdist[ctrl->mype]; + lastvtx = vtxdist[ctrl->mype+1]; + + /*------------------------------------------------------------ + / Send/Receive the where information of interface vertices. + / Also use this to also encode the vwgt information of this + / vertex. This is a hack, but it should work for now! + /------------------------------------------------------------*/ + swhere = wspace->indices; + rwhere = where + nvtxs; + + for (i=0; i<nvtxs; i++) { + ASSERTP(ctrl, where[i] >= 0 && where[i] < 2*nparts, (ctrl, "%d\n", where[i]) ); + where[i] = PackWeightWhereInfo(vwgt[i], where[i]); + } + + CommInterfaceData(ctrl, graph, where, swhere, rwhere); + + /*------------------------------------------------------------ + / Compute now the degrees + /------------------------------------------------------------*/ + for (nsep=i=0; i<nvtxs; i++) { + me = SelectWhere(where[i]); + ASSERT(ctrl, me >= 0 && me < 2*nparts); + lpwgts[me] += vwgt[i]; + + if (me >= nparts) { /* If it is a separator vertex */ + sepind[nsep++] = i; + lpwgts[2*nparts-1] += vwgt[i]; + + myrinfo = rinfo+i; + myrinfo->edegrees[0] = myrinfo->edegrees[1] = 0; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + other = SelectWhere(where[ladjncy[j]]); + otherwgt = SelectWeight(where[ladjncy[j]]); + if (me != other) + myrinfo->edegrees[other%2] += otherwgt; + } + } + } + graph->nsep = nsep; + + /* Finally, sum-up the partition weights */ + MPI_Allreduce((void *)lpwgts, (void *)gpwgts, 2*nparts, IDX_DATATYPE, MPI_SUM, ctrl->comm); + graph->mincut = gpwgts[2*nparts-1]; + +#ifdef XX + /* Print Weight information */ + if (ctrl->mype == 0) { + for (i=0; i<nparts; i+=2) + printf("[%5d %5d %5d] ", gpwgts[i], gpwgts[i+1], gpwgts[nparts+i]); + printf("\n"); + } +#endif + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->KWayInitTmr)); +} + + + +/************************************************************************* +* This function performs k-way refinement +**************************************************************************/ +void KWayNodeRefine(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace, int npasses, float ubfraction) +{ + int i, ii, j, k, pass, nvtxs, firstvtx, lastvtx, otherlastvtx, c, nmoves, + nlupd, nsupd, nnbrs, nchanged, nsep; + int npes = ctrl->npes, mype = ctrl->mype, nparts = ctrl->nparts; + idxtype *xadj, *ladjncy, *adjwgt, *vtxdist, *vwgt; + idxtype *where, *lpwgts, *gpwgts, *sepind; + idxtype *peind, *recvptr, *sendptr; + idxtype *update, *supdate, *rupdate, *pe_updates, *htable, *changed; + idxtype *badminpwgt, *badmaxpwgt; + KeyValueType *swchanges, *rwchanges; + int *nupds_pe; + NRInfoType *rinfo, *myrinfo; + int from, me, other, otherwgt, oldcut; + + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->KWayTmr)); + + nvtxs = graph->nvtxs; + + vtxdist = graph->vtxdist; + xadj = graph->xadj; + ladjncy = graph->adjncy; + adjwgt = graph->adjwgt; + vwgt = graph->vwgt; + + firstvtx = vtxdist[mype]; + lastvtx = vtxdist[mype+1]; + + where = graph->where; + rinfo = graph->nrinfo; + lpwgts = graph->lpwgts; + gpwgts = graph->gpwgts; + + nsep = graph->nsep; + sepind = graph->sepind; + + nnbrs = graph->nnbrs; + peind = graph->peind; + recvptr = graph->recvptr; + sendptr = graph->sendptr; + + changed = idxmalloc(nvtxs, "KWayRefine: changed"); + rwchanges = wspace->pairs; + swchanges = rwchanges + recvptr[nnbrs]; + + update = idxmalloc(nvtxs, "KWayRefine: update"); + supdate = wspace->indices; + rupdate = supdate + recvptr[nnbrs]; + nupds_pe = imalloc(npes, "KWayRefine: nupds_pe"); + + htable = idxsmalloc(nvtxs+graph->nrecv, 0, "KWayRefine: lhtable"); + + badminpwgt = wspace->pv1; + badmaxpwgt = wspace->pv2; + + for (i=0; i<nparts; i+=2) { + badminpwgt[i] = badminpwgt[i+1] = (1.0/ubfraction)*(gpwgts[i]+gpwgts[i+1])/2; + badmaxpwgt[i] = badmaxpwgt[i+1] = ubfraction*(gpwgts[i]+gpwgts[i+1])/2; + } + + IFSET(ctrl->dbglvl, DBG_REFINEINFO, PrintNodeBalanceInfo(ctrl, nparts, gpwgts, badminpwgt, badmaxpwgt, 1)); + + for (pass=0; pass<npasses; pass++) { + oldcut = graph->mincut; + + for (c=0; c<2; c++) { + for (i=0; i<nparts; i+=2) { + badminpwgt[i] = badminpwgt[i+1] = (1.0/ubfraction)*(gpwgts[i]+gpwgts[i+1])/2; + badmaxpwgt[i] = badmaxpwgt[i+1] = ubfraction*(gpwgts[i]+gpwgts[i+1])/2; + } + + nlupd = nsupd = nmoves = nchanged = 0; + for (ii=0; ii<nsep; ii++) { + i = sepind[ii]; + from = SelectWhere(where[i]); + + ASSERT(ctrl, from >= nparts); + + /* Go through the loop if gain is possible for the separator vertex */ + if (rinfo[i].edegrees[(c+1)%2] <= vwgt[i]) { + other = from%nparts+c; /* It is one-sided move so we know where it goes */ + + if (gpwgts[other]+vwgt[i] > badmaxpwgt[other]) { + /* printf("Skip because of weight! %d\n", vwgt[i]-rinfo[i].edegrees[(c+1)%2]); */ + continue; /* We cannot move it there because it gets too heavy */ + } + + /* Update where, weight, and ID/ED information of the vertex you moved */ + where[i] = PackWeightWhereInfo(vwgt[i], other); + + /* Remove this vertex from the sepind. Note the trick for looking at the sepind[ii] again */ + sepind[ii--] = sepind[--nsep]; + + /* myprintf(ctrl, "Vertex %d [%d %d] is moving to %d from %d [%d]\n", i+firstvtx, vwgt[i], rinfo[i].edegrees[(c+1)%2], other, from, SelectWhere(where[i])); */ + + lpwgts[from] -= vwgt[i]; + lpwgts[2*nparts-1] -= vwgt[i]; + lpwgts[other] += vwgt[i]; + gpwgts[other] += vwgt[i]; + + /* + * Put the vertices adjacent to i that belong to either the separator or + * the (c+1)%2 partition into the update array + */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = ladjncy[j]; + if (htable[k] == 0 && SelectWhere(where[k]) != other) { + htable[k] = 1; + if (k<nvtxs) + update[nlupd++] = k; + else + supdate[nsupd++] = k; + } + } + nmoves++; + if (graph->pexadj[i+1]-graph->pexadj[i] > 0) + changed[nchanged++] = i; + } + } + + /* myprintf(ctrl, "nmoves: %d, nlupd: %d, nsupd: %d\n", nmoves, nlupd, nsupd); */ + + /* Tell everybody interested what the new where[] info is for the interface vertices */ + CommChangedInterfaceData(ctrl, graph, nchanged, changed, where, swchanges, rwchanges, wspace->pv4); + + + IFSET(ctrl->dbglvl, DBG_RMOVEINFO, rprintf(ctrl, "\t[%d %d], [%d %d %d]\n", + pass, c, GlobalSESum(ctrl, nmoves), GlobalSESum(ctrl, nsupd), GlobalSESum(ctrl, nlupd))); + + + /*------------------------------------------------------------- + / Time to communicate with processors to send the vertices + / whose degrees need to be update. + /-------------------------------------------------------------*/ + /* Issue the receives first */ + for (i=0; i<nnbrs; i++) { + MPI_Irecv((void *)(rupdate+sendptr[i]), sendptr[i+1]-sendptr[i], IDX_DATATYPE, + peind[i], 1, ctrl->comm, ctrl->rreq+i); + } + + /* Issue the sends next. This needs some preporcessing */ + for (i=0; i<nsupd; i++) { + htable[supdate[i]] = 0; + supdate[i] = graph->imap[supdate[i]]; + } + iidxsort(nsupd, supdate); + + for (j=i=0; i<nnbrs; i++) { + otherlastvtx = vtxdist[peind[i]+1]; + for (k=j; k<nsupd && supdate[k] < otherlastvtx; k++); + MPI_Isend((void *)(supdate+j), k-j, IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->sreq+i); + j = k; + } + + /* OK, now get into the loop waiting for the send/recv operations to finish */ + MPI_Waitall(nnbrs, ctrl->rreq, ctrl->statuses); + for (i=0; i<nnbrs; i++) + MPI_Get_count(ctrl->statuses+i, IDX_DATATYPE, nupds_pe+i); + MPI_Waitall(nnbrs, ctrl->sreq, ctrl->statuses); + + + /*------------------------------------------------------------- + / Place the received to-be updated vertices into update[] + /-------------------------------------------------------------*/ + for (i=0; i<nnbrs; i++) { + pe_updates = rupdate+sendptr[i]; + for (j=0; j<nupds_pe[i]; j++) { + k = pe_updates[j]; + if (htable[k-firstvtx] == 0) { + htable[k-firstvtx] = 1; + update[nlupd++] = k-firstvtx; + } + } + } + + + /*------------------------------------------------------------- + / Update the where information of the vertices that are pulled + / into the separator. + /-------------------------------------------------------------*/ + nchanged = 0; + for (ii=0; ii<nlupd; ii++) { + i = update[ii]; + me = SelectWhere(where[i]); + if (me < nparts && me%2 == (c+1)%2) { /* This vertex is pulled into the separator */ + lpwgts[me] -= vwgt[i]; + where[i] = PackWeightWhereInfo(vwgt[i], nparts+me-(me%2)); + sepind[nsep++] = i; /* Put the vertex into the sepind array */ + if (graph->pexadj[i+1]-graph->pexadj[i] > 0) + changed[nchanged++] = i; + + lpwgts[SelectWhere(where[i])] += vwgt[i]; + lpwgts[2*nparts-1] += vwgt[i]; + /* myprintf(ctrl, "Vertex %d moves into the separator from %d to %d\n", i+firstvtx, me, SelectWhere(where[i])); */ + } + } + + /* Tell everybody interested what the new where[] info is for the interface vertices */ + CommChangedInterfaceData(ctrl, graph, nchanged, changed, where, swchanges, rwchanges, wspace->pv4); + + + /*------------------------------------------------------------- + / Update the rinfo of the vertices in the update[] array + /-------------------------------------------------------------*/ + for (ii=0; ii<nlupd; ii++) { + i = update[ii]; + ASSERT(ctrl, htable[i] == 1); + + htable[i] = 0; + + me = SelectWhere(where[i]); + if (me >= nparts) { /* If it is a separator vertex */ + /* myprintf(ctrl, "Updating %d %d\n", i+firstvtx, me); */ + + myrinfo = rinfo+i; + myrinfo->edegrees[0] = myrinfo->edegrees[1] = 0; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + other = SelectWhere(where[ladjncy[j]]); + otherwgt = SelectWeight(where[ladjncy[j]]); + if (me != other) + myrinfo->edegrees[other%2] += otherwgt; + } + } + } + + /* Finally, sum-up the partition weights */ + MPI_Allreduce((void *)lpwgts, (void *)gpwgts, 2*nparts, IDX_DATATYPE, MPI_SUM, ctrl->comm); + graph->mincut = gpwgts[2*nparts-1]; + + IFSET(ctrl->dbglvl, DBG_REFINEINFO, PrintNodeBalanceInfo(ctrl, nparts, gpwgts, badminpwgt, badmaxpwgt, 0)); + } + + if (graph->mincut == oldcut) + break; + } + + /* Go and clear-up the where array */ + for (i=0; i<nvtxs+graph->nrecv; i++) + where[i] = SelectWhere(where[i]); + + GKfree((void **)&update, (void **)&nupds_pe, (void **)&htable, (void **)&changed, LTERM); + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->KWayTmr)); +} + + + + +/************************************************************************* +* This function prints balance information for the parallel k-section +* refinement algorithm +**************************************************************************/ +void PrintNodeBalanceInfo(CtrlType *ctrl, int nparts, idxtype *gpwgts, idxtype *badminpwgt, idxtype *badmaxpwgt, int title) +{ + int i; + + if (ctrl->mype == 0) { + if (title) + printf("K-way sep-refinement: TotalSep: %d, ", gpwgts[2*nparts-1]); + else + printf("\tTotalSep: %d, ", gpwgts[2*nparts-1]); + + for (i=0; i<nparts; i+=2) + printf(" [%5d %5d %5d %5d %5d]", gpwgts[i], gpwgts[i+1], gpwgts[nparts+i], badminpwgt[i], badmaxpwgt[i]); + printf("\n"); + } + MPI_Barrier(ctrl->comm); +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/ometis.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/ometis.c new file mode 100644 index 0000000..1a461f1 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/ometis.c @@ -0,0 +1,188 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * ometis.c + * + * This is the entry point of parallel ordering + * + * Started 10/19/96 + * George + * + * $Id: ometis.c,v 1.4 2003/07/25 04:01:04 karypis Exp $ + * + */ + +#include <parmetislib.h> + + + + +/*********************************************************************************** +* This function is the entry point of the parallel ordering algorithm. +* This function assumes that the graph is already nice partitioned among the +* processors and then proceeds to perform recursive bisection. +************************************************************************************/ +void ParMETIS_V3_NodeND(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, int *numflag, + int *options, idxtype *order, idxtype *sizes, MPI_Comm *comm) +{ + int i, j; + int ltvwgts[MAXNCON]; + int nparts, npes, mype, wgtflag = 0, seed = GLOBAL_SEED; + CtrlType ctrl; + WorkSpaceType wspace; + GraphType *graph, *mgraph; + idxtype *morder; + int minnvtxs; + + MPI_Comm_size(*comm, &npes); + MPI_Comm_rank(*comm, &mype); + nparts = npes; + + if (!ispow2(npes)) { + if (mype == 0) + printf("Error: The number of processors must be a power of 2!\n"); + return; + } + + if (vtxdist[npes] < (int)((float)(npes*npes)*1.2)) { + if (mype == 0) + printf("Error: Too many processors for this many vertices.\n"); + return; + } + + minnvtxs = vtxdist[1]-vtxdist[0]; + for (i=0; i<npes; i++) + minnvtxs = (minnvtxs < vtxdist[i+1]-vtxdist[i]) ? minnvtxs : vtxdist[i+1]-vtxdist[i]; + + if (minnvtxs < (int)((float)npes*1.1)) { + if (mype == 0) + printf("Error: vertices are not distributed equally.\n"); + return; + } + + + if (*numflag == 1) + ChangeNumbering(vtxdist, xadj, adjncy, order, npes, mype, 1); + + SetUpCtrl(&ctrl, nparts, options[PMV3_OPTION_DBGLVL], *comm); + ctrl.CoarsenTo = amin(vtxdist[npes]+1, 25*npes); + + ctrl.CoarsenTo = amin(vtxdist[npes]+1, 25*amax(npes, nparts)); + ctrl.seed = mype; + ctrl.sync = seed; + ctrl.partType = STATIC_PARTITION; + ctrl.ps_relation = -1; + ctrl.tpwgts = fsmalloc(nparts, 1.0/(float)(nparts), "tpwgts"); + ctrl.ubvec[0] = 1.03; + + graph = Moc_SetUpGraph(&ctrl, 1, vtxdist, xadj, NULL, adjncy, NULL, &wgtflag); + + PreAllocateMemory(&ctrl, graph, &wspace); + + /*======================================================= + * Compute the initial k-way partitioning + =======================================================*/ + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + Moc_Global_Partition(&ctrl, graph, &wspace); + + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimingInfo(&ctrl)); + + /*======================================================= + * Move the graph according to the partitioning + =======================================================*/ + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.MoveTmr)); + + MALLOC_CHECK(NULL); + graph->ncon = 1; + mgraph = Moc_MoveGraph(&ctrl, graph, &wspace); + MALLOC_CHECK(NULL); + + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.MoveTmr)); + + /*======================================================= + * Now compute an ordering of the moved graph + =======================================================*/ + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + FreeWSpace(&wspace); + PreAllocateMemory(&ctrl, mgraph, &wspace); + + ctrl.ipart = ISEP_NODE; + ctrl.CoarsenTo = amin(vtxdist[npes]+1, amax(20*npes, 1000)); + + /* compute tvwgts */ + for (j=0; j<mgraph->ncon; j++) + ltvwgts[j] = 0; + + for (i=0; i<mgraph->nvtxs; i++) + for (j=0; j<mgraph->ncon; j++) + ltvwgts[j] += mgraph->vwgt[i*mgraph->ncon+j]; + + for (j=0; j<mgraph->ncon; j++) + ctrl.tvwgts[j] = GlobalSESum(&ctrl, ltvwgts[j]); + + mgraph->nvwgt = fmalloc(mgraph->nvtxs*mgraph->ncon, "mgraph->nvwgt"); + for (i=0; i<mgraph->nvtxs; i++) + for (j=0; j<mgraph->ncon; j++) + mgraph->nvwgt[i*mgraph->ncon+j] = (float)(mgraph->vwgt[i*mgraph->ncon+j]) / (float)(ctrl.tvwgts[j]); + + + morder = idxmalloc(mgraph->nvtxs, "PAROMETIS: morder"); + MultilevelOrder(&ctrl, mgraph, morder, sizes, &wspace); + + MALLOC_CHECK(NULL); + + /* Invert the ordering back to the original graph */ + ProjectInfoBack(&ctrl, graph, order, morder, &wspace); + + MALLOC_CHECK(NULL); + + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimingInfo(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + + free(ctrl.tpwgts); + free(morder); + FreeGraph(mgraph); + FreeInitialGraphAndRemap(graph, 0); + FreeWSpace(&wspace); + FreeCtrl(&ctrl); + + if (*numflag == 1) + ChangeNumbering(vtxdist, xadj, adjncy, order, npes, mype, 0); + + MALLOC_CHECK(NULL); +} + + +/*********************************************************************************** +* This function is the entry point of the parallel ordering algorithm. +* This function assumes that the graph is already nice partitioned among the +* processors and then proceeds to perform recursive bisection. +************************************************************************************/ +void PAROMETIS(idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + idxtype *order, idxtype *sizes, int *options, MPI_Comm comm) +{ + int numflag, newoptions[5]; + + newoptions[0] = 1; + newoptions[PMV3_OPTION_DBGLVL] = options[4]; + newoptions[PMV3_OPTION_SEED] = GLOBAL_SEED; + + numflag = options[3]; + + ParMETIS_V3_NodeND(vtxdist, xadj, adjncy, &numflag, newoptions, order, sizes, &comm); + + options[0] = -1; + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/order.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/order.c new file mode 100644 index 0000000..a73c87b --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/order.c @@ -0,0 +1,348 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * order.c + * + * This file contains the driving routines for the multilevel ordering algorithm + * + * Started 5/3/97 + * George + * + * $Id: order.c,v 1.2 2003/07/21 17:18:50 karypis Exp $ + * + */ + +#define DEBUG_ORDER_ + +#include <parmetislib.h> + +/************************************************************************* +* This is the top level ordering routine +**************************************************************************/ +void MultilevelOrder(CtrlType *ctrl, GraphType *graph, idxtype *order, idxtype *sizes, WorkSpaceType *wspace) +{ + int i, nparts, nvtxs, npes; + idxtype *perm, *lastnode, *morder, *porder; + GraphType *mgraph; + + npes = ctrl->npes; + nvtxs = graph->nvtxs; + + perm = idxmalloc(nvtxs, "MultilevelOrder: perm"); + lastnode = idxsmalloc(4*npes, -1, "MultilevelOrder: lastnode"); + + for (i=0; i<nvtxs; i++) + perm[i] = i; + lastnode[2] = graph->gnvtxs; + + idxset(nvtxs, -1, order); + + sizes[0] = 2*npes-1; + + graph->where = idxsmalloc(nvtxs, 0, "MultilevelOrder: graph->where"); + + for (nparts=2; nparts<=ctrl->npes; nparts*=2) { + ctrl->nparts = nparts; + + Order_Partition(ctrl, graph, wspace); + + LabelSeparators(ctrl, graph, lastnode, perm, order, sizes, wspace); + + CompactGraph(ctrl, graph, perm, wspace); + + if (ctrl->CoarsenTo < 100*nparts) { + ctrl->CoarsenTo = 1.5*ctrl->CoarsenTo; + } + ctrl->CoarsenTo = amin(ctrl->CoarsenTo, graph->gnvtxs-1); + } + + + /*----------------------------------------------------------------- + / Move the graph so that each processor gets its partition + -----------------------------------------------------------------*/ + IFSET(ctrl->dbglvl, DBG_TIME, MPI_Barrier(ctrl->comm)); + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->MoveTmr)); + + SetUp(ctrl, graph, wspace); + graph->ncon = 1; /*needed for Moc_MoveGraph */ + mgraph = Moc_MoveGraph(ctrl, graph, wspace); + + /* Fill in the sizes[] array for the local part. Just the vtxdist of the mgraph */ + for (i=0; i<npes; i++) + sizes[i] = mgraph->vtxdist[i+1]-mgraph->vtxdist[i]; + + porder = idxmalloc(graph->nvtxs, "MultilevelOrder: porder"); + morder = idxmalloc(mgraph->nvtxs, "MultilevelOrder: morder"); + + IFSET(ctrl->dbglvl, DBG_TIME, MPI_Barrier(ctrl->comm)); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->MoveTmr)); + + /* Find the local ordering */ + LocalNDOrder(ctrl, mgraph, morder, lastnode[2*(ctrl->npes+ctrl->mype)]-mgraph->nvtxs, wspace); + + /* Project the ordering back to the before-move graph */ + ProjectInfoBack(ctrl, graph, porder, morder, wspace); + + /* Copy the ordering from porder to order using perm */ + for (i=0; i<graph->nvtxs; i++) { + ASSERT(ctrl, order[perm[i]] == -1); + order[perm[i]] = porder[i]; + } + + FreeGraph(mgraph); + GKfree((void **)&perm, (void **)&lastnode, (void **)&porder, (void **)&morder, LTERM); + + /* PrintVector(ctrl, 2*npes-1, 0, sizes, "SIZES"); */ +} + + +/************************************************************************* +* This function is used to assign labels to the nodes in the separators +* It uses the appropriate entry in the lastnode array to select label +* boundaries and adjusts it for the next level +**************************************************************************/ +void LabelSeparators(CtrlType *ctrl, GraphType *graph, idxtype *lastnode, idxtype *perm, idxtype *order, idxtype *sizes, WorkSpaceType *wspace) +{ + int i, nvtxs, nparts, sid; + idxtype *where, *lpwgts, *gpwgts, *sizescan; + + nparts = ctrl->nparts; + + nvtxs = graph->nvtxs; + where = graph->where; + lpwgts = graph->lpwgts; + gpwgts = graph->gpwgts; + + /* Compute the local size of the separator. This is required in case the + * graph has vertex weights */ + idxset(2*nparts, 0, lpwgts); + for (i=0; i<nvtxs; i++) + lpwgts[where[i]]++; + + sizescan = idxmalloc(2*nparts, "LabelSeparators: sizescan"); + + /* Perform a Prefix scan of the separator sizes to determine the boundaries */ + MPI_Scan((void *)lpwgts, (void *)sizescan, 2*nparts, IDX_DATATYPE, MPI_SUM, ctrl->comm); + MPI_Allreduce((void *)lpwgts, (void *)gpwgts, 2*nparts, IDX_DATATYPE, MPI_SUM, ctrl->comm); + +#ifdef DEBUG_ORDER + PrintVector(ctrl, 2*nparts, 0, lpwgts, "Lpwgts"); + PrintVector(ctrl, 2*nparts, 0, sizescan, "SizeScan"); + PrintVector(ctrl, 2*nparts, 0, lastnode, "LastNode"); +#endif + + /* Fillin the sizes[] array */ + for (i=nparts-2; i>=0; i-=2) + sizes[--sizes[0]] = gpwgts[nparts+i]; + + if (ctrl->dbglvl&DBG_INFO) { + if (ctrl->mype == 0) { + printf("SepSizes: "); + for (i=0; i<nparts; i+=2) + printf(" %d [%d %d]", gpwgts[nparts+i], gpwgts[i], gpwgts[i+1]); + printf("\n"); + } + MPI_Barrier(ctrl->comm); + } + + for (i=0; i<2*nparts; i++) + sizescan[i] -= lpwgts[i]; + + for (i=0; i<nvtxs; i++) { + if (where[i] >= nparts) { + sid = where[i]; + sizescan[sid]++; + ASSERT(ctrl, order[perm[i]] == -1); + order[perm[i]] = lastnode[sid] - sizescan[sid]; + /* myprintf(ctrl, "order[%d] = %d, %d\n", perm[i], order[perm[i]], sid); */ + } + } + + /* Update lastnode array */ + idxcopy(2*nparts, lastnode, sizescan); + for (i=0; i<nparts; i+=2) { + lastnode[2*nparts+2*i] = sizescan[nparts+i]-gpwgts[nparts+i]-gpwgts[i+1]; + lastnode[2*nparts+2*(i+1)] = sizescan[nparts+i]-gpwgts[nparts+i]; + } + + free(sizescan); + +} + + + + +/************************************************************************* +* This function compacts a graph by removing the vertex separator +**************************************************************************/ +void CompactGraph(CtrlType *ctrl, GraphType *graph, idxtype *perm, WorkSpaceType *wspace) +{ + int i, j, l, nvtxs, cnvtxs, cfirstvtx, nparts, npes; + idxtype *xadj, *ladjncy, *adjwgt, *vtxdist, *where; + idxtype *cmap, *cvtxdist, *newwhere; + + nparts = ctrl->nparts; + npes = ctrl->npes; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + ladjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + + if (graph->cmap == NULL) + graph->cmap = idxmalloc(nvtxs+graph->nrecv, "CompactGraph: cmap"); + cmap = graph->cmap; + + vtxdist = graph->vtxdist; + + /************************************************************* + * Construct the cvtxdist of the contracted graph. Uses the fact + * that lpwgts stores the local non separator vertices. + **************************************************************/ + cvtxdist = wspace->pv1; + cnvtxs = cvtxdist[npes] = idxsum(nparts, graph->lpwgts); + + MPI_Allgather((void *)(cvtxdist+npes), 1, IDX_DATATYPE, (void *)cvtxdist, 1, IDX_DATATYPE, ctrl->comm); + MAKECSR(i, npes, cvtxdist); + +#ifdef DEBUG_ORDER + PrintVector(ctrl, npes+1, 0, cvtxdist, "cvtxdist"); +#endif + + + /************************************************************* + * Construct the cmap vector + **************************************************************/ + cfirstvtx = cvtxdist[ctrl->mype]; + + /* Create the cmap of what you know so far locally */ + for (cnvtxs=0, i=0; i<nvtxs; i++) { + if (where[i] < nparts) { + perm[cnvtxs] = perm[i]; + cmap[i] = cfirstvtx + cnvtxs++; + } + } + + CommInterfaceData(ctrl, graph, cmap, wspace->indices, cmap+nvtxs); + + + /************************************************************* + * Finally, compact the graph + **************************************************************/ + newwhere = idxmalloc(cnvtxs, "CompactGraph: newwhere"); + cnvtxs = l = 0; + for (i=0; i<nvtxs; i++) { + if (where[i] < nparts) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (where[i] == where[ladjncy[j]]) { + ladjncy[l] = cmap[ladjncy[j]]; + adjwgt[l++] = adjwgt[j]; + } +#ifdef DEBUG_ORDER + else if (where[ladjncy[j]] < nparts) + printf("It seems that the separation has failed: %d %d\n", where[i], where[ladjncy[j]]); +#endif + } + + xadj[cnvtxs] = l; + graph->vwgt[cnvtxs] = graph->vwgt[i]; + newwhere[cnvtxs] = where[i]; + cnvtxs++; + } + } + for (i=cnvtxs; i>0; i--) + xadj[i] = xadj[i-1]; + xadj[0] = 0; + + GKfree((void **)&graph->match, (void **)&graph->cmap, (void **)&graph->lperm, (void **)&graph->where, (void **)&graph->label, (void **)&graph->rinfo, + (void **)&graph->nrinfo, (void **)&graph->lpwgts, (void **)&graph->gpwgts, (void **)&graph->sepind, (void **)&graph->peind, + (void **)&graph->sendptr, (void **)&graph->sendind, (void **)&graph->recvptr, (void **)&graph->recvind, + (void **)&graph->imap, (void **)&graph->rlens, (void **)&graph->slens, (void **)&graph->rcand, (void **)&graph->pexadj, + (void **)&graph->peadjncy, (void **)&graph->peadjloc, LTERM); + + graph->nvtxs = cnvtxs; + graph->nedges = l; + graph->gnvtxs = cvtxdist[npes]; + idxcopy(npes+1, cvtxdist, graph->vtxdist); + graph->where = newwhere; + +} + + +/************************************************************************* +* This function orders the locally stored graph using MMD. +* The vertices will be ordered from firstnode onwards. +**************************************************************************/ +void LocalNDOrder(CtrlType *ctrl, GraphType *graph, idxtype *order, int firstnode, WorkSpaceType *wspace) +{ + int i, j, nvtxs, firstvtx, lastvtx; + idxtype *xadj, *adjncy; + idxtype *perm, *iperm; + int numflag=0, options[10]; + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + + firstvtx = graph->vtxdist[ctrl->mype]; + lastvtx = graph->vtxdist[ctrl->mype+1]; + + /* Relabel the vertices so that they are in local index space */ + for (i=0; i<nvtxs; i++) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + ASSERT(ctrl, adjncy[j]>=firstvtx && adjncy[j]<lastvtx); + adjncy[j] -= firstvtx; + } + } + + ASSERT(ctrl, 2*(nvtxs+5) < wspace->maxcore); + + perm = wspace->core; + iperm = perm + nvtxs + 5; + + options[0] = 0; + METIS_NodeND(&nvtxs, xadj, adjncy, &numflag, options, perm, iperm); + + for (i=0; i<nvtxs; i++) { + ASSERT(ctrl, iperm[i]>=0 && iperm[i]<nvtxs); + order[i] = firstnode+iperm[i]; + } + +} + +/************************************************************************* +* This function is the driver for the partition refinement mode of ParMETIS +**************************************************************************/ +void Order_Partition(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + + SetUp(ctrl, graph, wspace); + graph->ncon = 1; + + IFSET(ctrl->dbglvl, DBG_PROGRESS, rprintf(ctrl, "[%6d %8d %5d %5d][%d][%d]\n", + graph->gnvtxs, GlobalSESum(ctrl, graph->nedges), GlobalSEMin(ctrl, graph->nvtxs), + GlobalSEMax(ctrl, graph->nvtxs), ctrl->CoarsenTo, + GlobalSEMax(ctrl, graph->vwgt[idxamax(graph->nvtxs, graph->vwgt)]))); + + if (graph->gnvtxs < 1.3*ctrl->CoarsenTo || (graph->finer != NULL && graph->gnvtxs > graph->finer->gnvtxs*COARSEN_FRACTION)) { + /* Compute the initial npart-way multisection */ + InitMultisection(ctrl, graph, wspace); + + if (graph->finer == NULL) { /* Do that only of no-coarsening took place */ + ComputeNodePartitionParams(ctrl, graph, wspace); + KWayNodeRefine(ctrl, graph, wspace, 2*NGR_PASSES, ORDER_UNBALANCE_FRACTION); + } + } + else { /* Coarsen it and the partition it */ + Mc_LocalMatch_HEM(ctrl, graph, wspace); + + Order_Partition(ctrl, graph->coarser, wspace); + + Moc_ProjectPartition(ctrl, graph, wspace); + ComputeNodePartitionParams(ctrl, graph, wspace); + KWayNodeRefine(ctrl, graph, wspace, 2*NGR_PASSES, ORDER_UNBALANCE_FRACTION); + } +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/parmetislib.h b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/parmetislib.h new file mode 100644 index 0000000..36c1041 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/parmetislib.h @@ -0,0 +1,31 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * par_metis.h + * + * This file includes all necessary header files + * + * Started 8/27/94 + * George + * + * $Id: parmetislib.h,v 1.2 2003/07/21 17:50:22 karypis Exp $ + */ + +/* +#define DEBUG 1 +#define DMALLOC 1 +*/ + +#include <stdheaders.h> +#include "../parmetis.h" + +#ifdef DMALLOC +#include <dmalloc.h> +#endif + +#include <rename.h> +#include <defs.h> +#include <struct.h> +#include <macros.h> +#include <proto.h> + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/proto.h b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/proto.h new file mode 100644 index 0000000..bbab2e5 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/proto.h @@ -0,0 +1,352 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * proto.h + * + * This file contains header files + * + * Started 10/19/95 + * George + * + * $Id: proto.h,v 1.11 2003/07/25 13:52:03 karypis Exp $ + * + */ + +/* kmetis.c */ +void Moc_Global_Partition(CtrlType *, GraphType *, WorkSpaceType *); + +/* mmetis.c */ + +/* gkmetis.c */ + +/* match.c */ +void Moc_GlobalMatch_Balance(CtrlType *, GraphType *, WorkSpaceType *); + +/* coarsen.c */ +void Moc_Global_CreateCoarseGraph(CtrlType *, GraphType *, WorkSpaceType *, int); + +/* initpart.c */ +void Moc_InitPartition_RB(CtrlType *, GraphType *, WorkSpaceType *); +void Moc_KeepPart(GraphType *, WorkSpaceType *, idxtype *, int); + +/* kwayrefine.c */ +void Moc_ProjectPartition(CtrlType *, GraphType *, WorkSpaceType *); +void Moc_ComputePartitionParams(CtrlType *, GraphType *, WorkSpaceType *); + +/* kwayfm.c */ +void Moc_KWayFM(CtrlType *, GraphType *, WorkSpaceType *, int); + +/* kwaybalance.c */ +void Moc_KWayBalance(CtrlType *, GraphType *, WorkSpaceType *, int); + +/* remap.c */ +void ParallelReMapGraph(CtrlType *, GraphType *, WorkSpaceType *); +void ParallelTotalVReMap(CtrlType *, idxtype *, idxtype *, WorkSpaceType *, int, int); +int SimilarTpwgts(float *, int, int, int); + +/* move.c */ +GraphType *Moc_MoveGraph(CtrlType *, GraphType *, WorkSpaceType *); +/* move.c */ +void CheckMGraph(CtrlType *, GraphType *); +void ProjectInfoBack(CtrlType *, GraphType *, idxtype *, idxtype *, WorkSpaceType *); +void FindVtxPerm(CtrlType *, GraphType *, idxtype *, WorkSpaceType *); + +/* memory.c */ +void PreAllocateMemory(CtrlType *, GraphType *, WorkSpaceType *); +void FreeWSpace(WorkSpaceType *); +void FreeCtrl(CtrlType *); +GraphType *CreateGraph(void); +void InitGraph(GraphType *); +void FreeGraph(GraphType *); +void FreeInitialGraphAndRemap(GraphType *, int); + + +/* ametis.c */ +void Adaptive_Partition(CtrlType *, GraphType *, WorkSpaceType *); + +/* rmetis.c */ + + +/* lmatch.c */ +void Mc_LocalMatch_HEM(CtrlType *, GraphType *, WorkSpaceType *); +void Mc_Local_CreateCoarseGraph(CtrlType *, GraphType *, WorkSpaceType *, int); + +/* wave.c */ +float WavefrontDiffusion(CtrlType *, GraphType *, idxtype *); + +/* balancemylink.c */ +int BalanceMyLink(CtrlType *, GraphType *, idxtype *, int, int, float *, float, float *, float *, float); + +/* redomylink.c */ +void RedoMyLink(CtrlType *, GraphType *, idxtype *, int, int, float *, float *, float *); + +/* initbalance.c */ +void Balance_Partition(CtrlType *, GraphType *, WorkSpaceType *); +GraphType *Moc_AssembleAdaptiveGraph(CtrlType *, GraphType *, WorkSpaceType *); + +/* mdiffusion.c */ +int Moc_Diffusion(CtrlType *, GraphType *, idxtype *, idxtype *, idxtype *, WorkSpaceType *, int); +GraphType *ExtractGraph(CtrlType *, GraphType *, idxtype *, idxtype *, idxtype *); + +/* diffutil.c */ +void SetUpConnectGraph(GraphType *, MatrixType *, idxtype *); +void Mc_ComputeMoveStatistics(CtrlType *, GraphType *, int *, int *, int *); + int Mc_ComputeSerialTotalV(GraphType *, idxtype *); +void ComputeLoad(GraphType *, int, float *, float *, int); +void ConjGrad2(MatrixType *, float *, float *, float, float *); +void mvMult2(MatrixType *, float *, float *); +void ComputeTransferVector(int, MatrixType *, float *, float *, int); +int ComputeSerialEdgeCut(GraphType *); +int ComputeSerialTotalV(GraphType *, idxtype *); + +/* akwayfm.c */ +void Moc_KWayAdaptiveRefine(CtrlType *, GraphType *, WorkSpaceType *, int); + +/* selectq.c */ +void Moc_DynamicSelectQueue(int, int, int, int, idxtype *, float *, int *, int *, int, float, float); +int Moc_HashVwgts(int, float *); +int Moc_HashVRank(int, int *); + + +/* csrmatch.c */ +void CSR_Match_SHEM(MatrixType *, idxtype *, idxtype *, idxtype *, int); + +/* serial.c */ +void Moc_SerialKWayAdaptRefine(GraphType *, int, idxtype *, float *, int); +void Moc_ComputeSerialPartitionParams(GraphType *, int, EdgeType *); +int AreAllHVwgtsBelow(int, float, float *, float, float *, float *); +void ComputeHKWayLoadImbalance(int, int, float *, float *); +void SerialRemap(GraphType *, int, idxtype *, idxtype *, idxtype *, float *); +int SSMIncKeyCmp(const void *, const void *); +void Moc_Serial_FM_2WayRefine(GraphType *, float *, int); +void Serial_SelectQueue(int, float *, float *, int *, int *, FPQueueType [MAXNCON][2]); +int Serial_BetterBalance(int, float *, float *, float *); +float Serial_Compute2WayHLoadImbalance(int, float *, float *); +void Moc_Serial_Balance2Way(GraphType *, float *, float); +void Moc_Serial_Init2WayBalance(GraphType *, float *); +int Serial_SelectQueueOneWay(int, float *, float *, int, FPQueueType [MAXNCON][2]); +void Moc_Serial_Compute2WayPartitionParams(GraphType *); +int Serial_AreAnyVwgtsBelow(int, float, float *, float, float *, float *); + +/* weird.c */ +void PartitionSmallGraph(CtrlType *, GraphType *, WorkSpaceType *); +void CheckInputs(int partType, int npes, int dbglvl, int *wgtflag, int *iwgtflag, + int *numflag, int *inumflag, int *ncon, int *incon, int *nparts, + int *inparts, float *tpwgts, float **itpwgts, float *ubvec, + float *iubvec, float *ipc2redist, float *iipc2redist, int *options, + int *ioptions, idxtype *part, MPI_Comm *comm); + +/* mesh.c */ + +/* ometis.c */ + +/* pspases.c */ +GraphType *AssembleEntireGraph(CtrlType *, idxtype *, idxtype *, idxtype *); + +/* node_refine.c */ +void ComputeNodePartitionParams0(CtrlType *, GraphType *, WorkSpaceType *); +void ComputeNodePartitionParams(CtrlType *, GraphType *, WorkSpaceType *); +void KWayNodeRefine0(CtrlType *, GraphType *, WorkSpaceType *, int, float); +void KWayNodeRefine(CtrlType *, GraphType *, WorkSpaceType *, int, float); +void KWayNodeRefine2(CtrlType *, GraphType *, WorkSpaceType *, int, float); +void PrintNodeBalanceInfo(CtrlType *, int, idxtype *, idxtype *, idxtype *, int); + +/* initmsection.c */ +void InitMultisection(CtrlType *, GraphType *, WorkSpaceType *); +GraphType *AssembleMultisectedGraph(CtrlType *, GraphType *, WorkSpaceType *); + +/* order.c */ +void MultilevelOrder(CtrlType *, GraphType *, idxtype *, idxtype *, WorkSpaceType *); +void LabelSeparators(CtrlType *, GraphType *, idxtype *, idxtype *, idxtype *, idxtype *, WorkSpaceType *); +void CompactGraph(CtrlType *, GraphType *, idxtype *, WorkSpaceType *); +void LocalOrder(CtrlType *, GraphType *, idxtype *, int, WorkSpaceType *); +void LocalNDOrder(CtrlType *, GraphType *, idxtype *, int, WorkSpaceType *); +void Order_Partition(CtrlType *, GraphType *, WorkSpaceType *); + +/* xyzpart.c */ +void Coordinate_Partition(CtrlType *, GraphType *, int, float *, int, WorkSpaceType *); +void PartSort(CtrlType *, GraphType *, KeyValueType *, WorkSpaceType *); + + +/* fpqueue.c */ +void FPQueueInit(FPQueueType *, int); +void FPQueueReset(FPQueueType *); +void FPQueueFree(FPQueueType *); +int FPQueueGetSize(FPQueueType *); +int FPQueueInsert(FPQueueType *, int, float); +int FPQueueDelete(FPQueueType *, int); +int FPQueueUpdate(FPQueueType *, int, float, float); +void FPQueueUpdateUp(FPQueueType *, int, float, float); +int FPQueueGetMax(FPQueueType *); +int FPQueueSeeMaxVtx(FPQueueType *); +float FPQueueSeeMaxGain(FPQueueType *); +float FPQueueGetKey(FPQueueType *); +int FPQueueGetQSize(FPQueueType *); +int CheckHeapFloat(FPQueueType *); + +/* stat.c */ +void Moc_ComputeSerialBalance(CtrlType *, GraphType *, idxtype *, float *); +void Moc_ComputeParallelBalance(CtrlType *, GraphType *, idxtype *, float *); +void Moc_PrintThrottleMatrix(CtrlType *, GraphType *, float *); +void Moc_ComputeRefineStats(CtrlType *, GraphType *, float *); + +/* debug.c */ +void PrintVector(CtrlType *, int, int, idxtype *, char *); +void PrintVector2(CtrlType *, int, int, idxtype *, char *); +void PrintPairs(CtrlType *, int, KeyValueType *, char *); +void PrintGraph(CtrlType *, GraphType *); +void PrintGraph2(CtrlType *, GraphType *); +void PrintSetUpInfo(CtrlType *ctrl, GraphType *graph); +void PrintTransferedGraphs(CtrlType *, int, idxtype *, idxtype *, idxtype *, idxtype *, idxtype *); +void WriteMetisGraph(int, idxtype *, idxtype *, idxtype *, idxtype *); + +/* comm.c */ +void CommInterfaceData(CtrlType *, GraphType *, idxtype *, idxtype *, idxtype *); +void CommChangedInterfaceData(CtrlType *, GraphType *, int, idxtype *, idxtype *, KeyValueType *, KeyValueType *, idxtype *); +int GlobalSEMax(CtrlType *, int); +double GlobalSEMaxDouble(CtrlType *, double); +int GlobalSEMin(CtrlType *, int); +int GlobalSESum(CtrlType *, int); +float GlobalSEMaxFloat(CtrlType *, float); +float GlobalSEMinFloat(CtrlType *, float); +float GlobalSESumFloat(CtrlType *, float); + +/* util.c */ +void errexit(char *,...); +void myprintf(CtrlType *, char *f_str,...); +void rprintf(CtrlType *, char *f_str,...); +#ifndef DMALLOC +int *imalloc(int, char *); +idxtype *idxmalloc(int, char *); +float *fmalloc(int, char *); +int *ismalloc(int, int, char *); +idxtype *idxsmalloc(int, idxtype, char *); +void *GKmalloc(int, char *); +#endif +/*void GKfree(void **,...); */ +int *iset(int n, int val, int *x); +idxtype * idxset(int n, idxtype val, idxtype *x); +int idxamax(int n, idxtype *x); +int idxamin(int n, idxtype *x); +int idxasum(int n, idxtype *x); +float snorm2(int, float *); +float sdot(int n, float *, float *); +void saxpy(int, float, float *, float *); +void ikeyvalsort_org(int, KeyValueType *); +int IncKeyValueCmp(const void *, const void *); +void dkeyvalsort(int, KeyValueType *); +int DecKeyValueCmp(const void *, const void *); +int BSearch(int, idxtype *, int); +void RandomPermute(int, idxtype *, int); +void FastRandomPermute(int, idxtype *, int); +int ispow2(int); +int log2Int(int); +void BucketSortKeysDec(int, int, idxtype *, idxtype *); +float *sset(int n, float val, float *x); +int iamax(int, int *); +int idxamax_strd(int, idxtype *, int); +int idxamin_strd(int, idxtype *, int); +int samax_strd(int, float *, int); +int sfamax(int, float *); +int samin_strd(int, float *, int); +float idxavg(int, idxtype *); +float savg(int, float *); +int samax(int, float *); +int sfavg(int n, float *x); +int samax2(int, float *); +int samin(int, float *); +int idxsum(int, idxtype *); +int idxsum_strd(int, idxtype *, int); +void idxadd(int, idxtype *, idxtype *); +float ssum(int, float *); +float ssum_strd(int, float *, int); +void sscale(int, float, float *); +void saneg(int, float *); +float BetterVBalance(int, float *, float *, float *); +int IsHBalanceBetterTT(int, float *, float *, float *, float *); +int IsHBalanceBetterFT(int, float *, float *, float *, float *); +int myvalkeycompare(const void *, const void *); +int imyvalkeycompare(const void *, const void *); +float *fsmalloc(int, float, char *); +void saxpy2(int, float, float *, int, float *, int); +void GetThreeMax(int, float *, int *, int *, int *); + +/* qsort_special.c */ +void iidxsort(int, idxtype *); +void iintsort(int, int *); +void ikeysort(int, KeyValueType *); +void ikeyvalsort(int, KeyValueType *); + +/* grsetup.c */ +GraphType *Moc_SetUpGraph(CtrlType *, int, idxtype *, idxtype *, idxtype *, idxtype *, idxtype *, int *); +void SetUpCtrl(CtrlType *ctrl, int, int, MPI_Comm); +void ChangeNumbering(idxtype *, idxtype *, idxtype *, idxtype *, int, int, int); +void ChangeNumberingMesh(idxtype *, idxtype *, idxtype *, idxtype *, idxtype *, int, int, int, int); +void ChangeNumberingMesh2(idxtype *elmdist, idxtype *eptr, idxtype *eind, + idxtype *xadj, idxtype *adjncy, idxtype *part, + int npes, int mype, int from); +void GraphRandomPermute(GraphType *); +void ComputeMoveStatistics(CtrlType *, GraphType *, int *, int *, int *); + +/* timer.c */ +void InitTimers(CtrlType *); +void PrintTimingInfo(CtrlType *); +void PrintTimer(CtrlType *, timer, char *); + +/* setup.c */ +void SetUp(CtrlType *, GraphType *, WorkSpaceType *); +int Home_PE(int, int, idxtype *, int); + + +/*********************/ +/* METIS subroutines */ +/*********************/ +void METIS_WPartGraphKway2(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void METIS_mCPartGraphRecursive2(int *, int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +int MCMlevelRecursiveBisection2(CtrlType *, GraphType *, int, float *, idxtype *, float, int); +void METIS_PartGraphKway(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, int *, int *, idxtype *); +void METIS_mCPartGraphKway(int *, int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, int *, float *, int *, int *, idxtype *); +void METIS_EdgeComputeSeparator(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, idxtype *); +void METIS_NodeComputeSeparator(int *, idxtype *, idxtype *, idxtype *, idxtype *, int *, int *, idxtype *); +void METIS_NodeND(int *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *); +void METIS_NodeNDP(int, idxtype *, idxtype *, int, int *, idxtype *, idxtype *, idxtype *); + + + +/***********************/ +/* TESTing subroutines */ +/***********************/ + +/* pio.c */ +void ParallelReadGraph(GraphType *, char *, MPI_Comm); +void Moc_ParallelWriteGraph(CtrlType *, GraphType *, char *, int, int); +void ReadTestGraph(GraphType *, char *, MPI_Comm); +float *ReadTestCoordinates(GraphType *, char *, int, MPI_Comm); +void ReadMetisGraph(char *, int *, idxtype **, idxtype **); +void Moc_SerialReadGraph(GraphType *, char *, int *, MPI_Comm); +void Moc_SerialReadMetisGraph(char *, int *, int *, int *, int *, idxtype **, idxtype **, idxtype **, idxtype **, int *); + +/* adaptgraph */ +void AdaptGraph(GraphType *, int, MPI_Comm); +void AdaptGraph2(GraphType *, int, MPI_Comm); +void Mc_AdaptGraph(GraphType *, idxtype *, int, int, MPI_Comm); + +/* ptest.c */ +void TestParMetis(char *, MPI_Comm); + +/* NEW_ptest.c */ +void TestParMetis_V3(char *, MPI_Comm); +int ComputeRealCut(idxtype *, idxtype *, char *, MPI_Comm); +int ComputeRealCut2(idxtype *, idxtype *, idxtype *, idxtype *, char *, MPI_Comm); +void TestMoveGraph(GraphType *, GraphType *, idxtype *, MPI_Comm); +GraphType *SetUpGraph(CtrlType *, idxtype *, idxtype *, idxtype *, idxtype *, idxtype *, int); + +/* mienio.c */ +void mienIO(MeshType *, char *, int, int, MPI_Comm); + +/* meshio.c */ +void ParallelReadMesh(MeshType *, char *, MPI_Comm); + +/* parmetis.c */ +void ChangeToFortranNumbering(idxtype *, idxtype *, idxtype *, int, int); + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/pspases.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/pspases.c new file mode 100644 index 0000000..8b7a182 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/pspases.c @@ -0,0 +1,167 @@ +/* + * pspases.c + * + * This file contains ordering routines that are to be used with the + * parallel Cholesky factorization code PSPASES + * + * Started 10/14/97 + * George + * + * $Id: pspases.c,v 1.3 2003/07/21 17:18:53 karypis Exp $ + * + */ + +#include <parmetislib.h> + + +/*********************************************************************************** +* This function is the entry point of the serial ordering algorithm. +************************************************************************************/ +void ParMETIS_SerialNodeND(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, int *numflag, + int *options, idxtype *order, idxtype *sizes, MPI_Comm *comm) +{ + int i, npes, mype, seroptions[10]; + CtrlType ctrl; + GraphType *agraph; + idxtype *perm=NULL, *iperm=NULL; + int *sendcount, *displs; + + MPI_Comm_size(*comm, &npes); + MPI_Comm_rank(*comm, &mype); + + if (!ispow2(npes)) { + if (mype == 0) + printf("Error: The number of processors must be a power of 2!\n"); + return; + } + + if (*numflag == 1) + ChangeNumbering(vtxdist, xadj, adjncy, order, npes, mype, 1); + + SetUpCtrl(&ctrl, npes, options[OPTION_DBGLVL], *comm); + + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.MoveTmr)); + + agraph = AssembleEntireGraph(&ctrl, vtxdist, xadj, adjncy); + + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.MoveTmr)); + + + if (mype == 0) { + perm = idxmalloc(agraph->nvtxs, "PAROMETISS: perm"); + iperm = idxmalloc(agraph->nvtxs, "PAROMETISS: iperm"); + + seroptions[0] = 0; + /* + seroptions[1] = 3; + seroptions[2] = 1; + seroptions[3] = 2; + seroptions[4] = 128; + seroptions[5] = 1; + seroptions[6] = 0; + seroptions[7] = 1; + */ + + METIS_NodeNDP(agraph->nvtxs, agraph->xadj, agraph->adjncy, npes, seroptions, perm, iperm, sizes); + } + + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.MoveTmr)); + + /* Broadcast the sizes array */ + MPI_Bcast((void *)sizes, 2*npes, IDX_DATATYPE, 0, ctrl.gcomm); + + /* Scatter the iperm */ + sendcount = imalloc(npes, "PAROMETISS: sendcount"); + displs = imalloc(npes, "PAROMETISS: displs"); + for (i=0; i<npes; i++) { + sendcount[i] = vtxdist[i+1]-vtxdist[i]; + displs[i] = vtxdist[i]; + } + + MPI_Scatterv((void *)iperm, sendcount, displs, IDX_DATATYPE, (void *)order, vtxdist[mype+1]-vtxdist[mype], IDX_DATATYPE, 0, ctrl.gcomm); + + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.MoveTmr)); + + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimingInfo(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + + GKfree((void **)&agraph->xadj, (void **)&agraph->adjncy, (void **)&perm, (void **)&iperm, (void **)&sendcount, (void **)&displs, LTERM); + free(agraph); + FreeCtrl(&ctrl); + + if (*numflag == 1) + ChangeNumbering(vtxdist, xadj, adjncy, order, npes, mype, 0); + +} + + + +/************************************************************************* +* This function assembles the graph into a single processor +**************************************************************************/ +GraphType *AssembleEntireGraph(CtrlType *ctrl, idxtype *vtxdist, idxtype *xadj, idxtype *adjncy) +{ + int i, gnvtxs, nvtxs, gnedges, nedges; + int npes = ctrl->npes, mype = ctrl->mype; + idxtype *axadj, *aadjncy; + int *recvcounts, *displs; + GraphType *agraph; + + gnvtxs = vtxdist[npes]; + nvtxs = vtxdist[mype+1]-vtxdist[mype]; + nedges = xadj[nvtxs]; + + recvcounts = imalloc(npes, "AssembleGraph: recvcounts"); + displs = imalloc(npes+1, "AssembleGraph: displs"); + + /* Gather all the xadj arrays first */ + for (i=0; i<nvtxs; i++) + xadj[i] = xadj[i+1]-xadj[i]; + + axadj = idxmalloc(gnvtxs+1, "AssembleEntireGraph: axadj"); + + for (i=0; i<npes; i++) { + recvcounts[i] = vtxdist[i+1]-vtxdist[i]; + displs[i] = vtxdist[i]; + } + + /* Assemble the xadj and then the adjncy */ + MPI_Gatherv((void *)xadj, nvtxs, IDX_DATATYPE, axadj, recvcounts, displs, IDX_DATATYPE, 0, ctrl->comm); + + MAKECSR(i, nvtxs, xadj); + MAKECSR(i, gnvtxs, axadj); + + /* Gather all the adjncy arrays next */ + /* Determine the # of edges stored at each processor */ + MPI_Allgather((void *)(&nedges), 1, MPI_INT, (void *)recvcounts, 1, MPI_INT, ctrl->comm); + + displs[0] = 0; + for (i=1; i<npes+1; i++) + displs[i] = displs[i-1] + recvcounts[i-1]; + gnedges = displs[npes]; + + aadjncy = idxmalloc(gnedges, "AssembleEntireGraph: aadjncy"); + + /* Assemble the xadj and then the adjncy */ + MPI_Gatherv((void *)adjncy, nedges, IDX_DATATYPE, aadjncy, recvcounts, displs, IDX_DATATYPE, 0, ctrl->comm); + + /* myprintf(ctrl, "Gnvtxs: %d, Gnedges: %d\n", gnvtxs, gnedges); */ + + agraph = CreateGraph(); + agraph->nvtxs = gnvtxs; + agraph->nedges = gnedges; + agraph->xadj = axadj; + agraph->adjncy = aadjncy; + + return agraph; +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/redomylink.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/redomylink.c new file mode 100644 index 0000000..98b6810 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/redomylink.c @@ -0,0 +1,175 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * redomylink.c + * + * This file contains code that implements the edge-based FM refinement + * + * Started 7/23/97 + * George + * + * $Id: redomylink.c,v 1.2 2003/07/21 17:18:53 karypis Exp $ + */ + +#include <parmetislib.h> +#define PE 0 + +/************************************************************************* +* This function performs an edge-based FM refinement +**************************************************************************/ +void RedoMyLink(CtrlType *ctrl, GraphType *graph, idxtype *home, int me, + int you, float *flows, float *sr_cost, float *sr_lbavg) +{ + int h, i, r; + int nvtxs, nedges, ncon; + int pass, lastseed, totalv; + idxtype *xadj, *adjncy, *adjwgt, *where, *vsize; + idxtype *costwhere, *lbwhere, *selectwhere; + idxtype *rdata, *ed, *id, *bndptr, *bndind, *perm; + float *nvwgt, mycost; + float lbavg, lbvec[MAXNCON]; + float best_lbavg, other_lbavg = -1.0, bestcost, othercost = -1.0; + float npwgts[2*MAXNCON], pwgts[MAXNCON*2], tpwgts[MAXNCON*2]; + float ipc_factor, redist_factor, ftmp; +int mype; +MPI_Comm_rank(MPI_COMM_WORLD, &mype); + + nvtxs = graph->nvtxs; + nedges = graph->nedges; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + vsize = graph->vsize; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + ipc_factor = ctrl->ipc_factor; + redist_factor = ctrl->redist_factor; + + /**************************/ + /* set up data structures */ + /**************************/ + rdata = idxmalloc(7*nvtxs, "rdata"); + id = graph->sendind = rdata; + ed = graph->recvind = rdata + nvtxs; + bndptr = graph->sendptr = rdata + 2*nvtxs; + bndind = graph->recvptr = rdata + 3*nvtxs; + costwhere = rdata + 4*nvtxs; + lbwhere = rdata + 5*nvtxs; + perm = rdata + 6*nvtxs; + graph->gnpwgts = npwgts; + + RandomPermute(nvtxs, perm, 1); + idxcopy(nvtxs, where, costwhere); + idxcopy(nvtxs, where, lbwhere); + + /*****************************/ + /* compute target pwgts */ + /*****************************/ + sset(ncon*2, 0.0, pwgts); + for (h=0; h<ncon; h++) { + tpwgts[h] = -1.0 * flows[h]; + tpwgts[ncon+h] = flows[h]; + } + + for (i=0; i<nvtxs; i++) { + if (where[i] == me) { + for (h=0; h<ncon; h++) { + tpwgts[h] += nvwgt[i*ncon+h]; + pwgts[h] += nvwgt[i*ncon+h]; + } + } + else { + ASSERTS(where[i] == you); + for (h=0; h<ncon; h++) { + tpwgts[ncon+h] += nvwgt[i*ncon+h]; + pwgts[ncon+h] += nvwgt[i*ncon+h]; + } + } + } + + /* we don't want any weights to be less than zero */ + for (h=0; h<ncon; h++) { + if (tpwgts[h] < 0.0) { + tpwgts[ncon+h] += tpwgts[h]; + tpwgts[h] = 0.0; + } + + if (tpwgts[ncon+h] < 0.0) { + tpwgts[h] += tpwgts[ncon+h]; + tpwgts[ncon+h] = 0.0; + } + } + + /*****************************/ + /* now compute new bisection */ + /*****************************/ + bestcost = (float)idxsum(nedges, adjwgt)*ipc_factor + (float)idxsum(nvtxs, vsize)*redist_factor; + best_lbavg = 10.0; + + lastseed = 0; + for (pass = N_MOC_REDO_PASSES; pass>0; pass--) { + idxset(nvtxs, 1, where); + + /***************************/ + /* find seed vertices */ + /***************************/ + r = perm[lastseed] % nvtxs; + lastseed = (lastseed+1) % nvtxs; + where[r] = 0; + + Moc_Serial_Compute2WayPartitionParams(graph); + Moc_Serial_Init2WayBalance(graph, tpwgts); + Moc_Serial_FM_2WayRefine(graph, tpwgts, 4); + Moc_Serial_Balance2Way(graph, tpwgts, 1.02); + Moc_Serial_FM_2WayRefine(graph, tpwgts, 4); + + for (i=0; i<nvtxs; i++) + where[i] = (where[i] == 0) ? me : you; + + for (i=0; i<ncon; i++) { + ftmp = (pwgts[i]+pwgts[ncon+i])/2.0; + if (ftmp != 0.0) + lbvec[i] = fabs(npwgts[i]-tpwgts[i])/ftmp; + else + lbvec[i] = 0.0; + } + lbavg = savg(ncon, lbvec); + + totalv = 0; + for (i=0; i<nvtxs; i++) + if (where[i] != home[i]) + totalv += vsize[i]; + + mycost = (float)(graph->mincut)*ipc_factor + (float)totalv*redist_factor; + + if (bestcost >= mycost) { + bestcost = mycost; + other_lbavg = lbavg; + idxcopy(nvtxs, where, costwhere); + } + + if (best_lbavg >= lbavg) { + best_lbavg = lbavg; + othercost = mycost; + idxcopy(nvtxs, where, lbwhere); + } + } + + if (other_lbavg <= .05) { + selectwhere = costwhere; + *sr_cost = bestcost; + *sr_lbavg = other_lbavg; + } + else { + selectwhere = lbwhere; + *sr_cost = othercost; + *sr_lbavg = best_lbavg; + } + + idxcopy(nvtxs, selectwhere, where); + + GKfree((void **)&rdata, LTERM); + return; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/remap.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/remap.c new file mode 100644 index 0000000..31f186b --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/remap.c @@ -0,0 +1,181 @@ +/* + * premap.c + * + * This file contains code that computes the assignment of processors to + * partition numbers so that it will minimize the redistribution cost + * + * Started 4/16/98 + * George + * + * $Id: remap.c,v 1.2 2003/07/21 17:18:53 karypis Exp $ + * + */ + +#include <parmetislib.h> + +/************************************************************************* +* This function remaps that graph so that it will minimize the +* redistribution cost +**************************************************************************/ +void ParallelReMapGraph(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int i, nvtxs, nparts; + idxtype *where, *vsize, *map, *lpwgts; + + IFSET(ctrl->dbglvl, DBG_TIME, MPI_Barrier(ctrl->comm)); + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->RemapTmr)); + + if (ctrl->npes != ctrl->nparts) { + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->RemapTmr)); + return; + } + + nvtxs = graph->nvtxs; + where = graph->where; + vsize = graph->vsize; + nparts = ctrl->nparts; + + map = wspace->pv1; + lpwgts = idxset(nparts, 0, wspace->pv2); + + for (i=0; i<nvtxs; i++) + lpwgts[where[i]] += (vsize == NULL) ? 1 : vsize[i]; + + ParallelTotalVReMap(ctrl, lpwgts, map, wspace, NREMAP_PASSES, graph->ncon); + + for (i=0; i<nvtxs; i++) + where[i] = map[where[i]]; + + IFSET(ctrl->dbglvl, DBG_TIME, MPI_Barrier(ctrl->comm)); + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->RemapTmr)); +} + + +/************************************************************************* +* This function computes the assignment using the the objective the +* minimization of the total volume of data that needs to move +**************************************************************************/ +void ParallelTotalVReMap(CtrlType *ctrl, idxtype *lpwgts, idxtype *map, + WorkSpaceType *wspace, int npasses, int ncon) +{ + int i, ii, j, k, nparts, mype; + int pass, maxipwgt, nmapped, oldwgt, newwgt, done; + idxtype *rowmap, *mylpwgts; + KeyValueType *recv, send; + int nsaved, gnsaved; + + mype = ctrl->mype; + nparts = ctrl->nparts; + recv = (KeyValueType *)GKmalloc(sizeof(KeyValueType)*nparts, "remap: recv"); + mylpwgts = idxmalloc(nparts, "mylpwgts"); + + done = nmapped = 0; + idxset(nparts, -1, map); + rowmap = idxset(nparts, -1, wspace->pv3); + idxcopy(nparts, lpwgts, mylpwgts); + for (pass=0; pass<npasses; pass++) { + maxipwgt = idxamax(nparts, mylpwgts); + + if (mylpwgts[maxipwgt] > 0 && !done) { + send.key = -mylpwgts[maxipwgt]; + send.val = mype*nparts+maxipwgt; + } + else { + send.key = 0; + send.val = -1; + } + + /* each processor sends its selection */ + MPI_Allgather((void *)&send, 2, IDX_DATATYPE, (void *)recv, 2, IDX_DATATYPE, ctrl->comm); + + ikeysort(nparts, recv); + if (recv[0].key == 0) + break; + + /* now make as many assignments as possible */ + for (ii=0; ii<nparts; ii++) { + i = recv[ii].val; + + if (i == -1) + continue; + + j = i % nparts; + k = i / nparts; + if (map[j] == -1 && rowmap[k] == -1 && SimilarTpwgts(ctrl->tpwgts, ncon, j, k)) { + map[j] = k; + rowmap[k] = j; + nmapped++; + mylpwgts[j] = 0; + if (mype == k) + done = 1; + } + + if (nmapped == nparts) + break; + } + + if (nmapped == nparts) + break; + } + + /* Map unmapped partitions */ + if (nmapped < nparts) { + for (i=j=0; j<nparts && nmapped<nparts; j++) { + if (map[j] == -1) { + for (; i<nparts; i++) { + if (rowmap[i] == -1 && SimilarTpwgts(ctrl->tpwgts, ncon, i, j)) { + map[j] = i; + rowmap[i] = j; + nmapped++; + break; + } + } + } + } + } + + /* check to see if remapping fails (due to dis-similar tpwgts) */ + /* if remapping fails, revert to original mapping */ + if (nmapped < nparts) { + for (i=0; i<nparts; i++) + map[i] = i; + IFSET(ctrl->dbglvl, DBG_REMAP, rprintf(ctrl, "Savings from parallel remapping: %0\n")); + } + else { + /* check for a savings */ + oldwgt = lpwgts[mype]; + newwgt = lpwgts[rowmap[mype]]; + nsaved = newwgt - oldwgt; + gnsaved = GlobalSESum(ctrl, nsaved); + + /* undo everything if we don't see a savings */ + if (gnsaved <= 0) { + for (i=0; i<nparts; i++) + map[i] = i; + } + IFSET(ctrl->dbglvl, DBG_REMAP, rprintf(ctrl, "Savings from parallel remapping: %d\n", amax(0,gnsaved))); + } + + GKfree((void **)&recv, (void **)&mylpwgts, LTERM); + +} + + +/************************************************************************* +* This function computes the assignment using the the objective the +* minimization of the total volume of data that needs to move +**************************************************************************/ +int SimilarTpwgts(float *tpwgts, int ncon, int s1, int s2) +{ + int i; + + for (i=0; i<ncon; i++) + if (fabs(tpwgts[s1*ncon+i]-tpwgts[s2*ncon+i]) > SMALLFLOAT) + break; + + if (i == ncon) + return 1; + + return 0; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/rename.h b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/rename.h new file mode 100644 index 0000000..d993257 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/rename.h @@ -0,0 +1,290 @@ +/* kmetis.c */ +#define Moc_Global_Partition Moc_Global_Partition__ + +/* mmetis.c */ + +/* gkmetis.c */ + +/* match.c */ +#define Moc_GlobalMatch_Balance Moc_GlobalMatch_Balance__ + +/* coarsen.c */ +#define Moc_Global_CreateCoarseGraph Moc_Global_CreateCoarseGraph__ + +/* initpart.c */ +#define Moc_InitPartition_RB Moc_InitPartition_RB__ +#define Moc_KeepPart Moc_KeepPart__ + +/* kwayrefine.c */ +#define Moc_ProjectPartition Moc_ProjectPartition__ +#define Moc_ComputePartitionParams Moc_ComputePartitionParams__ + +/* kwayfm.c */ +#define Moc_KWayFM Moc_KWayFM__ + +/* kwaybalance.c */ +#define Moc_KWayBalance Moc_KWayBalance__ + +/* remap.c */ +#define ParallelReMapGraph ParallelReMapGraph__ +#define ParallelTotalVReMap ParallelTotalVReMap__ +#define SimilarTpwgts SimilarTpwgts__ + +/* move.c */ +#define Moc_MoveGraph Moc_MoveGraph__ +#define CheckMGraph CheckMGraph__ +#define ProjectInfoBack ProjectInfoBack__ +#define FindVtxPerm FindVtxPerm__ + +/* memory.c */ +#define PreAllocateMemory PreAllocateMemory__ +#define FreeWSpace FreeWSpace__ +#define FreeCtrl FreeCtrl__ +#define CreateGraph CreateGraph__ +#define InitGraph InitGraph__ +#define FreeGraph FreeGraph__ +#define FreeInitialGraphAndRemap FreeInitialGraphAndRemap__ + + +/************************/ +/* Adaptive subroutines */ +/************************/ +/* ametis.c */ +#define Adaptive_Partition Adaptive_Partition__ + +/* rmetis.c */ + +/* lmatch.c */ +#define Mc_LocalMatch_HEM Mc_LocalMatch_HEM__ +#define Mc_Local_CreateCoarseGraph Mc_Local_CreateCoarseGraph__ + +/* wave.c */ +#define WavefrontDiffusion WavefrontDiffusion__ + +/* balancemylink.c */ +#define BalanceMyLink BalanceMyLink__ + +/* redomylink.c */ +#define RedoMyLink RedoMyLink__ + +/* initbalance.c */ +#define Balance_Partition Balance_Partition__ +#define Moc_AssembleAdaptiveGraph Moc_AssembleAdaptiveGraph__ + +/* mdiffusion.c */ +#define Moc_Diffusion Moc_Diffusion__ +#define ExtractGraph ExtractGraph__ + +/* diffutil.c */ +#define SetUpConnectGraph SetUpConnectGraph__ +#define Mc_ComputeMoveStatistics Mc_ComputeMoveStatistics__ +#define Mc_ComputeSerialTotalV Mc_ComputeSerialTotalV__ +#define ComputeLoad ComputeLoad__ +#define ConjGrad2 ConjGrad2__ +#define mvMult2 mvMult2__ +#define ComputeTransferVector ComputeTransferVector__ +#define ComputeSerialEdgeCut ComputeSerialEdgeCut__ +#define ComputeSerialTotalV ComputeSerialTotalV__ + +/* akwayfm.c */ +#define Moc_KWayAdaptiveRefine Moc_KWayAdaptiveRefine__ + +/* selectq.c */ +#define Moc_DynamicSelectQueue Moc_DynamicSelectQueue__ +#define Moc_HashVwgts Moc_HashVwgts__ +#define Moc_HashVRank Moc_HashVRank__ + +/* csrmatch.c */ +#define CSR_Match_SHEM CSR_Match_SHEM__ + +/* serial.c */ +#define Moc_SerialKWayAdaptRefine Moc_SerialKWayAdaptRefine__ +#define Moc_ComputeSerialPartitionParams Moc_ComputeSerialPartitionParams__ +#define AreAllHVwgtsBelow AreAllHVwgtsBelow__ +#define ComputeHKWayLoadImbalance ComputeHKWayLoadImbalance__ +#define SerialRemap SerialRemap__ +#define SSMIncKeyCmp SSMIncKeyCmp__ +#define Moc_Serial_FM_2WayRefine Moc_Serial_FM_2WayRefine__ +#define Serial_SelectQueue Serial_SelectQueue__ +#define Serial_BetterBalance Serial_BetterBalance__ +#define Serial_Compute2WayHLoadImbalance Serial_Compute2WayHLoadImbalance__ +#define Moc_Serial_Balance2Way Moc_Serial_Balance2Way__ +#define Moc_Serial_Init2WayBalance Moc_Serial_Init2WayBalance__ +#define Serial_SelectQueueOneWay Serial_SelectQueueOneWay__ +#define Moc_Serial_Compute2WayPartitionParams Moc_Serial_Compute2WayPartitionParams__ +#define Serial_AreAnyVwgtsBelow Serial_AreAnyVwgtsBelow__ + +/* weird.c */ +#define PartitionSmallGraph PartitionSmallGraph__ +#define CheckInputs CheckInputs__ + + +/****************************/ +/* Mesh to Dual subroutines */ +/****************************/ +/* mesh.c */ +/* msetup.c */ +#define SetUpMesh SetUpMesh__ +#define CreateMesh CreateMesh__ +#define InitMesh InitMesh__ + + +/************************/ +/* Ordering subroutines */ +/************************/ +/* ometis.c */ +/* pspases.c */ +#define AssembleEntireGraph AssembleEntireGraph__ + +/* node_refine.c */ +#define ComputeNodePartitionParams0 ComputeNodePartitionParams0__ +#define ComputeNodePartitionParams ComputeNodePartitionParams__ +#define KWayNodeRefine0 KWayNodeRefine0__ +#define KWayNodeRefine KWayNodeRefine__ +#define KWayNodeRefine2 KWayNodeRefine2__ +#define PrintNodeBalanceInfo PrintNodeBalanceInfo__ + +/* initmsection.c */ +#define InitMultisection InitMultisection__ +#define AssembleMultisectedGraph AssembleMultisectedGraph__ + +/* order.c */ +#define MultilevelOrder MultilevelOrder__ +#define LabelSeparators LabelSeparators__ +#define CompactGraph CompactGraph__ +#define LocalOrder LocalOrder__ +#define LocalNDOrder LocalNDOrder__ +#define Order_Partition Order_Partition__ + +/* xyzpart.c */ +#define Coordinate_Partition Coordinate_Partition__ +#define PartSort PartSort__ + +/***********************/ +/* Utility subroutines */ +/***********************/ +/* fpqueue.c */ +#define FPQueueInit FPQueueInit__ +#define FPQueueReset FPQueueReset__ +#define FPQueueFree FPQueueFree__ +#define FPQueueGetSize FPQueueGetSize__ +#define FPQueueInsert FPQueueInsert__ +#define FPQueueDelete FPQueueDelete__ +#define FPQueueUpdate FPQueueUpdate__ +#define FPQueueUpdateUp FPQueueUpdateUp__ +#define FPQueueGetMax FPQueueGetMax__ +#define FPQueueSeeMaxVtx FPQueueSeeMaxVtx__ +#define FPQueueSeeMaxGain FPQueueSeeMaxGain__ +#define FPQueueGetKey FPQueueGetKey__ +#define FPQueueGetQSize FPQueueGetQSize__ +#define CheckHeapFloat CheckHeapFloat__ + +/* stat.c */ +#define Moc_ComputeSerialBalance Moc_ComputeSerialBalance__ +#define Moc_ComputeParallelBalance Moc_ComputeParallelBalance__ +#define Moc_PrintThrottleMatrix Moc_PrintThrottleMatrix__ +#define Moc_ComputeRefineStats Moc_ComputeRefineStats__ + +/* debug.c */ +#define PrintVector PrintVector__ +#define PrintVector2 PrintVector2__ +#define PrintPairs PrintPairs__ +#define PrintGraph PrintGraph__ +#define PrintGraph2 PrintGraph2__ +#define PrintSetUpInfo PrintSetUpInfo__ +#define PrintTransferedGraphs PrintTransferedGraphs__ +#define WriteMetisGraph WriteMetisGraph__ + +/* comm.c */ +#define CommInterfaceData CommInterfaceData__ +#define CommChangedInterfaceData CommChangedInterfaceData__ +#define GlobalSEMax GlobalSEMax__ +#define GlobalSEMaxDouble GlobalSEMaxDouble__ +#define GlobalSEMin GlobalSEMin__ +#define GlobalSESum GlobalSESum__ +#define GlobalSEMaxFloat GlobalSEMaxFloat__ +#define GlobalSEMinFloat GlobalSEMinFloat__ +#define GlobalSESumFloat GlobalSESumFloat__ + +/* util.c */ +#define errexit errexit__ +#define myprintf myprintf__ +#define rprintf rprintf__ +#define imalloc imalloc__ +#define idxmalloc idxmalloc__ +#define fmalloc fmalloc__ +#define ismalloc ismalloc__ +#define idxsmalloc idxsmalloc__ +#define GKmalloc GKmalloc__ +#define GKfree GKfree__ +#define iset iset__ +#define idxset idxset__ +#define idxamax idxamax__ +#define idxamin idxamin__ +#define idxasum idxasum__ +#define snorm2 snorm2__ +#define sdot sdot__ +#define saxpy saxpy__ +#define ikeyvalsort_org ikeyvalsort_org__ +#define IncKeyValueCmp IncKeyValueCmp__ +#define dkeyvalsort dkeyvalsort__ +#define DecKeyValueCmp DecKeyValueCmp__ +#define BSearch BSearch__ +#define RandomPermute RandomPermute__ +#define FastRandomPermute FastRandomPermute__ +#define ispow2 ispow2__ +#define log2Int log2Int__ +#define BucketSortKeysDec BucketSortKeysDec__ +#define sset sset__ +#define iamax iamax__ +#define idxamax_strd idxamax_strd__ +#define idxamin_strd idxamin_strd__ +#define samax_strd samax_strd__ +#define sfamax sfamax__ +#define samin_strd samin_strd__ +#define idxavg idxavg__ +#define savg savg__ +#define samax samax__ +#define sfavg sfavg__ +#define samax2 samax2__ +#define samin samin__ +#define idxsum idxsum__ +#define idxsum_strd idxsum_strd__ +#define idxadd idxadd__ +#define ssum ssum__ +#define ssum_strd ssum_strd__ +#define sscale sscale__ +#define saneg saneg__ +#define BetterVBalance BetterVBalance__ +#define IsHBalanceBetterTT IsHBalanceBetterTT__ +#define IsHBalanceBetterFT IsHBalanceBetterFT__ +#define myvalkeycompare myvalkeycompare__ +#define imyvalkeycompare imyvalkeycompare__ +#define fsmalloc fsmalloc__ +#define saxpy2 saxpy2__ +#define GetThreeMax GetThreeMax__ + +/* qsort_special.c */ +#define iidxsort iidxsort__ +#define iintsort iintsort__ +#define ikeysort ikeysort__ +#define ikeyvalsort ikeyvalsort__ + +/* grsetup.c */ +#define Moc_SetUpGraph Moc_SetUpGraph__ +#define SetUpCtrl SetUpCtrl__ +#define ChangeNumbering ChangeNumbering__ +#define ChangeNumberingMesh ChangeNumberingMesh__ +#define GraphRandomPermute GraphRandomPermute__ +#define ComputeMoveStatistics ComputeMoveStatistics__ + +/* timer.c */ +#define InitTimers InitTimers__ +#define PrintTimingInfo PrintTimingInfo__ +#define PrintTimer PrintTimer__ + +/* setup.c */ +#define SetUp SetUp__ +#define Home_PE Home_PE__ + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/rmetis.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/rmetis.c new file mode 100644 index 0000000..3755209 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/rmetis.c @@ -0,0 +1,165 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * rmetis.c + * + * This is the entry point of the partitioning refinement routine + * + * Started 10/19/96 + * George + * + * $Id: rmetis.c,v 1.5 2003/07/25 04:01:05 karypis Exp $ + * + */ + +#include <parmetislib.h> + + + +/*********************************************************************************** +* This function is the entry point of the parallel multilevel local diffusion +* algorithm. It uses parallel undirected diffusion followed by adaptive k-way +* refinement. This function utilizes local coarsening. +************************************************************************************/ +void ParMETIS_V3_RefineKway(idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, + idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *ncon, + int *nparts, float *tpwgts, float *ubvec, int *options, int *edgecut, + idxtype *part, MPI_Comm *comm) +{ + int h, i; + int npes, mype; + CtrlType ctrl; + WorkSpaceType wspace; + GraphType *graph; + int tewgt, tvsize, nmoved, maxin, maxout; + float gtewgt, gtvsize, avg, maximb; + int ps_relation, seed, dbglvl = 0; + int iwgtflag, inumflag, incon, inparts, ioptions[10]; + float *itpwgts, iubvec[MAXNCON]; + + MPI_Comm_size(*comm, &npes); + MPI_Comm_rank(*comm, &mype); + + /********************************/ + /* Try and take care bad inputs */ + /********************************/ + if (options != NULL && options[0] == 1) + dbglvl = options[PMV3_OPTION_DBGLVL]; + CheckInputs(REFINE_PARTITION, npes, dbglvl, wgtflag, &iwgtflag, numflag, &inumflag, + ncon, &incon, nparts, &inparts, tpwgts, &itpwgts, ubvec, iubvec, + NULL, NULL, options, ioptions, part, comm); + + /* ADD: take care of disconnected graph */ + /* ADD: take care of highly unbalanced vtxdist */ + /*********************************/ + /* Take care the nparts = 1 case */ + /*********************************/ + if (inparts <= 1) { + idxset(vtxdist[mype+1]-vtxdist[mype], 0, part); + *edgecut = 0; + return; + } + + /**************************/ + /* Set up data structures */ + /**************************/ + if (inumflag == 1) + ChangeNumbering(vtxdist, xadj, adjncy, part, npes, mype, 1); + + /*****************************/ + /* Set up control structures */ + /*****************************/ + if (ioptions[0] == 1) { + dbglvl = ioptions[PMV3_OPTION_DBGLVL]; + seed = ioptions[PMV3_OPTION_SEED]; + ps_relation = (npes == inparts) ? ioptions[PMV3_OPTION_PSR] : DISCOUPLED; + } + else { + dbglvl = GLOBAL_DBGLVL; + seed = GLOBAL_SEED; + ps_relation = (npes == inparts) ? COUPLED : DISCOUPLED; + } + + SetUpCtrl(&ctrl, inparts, dbglvl, *comm); + ctrl.CoarsenTo = amin(vtxdist[npes]+1, 50*incon*amax(npes, inparts)); + ctrl.ipc_factor = 1000.0; + ctrl.redist_factor = 1.0; + ctrl.redist_base = 1.0; + ctrl.seed = (seed == 0) ? mype : seed*mype; + ctrl.sync = GlobalSEMax(&ctrl, seed); + ctrl.partType = REFINE_PARTITION; + ctrl.ps_relation = ps_relation; + ctrl.tpwgts = itpwgts; + + graph = Moc_SetUpGraph(&ctrl, incon, vtxdist, xadj, vwgt, adjncy, adjwgt, &iwgtflag); + graph->vsize = idxsmalloc(graph->nvtxs, 1, "vsize"); + + graph->home = idxmalloc(graph->nvtxs, "home"); + if (ctrl.ps_relation == COUPLED) + idxset(graph->nvtxs, mype, graph->home); + else + idxcopy(graph->nvtxs, part, graph->home); + + tewgt = idxsum(graph->nedges, graph->adjwgt); + tvsize = idxsum(graph->nvtxs, graph->vsize); + gtewgt = (float) GlobalSESum(&ctrl, tewgt) + 1.0/graph->gnvtxs; + gtvsize = (float) GlobalSESum(&ctrl, tvsize) + 1.0/graph->gnvtxs; + ctrl.edge_size_ratio = gtewgt/gtvsize; + scopy(incon, iubvec, ctrl.ubvec); + + PreAllocateMemory(&ctrl, graph, &wspace); + + /***********************/ + /* Partition and Remap */ + /***********************/ + IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); + + Adaptive_Partition(&ctrl, graph, &wspace); + ParallelReMapGraph(&ctrl, graph, &wspace); + + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); + + idxcopy(graph->nvtxs, graph->where, part); + if (edgecut != NULL) + *edgecut = graph->mincut; + + /***********************/ + /* Take care of output */ + /***********************/ + IFSET(ctrl.dbglvl, DBG_TIME, PrintTimingInfo(&ctrl)); + IFSET(ctrl.dbglvl, DBG_TIME, MPI_Barrier(ctrl.gcomm)); + + if (ctrl.dbglvl&DBG_INFO) { + Mc_ComputeMoveStatistics(&ctrl, graph, &nmoved, &maxin, &maxout); + rprintf(&ctrl, "Final %3d-way Cut: %6d \tBalance: ", inparts, graph->mincut); + avg = 0.0; + for (h=0; h<incon; h++) { + maximb = 0.0; + for (i=0; i<inparts; i++) + maximb = amax(maximb, graph->gnpwgts[i*incon+h]/itpwgts[i*incon+h]); + avg += maximb; + rprintf(&ctrl, "%.3f ", maximb); + } + rprintf(&ctrl, "\nNMoved: %d %d %d %d\n", nmoved, maxin, maxout, maxin+maxout); + } + + /*************************************/ + /* Free memory, renumber, and return */ + /*************************************/ + GKfree((void **)&graph->lnpwgts, (void **)&graph->gnpwgts, (void **)&graph->nvwgt, (void **)(&graph->home), (void **)(&graph->vsize), LTERM); + + GKfree((void **)&itpwgts, LTERM); + FreeInitialGraphAndRemap(graph, iwgtflag); + FreeWSpace(&wspace); + FreeCtrl(&ctrl); + + if (inumflag == 1) + ChangeNumbering(vtxdist, xadj, adjncy, part, npes, mype, 0); + + return; +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/selectq.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/selectq.c new file mode 100644 index 0000000..5ec9109 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/selectq.c @@ -0,0 +1,340 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * selectq.c + * + * This file contains the driving routines for multilevel k-way refinement + * + * Started 7/28/97 + * George + * + * $Id: selectq.c,v 1.2 2003/07/21 17:18:53 karypis Exp $ + */ + +#include <parmetislib.h> + +/************************************************************************* +* This stuff is hardcoded for up to four constraints +**************************************************************************/ +void Moc_DynamicSelectQueue(int nqueues, int ncon, int subdomain1, int subdomain2, + idxtype *currentq, float *flows, int *from, int *qnum, int minval, float avgvwgt, + float maxdiff) +{ + int i, j; + int hash, index = -1, current; + int cand[MAXNCON], rank[MAXNCON], dont_cares[MAXNCON]; + int nperms, perm[24][5]; + float sign = 0.0; + KVType array[MAXNCON]; +int mype; +MPI_Comm_rank(MPI_COMM_WORLD, &mype); + + *qnum = -1; + + if (*from == -1) { + for (i=0; i<ncon; i++) { + array[i].key = i; + array[i].val = (fabs)(flows[i]); + } + + qsort(array, ncon, sizeof(KVType), myvalkeycompare); + ASSERTS(array[ncon-1].val - array[0].val <= maxdiff) + + if (flows[array[ncon-1].key]>avgvwgt*MOC_GD_GRANULARITY_FACTOR) { + *from = subdomain1; + sign = 1.0; + index = 0; + } + + if (flows[array[ncon-1].key]<-1.0*avgvwgt*MOC_GD_GRANULARITY_FACTOR) { + *from = subdomain2; + sign = -1.0; + index = nqueues; + } + + if (*from == -1) { + return; + } + } + else { + ASSERTS(*from == subdomain1 || *from == subdomain2); + + if (*from == subdomain1) { + sign = 1.0; + index = 0; + } + else { + sign = -1.0; + index = nqueues; + } + } + + for (i=0; i<ncon; i++) { + array[i].key = i; + array[i].val = flows[i] * sign; + } + + qsort(array, ncon, sizeof(KVType), myvalkeycompare); + + iset(ncon, 1, dont_cares); + + current = 0; + for (i=0; i<ncon-1; i++) + if (array[i+1].val - array[i].val < maxdiff * MC_FLOW_BALANCE_THRESHOLD && dont_cares[current] < ncon-1) { + dont_cares[current]++; + dont_cares[i+1] = 0; + } + else + current = i+1; + + + switch (ncon) { + /***********************/ + case 2: + nperms = 1; + perm[0][0] = 0; perm[0][1] = 1; + + break; + /***********************/ + case 3: + + /* if the first and second flows are close */ + if (dont_cares[0] == 2 && dont_cares[1] == 0 && dont_cares[2] == 1) { + nperms = 4; + perm[0][0] = 0; perm[0][1] = 1; perm[0][2] = 2; + perm[1][0] = 1; perm[1][1] = 0; perm[1][2] = 2; + perm[2][0] = 0; perm[2][1] = 2; perm[2][2] = 1; + perm[3][0] = 1; perm[3][1] = 2; perm[3][2] = 0; + break; + } + + /* if the second and third flows are close */ + if (dont_cares[0] == 1 && dont_cares[1] == 2 && dont_cares[2] == 0) { + nperms = 4; + perm[0][0] = 0; perm[0][1] = 1; perm[0][2] = 2; + perm[1][0] = 0; perm[1][1] = 2; perm[1][2] = 1; + perm[2][0] = 1; perm[2][1] = 0; perm[2][2] = 2; + perm[3][0] = 2; perm[3][1] = 0; perm[3][2] = 1; + break; + } + + /* all or none of the flows are close */ + nperms = 3; + perm[0][0] = 0; perm[0][1] = 1; perm[0][2] = 2; + perm[1][0] = 1; perm[1][1] = 0; perm[1][2] = 2; + perm[2][0] = 0; perm[2][1] = 2; perm[2][2] = 1; + + break; + /***********************/ + case 4: + + if (dont_cares[0] == 2 && dont_cares[1] == 0 && + dont_cares[2] == 1 && dont_cares[3] == 1) { + nperms = 14; + perm[0][0] = 0; perm[0][1] = 1; perm[0][2] = 2; perm[0][3] = 3; + perm[1][0] = 1; perm[1][1] = 0; perm[1][2] = 2; perm[1][3] = 3; + perm[2][0] = 0; perm[2][1] = 2; perm[2][2] = 1; perm[2][3] = 3; + perm[3][0] = 1; perm[3][1] = 2; perm[3][2] = 0; perm[3][3] = 3; + perm[4][0] = 0; perm[4][1] = 1; perm[4][2] = 3; perm[4][3] = 2; + perm[5][0] = 1; perm[5][1] = 0; perm[5][2] = 3; perm[5][3] = 2; + + perm[6][0] = 0; perm[6][1] = 3; perm[6][2] = 1; perm[6][3] = 2; + perm[7][0] = 1; perm[7][1] = 3; perm[7][2] = 0; perm[7][3] = 2; + + perm[8][0] = 0; perm[8][1] = 2; perm[8][2] = 3; perm[8][3] = 1; + perm[9][0] = 1; perm[9][1] = 2; perm[9][2] = 3; perm[9][3] = 0; + + perm[10][0] = 2; perm[10][1] = 0; perm[10][2] = 1; perm[10][3] = 3; + perm[11][0] = 2; perm[11][1] = 1; perm[11][2] = 0; perm[11][3] = 3; + + perm[12][0] = 0; perm[12][1] = 3; perm[12][2] = 2; perm[12][3] = 1; + perm[13][0] = 1; perm[13][1] = 3; perm[13][2] = 2; perm[13][3] = 0; + break; + } + + if (dont_cares[0] == 1 && dont_cares[1] == 1 && + dont_cares[2] == 2 && dont_cares[3] == 0) { + nperms = 14; + perm[0][0] = 0; perm[0][1] = 1; perm[0][2] = 2; perm[0][3] = 3; + perm[1][0] = 0; perm[1][1] = 1; perm[1][2] = 3; perm[1][3] = 2; + perm[2][0] = 0; perm[2][1] = 2; perm[2][2] = 1; perm[2][3] = 3; + perm[3][0] = 0; perm[3][1] = 3; perm[3][2] = 1; perm[3][3] = 2; + perm[4][0] = 1; perm[4][1] = 0; perm[4][2] = 2; perm[4][3] = 3; + perm[5][0] = 1; perm[5][1] = 0; perm[5][2] = 3; perm[5][3] = 2; + + perm[6][0] = 1; perm[6][1] = 2; perm[6][2] = 0; perm[6][3] = 3; + perm[7][0] = 1; perm[7][1] = 3; perm[7][2] = 0; perm[7][3] = 2; + + perm[8][0] = 2; perm[8][1] = 0; perm[8][2] = 1; perm[8][3] = 3; + perm[9][0] = 3; perm[9][1] = 0; perm[9][2] = 1; perm[9][3] = 2; + + perm[10][0] = 0; perm[10][1] = 2; perm[10][2] = 3; perm[10][3] = 1; + perm[11][0] = 0; perm[11][1] = 3; perm[11][2] = 2; perm[11][3] = 1; + + perm[12][0] = 2; perm[12][1] = 1; perm[12][2] = 0; perm[12][3] = 3; + perm[13][0] = 3; perm[13][1] = 1; perm[13][2] = 0; perm[13][3] = 2; + break; + } + + if (dont_cares[0] == 2 && dont_cares[1] == 0 && + dont_cares[2] == 2 && dont_cares[3] == 0) { + nperms = 14; + perm[0][0] = 0; perm[0][1] = 1; perm[0][2] = 2; perm[0][3] = 3; + perm[1][0] = 1; perm[1][1] = 0; perm[1][2] = 2; perm[1][3] = 3; + perm[2][0] = 0; perm[2][1] = 1; perm[2][2] = 3; perm[2][3] = 2; + perm[3][0] = 1; perm[3][1] = 0; perm[3][2] = 3; perm[3][3] = 2; + + perm[4][0] = 0; perm[4][1] = 2; perm[4][2] = 1; perm[4][3] = 3; + perm[5][0] = 1; perm[5][1] = 2; perm[5][2] = 0; perm[5][3] = 3; + perm[6][0] = 0; perm[6][1] = 3; perm[6][2] = 1; perm[6][3] = 2; + perm[7][0] = 1; perm[7][1] = 3; perm[7][2] = 0; perm[7][3] = 2; + + perm[8][0] = 2; perm[8][1] = 0; perm[8][2] = 1; perm[8][3] = 3; + perm[9][0] = 0; perm[9][1] = 2; perm[9][2] = 3; perm[9][3] = 1; + perm[10][0] = 2; perm[10][1] = 1; perm[10][2] = 0; perm[10][3] = 3; + perm[11][0] = 0; perm[11][1] = 3; perm[11][2] = 2; perm[11][3] = 1; + perm[12][0] = 3; perm[12][1] = 0; perm[12][2] = 1; perm[12][3] = 2; + perm[13][0] = 1; perm[13][1] = 2; perm[13][2] = 3; perm[13][3] = 0; + break; + } + + if (dont_cares[0] == 3 && dont_cares[1] == 0 && + dont_cares[2] == 0 && dont_cares[3] == 1) { + nperms = 14; + perm[0][0] = 0; perm[0][1] = 1; perm[0][2] = 2; perm[0][3] = 3; + perm[1][0] = 0; perm[1][1] = 2; perm[1][2] = 1; perm[1][3] = 3; + perm[2][0] = 1; perm[2][1] = 0; perm[2][2] = 2; perm[2][3] = 3; + perm[3][0] = 2; perm[3][1] = 0; perm[3][2] = 1; perm[3][3] = 3; + perm[4][0] = 1; perm[4][1] = 2; perm[4][2] = 0; perm[4][3] = 3; + perm[5][0] = 2; perm[5][1] = 1; perm[5][2] = 0; perm[5][3] = 3; + + perm[6][0] = 0; perm[6][1] = 1; perm[6][2] = 3; perm[6][3] = 2; + perm[7][0] = 1; perm[7][1] = 0; perm[7][2] = 3; perm[7][3] = 2; + perm[8][0] = 0; perm[8][1] = 2; perm[8][2] = 3; perm[8][3] = 1; + perm[9][0] = 2; perm[9][1] = 0; perm[9][2] = 3; perm[9][3] = 1; + perm[10][0] = 1; perm[10][1] = 2; perm[10][2] = 3; perm[10][3] = 0; + perm[11][0] = 2; perm[11][1] = 1; perm[11][2] = 3; perm[11][3] = 0; + + perm[12][0] = 0; perm[12][1] = 3; perm[12][2] = 1; perm[12][3] = 2; + perm[13][0] = 0; perm[13][1] = 3; perm[13][2] = 2; perm[13][3] = 1; + break; + } + + if (dont_cares[0] == 1 && dont_cares[1] == 3 && + dont_cares[2] == 0 && dont_cares[3] == 0) { + nperms = 14; + perm[0][0] = 0; perm[0][1] = 1; perm[0][2] = 2; perm[0][3] = 3; + perm[1][0] = 0; perm[1][1] = 2; perm[1][2] = 1; perm[1][3] = 3; + perm[2][0] = 0; perm[2][1] = 1; perm[2][2] = 3; perm[2][3] = 2; + perm[3][0] = 0; perm[3][1] = 2; perm[3][2] = 3; perm[3][3] = 1; + perm[4][0] = 0; perm[4][1] = 3; perm[4][2] = 1; perm[4][3] = 2; + perm[5][0] = 0; perm[5][1] = 3; perm[5][2] = 2; perm[5][3] = 1; + + perm[6][0] = 1; perm[6][1] = 0; perm[6][2] = 2; perm[6][3] = 3; + perm[7][0] = 1; perm[7][1] = 0; perm[7][2] = 3; perm[7][3] = 2; + perm[8][0] = 2; perm[8][1] = 0; perm[8][2] = 1; perm[8][3] = 3; + perm[9][0] = 2; perm[9][1] = 0; perm[9][2] = 3; perm[9][3] = 1; + perm[10][0] = 3; perm[10][1] = 0; perm[10][2] = 1; perm[10][3] = 2; + perm[11][0] = 3; perm[11][1] = 0; perm[11][2] = 2; perm[11][3] = 1; + + perm[12][0] = 1; perm[12][1] = 2; perm[12][2] = 0; perm[12][3] = 3; + perm[13][0] = 2; perm[13][1] = 1; perm[13][2] = 0; perm[13][3] = 3; + + break; + } + + nperms = 14; + perm[0][0] = 0; perm[0][1] = 1; perm[0][2] = 2; perm[0][3] = 3; + perm[1][0] = 1; perm[1][1] = 0; perm[1][2] = 2; perm[1][3] = 3; + perm[2][0] = 0; perm[2][1] = 2; perm[2][2] = 1; perm[2][3] = 3; + perm[3][0] = 0; perm[3][1] = 1; perm[3][2] = 3; perm[3][3] = 2; + perm[4][0] = 1; perm[4][1] = 0; perm[4][2] = 3; perm[4][3] = 2; + + perm[5][0] = 2; perm[5][1] = 0; perm[5][2] = 1; perm[5][3] = 3; + perm[6][0] = 0; perm[6][1] = 2; perm[6][2] = 3; perm[6][3] = 1; + + perm[7][0] = 1; perm[7][1] = 2; perm[7][2] = 0; perm[7][3] = 3; + perm[8][0] = 0; perm[8][1] = 3; perm[8][2] = 1; perm[8][3] = 2; + + perm[9][0] = 2; perm[9][1] = 1; perm[9][2] = 0; perm[9][3] = 3; + perm[10][0] = 0; perm[10][1] = 3; perm[10][2] = 2; perm[10][3] = 1; + perm[11][0] = 2; perm[11][1] = 0; perm[11][2] = 3; perm[11][3] = 1; + + perm[12][0] = 3; perm[12][1] = 0; perm[12][2] = 1; perm[12][3] = 2; + perm[13][0] = 1; perm[13][1] = 2; perm[13][2] = 3; perm[13][3] = 0; + break; + /***********************/ + default: + return; + } + + for (i=0; i<nperms; i++) { + for (j=0; j<ncon; j++) + cand[j] = array[perm[i][j]].key; + + for (j=0; j<ncon; j++) + rank[cand[j]] = j; + + + hash = Moc_HashVRank(ncon, rank) - minval; + if (currentq[hash+index] > 0) { + *qnum = hash; + return; + } + } + + return; +} + + +/************************************************************************* +* This function sorts the nvwgts of a vertex and returns a hashed value +**************************************************************************/ +int Moc_HashVwgts(int ncon, float *nvwgt) +{ + int i; + int multiplier, retval; + int rank[MAXNCON]; + KVType array[MAXNCON]; + + + for (i=0; i<ncon; i++) { + array[i].key = i; + array[i].val = nvwgt[i]; + } + + qsort(array, ncon, sizeof(KVType), myvalkeycompare); + for (i=0; i<ncon; i++) + rank[array[i].key] = i; + + multiplier = 1; + + retval = 0; + for (i=0; i<ncon; i++) { + multiplier *= (i+1); + retval += rank[ncon-i-1] * multiplier; + } + + return retval; +} + + +/************************************************************************* +* This function sorts the vwgts of a vertex and returns a hashed value +**************************************************************************/ +int Moc_HashVRank(int ncon, int *vwgt) +{ + int i, multiplier, retval; + + multiplier = 1; + + retval = 0; + for (i=0; i<ncon; i++) { + multiplier *= (i+1); + retval += vwgt[ncon-1-i] * multiplier; + } + + return retval; +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/serial.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/serial.c new file mode 100644 index 0000000..630d4e5 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/serial.c @@ -0,0 +1,1251 @@ +/* + * serial.c + * + * This file contains code that implements k-way refinement + * + * Started 7/28/97 + * George + * + * $Id: serial.c,v 1.2 2003/07/21 17:18:53 karypis Exp $ + * + */ + +#include <parmetislib.h> + + +/************************************************************************* +* This function performs k-way refinement +**************************************************************************/ +void Moc_SerialKWayAdaptRefine(GraphType *graph, int nparts, idxtype *home, + float *orgubvec, int npasses) +{ + int i, ii, iii, j, k; + int nvtxs, ncon, pass, nmoves, myndegrees; + int from, me, myhome, to, oldcut, gain, tmp; + idxtype *xadj, *adjncy, *adjwgt; + idxtype *where; + EdgeType *mydegrees; + RInfoType *rinfo, *myrinfo; + float *npwgts, *nvwgt, *minwgt, *maxwgt, ubvec[MAXNCON]; + int gain_is_greater, gain_is_same, fit_in_to, fit_in_from, going_home; + int zero_gain, better_balance_ft, better_balance_tt; + KeyValueType *cand; +int mype; +MPI_Comm_rank(MPI_COMM_WORLD, &mype); + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + rinfo = graph->rinfo; + npwgts = graph->gnpwgts; + + /* Setup the weight intervals of the various subdomains */ + cand = (KeyValueType *)GKmalloc(nvtxs*sizeof(KeyValueType), "cand"); + minwgt = fmalloc(nparts*ncon, "minwgt"); + maxwgt = fmalloc(nparts*ncon, "maxwgt"); + + ComputeHKWayLoadImbalance(ncon, nparts, npwgts, ubvec); + for (i=0; i<ncon; i++) + ubvec[i] = amax(ubvec[i], orgubvec[i]); + + for (i=0; i<nparts; i++) { + for (j=0; j<ncon; j++) { + maxwgt[i*ncon+j] = ubvec[j]/(float)nparts; + minwgt[i*ncon+j] = ubvec[j]*(float)nparts; + } + } + + for (pass=0; pass<npasses; pass++) { + oldcut = graph->mincut; + + for (i=0; i<nvtxs; i++) { + cand[i].key = rinfo[i].id-rinfo[i].ed; + cand[i].val = i; + } + ikeysort(nvtxs, cand); + + nmoves = 0; + for (iii=0; iii<nvtxs; iii++) { + i = cand[iii].val; + + myrinfo = rinfo+i; + + if (myrinfo->ed >= myrinfo->id) { + from = where[i]; + myhome = home[i]; + nvwgt = graph->nvwgt+i*ncon; + + if (myrinfo->id > 0 && + AreAllHVwgtsBelow(ncon, 1.0, npwgts+from*ncon, -1.0, nvwgt, minwgt+from*ncon)) + continue; + + mydegrees = myrinfo->degrees; + myndegrees = myrinfo->ndegrees; + + for (k=0; k<myndegrees; k++) { + to = mydegrees[k].edge; + gain = mydegrees[k].ewgt - myrinfo->id; + if (gain >= 0 && + (AreAllHVwgtsBelow(ncon, 1.0, npwgts+to*ncon, 1.0, nvwgt, maxwgt+to*ncon) || + IsHBalanceBetterFT(ncon,npwgts+from*ncon,npwgts+to*ncon,nvwgt,ubvec))) { + break; + } + } + + /* break out if you did not find a candidate */ + if (k == myndegrees) + continue; + + for (j=k+1; j<myndegrees; j++) { + to = mydegrees[j].edge; + going_home = (myhome == to); + gain_is_same = (mydegrees[j].ewgt == mydegrees[k].ewgt); + gain_is_greater = (mydegrees[j].ewgt > mydegrees[k].ewgt); + fit_in_to = AreAllHVwgtsBelow(ncon,1.0,npwgts+to*ncon,1.0,nvwgt,maxwgt+to*ncon); + better_balance_ft = IsHBalanceBetterFT(ncon,npwgts+from*ncon, + npwgts+to*ncon,nvwgt,ubvec); + better_balance_tt = IsHBalanceBetterTT(ncon,npwgts+mydegrees[k].edge*ncon, + npwgts+to*ncon,nvwgt,ubvec); + + if ( + (gain_is_greater && + (fit_in_to || + better_balance_ft) + ) + || + (gain_is_same && + ( + (fit_in_to && + going_home) + || + better_balance_tt + ) + ) + ) { + k = j; + } + } + + to = mydegrees[k].edge; + going_home = (myhome == to); + zero_gain = (mydegrees[k].ewgt == myrinfo->id); + + fit_in_from = AreAllHVwgtsBelow(ncon,1.0,npwgts+from*ncon,0.0,npwgts+from*ncon, + maxwgt+from*ncon); + better_balance_ft = IsHBalanceBetterFT(ncon,npwgts+from*ncon, + npwgts+to*ncon,nvwgt,ubvec); + + if (zero_gain && + !going_home && + !better_balance_ft && + fit_in_from) + continue; + + /*===================================================================== + * If we got here, we can now move the vertex from 'from' to 'to' + *======================================================================*/ + graph->mincut -= mydegrees[k].ewgt-myrinfo->id; + + /* Update where, weight, and ID/ED information of the vertex you moved */ + saxpy2(ncon, 1.0, nvwgt, 1, npwgts+to*ncon, 1); + saxpy2(ncon, -1.0, nvwgt, 1, npwgts+from*ncon, 1); + where[i] = to; + myrinfo->ed += myrinfo->id-mydegrees[k].ewgt; + SWAP(myrinfo->id, mydegrees[k].ewgt, tmp); + + if (mydegrees[k].ewgt == 0) { + myrinfo->ndegrees--; + mydegrees[k].edge = mydegrees[myrinfo->ndegrees].edge; + mydegrees[k].ewgt = mydegrees[myrinfo->ndegrees].ewgt; + } + else + mydegrees[k].edge = from; + + /* Update the degrees of adjacent vertices */ + for (j=xadj[i]; j<xadj[i+1]; j++) { + ii = adjncy[j]; + me = where[ii]; + + myrinfo = rinfo+ii; + mydegrees = myrinfo->degrees; + + if (me == from) { + INC_DEC(myrinfo->ed, myrinfo->id, adjwgt[j]); + } + else { + if (me == to) { + INC_DEC(myrinfo->id, myrinfo->ed, adjwgt[j]); + } + } + + /* Remove contribution of the ed from 'from' */ + if (me != from) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (mydegrees[k].edge == from) { + if (mydegrees[k].ewgt == adjwgt[j]) { + myrinfo->ndegrees--; + mydegrees[k].edge = mydegrees[myrinfo->ndegrees].edge; + mydegrees[k].ewgt = mydegrees[myrinfo->ndegrees].ewgt; + } + else + mydegrees[k].ewgt -= adjwgt[j]; + break; + } + } + } + + /* Add contribution of the ed to 'to' */ + if (me != to) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (mydegrees[k].edge == to) { + mydegrees[k].ewgt += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + mydegrees[myrinfo->ndegrees].edge = to; + mydegrees[myrinfo->ndegrees++].ewgt = adjwgt[j]; + } + } + + } + nmoves++; + } + } + + if (graph->mincut == oldcut) + break; + } + + GKfree((void **)&minwgt, (void **)&maxwgt, (void **)&cand, LTERM); + + return; +} + + +/************************************************************************* +* This function computes the initial id/ed +**************************************************************************/ +void Moc_ComputeSerialPartitionParams(GraphType *graph, int nparts, + EdgeType *degrees) +{ + int i, j, k; + int nvtxs, nedges, ncon, mincut, me, other; + idxtype *xadj, *adjncy, *adjwgt, *where; + RInfoType *rinfo, *myrinfo; + EdgeType *mydegrees; + float *nvwgt, *npwgts; +int mype; +MPI_Comm_rank(MPI_COMM_WORLD, &mype); + + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + rinfo = graph->rinfo; + + npwgts = sset(ncon*nparts, 0.0, graph->gnpwgts); + + /*------------------------------------------------------------ + / Compute now the id/ed degrees + /------------------------------------------------------------*/ + nedges = mincut = 0; + for (i=0; i<nvtxs; i++) { + me = where[i]; + saxpy2(ncon, 1.0, nvwgt+i*ncon, 1, npwgts+me*ncon, 1); + + myrinfo = rinfo+i; + myrinfo->id = myrinfo->ed = myrinfo->ndegrees = 0; + myrinfo->degrees = degrees + nedges; + nedges += xadj[i+1]-xadj[i]; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (me == where[adjncy[j]]) { + myrinfo->id += adjwgt[j]; + } + else { + myrinfo->ed += adjwgt[j]; + } + } + + mincut += myrinfo->ed; + + /* Time to compute the particular external degrees */ + if (myrinfo->ed > 0) { + mydegrees = myrinfo->degrees; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + other = where[adjncy[j]]; + if (me != other) { + for (k=0; k<myrinfo->ndegrees; k++) { + if (mydegrees[k].edge == other) { + mydegrees[k].ewgt += adjwgt[j]; + break; + } + } + if (k == myrinfo->ndegrees) { + mydegrees[myrinfo->ndegrees].edge = other; + mydegrees[myrinfo->ndegrees++].ewgt = adjwgt[j]; + } + } + } + } + } + + graph->mincut = mincut/2; + + return; +} + + +/************************************************************************* +* This function checks if the vertex weights of two vertices are below +* a given set of values +**************************************************************************/ +int AreAllHVwgtsBelow(int ncon, float alpha, float *vwgt1, float beta, float *vwgt2, float *limit) +{ + int i; + + for (i=0; i<ncon; i++) + if (alpha*vwgt1[i] + beta*vwgt2[i] > limit[i]) + return 0; + + return 1; +} + + +/************************************************************************* +* This function computes the load imbalance over all the constrains +* For now assume that we just want balanced partitionings +**************************************************************************/ +void ComputeHKWayLoadImbalance(int ncon, int nparts, float *npwgts, float *lbvec) +{ + int i, j; + float max; + + for (i=0; i<ncon; i++) { + max = 0.0; + for (j=0; j<nparts; j++) { + if (npwgts[j*ncon+i] > max) + max = npwgts[j*ncon+i]; + } + + lbvec[i] = max*nparts; + } +} + + +/************************************************************** +* This subroutine remaps a partitioning on a single processor +**************************************************************/ +void SerialRemap(GraphType *graph, int nparts, idxtype *base, idxtype *scratch, + idxtype *remap, float *tpwgts) +{ + int i, ii, j, k; + int nvtxs, nmapped, max_mult; + int from, to, current_from, smallcount, bigcount; + KeyValueType *flowto, *bestflow; + KeyKeyValueType *sortvtx; + idxtype *vsize, *htable, *map, *rowmap; + + nvtxs = graph->nvtxs; + vsize = graph->vsize; + max_mult = amin(MAX_NPARTS_MULTIPLIER, nparts); + + sortvtx = (KeyKeyValueType *)GKmalloc(nvtxs*sizeof(KeyKeyValueType), "sortvtx"); + flowto = (KeyValueType *)GKmalloc((nparts*max_mult+nparts)*sizeof(KeyValueType), "flowto"); + bestflow = flowto+nparts; + map = htable = idxsmalloc(nparts*2, -1, "htable"); + rowmap = map+nparts; + + for (i=0; i<nvtxs; i++) { + sortvtx[i].key1 = base[i]; + sortvtx[i].key2 = vsize[i]; + sortvtx[i].val = i; + } + + qsort((void *)sortvtx, (size_t)nvtxs, (size_t)sizeof(KeyKeyValueType), SSMIncKeyCmp); + + for (j=0; j<nparts; j++) { + flowto[j].key = 0; + flowto[j].val = j; + } + + /* this step has nparts*nparts*log(nparts) computational complexity */ + bigcount = smallcount = current_from = 0; + for (ii=0; ii<nvtxs; ii++) { + i = sortvtx[ii].val; + from = base[i]; + to = scratch[i]; + + if (from > current_from) { + /* reset the hash table */ + for (j=0; j<smallcount; j++) + htable[flowto[j].val] = -1; + ASSERTS(idxsum(nparts, htable) == -nparts); + + ikeysort(smallcount, flowto); + + for (j=0; j<amin(smallcount, max_mult); j++, bigcount++) { + bestflow[bigcount].key = flowto[j].key; + bestflow[bigcount].val = current_from*nparts+flowto[j].val; + } + + smallcount = 0; + current_from = from; + } + + if (htable[to] == -1) { + htable[to] = smallcount; + flowto[smallcount].key = -vsize[i]; + flowto[smallcount].val = to; + smallcount++; + } + else { + flowto[htable[to]].key += -vsize[i]; + } + } + + /* reset the hash table */ + for (j=0; j<smallcount; j++) + htable[flowto[j].val] = -1; + ASSERTS(idxsum(nparts, htable) == -nparts); + + ikeysort(smallcount, flowto); + + for (j=0; j<amin(smallcount, max_mult); j++, bigcount++) { + bestflow[bigcount].key = flowto[j].key; + bestflow[bigcount].val = current_from*nparts+flowto[j].val; + } + ikeysort(bigcount, bestflow); + + ASSERTS(idxsum(nparts, map) == -nparts); + ASSERTS(idxsum(nparts, rowmap) == -nparts); + nmapped = 0; + + /* now make as many assignments as possible */ + for (ii=0; ii<bigcount; ii++) { + i = bestflow[ii].val; + j = i % nparts; /* to */ + k = i / nparts; /* from */ + + if (map[j] == -1 && rowmap[k] == -1 && SimilarTpwgts(tpwgts, graph->ncon, j, k)) { + map[j] = k; + rowmap[k] = j; + nmapped++; + } + + if (nmapped == nparts) + break; + } + + + /* remap the rest */ + /* it may help try remapping to the same label first */ + if (nmapped < nparts) { + for (j=0; j<nparts && nmapped<nparts; j++) { + if (map[j] == -1) { + for (ii=0; ii<nparts; ii++) { + i = (j+ii) % nparts; + if (rowmap[i] == -1 && SimilarTpwgts(tpwgts, graph->ncon, i, j)) { + map[j] = i; + rowmap[i] = j; + nmapped++; + break; + } + } + } + } + } + + /* check to see if remapping fails (due to dis-similar tpwgts) */ + /* if remapping fails, revert to original mapping */ + if (nmapped < nparts) + for (i=0; i<nparts; i++) + map[i] = i; + + for (i=0; i<nvtxs; i++) + remap[i] = map[remap[i]]; + + GKfree((void **)&sortvtx, (void **)&flowto, (void **)&htable, LTERM); +} + + +/************************************************************************* +* This is a comparison function for Serial Remap +**************************************************************************/ +int SSMIncKeyCmp(const void *fptr, const void *sptr) +{ + KeyKeyValueType *first, *second; + + first = (KeyKeyValueType *)(fptr); + second = (KeyKeyValueType *)(sptr); + + if (first->key1 > second->key1) + return 1; + + if (first->key1 < second->key1) + return -1; + + if (first->key2 < second->key2) + return 1; + + if (first->key2 > second->key2) + return -1; + + return 0; +} + + +/************************************************************************* +* This function performs an edge-based FM refinement +**************************************************************************/ +void Moc_Serial_FM_2WayRefine(GraphType *graph, float *tpwgts, int npasses) +{ + int i, ii, j, k; + int kwgt, nvtxs, ncon, nbnd, nswaps, from, to, pass, limit, tmp, cnum; + idxtype *xadj, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind; + idxtype *moved, *swaps, *qnum; + float *nvwgt, *npwgts, mindiff[MAXNCON], origbal, minbal, newbal; + FPQueueType parts[MAXNCON][2]; + int higain, oldgain, mincut, initcut, newcut, mincutorder; + float rtpwgts[MAXNCON*2]; + KeyValueType *cand; +int mype; +MPI_Comm_rank(MPI_COMM_WORLD, &mype); + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + id = graph->sendind; + ed = graph->recvind; + npwgts = graph->gnpwgts; + bndptr = graph->sendptr; + bndind = graph->recvptr; + + moved = idxmalloc(nvtxs, "moved"); + swaps = idxmalloc(nvtxs, "swaps"); + qnum = idxmalloc(nvtxs, "qnum"); + cand = (KeyValueType *)GKmalloc(nvtxs*sizeof(KeyValueType), "cand"); + + limit = amin(amax(0.01*nvtxs, 25), 150); + + /* Initialize the queues */ + for (i=0; i<ncon; i++) { + FPQueueInit(&parts[i][0], nvtxs); + FPQueueInit(&parts[i][1], nvtxs); + } + for (i=0; i<nvtxs; i++) + qnum[i] = samax(ncon, nvwgt+i*ncon); + + origbal = Serial_Compute2WayHLoadImbalance(ncon, npwgts, tpwgts); + + for (i=0; i<ncon; i++) { + rtpwgts[i] = origbal*tpwgts[i]; + rtpwgts[ncon+i] = origbal*tpwgts[ncon+i]; + } + + idxset(nvtxs, -1, moved); + for (pass=0; pass<npasses; pass++) { /* Do a number of passes */ + for (i=0; i<ncon; i++) { + FPQueueReset(&parts[i][0]); + FPQueueReset(&parts[i][1]); + } + + mincutorder = -1; + newcut = mincut = initcut = graph->mincut; + for (i=0; i<ncon; i++) + mindiff[i] = fabs(tpwgts[i]-npwgts[i]); + minbal = Serial_Compute2WayHLoadImbalance(ncon, npwgts, tpwgts); + + /* Insert boundary nodes in the priority queues */ + nbnd = graph->gnvtxs; + + for (i=0; i<nbnd; i++) { + cand[i].key = id[i]-ed[i]; + cand[i].val = i; + } + ikeysort(nbnd, cand); + + for (ii=0; ii<nbnd; ii++) { + i = bndind[cand[ii].val]; + FPQueueInsert(&parts[qnum[i]][where[i]], i, (float)(ed[i]-id[i])); + } + + for (nswaps=0; nswaps<nvtxs; nswaps++) { + Serial_SelectQueue(ncon, npwgts, rtpwgts, &from, &cnum, parts); + to = (from+1)%2; + + if (from == -1 || (higain = FPQueueGetMax(&parts[cnum][from])) == -1) + break; + + saxpy2(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy2(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + + newcut -= (ed[higain]-id[higain]); + newbal = Serial_Compute2WayHLoadImbalance(ncon, npwgts, tpwgts); + + if ((newcut < mincut && newbal-origbal <= .00001) || + (newcut == mincut && (newbal < minbal || + (newbal == minbal && Serial_BetterBalance(ncon, npwgts, tpwgts, mindiff))))) { + mincut = newcut; + minbal = newbal; + mincutorder = nswaps; + for (i=0; i<ncon; i++) + mindiff[i] = fabs(tpwgts[i]-npwgts[i]); + } + else if (nswaps-mincutorder > limit) { /* We hit the limit, undo last move */ + newcut += (ed[higain]-id[higain]); + saxpy2(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + saxpy2(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + break; + } + + where[higain] = to; + moved[higain] = nswaps; + swaps[nswaps] = higain; + + /************************************************************** + * Update the id[i]/ed[i] values of the affected nodes + ***************************************************************/ + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + oldgain = ed[k]-id[k]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + /* Update its boundary information and queue position */ + if (bndptr[k] != -1) { /* If k was a boundary vertex */ + if (ed[k] == 0) { /* Not a boundary vertex any more */ + BNDDelete(nbnd, bndind, bndptr, k); + if (moved[k] == -1) /* Remove it if in the queues */ + FPQueueDelete(&parts[qnum[k]][where[k]], k); + } + else { /* If it has not been moved, update its position in the queue */ + if (moved[k] == -1) + FPQueueUpdate(&parts[qnum[k]][where[k]], k, (float)oldgain, (float)(ed[k]-id[k])); + } + } + else { + if (ed[k] > 0) { /* It will now become a boundary vertex */ + BNDInsert(nbnd, bndind, bndptr, k); + if (moved[k] == -1) + FPQueueInsert(&parts[qnum[k]][where[k]], k, (float)(ed[k]-id[k])); + } + } + } + } + + /**************************************************************** + * Roll back computations + *****************************************************************/ + for (i=0; i<nswaps; i++) + moved[swaps[i]] = -1; /* reset moved array */ + for (nswaps--; nswaps>mincutorder; nswaps--) { + higain = swaps[nswaps]; + + to = where[higain] = (where[higain]+1)%2; + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + else if (ed[higain] > 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + saxpy2(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy2(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+((to+1)%2)*ncon, 1); + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + if (bndptr[k] != -1 && ed[k] == 0) + BNDDelete(nbnd, bndind, bndptr, k); + if (bndptr[k] == -1 && ed[k] > 0) + BNDInsert(nbnd, bndind, bndptr, k); + } + } + + graph->mincut = mincut; + graph->gnvtxs = nbnd; + + if (mincutorder == -1 || mincut == initcut) + break; + } + + for (i=0; i<ncon; i++) { + FPQueueFree(&parts[i][0]); + FPQueueFree(&parts[i][1]); + } + + GKfree((void **)&cand, (void **)&qnum, (void **)&moved, (void **)&swaps, LTERM); + return; +} + +/************************************************************************* +* This function selects the partition number and the queue from which +* we will move vertices out +**************************************************************************/ +void Serial_SelectQueue(int ncon, float *npwgts, float *tpwgts, int *from, int *cnum, + FPQueueType queues[MAXNCON][2]) +{ + int i, part; + float maxgain=0.0; + float max = -1.0, maxdiff=0.0; +int mype; +MPI_Comm_rank(MPI_COMM_WORLD, &mype); + + *from = -1; + *cnum = -1; + + /* First determine the side and the queue, irrespective of the presence of nodes */ + for (part=0; part<2; part++) { + for (i=0; i<ncon; i++) { + if (npwgts[part*ncon+i]-tpwgts[part*ncon+i] >= maxdiff) { + maxdiff = npwgts[part*ncon+i]-tpwgts[part*ncon+i]; + *from = part; + *cnum = i; + } + } + } + + if (*from != -1 && FPQueueGetQSize(&queues[*cnum][*from]) == 0) { + /* The desired queue is empty, select a node from that side anyway */ + for (i=0; i<ncon; i++) { + if (FPQueueGetQSize(&queues[i][*from]) > 0) { + max = npwgts[(*from)*ncon + i]; + *cnum = i; + break; + } + } + + for (i++; i<ncon; i++) { + if (npwgts[(*from)*ncon + i] > max && FPQueueGetQSize(&queues[i][*from]) > 0) { + max = npwgts[(*from)*ncon + i]; + *cnum = i; + } + } + } + + + /* Check to see if you can focus on the cut */ + if (maxdiff <= 0.0 || *from == -1) { + maxgain = -100000.0; + + for (part=0; part<2; part++) { + for (i=0; i<ncon; i++) { + if (FPQueueGetQSize(&queues[i][part]) > 0 && + FPQueueSeeMaxGain(&queues[i][part]) > maxgain) { + maxgain = FPQueueSeeMaxGain(&queues[i][part]); + *from = part; + *cnum = i; + } + } + } + } + + return; +} + +/************************************************************************* +* This function checks if the balance achieved is better than the diff +* For now, it uses a 2-norm measure +**************************************************************************/ +int Serial_BetterBalance(int ncon, float *npwgts, float *tpwgts, float *diff) +{ + int i; + float ndiff[MAXNCON]; + + for (i=0; i<ncon; i++) + ndiff[i] = fabs(tpwgts[i]-npwgts[i]); + + return snorm2(ncon, ndiff) < snorm2(ncon, diff); +} + + + +/************************************************************************* +* This function computes the load imbalance over all the constrains +**************************************************************************/ +float Serial_Compute2WayHLoadImbalance(int ncon, float *npwgts, float *tpwgts) +{ + int i; + float max=0.0, temp; + + for (i=0; i<ncon; i++) { + if (tpwgts[i] == 0.0) + temp = 0.0; + else + temp = fabs(tpwgts[i]-npwgts[i])/tpwgts[i]; + max = (max < temp ? temp : max); + } + return 1.0+max; +} + + + +/************************************************************************* +* This function performs an edge-based FM refinement +**************************************************************************/ +void Moc_Serial_Balance2Way(GraphType *graph, float *tpwgts, float lbfactor) +{ + int i, ii, j, k, kwgt, nvtxs, ncon, nbnd, nswaps, from, to, limit, tmp, cnum; + idxtype *xadj, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind; + idxtype *moved, *swaps, *qnum; + float *nvwgt, *npwgts, mindiff[MAXNCON], origbal, minbal, newbal; + FPQueueType parts[MAXNCON][2]; + int higain, oldgain, mincut, newcut, mincutorder; + int qsizes[MAXNCON][2]; + KeyValueType *cand; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + id = graph->sendind; + ed = graph->recvind; + npwgts = graph->gnpwgts; + bndptr = graph->sendptr; + bndind = graph->recvptr; + + moved = idxmalloc(nvtxs, "moved"); + swaps = idxmalloc(nvtxs, "swaps"); + qnum = idxmalloc(nvtxs, "qnum"); + cand = (KeyValueType *)GKmalloc(nvtxs*sizeof(KeyValueType), "cand"); + + + limit = amin(amax(0.01*nvtxs, 15), 100); + + /* Initialize the queues */ + for (i=0; i<ncon; i++) { + FPQueueInit(&parts[i][0], nvtxs); + FPQueueInit(&parts[i][1], nvtxs); + qsizes[i][0] = qsizes[i][1] = 0; + } + + for (i=0; i<nvtxs; i++) { + qnum[i] = samax(ncon, nvwgt+i*ncon); + qsizes[qnum[i]][where[i]]++; + } + + for (from=0; from<2; from++) { + for (j=0; j<ncon; j++) { + if (qsizes[j][from] == 0) { + for (i=0; i<nvtxs; i++) { + if (where[i] != from) + continue; + + k = samax2(ncon, nvwgt+i*ncon); + if (k == j && + qsizes[qnum[i]][from] > qsizes[j][from] && + nvwgt[i*ncon+qnum[i]] < 1.3*nvwgt[i*ncon+j]) { + qsizes[qnum[i]][from]--; + qsizes[j][from]++; + qnum[i] = j; + } + } + } + } + } + + + for (i=0; i<ncon; i++) + mindiff[i] = fabs(tpwgts[i]-npwgts[i]); + minbal = origbal = Serial_Compute2WayHLoadImbalance(ncon, npwgts, tpwgts); + newcut = mincut = graph->mincut; + mincutorder = -1; + + idxset(nvtxs, -1, moved); + + /* Insert all nodes in the priority queues */ + nbnd = graph->gnvtxs; + for (i=0; i<nvtxs; i++) { + cand[i].key = id[i]-ed[i]; + cand[i].val = i; + } + ikeysort(nvtxs, cand); + + for (ii=0; ii<nvtxs; ii++) { + i = cand[ii].val; + FPQueueInsert(&parts[qnum[i]][where[i]], i, (float)(ed[i]-id[i])); + } + + for (nswaps=0; nswaps<nvtxs; nswaps++) { + if (minbal < lbfactor) + break; + + Serial_SelectQueue(ncon, npwgts, tpwgts, &from, &cnum, parts); + to = (from+1)%2; + + if (from == -1 || (higain = FPQueueGetMax(&parts[cnum][from])) == -1) + break; + + saxpy2(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy2(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + newcut -= (ed[higain]-id[higain]); + newbal = Serial_Compute2WayHLoadImbalance(ncon, npwgts, tpwgts); + + if (newbal < minbal || (newbal == minbal && + (newcut < mincut || (newcut == mincut && + Serial_BetterBalance(ncon, npwgts, tpwgts, mindiff))))) { + mincut = newcut; + minbal = newbal; + mincutorder = nswaps; + for (i=0; i<ncon; i++) + mindiff[i] = fabs(tpwgts[i]-npwgts[i]); + } + else if (nswaps-mincutorder > limit) { /* We hit the limit, undo last move */ + newcut += (ed[higain]-id[higain]); + saxpy2(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + saxpy2(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + break; + } + + where[higain] = to; + moved[higain] = nswaps; + swaps[nswaps] = higain; + + /************************************************************** + * Update the id[i]/ed[i] values of the affected nodes + ***************************************************************/ + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + if (ed[higain] > 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + oldgain = ed[k]-id[k]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + /* Update the queue position */ + if (moved[k] == -1) + FPQueueUpdate(&parts[qnum[k]][where[k]], k, (float)(oldgain), (float)(ed[k]-id[k])); + + /* Update its boundary information */ + if (ed[k] == 0 && bndptr[k] != -1) + BNDDelete(nbnd, bndind, bndptr, k); + else if (ed[k] > 0 && bndptr[k] == -1) + BNDInsert(nbnd, bndind, bndptr, k); + } + } + + + /**************************************************************** + * Roll back computations + *****************************************************************/ + for (nswaps--; nswaps>mincutorder; nswaps--) { + higain = swaps[nswaps]; + + to = where[higain] = (where[higain]+1)%2; + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + else if (ed[higain] > 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + saxpy2(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy2(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+((to+1)%2)*ncon, 1); + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + if (bndptr[k] != -1 && ed[k] == 0) + BNDDelete(nbnd, bndind, bndptr, k); + if (bndptr[k] == -1 && ed[k] > 0) + BNDInsert(nbnd, bndind, bndptr, k); + } + } + + graph->mincut = mincut; + graph->gnvtxs = nbnd; + + + for (i=0; i<ncon; i++) { + FPQueueFree(&parts[i][0]); + FPQueueFree(&parts[i][1]); + } + + GKfree((void **)&cand, (void **)&qnum, (void **)&moved, (void **)&swaps, LTERM); + return; +} + +/************************************************************************* +* This function balances two partitions by moving the highest gain +* (including negative gain) vertices to the other domain. +* It is used only when tha unbalance is due to non contigous +* subdomains. That is, the are no boundary vertices. +* It moves vertices from the domain that is overweight to the one that +* is underweight. +**************************************************************************/ +void Moc_Serial_Init2WayBalance(GraphType *graph, float *tpwgts) +{ + int i, ii, j, k; + int kwgt, nvtxs, nbnd, ncon, nswaps, from, to, cnum, tmp; + idxtype *xadj, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind; + idxtype *qnum; + float *nvwgt, *npwgts; + FPQueueType parts[MAXNCON][2]; + int higain, oldgain, mincut; + KeyValueType *cand; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + adjncy = graph->adjncy; + nvwgt = graph->nvwgt; + adjwgt = graph->adjwgt; + where = graph->where; + id = graph->sendind; + ed = graph->recvind; + npwgts = graph->gnpwgts; + bndptr = graph->sendptr; + bndind = graph->recvptr; + + qnum = idxmalloc(nvtxs, "qnum"); + cand = (KeyValueType *)GKmalloc(nvtxs*sizeof(KeyValueType), "cand"); + + /* This is called for initial partitioning so we know from where to pick nodes */ + from = 1; + to = (from+1)%2; + + for (i=0; i<ncon; i++) { + FPQueueInit(&parts[i][0], nvtxs); + FPQueueInit(&parts[i][1], nvtxs); + } + + /* Compute the queues in which each vertex will be assigned to */ + for (i=0; i<nvtxs; i++) + qnum[i] = samax(ncon, nvwgt+i*ncon); + + for (i=0; i<nvtxs; i++) { + cand[i].key = id[i]-ed[i]; + cand[i].val = i; + } + ikeysort(nvtxs, cand); + + /* Insert the nodes of the proper partition in the appropriate priority queue */ + for (ii=0; ii<nvtxs; ii++) { + i = cand[ii].val; + if (where[i] == from) { + if (ed[i] > 0) + FPQueueInsert(&parts[qnum[i]][0], i, (float)(ed[i]-id[i])); + else + FPQueueInsert(&parts[qnum[i]][1], i, (float)(ed[i]-id[i])); + } + } + + mincut = graph->mincut; + nbnd = graph->gnvtxs; + for (nswaps=0; nswaps<nvtxs; nswaps++) { + if (Serial_AreAnyVwgtsBelow(ncon, 1.0, npwgts+from*ncon, 0.0, nvwgt, tpwgts+from*ncon)) + break; + + if ((cnum = Serial_SelectQueueOneWay(ncon, npwgts, tpwgts, from, parts)) == -1) + break; + + + if ((higain = FPQueueGetMax(&parts[cnum][0])) == -1) + higain = FPQueueGetMax(&parts[cnum][1]); + + mincut -= (ed[higain]-id[higain]); + saxpy2(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy2(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + + where[higain] = to; + + /************************************************************** + * Update the id[i]/ed[i] values of the affected nodes + ***************************************************************/ + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + if (ed[higain] > 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + for (j=xadj[higain]; j<xadj[higain+1]; j++) { + k = adjncy[j]; + oldgain = ed[k]-id[k]; + + kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]); + INC_DEC(id[k], ed[k], kwgt); + + /* Update the queue position */ + if (where[k] == from) { + if (ed[k] > 0 && bndptr[k] == -1) { /* It moves in boundary */ + FPQueueDelete(&parts[qnum[k]][1], k); + FPQueueInsert(&parts[qnum[k]][0], k, (float)(ed[k]-id[k])); + } + else { /* It must be in the boundary already */ + FPQueueUpdate(&parts[qnum[k]][0], k, (float)(oldgain), (float)(ed[k]-id[k])); + } + } + + /* Update its boundary information */ + if (ed[k] == 0 && bndptr[k] != -1) + BNDDelete(nbnd, bndind, bndptr, k); + else if (ed[k] > 0 && bndptr[k] == -1) + BNDInsert(nbnd, bndind, bndptr, k); + } + } + + graph->mincut = mincut; + graph->gnvtxs = nbnd; + + for (i=0; i<ncon; i++) { + FPQueueFree(&parts[i][0]); + FPQueueFree(&parts[i][1]); + } + + GKfree((void **)&cand, (void **)&qnum, LTERM); +} + + +/************************************************************************* +* This function selects the partition number and the queue from which +* we will move vertices out +**************************************************************************/ +int Serial_SelectQueueOneWay(int ncon, float *npwgts, float *tpwgts, int from, + FPQueueType queues[MAXNCON][2]) +{ + int i, cnum=-1; + float max=0.0; + + for (i=0; i<ncon; i++) { + if (npwgts[from*ncon+i]-tpwgts[from*ncon+i] >= max && + FPQueueGetQSize(&queues[i][0]) + FPQueueGetQSize(&queues[i][1]) > 0) { + max = npwgts[from*ncon+i]-tpwgts[i]; + cnum = i; + } + } + + return cnum; +} + + +/************************************************************************* +* This function computes the initial id/ed +**************************************************************************/ +void Moc_Serial_Compute2WayPartitionParams(GraphType *graph) +{ + int i, j, me, nvtxs, ncon, nbnd, mincut; + idxtype *xadj, *adjncy, *adjwgt; + float *nvwgt, *npwgts; + idxtype *id, *ed, *where; + idxtype *bndptr, *bndind; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + + npwgts = sset(2*ncon, 0.0, graph->gnpwgts); + id = idxset(nvtxs, 0, graph->sendind); + ed = idxset(nvtxs, 0, graph->recvind); + bndptr = idxset(nvtxs, -1, graph->sendptr); + bndind = graph->recvptr; + + /*------------------------------------------------------------ + / Compute now the id/ed degrees + /------------------------------------------------------------*/ + nbnd = mincut = 0; + for (i=0; i<nvtxs; i++) { + me = where[i]; + saxpy2(ncon, 1.0, nvwgt+i*ncon, 1, npwgts+me*ncon, 1); + + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (me == where[adjncy[j]]) + id[i] += adjwgt[j]; + else + ed[i] += adjwgt[j]; + } + + if (ed[i] > 0 || xadj[i] == xadj[i+1]) { + mincut += ed[i]; + bndptr[i] = nbnd; + bndind[nbnd++] = i; + } + } + + graph->mincut = mincut/2; + graph->gnvtxs = nbnd; + +} + +/************************************************************************* +* This function checks if the vertex weights of two vertices are below +* a given set of values +**************************************************************************/ +int Serial_AreAnyVwgtsBelow(int ncon, float alpha, float *vwgt1, float beta, float *vwgt2, float *limit) +{ + int i; + + for (i=0; i<ncon; i++) + if (alpha*vwgt1[i] + beta*vwgt2[i] < limit[i]) + return 1; + + return 0; +} + + +/************************************************************************* +* This function computes the edge-cut of a serial graph. +**************************************************************************/ +int ComputeSerialEdgeCut(GraphType *graph) +{ + int i, j; + int cut = 0; + + for (i=0; i<graph->nvtxs; i++) { + for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++) + if (graph->where[i] != graph->where[graph->adjncy[j]]) + cut += graph->adjwgt[j]; + } + graph->mincut = cut/2; + + return graph->mincut; +} + +/************************************************************************* +* This function computes the TotalV of a serial graph. +**************************************************************************/ +int ComputeSerialTotalV(GraphType *graph, idxtype *home) +{ + int i; + int totalv = 0; + + for (i=0; i<graph->nvtxs; i++) + if (graph->where[i] != home[i]) + totalv += (graph->vsize == NULL) ? graph->vwgt[i] : graph->vsize[i]; + + return totalv; +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/setup.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/setup.c new file mode 100644 index 0000000..682a31d --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/setup.c @@ -0,0 +1,219 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * setup.c + * + * This file contains functions that setup the various communication + * data structures for parallel KWAY + * + * Started 2/21/96 + * George + * + * $Id: setup.c,v 1.3 2003/07/31 16:23:30 karypis Exp $ + * + */ + + +#include <parmetislib.h> + +#define DEBUG_SETUPINFO_ + + +/************************************************************************* +* This function tests the repeated shmem_put +**************************************************************************/ +void SetUp(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int i, j, k, islocal, penum, gnvtxs, nvtxs, nlocal, firstvtx, lastvtx, nsend, nrecv, nnbrs, nadj; + int npes=ctrl->npes, mype=ctrl->mype; + idxtype *vtxdist, *xadj, *adjncy; + idxtype *peind, *recvptr, *recvind, *sendptr, *sendind; + idxtype *receive, *pemap, *imap, *lperm; + idxtype *pexadj, *peadjncy, *peadjloc, *startsind; + KeyValueType *recvrequests, *sendrequests, *adjpairs; + + IFSET(ctrl->dbglvl, DBG_TIME, MPI_Barrier(ctrl->comm)); + IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->SetupTmr)); + + gnvtxs = graph->gnvtxs; + nvtxs = graph->nvtxs; + vtxdist = graph->vtxdist; + xadj = graph->xadj; + adjncy = graph->adjncy; + + firstvtx = vtxdist[mype]; + lastvtx = vtxdist[mype+1]; + + pemap = wspace->pv1; + idxset(npes, -1, pemap); + + lperm = graph->lperm = idxmalloc(nvtxs, "SetUp: graph->lperm"); + for (i=0; i<nvtxs; i++) + lperm[i] = i; + + /************************************************************* + * Determine what you need to receive + *************************************************************/ + receive = wspace->indices; /* Use the large global received array for now */ + adjpairs = wspace->pairs; + + for (nlocal = nadj = i = 0; i<nvtxs; i++) { + islocal = 1; + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (k >= firstvtx && k < lastvtx) { + adjncy[j] = k-firstvtx; + continue; /* local vertex */ + } + adjpairs[nadj].key = k; + adjpairs[nadj++].val = j; + islocal = 0; + } + if (islocal) { + lperm[i] = lperm[nlocal]; + lperm[nlocal++] = i; + } + } + + /* Take care the received part now */ + ikeysort(nadj, adjpairs); + adjpairs[nadj].key = gnvtxs+1; /* Boundary condition */ + for (nrecv=i=0; i<nadj; i++) { + adjncy[adjpairs[i].val] = nvtxs+nrecv; + if (adjpairs[i].key != adjpairs[i+1].key) + receive[nrecv++] = adjpairs[i].key; + } + + + /* Allocate space for the setup info attached to this level of the graph */ + peind = graph->peind = idxmalloc(npes, "SetUp: peind"); + recvptr = graph->recvptr = idxmalloc(npes+1, "SetUp: recvptr"); + recvind = graph->recvind = idxmalloc(nrecv, "SetUp: recvind"); + + /* Take care of the received portion */ + idxcopy(nrecv, receive, recvind); /* Copy the vertices to be received into recvind */ + + i = nnbrs = recvptr[0] = 0; + for (penum=0; penum<npes; penum++) { + for (j=i; j<nrecv; j++) { + if (recvind[j] >= vtxdist[penum+1]) + break; + } + if (j > i) { + peind[nnbrs] = penum; + recvptr[++nnbrs] = j; + i = j; + } + } + + + /************************************************************* + * Determine what you need to send + *************************************************************/ + /* Tell the other processors what they need to send you */ + recvrequests = wspace->pepairs1; + sendrequests = wspace->pepairs2; + for (i=0; i<npes; i++) + recvrequests[i].key = 0; + for (i=0; i<nnbrs; i++) { + recvrequests[peind[i]].key = recvptr[i+1]-recvptr[i]; + recvrequests[peind[i]].val = nvtxs+recvptr[i]; + } + MPI_Alltoall((void *)recvrequests, 2, IDX_DATATYPE, (void *)sendrequests, 2, IDX_DATATYPE, ctrl->comm); + + + sendptr = graph->sendptr = idxmalloc(npes+1, "SetUp: sendptr"); + startsind = wspace->pv2; + for (j=i=0; i<npes; i++) { + if (sendrequests[i].key > 0) { + sendptr[j] = sendrequests[i].key; + startsind[j] = sendrequests[i].val; + j++; + } + } + ASSERT(ctrl, nnbrs == j); + MAKECSR(i, j, sendptr); + + nsend = sendptr[nnbrs]; + sendind = graph->sendind = idxmalloc(nsend, "SetUp: sendind"); + + + /* Issue the receives for sendind */ + for (i=0; i<nnbrs; i++) { + MPI_Irecv((void *)(sendind+sendptr[i]), sendptr[i+1]-sendptr[i], IDX_DATATYPE, + peind[i], 1, ctrl->comm, ctrl->rreq+i); + } + + /* Issue the sends. My recvind[penum] becomes penum's sendind[mype] */ + for (i=0; i<nnbrs; i++) { + MPI_Isend((void *)(recvind+recvptr[i]), recvptr[i+1]-recvptr[i], IDX_DATATYPE, + peind[i], 1, ctrl->comm, ctrl->sreq+i); + } + + MPI_Waitall(nnbrs, ctrl->rreq, ctrl->statuses); + MPI_Waitall(nnbrs, ctrl->sreq, ctrl->statuses); + + + + /* Create the peadjncy data structure for sparse boundary exchanges */ + pexadj = graph->pexadj = idxsmalloc(nvtxs+1, 0, "SetUp: pexadj"); + peadjncy = graph->peadjncy = idxmalloc(nsend, "SetUp: peadjncy"); + peadjloc = graph->peadjloc = idxmalloc(nsend, "SetUp: peadjloc"); + + for (i=0; i<nsend; i++) { + ASSERTP(ctrl, sendind[i] >= firstvtx && sendind[i] < lastvtx, (ctrl, "%d %d %d\n", sendind[i], firstvtx, lastvtx)); + pexadj[sendind[i]-firstvtx]++; + } + MAKECSR(i, nvtxs, pexadj); + + for (i=0; i<nnbrs; i++) { + for (j=sendptr[i]; j<sendptr[i+1]; j++) { + k = pexadj[sendind[j]-firstvtx]++; + peadjncy[k] = i; /* peind[i] is the actual PE number */ + peadjloc[k] = startsind[i]++; + } + } + ASSERT(ctrl, pexadj[nvtxs] == nsend); + + for (i=nvtxs; i>0; i--) + pexadj[i] = pexadj[i-1]; + pexadj[0] = 0; + + + graph->nnbrs = nnbrs; + graph->nrecv = nrecv; + graph->nsend = nsend; + graph->nlocal = nlocal; + + + /* Create the inverse map from ladjncy to adjncy */ + imap = graph->imap = idxmalloc(nvtxs+nrecv, "SetUp: imap"); + for (i=0; i<nvtxs; i++) + imap[i] = firstvtx+i; + for (i=0; i<nrecv; i++) + imap[nvtxs+i] = recvind[i]; + + + /* Check if wspace->nlarge is large enough for nrecv and nsend */ + if (wspace->nlarge < nrecv+nsend) { + free(wspace->indices); + free(wspace->pairs); + wspace->nlarge = nrecv+nsend; + wspace->indices = idxmalloc(wspace->nlarge, "SetUp: wspace->indices"); + wspace->pairs = (KeyValueType *)GKmalloc(sizeof(KeyValueType)*wspace->nlarge, "SetUp: wspace->pairs"); + } + + IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->SetupTmr)); + +#ifdef DEBUG_SETUPINFO + rprintf(ctrl, "[%5d %5d] \tl:[%5d %5d] \ts:[%5d, %5d] \tr:[%5d, %5d]\n", + GlobalSEMin(ctrl, nvtxs), GlobalSEMax(ctrl, nvtxs), + GlobalSEMin(ctrl, nlocal), GlobalSEMax(ctrl, nlocal), + GlobalSEMin(ctrl, nsend), GlobalSEMax(ctrl, nsend), + GlobalSEMin(ctrl, nrecv), GlobalSEMax(ctrl, nrecv)); + + PrintSetUpInfo(ctrl, graph); +#endif +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/stat.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/stat.c new file mode 100644 index 0000000..4a32bc8 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/stat.c @@ -0,0 +1,332 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * stat.c + * + * This file computes various statistics + * + * Started 7/25/97 + * George + * + * $Id: stat.c,v 1.3 2003/07/23 00:54:56 karypis Exp $ + * + */ + +#include <parmetislib.h> + + + +/************************************************************************* +* This function computes the balance of the partitioning +**************************************************************************/ +void Moc_ComputeSerialBalance(CtrlType *ctrl, GraphType *graph, idxtype *where, float *ubvec) +{ + int i, j, nvtxs, ncon, nparts; + idxtype *pwgts, *tvwgts, *vwgt; + float *tpwgts, maximb; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + vwgt = graph->vwgt; + nparts = ctrl->nparts; + tpwgts = ctrl->tpwgts; + + pwgts = idxsmalloc(nparts*ncon, 0, "pwgts"); + tvwgts = idxsmalloc(ncon, 0, "tvwgts"); + + for (i=0; i<graph->nvtxs; i++) { + for (j=0; j<ncon; j++) { + pwgts[where[i]*ncon+j] += vwgt[i*ncon+j]; + tvwgts[j] += vwgt[i*ncon+j]; + } + } + + /* The +1 in the following code is to deal with bad cases of tpwgts[i*ncon+j] == 0 */ + for (j=0; j<ncon; j++) { + maximb = 0.0; + for (i=0; i<nparts; i++) + maximb = amax(maximb, (1.0+(float)pwgts[i*ncon+j])/(1.0+(tpwgts[i*ncon+j]*(float)tvwgts[j]))); + ubvec[j] = maximb; + } + + GKfree((void **)&pwgts, (void **)&tvwgts, LTERM); +} + + +/************************************************************************* +* This function computes the balance of the partitioning +**************************************************************************/ +void Moc_ComputeParallelBalance(CtrlType *ctrl, GraphType *graph, idxtype *where, float *ubvec) +{ + int i, j, nvtxs, ncon, nparts; + float *nvwgt, *lnpwgts, *gnpwgts; + float *tpwgts, maximb; + float lminvwgts[MAXNCON], gminvwgts[MAXNCON]; + + ncon = graph->ncon; + nvtxs = graph->nvtxs; + nvwgt = graph->nvwgt; + nparts = ctrl->nparts; + tpwgts = ctrl->tpwgts; + + lnpwgts = fmalloc(nparts*ncon, "CPB: lnpwgts"); + gnpwgts = fmalloc(nparts*ncon, "CPB: gnpwgts"); + sset(nparts*ncon, 0.0, lnpwgts); + sset(ncon, 1.0, lminvwgts); + + for (i=0; i<nvtxs; i++) { + for (j=0; j<ncon; j++) { + lnpwgts[where[i]*ncon+j] += nvwgt[i*ncon+j]; + + /* The following is to deal with tpwgts[] that are 0.0 for certain partitions/constraints */ + lminvwgts[j] = (nvwgt[i*ncon+j] > 0.0 && lminvwgts[j] > nvwgt[i*ncon+j] ? nvwgt[i*ncon+j] : lminvwgts[j]); + } + } + + MPI_Allreduce((void *)(lnpwgts), (void *)(gnpwgts), nparts*ncon, MPI_FLOAT, MPI_SUM, ctrl->comm); + MPI_Allreduce((void *)(lminvwgts), (void *)(gminvwgts), ncon, MPI_FLOAT, MPI_MIN, ctrl->comm); + + /* The +gminvwgts[j] in the following code is to deal with bad cases of tpwgts[i*ncon+j] == 0 */ + for (j=0; j<ncon; j++) { + maximb = 0.0; + for (i=0; i<nparts; i++) + maximb = amax(maximb, (gminvwgts[j]+gnpwgts[i*ncon+j])/(gminvwgts[j]+tpwgts[i*ncon+j])); + ubvec[j] = maximb; + } + + GKfree((void **)&lnpwgts, (void **)&gnpwgts, LTERM); + + return; +} + + +/************************************************************************* +* This function prints a matrix +**************************************************************************/ +void Moc_PrintThrottleMatrix(CtrlType *ctrl, GraphType *graph, float *matrix) +{ + int i, j; + + for (i=0; i<ctrl->npes; i++) { + if (i == ctrl->mype) { + for (j=0; j<ctrl->npes; j++) + printf("%.3f ", matrix[j]); + printf("\n"); + fflush(stdout); + } + MPI_Barrier(ctrl->comm); + } + + if (ctrl->mype == 0) { + printf("****************************\n"); + fflush(stdout); + } + MPI_Barrier(ctrl->comm); + + return; +} + + +/************************************************************************* +* This function computes stats for refinement +**************************************************************************/ +void Moc_ComputeRefineStats(CtrlType *ctrl, GraphType *graph, float *ubvec) +{ + int h, i, j, k; + int nvtxs, ncon; + idxtype *xadj, *adjncy, *adjwgt, *where; + float *nvwgt, *lnpwgts, *gnpwgts; + RInfoType *rinfo; + int mype = ctrl->mype, nparts = ctrl->nparts; + idxtype *gborder, *border, *gfrom, *from, *gto, *to, *connect, *gconnect; + idxtype gain[20] = {0}, ggain[20]; + int lnborders, gnborders; + int bestgain, pmoves, gpmoves, other; + float tpwgts[MAXNCON], badmaxpwgt[MAXNCON]; + int HIST_FACTOR = graph->level + 1; + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + lnpwgts = graph->lnpwgts; + gnpwgts = graph->gnpwgts; + rinfo = graph->rinfo; + + connect = idxsmalloc(nparts*nparts, 0, "CRS: connect"); + gconnect = idxmalloc(nparts*nparts, "CRS: gconnect"); + border = idxsmalloc(nparts, 0, "CRS: border"); + gborder = idxmalloc(nparts, "CRS: gborder"); + from = idxsmalloc(nparts, 0, "CRS: from"); + gfrom = idxmalloc(nparts, "CRS: gfrom"); + to = idxsmalloc(nparts, 0, "CRS: to"); + gto = idxmalloc(nparts, "CRS: gto"); + + for (h=0; h<ncon; h++) { + tpwgts[h] = ssum_strd(nparts, gnpwgts+h, ncon)/(float)(nparts); + badmaxpwgt[h] = ubvec[h]*tpwgts[h]; + } + + if (mype == 0) printf("******************************\n"); + if (mype == 0) printf("******************************\n"); + + /***************************************/ + if (mype == 0) { + printf("subdomain weights:\n"); + for (h=0; h<ncon; h++) { + for (i=0; i<nparts; i++) + printf("%9.3f ", gnpwgts[i*ncon+h]); + printf("\n"); + } + printf("\n"); + } + + /***************************************/ + if (mype == 0) { + printf("subdomain imbalance:\n"); + for (h=0; h<ncon; h++) { + for (i=0; i<nparts; i++) + printf("%9.3f ", gnpwgts[i*ncon+h] * (float)(nparts)); + printf("\n"); + } + printf("\n"); + } + + /***************************************/ + for (i=0; i<nparts; i++) + connect[i*nparts+i] = -1; + + for (i=0; i<nvtxs; i++) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (where[i] != where[adjncy[j]]) { + connect[where[i]*nparts+where[adjncy[j]]] = 1; + connect[where[adjncy[j]]*nparts+where[i]] = 1; + } + } + } + + MPI_Reduce((void *)connect, (void *)gconnect, nparts*nparts, IDX_DATATYPE, MPI_MAX, 0, ctrl->comm); + if (mype == 0) { + printf("connectivity\n"); + for (i=0; i<nparts; i++) { + printf("%d: ", i); + for (j=0; j<nparts; j++) + printf("%9d ", gconnect[i*nparts+j]); + printf("\n"); + } + printf("\n"); + } + + /***************************************/ + lnborders = 0; + for (i=0; i<nvtxs; i++) + if (rinfo[i].ndegrees > 0) { + lnborders++; + border[where[i]]++; + } + + MPI_Reduce((void *)border, (void *)gborder, nparts, IDX_DATATYPE, MPI_SUM, 0, ctrl->comm); + gnborders = GlobalSESum(ctrl, lnborders); + if (mype == 0) { + printf("number of borders: %d\n", gnborders); + for (i=0; i<nparts; i++) + printf("%9d ", gborder[i]); + printf("\n\n"); + } + + /***************************************/ + pmoves = 0; + for (i=0; i<nvtxs; i++) { + nvwgt = graph->nvwgt+i*ncon; + + for (j=0; j<rinfo[i].ndegrees; j++) { + other = rinfo[i].degrees[j].edge; + for (h=0; h<ncon; h++) + if (gnpwgts[other*ncon+h]+nvwgt[h] > badmaxpwgt[h]) + break; + + if (h == ncon) + break; + } + + if (j < rinfo[i].ndegrees) { + pmoves++; + from[where[i]]++; + to[other]++; + for (k=j+1; k<rinfo[i].ndegrees; k++) { + other = rinfo[i].degrees[k].edge; + for (h=0; h<ncon; h++) + if (gnpwgts[other*ncon+h]+nvwgt[h] > badmaxpwgt[h]) + break; + + if (h == ncon) { + pmoves++; + from[where[i]]++; + to[other]++; + } + } + } + } + + gpmoves = GlobalSESum(ctrl, pmoves); + MPI_Reduce((void *)from, (void *)gfrom, nparts, IDX_DATATYPE, MPI_SUM, 0, ctrl->comm); + MPI_Reduce((void *)to, (void *)gto, nparts, IDX_DATATYPE, MPI_SUM, 0, ctrl->comm); + + if (mype == 0) { + printf("possible moves: %d\n", gpmoves); + printf("from "); + for (i=0; i<nparts; i++) { + printf("%9d ", gfrom[i]); + } + printf("\n"); + printf("to "); + for (i=0; i<nparts; i++) { + printf("%9d ", gto[i]); + } + printf("\n\n"); + } + + /***************************************/ + for (i=0; i<nvtxs; i++) { + if (rinfo[i].ndegrees > 0) { + bestgain = rinfo[i].degrees[0].ewgt-rinfo[i].id; + for (j=0; j<rinfo[i].ndegrees; j++) + bestgain = amax(bestgain, rinfo[i].degrees[j].ewgt-rinfo[i].id); + + if (bestgain / HIST_FACTOR >= 10) { + gain[19]++; + continue; + } + + if (bestgain / HIST_FACTOR < -10) { + gain[0]++; + continue; + } + + gain[(bestgain/HIST_FACTOR)+10]++; + } + } + + MPI_Reduce((void *)gain, (void *)ggain, 20, IDX_DATATYPE, MPI_SUM, 0, ctrl->comm); + if (mype == 0) { + printf("gain histogram (buckets of %d)\n", HIST_FACTOR); + for (i=0; i<20; i++) { + if (i == 10 || i == 11) + printf(" "); + printf("%d ", ggain[i]); + } + printf("\n\n"); + } + + + + + /***************************************/ + if (mype == 0) printf("******************************\n"); + if (mype == 0) printf("******************************\n"); + + GKfree((void **)&gconnect, (void **)&connect, (void **)&gborder, (void **)&border, (void **)&gfrom, (void **)&from, (void **)>o, (void **)&to, LTERM); + return; +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/stdheaders.h b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/stdheaders.h new file mode 100644 index 0000000..e30f989 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/stdheaders.h @@ -0,0 +1,25 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * stdheaders.h + * + * This file includes all necessary header files + * + * Started 8/27/94 + * George + * + * $Id: stdheaders.h,v 1.4 2003/07/25 14:31:47 karypis Exp $ + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <malloc.h> +#include <string.h> +#include <ctype.h> +#include <math.h> +#include <stdarg.h> +#include <limits.h> +#include <time.h> +#include <mpi.h> + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/struct.h b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/struct.h new file mode 100644 index 0000000..3016c5e --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/struct.h @@ -0,0 +1,290 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * struct.h + * + * This file contains data structures for ILU routines. + * + * Started 9/26/95 + * George + * + * $Id: struct.h,v 1.2 2003/07/21 17:50:22 karypis Exp $ + */ + +/* Indexes are as long as integers for now */ +#ifdef IDXTYPE_INT +#define IDX_DATATYPE MPI_INT +#define MAX_INT INT_MAX +#define MIN_INT INT_MIN +#else +#define IDX_DATATYPE MPI_SHORT +#define MAX_INT SHRT_MAX +#define MIN_INT SHRT_MIN +#endif + + +/************************************************************************* +* The following data structure stores key-value pair +**************************************************************************/ +struct KeyValueType { + idxtype key; + idxtype val; +}; + +typedef struct KeyValueType KeyValueType; + +/************************************************************************* +* The following data structure stores key-value pair +**************************************************************************/ +struct KVType { + int key; + float val; +}; + +typedef struct KVType KVType; + + +/************************************************************************* +* The following data structure stores key-value pair +**************************************************************************/ +struct FKeyValueType { + float key; + idxtype val; +}; + +typedef struct FKeyValueType FKeyValueType; + +/************************************************************************* +* The following data structure stores key-key-value triplets +**************************************************************************/ +struct KeyKeyValueType { + idxtype key1, key2; + idxtype val; +}; + +typedef struct KeyKeyValueType KeyKeyValueType; + +/************************************************************************* +* The following data structure is used to store the buckets for the +* refinment algorithms +**************************************************************************/ +struct PQueueType { + int nnodes; + int maxnnodes; + idxtype *perm, *iperm, *values; + /* iperm[i] stores where the ith entry is located + perm[i] stores the entry that is located in the ith position */ +}; + +typedef struct PQueueType PQueueType; + + +/************************************************************************* +* The following data structure is used to store the buckets for the +* refinment algorithms +**************************************************************************/ +struct FPQueueType { + int type; /* The type of the representation used */ + int nnodes; + int maxnodes; + + /* Heap version of the data structure */ + FKeyValueType *heap; + idxtype *locator; +}; + +typedef struct FPQueueType FPQueueType; + +/************************************************************************* +* The following data structure stores an edge +**************************************************************************/ +struct edgedef { + idxtype edge; + idxtype ewgt; +}; +typedef struct edgedef EdgeType; + + +/************************************************************************* +* This data structure holds various working space data +**************************************************************************/ +struct workspacedef { + idxtype *core; /* Where pairs, indices, and degrees are coming from */ + int maxcore; + + int nlarge; /* The size of 'Large' */ + + KeyValueType *pairs; /* Large pair array used during setup */ + idxtype *indices; /* Large array of indxtype used for various purposes */ + + /* Auxiliary parameters */ + idxtype *pv1, *pv2, *pv3, *pv4; /* Vectors of npes+1 size used in various places */ + KeyValueType *pepairs1, *pepairs2; + + EdgeType *degrees; +}; + +typedef struct workspacedef WorkSpaceType; + + +/************************************************************************* +* The following data structure holds information on degrees for k-way +* partition +**************************************************************************/ +struct rinfodef { + int id, ed; /* ID/ED of edges */ + int ndegrees; /* The number of different ext-degrees */ + EdgeType *degrees; /* List of edges */ +}; + +typedef struct rinfodef RInfoType; + + +/************************************************************************* +* The following data structure holds information on degrees for k-way +* partition +**************************************************************************/ +struct nrinfodef { + int edegrees[2]; +}; + +typedef struct nrinfodef NRInfoType; + + +/************************************************************************* +* The following data structure stores a sparse matrix in CSR format +* The diagonal entry is in the first position of each row. +**************************************************************************/ +struct matrixdef { + int nrows, nnzs; /* Number of rows and nonzeros in the matrix */ + idxtype *rowptr; + idxtype *colind; + float *values; + float *transfer; +}; + +typedef struct matrixdef MatrixType; + + +/************************************************************************* +* This data structure holds the input graph +**************************************************************************/ +struct graphdef { + int gnvtxs, nvtxs, nedges, ncon, nobj; + idxtype *xadj; /* Pointers to the locally stored vertices */ + idxtype *vwgt; /* Vertex weights */ + float *nvwgt; /* Vertex weights */ + idxtype *vsize; /* Vertex size */ + idxtype *adjncy; /* Array that stores the adjacency lists of nvtxs */ + idxtype *adjwgt; /* Array that stores the weights of the adjacency lists */ + idxtype *vtxdist; /* Distribution of vertices */ + + idxtype *match; + idxtype *cmap; + + idxtype *label; + + /* Communication/Setup parameters */ + int nnbrs, nrecv, nsend; /* The number of neighboring processors */ + idxtype *peind; /* Array of size nnbrs storing the neighboring PEs */ + idxtype *sendptr, *sendind; /* CSR format of the vertices that are sent */ + idxtype *recvptr, *recvind; /* CSR format of the vertices that are received */ + idxtype *imap; /* The inverse map of local to global indices */ + idxtype *pexadj, *peadjncy, + *peadjloc; /* CSR format of the PEs each vertex is adjancent to */ + + int nlocal; /* Number of interior vertices */ + idxtype *lperm; /* lperm[0:nlocal] points to interior vertices, the rest are interface */ + + /* Communication parameters for projecting the partition. + * These are computed during CreateCoarseGraph and used during projection + * Note that during projection, the meaning of received and sent is reversed! */ + idxtype *rlens, *slens; /* Arrays of size nnbrs of how many vertices you are sending and receiving */ + KeyValueType *rcand; + + + /* Partition parameters */ + idxtype *where, *home; + idxtype *lpwgts, *gpwgts; + float *lnpwgts, *gnpwgts; + RInfoType *rinfo; + + /* Node refinement information */ + NRInfoType *nrinfo; + int nsep; /* The number of vertices in the separator */ + idxtype *sepind; /* The indices of the vertices in the separator */ + + int lmincut, mincut; + + int level; + int match_type; + int edgewgt_type; + + struct graphdef *coarser, *finer; +}; + +typedef struct graphdef GraphType; + + +/************************************************************************* +* The following data type implements a timer +**************************************************************************/ +typedef double timer; + + +/************************************************************************* +* The following structure stores information used by parallel kmetis +**************************************************************************/ +struct controldef { + int mype, npes; /* Info about the parallel system */ + int CoarsenTo; /* The # of vertices in the coarsest graph */ + int dbglvl; /* Controls the debuging output of the program */ + int nparts; /* The number of partitions */ + int foldf; /* What is the folding factor */ + int ipart; /* The type of initial partitioning */ + int xyztype; /* The type of coordinate indexing */ + int seed; /* Random number seed */ + int sync; /* Random number seed */ + float *tpwgts; /* Target subdomain weights */ + int tvwgts[MAXNCON]; + float ubvec[MAXNCON]; + int partType; + int ps_relation; + + float redist_factor, redist_base, ipc_factor; + float edge_size_ratio; + MatrixType *matrix; + + MPI_Comm gcomm; + MPI_Comm comm; /* MPI Communicator */ + MPI_Request sreq[MAX_PES], + rreq[MAX_PES]; /* MPI send and receive requests */ + MPI_Status statuses[MAX_PES]; + MPI_Status status; + + /* Various Timers */ + timer TotalTmr, InitPartTmr, MatchTmr, ContractTmr, CoarsenTmr, RefTmr, + SetupTmr, ColorTmr, ProjectTmr, KWayInitTmr, KWayTmr, MoveTmr, + RemapTmr, AuxTmr1, AuxTmr2, AuxTmr3, AuxTmr4, AuxTmr5, AuxTmr6; +}; + +typedef struct controldef CtrlType; + + + +/************************************************************************* +* The following data structure stores a mesh. +**************************************************************************/ +struct meshdef { + int etype; + int gnelms, gnns; + int nelms, nns; + int ncon; + int esize, gminnode; + idxtype *elmdist; + idxtype *elements; + idxtype *elmwgt; +}; + +typedef struct meshdef MeshType; + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/sync b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/sync new file mode 100644 index 0000000..11a0cfb --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/sync @@ -0,0 +1,186 @@ +adrivers.c: ubavg = savg(graph->ncon, ctrl->ubvec); +adrivers.c: ctrl->redist_factor = ctrl->redist_base * ((gtewgt/gtvsize)/ ctrl->edge_size_ratio); +adrivers.c: IFSET(ctrl->dbglvl, DBG_PROGRESS, rprintf(ctrl, "[%6d %8d %5d %5d][%d]\n", +adrivers.c: graph->gnvtxs, GlobalSESum(ctrl, graph->nedges), GlobalSEMin(ctrl, graph->nvtxs), GlobalSEMax(ctrl, graph->nvtxs), ctrl->CoarsenTo)); +adrivers.c: if (graph->gnvtxs < 1.3*ctrl->CoarsenTo || +adrivers.c: if (lbavg > ubavg + 0.035 && ctrl->partType != REFINE_PARTITION) +adrivers.c: if (ctrl->dbglvl&DBG_PROGRESS) { +adrivers.c: switch (ctrl->ps_relation) { +adrivers.c: if (ctrl->dbglvl&DBG_PROGRESS) { +akwayfm.c: int npes = ctrl->npes, mype = ctrl->mype, nparts = ctrl->nparts; +akwayfm.c: IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->KWayTmr)); +akwayfm.c: ubvec = ctrl->ubvec; +akwayfm.c: tpwgts = ctrl->tpwgts; +akwayfm.c: ipc_factor = ctrl->ipc_factor; +akwayfm.c: redist_factor = ctrl->redist_factor; +akwayfm.c: MPI_Bcast((void *)pperm, nparts, IDX_DATATYPE, 0, ctrl->comm); +akwayfm.c: switch (ctrl->ps_relation) { +akwayfm.c: switch (ctrl->ps_relation) { +akwayfm.c: MPI_Allreduce((void *)lnpwgts, (void *)pgnpwgts, nparts*ncon, MPI_FLOAT, MPI_SUM, ctrl->comm); +akwayfm.c: IFSET(ctrl->dbglvl, DBG_RMOVEINFO, rprintf(ctrl, "\t[%d %d], [%.4f], [%d %d %d]\n", +akwayfm.c: MPI_Irecv((void *)(rupdate+sendptr[i]), sendptr[i+1]-sendptr[i], IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->rreq+i); +akwayfm.c: MPI_Isend((void *)(supdate+j), k-j, IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->sreq+i); +akwayfm.c: MPI_Waitall(nnbrs, ctrl->rreq, ctrl->statuses); +akwayfm.c: MPI_Get_count(ctrl->statuses+i, IDX_DATATYPE, nupds_pe+i); +akwayfm.c: MPI_Waitall(nnbrs, ctrl->sreq, ctrl->statuses); +akwayfm.c: MPI_Allreduce((void *)lnpwgts, (void *)gnpwgts, nparts*ncon, MPI_FLOAT, MPI_SUM, ctrl->comm); +akwayfm.c: IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->KWayTmr)); +balancemylink.c: ipc_factor = ctrl->ipc_factor; +balancemylink.c: redist_factor = ctrl->redist_factor; +coarsen.c: int npes=ctrl->npes, mype=ctrl->mype; +coarsen.c: MPI_Allgather((void *)(cvtxdist+npes), 1, IDX_DATATYPE, (void *)cvtxdist, 1, IDX_DATATYPE, ctrl->comm); +coarsen.c: MPI_Irecv((void *)(rsizes+i), 1, IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->rreq+i); +coarsen.c: MPI_Isend((void *)(ssizes+i), 1, IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->sreq+i); +coarsen.c: MPI_Wait(ctrl->rreq+i, &ctrl->status); +coarsen.c: MPI_Wait(ctrl->sreq+i, &ctrl->status); +coarsen.c: MPI_Irecv((void *)(rgraph+l), (4+ncon)*(rlens[i+1]-rlens[i])+2*rsizes[i], IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->rreq+i); +coarsen.c: sgraph[ll++] = (ctrl->partType == STATIC_PARTITION) ? -1 : vsize[ii]; +coarsen.c: sgraph[ll++] = (ctrl->partType == STATIC_PARTITION) ? -1 : home[ii]; +coarsen.c: MPI_Isend((void *)(sgraph+l), ll-l, IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->sreq+i); +coarsen.c: MPI_Wait(ctrl->rreq+i, &ctrl->status); +coarsen.c: MPI_Wait(ctrl->sreq+i, &ctrl->status); +coarsen.c: if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) { +coarsen.c: if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) { +coarsen.c: if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) { +coarsen.c: if (ctrl->partType == ADAPTIVE_PARTITION || ctrl->partType == REFINE_PARTITION) { +coarsen.c: cgraph->nvwgt[j*ncon+h] = (float)(cvwgt[j*ncon+h])/(float)(ctrl->tvwgts[h]); +comm.c: firstvtx = graph->vtxdist[ctrl->mype]; +comm.c: peind[i], 1, ctrl->comm, ctrl->rreq+i); +comm.c: peind[i], 1, ctrl->comm, ctrl->sreq+i); +comm.c: MPI_Waitall(nnbrs, ctrl->rreq, ctrl->statuses); +comm.c: MPI_Waitall(nnbrs, ctrl->sreq, ctrl->statuses); +comm.c: firstvtx = graph->vtxdist[ctrl->mype]; +comm.c: peind[i], 1, ctrl->comm, ctrl->rreq+i); +comm.c: idxcopy(ctrl->npes, sendptr, psendptr); +comm.c: peind[i], 1, ctrl->comm, ctrl->sreq+i); +comm.c: MPI_Isend((void *)(sendpairs), 0, IDX_DATATYPE, peind[i], 1, ctrl->comm, ctrl->sreq+i); +comm.c: MPI_Wait(ctrl->rreq+i, &(ctrl->status)); +comm.c: MPI_Get_count(&ctrl->status, IDX_DATATYPE, &n); +comm.c: MPI_Waitall(nnbrs, ctrl->sreq, ctrl->statuses); +comm.c: MPI_Allreduce((void *)&value, (void *)&max, 1, MPI_INT, MPI_MAX, ctrl->comm); +comm.c: MPI_Allreduce((void *)&value, (void *)&max, 1, MPI_DOUBLE, MPI_MAX, ctrl->comm); +comm.c: MPI_Allreduce((void *)&value, (void *)&min, 1, MPI_INT, MPI_MIN, ctrl->comm); +comm.c: MPI_Allreduce((void *)&value, (void *)&sum, 1, MPI_INT, MPI_SUM, ctrl->comm); +comm.c: MPI_Allreduce((void *)&value, (void *)&max, 1, MPI_FLOAT, MPI_MAX, ctrl->comm); +comm.c: MPI_Allreduce((void *)&value, (void *)&min, 1, MPI_FLOAT, MPI_MIN, ctrl->comm); +comm.c: MPI_Allreduce((void *)&value, (void *)&sum, 1, MPI_FLOAT, MPI_SUM, ctrl->comm); +debug.c: for (penum=0; penum<ctrl->npes; penum++) { +debug.c: if (ctrl->mype == penum) { +debug.c: if (ctrl->mype == 0) +debug.c: printf("\t%3d. ", ctrl->mype); +debug.c: MPI_Barrier(ctrl->comm); +debug.c: for (penum=0; penum<ctrl->npes; penum++) { +debug.c: if (ctrl->mype == penum) { +debug.c: if (ctrl->mype == 0) +debug.c: printf("\t%3d. ", ctrl->mype); +debug.c: MPI_Barrier(ctrl->comm); +debug.c: for (penum=0; penum<ctrl->npes; penum++) { +debug.c: if (ctrl->mype == penum) { +debug.c: if (ctrl->mype == 0) +debug.c: printf("\t%3d. ", ctrl->mype); +debug.c: MPI_Barrier(ctrl->comm); +debug.c: MPI_Barrier(ctrl->comm); +debug.c: firstvtx = graph->vtxdist[ctrl->mype]; +debug.c: for (penum=0; penum<ctrl->npes; penum++) { +debug.c: if (ctrl->mype == penum) { +debug.c: MPI_Barrier(ctrl->comm); +debug.c: MPI_Barrier(ctrl->comm); +debug.c: firstvtx = graph->vtxdist[ctrl->mype]; +debug.c: for (penum=0; penum<ctrl->npes; penum++) { +debug.c: if (ctrl->mype == penum) { +debug.c: MPI_Barrier(ctrl->comm); +debug.c: MPI_Barrier(ctrl->comm); +debug.c: for (penum=0; penum<ctrl->npes; penum++) { +debug.c: if (ctrl->mype == penum) { +debug.c: printf("PE: %d, nnbrs: %d\n", ctrl->mype, graph->nnbrs); +debug.c: MPI_Barrier(ctrl->comm); +debug.c: MPI_Barrier(ctrl->comm); +debug.c: for (penum=0; penum<ctrl->npes; penum++) { +debug.c: if (ctrl->mype == penum) { +debug.c: printf("PE: %d, nnbrs: %d", ctrl->mype, nnbrs); +debug.c: MPI_Barrier(ctrl->comm); +diffutil.c: nparts = ctrl->nparts; +diffutil.c: myhome = (ctrl->ps_relation == COUPLED) ? ctrl->mype : graph->home[i]; +diffutil.c: /* PrintVector(ctrl, ctrl->npes, 0, lend, "Lend: "); */ +diffutil.c: MPI_Allreduce((void *)lstart, (void *)gstart, nparts, IDX_DATATYPE, MPI_SUM, ctrl->comm); +diffutil.c: MPI_Allreduce((void *)lleft, (void *)gleft, nparts, IDX_DATATYPE, MPI_SUM, ctrl->comm); +diffutil.c: MPI_Allreduce((void *)lend, (void *)gend, nparts, IDX_DATATYPE, MPI_SUM, ctrl->comm); +grsetup.c: graph->gnvtxs = vtxdist[ctrl->npes]; +grsetup.c: graph->nvtxs = vtxdist[ctrl->mype+1]-vtxdist[ctrl->mype]; +grsetup.c: ctrl->tvwgts[j] = GlobalSESum(ctrl, ltvwgts[j]); +grsetup.c: if (ctrl->tvwgts[i] == 0) { +grsetup.c: graph->nvwgt[i*ncon+j] = (float)(graph->vwgt[i*ncon+j]) / (float)(ctrl->tvwgts[j]); +grsetup.c: srand(ctrl->seed); +grsetup.c: MPI_Comm_dup(comm, &(ctrl->gcomm)); +grsetup.c: MPI_Comm_rank(ctrl->gcomm, &ctrl->mype); +grsetup.c: MPI_Comm_size(ctrl->gcomm, &ctrl->npes); +grsetup.c: ctrl->dbglvl = dbglvl; +grsetup.c: ctrl->nparts = nparts; /* Set the # of partitions is de-coupled from the # of domains */ +grsetup.c: ctrl->comm = ctrl->gcomm; +grsetup.c: ctrl->xyztype = XYZ_SPFILL; +grsetup.c: srand(ctrl->mype); +grsetup.c: lpvtxs = idxsmalloc(ctrl->nparts, 0, "ComputeMoveStatistics: lpvtxs"); +grsetup.c: gpvtxs = idxsmalloc(ctrl->nparts, 0, "ComputeMoveStatistics: gpvtxs"); +grsetup.c: if (where[i] != ctrl->mype) +grsetup.c: /* PrintVector(ctrl, ctrl->npes, 0, lpvtxs, "Lpvtxs: "); */ +grsetup.c: MPI_Allreduce((void *)lpvtxs, (void *)gpvtxs, ctrl->nparts, IDX_DATATYPE, MPI_SUM, ctrl->comm); +grsetup.c: *maxin = GlobalSEMax(ctrl, gpvtxs[ctrl->mype]-(nvtxs-j)); +initbalance.c: IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->InitPartTmr)); +initbalance.c: mytpwgts = fsmalloc(ctrl->nparts, 0.0, "mytpwgts"); +initbalance.c: for (i=0; i<ctrl->nparts; i++) +initbalance.c: mytpwgts[i] += ctrl->tpwgts[i*ncon+j]; +initbalance.c: for (i=0; i<ctrl->nparts; i++) +initbalance.c: if (ctrl->ps_relation == DISCOUPLED) { +initbalance.c: rcounts = imalloc(ctrl->npes, "rcounts"); +initbalance.c: rdispls = imalloc(ctrl->npes+1, "rdispls"); +initbalance.c: for (i=0; i<ctrl->npes; i++) { +initbalance.c: MAKECSR(i, ctrl->npes, rdispls); +initbalance.c: (void *)part, rcounts, rdispls, IDX_DATATYPE, ctrl->comm); +initbalance.c: for (i=0; i<ctrl->npes; i++) +initbalance.c: if (part[i] >= ctrl->nparts) +initbalance.c: part[i] = home[i] = part[i] % ctrl->nparts; +initbalance.c: part[i] = home[i] = (-1*part[i]) % ctrl->nparts; +initbalance.c: IFSET(ctrl->dbglvl, DBG_REFINEINFO, Moc_ComputeSerialBalance(ctrl, agraph, agraph->where, lbvec)); +initbalance.c: IFSET(ctrl->dbglvl, DBG_REFINEINFO, rprintf(ctrl, "input cut: %d, balance: ", ComputeSerialEdgeCut(agraph))); +initbalance.c: IFSET(ctrl->dbglvl, DBG_REFINEINFO, rprintf(ctrl, "%.3f ", lbvec[i])); +initbalance.c: IFSET(ctrl->dbglvl, DBG_REFINEINFO, rprintf(ctrl, "\n")); +initbalance.c: sr = (ctrl->mype % 2 == 0) ? 1 : 0; +initbalance.c: gd = (ctrl->mype % 2 == 1) ? 1 : 0; +initbalance.c: if (graph->ncon > MAX_NCON_FOR_DIFFUSION || ctrl->npes == 1) { +initbalance.c: MPI_Comm_split(ctrl->gcomm, sr, 0, &ipcomm); +initbalance.c: myctrl.sync = ctrl->sync; +initbalance.c: myctrl.seed = ctrl->seed; +initbalance.c: myctrl.nparts = ctrl->nparts; +initbalance.c: myctrl.ipc_factor = ctrl->ipc_factor; +initbalance.c: myctrl.redist_factor = ctrl->redist_base; +initbalance.c: myctrl.tpwgts = ctrl->tpwgts; +initbalance.c: icopy(ncon, ctrl->tvwgts, myctrl.tvwgts); +initbalance.c: icopy(ncon, ctrl->ubvec, myctrl.ubvec); +initbalance.c: moptions[7] = ctrl->sync + (mype % ngroups) + 1; +initbalance.c: lnparts = ctrl->nparts; +initbalance.c: lpecost.rank = ctrl->mype; +initbalance.c: if (ctrl->mype == gpecost.rank && ctrl->mype != sr_pe) { +initbalance.c: MPI_Send((void *)part, nvtxs, IDX_DATATYPE, sr_pe, 1, ctrl->comm); +initbalance.c: if (ctrl->mype != gpecost.rank && ctrl->mype == sr_pe) { +initbalance.c: MPI_Recv((void *)part, nvtxs, IDX_DATATYPE, gpecost.rank, 1, ctrl->comm, &status); +initbalance.c: if (ctrl->mype == sr_pe) { +initbalance.c: SerialRemap(&cgraph, ctrl->nparts, home, lwhere, part, ctrl->tpwgts); +initbalance.c: lpecost.rank = ctrl->mype; +initbalance.c: if (ctrl->mype == gpecost.rank && ctrl->mype != gd_pe) +initbalance.c: MPI_Send((void *)part, nvtxs, IDX_DATATYPE, gd_pe, 1, ctrl->comm); +initbalance.c: if (ctrl->mype != gpecost.rank && ctrl->mype == gd_pe) +initbalance.c: MPI_Recv((void *)part, nvtxs, IDX_DATATYPE, gpecost.rank, 1, ctrl->comm, &status); +initbalance.c: if (ctrl->mype == gd_pe) { +initbalance.c: SerialRemap(&cgraph, ctrl->nparts, home, lwhere, part, ctrl->tpwgts); +initbalance.c: if (ctrl->mype == sr_pe || ctrl->mype == gd_pe) { +initbalance.c: my_cost = ctrl->ipc_factor * my_cut + REDIST_WGT * ctrl->redist_base * my_totalv; +initbalance.c: IFSET(ctrl->dbglvl, DBG_REFINEINFO, printf("%s initial cut: %.1f, totalv: %.1f, balance: %.3f\n", +initbalance.c: (ctrl->mype == sr_pe ? "scratch-remap" : "diffusion"), my_cut, my_totalv, my_balance)); +initbalance.c: if (ctrl->mype == gd_pe) { +initbalance.c: MPI_Send((void *)buffer, 2, MPI_FLOAT, sr_pe, 1, ctrl->comm); +initbalance.c: MPI_Recv((void *)buffer, 2, MPI_FLOAT, gd_pe, 1, ctrl->comm, &status); +initbalance.c: if (ctrl->mype == sr_pe) { +initbalance.c: MPI_Bcast((void *)&who_wins, 1, MPI_INT, sr_pe, ctrl->comm); +initbalance.c: MPI_Bcast((void *)part, nvtxs, IDX_DATATYPE, who_wins, ctrl->comm); +initbalance.c: idxcopy(graph->nvtxs, part+vtxdist[ctrl->mype], graph->where); +initbalance.c: IFSET(ctrl->dbglvl, DBG_TIME, stoptim
\ No newline at end of file diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/timer.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/timer.c new file mode 100644 index 0000000..73cc11a --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/timer.c @@ -0,0 +1,90 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * timer.c + * + * This file contain various timing routines + * + * Started 10/19/96 + * George + * + * $Id: timer.c,v 1.2 2003/07/21 17:18:54 karypis Exp $ + * + */ + +#include <parmetislib.h> + + + + +/************************************************************************* +* This function initializes the various timers +**************************************************************************/ +void InitTimers(CtrlType *ctrl) +{ + cleartimer(ctrl->TotalTmr); + cleartimer(ctrl->InitPartTmr); + cleartimer(ctrl->MatchTmr); + cleartimer(ctrl->ContractTmr); + cleartimer(ctrl->CoarsenTmr); + cleartimer(ctrl->RefTmr); + cleartimer(ctrl->SetupTmr); + cleartimer(ctrl->ProjectTmr); + cleartimer(ctrl->KWayInitTmr); + cleartimer(ctrl->KWayTmr); + cleartimer(ctrl->MoveTmr); + cleartimer(ctrl->RemapTmr); + + cleartimer(ctrl->AuxTmr1); + cleartimer(ctrl->AuxTmr2); + cleartimer(ctrl->AuxTmr3); + cleartimer(ctrl->AuxTmr4); + cleartimer(ctrl->AuxTmr5); + cleartimer(ctrl->AuxTmr6); +} + + +/************************************************************************* +* This function prints timing information about KMETIS +**************************************************************************/ +void PrintTimingInfo(CtrlType *ctrl) +{ +/* PrintTimer(ctrl, ctrl->CoarsenTmr, " Coarsening"); */ + PrintTimer(ctrl, ctrl->SetupTmr, " Setup"); + PrintTimer(ctrl, ctrl->MatchTmr, " Matching"); + PrintTimer(ctrl, ctrl->ContractTmr, "Contraction"); + PrintTimer(ctrl, ctrl->InitPartTmr, " InitPart"); +/* PrintTimer(ctrl, ctrl->RefTmr, " Refinement"); */ + PrintTimer(ctrl, ctrl->ProjectTmr, " Project"); + PrintTimer(ctrl, ctrl->KWayInitTmr, " Initialize"); + PrintTimer(ctrl, ctrl->KWayTmr, " K-way"); + PrintTimer(ctrl, ctrl->MoveTmr, " Move"); + PrintTimer(ctrl, ctrl->RemapTmr, " Remap"); + PrintTimer(ctrl, ctrl->TotalTmr, " Total"); + PrintTimer(ctrl, ctrl->AuxTmr1, " Aux1"); + PrintTimer(ctrl, ctrl->AuxTmr2, " Aux2"); + PrintTimer(ctrl, ctrl->AuxTmr3, " Aux3"); + PrintTimer(ctrl, ctrl->AuxTmr4, " Aux4"); + PrintTimer(ctrl, ctrl->AuxTmr5, " Aux5"); + PrintTimer(ctrl, ctrl->AuxTmr6, " Aux6"); +} + + +/************************************************************************* +* This function prints timer stat +**************************************************************************/ +void PrintTimer(CtrlType *ctrl, timer tmr, char *msg) +{ + double sum, max, tsec; + + tsec = gettimer(tmr); + MPI_Reduce((void *)&tsec, (void *)&sum, 1, MPI_DOUBLE, MPI_SUM, 0, ctrl->comm); + + tsec = gettimer(tmr); + MPI_Reduce((void *)&tsec, (void *)&max, 1, MPI_DOUBLE, MPI_MAX, 0, ctrl->comm); + + if (ctrl->mype == 0 && sum != 0.0) + printf("%s: Max: %7.3f, Sum: %7.3f, Balance: %7.3f\n", + msg, (float)max, (float)sum, (float)(max*ctrl->npes/sum)); +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/util.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/util.c new file mode 100644 index 0000000..34c657d --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/util.c @@ -0,0 +1,983 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * util.c + * + * This function contains various utility routines + * + * Started 9/28/95 + * George + * + * $Id: util.c,v 1.2 2003/07/21 17:18:54 karypis Exp $ + */ + +#include <parmetislib.h> + + +/************************************************************************* +* This function prints an error message and exits +**************************************************************************/ +void errexit(char *f_str,...) +{ + va_list argp; + char out1[256], out2[256]; + + va_start(argp, f_str); + vsprintf(out1, f_str, argp); + va_end(argp); + + sprintf(out2, "Error! %s", out1); + + fprintf(stdout, out2); + fflush(stdout); + + abort(); +} + + +/************************************************************************* +* This function prints an error message and exits +**************************************************************************/ +void myprintf(CtrlType *ctrl, char *f_str,...) +{ + va_list argp; + char out1[256], out2[256]; + + va_start(argp, f_str); + vsprintf(out1, f_str, argp); + va_end(argp); + + sprintf(out2, "[%2d] %s", ctrl->mype, out1); + + fprintf(stdout, out2); + fflush(stdout); + +} + + + +/************************************************************************* +* This function prints an error message and exits +**************************************************************************/ +void rprintf(CtrlType *ctrl, char *f_str,...) +{ + va_list argp; + + if (ctrl->mype == 0) { + va_start(argp, f_str); + vfprintf(stdout, f_str, argp); + va_end(argp); + } + + fflush(stdout); + + MPI_Barrier(ctrl->comm); + +} + + +#ifndef DMALLOC +/************************************************************************* +* The following function allocates an array of integers +**************************************************************************/ +int *imalloc(int n, char *msg) +{ + if (n == 0) + return NULL; + + return (int *)GKmalloc(sizeof(int)*n, msg); +} + + +/************************************************************************* +* The following function allocates an array of integers +**************************************************************************/ +idxtype *idxmalloc(int n, char *msg) +{ + if (n == 0) + return NULL; + + return (idxtype *)GKmalloc(sizeof(idxtype)*n, msg); +} + + +/************************************************************************* +* The following function allocates an array of float +**************************************************************************/ +float *fmalloc(int n, char *msg) +{ + if (n == 0) + return NULL; + + return (float *)GKmalloc(sizeof(float)*n, msg); +} + + +/************************************************************************* +* The follwoing function allocates an array of integers +**************************************************************************/ +int *ismalloc(int n, int ival, char *msg) +{ + if (n == 0) + return NULL; + + return iset(n, ival, (int *)GKmalloc(sizeof(int)*n, msg)); +} + + + +/************************************************************************* +* The follwoing function allocates an array of integers +**************************************************************************/ +idxtype *idxsmalloc(int n, idxtype ival, char *msg) +{ + if (n == 0) + return NULL; + + return idxset(n, ival, (idxtype *)GKmalloc(sizeof(idxtype)*n, msg)); +} + + +/************************************************************************* +* This function is my wrapper around malloc +**************************************************************************/ +void *GKmalloc(int nbytes, char *msg) +{ + void *ptr; + + if (nbytes == 0) + return NULL; + + ptr = (void *)malloc(nbytes); + if (ptr == NULL) + errexit("***Memory allocation failed for %s. Requested size: %d bytes", msg, nbytes); + + return ptr; +} +#endif + +/************************************************************************* +* This function is my wrapper around free, allows multiple pointers +**************************************************************************/ +void GKfree(void **ptr1,...) +{ + va_list plist; + void **ptr; + + if (*ptr1 != NULL) + free(*ptr1); + *ptr1 = NULL; + + va_start(plist, ptr1); + + while ((ptr = va_arg(plist, void **)) != LTERM) { + if (*ptr != NULL) + free(*ptr); + *ptr = NULL; + } + + va_end(plist); +} + + +/************************************************************************* +* These functions set the values of a vector +**************************************************************************/ +int *iset(int n, int val, int *x) +{ + int i; + + for (i=0; i<n; i++) + x[i] = val; + + return x; +} + + +/************************************************************************* +* These functions set the values of a vector +**************************************************************************/ +idxtype *idxset(int n, idxtype val, idxtype *x) +{ + int i; + + for (i=0; i<n; i++) + x[i] = val; + + return x; +} + + + +/************************************************************************* +* These functions return the index of the maximum element in a vector +**************************************************************************/ +int idxamax(int n, idxtype *x) +{ + int i, max=0; + + for (i=1; i<n; i++) + max = (x[i] > x[max] ? i : max); + + return max; +} + + +/************************************************************************* +* These functions return the index of the minimum element in a vector +**************************************************************************/ +int idxamin(int n, idxtype *x) +{ + int i, min=0; + + for (i=1; i<n; i++) + min = (x[i] < x[min] ? i : min); + + return min; +} + + +/************************************************************************* +* This function sums the entries in an array +**************************************************************************/ +int idxsum(int n, idxtype *x) +{ + int i, sum = 0; + + for (i=0; i<n; i++) + sum += x[i]; + + return sum; +} + + +/************************************************************************* +* This function sums the entries in an array +**************************************************************************/ +int charsum(int n, char *x) +{ + int i, sum = 0; + + for (i=0; i<n; i++) + sum += x[i]; + + return sum; +} + +/************************************************************************* +* This function sums the entries in an array +**************************************************************************/ +int isum(int n, int *x) +{ + int i, sum = 0; + + for (i=0; i<n; i++) + sum += x[i]; + + return sum; +} + + +/************************************************************************* +* This function computes a 2-norm +**************************************************************************/ +float snorm2(int n, float *v) +{ + int i; + float partial = 0; + + for (i = 0; i<n; i++) + partial += v[i] * v[i]; + + return sqrt(partial); +} + + + +/************************************************************************* +* This function computes a 2-norm +**************************************************************************/ +float sdot(int n, float *x, float *y) +{ + int i; + float partial = 0; + + for (i = 0; i<n; i++) + partial += x[i] * y[i]; + + return partial; +} + + +/************************************************************************* +* This function computes a 2-norm +**************************************************************************/ +void saxpy(int n, float alpha, float *x, float *y) +{ + int i; + + for (i=0; i<n; i++) + y[i] += alpha*x[i]; +} + + + + + + +/************************************************************************* +* This function sorts an array of type KeyValueType in increasing order +**************************************************************************/ +void ikeyvalsort_org(int n, KeyValueType *nodes) +{ + qsort((void *)nodes, (size_t)n, (size_t)sizeof(KeyValueType), IncKeyValueCmp); +} + + +/************************************************************************* +* This function compares 2 KeyValueType variables for sorting in inc order +**************************************************************************/ +int IncKeyValueCmp(const void *v1, const void *v2) +{ + KeyValueType *n1, *n2; + + n1 = (KeyValueType *)v1; + n2 = (KeyValueType *)v2; + + return (n1->key != n2->key ? n1->key - n2->key : n1->val - n2->val); +} + + + +/************************************************************************* +* This function sorts an array of type KeyValueType in increasing order +**************************************************************************/ +void dkeyvalsort(int n, KeyValueType *nodes) +{ + qsort((void *)nodes, (size_t)n, (size_t)sizeof(KeyValueType), DecKeyValueCmp); +} + + +/************************************************************************* +* This function compares 2 KeyValueType variables for sorting in inc order +**************************************************************************/ +int DecKeyValueCmp(const void *v1, const void *v2) +{ + KeyValueType *n1, *n2; + + n1 = (KeyValueType *)v1; + n2 = (KeyValueType *)v2; + + return n2->key - n1->key; + +} + + + +/************************************************************************* +* This function does a binary search on an array for a key and returns +* the index +**************************************************************************/ +int BSearch(int n, idxtype *array, int key) +{ + int a=0, b=n, c; + + while (b-a > 8) { + c = (a+b)>>1; + if (array[c] > key) + b = c; + else + a = c; + } + + for (c=a; c<b; c++) { + if (array[c] == key) + return c; + } + + errexit("Key %d not found!\n", key); + + return 0; +} + + + +/************************************************************************* +* This file randomly permutes the contents of an array. +* flag == 0, don't initialize perm +* flag == 1, set p[i] = i +**************************************************************************/ +void RandomPermute(int n, idxtype *p, int flag) +{ + int i, u, v; + idxtype tmp; + + if (flag == 1) { + for (i=0; i<n; i++) + p[i] = i; + } + + for (i=0; i<n; i++) { + v = RandomInRange(n); + u = RandomInRange(n); + SWAP(p[v], p[u], tmp); + } +} + + +/************************************************************************* +* This file randomly permutes the contents of an array. +* flag == 0, don't initialize perm +* flag == 1, set p[i] = i +**************************************************************************/ +void FastRandomPermute(int n, idxtype *p, int flag) +{ + int i, u, v; + idxtype tmp; + + /* this is for very small arrays */ + if (n < 25) { + RandomPermute(n, p, flag); + return; + } + + if (flag == 1) { + for (i=0; i<n; i++) + p[i] = i; + } + + for (i=0; i<n; i+=8) { + v = RandomInRange(n-4); + u = RandomInRange(n-4); + SWAP(p[v], p[u], tmp); + SWAP(p[v+1], p[u+1], tmp); + SWAP(p[v+2], p[u+2], tmp); + SWAP(p[v+3], p[u+3], tmp); + } +} + +/************************************************************************* +* This function returns true if the a is a power of 2 +**************************************************************************/ +int ispow2(int a) +{ + for (; a%2 != 1; a = a>>1); + return (a > 1 ? 0 : 1); +} + +/************************************************************************* +* This function returns the log2(x) +**************************************************************************/ +int log2Int(int a) +{ + int i; + + for (i=1; a > 1; i++, a = a>>1); + return i-1; +} + + +/************************************************************************* +* These functions set the values of a vector +**************************************************************************/ +float *sset(int n, float val, float *x) +{ + int i; + + for (i=0; i<n; i++) + x[i] = val; + + return x; +} + + + +/************************************************************************* +* These functions return the index of the maximum element in a vector +**************************************************************************/ +int iamax(int n, int *x) +{ + int i, max=0; + + for (i=1; i<n; i++) + max = (x[i] > x[max] ? i : max); + + return max; +} + + +/************************************************************************* +* These functions return the index of the maximum element in a vector +**************************************************************************/ +int samax_strd(int n, float *x, int incx) +{ + int i; + int max=0; + + n *= incx; + for (i=incx; i<n; i+=incx) + max = (x[i] > x[max] ? i : max); + + return max/incx; +} + + +/************************************************************************* +* These functions return the index of the maximum element in a vector +**************************************************************************/ +int sfamax(int n, float *x) +{ + int i; + int max=0; + + for (i=1; i<n; i++) + max = (fabs(x[i]) > fabs(x[max]) ? i : max); + + return max; +} + + + +/************************************************************************* +* These functions return the index of the maximum element in a vector +**************************************************************************/ +int samin_strd(int n, float *x, int incx) +{ + int i; + int min=0; + + n *= incx; + for (i=incx; i<n; i+=incx) + min = (x[i] < x[min] ? i : min); + + return min/incx; +} + + +/************************************************************************* +* These functions return the index of the maximum element in a vector +**************************************************************************/ +int idxamax_strd(int n, idxtype *x, int incx) +{ + int i, max=0; + + n *= incx; + for (i=incx; i<n; i+=incx) + max = (x[i] > x[max] ? i : max); + + return max/incx; +} + + +/************************************************************************* +* These functions return the index of the maximum element in a vector +**************************************************************************/ +int idxamin_strd(int n, idxtype *x, int incx) +{ + int i, min=0; + + n *= incx; + for (i=incx; i<n; i+=incx) + min = (x[i] < x[min] ? i : min); + + return min/incx; +} + + +/************************************************************************* +* This function returns the average value of an array +**************************************************************************/ +float idxavg(int n, idxtype *x) +{ + int i; + float retval = 0.0; + + for (i=0; i<n; i++) + retval += (float)(x[i]); + + return retval / (float)(n); +} + + +/************************************************************************* +* This function returns the average value of an array +**************************************************************************/ +float savg(int n, float *x) +{ + int i; + float retval = 0.0; + + for (i=0; i<n; i++) + retval += x[i]; + + return retval / (float)(n); +} + + +/************************************************************************* +* These functions return the index of the maximum element in a vector +**************************************************************************/ +int samax(int n, float *x) +{ + int i, max=0; + + for (i=1; i<n; i++) + max = (x[i] > x[max] ? i : max); + + return max; +} + + +/************************************************************************* +* These functions return the index of the maximum element in a vector +**************************************************************************/ +int sfavg(int n, float *x) +{ + int i; + float total = 0.0; + + if (n == 0) + return 0.0; + + for (i=0; i<n; i++) + total += fabs(x[i]); + + return total / (float) n; +} + + +/************************************************************************* +* These functions return the index of the almost maximum element in a vector +**************************************************************************/ +int samax2(int n, float *x) +{ + int i, max1, max2; + + if (x[0] > x[1]) { + max1 = 0; + max2 = 1; + } + else { + max1 = 1; + max2 = 0; + } + + for (i=2; i<n; i++) { + if (x[i] > x[max1]) { + max2 = max1; + max1 = i; + } + else if (x[i] > x[max2]) + max2 = i; + } + + return max2; +} + + +/************************************************************************* +* These functions return the index of the minimum element in a vector +**************************************************************************/ +int samin(int n, float *x) +{ + int i, min=0; + + for (i=1; i<n; i++) + min = (x[i] < x[min] ? i : min); + + return min; +} + + +/************************************************************************* +* This function sums the entries in an array +**************************************************************************/ +int idxsum_strd(int n, idxtype *x, int incx) +{ + int i, sum = 0; + + for (i=0; i<n; i++, x+=incx) { + sum += *x; + } + + return sum; +} + + +/************************************************************************* +* This function sums the entries in an array +**************************************************************************/ +void idxadd(int n, idxtype *x, idxtype *y) +{ + for (n--; n>=0; n--) + y[n] += x[n]; +} + + +/************************************************************************* +* This function sums the entries in an array +**************************************************************************/ +float ssum(int n, float *x) +{ + int i; + float sum = 0.0; + + for (i=0; i<n; i++) + sum += x[i]; + + return sum; +} + +/************************************************************************* +* This function sums the entries in an array +**************************************************************************/ +float ssum_strd(int n, float *x, int incx) +{ + int i; + float sum = 0.0; + + for (i=0; i<n; i++, x+=incx) + sum += *x; + + return sum; +} + +/************************************************************************* +* This function sums the entries in an array +**************************************************************************/ +void sscale(int n, float alpha, float *x) +{ + int i; + + for (i=0; i<n; i++) + x[i] *= alpha; +} + + +/************************************************************************* +* This function negates the entries in an array +**************************************************************************/ +void saneg(int n, float *x) +{ + int i; + + for (i=0; i<n; i++) + x[i] = -1.0*x[i]; +} + + + +/************************************************************************* +* This function checks if v+u2 provides a better balance in the weight +* vector that v+u1 +**************************************************************************/ +float BetterVBalance(int ncon, float *vwgt, float *u1wgt, float *u2wgt) +{ + int i; + float sum1, sum2, diff1, diff2; + + if (ncon == 1) + return u1wgt[0] - u1wgt[0]; + + sum1 = sum2 = 0.0; + for (i=0; i<ncon; i++) { + sum1 += vwgt[i]+u1wgt[i]; + sum2 += vwgt[i]+u2wgt[i]; + } + sum1 = sum1/(1.0*ncon); + sum2 = sum2/(1.0*ncon); + + diff1 = diff2 = 0.0; + for (i=0; i<ncon; i++) { + diff1 += fabs(sum1 - (vwgt[i]+u1wgt[i])); + diff2 += fabs(sum2 - (vwgt[i]+u2wgt[i])); + } + + return diff1 - diff2; + +} + + +/************************************************************************* +* This function checks if the pairwise balance of the between the two +* partitions will improve by moving the vertex v from pfrom to pto, +* subject to the target partition weights of tfrom, and tto respectively +**************************************************************************/ +int IsHBalanceBetterFT(int ncon, float *pfrom, float *pto, float *nvwgt, float *ubvec) +{ + int i; + float blb1=0.0, alb1=0.0, sblb=0.0, salb=0.0; + float blb2=0.0, alb2=0.0; + float temp; + + for (i=0; i<ncon; i++) { + temp = amax(pfrom[i], pto[i])/ubvec[i]; + if (blb1 < temp) { + blb2 = blb1; + blb1 = temp; + } + else if (blb2 < temp) + blb2 = temp; + sblb += temp; + + temp = amax(pfrom[i]-nvwgt[i], pto[i]+nvwgt[i])/ubvec[i]; + if (alb1 < temp) { + alb2 = alb1; + alb1 = temp; + } + else if (alb2 < temp) + alb2 = temp; + salb += temp; + } + + if (alb1 < blb1) + return 1; + if (blb1 < alb1) + return 0; + if (alb2 < blb2) + return 1; + if (blb2 < alb2) + return 0; + + return salb < sblb; + +} + +/************************************************************************* +* This function checks if it will be better to move a vertex to pt2 than +* to pt1 subject to their target weights of tt1 and tt2, respectively +* This routine takes into account the weight of the vertex in question +**************************************************************************/ +int IsHBalanceBetterTT(int ncon, float *pt1, float *pt2, float *nvwgt, float *ubvec) +{ + int i; + float m11=0.0, m12=0.0, m21=0.0, m22=0.0, sm1=0.0, sm2=0.0, temp; + + for (i=0; i<ncon; i++) { + temp = (pt1[i]+nvwgt[i])/ubvec[i]; + if (m11 < temp) { + m12 = m11; + m11 = temp; + } + else if (m12 < temp) + m12 = temp; + sm1 += temp; + temp = (pt2[i]+nvwgt[i])/ubvec[i]; + if (m21 < temp) { + m22 = m21; + m21 = temp; + } + else if (m22 < temp) + m22 = temp; + sm2 += temp; + } + if (m21 < m11) + return 1; + if (m21 > m11) + return 0; + if (m22 < m12) + return 1; + if (m22 > m12) + return 0; + + return sm2 < sm1; +} + +/************************************************************************* +* This is a comparison function +**************************************************************************/ +int myvalkeycompare(const void *fptr, const void *sptr) +{ + KVType *first, *second; + + first = (KVType *)(fptr); + second = (KVType *)(sptr); + + if (first->val > second->val) + return 1; + + if (first->val < second->val) + return -1; + + return 0; +} + +/************************************************************************* +* This is the inverse comparison function +**************************************************************************/ +int imyvalkeycompare(const void *fptr, const void *sptr) +{ + KVType *first, *second; + + first = (KVType *)(fptr); + second = (KVType *)(sptr); + + if (first->val > second->val) + return -1; + + if (first->val < second->val) + return 1; + + return 0; +} + + +/************************************************************************* +* The following function allocates and sets an array of floats +**************************************************************************/ +float *fsmalloc(int n, float fval, char *msg) +{ + if (n == 0) + return NULL; + + return sset(n, fval, (float *)GKmalloc(sizeof(float)*n, msg)); +} + + +/************************************************************************* +* This function computes a 2-norm +**************************************************************************/ +void saxpy2(int n, float alpha, float *x, int incx, float *y, int incy) +{ + int i; + + for (i=0; i<n; i++, x+=incx, y+=incy) + *y += alpha*(*x); +} + + +/************************************************************************* +* This function computes the top three values of a float array +**************************************************************************/ +void GetThreeMax(int n, float *x, int *first, int *second, int *third) +{ + int i; + + if (n <= 0) { + *first = *second = *third = -1; + return; + } + + *second = *third = -1; + *first = 0; + + for (i=1; i<n; i++) { + if (x[i] > x[*first]) { + *third = *second; + *second = *first; + *first = i; + continue; + } + + if (*second == -1 || x[i] > x[*second]) { + *third = *second; + *second = i; + continue; + } + + if (*third == -1 || x[i] > x[*third]) + *third = i; + } + + return; +} diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/wave.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/wave.c new file mode 100644 index 0000000..0f1cb3f --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/wave.c @@ -0,0 +1,241 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * wave.c + * + * This file contains code for directed diffusion at the coarsest graph + * + * Started 5/19/97, Kirk, George + * + * $Id: wave.c,v 1.3 2003/07/22 21:47:18 karypis Exp $ + * + */ + +#include <parmetislib.h> + +/************************************************************************* +* This function performs a k-way directed diffusion +**************************************************************************/ +float WavefrontDiffusion(CtrlType *ctrl, GraphType *graph, idxtype *home) +{ + int ii, i, j, k, l, nvtxs, nedges, nparts; + int from, to, edge, done, nswaps, noswaps, totalv, wsize; + int npasses, first, second, third, mind, maxd; + idxtype *xadj, *adjncy, *adjwgt, *where, *perm; + idxtype *rowptr, *colind, *ed, *psize; + float *transfer, *tmpvec; + float balance = -1.0, *load, *solution, *workspace; + float *nvwgt, *npwgts, flowFactor, cost, ubfactor; + MatrixType matrix; + KeyValueType *cand; + int ndirty, nclean, dptr, clean; + + nvtxs = graph->nvtxs; + nedges = graph->nedges; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + nparts = ctrl->nparts; + ubfactor = ctrl->ubvec[0]; + matrix.nrows = nparts; + + flowFactor = 0.35; + flowFactor = (ctrl->mype == 2) ? 0.50 : flowFactor; + flowFactor = (ctrl->mype == 3) ? 0.75 : flowFactor; + flowFactor = (ctrl->mype == 4) ? 1.00 : flowFactor; + + /* allocate memory */ + solution = fmalloc(4*nparts+2*nedges, "WavefrontDiffusion: solution"); + tmpvec = solution + nparts; + npwgts = solution + 2*nparts; + load = solution + 3*nparts; + matrix.values = solution + 4*nparts; + transfer = matrix.transfer = solution + 4*nparts + nedges; + + perm = idxmalloc(2*nvtxs+2*nparts+nedges+1, "WavefrontDiffusion: perm"); + ed = perm + nvtxs; + psize = perm + 2*nvtxs; + rowptr = matrix.rowptr = perm + 2*nvtxs + nparts; + colind = matrix.colind = perm + 2*nvtxs + 2*nparts + 1; + + wsize = amax(sizeof(float)*nparts*6, sizeof(idxtype)*(nvtxs+nparts*2+1)); + workspace = (float *)GKmalloc(wsize, "WavefrontDiffusion: workspace"); + cand = (KeyValueType *)GKmalloc(nvtxs*sizeof(KeyValueType), "WavefrontDiffusion: cand"); + + + /*****************************/ + /* Populate empty subdomains */ + /*****************************/ + idxset(nparts, 0, psize); + for (i=0; i<nvtxs; i++) + psize[where[i]]++; + + mind = idxamin(nparts, psize); + maxd = idxamax(nparts, psize); + if (psize[mind] == 0) { + for (i=0; i<nvtxs; i++) { + k = (RandomInRange(nvtxs)+i)%nvtxs; + if (where[k] == maxd) { + where[k] = mind; + psize[mind]++; + psize[maxd]--; + break; + } + } + } + idxset(nvtxs, 0, ed); + sset(nparts, 0.0, npwgts); + for (i=0; i<nvtxs; i++) { + npwgts[where[i]] += nvwgt[i]; + for (j=xadj[i]; j<xadj[i+1]; j++) + ed[i] += (where[i] != where[adjncy[j]] ? adjwgt[j] : 0); + } + + ComputeLoad(graph, nparts, load, ctrl->tpwgts, 0); + done = 0; + + npasses = amin(nparts/2, NGD_PASSES); + for (l=0; l<npasses; l++) { + /* Set-up and solve the diffusion equation */ + nswaps = 0; + + /************************/ + /* Solve flow equations */ + /************************/ + SetUpConnectGraph(graph, &matrix, (idxtype *)workspace); + + /* check for disconnected subdomains */ + for(i=0; i<matrix.nrows; i++) { + if (matrix.rowptr[i]+1 == matrix.rowptr[i+1]) { + cost = (float)(ctrl->mype); + goto CleanUpAndExit; + } + } + + ConjGrad2(&matrix, load, solution, 0.001, workspace); + ComputeTransferVector(1, &matrix, solution, transfer, 0); + + GetThreeMax(nparts, load, &first, &second, &third); + + if (l%3 == 0) { + FastRandomPermute(nvtxs, perm, 1); + } + else { + /*****************************/ + /* move dirty vertices first */ + /*****************************/ + ndirty = 0; + for (i=0; i<nvtxs; i++) + if (where[i] != home[i]) + ndirty++; + + dptr = 0; + for (i=0; i<nvtxs; i++) + if (where[i] != home[i]) + perm[dptr++] = i; + else + perm[ndirty++] = i; + + ASSERT(ctrl, ndirty == nvtxs); + ndirty = dptr; + nclean = nvtxs-dptr; + FastRandomPermute(ndirty, perm, 0); + FastRandomPermute(nclean, perm+ndirty, 0); + } + + if (ctrl->mype == 0) { + for (j=nvtxs, k=0, ii=0; ii<nvtxs; ii++) { + i = perm[ii]; + if (ed[i] != 0) { + cand[k].key = -ed[i]; + cand[k++].val = i; + } + else { + cand[--j].key = 0; + cand[j].val = i; + } + } + ikeysort(k, cand); + } + + for (ii=0; ii<nvtxs/3; ii++) { + i = (ctrl->mype == 0) ? cand[ii].val : perm[ii]; + from = where[i]; + + /* don't move out the last vertex in a subdomain */ + if (psize[from] == 1) + continue; + + clean = (from == home[i]) ? 1 : 0; + + /* only move from top three or dirty vertices */ + if (from != first && from != second && from != third && clean) + continue; + + /* Scatter the sparse transfer row into the dense tmpvec row */ + for (j=rowptr[from]+1; j<rowptr[from+1]; j++) + tmpvec[colind[j]] = transfer[j]; + + for (j=xadj[i]; j<xadj[i+1]; j++) { + to = where[adjncy[j]]; + if (from != to) { + if (tmpvec[to] > (flowFactor * nvwgt[i])) { + tmpvec[to] -= nvwgt[i]; + INC_DEC(psize[to], psize[from], 1); + INC_DEC(npwgts[to], npwgts[from], nvwgt[i]); + INC_DEC(load[to], load[from], nvwgt[i]); + where[i] = to; + nswaps++; + + /* Update external degrees */ + ed[i] = 0; + for (k=xadj[i]; k<xadj[i+1]; k++) { + edge = adjncy[k]; + ed[i] += (to != where[edge] ? adjwgt[k] : 0); + + if (where[edge] == from) + ed[edge] += adjwgt[k]; + if (where[edge] == to) + ed[edge] -= adjwgt[k]; + } + break; + } + } + } + + /* Gather the dense tmpvec row into the sparse transfer row */ + for (j=rowptr[from]+1; j<rowptr[from+1]; j++) { + transfer[j] = tmpvec[colind[j]]; + tmpvec[colind[j]] = 0.0; + } + ASSERTS(fabs(ssum(nparts, tmpvec)) < .0001) + } + + if (l % 2 == 1) { + balance = npwgts[samax(nparts, npwgts)] * (float)nparts; + if (balance < ubfactor + 0.035) + done = 1; + + if (GlobalSESum(ctrl, done) > 0) + break; + + noswaps = (nswaps > 0) ? 0 : 1; + if (GlobalSESum(ctrl, noswaps) > ctrl->npes/2) + break; + + } + } + + graph->mincut = ComputeSerialEdgeCut(graph); + totalv = Mc_ComputeSerialTotalV(graph, home); + cost = ctrl->ipc_factor * (float)graph->mincut + ctrl->redist_factor * (float)totalv; + + +CleanUpAndExit: + GKfree((void **)&solution, (void **)&perm, (void **)&workspace, (void **)&cand, LTERM); + + return cost; +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/weird.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/weird.c new file mode 100644 index 0000000..69d0e5d --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/weird.c @@ -0,0 +1,275 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * weird.c + * + * This file contain various graph setting up routines + * + * Started 10/19/96 + * George + * + * $Id: weird.c,v 1.9 2003/07/31 16:27:28 karypis Exp $ + * + */ + +#include <parmetislib.h> + + + +/************************************************************************* +* This function computes a partitioning of a small graph +**************************************************************************/ +void PartitionSmallGraph(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace) +{ + int i, h, ncon, nparts, npes, mype; + int moptions[10]; + int mynumflag, mywgtflag, me; + idxtype *mypart; + int lpecut[2], gpecut[2]; + GraphType *agraph; + int *sendcounts, *displs; + float *mytpwgts, *gnpwgts, *lnpwgts; + + ncon = graph->ncon; + nparts = ctrl->nparts; + + MPI_Comm_size(ctrl->comm, &npes); + MPI_Comm_rank(ctrl->comm, &mype); + + SetUp(ctrl, graph, wspace); + graph->where = idxmalloc(graph->nvtxs+graph->nrecv, "PartitionSmallGraph: where"); + agraph = Moc_AssembleAdaptiveGraph(ctrl, graph, wspace); + mypart = idxmalloc(agraph->nvtxs, "mypart"); + + moptions[0] = 0; + moptions[7] = ctrl->sync + mype; + mynumflag = 0; + mywgtflag = 3; + if (ncon == 1) { + METIS_WPartGraphKway2(&agraph->nvtxs, agraph->xadj, agraph->adjncy, agraph->vwgt, + agraph->adjwgt, &mywgtflag, &mynumflag, &nparts, ctrl->tpwgts, moptions, + &graph->mincut, mypart); + } + else { + mytpwgts = fmalloc(nparts, "mytpwgts"); + for (i=0; i<nparts; i++) + mytpwgts[i] = ctrl->tpwgts[i*ncon]; + + METIS_mCPartGraphRecursive2(&agraph->nvtxs, &ncon, agraph->xadj, agraph->adjncy, + agraph->vwgt, agraph->adjwgt, &mywgtflag, &mynumflag, &nparts, mytpwgts, + moptions, &graph->mincut, mypart); + + free(mytpwgts); + } + + lpecut[0] = graph->mincut; + lpecut[1] = mype; + MPI_Allreduce(lpecut, gpecut, 1, MPI_2INT, MPI_MINLOC, ctrl->comm); + graph->mincut = gpecut[0]; + + if (lpecut[1] == gpecut[1] && gpecut[1] != 0) + MPI_Send((void *)mypart, agraph->nvtxs, IDX_DATATYPE, 0, 1, ctrl->comm); + if (lpecut[1] == 0 && gpecut[1] != 0) + MPI_Recv((void *)mypart, agraph->nvtxs, IDX_DATATYPE, gpecut[1], 1, ctrl->comm, &ctrl->status); + + sendcounts = imalloc(npes, "sendcounts"); + displs = imalloc(npes, "displs"); + + for (i=0; i<npes; i++) { + sendcounts[i] = graph->vtxdist[i+1]-graph->vtxdist[i]; + displs[i] = graph->vtxdist[i]; + } + + MPI_Scatterv((void *)mypart, sendcounts, displs, IDX_DATATYPE, + (void *)graph->where, graph->nvtxs, IDX_DATATYPE, 0, ctrl->comm); + + lnpwgts = graph->lnpwgts = fmalloc(nparts*ncon, "lnpwgts"); + gnpwgts = graph->gnpwgts = fmalloc(nparts*ncon, "gnpwgts"); + sset(nparts*ncon, 0, lnpwgts); + for (i=0; i<graph->nvtxs; i++) { + me = graph->where[i]; + for (h=0; h<ncon; h++) + lnpwgts[me*ncon+h] += graph->nvwgt[i*ncon+h]; + } + MPI_Allreduce((void *)lnpwgts, (void *)gnpwgts, nparts*ncon, MPI_FLOAT, MPI_SUM, ctrl->comm); + GKfree((void**)&mypart, (void**)&sendcounts, (void**)&displs, LTERM); + FreeGraph(agraph); + + return; +} + + + +/************************************************************************* +* This function checks the inputs for the partitioning routines +**************************************************************************/ +void CheckInputs(int partType, int npes, int dbglvl, int *wgtflag, int *iwgtflag, + int *numflag, int *inumflag, int *ncon, int *incon, int *nparts, + int *inparts, float *tpwgts, float **itpwgts, float *ubvec, + float *iubvec, float *ipc2redist, float *iipc2redist, int *options, + int *ioptions, idxtype *part, MPI_Comm *comm) +{ + int i, j; + int doweabort, doiabort = 0; + float tsum, *myitpwgts; + int mgcnums[5] = {-1, 2, 3, 4, 2}; + + /**************************************/ + if (part == NULL) { + doiabort = 1; + IFSET(dbglvl, DBG_INFO, printf("ERROR: part array is set to NULL.\n")); + } + /**************************************/ + + + /**************************************/ + if (wgtflag == NULL) { + *iwgtflag = 0; + IFSET(dbglvl, DBG_INFO, printf("WARNING: wgtflag is NULL. Using a value of 0.\n")); + } + else { + *iwgtflag = *wgtflag; + } + /**************************************/ + + + /**************************************/ + if (numflag == NULL) { + *inumflag = 0; + IFSET(dbglvl, DBG_INFO, printf("WARNING: numflag is NULL. Using a value of 0.\n")); + } + else { + if (*numflag != 0 && *numflag != 1) { + IFSET(dbglvl, DBG_INFO, printf("WARNING: bad value for numflag %d. Using a value of 0.\n", *numflag)); + *inumflag = 0; + } + else { + *inumflag = *numflag; + } + } + /**************************************/ + + + /**************************************/ + if (ncon == NULL) { + *incon = 1; + IFSET(dbglvl, DBG_INFO, printf("WARNING: ncon is NULL. Using a value of 1.\n")); + } + else { + if (*ncon < 1 || *ncon > MAXNCON) { + IFSET(dbglvl, DBG_INFO, printf("WARNING: bad value for ncon %d. Using a value of 1.\n", *ncon)); + *incon = 1; + } + else { + *incon = *ncon; + } + } + /**************************************/ + + + /**************************************/ + if (nparts == NULL) { + *inparts = npes; + IFSET(dbglvl, DBG_INFO, printf("WARNING: nparts is NULL. Using a value of %d.\n", npes)); + } + else { + if (*nparts < 1 || *nparts > MAX_NPARTS) { + IFSET(dbglvl, DBG_INFO, printf("WARNING: bad value for nparts %d. Using a value of %d.\n", *nparts, npes)); + *inparts = npes; + } + else { + *inparts = *nparts; + } + } + /**************************************/ + + + /**************************************/ + myitpwgts = *itpwgts = fmalloc((*inparts)*(*incon), "CheckInputs: itpwgts"); + if (tpwgts == NULL) { + sset((*inparts)*(*incon), 1.0/(float)(*inparts), myitpwgts); + IFSET(dbglvl, DBG_INFO, printf("WARNING: tpwgts is NULL. Setting all array elements to %.3f.\n", 1.0/(float)(*inparts))); + } + else { + for (i=0; i<*incon; i++) { + tsum = 0.0; + for (j=0; j<*inparts; j++) { + tsum += tpwgts[j*(*incon)+i]; + } + if (fabs(1.0-tsum) < SMALLFLOAT) + tsum = 1.0; + for (j=0; j<*inparts; j++) + myitpwgts[j*(*incon)+i] = tpwgts[j*(*incon)+i] / tsum; + } + } + /**************************************/ + + + /**************************************/ + if (ubvec == NULL) { + sset(*incon, 1.05, iubvec); + IFSET(dbglvl, DBG_INFO, printf("WARNING: ubvec is NULL. Setting all array elements to 1.05.\n")); + } + else { + for (i=0; i<*incon; i++) { + if (ubvec[i] < 1.0 || ubvec[i] > (float)(*inparts)) { + iubvec[i] = 1.05; + IFSET(dbglvl, DBG_INFO, printf("WARNING: bad value for ubvec[%d]: %.3f. Setting value to 1.05.[%d]\n", i, ubvec[i], *inparts)); + } + else { + iubvec[i] = ubvec[i]; + } + } + } + /**************************************/ + + + /**************************************/ + if (partType == ADAPTIVE_PARTITION) { + if (ipc2redist != NULL) { + if (*ipc2redist < SMALLFLOAT || *ipc2redist > 1000000.0) { + IFSET(dbglvl, DBG_INFO, printf("WARNING: bad value for ipc2redist %.3f. Using a value of 1000.\n", *ipc2redist)); + *iipc2redist = 1000.0; + } + else { + *iipc2redist = *ipc2redist; + } + } + else { + IFSET(dbglvl, DBG_INFO, printf("WARNING: ipc2redist is NULL. Using a value of 1000.\n")); + *iipc2redist = 1000.0; + } + } + /**************************************/ + + + /**************************************/ + if (options == NULL) { + ioptions[0] = 0; + IFSET(dbglvl, DBG_INFO, printf("WARNING: options is NULL. Using defaults\n")); + } + else { + ioptions[0] = options[0]; + ioptions[1] = options[1]; + ioptions[2] = options[2]; + if (partType == ADAPTIVE_PARTITION || partType == REFINE_PARTITION) + ioptions[3] = options[3]; + } + /**************************************/ + + + /**************************************/ + if (comm == NULL) { + IFSET(dbglvl, DBG_INFO, printf("ERROR: comm is NULL. Aborting\n")); + abort(); + } + else { + MPI_Allreduce((void *)&doiabort, (void *)&doweabort, 1, MPI_INT, MPI_MAX, *comm); + if (doweabort > 0) + abort(); + } + /**************************************/ + +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/xyzpart.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/xyzpart.c new file mode 100644 index 0000000..e538034 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/ParMETISLib/xyzpart.c @@ -0,0 +1,257 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * xyzpart.c + * + * This file contains code that implements a coordinate based partitioning + * + * Started 7/11/97 + * George + * + * $Id: xyzpart.c,v 1.3 2003/07/30 18:37:59 karypis Exp $ + * + */ + +#include <parmetislib.h> + + +/************************************************************************* +* This function implements a simple coordinate based partitioning +**************************************************************************/ +void Coordinate_Partition(CtrlType *ctrl, GraphType *graph, int ndims, float *xyz, + int setup, WorkSpaceType *wspace) +{ + int i, j, k, nvtxs, firstvtx, icoord, coords[3]; + idxtype *vtxdist; + float max[3], min[3], gmin[3], gmax[3], shift[3], scale[3]; + KeyValueType *cand; + + if (setup) + SetUp(ctrl, graph, wspace); + else + graph->nrecv = 0; + + nvtxs = graph->nvtxs; + vtxdist = graph->vtxdist; + + firstvtx = vtxdist[ctrl->mype]; + + cand = (KeyValueType *)GKmalloc(nvtxs*sizeof(KeyValueType), "Coordinate_Partition: cand"); + + /* Compute parameters for coordinate transformation */ + for (k=0; k<ndims; k++) { + min[k] = +10000000; + max[k] = -10000000; + } + for (i=0; i<nvtxs; i++) { + for (k=0; k<ndims; k++) { + if (xyz[i*ndims+k] < min[k]) + min[k] = xyz[i*ndims+k]; + if (xyz[i*ndims+k] > max[k]) + max[k] = xyz[i*ndims+k]; + } + } + + /* Compute global min and max */ + MPI_Allreduce((void *)min, (void *)gmin, ndims, MPI_FLOAT, MPI_MIN, ctrl->comm); + MPI_Allreduce((void *)max, (void *)gmax, ndims, MPI_FLOAT, MPI_MAX, ctrl->comm); + + /* myprintf(ctrl, "Coordinate Range: %e %e, Global %e %e\n", min[0], max[0], gmin[0], gmax[0]); */ + + for (k=0; k<ndims; k++) { + /* rprintf(ctrl, "Dim#%d: %e %e, span: %e\n", k, gmin[k], gmax[k], gmax[k]-gmin[k]); */ + shift[k] = -gmin[k]; + if (gmax[k] != gmin[k]) + scale[k] = 1.0/(gmax[k]-gmin[k]); + else + scale[k] = 1.0; + } + + switch (ctrl->xyztype) { + case XYZ_XCOORD: + for (i=0; i<nvtxs; i++) { + cand[i].key = 1000000*((xyz[i*ndims]+shift[0])*scale[0]); + ASSERT(ctrl, cand[i].key>=0 && cand[i].key<=1000000); + cand[i].val = firstvtx+i; + } + break; + case XYZ_SPFILL: + for (i=0; i<nvtxs; i++) { + for (k=0; k<ndims; k++) + coords[k] = 1024*((xyz[i*ndims+k]+shift[k])*scale[k]); + for (icoord=0, j=9; j>=0; j--) { + for (k=0; k<ndims; k++) + icoord = (icoord<<1) + (coords[k]&(1<<j) ? 1 : 0); + } + cand[i].key = icoord; + cand[i].val = firstvtx+i; + } + break; + default: + errexit("Unknown XYZ_Type type!\n"); + } + + + /* Partition using sorting */ + PartSort(ctrl, graph, cand, wspace); + + free(cand); + +} + + + +/************************************************************************* +* This function sorts a distributed list of KeyValueType in increasing +* order, and uses it to compute a partition. It uses samplesort. +**************************************************************************/ +void PartSort(CtrlType *ctrl, GraphType *graph, KeyValueType *elmnts, WorkSpaceType *wspace) +{ + int i, j, k, nvtxs, nrecv, npes=ctrl->npes, mype=ctrl->mype, firstvtx, lastvtx; + idxtype *scounts, *rcounts, *vtxdist, *perm; + KeyValueType *relmnts, *mypicks, *allpicks; + + nvtxs = graph->nvtxs; + vtxdist = graph->vtxdist; + + scounts = wspace->pv1; + rcounts = wspace->pv2; + + /* Allocate memory for the splitters */ + mypicks = (KeyValueType *)GKmalloc(sizeof(KeyValueType)*(npes+1), "ParSort: mypicks"); + allpicks = (KeyValueType *)GKmalloc(sizeof(KeyValueType)*npes*npes, "ParSort: allpicks"); + + /* Sort the local elements */ + ikeysort(nvtxs, elmnts); + + /* Select the local npes-1 equally spaced elements */ + for (i=1; i<npes; i++) { + mypicks[i-1].key = elmnts[i*(nvtxs/npes)].key; + mypicks[i-1].val = elmnts[i*(nvtxs/npes)].val; + } + + /* PrintPairs(ctrl, npes-1, mypicks, "Mypicks"); */ + + /* Gather the picks to all the processors */ + MPI_Allgather((void *)mypicks, 2*(npes-1), IDX_DATATYPE, (void *)allpicks, 2*(npes-1), IDX_DATATYPE, ctrl->comm); + + /* PrintPairs(ctrl, npes*(npes-1), allpicks, "Allpicks"); */ + + /* Sort all the picks */ + ikeyvalsort(npes*(npes-1), allpicks); + + /* PrintPairs(ctrl, npes*(npes-1), allpicks, "Allpicks"); */ + + /* Select the final splitters. Set the boundaries to simplify coding */ + for (i=1; i<npes; i++) + mypicks[i] = allpicks[i*(npes-1)]; + mypicks[0].key = MIN_INT; + mypicks[npes].key = MAX_INT; + + /* PrintPairs(ctrl, npes+1, mypicks, "Mypicks"); */ + + /* Compute the number of elements that belong to each bucket */ + idxset(npes, 0, scounts); + for (j=i=0; i<nvtxs; i++) { + if (elmnts[i].key < mypicks[j+1].key || (elmnts[i].key == mypicks[j+1].key && elmnts[i].val < mypicks[j+1].val)) + scounts[j]++; + else + scounts[++j]++; + } + MPI_Alltoall(scounts, 1, IDX_DATATYPE, rcounts, 1, IDX_DATATYPE, ctrl->comm); + +/* + PrintVector(ctrl, npes, 0, scounts, "Scounts"); + PrintVector(ctrl, npes, 0, rcounts, "Rcounts"); +*/ + + /* Allocate memory for sorted elements and receive them */ + MAKECSR(i, npes, scounts); + MAKECSR(i, npes, rcounts); + nrecv = rcounts[npes]; + if (wspace->nlarge >= nrecv) + relmnts = (KeyValueType *)wspace->pairs; + else + relmnts = (KeyValueType *)GKmalloc(sizeof(KeyValueType)*nrecv, "ParSort: relmnts"); + + /* Issue the receives first */ + for (i=0; i<npes; i++) + MPI_Irecv((void *)(relmnts+rcounts[i]), 2*(rcounts[i+1]-rcounts[i]), IDX_DATATYPE, i, 1, ctrl->comm, ctrl->rreq+i); + + /* Issue the sends next */ + for (i=0; i<npes; i++) + MPI_Isend((void *)(elmnts+scounts[i]), 2*(scounts[i+1]-scounts[i]), IDX_DATATYPE, i, 1, ctrl->comm, ctrl->sreq+i); + + MPI_Waitall(npes, ctrl->rreq, ctrl->statuses); + MPI_Waitall(npes, ctrl->sreq, ctrl->statuses); + + + /* OK, now do the local sort of the relmnts. Use perm to keep track original order */ + perm = idxmalloc(nrecv, "ParSort: perm"); + for (i=0; i<nrecv; i++) { + perm[i] = relmnts[i].val; + relmnts[i].val = i; + } + ikeysort(nrecv, relmnts); + + + /* Compute what needs to be shifted */ + MPI_Scan((void *)(&nrecv), (void *)(&lastvtx), 1, MPI_INT, MPI_SUM, ctrl->comm); + firstvtx = lastvtx-nrecv; + + /*myprintf(ctrl, "first, last: %d %d\n", firstvtx, lastvtx); */ + + for (j=0, i=0; i<npes; i++) { + if (vtxdist[i+1] > firstvtx) { /* Found the first PE that is passed me */ + if (vtxdist[i+1] >= lastvtx) { + /* myprintf(ctrl, "Shifting %d elements to processor %d\n", lastvtx-firstvtx, i); */ + for (k=0; k<lastvtx-firstvtx; k++, j++) + relmnts[relmnts[j].val].key = i; + } + else { + /* myprintf(ctrl, "Shifting %d elements to processor %d\n", vtxdist[i+1]-firstvtx, i); */ + for (k=0; k<vtxdist[i+1]-firstvtx; k++, j++) + relmnts[relmnts[j].val].key = i; + + firstvtx = vtxdist[i+1]; + } + } + if (vtxdist[i+1] >= lastvtx) + break; + } + + /* Reverse the ordering on the relmnts[].val */ + for (i=0; i<nrecv; i++) { + ASSERTP(ctrl, relmnts[i].key>=0 && relmnts[i].key<npes, (ctrl, "%d %d\n", i, relmnts[i].key)); + relmnts[i].val = perm[i]; + } + + /* OK, now sent it back */ + /* Issue the receives first */ + for (i=0; i<npes; i++) + MPI_Irecv((void *)(elmnts+scounts[i]), 2*(scounts[i+1]-scounts[i]), IDX_DATATYPE, i, 1, ctrl->comm, ctrl->rreq+i); + + /* Issue the sends next */ + for (i=0; i<npes; i++) + MPI_Isend((void *)(relmnts+rcounts[i]), 2*(rcounts[i+1]-rcounts[i]), IDX_DATATYPE, i, 1, ctrl->comm, ctrl->sreq+i); + + MPI_Waitall(npes, ctrl->rreq, ctrl->statuses); + MPI_Waitall(npes, ctrl->sreq, ctrl->statuses); + + + /* Construct a partition for the graph */ + graph->where = idxmalloc(graph->nvtxs+graph->nrecv, "PartSort: graph->where"); + firstvtx = vtxdist[mype]; + for (i=0; i<nvtxs; i++) { + ASSERTP(ctrl, elmnts[i].key>=0 && elmnts[i].key<npes, (ctrl, "%d %d\n", i, elmnts[i].key)); + ASSERTP(ctrl, elmnts[i].val>=vtxdist[mype] && elmnts[i].val<vtxdist[mype+1], (ctrl, "%d %d %d %d\n", i, vtxdist[mype], vtxdist[mype+1], elmnts[i].val)); + graph->where[elmnts[i].val-firstvtx] = elmnts[i].key; + } + + + GKfree((void **)&mypicks, (void **)&allpicks, (void **)&perm, LTERM); + if (wspace->nlarge < nrecv) + free(relmnts); + +} + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/Makefile b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/Makefile new file mode 100644 index 0000000..0254eec --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/Makefile @@ -0,0 +1,56 @@ +include ../Makefile.in + +BINDIR = ../Graphs + +INCLUDES = -I./ -I../ParMETISLib $(INCDIR) +CFLAGS = $(COPTIONS) $(OPTFLAGS) $(INCLUDES) + + +LIBSDIR = -L.. $(LIBDIR) +LIBS = -lparmetis -lmetis $(XTRALIBS) -lm +PARMETISLIB = ../libparmetis.a ../libmetis.a + + +PTESTOBJS = ptest.o io.o adaptgraph.o +MESHTESTOBJS = mtest.o io.o +PARMETISOBJS = parmetis.o io.o adaptgraph.o + + +.c.o: + $(CC) $(CFLAGS) -c $*.c + + +default: $(BINDIR)/ptest$(VERNUM) $(BINDIR)/mtest$(VERNUM) + +$(BINDIR)/mtest$(VERNUM): $(MESHTESTOBJS) $(PARMETISLIB) + $(LD) -o $@ $(MESHTESTOBJS) $(LIBSDIR) $(LIBS) + chmod 744 $@ + +$(BINDIR)/ptest$(VERNUM): $(PTESTOBJS) $(PARMETISLIB) + $(LD) -o $@ $(PTESTOBJS) $(LIBSDIR) $(LIBS) + chmod 744 $@ + +clean: + rm -f *.o ;\ + rm -f $(BINDIR)/ptest$(VERNUM) + rm -f $(BINDIR)/mtest$(VERNUM) + +realclean: + rm -f *.o ;\ + rm -f $(BINDIR)/ptest$(VERNUM) + rm -f $(BINDIR)/mtest$(VERNUM) + + +checkin: + @for file in *.[c,h]; \ + do \ + ci -u -m'Maintance' $$file;\ + done + +checkin2: + @for file in *.[c,h]; \ + do \ + ci $$file;\ + rcs -U $$file;\ + co $$file;\ + done diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/adaptgraph.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/adaptgraph.c new file mode 100644 index 0000000..50de22e --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/adaptgraph.c @@ -0,0 +1,171 @@ +/* + * Copyright 1998, Regents of the University of Minnesota + * + * tstadpt.c + * + * This file contains code for testing teh adaptive partitioning routines + * + * Started 5/19/97 + * George + * + * $Id: adaptgraph.c,v 1.2 2003/07/21 17:50:22 karypis Exp $ + * + */ + +#include <parmetisbin.h> + + +/************************************************************************* +* This function implements a simple graph adaption strategy. +**************************************************************************/ +void AdaptGraph(GraphType *graph, int afactor, MPI_Comm comm) +{ + int i, nvtxs, nadapt, firstvtx, lastvtx; + int npes, mype, mypwgt, max, min, sum; + idxtype *vwgt, *xadj, *adjncy, *adjwgt, *perm; + + MPI_Comm_size(comm, &npes); + MPI_Comm_rank(comm, &mype); + + srand(mype*afactor); + srand48(mype*afactor); + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + if (graph->adjwgt == NULL) + adjwgt = graph->adjwgt = idxsmalloc(graph->nedges, 1, "AdaptGraph: adjwgt"); + else + adjwgt = graph->adjwgt; + vwgt = graph->vwgt; + + firstvtx = graph->vtxdist[mype]; + lastvtx = graph->vtxdist[mype+1]; + + perm = idxmalloc(nvtxs, "AdaptGraph: perm"); + FastRandomPermute(nvtxs, perm, 1); + + nadapt = RandomInRange(nvtxs); + nadapt = RandomInRange(nvtxs); + nadapt = RandomInRange(nvtxs); + + for (i=0; i<nadapt; i++) + vwgt[perm[i]] = afactor*vwgt[perm[i]]; + +/* + for (i=0; i<nvtxs; i++) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (k >= firstvtx && k < lastvtx) { + adjwgt[j] = (int)pow(1.0*(amin(vwgt[i],vwgt[k-firstvtx])), .6667); + if (adjwgt[j] == 0) + adjwgt[j] = 1; + } + } + } +*/ + + mypwgt = idxsum(nvtxs, vwgt); + + MPI_Allreduce((void *)&mypwgt, (void *)&max, 1, MPI_INT, MPI_MAX, comm); + MPI_Allreduce((void *)&mypwgt, (void *)&min, 1, MPI_INT, MPI_MIN, comm); + MPI_Allreduce((void *)&mypwgt, (void *)&sum, 1, MPI_INT, MPI_SUM, comm); + + if (mype == 0) + printf("Initial Load Imbalance: %5.4f, [%5d %5d %5d] for afactor: %d\n", (1.0*max*npes)/(1.0*sum), min, max, sum, afactor); + + free(perm); +} + + +/************************************************************************* +* This function implements a simple graph adaption strategy. +**************************************************************************/ +void AdaptGraph2(GraphType *graph, int afactor, MPI_Comm comm) +{ + int i, j, k, nvtxs, firstvtx, lastvtx; + int npes, mype, mypwgt, max, min, sum; + idxtype *vwgt, *xadj, *adjncy, *adjwgt; + + MPI_Comm_size(comm, &npes); + MPI_Comm_rank(comm, &mype); + + srand(mype*afactor); + srand48(mype*afactor); + + nvtxs = graph->nvtxs; + xadj = graph->xadj; + adjncy = graph->adjncy; + if (graph->adjwgt == NULL) + adjwgt = graph->adjwgt = idxsmalloc(graph->nedges, 1, "AdaptGraph: adjwgt"); + else + adjwgt = graph->adjwgt; + vwgt = graph->vwgt; + + firstvtx = graph->vtxdist[mype]; + lastvtx = graph->vtxdist[mype+1]; + + +/* if (RandomInRange(npes+1) < .05*npes) { */ + if (RandomInRange(npes+1) < 2) { + printf("[%d] is adapting\n", mype); + for (i=0; i<nvtxs; i++) + vwgt[i] = afactor*vwgt[i]; + } + + for (i=0; i<nvtxs; i++) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + k = adjncy[j]; + if (k >= firstvtx && k < lastvtx) { + adjwgt[j] = (int)pow(1.0*(amin(vwgt[i],vwgt[k-firstvtx])), .6667); + if (adjwgt[j] == 0) + adjwgt[j] = 1; + } + } + } + + mypwgt = idxsum(nvtxs, vwgt); + + MPI_Allreduce((void *)&mypwgt, (void *)&max, 1, MPI_INT, MPI_MAX, comm); + MPI_Allreduce((void *)&mypwgt, (void *)&min, 1, MPI_INT, MPI_MIN, comm); + MPI_Allreduce((void *)&mypwgt, (void *)&sum, 1, MPI_INT, MPI_SUM, comm); + + if (mype == 0) + printf("Initial Load Imbalance: %5.4f, [%5d %5d %5d]\n", (1.0*max*npes)/(1.0*sum), min, max, sum); + +} + + +/************************************************************************* +* This function implements a simple graph adaption strategy. +**************************************************************************/ +void Mc_AdaptGraph(GraphType *graph, idxtype *part, int ncon, int nparts, MPI_Comm comm) +{ + int h, i; + int nvtxs; + int npes, mype; + idxtype *vwgt, *pwgts; + MPI_Comm_size(comm, &npes); + MPI_Comm_rank(comm, &mype); + + nvtxs = graph->nvtxs; + vwgt = graph->vwgt; + pwgts = idxsmalloc(nparts*ncon, 1, "pwgts"); + + if (mype == 0) { + for (i=0; i<nparts; i++) + for (h=0; h<ncon; h++) + pwgts[i*ncon+h] = RandomInRange(20)+1; + } + + MPI_Bcast((void *)pwgts, nparts*ncon, IDX_DATATYPE, 0, comm); + + for (i=0; i<nvtxs; i++) + for (h=0; h<ncon; h++) + vwgt[i*ncon+h] = pwgts[part[i]*ncon+h]; + + free(pwgts); + return; +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/io.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/io.c new file mode 100644 index 0000000..2f1822f --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/io.c @@ -0,0 +1,951 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * pio.c + * + * This file contains routines related to I/O + * + * Started 10/19/94 + * George + * + * $Id: io.c,v 1.1 2003/07/22 21:47:18 karypis Exp $ + * + */ + +#include <parmetisbin.h> +#define MAXLINE 8192 + +/************************************************************************* +* This function reads the CSR matrix +**************************************************************************/ +void ParallelReadGraph(GraphType *graph, char *filename, MPI_Comm comm) +{ + int i, k, l, pe; + int npes, mype, ier; + int gnvtxs, nvtxs, your_nvtxs, your_nedges, gnedges; + int maxnvtxs = -1, maxnedges = -1; + int readew = -1, readvw = -1, dummy, edge; + idxtype *vtxdist, *xadj, *adjncy, *vwgt, *adjwgt; + idxtype *your_xadj, *your_adjncy, *your_vwgt, *your_adjwgt, graphinfo[4]; + int fmt, ncon, nobj; + MPI_Status stat; + char *line = NULL, *oldstr, *newstr; + FILE *fpin = NULL; + + MPI_Comm_size(comm, &npes); + MPI_Comm_rank(comm, &mype); + + vtxdist = graph->vtxdist = idxsmalloc(npes+1, 0, "ReadGraph: vtxdist"); + + if (mype == npes-1) { + ier = 0; + fpin = fopen(filename, "r"); + + if (fpin == NULL){ + printf("COULD NOT OPEN FILE '%s' FOR SOME REASON!\n", filename); + ier++; + } + + MPI_Bcast(&ier, 1, MPI_INT, npes-1, comm); + if (ier > 0){ + MPI_Finalize(); + exit(0); + } + + line = (char *)GKmalloc(sizeof(char)*(MAXLINE+1), "line"); + + do { + fgets(line, MAXLINE, fpin); + } while (line[0] == '%' && !feof(fpin)); + + fmt = ncon = nobj = 0; + sscanf(line, "%d %d %d %d %d", &gnvtxs, &gnedges, &fmt, &ncon, &nobj); + gnedges *=2; + readew = (fmt%10 > 0); + readvw = ((fmt/10)%10 > 0); + graph->ncon = ncon = (ncon == 0 ? 1 : ncon); + graph->nobj = nobj = (nobj == 0 ? 1 : nobj); + +/* printf("Nvtxs: %d, Nedges: %d, Ncon: %d\n", gnvtxs, gnedges, ncon); */ + + graphinfo[0] = ncon; + graphinfo[1] = nobj; + graphinfo[2] = readvw; + graphinfo[3] = readew; + MPI_Bcast((void *)graphinfo, 4, IDX_DATATYPE, npes-1, comm); + + /* Construct vtxdist and send it to all the processors */ + vtxdist[0] = 0; + for (i=0,k=gnvtxs; i<npes; i++) { + l = k/(npes-i); + vtxdist[i+1] = vtxdist[i]+l; + k -= l; + } + + MPI_Bcast((void *)vtxdist, npes+1, IDX_DATATYPE, npes-1, comm); + } + else { + MPI_Bcast(&ier, 1, MPI_INT, npes-1, comm); + if (ier > 0){ + MPI_Finalize(); + exit(0); + } + + MPI_Bcast((void *)graphinfo, 4, IDX_DATATYPE, npes-1, comm); + graph->ncon = ncon = graphinfo[0]; + graph->nobj = nobj = graphinfo[1]; + readvw = graphinfo[2]; + readew = graphinfo[3]; + + MPI_Bcast((void *)vtxdist, npes+1, IDX_DATATYPE, npes-1, comm); + } + + if ((ncon > 1 && !readvw) || (nobj > 1 && !readew)) { + printf("fmt and ncon/nobj are inconsistant. Exiting...\n"); + MPI_Finalize(); + exit(-1); + } + + graph->gnvtxs = vtxdist[npes]; + nvtxs = graph->nvtxs = vtxdist[mype+1]-vtxdist[mype]; + xadj = graph->xadj = idxmalloc(graph->nvtxs+1, "ParallelReadGraph: xadj"); + vwgt = graph->vwgt = idxmalloc(graph->nvtxs*ncon, "ParallelReadGraph: vwgt"); + /*******************************************/ + /* Go through first time and generate xadj */ + /*******************************************/ + if (mype == npes-1) { + maxnvtxs = 0; + for (i=0; i<npes; i++) { + maxnvtxs = (maxnvtxs < vtxdist[i+1]-vtxdist[i]) ? + vtxdist[i+1]-vtxdist[i] : maxnvtxs; + } + + your_xadj = idxmalloc(maxnvtxs+1, "your_xadj"); + your_vwgt = idxmalloc(maxnvtxs*ncon, "your_vwgt"); + + maxnedges = 0; + for (pe=0; pe<npes; pe++) { + idxset(maxnvtxs*ncon, 1, your_vwgt); + your_nvtxs = vtxdist[pe+1]-vtxdist[pe]; + for (i=0; i<your_nvtxs; i++) { + your_nedges = 0; + + do { + fgets(line, MAXLINE, fpin); + } while (line[0] == '%' && !feof(fpin)); + + oldstr = line; + newstr = NULL; + + if (readvw) { + for (l=0; l<ncon; l++) { + your_vwgt[i*ncon+l] = (int)strtol(oldstr, &newstr, 10); + oldstr = newstr; + } + } + + for (;;) { + edge = (int)strtol(oldstr, &newstr, 10) -1; + oldstr = newstr; + + if (edge < 0) + break; + + if (readew) { + for (l=0; l<nobj; l++) { + dummy = (int)strtol(oldstr, &newstr, 10); + oldstr = newstr; + } + } + your_nedges++; + } + your_xadj[i] = your_nedges; + } + + MAKECSR(i, your_nvtxs, your_xadj); + maxnedges = (maxnedges < your_xadj[your_nvtxs]) ? + your_xadj[your_nvtxs] : maxnedges; + + if (pe < npes-1) { + MPI_Send((void *)your_xadj, your_nvtxs+1, IDX_DATATYPE, pe, 0, comm); + MPI_Send((void *)your_vwgt, your_nvtxs*ncon, IDX_DATATYPE, pe, 1, comm); + } + else { + for (i=0; i<your_nvtxs+1; i++) + xadj[i] = your_xadj[i]; + for (i=0; i<your_nvtxs*ncon; i++) + vwgt[i] = your_vwgt[i]; + } + } + fclose(fpin); + GKfree(&your_xadj, &your_vwgt, LTERM); + } + else { + MPI_Recv((void *)xadj, nvtxs+1, IDX_DATATYPE, npes-1, 0, comm, &stat); + MPI_Recv((void *)vwgt, nvtxs*ncon, IDX_DATATYPE, npes-1, 1, comm, &stat); + } + + graph->nedges = xadj[nvtxs]; + adjncy = graph->adjncy = idxmalloc(xadj[nvtxs], "ParallelReadGraph: adjncy"); + adjwgt = graph->adjwgt = idxmalloc(xadj[nvtxs]*nobj, "ParallelReadGraph: adjwgt"); + /***********************************************/ + /* Now go through again and record adjncy data */ + /***********************************************/ + if (mype == npes-1) { + ier = 0; + fpin = fopen(filename, "r"); + + if (fpin == NULL){ + printf("COULD NOT OPEN FILE '%s' FOR SOME REASON!\n", filename); + ier++; + } + + MPI_Bcast(&ier, 1, MPI_INT, npes-1, comm); + if (ier > 0){ + MPI_Finalize(); + exit(0); + } + + /* get first line again */ + do { + fgets(line, MAXLINE, fpin); + } while (line[0] == '%' && !feof(fpin)); + + your_adjncy = idxmalloc(maxnedges, "your_adjncy"); + your_adjwgt = idxmalloc(maxnedges*nobj, "your_adjwgt"); + + for (pe=0; pe<npes; pe++) { + your_nedges = 0; + idxset(maxnedges*nobj, 1, your_adjwgt); + your_nvtxs = vtxdist[pe+1]-vtxdist[pe]; + for (i=0; i<your_nvtxs; i++) { + do { + fgets(line, MAXLINE, fpin); + } while (line[0] == '%' && !feof(fpin)); + + oldstr = line; + newstr = NULL; + + if (readvw) { + for (l=0; l<ncon; l++) { + dummy = (int)strtol(oldstr, &newstr, 10); + oldstr = newstr; + } + } + + for (;;) { + edge = (int)strtol(oldstr, &newstr, 10) -1; + oldstr = newstr; + + if (edge < 0) + break; + + your_adjncy[your_nedges] = edge; + if (readew) { + for (l=0; l<nobj; l++) { + your_adjwgt[your_nedges*nobj+l] = (int)strtol(oldstr, &newstr, 10); + oldstr = newstr; + } + } + your_nedges++; + + } + } + if (pe < npes-1) { + MPI_Send((void *)your_adjncy, your_nedges, IDX_DATATYPE, pe, 0, comm); + MPI_Send((void *)your_adjwgt, your_nedges*nobj, IDX_DATATYPE, pe, 1, comm); + } + else { + for (i=0; i<your_nedges; i++) + adjncy[i] = your_adjncy[i]; + for (i=0; i<your_nedges*nobj; i++) + adjwgt[i] = your_adjwgt[i]; + } + } + fclose(fpin); + GKfree(&your_adjncy, &your_adjwgt, &line, LTERM); + } + else { + MPI_Bcast(&ier, 1, MPI_INT, npes-1, comm); + if (ier > 0){ + MPI_Finalize(); + exit(0); + } + + MPI_Recv((void *)adjncy, xadj[nvtxs], IDX_DATATYPE, npes-1, 0, comm, &stat); + MPI_Recv((void *)adjwgt, xadj[nvtxs]*nobj, IDX_DATATYPE, npes-1, 1, comm, &stat); + } + +} + + + +/************************************************************************* +* This function writes a distributed graph to file +**************************************************************************/ +void Moc_ParallelWriteGraph(CtrlType *ctrl, GraphType *graph, char *filename, + int nparts, int testset) +{ + int h, i, j; + int npes, mype, penum, gnedges; + char partfile[256]; + FILE *fpin; + MPI_Comm comm; + + comm = ctrl->comm; + MPI_Comm_size(comm, &npes); + MPI_Comm_rank(comm, &mype); + + gnedges = GlobalSESum(ctrl, graph->nedges); + sprintf(partfile, "%s.%d.%d.%d", filename, testset, graph->ncon, nparts); + + if (mype == 0) { + if ((fpin = fopen(partfile, "w")) == NULL) + errexit("Failed to open file %s", partfile); + + fprintf(fpin, "%d %d %d %d %d\n", graph->gnvtxs, gnedges/2, 11, graph->ncon, 1); + fclose(fpin); + } + + MPI_Barrier(comm); + for (penum=0; penum<npes; penum++) { + if (mype == penum) { + + if ((fpin = fopen(partfile, "a")) == NULL) + errexit("Failed to open file %s", partfile); + + for (i=0; i<graph->nvtxs; i++) { + for (h=0; h<graph->ncon; h++) + fprintf(fpin, "%d ", graph->vwgt[i*graph->ncon+h]); + + for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++) { + fprintf(fpin, "%d ", graph->adjncy[j]+1); + fprintf(fpin, "%d ", graph->adjwgt[j]); + } + fprintf(fpin, "\n"); + } + fclose(fpin); + } + MPI_Barrier(comm); + } + + return; +} + + +/************************************************************************* +* This function reads the CSR matrix +**************************************************************************/ +void ReadTestGraph(GraphType *graph, char *filename, MPI_Comm comm) +{ + int i, k, l, npes, mype; + int nvtxs, penum, snvtxs; + idxtype *gxadj, *gadjncy; + idxtype *vtxdist, *sxadj, *ssize = NULL; + MPI_Status status; + + MPI_Comm_size(comm, &npes); + MPI_Comm_rank(comm, &mype); + + vtxdist = graph->vtxdist = idxsmalloc(npes+1, 0, "ReadGraph: vtxdist"); + + if (mype == 0) { + ssize = idxsmalloc(npes, 0, "ReadGraph: ssize"); + + ReadMetisGraph(filename, &nvtxs, &gxadj, &gadjncy); + + printf("Nvtxs: %d, Nedges: %d\n", nvtxs, gxadj[nvtxs]); + + /* Construct vtxdist and send it to all the processors */ + vtxdist[0] = 0; + for (i=0,k=nvtxs; i<npes; i++) { + l = k/(npes-i); + vtxdist[i+1] = vtxdist[i]+l; + k -= l; + } + } + + MPI_Bcast((void *)vtxdist, npes+1, IDX_DATATYPE, 0, comm); + + graph->gnvtxs = vtxdist[npes]; + graph->nvtxs = vtxdist[mype+1]-vtxdist[mype]; + graph->xadj = idxmalloc(graph->nvtxs+1, "ReadGraph: xadj"); + + if (mype == 0) { + for (penum=0; penum<npes; penum++) { + snvtxs = vtxdist[penum+1]-vtxdist[penum]; + sxadj = idxmalloc(snvtxs+1, "ReadGraph: sxadj"); + + idxcopy(snvtxs+1, gxadj+vtxdist[penum], sxadj); + for (i=snvtxs; i>=0; i--) + sxadj[i] -= sxadj[0]; + + ssize[penum] = gxadj[vtxdist[penum+1]] - gxadj[vtxdist[penum]]; + + if (penum == mype) + idxcopy(snvtxs+1, sxadj, graph->xadj); + else + MPI_Send((void *)sxadj, snvtxs+1, IDX_DATATYPE, penum, 1, comm); + + free(sxadj); + } + } + else + MPI_Recv((void *)graph->xadj, graph->nvtxs+1, IDX_DATATYPE, 0, 1, comm, &status); + + + graph->nedges = graph->xadj[graph->nvtxs]; + graph->adjncy = idxmalloc(graph->nedges, "ReadGraph: graph->adjncy"); + + if (mype == 0) { + for (penum=0; penum<npes; penum++) { + if (penum == mype) + idxcopy(ssize[penum], gadjncy+gxadj[vtxdist[penum]], graph->adjncy); + else + MPI_Send((void *)(gadjncy+gxadj[vtxdist[penum]]), ssize[penum], IDX_DATATYPE, penum, 1, comm); + } + + free(ssize); + } + else + MPI_Recv((void *)graph->adjncy, graph->nedges, IDX_DATATYPE, 0, 1, comm, &status); + + graph->vwgt = NULL; + graph->adjwgt = NULL; + + if (mype == 0) + GKfree(&gxadj, &gadjncy, LTERM); + + MALLOC_CHECK(NULL); +} + + + +/************************************************************************* +* This function reads the CSR matrix +**************************************************************************/ +float *ReadTestCoordinates(GraphType *graph, char *filename, int ndims, MPI_Comm comm) +{ + int i, j, k, npes, mype, penum; + float *xyz, *txyz; + FILE *fpin; + idxtype *vtxdist; + MPI_Status status; + char xyzfile[256]; + + MPI_Comm_size(comm, &npes); + MPI_Comm_rank(comm, &mype); + + vtxdist = graph->vtxdist; + + xyz = fmalloc(graph->nvtxs*ndims, "io"); + + if (mype == 0) { + sprintf(xyzfile, "%s.xyz", filename); + if ((fpin = fopen(xyzfile, "r")) == NULL) + errexit("Failed to open file %s\n", xyzfile); + } + + if (mype == 0) { + txyz = fmalloc(2*graph->nvtxs*ndims, "io"); + + for (penum=0; penum<npes; penum++) { + for (k=0, i=vtxdist[penum]; i<vtxdist[penum+1]; i++, k++) { + for (j=0; j<ndims; j++) + fscanf(fpin, "%e ", txyz+k*ndims+j); + } + + if (penum == mype) + memcpy((void *)xyz, (void *)txyz, sizeof(float)*ndims*k); + else { + MPI_Send((void *)txyz, ndims*k, MPI_FLOAT, penum, 1, comm); + } + } + free(txyz); + fclose(fpin); + } + else + MPI_Recv((void *)xyz, ndims*graph->nvtxs, MPI_FLOAT, 0, 1, comm, &status); + + return xyz; +} + + + +/************************************************************************* +* This function reads the spd matrix +**************************************************************************/ +void ReadMetisGraph(char *filename, int *r_nvtxs, idxtype **r_xadj, idxtype **r_adjncy) +{ + int i, k, edge, nvtxs, nedges; + idxtype *xadj, *adjncy; + char *line, *oldstr, *newstr; + FILE *fpin; + + line = (char *)malloc(sizeof(char)*(8192+1)); + + if ((fpin = fopen(filename, "r")) == NULL) { + printf("Failed to open file %s\n", filename); + exit(0); + } + + fgets(line, 8192, fpin); + sscanf(line, "%d %d", &nvtxs, &nedges); + nedges *=2; + + xadj = idxmalloc(nvtxs+1, "ReadGraph: xadj"); + adjncy = idxmalloc(nedges, "ReadGraph: adjncy"); + + /* Start reading the graph file */ + for (xadj[0]=0, k=0, i=0; i<nvtxs; i++) { + fgets(line, 8192, fpin); + oldstr = line; + newstr = NULL; + + for (;;) { + edge = (int)strtol(oldstr, &newstr, 10) -1; + oldstr = newstr; + + if (edge < 0) + break; + + adjncy[k++] = edge; + } + xadj[i+1] = k; + } + + fclose(fpin); + + free(line); + + *r_nvtxs = nvtxs; + *r_xadj = xadj; + *r_adjncy = adjncy; +} + + +/************************************************************************* +* This function reads the CSR matrix +**************************************************************************/ +void Moc_SerialReadGraph(GraphType *graph, char *filename, int *wgtflag, MPI_Comm comm) +{ + int i, k, l, npes, mype; + int nvtxs, ncon, nobj, fmt; + int penum, snvtxs; + idxtype *gxadj, *gadjncy, *gvwgt, *gadjwgt; + idxtype *vtxdist, *sxadj, *ssize = NULL; + MPI_Status status; + + MPI_Comm_size(comm, &npes); + MPI_Comm_rank(comm, &mype); + + vtxdist = graph->vtxdist = idxsmalloc(npes+1, 0, "ReadGraph: vtxdist"); + + if (mype == 0) { + ssize = idxsmalloc(npes, 0, "ReadGraph: ssize"); + + Moc_SerialReadMetisGraph(filename, &nvtxs, &ncon, &nobj, &fmt, &gxadj, &gvwgt, + &gadjncy, &gadjwgt, wgtflag); + + printf("Nvtxs: %d, Nedges: %d\n", nvtxs, gxadj[nvtxs]); + + /* Construct vtxdist and send it to all the processors */ + vtxdist[0] = 0; + for (i=0,k=nvtxs; i<npes; i++) { + l = k/(npes-i); + vtxdist[i+1] = vtxdist[i]+l; + k -= l; + } + } + + MPI_Bcast((void *)(&fmt), 1, MPI_INT, 0, comm); + MPI_Bcast((void *)(&ncon), 1, MPI_INT, 0, comm); + MPI_Bcast((void *)(&nobj), 1, MPI_INT, 0, comm); + MPI_Bcast((void *)(wgtflag), 1, MPI_INT, 0, comm); + MPI_Bcast((void *)vtxdist, npes+1, IDX_DATATYPE, 0, comm); + + graph->gnvtxs = vtxdist[npes]; + graph->nvtxs = vtxdist[mype+1]-vtxdist[mype]; + graph->ncon = ncon; + graph->xadj = idxmalloc(graph->nvtxs+1, "ReadGraph: xadj"); + /*************************************************/ + /* distribute xadj array */ + if (mype == 0) { + for (penum=0; penum<npes; penum++) { + snvtxs = vtxdist[penum+1]-vtxdist[penum]; + sxadj = idxmalloc(snvtxs+1, "ReadGraph: sxadj"); + + idxcopy(snvtxs+1, gxadj+vtxdist[penum], sxadj); + for (i=snvtxs; i>=0; i--) + sxadj[i] -= sxadj[0]; + + ssize[penum] = gxadj[vtxdist[penum+1]] - gxadj[vtxdist[penum]]; + + if (penum == mype) + idxcopy(snvtxs+1, sxadj, graph->xadj); + else + MPI_Send((void *)sxadj, snvtxs+1, IDX_DATATYPE, penum, 1, comm); + + free(sxadj); + } + } + else + MPI_Recv((void *)graph->xadj, graph->nvtxs+1, IDX_DATATYPE, 0, 1, comm, + &status); + + + + graph->nedges = graph->xadj[graph->nvtxs]; + graph->adjncy = idxmalloc(graph->nedges, "ReadGraph: graph->adjncy"); + /*************************************************/ + /* distribute adjncy array */ + if (mype == 0) { + for (penum=0; penum<npes; penum++) { + if (penum == mype) + idxcopy(ssize[penum], gadjncy+gxadj[vtxdist[penum]], graph->adjncy); + else + MPI_Send((void *)(gadjncy+gxadj[vtxdist[penum]]), ssize[penum], + IDX_DATATYPE, penum, 1, comm); + } + + } + else + MPI_Recv((void *)graph->adjncy, graph->nedges, IDX_DATATYPE, 0, 1, comm, + &status); + + + graph->adjwgt = idxmalloc(graph->nedges*nobj, "ReadGraph: graph->adjwgt"); + if (fmt%10 > 0) { + /*************************************************/ + /* distribute adjwgt array */ + if (mype == 0) { + for (penum=0; penum<npes; penum++) { + ssize[penum] *= nobj; + if (penum == mype) + idxcopy(ssize[penum], gadjwgt+(gxadj[vtxdist[penum]]*nobj), graph->adjwgt); + else + MPI_Send((void *)(gadjwgt+(gxadj[vtxdist[penum]]*nobj)), ssize[penum], + IDX_DATATYPE, penum, 1, comm); + } + + } + else + MPI_Recv((void *)graph->adjwgt, graph->nedges*nobj, IDX_DATATYPE, 0, 1, + comm, &status); + + } + else { + for (i=0; i<graph->nedges*nobj; i++) + graph->adjwgt[i] = 1; + } + + graph->vwgt = idxmalloc(graph->nvtxs*ncon, "ReadGraph: graph->vwgt"); + if ((fmt/10)%10 > 0) { + /*************************************************/ + /* distribute vwgt array */ + + if (mype == 0) { + for (penum=0; penum<npes; penum++) { + ssize[penum] = (vtxdist[penum+1]-vtxdist[penum])*ncon; + + if (penum == mype) + idxcopy(ssize[penum], gvwgt+(vtxdist[penum]*ncon), graph->vwgt); + else + MPI_Send((void *)(gvwgt+(vtxdist[penum]*ncon)), ssize[penum], + IDX_DATATYPE, penum, 1, comm); + } + + free(ssize); + } + else + MPI_Recv((void *)graph->vwgt, graph->nvtxs*ncon, IDX_DATATYPE, 0, 1, + comm, &status); + + } + else { + for (i=0; i<graph->nvtxs*ncon; i++) + graph->vwgt[i] = 1; + } + + if (mype == 0) + GKfree((void *)&gxadj, (void *)&gadjncy, (void *)&gvwgt, (void *)&gadjwgt, LTERM); + + MALLOC_CHECK(NULL); +} + + + +/************************************************************************* +* This function reads the spd matrix +**************************************************************************/ +void Moc_SerialReadMetisGraph(char *filename, int *r_nvtxs, int *r_ncon, int *r_nobj, + int *r_fmt, idxtype **r_xadj, idxtype **r_vwgt, idxtype **r_adjncy, + idxtype **r_adjwgt, int *wgtflag) +{ + int i, k, l; + int ncon, nobj, edge, nvtxs, nedges; + idxtype *xadj, *adjncy, *vwgt, *adjwgt; + char *line, *oldstr, *newstr; + int fmt, readew, readvw; + int ewgt[MAXNOBJ]; + FILE *fpin; + + line = (char *)GKmalloc(sizeof(char)*(8192+1), "line"); + + if ((fpin = fopen(filename, "r")) == NULL) { + printf("Failed to open file %s\n", filename); + exit(-1); + } + + fgets(line, 8192, fpin); + fmt = ncon = nobj = 0; + sscanf(line, "%d %d %d %d %d", &nvtxs, &nedges, &fmt, &ncon, &nobj); + readew = (fmt%10 > 0); + readvw = ((fmt/10)%10 > 0); + + *wgtflag = 0; + if (readew) + *wgtflag += 1; + if (readvw) + *wgtflag += 2; + + if ((ncon > 0 && !readvw) || (nobj > 0 && !readew)) { + printf("fmt and ncon/nobj are inconsistant.\n"); + exit(-1); + } + + nedges *=2; + ncon = (ncon == 0 ? 1 : ncon); + nobj = (nobj == 0 ? 1 : nobj); + + xadj = idxmalloc(nvtxs+1, "ReadGraph: xadj"); + adjncy = idxmalloc(nedges, "Moc_ReadGraph: adjncy"); + vwgt = (readvw ? idxmalloc(ncon*nvtxs, "RG: vwgt") : NULL); + adjwgt = (readew ? idxmalloc(nobj*nedges, "RG: adjwgt") : NULL); + + /* Start reading the graph file */ + for (xadj[0]=0, k=0, i=0; i<nvtxs; i++) { + do { + fgets(line, 8192, fpin); + } while (line[0] == '%' && !feof(fpin)); + oldstr = line; + newstr = NULL; + + if (readvw) { + for (l=0; l<ncon; l++) { + vwgt[i*ncon+l] = (int)strtol(oldstr, &newstr, 10); + oldstr = newstr; + } + } + + for (;;) { + edge = (int)strtol(oldstr, &newstr, 10) -1; + oldstr = newstr; + + if (readew) { + for (l=0; l<nobj; l++) { + ewgt[l] = (float)strtod(oldstr, &newstr); + oldstr = newstr; + } + } + + if (edge < 0) + break; + + adjncy[k] = edge; + if (readew) + for (l=0; l<nobj; l++) + adjwgt[k*nobj+l] = ewgt[l]; + k++; + } + xadj[i+1] = k; + } + + fclose(fpin); + + free(line); + + *r_nvtxs = nvtxs; + *r_ncon = ncon; + *r_nobj = nobj; + *r_fmt = fmt; + *r_xadj = xadj; + *r_vwgt = vwgt; + *r_adjncy = adjncy; + *r_adjwgt = adjwgt; +} + + + + +/************************************************************************* +* This function writes out a partition vector +**************************************************************************/ +void WritePVector(char *gname, idxtype *vtxdist, idxtype *part, MPI_Comm comm) +{ + int i, j, k, l, rnvtxs, npes, mype, penum; + FILE *fpin; + idxtype *rpart; + char partfile[256]; + MPI_Status status; + + MPI_Comm_size(comm, &npes); + MPI_Comm_rank(comm, &mype); + + if (mype == 0) { + sprintf(partfile, "%s.part", gname); + if ((fpin = fopen(partfile, "w")) == NULL) + errexit("Failed to open file %s", partfile); + + for (i=0; i<vtxdist[1]; i++) + fprintf(fpin, "%d\n", part[i]); + + for (penum=1; penum<npes; penum++) { + rnvtxs = vtxdist[penum+1]-vtxdist[penum]; + rpart = idxmalloc(rnvtxs, "rpart"); + MPI_Recv((void *)rpart, rnvtxs, IDX_DATATYPE, penum, 1, comm, &status); + + for (i=0; i<rnvtxs; i++) + fprintf(fpin, "%d\n", rpart[i]); + + free(rpart); + } + fclose(fpin); + } + else + MPI_Send((void *)part, vtxdist[mype+1]-vtxdist[mype], IDX_DATATYPE, 0, 1, comm); + +} + + +/************************************************************************* +* This function reads a mesh from a file +**************************************************************************/ +void ParallelReadMesh(MeshType *mesh, char *filename, MPI_Comm comm) +{ + int i, j, k, pe; + int npes, mype, ier; + int gnelms, nelms, your_nelms, etype, maxnelms; + int maxnode, gmaxnode, minnode, gminnode; + idxtype *elmdist, *elements; + idxtype *your_elements; + MPI_Status stat; + char *line = NULL, *oldstr, *newstr; + FILE *fpin = NULL; + int esize, esizes[5] = {-1, 3, 4, 8, 4}; + int mgcnum, mgcnums[5] = {-1, 2, 3, 4, 2}; + + MPI_Comm_size(comm, &npes); + MPI_Comm_rank(comm, &mype); + + elmdist = mesh->elmdist = idxsmalloc(npes+1, 0, "ReadGraph: elmdist"); + + if (mype == npes-1) { + ier = 0; + fpin = fopen(filename, "r"); + + if (fpin == NULL){ + printf("COULD NOT OPEN FILE '%s' FOR SOME REASON!\n", filename); + ier++; + } + + MPI_Bcast(&ier, 1, MPI_INT, npes-1, comm); + if (ier > 0){ + fclose(fpin); + MPI_Finalize(); + exit(0); + } + + line = (char *)GKmalloc(sizeof(char)*(MAXLINE+1), "line"); + + fgets(line, MAXLINE, fpin); + sscanf(line, "%d %d", &gnelms, &etype); + + /* Construct elmdist and send it to all the processors */ + elmdist[0] = 0; + for (i=0,j=gnelms; i<npes; i++) { + k = j/(npes-i); + elmdist[i+1] = elmdist[i]+k; + j -= k; + } + + MPI_Bcast((void *)elmdist, npes+1, IDX_DATATYPE, npes-1, comm); + } + else { + MPI_Bcast(&ier, 1, MPI_INT, npes-1, comm); + if (ier > 0){ + MPI_Finalize(); + exit(0); + } + + MPI_Bcast((void *)elmdist, npes+1, IDX_DATATYPE, npes-1, comm); + } + + MPI_Bcast((void *)(&etype), 1, MPI_INT, npes-1, comm); + + gnelms = mesh->gnelms = elmdist[npes]; + nelms = mesh->nelms = elmdist[mype+1]-elmdist[mype]; + mesh->etype = etype; + esize = esizes[etype]; + mgcnum = mgcnums[etype]; + + elements = mesh->elements = idxmalloc(nelms*esize, "ParallelReadMesh: elements"); + + if (mype == npes-1) { + maxnelms = 0; + for (i=0; i<npes; i++) { + maxnelms = (maxnelms > elmdist[i+1]-elmdist[i]) ? + maxnelms : elmdist[i+1]-elmdist[i]; + } + + your_elements = idxmalloc(maxnelms*esize, "your_elements"); + + for (pe=0; pe<npes; pe++) { + your_nelms = elmdist[pe+1]-elmdist[pe]; + for (i=0; i<your_nelms; i++) { + + fgets(line, MAXLINE, fpin); + oldstr = line; + newstr = NULL; + + /*************************************/ + /* could get element weigts here too */ + /*************************************/ + + for (j=0; j<esize; j++) { + your_elements[i*esize+j] = (int)strtol(oldstr, &newstr, 10); + oldstr = newstr; + } + } + + if (pe < npes-1) { + MPI_Send((void *)your_elements, your_nelms*esize, IDX_DATATYPE, pe, 0, comm); + } + else { + for (i=0; i<your_nelms*esize; i++) + elements[i] = your_elements[i]; + } + } + fclose(fpin); + free(your_elements); + } + else { + MPI_Recv((void *)elements, nelms*esize, IDX_DATATYPE, npes-1, 0, comm, &stat); + } + + /*********************************/ + /* now check for number of nodes */ + /*********************************/ + minnode = elements[idxamin(nelms*esize, elements)]; + MPI_Allreduce((void *)&minnode, (void *)&gminnode, 1, MPI_INT, MPI_MIN, comm); + for (i=0; i<nelms*esize; i++) + elements[i] -= gminnode; + + maxnode = elements[idxamax(nelms*esize, elements)]; + MPI_Allreduce((void *)&maxnode, (void *)&gmaxnode, 1, MPI_INT, MPI_MAX, comm); + mesh->gnns = gmaxnode+1; + + if (mype==0) printf("Nelements: %d, Nnodes: %d, EType: %d\n", gnelms, mesh->gnns, etype); +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/mtest.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/mtest.c new file mode 100644 index 0000000..9aa2f7d --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/mtest.c @@ -0,0 +1,96 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * main.c + * + * This file contains code for testing teh adaptive partitioning routines + * + * Started 5/19/97 + * George + * + * $Id: mtest.c,v 1.3 2003/07/25 14:31:47 karypis Exp $ + * + */ + +#include <parmetisbin.h> + + +/************************************************************************* +* Let the game begin +**************************************************************************/ +int main(int argc, char *argv[]) +{ + int i, mype, npes, nelms; + idxtype *part, *eptr; + MeshType mesh; + MPI_Comm comm; + int wgtflag, numflag, edgecut, nparts, options[10]; + int mgcnum = -1, mgcnums[5] = {-1, 2, 3, 4, 2}, esizes[5] = {-1, 3, 4, 8, 4}; + float *tpwgts, ubvec[MAXNCON]; + + MPI_Init(&argc, &argv); + MPI_Comm_dup(MPI_COMM_WORLD, &comm); + MPI_Comm_size(comm, &npes); + MPI_Comm_rank(comm, &mype); + + if (argc < 2) { + if (mype == 0) + printf("Usage: %s <mesh-file> [NCommonNodes]\n", argv[0]); + + MPI_Finalize(); + exit(0); + } + + ParallelReadMesh(&mesh, argv[1], comm); + mgcnum = mgcnums[mesh.etype]; + mesh.ncon = 1; + + if (argc > 2) + mgcnum = atoi(argv[2]); + + if (mype == 0) printf("MGCNUM: %d\n", mgcnum); + + nparts = npes; + tpwgts = fmalloc(nparts*mesh.ncon, "tpwgts"); + for (i=0; i<nparts*mesh.ncon; i++) + tpwgts[i] = 1.0/(float)(nparts); + + for (i=0; i<mesh.ncon; i++) + ubvec[i] = UNBALANCE_FRACTION; + + part = idxmalloc(mesh.nelms, "part"); + + numflag = wgtflag = 0; + options[0] = 1; + options[PMV3_OPTION_DBGLVL] = 7; + options[PMV3_OPTION_SEED] = 0; + + nelms = mesh.elmdist[mype+1]-mesh.elmdist[mype]; + eptr = idxsmalloc(nelms+1, esizes[mesh.etype], "main; eptr"); + MAKECSR(i, nelms, eptr); + eptr[nelms]--; /* make the last element different */ + ParMETIS_V3_PartMeshKway(mesh.elmdist, eptr, mesh.elements, NULL, &wgtflag, + &numflag, &(mesh.ncon), &mgcnum, &nparts, tpwgts, ubvec, options, + &edgecut, part, &comm); + +/* + graph = ParallelMesh2Dual(&mesh, mgcnum, comm); + MPI_Barrier(comm); + + MPI_Allreduce((void *)&(graph->nedges), (void *)&gnedges, 1, MPI_INT, MPI_SUM, comm); + if (mype == 0) + printf("Completed Dual Graph -- Nvtxs: %d, Nedges: %d\n", graph->gnvtxs, gnedges/2); + + numflag = wgtflag = 0; + ParMETIS_V3_PartKway(graph->vtxdist, graph->xadj, graph->adjncy, NULL, NULL, &wgtflag, + &numflag, &(graph->ncon), &nparts, tpwgts, ubvec, options, &edgecut, part, &comm); + GKfree((void *)&(graph.vtxdist), (void *)&(graph.xadj), (void *)&(graph.vwgt), (void *)&(graph.adjncy), (void *)&(graph.adjwgt), LTERM); +*/ + + GKfree((void *)&part, (void *)&tpwgts, (void *)&eptr, LTERM); + MPI_Comm_free(&comm); + MPI_Finalize(); + return 0; +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/parmetisbin.h b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/parmetisbin.h new file mode 100644 index 0000000..d331af3 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/parmetisbin.h @@ -0,0 +1,31 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * par_metis.h + * + * This file includes all necessary header files + * + * Started 8/27/94 + * George + * + * $Id: parmetisbin.h,v 1.1 2003/07/21 17:50:23 karypis Exp $ + */ + +/* +#define DEBUG 1 +#define DMALLOC 1 +*/ + +#include <stdheaders.h> +#include "../parmetis.h" + +#ifdef DMALLOC +#include <dmalloc.h> +#endif + +#include <rename.h> +#include <defs.h> +#include <struct.h> +#include <macros.h> +#include <proto.h> + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/ptest.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/ptest.c new file mode 100644 index 0000000..2eb8baa --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/Programs/ptest.c @@ -0,0 +1,477 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * main.c + * + * This file contains code for testing teh adaptive partitioning routines + * + * Started 5/19/97 + * George + * + * $Id: ptest.c,v 1.3 2003/07/22 21:47:20 karypis Exp $ + * + */ + +#include <parmetisbin.h> + + +/************************************************************************* +* Let the game begin +**************************************************************************/ +int main(int argc, char *argv[]) +{ + int mype, npes; + MPI_Comm comm; + + MPI_Init(&argc, &argv); + MPI_Comm_dup(MPI_COMM_WORLD, &comm); + MPI_Comm_size(comm, &npes); + MPI_Comm_rank(comm, &mype); + + if (argc != 2) { + if (mype == 0) + printf("Usage: %s <graph-file>\n", argv[0]); + + MPI_Finalize(); + exit(0); + } + + TestParMetis_V3(argv[1], comm); + + MPI_Comm_free(&comm); + + MPI_Finalize(); + + return 0; +} + + + +/*********************************************************************************** +* This function is the testing routine for the adaptive multilevel partitioning code. +* It computes a partition from scratch, it then moves the graph and changes some +* of the vertex weights and then call the adaptive code. +************************************************************************************/ +void TestParMetis_V3(char *filename, MPI_Comm comm) +{ + int ncon, nparts, npes, mype, opt2, realcut; + GraphType graph, mgraph; + idxtype *part, *mpart, *savepart, *order, *sizes; + int numflag=0, wgtflag=0, options[10], edgecut, ndims; + float ipc2redist, *xyz, *tpwgts = NULL, ubvec[MAXNCON]; + + MPI_Comm_size(comm, &npes); + MPI_Comm_rank(comm, &mype); + + ndims = 2; + + ParallelReadGraph(&graph, filename, comm); + xyz = ReadTestCoordinates(&graph, filename, 2, comm); + MPI_Barrier(comm); + + part = idxmalloc(graph.nvtxs, "TestParMetis_V3: part"); + tpwgts = fmalloc(MAXNCON*npes*2, "TestParMetis_V3: tpwgts"); + sset(MAXNCON, 1.05, ubvec); + graph.vwgt = idxsmalloc(graph.nvtxs*5, 1, "TestParMetis_V3: vwgt"); + + + /*====================================================================== + / ParMETIS_V3_PartKway + /=======================================================================*/ + options[0] = 1; + options[1] = 3; + options[2] = 1; + wgtflag = 2; + numflag = 0; + edgecut = 0; + for (nparts=2*npes; nparts>=npes/2 && nparts > 0; nparts = nparts/2) { + for (ncon=1; ncon<=5; ncon+=2) { + + if (ncon > 1 && nparts > 1) + Mc_AdaptGraph(&graph, part, ncon, nparts, comm); + else + idxset(graph.nvtxs, 1, graph.vwgt); + + for (opt2=1; opt2<=2; opt2++) { + options[2] = opt2; + + sset(nparts*ncon, 1.0/(float)nparts, tpwgts); + if (mype == 0) + printf("\nTesting ParMETIS_V3_PartKway with options[1-2] = {%d %d}, Ncon: %d, Nparts: %d\n", options[1], options[2], ncon, nparts); + + ParMETIS_V3_PartKway(graph.vtxdist, graph.xadj, graph.adjncy, graph.vwgt, NULL, &wgtflag, + &numflag, &ncon, &nparts, tpwgts, ubvec, options, &edgecut, part, &comm); + + if (mype == 0) { + printf("ParMETIS_V3_PartKway reported a cut of %d\n", edgecut); + } + } + } + } + + + /*====================================================================== + / ParMETIS_V3_PartGeomKway + /=======================================================================*/ + options[0] = 1; + options[1] = 3; + wgtflag = 2; + numflag = 0; + for (nparts=2*npes; nparts>=npes/2 && nparts > 0; nparts = nparts/2) { + for (ncon=1; ncon<=5; ncon+=2) { + + if (ncon > 1) + Mc_AdaptGraph(&graph, part, ncon, nparts, comm); + else + idxset(graph.nvtxs, 1, graph.vwgt); + + for (opt2=1; opt2<=2; opt2++) { + options[2] = opt2; + + sset(nparts*ncon, 1.0/(float)nparts, tpwgts); + if (mype == 0) + printf("\nTesting ParMETIS_V3_PartGeomKway with options[1-2] = {%d %d}, Ncon: %d, Nparts: %d\n", options[1], options[2], ncon, nparts); + + ParMETIS_V3_PartGeomKway(graph.vtxdist, graph.xadj, graph.adjncy, graph.vwgt, NULL, &wgtflag, + &numflag, &ndims, xyz, &ncon, &nparts, tpwgts, ubvec, options, &edgecut, part, &comm); + + if (mype == 0) { + printf("ParMETIS_V3_PartGeomKway reported a cut of %d\n", edgecut); + } + } + } + } + + + + /*====================================================================== + / ParMETIS_V3_PartGeom + /=======================================================================*/ + wgtflag = 0; + numflag = 0; + if (mype == 0) + printf("\nTesting ParMETIS_V3_PartGeom\n"); + +/* ParMETIS_V3_PartGeom(graph.vtxdist, &ndims, xyz, part, &comm); */ + + if (mype == 0) + printf("ParMETIS_V3_PartGeom partition complete\n"); +/* + realcut = ComputeRealCut(graph.vtxdist, part, filename, comm); + if (mype == 0) + printf("ParMETIS_V3_PartGeom reported a cut of %d\n", realcut); +*/ + + /*====================================================================== + / ParMETIS_V3_RefineKway + /=======================================================================*/ + options[0] = 1; + options[1] = 3; + options[2] = 1; + options[3] = COUPLED; + nparts = npes; + wgtflag = 0; + numflag = 0; + ncon = 1; + sset(nparts*ncon, 1.0/(float)nparts, tpwgts); + + if (mype == 0) + printf("\nTesting ParMETIS_V3_RefineKway with default options (before move)\n"); + + ParMETIS_V3_RefineKway(graph.vtxdist, graph.xadj, graph.adjncy, NULL, NULL, &wgtflag, + &numflag, &ncon, &nparts, tpwgts, ubvec, options, &edgecut, part, &comm); + + MALLOC_CHECK(NULL); + + if (mype == 0) { + printf("ParMETIS_V3_RefineKway reported a cut of %d\n", edgecut); + } + + + MALLOC_CHECK(NULL); + + /* Compute a good partition and move the graph. Do so quietly! */ + options[0] = 0; + nparts = npes; + wgtflag = 0; + numflag = 0; + ncon = 1; + sset(nparts*ncon, 1.0/(float)nparts, tpwgts); + ParMETIS_V3_PartKway(graph.vtxdist, graph.xadj, graph.adjncy, NULL, NULL, &wgtflag, + &numflag, &ncon, &npes, tpwgts, ubvec, options, &edgecut, part, &comm); + TestMoveGraph(&graph, &mgraph, part, comm); + GKfree((void *)&(graph.vwgt), LTERM); + mpart = idxsmalloc(mgraph.nvtxs, mype, "TestParMetis_V3: mpart"); + savepart = idxmalloc(mgraph.nvtxs, "TestParMetis_V3: savepart"); + + MALLOC_CHECK(NULL); + + /*====================================================================== + / ParMETIS_V3_RefineKway + /=======================================================================*/ + options[0] = 1; + options[1] = 3; + options[3] = COUPLED; + nparts = npes; + wgtflag = 0; + numflag = 0; + + for (ncon=1; ncon<=5; ncon+=2) { + for (opt2=1; opt2<=2; opt2++) { + options[2] = opt2; + + sset(nparts*ncon, 1.0/(float)nparts, tpwgts); + if (mype == 0) + printf("\nTesting ParMETIS_V3_RefineKway with options[1-3] = {%d %d %d}, Ncon: %d, Nparts: %d\n", options[1], options[2], options[3], ncon, nparts); + ParMETIS_V3_RefineKway(mgraph.vtxdist, mgraph.xadj, mgraph.adjncy, NULL, NULL, &wgtflag, + &numflag, &ncon, &nparts, tpwgts, ubvec, options, &edgecut, mpart, &comm); + + if (mype == 0) { + printf("ParMETIS_V3_RefineKway reported a cut of %d\n", edgecut); + } + } + } + + + /*====================================================================== + / ParMETIS_V3_AdaptiveRepart + /=======================================================================*/ + mgraph.vwgt = idxsmalloc(mgraph.nvtxs*5, 1, "TestParMetis_V3: mgraph.vwgt"); + mgraph.vsize = idxsmalloc(mgraph.nvtxs, 1, "TestParMetis_V3: mgraph.vsize"); + AdaptGraph(&mgraph, 4, comm); + options[0] = 1; + options[1] = 7; + options[3] = COUPLED; + wgtflag = 2; + numflag = 0; + + for (nparts=2*npes; nparts>=npes/2; nparts = nparts/2) { + + ncon = 1; + wgtflag = 0; + options[0] = 0; + sset(nparts*ncon, 1.0/(float)nparts, tpwgts); + ParMETIS_V3_PartKway(mgraph.vtxdist, mgraph.xadj, mgraph.adjncy, NULL, NULL, + &wgtflag, &numflag, &ncon, &nparts, tpwgts, ubvec, options, &edgecut, savepart, &comm); + options[0] = 1; + wgtflag = 2; + + for (ncon=1; ncon<=3; ncon+=2) { + sset(nparts*ncon, 1.0/(float)nparts, tpwgts); + + if (ncon > 1) + Mc_AdaptGraph(&mgraph, savepart, ncon, nparts, comm); + else + AdaptGraph(&mgraph, 4, comm); +/* idxset(mgraph.nvtxs, 1, mgraph.vwgt); */ + + for (ipc2redist=1000.0; ipc2redist>=0.001; ipc2redist/=1000.0) { + for (opt2=1; opt2<=2; opt2++) { + idxcopy(mgraph.nvtxs, savepart, mpart); + options[2] = opt2; + + if (mype == 0) + printf("\nTesting ParMETIS_V3_AdaptiveRepart with options[1-3] = {%d %d %d}, ipc2redist: %.3f, Ncon: %d, Nparts: %d\n", options[1], options[2], options[3], ipc2redist, ncon, nparts); + + ParMETIS_V3_AdaptiveRepart(mgraph.vtxdist, mgraph.xadj, mgraph.adjncy, mgraph.vwgt, + mgraph.vsize, NULL, &wgtflag, &numflag, &ncon, &nparts, tpwgts, ubvec, &ipc2redist, + options, &edgecut, mpart, &comm); + + if (mype == 0) { + printf("ParMETIS_V3_AdaptiveRepart reported a cut of %d\n", edgecut); + } + } + } + } + } + + free(mgraph.vwgt); + free(mgraph.vsize); + + + + /*====================================================================== + / ParMETIS_V3_NodeND + /=======================================================================*/ + sizes = idxmalloc(2*npes, "TestParMetis_V3: sizes"); + order = idxmalloc(graph.nvtxs, "TestParMetis_V3: sizes"); + + options[0] = 1; + options[PMV3_OPTION_DBGLVL] = 3; + options[PMV3_OPTION_SEED] = 1; + numflag = 0; + + for (opt2=1; opt2<=2; opt2++) { + options[PMV3_OPTION_IPART] = opt2; + + if (mype == 0) + printf("\nTesting ParMETIS_V3_NodeND with options[1-3] = {%d %d %d}\n", options[1], options[2], options[3]); + + ParMETIS_V3_NodeND(graph.vtxdist, graph.xadj, graph.adjncy, &numflag, options, + order, sizes, &comm); + } + + + GKfree(&tpwgts, &part, &mpart, &savepart, &order, &sizes, LTERM); + +} + + + +/****************************************************************************** +* This function takes a partition vector that is distributed and reads in +* the original graph and computes the edgecut +*******************************************************************************/ +int ComputeRealCut(idxtype *vtxdist, idxtype *part, char *filename, MPI_Comm comm) +{ + int i, j, nvtxs, mype, npes, cut; + idxtype *xadj, *adjncy, *gpart; + MPI_Status status; + + MPI_Comm_size(comm, &npes); + MPI_Comm_rank(comm, &mype); + + if (mype != 0) { + MPI_Send((void *)part, vtxdist[mype+1]-vtxdist[mype], IDX_DATATYPE, 0, 1, comm); + } + else { /* Processor 0 does all the rest */ + gpart = idxmalloc(vtxdist[npes], "ComputeRealCut: gpart"); + idxcopy(vtxdist[1], part, gpart); + + for (i=1; i<npes; i++) + MPI_Recv((void *)(gpart+vtxdist[i]), vtxdist[i+1]-vtxdist[i], IDX_DATATYPE, i, 1, comm, &status); + + ReadMetisGraph(filename, &nvtxs, &xadj, &adjncy); + + /* OK, now compute the cut */ + for (cut=0, i=0; i<nvtxs; i++) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (gpart[i] != gpart[adjncy[j]]) + cut++; + } + } + cut = cut/2; + + GKfree(&gpart, &xadj, &adjncy, LTERM); + + return cut; + } + return 0; +} + + +/****************************************************************************** +* This function takes a partition vector that is distributed and reads in +* the original graph and computes the edgecut +*******************************************************************************/ +int ComputeRealCut2(idxtype *vtxdist, idxtype *mvtxdist, idxtype *part, idxtype *mpart, char *filename, MPI_Comm comm) +{ + int i, j, nvtxs, mype, npes, cut; + idxtype *xadj, *adjncy, *gpart, *gmpart, *perm, *sizes; + MPI_Status status; + + + MPI_Comm_size(comm, &npes); + MPI_Comm_rank(comm, &mype); + + if (mype != 0) { + MPI_Send((void *)part, vtxdist[mype+1]-vtxdist[mype], IDX_DATATYPE, 0, 1, comm); + MPI_Send((void *)mpart, mvtxdist[mype+1]-mvtxdist[mype], IDX_DATATYPE, 0, 1, comm); + } + else { /* Processor 0 does all the rest */ + gpart = idxmalloc(vtxdist[npes], "ComputeRealCut: gpart"); + idxcopy(vtxdist[1], part, gpart); + gmpart = idxmalloc(mvtxdist[npes], "ComputeRealCut: gmpart"); + idxcopy(mvtxdist[1], mpart, gmpart); + + for (i=1; i<npes; i++) { + MPI_Recv((void *)(gpart+vtxdist[i]), vtxdist[i+1]-vtxdist[i], IDX_DATATYPE, i, 1, comm, &status); + MPI_Recv((void *)(gmpart+mvtxdist[i]), mvtxdist[i+1]-mvtxdist[i], IDX_DATATYPE, i, 1, comm, &status); + } + + /* OK, now go and reconstruct the permutation to go from the graph to mgraph */ + perm = idxmalloc(vtxdist[npes], "ComputeRealCut: perm"); + sizes = idxsmalloc(npes+1, 0, "ComputeRealCut: sizes"); + + for (i=0; i<vtxdist[npes]; i++) + sizes[gpart[i]]++; + MAKECSR(i, npes, sizes); + for (i=0; i<vtxdist[npes]; i++) + perm[i] = sizes[gpart[i]]++; + + /* Ok, now read the graph from the file */ + ReadMetisGraph(filename, &nvtxs, &xadj, &adjncy); + + /* OK, now compute the cut */ + for (cut=0, i=0; i<nvtxs; i++) { + for (j=xadj[i]; j<xadj[i+1]; j++) { + if (gmpart[perm[i]] != gmpart[perm[adjncy[j]]]) + cut++; + } + } + cut = cut/2; + + GKfree(&gpart, &gmpart, &perm, &sizes, &xadj, &adjncy, LTERM); + + return cut; + } + + return 0; +} + + + +/****************************************************************************** +* This function takes a graph and its partition vector and creates a new +* graph corresponding to the one after the movement +*******************************************************************************/ +void TestMoveGraph(GraphType *ograph, GraphType *omgraph, idxtype *part, MPI_Comm comm) +{ + int npes, mype; + CtrlType ctrl; + WorkSpaceType wspace; + GraphType *graph, *mgraph; + int options[5] = {0, 0, 1, 0, 0}; + + MPI_Comm_size(comm, &npes); + MPI_Comm_rank(comm, &mype); + + SetUpCtrl(&ctrl, npes, 0, comm); + ctrl.CoarsenTo = 1; /* Needed by SetUpGraph, otherwise we can FP errors */ + graph = SetUpGraph(&ctrl, ograph->vtxdist, ograph->xadj, NULL, ograph->adjncy, NULL, 0); + PreAllocateMemory(&ctrl, graph, &wspace); + + SetUp(&ctrl, graph, &wspace); + graph->where = part; + graph->ncon = 1; + mgraph = Moc_MoveGraph(&ctrl, graph, &wspace); + + omgraph->gnvtxs = mgraph->gnvtxs; + omgraph->nvtxs = mgraph->nvtxs; + omgraph->nedges = mgraph->nedges; + omgraph->vtxdist = mgraph->vtxdist; + omgraph->xadj = mgraph->xadj; + omgraph->adjncy = mgraph->adjncy; + mgraph->vtxdist = NULL; + mgraph->xadj = NULL; + mgraph->adjncy = NULL; + FreeGraph(mgraph); + + graph->where = NULL; + FreeInitialGraphAndRemap(graph, 0); + FreeWSpace(&wspace); +} + +/***************************************************************************** +* This function sets up a graph data structure for partitioning +*****************************************************************************/ +GraphType *SetUpGraph(CtrlType *ctrl, idxtype *vtxdist, idxtype *xadj, + idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, int wgtflag) +{ + int mywgtflag; + + mywgtflag = wgtflag; + return Moc_SetUpGraph(ctrl, 1, vtxdist, xadj, vwgt, adjncy, adjwgt, &mywgtflag); +} + + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/README b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/README new file mode 100644 index 0000000..abcde38 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/README @@ -0,0 +1,9 @@ +This is ParMetis version 3.1. You can find the manual describing the +various routines in the directory 'Manual'. Also, the file called +INSTALL contains instructions on how to build and test ParMetis. + + +Please let me know of any problems that you have found with it. + +George Karypis diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/VERSION b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/VERSION new file mode 100644 index 0000000..1a26826 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/VERSION @@ -0,0 +1,5 @@ +ParMetis Version 3.1.0 Fri Aug 15 13:59:41 CDT 2003 +ParMetis Version 3.0.0 Wed Mar 27 23:56:38 CST 2002 +ParMetis Version 2.0.0 Tue Sep 22 18:58:31 CDT 1998 +ParMetis Version 1.0.2 Wed Apr 15 13:14:50 CDT 1998 + diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/parmetis.h b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/parmetis.h new file mode 100644 index 0000000..64a90ea --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/parmetis.h @@ -0,0 +1,193 @@ +/* + * Copyright 1997-2003, Regents of the University of Minnesota + * + * parmetis.h + * + * This file contains function prototypes and constrant definitions for + * ParMETIS + * + * Started 7/21/03 + * George + * + */ + +#ifndef __parmetis_h__ +#define __parmetis_h__ + +#include <mpi.h> + +#ifndef _MSC_VER +#define __cdecl +#endif + + +/************************************************************************* +* Data-structures +**************************************************************************/ +/* Undefine the following #define in order to use short int as the idxtype */ +#define IDXTYPE_INT + +/* Indexes are as long as integers for now */ +#ifdef IDXTYPE_INT +typedef int idxtype; +#else +typedef short idxtype; +#endif + + +/************************************************************************* +* Constants +**************************************************************************/ +#define PARMETIS_MAJOR_VERSION 3 +#define PARMETIS_MINOR_VERSION 1 + + +/************************************************************************* +* Function prototypes +**************************************************************************/ +#ifdef __cplusplus +extern "C" { +#endif + +/*------------------------------------------------------------------- +* API Introduced with Release 3.0 (current API) +*--------------------------------------------------------------------*/ +void __cdecl ParMETIS_V3_AdaptiveRepart( + idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *vsize, idxtype *adjwgt, int *wgtflag, int *numflag, int *ncon, + int *nparts, float *tpwgts, float *ubvec, float *ipc2redist, + int *options, int *edgecut, idxtype *part, MPI_Comm *comm); + +void __cdecl ParMETIS_V3_PartGeomKway( + idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *ndims, float *xyz, + int *ncon, int *nparts, float *tpwgts, float *ubvec, int *options, + int *edgecut, idxtype *part, MPI_Comm *comm); + +void __cdecl ParMETIS_V3_PartGeom( + idxtype *vtxdist, int *ndims, float *xyz, idxtype *part, MPI_Comm *comm); + +void __cdecl ParMETIS_V3_PartKway( + idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *ncon, int *nparts, + float *tpwgts, float *ubvec, int *options, int *edgecut, idxtype *part, + MPI_Comm *comm); + +void __cdecl ParMETIS_V3_Mesh2Dual( + idxtype *elmdist, idxtype *eptr, idxtype *eind, int *numflag, + int *ncommonnodes, idxtype **xadj, idxtype **adjncy, MPI_Comm *comm); + +void __cdecl ParMETIS_V3_PartMeshKway( + idxtype *elmdist, idxtype *eptr, idxtype *eind, idxtype *elmwgt, + int *wgtflag, int *numflag, int *ncon, int *ncommonnodes, int *nparts, + float *tpwgts, float *ubvec, int *options, int *edgecut, idxtype *part, + MPI_Comm *comm); + +void __cdecl ParMETIS_V3_NodeND( + idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, int *numflag, + int *options, idxtype *order, idxtype *sizes, MPI_Comm *comm); + +void __cdecl ParMETIS_V3_RefineKway( + idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *ncon, int *nparts, + float *tpwgts, float *ubvec, int *options, int *edgecut, + idxtype *part, MPI_Comm *comm); + + + +/*------------------------------------------------------------------ +* Backward compatibility routines with Release 2.0 +*-------------------------------------------------------------------*/ +void __cdecl ParMETIS_PartKway( + idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, + int *edgecut, idxtype *part, MPI_Comm *comm); + +void __cdecl ParMETIS_PartGeomKway( + idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, + int *wgtflag, int *numflag, int *ndims, float *xyz, int *nparts, int *options, + int *edgecut, idxtype *part, MPI_Comm *comm); + +void __cdecl ParMETIS_PartGeom( + idxtype *vtxdist, int *ndims, float *xyz, idxtype *part, MPI_Comm *comm); + +void __cdecl ParMETIS_PartGeomRefine( + idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *ndims, float *xyz, + int *options, int *edgecut, idxtype *part, MPI_Comm *comm); + +void __cdecl ParMETIS_RefineKway( + idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *options, int *edgecut, + idxtype *part, MPI_Comm *comm); + +void __cdecl ParMETIS_RepartLDiffusion( + idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *options, int *edgecut, + idxtype *part, MPI_Comm *comm); + +void __cdecl ParMETIS_RepartGDiffusion( + idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, + idxtype *adjwgt, int *wgtflag, int *numflag, int *options, int *edgecut, + idxtype *part, MPI_Comm *comm); + +void __cdecl ParMETIS_RepartRemap( + idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, + int *wgtflag, int *numflag, int *options, int *edgecut, idxtype *part, + MPI_Comm *comm); + +void __cdecl ParMETIS_RepartMLRemap( + idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, + int *wgtflag, int *numflag, int *options, int *edgecut, idxtype *part, + MPI_Comm *comm); + +void __cdecl ParMETIS_NodeND( + idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, int *numflag, int *options, + idxtype *order, idxtype *sizes, MPI_Comm *comm); + +void __cdecl ParMETIS_SerialNodeND( + idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, int *numflag, int *options, + idxtype *order, idxtype *sizes, MPI_Comm *comm); + + + + +/*------------------------------------------------------------------- +* Backward compatibility routines with Release 1.0 +*--------------------------------------------------------------------*/ +void __cdecl PARKMETIS( + idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + idxtype *part, int *options, MPI_Comm comm); + +void __cdecl PARGKMETIS( + idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + int ndims, float *xyz, idxtype *part, int *options, MPI_Comm comm); + +void __cdecl PARGRMETIS( + idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + int ndims, float *xyz, idxtype *part, int *options, MPI_Comm comm); + +void __cdecl PARGMETIS( + idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, int ndims, float *xyz, + idxtype *part, int *options, MPI_Comm comm); + +void __cdecl PARRMETIS( + idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, + idxtype *adjwgt, idxtype *part, int *options, MPI_Comm comm); + +void __cdecl PARUAMETIS( + idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, + idxtype *adjwgt, idxtype *part, int *options, MPI_Comm comm); + +void __cdecl PARDAMETIS( + idxtype *vtxdist, idxtype *xadj, idxtype *vwgt, idxtype *adjncy, idxtype *adjwgt, + idxtype *part, int *options, MPI_Comm comm); + +#ifdef __cplusplus +} +#endif + + + + +#endif |
