00001 !||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 00002 !BOP 00003 00004 module ice_communicate 00005 00006 ! !MODULE: ice_communicate 00007 ! !DESCRIPTION: 00008 ! This module contains the necessary routines and variables for 00009 ! communicating between processors. 00010 ! 00011 ! !REVISION HISTORY: 00012 ! SVN:$Id: ice_communicate.F90 100 2008-01-29 00:25:32Z eclare $ 00013 ! 00014 ! author: Phil Jones, LANL 00015 ! Oct. 2004: Adapted from POP version by William H. Lipscomb, LANL 00016 ! 00017 ! !USES: 00018 00019 use ice_kinds_mod 00020 00021 implicit none 00022 private 00023 save 00024 00025 ! !PUBLIC MEMBER FUNCTIONS: 00026 00027 public :: init_communicate, & 00028 get_num_procs, & 00029 create_communicator 00030 00031 public :: ice_barrier 00032 ! !PUBLIC DATA MEMBERS: 00033 00034 integer (int_kind), public :: 00035 MPI_COMM_ICE, ! MPI communicator for ice comms 00036 mpiR16, ! MPI type for r16_kind 00037 mpiR8, ! MPI type for dbl_kind 00038 mpiR4, ! MPI type for real_kind 00039 my_task, ! MPI task number for this task 00040 master_task ! task number of master task 00041 00042 integer (int_kind), parameter, public :: 00043 mpitagHalo = 1, ! MPI tags for various 00044 mpitag_gs = 1000 ! communication patterns 00045 00046 logical (log_kind), public :: lprint_stats ! if true output decomposition statistics 00047 00048 !EOP 00049 !BOC 00050 !EOC 00051 !*********************************************************************** 00052 00053 contains 00054 00055 !*********************************************************************** 00056 !BOP 00057 ! !IROUTINE: init_communicate 00058 ! !INTERFACE: 00059 00060 subroutine init_communicate (mpicom_ice) 00061 00062 ! !DESCRIPTION: 00063 ! This routine sets up MPI environment and defines ice 00064 ! communicator. 00065 ! 00066 ! !REVISION HISTORY: 00067 ! same as module 00068 00069 ! !INPUT/OUTPUT PARAMETERS: 00070 ! 00071 integer (kind=int_kind), intent(in) :: 00072 mpicom_ice ! communicator for sequential ccsm 00073 00074 !EOP 00075 !BOC 00076 !----------------------------------------------------------------------- 00077 ! 00078 ! local variables 00079 ! 00080 !----------------------------------------------------------------------- 00081 00082 include 'mpif.h' ! MPI Fortran include file 00083 00084 integer (int_kind) :: ierr ! MPI error flag 00085 00086 !----------------------------------------------------------------------- 00087 ! 00088 ! initiate mpi environment and create communicator for internal 00089 ! ice communications 00090 ! 00091 !----------------------------------------------------------------------- 00092 00093 call MPI_COMM_DUP(mpicom_ice, MPI_COMM_ICE, ierr) 00094 00095 master_task = 0 00096 call MPI_COMM_RANK (MPI_COMM_ICE, my_task, ierr) 00097 00098 ! mpiR16 = MPI_REAL16 00099 mpiR8 = MPI_REAL8 00100 mpiR4 = MPI_REAL4 00101 00102 !----------------------------------------------------------------------- 00103 !EOC 00104 00105 end subroutine init_communicate 00106 00107 !*********************************************************************** 00108 !BOP 00109 ! !IROUTINE: get_num_procs 00110 ! !INTERFACE: 00111 00112 function get_num_procs() 00113 00114 ! !DESCRIPTION: 00115 ! This function returns the number of processor assigned to 00116 ! MPI_COMM_ICE 00117 ! 00118 ! !REVISION HISTORY: 00119 ! same as module 00120 00121 ! !OUTPUT PARAMETERS: 00122 00123 integer (int_kind) :: get_num_procs 00124 00125 !EOP 00126 !BOC 00127 !----------------------------------------------------------------------- 00128 ! 00129 ! local variables 00130 ! 00131 !----------------------------------------------------------------------- 00132 00133 integer (int_kind) :: ierr 00134 00135 !----------------------------------------------------------------------- 00136 00137 call MPI_COMM_SIZE(MPI_COMM_ICE, get_num_procs, ierr) 00138 00139 !----------------------------------------------------------------------- 00140 !EOC 00141 00142 end function get_num_procs 00143 00144 !*********************************************************************** 00145 !BOP 00146 ! !IROUTINE: create_communicator 00147 ! !INTERFACE: 00148 00149 subroutine create_communicator(new_comm, num_procs) 00150 00151 ! !DESCRIPTION: 00152 ! This routine creates a separate communicator for a subset of 00153 ! processors under default ice communicator. 00154 ! 00155 ! this routine should be called from init_domain1 when the 00156 ! domain configuration (e.g. nprocs_btrop) has been determined 00157 ! 00158 ! !REVISION HISTORY: 00159 ! same as module 00160 00161 ! !INCLUDES: 00162 00163 include 'mpif.h' 00164 00165 ! !INPUT PARAMETERS: 00166 00167 integer (int_kind), intent(in) :: 00168 num_procs ! num of procs in new distribution 00169 00170 ! !OUTPUT PARAMETERS: 00171 00172 integer (int_kind), intent(out) :: 00173 new_comm ! new communicator for this distribution 00174 00175 !EOP 00176 !BOC 00177 !----------------------------------------------------------------------- 00178 ! 00179 ! local variables 00180 ! 00181 !----------------------------------------------------------------------- 00182 00183 integer (int_kind) :: 00184 MPI_GROUP_ICE, ! group of processors assigned to ice 00185 MPI_GROUP_NEW ! group of processors assigned to new dist 00186 00187 integer (int_kind) :: 00188 ierr ! error flag for MPI comms 00189 00190 integer (int_kind), dimension(3) :: 00191 range ! range of tasks assigned to new dist 00192 ! (assumed 0,num_procs-1) 00193 00194 !----------------------------------------------------------------------- 00195 ! 00196 ! determine group of processes assigned to distribution 00197 ! 00198 !----------------------------------------------------------------------- 00199 00200 call MPI_COMM_GROUP (MPI_COMM_ICE, MPI_GROUP_ICE, ierr) 00201 00202 range(1) = 0 00203 range(2) = num_procs-1 00204 range(3) = 1 00205 00206 !----------------------------------------------------------------------- 00207 ! 00208 ! create subroup and communicator for new distribution 00209 ! note: MPI_COMM_CREATE must be called by all procs in MPI_COMM_ICE 00210 ! 00211 !----------------------------------------------------------------------- 00212 00213 #ifdef SPMD 00214 call MPI_GROUP_RANGE_INCL(MPI_GROUP_ICE, 1, range, & 00215 MPI_GROUP_NEW, ierr) 00216 00217 call MPI_COMM_CREATE (MPI_COMM_ICE, MPI_GROUP_NEW, & 00218 new_comm, ierr) 00219 #else 00220 call MPI_COMM_DUP(MPI_COMM_ICE, new_comm, ierr) 00221 #endif 00222 00223 !----------------------------------------------------------------------- 00224 !EOC 00225 00226 end subroutine create_communicator 00227 00228 !*********************************************************************** 00229 !BOP 00230 ! !IROUTINE: ice_barrier 00231 ! !INTERFACE: 00232 00233 subroutine ice_barrier 00234 00235 ! !DESCRIPTION: 00236 ! This routine performs a barrier. 00237 ! 00238 ! !REVISION HISTORY: 00239 ! same as module 00240 00241 ! !INCLUDES: 00242 00243 !EOP 00244 !BOC 00245 !----------------------------------------------------------------------- 00246 ! 00247 ! local variables 00248 ! 00249 !----------------------------------------------------------------------- 00250 integer(int_kind) :: ierr 00251 00252 call MPI_Barrier(MPI_COMM_ICE,ierr) 00253 00254 !----------------------------------------------------------------------- 00255 !EOC 00256 00257 end subroutine ice_barrier 00258 00259 00260 !*********************************************************************** 00261 00262 00263 end module ice_communicate 00264 00265 !|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||