source: CIVL/examples/mpi-omp/AMG2013/seq_mv/genpart.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[2aa6644]1/*BHEADER**********************************************************************
2 * Copyright (c) 2008, Lawrence Livermore National Security, LLC.
3 * Produced at the Lawrence Livermore National Laboratory.
4 * This file is part of HYPRE. See file COPYRIGHT for details.
5 *
6 * HYPRE is free software; you can redistribute it and/or modify it under the
7 * terms of the GNU Lesser General Public License (as published by the Free
8 * Software Foundation) version 2.1 dated February 1999.
9 *
10 * $Revision: 2.4 $
11 ***********************************************************************EHEADER*/
12
13
14
15
16#include "headers.h"
17
18/*--------------------------------------------------------------------------
19 * hypre_GeneratePartitioning:
20 * generates load balanced partitioning of a 1-d array
21 *--------------------------------------------------------------------------*/
22/* for multivectors, length should be the (global) length of a single vector.
23 Thus each of the vectors of the multivector will get the same data distribution. */
24
25int
26hypre_GeneratePartitioning(HYPRE_BigInt length, int num_procs, HYPRE_BigInt **part_ptr)
27{
28 int ierr = 0;
29 HYPRE_BigInt *part;
30 HYPRE_BigInt size;
31 int i, rest;
32
33
34 part = hypre_CTAlloc(HYPRE_BigInt, num_procs+1);
35 size = length / (HYPRE_BigInt)num_procs;
36 rest = (int)(length - size*(HYPRE_BigInt)num_procs);
37 part[0] = 0;
38 for (i=0; i < num_procs; i++)
39 {
40 part[i+1] = part[i]+size;
41 if (i < rest) part[i+1]++;
42 }
43
44
45 *part_ptr = part;
46 return ierr;
47}
48
49
50/* This function differs from the above in that it only returns
51 the portion of the partition belonging to the individual process -
52 to do this it requires the processor id as well AHB 6/05*/
53
54int
55hypre_GenerateLocalPartitioning(HYPRE_BigInt length, int num_procs, int myid, HYPRE_BigInt **part_ptr)
56{
57
58
59 int ierr = 0;
60 HYPRE_BigInt *part;
61 HYPRE_BigInt size;
62 int rest;
63
64 part = hypre_CTAlloc(HYPRE_BigInt, 2);
65 size = length /(HYPRE_BigInt)num_procs;
66 rest = (int)(length - size*(HYPRE_BigInt)num_procs);
67
68 /* first row I own */
69 part[0] = size*(HYPRE_BigInt)myid;
70 part[0] += (HYPRE_BigInt)hypre_min(myid, rest);
71
72 /* last row I own */
73 part[1] = size*(HYPRE_BigInt)(myid+1);
74 part[1] += (HYPRE_BigInt)hypre_min(myid+1, rest);
75 part[1] = part[1] - 1;
76
77 /* add 1 to last row since this is for "starts" vector */
78 part[1] = part[1] + 1;
79
80
81 *part_ptr = part;
82 return ierr;
83}
Note: See TracBrowser for help on using the repository browser.