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

73
thirdParty/Zoltan/src/params/README vendored Normal file
View File

@ -0,0 +1,73 @@
# @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
PARAMS DIRECTORY -- Routines for setting parameter values
----------------------------------------------------------------
Files compiled into Zoltan:
params_const.h -- Prototypes for parameter functions.
assign_param_vals.c -- Contains Zoltan_Assign_Param_Vals which loops over the
set of new parameters/values associated with an Zoltan
structure and sets those which are appropriate.
bind_param.c -- Routine to bind a parameter name to a variable.
This function must be called before
Zoltan_Assign_Param_Vals.
check_param.c -- Routine Zoltan_Check_Param compares a string against a
list of valid parameter names & checks the type for
correctness.
free_params.c -- Frees all the parameters allocated for an Zoltan struct.
key_params.c -- Set parameter values for variables in Zoltan struct.
print_params.c -- Debugging routine to print out the parameter settings.
set_param.c -- Routine Zoltan_Set_Param calls domain-specific routines
to identify a parameter being set & usually adds it to
list of modified parameters & values.

View File

@ -0,0 +1,276 @@
/*
* @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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "params_const.h"
#include "zoltan_types.h"
#include "zoltan_util.h"
#include "zz_const.h"
/*****************************************************************************/
/*** Function prototypes: ***/
/*****************************************************************************/
static void Zoltan_Print_Assigned_Param_Vals(PARAM_VARS * );
/*****************************************************************************/
/*** Local macros: ***/
/*****************************************************************************/
#define SET_PARAM_VAL(datatype,value) { \
for (i=lo; i<hi; i++) \
((datatype *) param_ptr->ptr)[i] = value; \
}
/*****************************************************************************/
/*** Function definitions: ***/
/*****************************************************************************/
int Zoltan_Assign_Param_Vals(
PARAM_LIST * change_list, /* list of parameter values being changed */
PARAM_VARS * params, /* structure describing parameters */
int debug_level, /* level for output of debugging info */
int proc, /* processor # (controls debug printing) */
int print_proc /* processor that should perform printing */
)
{
char *yo = "Zoltan_Assign_Param_Vals";
char msg[256];
char *name; /* name of parameter being reset */
char *val; /* new value for parameter */
int index; /* index of parameter entry */
int lo, hi; /* lower/upper bounds on index */
int found; /* is name found? */
int ierr; /* error code */
int i; /* loop variable */
PARAM_VARS *param_ptr; /* pointer to current param */
ierr = ZOLTAN_OK;
while (change_list != NULL) {
param_ptr = params;
name = change_list->name;
val = change_list->new_val;
index = change_list->index;
found = 0;
while (param_ptr->name != NULL) {
if (!strcmp(param_ptr->name, name)) {
found = 1;
break;
}
param_ptr++;
}
if (found) { /* name found */
/* Check that param_ptr->ptr isn't NULL */
if (param_ptr->ptr == NULL) {
ierr = ZOLTAN_WARN;
if (debug_level > 0 && proc == print_proc) {
sprintf(msg, "Parameter %s is not bound "
"to any variable. Parameter ignored.\n",
param_ptr->name);
ZOLTAN_PRINT_WARN(proc, yo, msg);
}
}
/* Check that index is in valid range */
if ((index > param_ptr->length) || (index < -1)) {
ierr = ZOLTAN_WARN;
if (debug_level > 0 && proc == print_proc) {
sprintf(msg, "Invalid index %d for parameter %s. "
"Parameter entry ignored.\n",
index, param_ptr->name);
ZOLTAN_PRINT_WARN(proc, yo, msg);
}
}
if (ierr == ZOLTAN_OK) { /* OK so far. */
if (index == -1){ /* Set all entries in a param vector. */
lo = 0;
hi = param_ptr->length;
if (hi == 0) hi = 1; /* Special case for scalar parameters. */
}
else { /* Set just one entry in the param vector. */
lo = index;
hi = lo+1;
}
/* Figure out what type it is and read value. */
if (!strcmp(param_ptr->type, "INT") ||
!strcmp(param_ptr->type, "INTEGER")) {
/* First special case if True or False */
if (*val == 'T')
SET_PARAM_VAL(int, 1)
else if (*val == 'F')
SET_PARAM_VAL(int, 0)
else {
SET_PARAM_VAL(int, atoi(val))
}
}
else if ((!strcmp(param_ptr->type, "FLOAT")) ||
(!strcmp(param_ptr->type, "REAL"))) {
SET_PARAM_VAL(float, atof(val))
}
else if (!strcmp(param_ptr->type, "DOUBLE")) {
SET_PARAM_VAL(double, atof(val))
}
else if (!strcmp(param_ptr->type, "LONG")) {
/* First special case if True or False */
if (*val == 'T')
SET_PARAM_VAL(long, 1)
else if (*val == 'F')
SET_PARAM_VAL(long, 0)
else {
SET_PARAM_VAL(long, atol(val))
}
}
else if (!strcmp(param_ptr->type, "CHAR")) {
SET_PARAM_VAL(char, (*val))
}
else if (!strcmp(param_ptr->type, "STRING")) {
/* String parameters are assumed to be scalar. */
strncpy((char *) param_ptr->ptr, val, MAX_PARAM_STRING_LEN);
}
}
}
change_list = change_list->next;
}
if (debug_level > 0 && proc == print_proc)
Zoltan_Print_Assigned_Param_Vals(params);
return ierr;
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
static void Zoltan_Print_Assigned_Param_Vals(
PARAM_VARS * params /* structure describing parameters */
)
{
/* Prints the parameter values in PARAM_VARS *param. */
PARAM_VARS *param_ptr = params; /* pointer to current param */
int i;
while (param_ptr->name != NULL) {
if (param_ptr->ptr != NULL) {
if (!strcmp(param_ptr->type, "INT") ||
!strcmp(param_ptr->type, "INTEGER")) {
if (param_ptr->length < 1)
printf("ZOLTAN Parameter %s = %d\n",
param_ptr->name, *((int *) param_ptr->ptr));
else
for (i=0; i<param_ptr->length; i++)
printf("ZOLTAN Parameter %s = %d\n",
param_ptr->name, ((int *) param_ptr->ptr)[i]);
}
else if (!strcmp(param_ptr->type, "FLOAT") ||
!strcmp(param_ptr->type, "REAL")) {
if (param_ptr->length < 1)
printf("ZOLTAN Parameter %s = %f\n",
param_ptr->name, *((float *) param_ptr->ptr));
else
for (i=0; i<param_ptr->length; i++)
printf("ZOLTAN Parameter %s = %f\n",
param_ptr->name, ((float *) param_ptr->ptr)[i]);
}
else if (!strcmp(param_ptr->type, "DOUBLE")) {
if (param_ptr->length < 1)
printf("ZOLTAN Parameter %s = %f\n",
param_ptr->name, *((double *) param_ptr->ptr));
else
for (i=0; i<param_ptr->length; i++)
printf("ZOLTAN Parameter %s = %f\n",
param_ptr->name, ((double *) param_ptr->ptr)[i]);
}
else if (!strcmp(param_ptr->type, "LONG")) {
if (param_ptr->length < 1)
printf("ZOLTAN Parameter %s = %ld\n",
param_ptr->name, *((long *) param_ptr->ptr));
else
for (i=0; i<param_ptr->length; i++)
printf("ZOLTAN Parameter %s = %ld\n",
param_ptr->name, ((long *) param_ptr->ptr)[i]);
}
else if (!strcmp(param_ptr->type, "STRING")) {
printf("ZOLTAN Parameter %s = %s\n",
param_ptr->name, (char *) param_ptr->ptr);
}
else if (!strcmp(param_ptr->type, "CHAR")) {
printf("ZOLTAN Parameter %s = %c\n",
param_ptr->name, *((char *) param_ptr->ptr));
}
}
param_ptr++;
}
}
#ifdef __cplusplus
} /* closing bracket for extern "C" */
#endif

