1 | #include <stdio.h> |
---|
2 | #include "rsl_lite.h" |
---|
3 | |
---|
4 | /* updated 20051021, new algorithm distributes the remainder, if any, at either ends of the dimension |
---|
5 | rather than the first remainder number of processors in the dimension. Idea is that the processes |
---|
6 | on the ends have less work because they're boundary processes. New alg works like this: |
---|
7 | a b |
---|
8 | + + + + + + o o o o o o o o o o o o o + + + + + + |
---|
9 | |
---|
10 | + represents a process with an extra point (npoints is n/p+1), o processors that don't (n/p) |
---|
11 | a and b are the starting process indices in the dimension of the new section of o or x. |
---|
12 | JM |
---|
13 | */ |
---|
14 | |
---|
15 | TASK_FOR_POINT ( i_p , j_p , ids_p, ide_p , jds_p, jde_p , npx_p , npy_p , Px_p, Py_p ) |
---|
16 | int_p i_p , j_p , Px_p , Py_p , ids_p, ide_p , jds_p, jde_p , npx_p , npy_p ; |
---|
17 | { |
---|
18 | int i , j , ids, ide, jds, jde, npx, npy ; /* inputs */ |
---|
19 | int Px, Py ; /* output */ |
---|
20 | int idim, jdim ; |
---|
21 | int rem, a, b ; |
---|
22 | i = *i_p - 1 ; |
---|
23 | j = *j_p - 1 ; |
---|
24 | npx = *npx_p ; |
---|
25 | npy = *npy_p ; |
---|
26 | ids = *ids_p - 1 ; ide = *ide_p - 1 ; |
---|
27 | jds = *jds_p - 1 ; jde = *jde_p - 1 ; |
---|
28 | idim = ide - ids + 1 ; |
---|
29 | jdim = jde - jds + 1 ; |
---|
30 | |
---|
31 | i = i >= ids ? i : ids ; i = i <= ide ? i : ide ; |
---|
32 | rem = idim % npx ; |
---|
33 | a = ( rem / 2 ) * ( (idim / npx) + 1 ) ; |
---|
34 | b = a + ( npx - rem ) * ( idim / npx ) ; |
---|
35 | if ( i-ids < a ) { |
---|
36 | Px = (i-ids) / ( (idim / npx) + 1 ) ; |
---|
37 | } |
---|
38 | else if ( i-ids < b ) { |
---|
39 | Px = ( a / ( (idim / npx) + 1 ) ) + (i-a-ids) / ( ( b - a ) / ( npx - rem ) ) ; |
---|
40 | } |
---|
41 | else { |
---|
42 | Px = ( a / ( (idim / npx) + 1 ) ) + (b-a-ids) / ( ( b - a ) / ( npx - rem ) ) + |
---|
43 | (i-b-ids) / ( ( idim / npx ) + 1 ) ; |
---|
44 | } |
---|
45 | |
---|
46 | j = j >= jds ? j : jds ; j = j <= jde ? j : jde ; |
---|
47 | rem = jdim % npy ; |
---|
48 | a = ( rem / 2 ) * ( (jdim / npy) + 1 ) ; |
---|
49 | b = a + ( npy - rem ) * ( jdim / npy ) ; |
---|
50 | if ( j-jds < a ) { |
---|
51 | Py = (j-jds) / ( (jdim / npy) + 1 ) ; |
---|
52 | } |
---|
53 | else if ( j-jds < b ) { |
---|
54 | Py = ( a / ( (jdim / npy) + 1 ) ) + (j-a-jds) / ( ( b - a ) / ( npy - rem ) ) ; |
---|
55 | } |
---|
56 | else { |
---|
57 | Py = ( a / ( (jdim / npy) + 1 ) ) + (b-a-jds) / ( ( b - a ) / ( npy - rem ) ) + |
---|
58 | (j-b-jds) / ( ( jdim / npy ) + 1 ) ; |
---|
59 | } |
---|
60 | |
---|
61 | *Px_p = Px ; |
---|
62 | *Py_p = Py ; |
---|
63 | } |
---|
64 | |
---|
65 | #if 0 |
---|
66 | main() |
---|
67 | { |
---|
68 | int ips[100], ipe[100] ; |
---|
69 | int jps[100], jpe[100] ; |
---|
70 | int shw, i , j , ids, ide, jds, jde, npx, npy ; /* inputs */ |
---|
71 | int Px, Py, P ; /* output */ |
---|
72 | printf("i, j, ids, ide, jds, jde, npx, npy\n") ; |
---|
73 | scanf("%d %d %d %d %d %d %d %d",&i, &j, &ids,&ide,&jds,&jde,&npx,&npy ) ; |
---|
74 | shw =0 ; |
---|
75 | for ( i = 0 ; i < 100 ; i++ ) { ips[i] = 9999999 ; ipe[i] = -99999999 ; } |
---|
76 | for ( i = 0 ; i < 100 ; i++ ) { jps[i] = 9999999 ; jpe[i] = -99999999 ; } |
---|
77 | #if 1 |
---|
78 | for ( j = jds-shw ; j <= jde+shw ; j++ ) |
---|
79 | { |
---|
80 | for ( i = ids-shw ; i <= ide+shw ; i++ ) |
---|
81 | { |
---|
82 | #endif |
---|
83 | TASK_FOR_POINT ( &i , &j , |
---|
84 | &ids, &ide, &jds, &jde , &npx , &npy , |
---|
85 | &Px, &Py ) ; |
---|
86 | /* printf("%3d",P) ; */ |
---|
87 | #if 1 |
---|
88 | } |
---|
89 | /* printf("\n") ; */ |
---|
90 | } |
---|
91 | for ( i = 0 ; i < npx*npy ; i++ ) { |
---|
92 | fprintf(stderr,"%3d. ips %d ipe %d (%d) jps %d jpe %d (%d)\n", i, ips[i], ipe[i], ipe[i]-ips[i]+1, jps[i], jpe[i], jpe[i]-jps[i]+1 ) ; |
---|
93 | } |
---|
94 | #endif |
---|
95 | } |
---|
96 | #endif |
---|
97 | |
---|