Zoltan is added as thirdParty package

This commit is contained in:
Hamidreza
2025-05-15 21:58:43 +03:30
parent 83a6e4baa1
commit d7479cf1bd
3392 changed files with 318142 additions and 1 deletions

180
thirdParty/Zoltan/src/coloring/bucket.c vendored Normal file
View File

@ -0,0 +1,180 @@
/*
* @HEADER
*
* ***********************************************************************
*
* Zoltan Toolkit for Load-balancing, Partitioning, Ordering and Coloring
* Copyright 2012 Sandia Corporation
*
* Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
* the U.S. Government retains certain rights in this software.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the Corporation nor the names of the
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Questions? Contact Karen Devine kddevin@sandia.gov
* Erik Boman egboman@sandia.gov
*
* ***********************************************************************
*
* @HEADER
*/
#ifdef __cplusplus
/* if C++, define the rest of this header file as extern C */
extern "C" {
#endif
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include "zoltan_mem.h"
#include "bucket.h"
void Zoltan_Bucket_Insert(Bucket* bs, int id, int value)
{
#if 0
assert (bs != NULL);
assert (value >= 0);
assert (value <= bs->max_value);
assert (id >= 0);
assert (id < bs->nb_elements);
#endif
bs->values[id] = value;
bs->elements[id].prev = NULL;
bs->elements[id].next = bs->buckets[value];
if (bs->buckets[value] != NULL)
bs->buckets[value]->prev = &(bs->elements[id]);
else if (bs->current_min_value > value)
bs->current_min_value = value;
bs->buckets[value] = &(bs->elements[id]);
}
void Zoltan_Bucket_Update(Bucket* bs, int id, int new_value)
{
int old_value = bs->values[id];
if (old_value == INT_MAX)
return;
#if 0
assert (bs != NULL);
assert (new_value >= 0);
assert (new_value <= bs->max_value);
assert (id >= 0);
assert (id < bs->nb_elements);
#endif
bs->values[id] = new_value;
if (bs->elements[id].prev == NULL)
bs->buckets[old_value] = bs->elements[id].next;
else
bs->elements[id].prev->next = bs->elements[id].next;
if (bs->elements[id].next != NULL)
bs->elements[id].next->prev = bs->elements[id].prev;
Zoltan_Bucket_Insert(bs, id, new_value);
}
int Zoltan_Bucket_PopMin(Bucket* bs)
{
int id;
#if 0
assert (bs != NULL);
assert (bs->current_min_value >= 0);
#endif
for (; bs->current_min_value<=bs->max_value; bs->current_min_value++) {
if (bs->buckets[bs->current_min_value] != NULL) {
id = bs->buckets[bs->current_min_value] - bs->elements;
bs->buckets[bs->current_min_value] = bs->buckets[bs->current_min_value]->next;
if (bs->buckets[bs->current_min_value] != NULL) {
bs->buckets[bs->current_min_value]->prev = NULL;
}
bs->values[id] = INT_MAX;
return id;
}
}
return -1;
}
Bucket Zoltan_Bucket_Initialize(int max_value, int nb_element)
{
Bucket bs;
int i;
#if 0
assert (max_value>=0);
assert (nb_element>=0);
#endif
bs.buckets = (Bucket_element **)ZOLTAN_MALLOC(sizeof(Bucket_element *)*(max_value+1));
bs.elements = (Bucket_element *)ZOLTAN_MALLOC(sizeof(Bucket_element)*nb_element);
bs.values = (int *) ZOLTAN_MALLOC(sizeof(int)*nb_element);
bs.max_value = max_value;
bs.nb_elements = nb_element;
if (bs.buckets == NULL || bs.elements == NULL || bs.values == NULL) {
ZOLTAN_FREE(&(bs.values));
ZOLTAN_FREE(&(bs.buckets));
ZOLTAN_FREE(&(bs.elements));
} else {
for (i=0; i<=max_value; i++)
bs.buckets[i] = NULL;
for (i=0; i<nb_element; i++) {
bs.elements[i].prev = NULL;
bs.elements[i].next = NULL;
}
}
bs.current_min_value = max_value+1;
return bs;
}
void Zoltan_Bucket_Free(Bucket* bs)
{
ZOLTAN_FREE(&(bs->values));
ZOLTAN_FREE(&(bs->buckets));
ZOLTAN_FREE(&(bs->elements));
}
#ifdef __cplusplus
} /* closing bracket for extern "C" */
#endif

