Original WRF subgrid support version from John Michalakes without fire
[wrffire.git] / wrfv2_fire / external / RSL / RSL / border.c
blob45cf7756f00faed096cb7347f1d85764425740d4
1 /***********************************************************************
3 COPYRIGHT
5 The following is a notice of limited availability of the code and
6 Government license and disclaimer which must be included in the
7 prologue of the code and in all source listings of the code.
9 Copyright notice
10 (c) 1977 University of Chicago
12 Permission is hereby granted to use, reproduce, prepare
13 derivative works, and to redistribute to others at no charge. If
14 you distribute a copy or copies of the Software, or you modify a
15 copy or copies of the Software or any portion of it, thus forming
16 a work based on the Software and make and/or distribute copies of
17 such work, you must meet the following conditions:
19 a) If you make a copy of the Software (modified or verbatim)
20 it must include the copyright notice and Government
21 license and disclaimer.
23 b) You must cause the modified Software to carry prominent
24 notices stating that you changed specified portions of
25 the Software.
27 This software was authored by:
29 Argonne National Laboratory
30 J. Michalakes: (630) 252-6646; email: michalak@mcs.anl.gov
31 Mathematics and Computer Science Division
32 Argonne National Laboratory, Argonne, IL 60439
34 ARGONNE NATIONAL LABORATORY (ANL), WITH FACILITIES IN THE STATES
35 OF ILLINOIS AND IDAHO, IS OWNED BY THE UNITED STATES GOVERNMENT,
36 AND OPERATED BY THE UNIVERSITY OF CHICAGO UNDER PROVISION OF A
37 CONTRACT WITH THE DEPARTMENT OF ENERGY.
39 GOVERNMENT LICENSE AND DISCLAIMER
41 This computer code material was prepared, in part, as an account
42 of work sponsored by an agency of the United States Government.
43 The Government is granted for itself and others acting on its
44 behalf a paid-up, nonexclusive, irrevocable worldwide license in
45 this data to reproduce, prepare derivative works, distribute
46 copies to the public, perform publicly and display publicly, and
47 to permit others to do so. NEITHER THE UNITED STATES GOVERNMENT
48 NOR ANY AGENCY THEREOF, NOR THE UNIVERSITY OF CHICAGO, NOR ANY OF
49 THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
50 ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
51 COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS,
52 PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD
53 NOT INFRINGE PRIVATELY OWNED RIGHTS.
55 ***************************************************************************/
57 #include <stdio.h>
58 #include <stdlib.h>
59 #include "rsl.h"
61 static int zero = 0 ;
63 rsl_processor_t
64 locproc( i, m, numproc )
65 rsl_index_t i ;
66 rsl_dimlen_t m ;
67 rsl_processor_t numproc ;
69 int val ;
70 rsl_processor_t retval ;
72 int ii, im, inumproc ;
74 ii = i ; im = m ; inumproc = numproc ;
75 c_locproc( &ii, &im, &inumproc, &zero, &zero, &val ) ;
76 retval = val ;
77 return( retval ) ;
82 /***************************************************************************
83 patchmap routine:
84 Given position(p) in the global dimension (max) in the grid, with
85 margins of size ml (left/top) and mr (right/bottom), divide it among
86 the nproc processors in that dimension so the margins get at least
87 the margin and no more than width+1 processes.
89 J A Mogill 19 April 1993
90 ****************************************************************************/
92 c_locproc(p, max, nproc, ml, mr, ret)
93 int *p, *max, *nproc, *ml, *mr, *ret;
96 int width, rem, ret2, bl, br, mid, adjust;
98 int p_r, max_r, nproc_r, zero ;
100 adjust = 0;
101 rem = *max%*nproc;
102 width = *max/(*nproc);
103 mid = *max/2;
105 if(rem>0 && ((rem%2==0 || rem>2) || *p<=mid ))
106 width++;
107 if(*p<=mid && rem%2!=0)
108 adjust++;
110 bl = maximum(width,*ml);
111 br = maximum(width,*mr);
113 if(*p<bl)
114 *ret = 0;
115 else if(*p>*max-br-1)
116 *ret = *nproc-1;
117 else
119 p_r = *p-bl ;
120 max_r = *max-bl-br+adjust ;
121 nproc_r = maximum(*nproc-2,1) ;
122 zero = 0 ;
124 c_locproc( &p_r, &max_r, &nproc_r, &zero, &zero, &ret2);
125 *ret = ret2 + 1;
134 int maximum(x,y)
135 int x,y;
138 if(x>=y)
139 return(x);
140 else
141 return(y);
144 #if 0
145 main()
147 int i, m, numproc ;
148 m = 61 ;
149 numproc = 10 ;
150 for ( i = 0; i < 61 ; i++ )
152 printf("locproc(%d,%d,%d) = %d\n",i,m,numproc,locproc(i,m,numproc)) ;
155 #endif