hypre/seq_matrix_vector/genpart.c

36 lines
1012 B
C

/*BHEADER**********************************************************************
* (c) 1998 The Regents of the University of California
*
* See the file COPYRIGHT_and_DISCLAIMER for a complete copyright
* notice, contact person, and disclaimer.
*
* $Revision$
*********************************************************************EHEADER*/
#include "headers.h"
/*--------------------------------------------------------------------------
* hypre_GeneratePartitioning:
* generates load balanced partitioning of a 1-d array
*--------------------------------------------------------------------------*/
int
hypre_GeneratePartitioning(int length, int num_procs, int **part_ptr)
{
int ierr = 0;
int *part;
int size, rest;
int i;
part = hypre_CTAlloc(int, num_procs+1);
size = length / num_procs;
rest = length - size*num_procs;
part[0] = 0;
for (i=0; i < num_procs; i++)
{
part[i+1] = part[i]+size;
if (i < rest) part[i+1]++;
}
*part_ptr = part;
return ierr;
}