View File

@ -0,0 +1,122 @@
/*
* @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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "zz_util_const.h"
#include "params_const.h"
#include "zoltan_mem.h"
#include "zoltan_util.h"
#include "zz_const.h"
int Zoltan_Bind_Param(
PARAM_VARS *params, /* parameter structure */
char *name, /* parameter name */
void *var /* pointer to variable to be associated
with the parameter name */
)
{
return Zoltan_Bind_Param_Vec(params, name, var, 0);
}
int Zoltan_Bind_Param_Vec(
PARAM_VARS *params, /* parameter structure */
char *name, /* parameter name */
void *var, /* pointer to variable to be associated
with the parameter name */
int dim /* dimension of parameter vector */
)
{
/*
* Function to bind a parameter name to a variable.
* On output:
* ZOLTAN_OK indicates success.
* ZOLTAN_WARN indicates that parameter name was not found (misspelled?).
* No binding took place. A warning message is printed in this case.
* ZOLTAN_FATAL signals something more serious.
*/
char *yo = "Zoltan_Bind_Param";
char msg[256];
char *name2; /* clean version of name */
int flag; /* return value from function */
PARAM_VARS *ptr; /* pointer to a parameter */
/* First convert to upper case & remove leading white space. */
flag = Zoltan_Clean_String(name, &name2);
if (flag)
return (flag);
/* Search through parameter array to find name2 */
for (ptr = params; ptr->name != NULL; ptr++) {
if (!strcmp(name2, ptr->name)) { /* string match */
ptr->ptr = var;
ptr->length = dim;
ZOLTAN_FREE(&name2);
return (ZOLTAN_OK);
}
}
/* If we reach this point, the parameter name must be invalid */
sprintf(msg, "Parameter name %s not found; it will"
"not be bound to any variable.", name2);
ZOLTAN_PRINT_WARN(-1, yo, msg);
ZOLTAN_FREE(&name2);
return (ZOLTAN_WARN);
}
#ifdef __cplusplus
} /* closing bracket for extern "C" */
#endif

View File

@ -0,0 +1,175 @@
/*
* @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 <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "params_const.h"
#include "zoltan_util.h"
#include "zz_const.h"
int Zoltan_Check_Param(
const char *name, /* name of parameter being reset */
const char *val, /* new value for parameter */
PARAM_VARS * params, /* structure describing parameters */
PARAM_UTYPE *result, /* pointer to return value */
int *matched_index) /* where in struct the match occurs */
{
char *yo = "Zoltan_Check_Param";
char msg[256];
int i; /* loop counter */
int status; /* return code: */
/* 0 => name found and value OK */
/* 1 => name not found */
/* 2 => name found, but value bad */
status = 1;
i = 0;
while (params->name != NULL) {
if (!strcmp(params->name, name)) {
status = 0;
break;
}
i++;
params++;
}
if (status == 0) { /* name found */
*matched_index = i;
if (!strcmp(val, "DEFAULT")){
result->def = 1;
}
else {
/* Figure out what type it is and read value. */
result->def = 0;
if (!strcmp(params->type, "INT") || !strcmp(params->type, "INTEGER")) {
/* First special case if True or False */
if (*val == 'T')
(*result).ival = 1;
else if (*val == 'F')
(*result).ival = 0;
else {
/* Check that there's a digit here */
for (i = strlen(val); i >= 0; i--)
if (isdigit((int)(val[i])))
break;
if (i < 0)
status = 2;
else {
(*result).ival = atoi(val);
}
}
}
else if ((!strcmp(params->type, "FLOAT")) ||
(!strcmp(params->type, "REAL")) ||
(!strcmp(params->type, "DOUBLE"))) {
/* Check that there's a digit here */
for (i = strlen(val); i >= 0; i--)
if (isdigit((int)(val[i])))
break;
if (i < 0)
status = 2;
else {
(*result).fval = atof(val);
(*result).dval = atof(val);
}
}
else if (!strcmp(params->type, "LONG")) {
/* First special case if True or False */
if (*val == 'T')
(*result).lval = 1;
else if (*val == 'F')
(*result).lval = 0;
else {
/* Check that there's a digit here */
for (i = strlen(val); i >= 0; i--)
if (isdigit((int)(val[i])))
break;
if (i < 0)
status = 2;
else {
(*result).lval = atol(val);
}
}
}
else if (!strcmp(params->type, "STRING")) {
strncpy((*result).sval, val, MAX_PARAM_STRING_LEN);
}
else if (!strcmp(params->type, "CHAR")) {
(*result).cval = *val;
}
else {
sprintf(msg, "Bad type for parameter `%s'",
params->name);
ZOLTAN_PRINT_WARN(-1, yo, msg);
status = 2;
}
}
}
else { /* name not matched */
*matched_index = -1;
}
return (status);
}
#ifdef __cplusplus
} /* closing bracket for extern "C" */
#endif