99
thirdParty/Zoltan/src/coloring/bucket.h vendored Normal file
View File

@ -0,0 +1,99 @@
/*
* @HEADER
*
* ***********************************************************************
*
* Zoltan Toolkit for Load-balancing, Partitioning, Ordering and Coloring
* Copyright 2012 Sandia Corporation
*
* Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
* the U.S. Government retains certain rights in this software.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the Corporation nor the names of the
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Questions? Contact Karen Devine kddevin@sandia.gov
* Erik Boman egboman@sandia.gov
*
* ***********************************************************************
*
* @HEADER
*/
#ifndef __BUCKET__H
#define __BUCKET__H
#ifdef __cplusplus
/* if C++, define the rest of this header file as extern C */
extern "C" {
#endif
/* This is ID-less bucket datastructure to save memory
and hence speed up bucket updates. It assumes IDs are
0-based indices without any gap */
typedef struct S
{
struct S* prev;
struct S* next;
} Bucket_element;
typedef struct arg
{
Bucket_element **buckets; /* actual pointers to bucket heads */
Bucket_element *elements; /* for direct access to bucket elements
elements[id] is the id-th element */
int nb_elements;
int max_value;
int *values; /* needed for update, incase bucket head
changed. */
int current_min_value;
} Bucket;
/* value == INT_MAX means not present in bucket */
void Zoltan_Bucket_Insert(Bucket* bs, int id, int value);
void Zoltan_Bucket_Update(Bucket* bs, int id, int new_value);
#define Zoltan_Bucket_DecVal(bs, id) Zoltan_Bucket_Update(bs, id, (bs)->values[id]-1)
/*returns -1 if empty*/
int Zoltan_Bucket_PopMin(Bucket* bs);
Bucket Zoltan_Bucket_Initialize(int max_value, int nb_element);
void Zoltan_Bucket_Free(Bucket* bs);
#ifdef __cplusplus
} /* closing bracket for extern "C" */
#endif
#endif

View File

