PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/wrfv2_fire/external/RSL_LITE/task_for_point.c

http://github.com/jbeezley/wrf-fire
C | 142 lines | 111 code | 11 blank | 20 comment | 22 complexity | f5021698d814dc18fe9a25ab25201a74 MD5 | raw file
Possible License(s): AGPL-1.0
  1. #ifndef MS_SUA
  2. # include <stdio.h>
  3. #endif
  4. #include "rsl_lite.h"
  5. /* updated 20051021, new algorithm distributes the remainder, if any, at either ends of the dimension
  6. rather than the first remainder number of processors in the dimension. Idea is that the processes
  7. on the ends have less work because they're boundary processes. New alg works like this:
  8. a b
  9. + + + + + + o o o o o o o o o o o o o + + + + + +
  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. static char tfpmess[1024] ;
  15. TASK_FOR_POINT ( i_p , j_p , ids_p, ide_p , jds_p, jde_p , npx_p , npy_p , Px_p, Py_p , minx_p, miny_p, ierr_p )
  16. int_p i_p , j_p , Px_p , Py_p , ids_p, ide_p , jds_p, jde_p , npx_p , npy_p, minx_p, miny_p, ierr_p ;
  17. {
  18. int i , j , ids, ide, jds, jde, npx, npy, minx, miny ; /* 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. #if 0
  27. minx = *minx_p ;
  28. miny = *miny_p ;
  29. #else
  30. minx = 1 ;
  31. miny = 1 ;
  32. #endif
  33. ids = *ids_p - 1 ; ide = *ide_p - 1 ;
  34. jds = *jds_p - 1 ; jde = *jde_p - 1 ;
  35. idim = ide - ids + 1 ;
  36. jdim = jde - jds + 1 ;
  37. *ierr_p = 0 ;
  38. /* begin: jm for Peter Johnsen -- noticed problem with polar filters in gwrf
  39. if the number of processors exceeds number of vertical levels */
  40. if ( npx > idim ) { npx = idim ; }
  41. if ( npy > jdim ) { npy = jdim ; }
  42. /* begin: wig; 10-Mar-2008
  43. Check that the number of processors is not so high that the halos begin to overlap.
  44. If they do, then reduce the number of processors allowed for that dimension.
  45. */
  46. tfpmess[0] = '\0' ;
  47. if ( idim / npx < minx ) {
  48. npx = idim/minx ;
  49. if (npx < 1) { npx = 1 ;}
  50. if (npx != *npx_p) {
  51. sprintf(tfpmess,"RSL_LITE: TASK_FOR_POINT LIMITING PROCESSOR COUNT IN X-DIRECTION TO %d %d\n", npx,*npx_p) ;
  52. *ierr_p = 1 ;
  53. }
  54. }
  55. if ( jdim / npy < miny ) {
  56. npy = jdim/miny ;
  57. if (npy < 1) { npy = 1 ;}
  58. if (npy != *npy_p) {
  59. sprintf(tfpmess,"RSL_LITE: TASK_FOR_POINT LIMITING PROCESSOR COUNT IN Y-DIRECTION TO %d %d\n", npy,*npy_p) ;
  60. *ierr_p = 1 ;
  61. }
  62. }
  63. /* end: wig */
  64. i = i >= ids ? i : ids ; i = i <= ide ? i : ide ;
  65. rem = idim % npx ;
  66. a = ( rem / 2 ) * ( (idim / npx) + 1 ) ;
  67. b = a + ( npx - rem ) * ( idim / npx ) ;
  68. if ( i-ids < a ) {
  69. Px = (i-ids) / ( (idim / npx) + 1 ) ;
  70. }
  71. else if ( i-ids < b ) {
  72. Px = ( a / ( (idim / npx) + 1 ) ) + (i-a-ids) / ( ( b - a ) / ( npx - rem ) ) ;
  73. }
  74. else {
  75. Px = ( a / ( (idim / npx) + 1 ) ) + (b-a-ids) / ( ( b - a ) / ( npx - rem ) ) +
  76. (i-b-ids) / ( ( idim / npx ) + 1 ) ;
  77. }
  78. j = j >= jds ? j : jds ; j = j <= jde ? j : jde ;
  79. rem = jdim % npy ;
  80. a = ( rem / 2 ) * ( (jdim / npy) + 1 ) ;
  81. b = a + ( npy - rem ) * ( jdim / npy ) ;
  82. if ( j-jds < a ) {
  83. Py = (j-jds) / ( (jdim / npy) + 1 ) ;
  84. }
  85. else if ( j-jds < b ) {
  86. Py = ( a / ( (jdim / npy) + 1 ) ) + (j-a-jds) / ( ( b - a ) / ( npy - rem ) ) ;
  87. }
  88. else {
  89. Py = ( a / ( (jdim / npy) + 1 ) ) + (b-a-jds) / ( ( b - a ) / ( npy - rem ) ) +
  90. (j-b-jds) / ( ( jdim / npy ) + 1 ) ;
  91. }
  92. *Px_p = Px ;
  93. *Py_p = Py ;
  94. }
  95. TASK_FOR_POINT_MESSAGE()
  96. {
  97. fprintf(stderr,"%s\n",tfpmess) ;
  98. }
  99. #if 0
  100. main()
  101. {
  102. int ips[100], ipe[100] ;
  103. int jps[100], jpe[100] ;
  104. int shw, i , j , ids, ide, jds, jde, npx, npy ; /* inputs */
  105. int Px, Py, P ; /* output */
  106. printf("i, j, ids, ide, jds, jde, npx, npy\n") ;
  107. scanf("%d %d %d %d %d %d %d %d",&i, &j, &ids,&ide,&jds,&jde,&npx,&npy ) ;
  108. shw =0 ;
  109. for ( i = 0 ; i < 100 ; i++ ) { ips[i] = 9999999 ; ipe[i] = -99999999 ; }
  110. for ( i = 0 ; i < 100 ; i++ ) { jps[i] = 9999999 ; jpe[i] = -99999999 ; }
  111. #if 1
  112. for ( j = jds-shw ; j <= jde+shw ; j++ )
  113. {
  114. for ( i = ids-shw ; i <= ide+shw ; i++ )
  115. {
  116. #endif
  117. TASK_FOR_POINT ( &i , &j ,
  118. &ids, &ide, &jds, &jde , &npx , &npy ,
  119. &Px, &Py ) ;
  120. printf("(%3d %3d) ",Px,Py) ;
  121. #if 1
  122. }
  123. printf("\n") ;
  124. }
  125. /* for ( i = 0 ; i < npx*npy ; i++ ) { */
  126. /* 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 ) ; */
  127. /* } */
  128. #endif
  129. }
  130. #endif