View File

@ -0,0 +1,183 @@
/*
* @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 <stdio.h>
#include <stdlib.h>
#include "params_const.h"
#include "zoltan_mem.h"
#include "zoltan_types.h"
#include "zz_util_const.h"
#include "zz_const.h"
void Zoltan_Free_Params(
PARAM_LIST **params) /* parameters structure */
{
/*
* Free the list of new parameter values.
*/
PARAM_LIST *ptr, *next;
if (params == NULL) return;
ptr = *params;
while (ptr != NULL) {
next = ptr->next;
ZOLTAN_FREE(&(ptr->name));
ZOLTAN_FREE(&(ptr->new_val));
ZOLTAN_FREE(&ptr);
ptr = next;
}
*params = NULL;
}
size_t Zoltan_Serialize_Params_Size(struct Zoltan_Struct const *from)
{
/* Count the number of parameters */
PARAM_LIST const *param = from->Params;
int nParam = 0;
while (param) {
nParam++;
param = param->next;
}
return sizeof(int) /* to store number of params */
+ nParam * (MAX_PARAM_STRING_LEN * 2); /* max per param: (name, value) */
}
int Zoltan_Serialize_Params(struct Zoltan_Struct const *from, char **buf)
{
/* Serialize the parameters */
char *bufptr = *buf;
PARAM_LIST const *param = from->Params;
size_t paramSize = Zoltan_Serialize_Params_Size(from);
/* Pack number of parameters */
int nParam = paramSize / (MAX_PARAM_STRING_LEN * 2);
*((int *) bufptr) = nParam;
bufptr += sizeof(int);
/* Pack each parameter, using max string length bytes per string */
while (param) {
strcpy(bufptr, param->name);
bufptr += MAX_PARAM_STRING_LEN;
strcpy(bufptr, param->new_val);
bufptr += MAX_PARAM_STRING_LEN;
param = param->next;
}
*buf = bufptr;
}
int Zoltan_Deserialize_Params(struct Zoltan_Struct *to, char **buf)
{
/* Serialize the parameters */
char *bufptr = *buf;
int i;
/* Unpack number of parameters */
int nParam = *((int *)bufptr);
bufptr += sizeof(int);
/* Unpack parameters' (name, value) pairs and set them */
for (i = 0; i < nParam; i++) {
char *pname = bufptr;
char *pval = bufptr + MAX_PARAM_STRING_LEN;
Zoltan_Set_Param(to, pname, pval);
bufptr += 2 * MAX_PARAM_STRING_LEN;
}
*buf = bufptr;
}
int Zoltan_Copy_Params(PARAM_LIST **to, PARAM_LIST const *from)
{
PARAM_LIST *param;
PARAM_LIST *prev;
if (*to != NULL) {
Zoltan_Free_Params(to);
}
prev = NULL;
while (from) {
param = (PARAM_LIST *) ZOLTAN_MALLOC(sizeof(PARAM_LIST));
if (param == NULL) {
Zoltan_Free_Params(to);
return ZOLTAN_MEMERR;
}
param->name = Zoltan_Strdup(from->name);
param->new_val = Zoltan_Strdup(from->new_val);
param->index = from->index;
param->next = NULL;
if (prev){
prev->next = param;
}
from = from->next;
prev = param;
if (*to == NULL){
*to = param;
}
}
return ZOLTAN_OK;
}
#ifdef __cplusplus
} /* closing bracket for extern "C" */
#endif

View File

