Path: blob/devel/elmergrid/src/metis-5.1.0/libmetis/util.c
3206 views
/*1* Copyright 1997, Regents of the University of Minnesota2*3* util.c4*5* This function contains various utility routines6*7* Started 9/28/958* George9*10* $Id: util.c 10495 2011-07-06 16:04:45Z karypis $11*/1213#include "metislib.h"141516/*************************************************************************/17/*! This function initializes the random number generator18*/19/*************************************************************************/20void InitRandom(idx_t seed)21{22isrand((seed == -1 ? 4321 : seed));23}242526/*************************************************************************/27/*! Returns the highest weight index of x[i]*y[i]28*/29/*************************************************************************/30idx_t iargmax_nrm(size_t n, idx_t *x, real_t *y)31{32idx_t i, max=0;3334for (i=1; i<n; i++)35max = (x[i]*y[i] > x[max]*y[max] ? i : max);3637return max;38}394041/*************************************************************************/42/*! These functions return the index of the maximum element in a vector43*/44/*************************************************************************/45idx_t iargmax_strd(size_t n, idx_t *x, idx_t incx)46{47size_t i, max=0;4849n *= incx;50for (i=incx; i<n; i+=incx)51max = (x[i] > x[max] ? i : max);5253return max/incx;54}555657/*************************************************************************/58/*! These functions return the index of the almost maximum element in a59vector60*/61/*************************************************************************/62idx_t rargmax2(size_t n, real_t *x)63{64size_t i, max1, max2;6566if (x[0] > x[1]) {67max1 = 0;68max2 = 1;69}70else {71max1 = 1;72max2 = 0;73}7475for (i=2; i<n; i++) {76if (x[i] > x[max1]) {77max2 = max1;78max1 = i;79}80else if (x[i] > x[max2])81max2 = i;82}8384return max2;85}868788/*************************************************************************/89/*! These functions return the index of the second largest elements in the90vector formed by x.y where '.' is element-wise multiplication */91/*************************************************************************/92idx_t iargmax2_nrm(size_t n, idx_t *x, real_t *y)93{94size_t i, max1, max2;9596if (x[0]*y[0] > x[1]*y[1]) {97max1 = 0;98max2 = 1;99}100else {101max1 = 1;102max2 = 0;103}104105for (i=2; i<n; i++) {106if (x[i]*y[i] > x[max1]*y[max1]) {107max2 = max1;108max1 = i;109}110else if (x[i]*y[i] > x[max2]*y[max2])111max2 = i;112}113114return max2;115}116117118/*************************************************************************/119/*! converts a signal code into a Metis return code120*/121/*************************************************************************/122int metis_rcode(int sigrval)123{124switch (sigrval) {125case 0:126return METIS_OK;127break;128case SIGMEM:129return METIS_ERROR_MEMORY;130break;131default:132return METIS_ERROR;133break;134}135}136137138139140