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 127 2008-04-28 21:59:36Z 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 #if defined key_oasis3 00022 use cpl_oasis3 00023 #endif 00024 00025 #if defined key_oasis4 00026 use cpl_oasis4 00027 #endif 00028 00029 implicit none 00030 private 00031 save 00032 00033 ! !PUBLIC MEMBER FUNCTIONS: 00034 00035 public :: init_communicate, & 00036 get_num_procs, & 00037 create_communicator 00038 00039 ! !PUBLIC DATA MEMBERS: 00040 00041 integer (int_kind), public :: 00042 MPI_COMM_ICE, ! MPI communicator for ice comms 00043 mpiR16, ! MPI type for r16_kind 00044 mpiR8, ! MPI type for dbl_kind 00045 mpiR4, ! MPI type for real_kind 00046 my_task, ! MPI task number for this task 00047 master_task ! task number of master task 00048 00049 integer (int_kind), parameter, public :: 00050 mpitagHalo = 1, ! MPI tags for various 00051 mpitag_gs = 1000 ! communication patterns 00052 00053 !EOP 00054 !BOC 00055 !EOC 00056 !*********************************************************************** 00057 00058 contains 00059 00060 !*********************************************************************** 00061 !BOP 00062 ! !IROUTINE: init_communicate 00063 ! !INTERFACE: 00064 00065 subroutine init_communicate 00066 00067 ! !DESCRIPTION: 00068 ! This routine sets up MPI environment and defines ice 00069 ! communicator. 00070 ! 00071 ! !REVISION HISTORY: 00072 ! same as module 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 integer (int_kind) :: ice_comm 00087 00088 !----------------------------------------------------------------------- 00089 ! 00090 ! initiate mpi environment and create communicator for internal 00091 ! ice communications 00092 ! 00093 !----------------------------------------------------------------------- 00094 00095 #if (defined key_oasis3 || defined key_oasis4) 00096 ice_comm = localComm ! communicator from NEMO/OASISn 00097 #else 00098 ice_comm = MPI_COMM_WORLD ! Global communicator 00099 #endif 00100 00101 #if (defined popcice || defined CICE_IN_NEMO) 00102 ! MPI_INIT is called elsewhere in coupled configuration 00103 #else 00104 call MPI_INIT(ierr) 00105 #endif 00106 00107 call MPI_BARRIER (ice_comm, ierr) 00108 call MPI_COMM_DUP(ice_comm, MPI_COMM_ICE, ierr) 00109 00110 master_task = 0 00111 call MPI_COMM_RANK (MPI_COMM_ICE, my_task, ierr) 00112 00113 mpiR16 = MPI_REAL16 00114 mpiR8 = MPI_REAL8 00115 mpiR4 = MPI_REAL4 00116 00117 !----------------------------------------------------------------------- 00118 !EOC 00119 00120 end subroutine init_communicate 00121 00122 !*********************************************************************** 00123 !BOP 00124 ! !IROUTINE: get_num_procs 00125 ! !INTERFACE: 00126 00127 function get_num_procs() 00128 00129 ! !DESCRIPTION: 00130 ! This function returns the number of processor assigned to 00131 ! MPI_COMM_ICE 00132 ! 00133 ! !REVISION HISTORY: 00134 ! same as module 00135 00136 ! !OUTPUT PARAMETERS: 00137 00138 integer (int_kind) :: get_num_procs 00139 00140 !EOP 00141 !BOC 00142 !----------------------------------------------------------------------- 00143 ! 00144 ! local variables 00145 ! 00146 !----------------------------------------------------------------------- 00147 00148 integer (int_kind) :: ierr 00149 00150 !----------------------------------------------------------------------- 00151 00152 call MPI_COMM_SIZE(MPI_COMM_ICE, get_num_procs, ierr) 00153 00154 !----------------------------------------------------------------------- 00155 !EOC 00156 00157 end function get_num_procs 00158 00159 !*********************************************************************** 00160 !BOP 00161 ! !IROUTINE: create_communicator 00162 ! !INTERFACE: 00163 00164 subroutine create_communicator(new_comm, num_procs) 00165 00166 ! !DESCRIPTION: 00167 ! This routine creates a separate communicator for a subset of 00168 ! processors under default ice communicator. 00169 ! 00170 ! this routine should be called from init_domain1 when the 00171 ! domain configuration (e.g. nprocs_btrop) has been determined 00172 ! 00173 ! !REVISION HISTORY: 00174 ! same as module 00175 00176 ! !INCLUDES: 00177 00178 include 'mpif.h' 00179 00180 ! !INPUT PARAMETERS: 00181 00182 integer (int_kind), intent(in) :: 00183 num_procs ! num of procs in new distribution 00184 00185 ! !OUTPUT PARAMETERS: 00186 00187 integer (int_kind), intent(out) :: 00188 new_comm ! new communicator for this distribution 00189 00190 !EOP 00191 !BOC 00192 !----------------------------------------------------------------------- 00193 ! 00194 ! local variables 00195 ! 00196 !----------------------------------------------------------------------- 00197 00198 integer (int_kind) :: 00199 MPI_GROUP_ICE, ! group of processors assigned to ice 00200 MPI_GROUP_NEW ! group of processors assigned to new dist 00201 00202 integer (int_kind) :: 00203 ierr ! error flag for MPI comms 00204 00205 integer (int_kind), dimension(3) :: 00206 range ! range of tasks assigned to new dist 00207 ! (assumed 0,num_procs-1) 00208 00209 !----------------------------------------------------------------------- 00210 ! 00211 ! determine group of processes assigned to distribution 00212 ! 00213 !----------------------------------------------------------------------- 00214 00215 call MPI_COMM_GROUP (MPI_COMM_ICE, MPI_GROUP_ICE, ierr) 00216 00217 range(1) = 0 00218 range(2) = num_procs-1 00219 range(3) = 1 00220 00221 !----------------------------------------------------------------------- 00222 ! 00223 ! create subroup and communicator for new distribution 00224 ! note: MPI_COMM_CREATE must be called by all procs in MPI_COMM_ICE 00225 ! 00226 !----------------------------------------------------------------------- 00227 00228 call MPI_GROUP_RANGE_INCL(MPI_GROUP_ICE, 1, range, & 00229 MPI_GROUP_NEW, ierr) 00230 00231 call MPI_COMM_CREATE (MPI_COMM_ICE, MPI_GROUP_NEW, & 00232 new_comm, ierr) 00233 00234 !----------------------------------------------------------------------- 00235 !EOC 00236 00237 end subroutine create_communicator 00238 00239 !*********************************************************************** 00240 00241 end module ice_communicate 00242 00243 !|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||