@ -0,0 +1,517 @@
/*
* @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 <stdio.h>
#include "zz_util_const.h"
#include "key_params.h"
#include "params_const.h"
#include "timer_const.h"
#include "zz_rand.h"
#include "third_library_const.h"
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
static PARAM_VARS Key_params[] = {
{ "IMBALANCE_TOL", NULL, "FLOAT", 1 },
{ "AUTO_MIGRATE", NULL, "INT", 0 },
{ "OBJ_WEIGHT_DIM", NULL, "INT", 0 },
{ "EDGE_WEIGHT_DIM", NULL, "INT", 0 },
{ "DEBUG_LEVEL", NULL, "INT", 0 },
{ "DEBUG_PROCESSOR", NULL, "INT", 0 },
{ "DETERMINISTIC", NULL, "INT", 0 },
{ "TIMER", NULL, "STRING", 0 },
{ "NUM_GID_ENTRIES", NULL, "INT", 0 },
{ "NUM_LID_ENTRIES", NULL, "INT", 0 },
{ "RETURN_LISTS", NULL, "STRING", 0 },
{ "LB_METHOD", NULL, "STRING", 0 },
{ "TFLOPS_SPECIAL", NULL, "INT", 0 },
{ "COMM_WEIGHT_DIM", NULL, "INT", 0 }, /* For backward compatibility only. */
/* Prefer use of EDGE_WEIGHT_DIM. */
{ "NUM_GLOBAL_PARTS", NULL, "INT", 0 },
{ "NUM_GLOBAL_PARTITIONS", NULL, "INT", 0 }, /* Deprecated */
{ "NUM_LOCAL_PARTS", NULL, "INT", 0 },
{ "NUM_LOCAL_PARTITIONS", NULL, "INT", 0 }, /* Deprecated */
{ "MIGRATE_ONLY_PROC_CHANGES", NULL, "INT", 0 },
{ "REMAP", NULL, "INT", 0 },
{ "SEED", NULL, "INT", 0 },
{ "LB_APPROACH", NULL, "STRING", 0 },
{ NULL, NULL, NULL, 0 } };
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*
* Handle parameter changes for variables stored in Zoltan structure.
*/
int Zoltan_Set_Key_Param(
ZZ *zz, /* Zoltan structure */
const char *name, /* name of variable */
const char *val, /* value of variable */
int idx /* index of vector param, -1 if scalar */
)
{
char *yo = "Zoltan_Set_Key_Param";
char msg[256];
int status; /* return code */
PARAM_UTYPE result; /* value returned from Check_Param */
int index; /* index returned from Check_Param */
int tmp;
int export, import;
status = Zoltan_Check_Param(name, val, Key_params, &result, &index);
if (status == 0) {
switch (index) {
case 0: /* Imbalance_Tol */
if (result.def)
result.fval = ZOLTAN_LB_IMBALANCE_TOL_DEF;
if (result.fval < 1.0) {
sprintf(msg, "Invalid Imbalance_Tol value (%g) "
"being set to %g.", result.fval, ZOLTAN_LB_IMBALANCE_TOL_DEF);
ZOLTAN_PRINT_WARN(zz->Proc, yo, msg);
result.fval = ZOLTAN_LB_IMBALANCE_TOL_DEF;
}
if (idx > zz->Obj_Weight_Dim){
sprintf(msg, "Imbalance_Tol index %d > Obj_Weight_Dim = %d\n",
idx, zz->Obj_Weight_Dim);
ZOLTAN_PRINT_WARN(zz->Proc, yo, msg);
}
else if (idx < -1){
sprintf(msg, "Invalid Imbalance_Tol index %d\n", idx);
ZOLTAN_PRINT_WARN(zz->Proc, yo, msg);
}
else if (idx == -1){
/* Set all entries to the same value. */
for (idx=0; idx<zz->LB.Imb_Tol_Len; idx++)
zz->LB.Imbalance_Tol[idx] = result.fval;
}
else
zz->LB.Imbalance_Tol[idx] = result.fval;
status = 3; /* Don't add to Params field of ZZ */
break;
case 1: /* Help_Migrate */
if (result.def)
result.ival = ZOLTAN_AUTO_MIGRATE_DEF;
zz->Migrate.Auto_Migrate = result.ival;
status = 3; /* Don't add to Params field of ZZ */
break;
case 2: /* Object weight dim. */
if (result.def)
result.ival = ZOLTAN_OBJ_WEIGHT_DEF;
if (result.ival < 0) {
sprintf(msg, "Invalid Obj_Weight_Dim value (%d) "
"being set to %d.", result.ival, ZOLTAN_OBJ_WEIGHT_DEF);
ZOLTAN_PRINT_WARN(zz->Proc, yo, msg);
result.ival = ZOLTAN_OBJ_WEIGHT_DEF;
}
zz->Obj_Weight_Dim = result.ival;
if (zz->Obj_Weight_Dim > zz->LB.Imb_Tol_Len){
/* Resize and reallocate Imb_Tol. */
zz->LB.Imb_Tol_Len += 10;
zz->LB.Imbalance_Tol = (float *) ZOLTAN_REALLOC(zz->LB.Imbalance_Tol, zz->LB.Imb_Tol_Len * sizeof(float));
}
status = 3; /* Don't add to Params field of ZZ */
break;
case 3: /* Edge weight dim. */
case 13:
if (result.def)
result.ival = ZOLTAN_EDGE_WEIGHT_DEF;
if (result.ival < 0) {
sprintf(msg, "Invalid Edge_Weight_Dim value (%d) "
"being set to %d.", result.ival, ZOLTAN_EDGE_WEIGHT_DEF);
ZOLTAN_PRINT_WARN(zz->Proc, yo, msg);
result.ival = ZOLTAN_EDGE_WEIGHT_DEF;
}
zz->Edge_Weight_Dim = result.ival;
status = 3; /* Don't add to Params field of ZZ */
break;
case 4: /* Debug level */
if (result.def)
result.ival = ZOLTAN_DEBUG_LEVEL_DEF;
if (result.ival < 0) {
sprintf(msg, "Invalid Debug_Level value (%d) "
"being set to %d.", result.ival, ZOLTAN_DEBUG_LEVEL_DEF);
ZOLTAN_PRINT_WARN(zz->Proc, yo, msg);
result.ival = ZOLTAN_DEBUG_LEVEL_DEF;
}
zz->Debug_Level = result.ival;
status = 3; /* Don't add to Params field of ZZ */
break;
case 5: /* Debug processor */
if (result.def)
result.ival = ZOLTAN_DEBUG_PROC_DEF;
if (result.ival < 0 || result.ival > zz->Num_Proc) {
sprintf(msg, "Invalid Debug_Processor value (%d) "
"being set to %d.", result.ival, ZOLTAN_DEBUG_PROC_DEF);
ZOLTAN_PRINT_WARN(zz->Proc, yo, msg);
result.ival = ZOLTAN_DEBUG_PROC_DEF;
}
zz->Debug_Proc = result.ival;
status = 3; /* Don't add to Params field of ZZ */
break;
case 6: /* Deterministic flag */
if (result.def)
result.ival = ZOLTAN_DETERMINISTIC_DEF;
if (result.ival < 0) {
sprintf(msg, "Invalid Deterministic value (%d) "
"being set to %d.", result.ival, ZOLTAN_DETERMINISTIC_DEF);
ZOLTAN_PRINT_WARN(zz->Proc, yo, msg);
result.ival = ZOLTAN_DETERMINISTIC_DEF;
}
zz->Deterministic = result.ival;
status = 3; /* Don't add to Params field of ZZ */
break;
case 7: /* Timer */
status = Zoltan_Set_Timer_Param(name, val, &tmp);
zz->Timer = tmp;
Zoltan_Timer_ChangeFlag(zz->ZTime, zz->Timer);
if (status==0) status = 3; /* Don't add to Params field of ZZ */
break;
case 8: /* Num_GID_Entries */
if (result.def)
result.ival = ZOLTAN_NUM_ID_ENTRIES_DEF;
if (result.ival < 1) {
sprintf(msg, "Invalid Num_GID_Entries value (%d); "
"being set to %d.", result.ival, ZOLTAN_NUM_ID_ENTRIES_DEF);
ZOLTAN_PRINT_WARN(zz->Proc, yo, msg);
result.ival = ZOLTAN_NUM_ID_ENTRIES_DEF;
}
zz->Num_GID = result.ival;
status = 3;
break;
case 9: /* Num_LID_Entries */
if (result.def)
result.ival = ZOLTAN_NUM_ID_ENTRIES_DEF;
if (result.ival < 0) {
sprintf(msg, "Invalid Num_LID_Entries value (%d); "
"being set to %d.", result.ival, ZOLTAN_NUM_ID_ENTRIES_DEF);
ZOLTAN_PRINT_WARN(zz->Proc, yo, msg);
result.ival = ZOLTAN_NUM_ID_ENTRIES_DEF;
}
zz->Num_LID = result.ival;
status = 3;
break;
case 10: /* LB.Return_Lists */
export = (strstr(result.sval, "EXPORT") != NULL);
import = (strstr(result.sval, "IMPORT") != NULL);
if ((export && import) || (strcmp(result.sval, "ALL") == 0)) {
tmp = ZOLTAN_LB_ALL_LISTS; /* export AND import lists */
status = 3;
}
else if (import){
tmp = ZOLTAN_LB_IMPORT_LISTS; /* import lists */
status = 3;
}
else if (export){
tmp = ZOLTAN_LB_EXPORT_LISTS; /* export lists */
status = 3;
}
else if (strstr(result.sval, "PART")!=NULL) {
/* list of every object's part assignment */
tmp = ZOLTAN_LB_COMPLETE_EXPORT_LISTS;
status = 3;
}
else if (strcmp(result.sval, "NONE")==0) {
tmp = ZOLTAN_LB_NO_LISTS; /* no lists */
status = 3;
}
else if (strcmp(result.sval, "CANDIDATE_LISTS")==0) {
tmp = ZOLTAN_LB_CANDIDATE_LISTS; /* candidates needed in matching */
status = 3;
}
else{
tmp = ZOLTAN_LB_RETURN_LISTS_DEF;
sprintf(msg, "Unknown return_lists option %s.", result.sval);
ZOLTAN_PRINT_WARN(zz->Proc, yo, msg);
status = 2; /* Illegal parameter */
}
zz->LB.Return_Lists = tmp;
break;
case 11: /* LB_Method */
if (result.def)
strcpy(result.sval, "RCB");
status = Zoltan_LB_Set_LB_Method(zz,result.sval);
if (status == ZOLTAN_OK)
status = 3;
break;
case 12: /* Tflops Special flag */
if (result.def)
result.ival = ZOLTAN_TFLOPS_SPECIAL_DEF;
if (result.ival < 0) {
sprintf(msg, "Invalid Tflops Special value (%d) "
"being set to %d.", result.ival, ZOLTAN_TFLOPS_SPECIAL_DEF);
ZOLTAN_PRINT_WARN(zz->Proc, yo, msg);
result.ival = ZOLTAN_TFLOPS_SPECIAL_DEF;
}
zz->Tflops_Special = result.ival;
status = 3; /* Don't add to Params field of ZZ */
break;
case 14: /* Num_Global_Parts */
case 15:
if (result.def)
result.ival = zz->Num_Proc;
if (result.ival < 1) {
sprintf(msg, "Invalid Num_Global_Parts value (%d); "
"being set to %d.", result.ival,zz->Num_Proc);
ZOLTAN_PRINT_WARN(zz->Proc, yo, msg);
result.ival = zz->Num_Proc;
}
zz->LB.Num_Global_Parts_Param = result.ival;
status = 3;
break;
case 16: /* Num_Local_Parts */
case 17:
if (result.def)
result.ival = -1;
if (result.ival < -1) {
sprintf(msg, "Invalid Num_Local_Parts value (%d); "
"being set to %d.", result.ival,-1);
ZOLTAN_PRINT_WARN(zz->Proc, yo, msg);
result.ival = -1;
}
zz->LB.Num_Local_Parts_Param = result.ival;
status = 3;
break;
case 18: /* Migrate_Only_Proc_Changes */
if (result.def)
result.ival = ZOLTAN_MIGRATE_ONLY_PROC_CHANGES_DEF;
zz->Migrate.Only_Proc_Changes = result.ival;
status = 3; /* Don't add to Params field of ZZ */
break;
case 19: /* LB.Remap */
if (result.def)
result.ival = 0;
zz->LB.Remap_Flag = result.ival;
status = 3; /* Don't add to Params field of ZZ */
break;
case 20: /* Seed */
if (result.def)
result.ival = Zoltan_Seed();
zz->Seed = result.ival;
Zoltan_Srand(result.ival, NULL);
status = 3;
break;
case 21: /* LB_APPROACH */
if (result.def)
strcpy(result.sval, ZOLTAN_LB_APPROACH_DEF);
strcpy(zz->LB.Approach, result.sval);
status = 3;
break;
} /* end switch (index) */
}
return(status);
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*
* Print key parameters.
*/
void Zoltan_Print_Key_Params(ZZ const *zz)
{
int i;
for (i=0; i<(zz->Obj_Weight_Dim?zz->Obj_Weight_Dim:1); i++)
printf("ZOLTAN Parameter %s[%1d] = %f\n", Key_params[0].name,
i, zz->LB.Imbalance_Tol[i]);
printf("ZOLTAN Parameter %s = %s\n", Key_params[1].name,
(zz->Migrate.Auto_Migrate ? "TRUE" : "FALSE"));
printf("ZOLTAN Parameter %s = %d\n", Key_params[18].name,
zz->Migrate.Only_Proc_Changes);
printf("ZOLTAN Parameter %s = %d\n", Key_params[2].name,
zz->Obj_Weight_Dim);
printf("ZOLTAN Parameter %s = %d\n", Key_params[3].name,
zz->Edge_Weight_Dim);
printf("ZOLTAN Parameter %s = %d\n", Key_params[4].name,
zz->Debug_Level);
printf("ZOLTAN Parameter %s = %d\n", Key_params[5].name,
zz->Debug_Proc);
printf("ZOLTAN Parameter %s = %s\n", Key_params[6].name,
(zz->Deterministic ? "TRUE" : "FALSE"));
printf("ZOLTAN Parameter %s = %d ", Key_params[7].name, zz->Timer);
if (zz->Timer == ZOLTAN_TIME_WALL)
printf("(wall)");
else if (zz->Timer == ZOLTAN_TIME_CPU)
printf("(cpu)");
printf("\n");
printf("ZOLTAN Parameter %s = %d\n", Key_params[8].name,
zz->Num_GID);
printf("ZOLTAN Parameter %s = %d\n", Key_params[9].name,
zz->Num_LID);
printf("ZOLTAN Parameter %s = ", Key_params[10].name);
switch (zz->LB.Return_Lists) {
case ZOLTAN_LB_ALL_LISTS:
printf("IMPORT AND EXPORT\n");
break;
case ZOLTAN_LB_IMPORT_LISTS:
printf("IMPORT\n");
break;
case ZOLTAN_LB_EXPORT_LISTS:
printf("EXPORT\n");
break;
case ZOLTAN_LB_COMPLETE_EXPORT_LISTS:
printf("PARTITION ASSIGNMENTS\n");
break;
case ZOLTAN_LB_CANDIDATE_LISTS:
printf("CANDIDATE LISTS\n");
break;
case ZOLTAN_LB_NO_LISTS:
printf("NONE\n");
break;
}
if (zz->Tflops_Special) /* print only if set */
printf("ZOLTAN Parameter %s = %s\n", Key_params[12].name, "TRUE");
printf("ZOLTAN Parameter %s = %d\n", Key_params[14].name,
zz->LB.Num_Global_Parts_Param);
printf("ZOLTAN Parameter %s = %d\n", Key_params[16].name,
zz->LB.Num_Local_Parts_Param);
printf("ZOLTAN Parameter %s = %d\n", Key_params[19].name,
zz->LB.Remap_Flag);
printf("ZOLTAN Parameter %s = %d (%u)\n", Key_params[20].name,
Zoltan_Seed(), Zoltan_Seed());
printf("ZOLTAN Parameter %s = %s\n", Key_params[21].name,
zz->LB.Approach);
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*
* Print some compile time configuration information.
*/
void Zoltan_Print_Configuration(char *indent)
{
if (indent == NULL){
indent = "";
}
printf("\n%sBuild configuration:\n", indent);
printf("%sZOLTAN_ID_TYPE: %s (%lu bytes)\n",
indent, zoltan_id_datatype_name, (unsigned long)(sizeof(ZOLTAN_ID_TYPE)));
printf("%sZOLTAN_GNO_TYPE: %s, (%lu bytes)\n",
indent, zoltan_gno_datatype_name, (unsigned long)(sizeof(ZOLTAN_GNO_TYPE)));
printf("%sMPI_Datatype for ZOLTAN_ID_TYPE: %s\n", indent,
zoltan_mpi_id_datatype_name);
printf("%sMPI_Datatype for ZOLTAN_GNO_TYPE: %s\n", indent,
Zoltan_mpi_gno_name());
/* Metis and ParMetis have different version numbers. Some
* older versions do not define version numbers.
*/
#ifdef ZOLTAN_PARMETIS
printf("%sThird party library: ParMetis ", indent);
printf("version %d.%d", PARMETIS_MAJOR_VERSION, PARMETIS_MINOR_VERSION);
#ifdef PARMETIS_SUBMINOR_VERSION
printf(".%d", PARMETIS_SUBMINOR_VERSION);
#endif
printf("\n");
#endif
#ifdef ZOLTAN_METIS
#ifdef METISTITLE
printf("%sThird party library: %s\n",indent, METISTITLE);
#else
printf("%sThird party library: METIS\n",indent);
#endif
#endif
/* Scotch and PTScotch have the same version number. Version
* numbers are not defined in older versions.
*/
#ifdef ZOLTAN_PTSCOTCH
printf("%sThird party library: PTScotch ", indent);
#ifdef SCOTCH_VERSION
printf("version %d_%d_%d\n",
SCOTCH_VERSION, SCOTCH_RELEASE, SCOTCH_PATCHLEVEL);
#endif
#endif
#ifdef ZOLTAN_SCOTCH
printf("%sThird party library: Scotch ", indent);
#ifdef SCOTCH_VERSION
printf("version %d_%d_%d\n",
SCOTCH_VERSION, SCOTCH_RELEASE, SCOTCH_PATCHLEVEL);
#endif
#endif
#if defined(ZOLTAN_PARMETIS) || defined(ZOLTAN_METIS) || defined(ZOLTAN_SCOTCH) || defined(ZOLTAN_PTSCOTCH)
printf("%s sizeof indextype = %lu\n", indent, sizeof(indextype));
printf("%s sizeof realtype = %lu\n", indent, sizeof(realtype));
#endif
}
#ifdef __cplusplus
} /* closing bracket for extern "C" */
#endif

View File

@ -0,0 +1,68 @@
/*
* @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 __KEY_PARAMS_H
#define __KEY_PARAMS_H
#include "zz_const.h"
#ifdef __cplusplus
/* if C++, define the rest of this header file as extern C */
extern "C" {
#endif
extern int Zoltan_Set_Key_Param(ZZ *, const char *, const char *, int);
extern void Zoltan_Print_Key_Params(ZZ const *);
extern void Zoltan_Print_Configuration(char *indent);
extern int Zoltan_Filter_Params(ZZ *, ZZ *, PARAM_VARS *, int , int, int);
#ifdef __cplusplus
} /* closing bracket for extern "C" */
#endif
#endif

View File

@ -0,0 +1,134 @@
/*
* @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
*/
#include <stdlib.h>
#ifndef __PARAMS_CONST_H
#define __PARAMS_CONST_H
#ifdef __cplusplus
/* if C++, define the rest of this header file as extern C */
extern "C" {
#endif
#ifndef HAVE_PROTOTYPES
# if defined(__STDC__) || defined(__GNUC__) || defined(__cplusplus) || defined(c_plusplus)
# define HAVE_PROTOTYPES
# endif
#endif
#undef PROTO
#ifdef HAVE_PROTOTYPES
# define PROTO(x) x
#else
# define PROTO(x) ()
#endif
/*
* Type used to pass list of available parameters to lower routines.
*/
typedef struct Param_Vars {
char *name; /* Parameter variable name (all CAPS) */
void *ptr; /* Pointer to parameter variable */
char *type; /* type of parameter: */
/* INT, FLOAT, DOUBLE, LONG, STRING, or CHAR */
int length; /* length of vector; 0 if scalar */
} PARAM_VARS;
/* string length limit for param val. Allocate space of this + 1 */
#define MAX_PARAM_STRING_LEN 50
/* Universal parameter value struct. (This can be a C union to save space.) */
typedef struct Param_Utype {
int def; /* default flag */
int ival;
float fval;
double dval;
long lval;
char sval[MAX_PARAM_STRING_LEN];
char cval;
} PARAM_UTYPE;
/*
* Type used to store linked list of new values for parameters.
*/
typedef struct Param_List {
char *name;
int index;
char *new_val;
struct Param_List *next;
} PARAM_LIST;
/* API for general parameter setting functions */
typedef int ZOLTAN_SET_PARAM_FN(char *, char *);
typedef int ZOLTAN_SET_PARAM_VEC_FN(char *, int, char *);
/* function declarations for parameter modification routines */
extern int Zoltan_Assign_Param_Vals(PARAM_LIST *, PARAM_VARS *, int, int, int);
extern int Zoltan_Bind_Param(PARAM_VARS *, char *, void *);
extern int Zoltan_Bind_Param_Vec(PARAM_VARS *, char *, void *, int);
extern void Zoltan_Print_Params(PARAM_LIST *ptr);
extern int Zoltan_Check_Param(const char *, const char *, PARAM_VARS *,
PARAM_UTYPE *, int *);
extern void Zoltan_Free_Params(PARAM_LIST **);
extern int Zoltan_Copy_Params(PARAM_LIST **to, PARAM_LIST const *from);
/* Functions to serialize; need forward declaration of Zoltan_Struct */
struct Zoltan_Struct;
extern size_t Zoltan_Serialize_Params_Size(struct Zoltan_Struct const *);
extern int Zoltan_Serialize_Params(struct Zoltan_Struct const *, char **);
extern int Zoltan_Deserialize_Params(struct Zoltan_Struct *, char **);
#ifdef __cplusplus
} /* closing bracket for extern "C" */
#endif
#endif

View File

@ -0,0 +1,76 @@
/*
* @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 <stdio.h>
#include "params_const.h"
#include "zz_const.h"
void Zoltan_Print_Params(
PARAM_LIST *ptr) /* pointer to list of parameters */
{
/*
* Function to print out list of set parameter values.
*/
printf("Parameter Settings\n");
while (ptr != NULL) {
printf("%s = %s\n",ptr->name, ptr->new_val);
ptr = ptr->next;
}
printf("\n");
}
#ifdef __cplusplus
} /* closing bracket for extern "C" */
#endif