@ -0,0 +1,340 @@
/*
* @HEADER
*
* ***********************************************************************
*
* Zoltan Toolkit for Load-balancing, Partitioning, Ordering and Coloring
* Copyright 2012 Sandia Corporation
*
* Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
* the U.S. Government retains certain rights in this software.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the Corporation nor the names of the
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Questions? Contact Karen Devine kddevin@sandia.gov
* Erik Boman egboman@sandia.gov
*
* ***********************************************************************
*
* @HEADER
*/
#ifdef __cplusplus
/* if C++, define the rest of this header file as extern C */
extern "C" {
#endif
#include <limits.h>
#include <ctype.h>
#include "zoltan_mem.h"
#include "zz_const.h"
#include "coloring.h"
#include "g2l_hash.h"
#include "params_const.h"
#include "zz_util_const.h"
#include "graph.h"
#include "all_allo_const.h"
/*****************************************************************************/
/* Parameters structure for Color method. Used in */
/* Zoltan_Color_Set_Param and Zoltan_Color. */
static PARAM_VARS Color_params[] = {
{ "COLORING_PROBLEM", NULL, "STRING", 0 },
{ "SUPERSTEP_SIZE", NULL, "INT", 0},
{ "COMM_PATTERN", NULL, "CHAR", 0 },
{ "VERTEX_VISIT_ORDER", NULL, "CHAR", 0 },
{ "COLORING_METHOD", NULL, "CHAR", 0},
{ NULL, NULL, NULL, 0 } };
/*****************************************************************************/
/* Interface routine for Graph Coloring Testing */
int Zoltan_Color_Test(
ZZ *zz, /* Zoltan structure */
int *num_gid_entries, /* # of entries for a global id */
int *num_lid_entries, /* # of entries for a local id */
int num_obj, /* Input: number of objects */
ZOLTAN_ID_PTR global_ids, /* Input: global ids of the vertices */
/* The application must allocate enough space */
ZOLTAN_ID_PTR local_ids, /* Input: local ids of the vertices */
/* The application must allocate enough space */
int *color_exp /* Input: Colors assigned to local vertices */
)
{
static char *yo = "color_test_fn";
int nvtx = num_obj; /* number of vertices */
int i, j;
int ierr = ZOLTAN_OK;
int ferr = ZOLTAN_OK; /* final error signal */
char coloring_problem; /* Input: which coloring to perform;
currently only supports D1, D2 coloring and variants */
char coloring_problemStr[MAX_PARAM_STRING_LEN]; /* string version coloring problem name */
int ss=100;
char comm_pattern='S', coloring_order='I', coloring_method='F';
int comm[2],gcomm[2];
int *color=NULL;
int *adjproc=NULL, *xadj=NULL;
ZOLTAN_GNO_TYPE gvtx; /* number of global vertices */
ZOLTAN_GNO_TYPE *vtxdist=NULL, *adjncy=NULL;
ZG graph;
ZOLTAN_GNO_TYPE *requested_GNOs = NULL; /* Return GNOs of
the requested GIDs. */
int *loc_partialD2 = NULL; /* local binary array showing which vertices to be colored */
int *partialD2 = NULL; /* global binary array showing which vertices to be colored */
struct Zoltan_DD_Struct *dd_color; /* DDirectory for colors */
ZOLTAN_GNO_TYPE *local_GNOs = NULL;
ZOLTAN_GNO_TYPE *global_GNOs = NULL;
memset (&graph, 0, sizeof(ZG));
/* PARAMETER SETTINGS */
Zoltan_Bind_Param(Color_params, "COLORING_PROBLEM", (void *) &coloring_problemStr);
Zoltan_Bind_Param(Color_params, "SUPERSTEP_SIZE", (void *) &ss);
Zoltan_Bind_Param(Color_params, "COMM_PATTERN", (void *) &comm_pattern);
Zoltan_Bind_Param(Color_params, "VERTEX_VISIT_ORDER", (void *) &coloring_order);
Zoltan_Bind_Param(Color_params, "COLORING_METHOD", (void *) &coloring_method);
strncpy(coloring_problemStr, "distance-1", MAX_PARAM_STRING_LEN);
Zoltan_Assign_Param_Vals(zz->Params, Color_params, zz->Debug_Level, zz->Proc,
zz->Debug_Proc);
/* Check validity of parameters - they should be consistent with Zoltan_Color */
if (!strcasecmp(coloring_problemStr, "distance-1"))
coloring_problem = '1';
else if (!strcasecmp(coloring_problemStr, "distance-2"))
coloring_problem = '2';
else if (!strcasecmp(coloring_problemStr, "partial-distance-2")
|| !strcasecmp(coloring_problemStr, "bipartite"))
coloring_problem = 'P';
else {
ZOLTAN_PRINT_WARN(zz->Proc, yo, "Unknown coloring requested. Using Distance-1 coloring.");
coloring_problem = '1';
}
if (ss == 0) {
ZOLTAN_PRINT_WARN(zz->Proc, yo, "Invalid superstep size. Using default value 100.");
ss = 100;
}
if (comm_pattern != 'S' && comm_pattern != 'A') {
ZOLTAN_PRINT_WARN(zz->Proc, yo, "Invalid communication pattern. Using synchronous communication (S).");
comm_pattern = 'S';
}
if (comm_pattern == 'A' && (coloring_problem == '2' || coloring_problem == 'P')) {
ZOLTAN_PRINT_WARN(zz->Proc, yo, "Asynchronous communication pattern is not implemented for distance-2 coloring and its variants. Using synchronous communication (S).");
comm_pattern = 'S';
}
if (coloring_order != 'I' && coloring_order != 'B' && coloring_order != 'U' && coloring_order != 'L' && coloring_order != 'N' && coloring_order != 'S') {
ZOLTAN_PRINT_WARN(zz->Proc, yo, "Invalid coloring order. Using internal first coloring order (I).");
coloring_order = 'I';
}
if (coloring_order == 'U' && (coloring_problem == '2' || coloring_problem == 'P')) {
ZOLTAN_PRINT_WARN(zz->Proc, yo, "Interleaved coloring order is not implemented for distance-2 coloring and its variants. Using internal first coloring order (I).");
coloring_order = 'I';
}
if (coloring_method !='F') {
ZOLTAN_PRINT_WARN(zz->Proc, yo, "Invalid coloring method. Using first fit method (F).");
coloring_method = 'F';
}
/* Compute Max number of array entries per ID over all processors.
This is a sanity-maintaining step; we don't want different
processors to have different values for these numbers. */
comm[0] = zz->Num_GID;
comm[1] = zz->Num_LID;
MPI_Allreduce(comm, gcomm, 2, MPI_INT, MPI_MAX, zz->Communicator);
zz->Num_GID = *num_gid_entries = gcomm[0];
zz->Num_LID = *num_lid_entries = gcomm[1];
/* Return if this processor is not in the Zoltan structure's
communicator. */
if (ZOLTAN_PROC_NOT_IN_COMMUNICATOR(zz))
return ZOLTAN_OK;
/* BUILD THE GRAPH */
/* Check that the user has allocated space for the return args. */
if (!color_exp)
ZOLTAN_COLOR_ERROR(ZOLTAN_FATAL, "Color argument is NULL. Please give colors of local vertices.");
requested_GNOs = (ZOLTAN_GNO_TYPE *) ZOLTAN_MALLOC(num_obj *
sizeof(ZOLTAN_GNO_TYPE));
Zoltan_ZG_Build (zz, &graph, 0, 1, num_obj,
global_ids, requested_GNOs);
Zoltan_ZG_Export (zz, &graph,
&gvtx, &nvtx, NULL, NULL,
&vtxdist, &xadj, &adjncy, &adjproc,
NULL, NULL);
if (gvtx > (ZOLTAN_GNO_TYPE)INT_MAX){
if (zz->Proc == 0){
fprintf(stderr,
"Zoltan_Color_Test assumes number of vertices (%ld) is less than INT_MAX\n",gvtx);
}
ierr = ZOLTAN_FATAL;
goto End;
}
/* Exchange global color information */
if (vtxdist[zz->Num_Proc] && !(color = (int *) ZOLTAN_CALLOC(vtxdist[zz->Num_Proc], sizeof(int))))
MEMORY_ERROR;
if (nvtx && !(local_GNOs = (ZOLTAN_GNO_TYPE *) ZOLTAN_MALLOC(nvtx * sizeof(ZOLTAN_GNO_TYPE))))
MEMORY_ERROR;
for (i=0; i<nvtx; ++i)
local_GNOs[i] = i+vtxdist[zz->Proc];
if (vtxdist[zz->Num_Proc] && !(global_GNOs = (ZOLTAN_GNO_TYPE *) ZOLTAN_MALLOC(vtxdist[zz->Num_Proc] * sizeof(ZOLTAN_GNO_TYPE))))
MEMORY_ERROR;
for (i=0; i<vtxdist[zz->Num_Proc]; ++i)
global_GNOs[i] = i;
ierr = Zoltan_DD_Create (&dd_color, zz->Communicator,
sizeof(ZOLTAN_GNO_TYPE)/sizeof(ZOLTAN_ID_TYPE), 0, 0, num_obj, 0);
if (ierr != ZOLTAN_OK)
ZOLTAN_COLOR_ERROR(ierr, "Cannot construct DDirectory.");
/* Put req obs with 1 but first inialize the rest with 0 */
ierr = Zoltan_DD_Update (dd_color, (ZOLTAN_ID_PTR)local_GNOs, NULL,
NULL, color, nvtx);
if (ierr != ZOLTAN_OK)
ZOLTAN_COLOR_ERROR(ierr, "Cannot update DDirectory.");
ierr = Zoltan_DD_Update (dd_color, (ZOLTAN_ID_PTR)requested_GNOs, NULL,
NULL, color_exp, num_obj);
if (ierr != ZOLTAN_OK)
ZOLTAN_COLOR_ERROR(ierr, "Cannot update DDirectory.");
/* Get requested colors from the DDirectory. */
ierr = Zoltan_DD_Find (dd_color, (ZOLTAN_ID_PTR)global_GNOs, NULL, NULL,
color, vtxdist[zz->Num_Proc], NULL);
if (ierr != ZOLTAN_OK)
ZOLTAN_COLOR_ERROR(ierr, "Cannot find object in DDirectory.");
/* Free DDirectory */
Zoltan_DD_Destroy(&dd_color);
ZOLTAN_FREE(&local_GNOs);
ZOLTAN_FREE(&global_GNOs);
if (coloring_problem == 'P' || coloring_problem == '2') {
if (vtxdist[zz->Num_Proc] && !(partialD2 = (int *) ZOLTAN_CALLOC(vtxdist[zz->Num_Proc], sizeof(int))))
MEMORY_ERROR;
if (vtxdist[zz->Num_Proc] && !(loc_partialD2 = (int *) ZOLTAN_CALLOC(vtxdist[zz->Num_Proc], sizeof(int))))
MEMORY_ERROR;
if (coloring_problem == 'P') {
for (i=0; i<num_obj; ++i) {
int gno=requested_GNOs[i];
loc_partialD2[gno] = 1;
}
MPI_Allreduce(loc_partialD2, partialD2, vtxdist[zz->Num_Proc], MPI_INT, MPI_LOR, zz->Communicator);
} else {
for (i=0; i<vtxdist[zz->Num_Proc]; ++i)
partialD2[i] = 1;
}
}
/* Check if there is an error in coloring */
if (coloring_problem == '1') {
for (i=0; i<nvtx; i++) {
int gno = i + (int)vtxdist[zz->Proc];
if (color[gno] <= 0) { /* object i is not colored properly */
ierr = ZOLTAN_FATAL;
printf("Error in coloring! u:%d, cu:%d\n", gno, color[gno]);
break;
}
for (j = xadj[i]; j < xadj[i+1]; ++j) {
int v = (int)adjncy[j];
if (color[gno] == color[v]) { /* neighbors have the same color */
ierr = ZOLTAN_FATAL;
printf("Error in coloring! u:%d, v:%d, cu:%d, cv:%d\n", gno, v, color[gno], color[v]);
break;
}
}
if (ierr == ZOLTAN_FATAL)
break;
}
} else if (coloring_problem == '2' || coloring_problem == 'P') {
for (i=0; i<nvtx; i++) {
int gno = i + (int)vtxdist[zz->Proc];
if (partialD2[gno] && color[gno] <= 0) { /* object i is not colored properly */
ierr = ZOLTAN_FATAL;
printf("Error in coloring! u:%d, cu:%d\n", gno, color[gno]);
break;
}
for (j = xadj[i]; j < xadj[i+1]; ++j) {
int v = (int)adjncy[j], k;
if (partialD2[v] && color[v] <= 0) {
ierr = ZOLTAN_FATAL;
printf("Error in coloring! d1-neigh: u:%d, v:%d, cu:%d, cv:%d pu:%d pv:%d\n", gno, v, color[gno], color[v], partialD2[gno], partialD2[v]);
break;
}
if (partialD2[gno] && partialD2[v] && color[gno] == color[v]) { /* d-1 neighbors have the same color */
ierr = ZOLTAN_FATAL;
printf("Error in coloring! d1-neigh: u:%d, v:%d, cu:%d, cv:%d pu:%d pv:%d\n", gno, v, color[gno], color[v], partialD2[gno], partialD2[v]);
break;
}
for (k = j+1; k < xadj[i+1]; ++k) {
int w = (int)adjncy[k];
if (partialD2[v] && partialD2[w] && color[v] == color[w]) { /* d-2 neighbors have the same color */
ierr = ZOLTAN_FATAL;
printf("Error in coloring! d2-neigh: v:%d, w:%d, cv:%d, cw:%d pv:%d pw:%d\n", v, w, color[v], color[w], partialD2[v], partialD2[w]);
break;
}
}
}
if (ierr == ZOLTAN_FATAL)
break;
}
} else
ZOLTAN_COLOR_ERROR(ZOLTAN_WARN, "Zoltan_Color_Test is only implemented for distance-1 and distance-2 coloring. Unknown coloring, skipping verification.");
End:
if (ierr==ZOLTAN_FATAL)
ierr = 2;
MPI_Allreduce(&ierr, &ferr, 1, MPI_INT, MPI_MAX, zz->Communicator);
if (ferr == 2)
ierr = ZOLTAN_FATAL;
else
ierr = ZOLTAN_OK;
Zoltan_ZG_Free (&graph);
ZOLTAN_FREE(&local_GNOs);
ZOLTAN_FREE(&global_GNOs);
ZOLTAN_FREE(&adjproc);
ZOLTAN_FREE(&color);
ZOLTAN_FREE(&requested_GNOs);
ZOLTAN_FREE(&partialD2);
ZOLTAN_FREE(&loc_partialD2);
return ierr;
}

2571
thirdParty/Zoltan/src/coloring/coloring.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,74 @@
/*
* @HEADER
*
* ***********************************************************************
*
* Zoltan Toolkit for Load-balancing, Partitioning, Ordering and Coloring
* Copyright 2012 Sandia Corporation
*
* Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
* the U.S. Government retains certain rights in this software.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the Corporation nor the names of the
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Questions? Contact Karen Devine kddevin@sandia.gov
* Erik Boman egboman@sandia.gov
*
* ***********************************************************************
*
* @HEADER
*/
#ifndef __COLORING_H
#define __COLORING_H
#ifdef __cplusplus
/* if C++, define the rest of this header file as extern C */
extern "C" {
#endif
#include <ctype.h>
#include "zz_const.h"
#include "zz_util_const.h"
#include "coloring_const.h"
/* Metis also has a swap */
#ifdef SWAP
#undef SWAP
#endif
#define SWAP(a,b) tmp=(a);(a)=(b);(b)=tmp;
/* Macros for error handling */
#define ZOLTAN_COLOR_ERROR(error,str) {ierr = error ; \
ZOLTAN_PRINT_ERROR(zz->Proc, yo, str) ; goto End ;}
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,63 @@
/*
* @HEADER
*
* ***********************************************************************
*
* Zoltan Toolkit for Load-balancing, Partitioning, Ordering and Coloring
* Copyright 2012 Sandia Corporation
*
* Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
* the U.S. Government retains certain rights in this software.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the Corporation nor the names of the
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Questions? Contact Karen Devine kddevin@sandia.gov
* Erik Boman egboman@sandia.gov
*
* ***********************************************************************
*
* @HEADER
*/
#ifndef __COLORING_CONST_H
#define __COLORING_CONST_H
#ifdef __cplusplus
/* if C++, define the rest of this header file as extern C */
extern "C" {
#endif
extern int Zoltan_Color_Set_Param(char *, char *);
#ifdef __cplusplus
} /* closing bracket for extern "C" */
#endif
#endif

View File

@ -0,0 +1,267 @@
/*
* @HEADER
*
* ***********************************************************************
*
* Zoltan Toolkit for Load-balancing, Partitioning, Ordering and Coloring
* Copyright 2012 Sandia Corporation
*
* Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
* the U.S. Government retains certain rights in this software.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the Corporation nor the names of the
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Questions? Contact Karen Devine kddevin@sandia.gov
* Erik Boman egboman@sandia.gov
*
* ***********************************************************************
*
* @HEADER
*/
#ifdef __cplusplus
/* if C++, define the rest of this header file as extern C */
extern "C" {
#endif
#include "zoltan_util.h"
#include "coloring.h"
#include "g2l_hash.h"
/*****************************************************************************/
/* Returns a prime number larger than (or equal to) stopafter,
hopefully close to stopafter. If stopafter is larger than
2147483647. 2147483647 will be returned.
*/
#define MAX_PRIME 193
int Zoltan_GenPrime(int stopafter, int *prime_num)
{
static const int primes[MAX_PRIME]=
{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 37, 41, 47, 53, 59, 67, 79, 89,
101, 113, 127, 149, 167, 191, 211, 233, 257, 283, 313, 347, 383, 431,
479, 541, 599, 659, 727, 809, 907, 1009, 1117, 1229, 1361, 1499, 1657,
1823, 2011, 2213, 2437, 2683, 2953, 3251, 3581, 3943, 4339, 4783,
5273, 5801, 6389, 7039, 7753, 8537, 9391, 10331, 11369, 12511, 13763,
15149, 16673, 18341, 20177, 22229, 24469, 26921, 29629, 32603, 35869,
39461, 43411, 47777, 52561, 57829, 63617, 69991, 76991, 84691, 93169,
102497, 112757, 124067, 136481, 150131, 165161, 181693, 199873,
219871, 241861, 266051, 292661, 321947, 354143, 389561, 428531,
471389, 518533, 570389, 627433, 690187, 759223, 835207, 918733,
1010617, 1111687, 1222889, 1345207, 1479733, 1627723, 1790501,
1969567, 2166529, 2383219, 2621551, 2883733, 3172123, 3489347,
3838283, 4222117, 4644329, 5108767, 5619667, 6181639, 6799811,
7479803, 8227787, 9050599, 9955697, 10951273, 12046403, 13251047,
14576161, 16033799, 17637203, 19400929, 21341053, 23475161, 25822679,
28404989, 31245491, 34370053, 37807061, 41587807, 45746593, 50321261,
55353391, 60888739, 66977621, 73675391, 81042947, 89147249, 98061979,
107868203, 118655027, 130520531, 143572609, 157929907, 173722907,
191095213, 210204763, 231225257, 254347801, 279782593, 307760897,
338536987, 372390691, 409629809, 450592801, 495652109, 545217341,
599739083, 659713007, 725684317, 798252779, 878078057, 965885863,
1062474559, 1168722059, 1285594279, 1414153729, 1555569107,
1711126033, 1882238639, 2070462533, 2147483647};
int uplimit=MAX_PRIME-1;
int botlimit=0;
int j;
int result=primes[uplimit];
while(1) {
if (uplimit-botlimit < 5) {
for (j = botlimit; primes[j]<= stopafter && j <= uplimit; j++);
result = (j==MAX_PRIME) ? j-1 : j;
break;
}
if (primes[botlimit + (uplimit - botlimit) / 2] < stopafter)
botlimit = botlimit + (uplimit-botlimit) / 2;
else
uplimit = uplimit - (uplimit-botlimit) / 2;
}
*prime_num = primes[result];
return ZOLTAN_OK;
}
#undef MAX_PRIME
int Zoltan_G2LHash_Create(G2LHash *hash, int maxsize, ZOLTAN_GNO_TYPE base, int nlvtx)
{
if (maxsize == 0) /* to avoid memory allocation errors */
maxsize = 1;
if (Zoltan_GenPrime(maxsize , &(hash->maxsize))==ZOLTAN_MEMERR)
return ZOLTAN_MEMERR;
hash->table = NULL;
hash->nodes = NULL;
hash->base = base;
hash->baseend = base+nlvtx-1;
hash->nlvtx = nlvtx;
hash->size = 0;
hash->num_gid_entries = sizeof(ZOLTAN_GNO_TYPE) / sizeof(ZOLTAN_ID_TYPE);
hash->table = (G2LHashNode **) ZOLTAN_CALLOC((size_t) hash->maxsize, sizeof(G2LHashNode *));
hash->nodes = (G2LHashNode *) ZOLTAN_MALLOC((size_t) hash->maxsize * (size_t) sizeof(G2LHashNode));
if (!hash->table || !hash->nodes) {
Zoltan_G2LHash_Destroy(hash);
return ZOLTAN_MEMERR;
}
return ZOLTAN_OK;
}
int Zoltan_G2LHash_Destroy(G2LHash *hash)
{
ZOLTAN_FREE(&hash->table);
ZOLTAN_FREE(&hash->nodes);
return ZOLTAN_OK;
}
int Zoltan_G2LHash_Insert(G2LHash *hash, ZOLTAN_GNO_TYPE gno)
{
int i, lno;
G2LHashNode *ptr;
if (gno<hash->base || gno>hash->baseend) {
i = Zoltan_Hash((ZOLTAN_ID_PTR) (void *)&gno, hash->num_gid_entries, (unsigned int) hash->maxsize);
for (ptr=hash->table[i]; ptr && ptr->gno!=gno; ptr = ptr->next);
if (!ptr) {
if (hash->size >= hash->maxsize) {
char st[2048];
sprintf(st, "Hash is full! #entries=%d maxsize=%d", hash->size, hash->maxsize);
ZOLTAN_PRINT_ERROR(-1, "Zoltan_G2LHash_G2L", st);
return -1;
}
ptr = &(hash->nodes[hash->size]);
ptr->gno = gno;
lno = ptr->lno = hash->nlvtx + hash->size;
ptr->next = hash->table[i];
hash->table[i] = ptr;
++hash->size;
} else
lno = ptr->lno;
} else
return gno-hash->base;
return lno;
}
int Zoltan_G2LHash_G2L(G2LHash *hash, ZOLTAN_GNO_TYPE gno)
{
int i;
G2LHashNode *ptr;
if (gno<hash->base || gno>hash->baseend) {
i = Zoltan_Hash((ZOLTAN_ID_PTR) (void *)&gno, hash->num_gid_entries, (unsigned int) hash->maxsize);
for (ptr=hash->table[i]; ptr && ptr->gno!=gno; ptr = ptr->next);
if (!ptr)
return -1;
else
return ptr->lno;
} else
return gno-hash->base;
}
/* --------------------------- KVHash -------------------------------- */
int Zoltan_KVHash_Create(KVHash *hash, int maxsize)
{
if (maxsize == 0) /* to avoid memory allocation errors */
maxsize = 1;
if (Zoltan_GenPrime(maxsize , &(hash->maxsize))==ZOLTAN_MEMERR)
return ZOLTAN_MEMERR;
hash->table = NULL;
hash->nodes = NULL;
hash->size = 0;
hash->num_gid_entries = sizeof(ZOLTAN_GNO_TYPE) / sizeof(ZOLTAN_ID_TYPE);
hash->table = (G2LHashNode **) ZOLTAN_CALLOC(hash->maxsize, sizeof(G2LHashNode *));
hash->nodes = (G2LHashNode *) ZOLTAN_MALLOC(hash->maxsize * sizeof(G2LHashNode));
if (!hash->table || !hash->nodes) {
Zoltan_G2LHash_Destroy(hash);
return ZOLTAN_MEMERR;
}
return ZOLTAN_OK;
}
int Zoltan_KVHash_Destroy(KVHash *hash)
{
ZOLTAN_FREE(&hash->table);
ZOLTAN_FREE(&hash->nodes);
return ZOLTAN_OK;
}
int Zoltan_KVHash_Insert(KVHash *hash, ZOLTAN_GNO_TYPE key, int value)
{
int i;
G2LHashNode *ptr;
i = Zoltan_Hash((ZOLTAN_ID_PTR) (void *)&key, hash->num_gid_entries, (unsigned int) hash->maxsize);
for (ptr=hash->table[i]; ptr && ptr->gno!=key; ptr = ptr->next);
if (!ptr) {
if (hash->size >= hash->maxsize) {
ZOLTAN_PRINT_ERROR(-1, "Zoltan_KVHash_Insert", "Hash is full!");
return -1;
}
ptr = &(hash->nodes[hash->size]);
ptr->gno = key;
ptr->lno = value;
ptr->next = hash->table[i];
hash->table[i] = ptr;
++hash->size;
} else
value = ptr->lno;
return value;
}
int Zoltan_KVHash_GetValue(KVHash *hash, ZOLTAN_GNO_TYPE key)
{
int i;
G2LHashNode *ptr;
i = Zoltan_Hash((ZOLTAN_ID_PTR) (void *) &key, hash->num_gid_entries, (unsigned int) hash->maxsize);
for (ptr=hash->table[i]; ptr && ptr->gno!=key; ptr = ptr->next);
if (!ptr)
return -1;
else
return ptr->lno;
}
#ifdef __cplusplus
} /* closing bracket for extern "C" */
#endif

View File

@ -0,0 +1,104 @@
/*
* @HEADER
*
* ***********************************************************************
*
* Zoltan Toolkit for Load-balancing, Partitioning, Ordering and Coloring
* Copyright 2012 Sandia Corporation
*
* Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
* the U.S. Government retains certain rights in this software.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the Corporation nor the names of the
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Questions? Contact Karen Devine kddevin@sandia.gov
* Erik Boman egboman@sandia.gov
*
* ***********************************************************************
*
* @HEADER
*/
#ifndef _G2L_HASH_H_
#define _G2L_HASH_H_
#ifdef __cplusplus
/* if C++, define the rest of this header file as extern C */
extern "C" {
#endif
/* Structure used for hashing */
struct G2L_Hash_Node {
ZOLTAN_GNO_TYPE gno; /* Global number */
int lno; /* Mapped id of gno*/
struct G2L_Hash_Node * next;
};
typedef struct G2L_Hash_Node G2LHashNode;
struct G2L_Hash {
int maxsize;
int size; /* number of ids stored in the hash */
ZOLTAN_GNO_TYPE base, baseend; /* base and baseend are inclusive gno's of local vertices */
int nlvtx; /* it is #localy owened vertices: simply equal to "baseend-base+1" */
int num_gid_entries; /* multiple of ZOLTAN_ID_TYPEs in a key */
G2LHashNode **table;
G2LHashNode *nodes;
};
typedef struct G2L_Hash G2LHash;
int Zoltan_G2LHash_Create(G2LHash *hash, int maxsize, ZOLTAN_GNO_TYPE base, int nlvtx);
int Zoltan_G2LHash_Destroy(G2LHash *hash);
int Zoltan_G2LHash_G2L(G2LHash *hash, ZOLTAN_GNO_TYPE gno);
/*
if gno exist it returns lno, if it does not exist,
it inserts andr returns newly assigned lno */
int Zoltan_G2LHash_Insert(G2LHash *hash, ZOLTAN_GNO_TYPE gno);
#define Zoltan_G2LHash_L2G(hash, lno) ((lno<(hash)->nlvtx) ? (hash)->base+lno : (hash)->nodes[lno-(hash)->nlvtx].gno)
/* Key&Value hash functions using same data structure above
the only difference will be the insert function */
typedef struct G2L_Hash KVHash;
int Zoltan_KVHash_Create(KVHash *hash, int maxsize);
int Zoltan_KVHash_Destroy(KVHash *hash);
int Zoltan_KVHash_Insert(KVHash *hash, ZOLTAN_GNO_TYPE key, int value);
int Zoltan_KVHash_GetValue(KVHash *hash, ZOLTAN_GNO_TYPE key);
#ifdef __cplusplus
} /* closing bracket for extern "C" */
#endif
#endif