355
thirdParty/Zoltan/src/params/set_param.c vendored Normal file
View File

@ -0,0 +1,355 @@
/*
* @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 <stdio.h>
#include <string.h>
#include "key_params.h"
#include "zz_util_const.h"
#include "params_const.h"
#include "rcb_const.h"
#include "reftree_const.h"
#include "ha_const.h"
#include "rib_const.h"
#include "simple_const.h"
#include "hsfc_const.h"
#include "all_allo_const.h"
#include "order_const.h"
#include "phg_const.h"
#include "graph_const.h"
#include "hier.h"
#ifdef ZOLTAN_OVIS
#include "ha_ovis.h"
#endif
#include "coloring_const.h"
#include "zz_const.h"
static int add_param(ZZ *, char **, char **, int);
static int remove_param(ZZ *, char *, int);
/* List of set_parameter functions to be called */
static ZOLTAN_SET_PARAM_FN * Param_func[] = {
Zoltan_Set_Malloc_Param,
Zoltan_RCB_Set_Param,
Zoltan_Third_Set_Param,
#if defined(ZOLTAN_PARMETIS)
Zoltan_ParMetis_Set_Param,
#endif
#if defined(ZOLTAN_SCOTCH) || defined(ZOLTAN_PTSCOTCH)
Zoltan_Scotch_Set_Param,
#endif
Zoltan_Reftree_Set_Param,
Zoltan_RIB_Set_Param,
Zoltan_HSFC_Set_Param,
Zoltan_Order_Set_Param,
Zoltan_PHG_Set_Param,
Zoltan_Hier_Set_Param,
#ifdef ZOLTAN_OVIS
Zoltan_OVIS_Set_Param,
#endif
Zoltan_ZG_Set_Param,
/* Zoltan_Set_Machine_Param, */
Zoltan_Color_Set_Param,
/*** Add your new parameter setting function here! ***/
Zoltan_Graph_Package_Set_Param,
Zoltan_Random_Set_Param,
NULL /* Last entry _must_ be NULL! */
};
int Zoltan_Set_Param(
ZZ *zz, /* Zoltan structure */
const char *name1, /* parameter name */
const char *val1) /* value to set this parameter to */
{
return Zoltan_Set_Param_Vec(zz, name1, val1, -1);
}
int Zoltan_Set_Param_Vec(
ZZ *zz, /* Zoltan structure */
const char *name1, /* parameter name */
const char *val1, /* value to set this parameter to */
int index /* index of vector parameter; -1 if scalar */
)
{
/*
* Function to set a parameter value.
* On output:
* ZOLTAN_OK indicates success.
* ZOLTAN_WARN indicates that parameter was not set properly (misspelled?).
* A warning message is printed in this case.
* ZOLTAN_FATAL signals something more serious.
*/
char *yo = "Zoltan_Set_Param_Vec";
char msg[256];
char *name, *val; /* clean versions of name1, val1 */
int flag; /* return value from function */
int status; /* has character string been matched? */
ZOLTAN_SET_PARAM_FN **func; /* pointer to parameter setting functions */
/* Status flag is used as follows:
* 0 -> matched and value passed all checks.
* 1 -> not matched.
* 2 -> matched, but failed checks.
* 3 -> matched and OK, but don't add it to params list.
* other -> more serious error (Zoltan return codes) */
/* First convert to upper case & remove leading white space. */
flag = Zoltan_Clean_String(name1, &name);
if (flag)
return (flag);
flag = Zoltan_Clean_String(val1, &val);
if (flag) {
ZOLTAN_FREE(&name);
return (flag);
}
/* Call the key parameter routine. This one is Zoltan-specific. */
/* Currently, only Set_Key_Param allows vector parameters. */
status = Zoltan_Set_Key_Param(zz, name, val, index);
/* Now call all the other parameter setting routines. */
/* Note that we don't pass on the index since vector parameters
are currently only supported for key parameters. */
for (func = Param_func; (status == 1) && (*func != NULL); func++) {
status = (**func)(name, val);
}
/* All parameter setting routines have been called, now finish up. */
if (status == 1) { /* Parameter name never found */
sprintf(msg, "Parameter `%s' not found; not reset to `%s'.\n",
name, val);
ZOLTAN_PRINT_WARN(zz->Proc, yo, msg);
ZOLTAN_FREE(&name);
ZOLTAN_FREE(&val);
}
else if (status == 2) {
sprintf(msg, "Invalid value `%s' for parameter `%s'; default "
"value will be used.\n", val, name);
ZOLTAN_PRINT_WARN(zz->Proc, yo, msg);
ZOLTAN_FREE(&name);
ZOLTAN_FREE(&val);
}
else {
if (!strcmp(val, "DEFAULT")){
remove_param(zz, name, index); /* Remove parameter from list */
status = 0; /* "DEFAULT" is always valid */
ZOLTAN_FREE(&name);
ZOLTAN_FREE(&val);
}
else if (status == 0){ /* Parameter OK */
add_param(zz, &name, &val, index); /* Add parameter to list */
}
else { /* Parameter not OK. Don't add. */
ZOLTAN_FREE(&name); /* (It may be used to set values */
ZOLTAN_FREE(&val); /* directly in zz rather than in */
/* the parameter list.) */
}
}
if (status == 0 || status == 3)
flag = ZOLTAN_OK;
else if (status == 1 || status == 2)
flag = ZOLTAN_WARN;
else
flag = status;
return (flag);
}
static int add_param(
ZZ *zz, /* Zoltan structure */
char **name, /* parameter name */
char **val, /* value to set this parameter to */
int index /* index of vector parameter; -1 if scalar */
)
{
/*
* Parameter checked out OK. Add it to linked list of param values.
* Search through existing list to replace value if its there.
* Otherwise, add it to the end of the list.
*/
PARAM_LIST *ptr; /* loops through parameter list */
PARAM_LIST *param; /* parameter entry in list */
/* printf("Debug: Adding parameter %s with value %s and index %d\n",
*name, *val, index); */
ptr = zz->Params;
while (ptr != NULL) {
if ((!strcmp(*name, ptr->name)) && (index == ptr->index)){
/* string and index match */
ZOLTAN_FREE(name);
ZOLTAN_FREE(&(ptr->new_val));
ptr->new_val = *val;
return (ZOLTAN_OK);
}
ptr = ptr->next;
}
/* This is a new parameter, add it to list. */
param = (PARAM_LIST *) ZOLTAN_MALLOC(sizeof(PARAM_LIST));
if (param == NULL) {
ZOLTAN_FREE(name);
ZOLTAN_FREE(val);
return (ZOLTAN_MEMERR);
}
ptr = zz->Params;
zz->Params = param;
param->next = ptr;
param->name = *name;
param->index = index;
param->new_val = *val;
return (ZOLTAN_OK);
}
static int remove_param(
ZZ *zz, /* Zoltan structure */
char *name, /* parameter name */
int index /* index for vector param; -1 for scalars */
)
{
/*
* Parameter checked out OK. Remove it from linked list of param values.
* If it is not in the list, do nothing.
*/
PARAM_LIST *ptr, *oldptr; /* loops through parameter list */
oldptr = NULL;
ptr = zz->Params;
while (ptr != NULL) {
if ((!strcmp(name, ptr->name)) &&
((index == ptr->index) || (index == -1))){
/* String and index match. (Index -1 matches anything.) */
/* Remove parameter from list */
if (oldptr == NULL)
zz->Params = ptr->next;
else
oldptr->next = ptr->next;
/* Free parameter */
ZOLTAN_FREE(&(ptr->name));
ZOLTAN_FREE(&(ptr->new_val));
ZOLTAN_FREE(&ptr);
/* Return OK */
return (ZOLTAN_OK);
}
oldptr = ptr;
ptr = ptr->next;
}
/* Parameter was not in list */
return (ZOLTAN_OK);
}
int Zoltan_Filter_Params(
struct Zoltan_Struct *to_zz, /* add to this ... */
struct Zoltan_Struct *from_zz, /* ... parameters of interest found here */
PARAM_VARS * params, /* parameters of interest */
int debug_level, /* level for output of debugging info */
int proc, /* processor # (controls debug printing) */
int print_proc /* processor that should perform printing */
)
{
char *name; /* name of parameter being reset */
char *val; /* new value for parameter */
int index; /* index of parameter entry */
int found; /* is name found? */
int ierr; /* error code */
PARAM_LIST *from_list;
PARAM_VARS *param_ptr; /* pointer to current param */
ierr = ZOLTAN_OK;
from_list = from_zz->Params;
while (from_list != NULL) {
param_ptr = params;
name = from_list->name;
val = from_list->new_val;
index = from_list->index;
if (debug_level > 0 && proc == print_proc){
printf("Incoming parameter list: %s = %s\n",name,val);
}
found = 0;
while (param_ptr->name != NULL) {
if (!strcmp(param_ptr->name, name)) {
found = 1;
break;
}
param_ptr++;
}
if (found) { /* name found */
Zoltan_Set_Param_Vec(to_zz, name, val, index);
if (debug_level > 0 && proc == print_proc){
if (index >= 0)
printf("Put %s[%d] = %s in outgoing parameter list\n",name,index,val);
else
printf("Put %s = %s in outgoing parameter list\n",name,val);
}
}
from_list = from_list->next;
}
return ierr;
}
#ifdef __cplusplus
} /* closing bracket for extern "C" */
#endif