Geant4 Cross Reference |
1 #ifdef PoPs_MPI 1 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <string.h> 5 6 #include "PoPs.h" 7 #include "PoPs_private.h" 8 #include "PoPs_Bcast_private.h" 9 10 #define NumberOfBcastArrays 3 11 12 enum PoPs_Bcast_mode { PoPs_Bcast_mode_count, 13 14 typedef struct PoPs_Bcast_info { 15 enum PoPs_Bcast_mode mode; 16 int int_count, char_count, double_count; 17 int *int_array; 18 char *char_array; 19 double *double_array; 20 } PoPs_Bcast_info; 21 22 static int PoPs_Bcast3( statusMessageReporting 23 static int PoPs_Bcast_PoPs( statusMessageRepor 24 static int PoPs_Bcast_PoPs2( statusMessageRepo 25 static int PoPs_Bcast_int( statusMessageReport 26 static int PoPs_Bcast_charAllocate( statusMess 27 static int PoPs_Bcast_double( statusMessageRep 28 /* 29 ============================================== 30 */ 31 int PoPs_Bcast2( statusMessageReporting *smr, 32 33 int myRank, status; 34 int description[NumberOfBcastArrays]; 35 PoPs_Bcast_info info = { PoPs_Bcast_mode_c 36 37 if( ( status = MPI_Errhandler_set( comm, M 38 /* New way but not on all systems yet 39 if( ( status = MPI_Comm_set_errhandler( co 40 */ 41 if( ( status = MPI_Comm_rank( comm, &myRan 42 43 if( myRank == bossRank ) { 44 info.mode = PoPs_Bcast_mode_count; 45 if( ( status = PoPs_Bcast3( smr, comm, 46 description[0] = info.int_count; 47 description[1] = info.char_count; 48 description[2] = info.double_count; 49 if( ( info.int_array = (int *) smr_mal 50 if( ( info.char_array = (char *) smr_m 51 if( ( info.double_array = (double *) s 52 53 info.mode = PoPs_Bcast_mode_pack; 54 info.int_count = 0; 55 info.char_count = 0; 56 info.double_count = 0; 57 if( ( status = PoPs_Bcast3( smr, comm, 58 if( info.int_count != description[0] ) 59 smr_setReportError2( smr, PoPs_smr 60 goto err; 61 } 62 if( info.char_count != description[1] 63 smr_setReportError2( smr, PoPs_smr 64 goto err; 65 } 66 if( info.double_count != description[2 67 smr_setReportError2( smr, PoPs_smr 68 goto err; 69 } 70 } 71 72 if( ( status = MPI_Bcast( description, Num 73 74 if( myRank != bossRank ) { 75 if( ( info.int_array = (int *) smr_mal 76 if( ( info.char_array = (char *) smr_m 77 if( ( info.double_array = (double *) s 78 } 79 if( ( status = MPI_Bcast( info.int_array, 80 if( ( status = MPI_Bcast( info.char_array, 81 if( ( status = MPI_Bcast( info.double_arra 82 83 if( myRank != bossRank ) { 84 info.mode = PoPs_Bcast_mode_unpack; 85 if( ( status = PoPs_Bcast3( smr, comm, 86 } 87 88 if( info.int_array != NULL ) smr_freeMemor 89 if( info.char_array != NULL ) smr_freeMemo 90 if( info.double_array != NULL ) smr_freeMe 91 92 return( 0 ); 93 94 err: 95 if( info.int_array != NULL ) smr_freeMemor 96 if( info.char_array != NULL ) smr_freeMemo 97 if( info.double_array != NULL ) smr_freeMe 98 if( unitsRoot->unsorted != NULL ) smr_free 99 if( popsRoot->pops != NULL ) smr_freeMemor 100 if( popsRoot->sorted != NULL ) smr_freeMem 101 return( -1 ); 102 } 103 /* 104 ============================================== 105 */ 106 static int PoPs_Bcast3( statusMessageReporting 107 108 int i, status, numberOfUnits, numberOfPart 109 110 if( info->mode == PoPs_Bcast_mode_unpack ) 111 if( ( status = PoPs_Bcast_int( smr, info, 112 numberOfUnits = unitsRoot->numberOfUnits; 113 if( info->mode == PoPs_Bcast_mode_unpack ) 114 unitsRoot->allocated = unitsRoot->numb 115 unitsRoot->numberOfUnits = 0; 116 if( ( unitsRoot->unsorted = (char cons 117 } 118 for( i = 0; i < numberOfUnits; i++ ) { 119 if( ( status = PoPs_Bcast_charAllocate 120 if( info->mode == PoPs_Bcast_mode_unpa 121 } 122 123 if( ( status = PoPs_Bcast_int( smr, info, 124 numberOfParticles = popsRoot->numberOfPart 125 if( info->mode == PoPs_Bcast_mode_unpack ) 126 popsRoot->allocated = popsRoot->number 127 popsRoot->numberOfParticles = 0; 128 if( ( popsRoot->pops = (PoP **) smr_ma 129 if( ( popsRoot->sorted = (PoP **) smr_ 130 } 131 for( i = 0; i < numberOfParticles; i++ ) { 132 if( ( status = PoPs_Bcast_PoPs( smr, i 133 } 134 return( 0 ); 135 } 136 /* 137 ============================================== 138 */ 139 static int PoPs_Bcast_PoPs( statusMessageRepor 140 141 int status; 142 PoP pop; 143 144 if( info->mode != PoPs_Bcast_mode_unpack ) 145 if( ( status = PoPs_Bcast_PoPs2( smr, info 146 return( 0 ); 147 } 148 /* 149 ============================================== 150 */ 151 static int PoPs_Bcast_PoPs2( statusMessageRepo 152 153 int status, n = 0; 154 155 if( ( status = PoPs_Bcast_int( smr, info, 156 if( ( status = PoPs_Bcast_int( smr, info, 157 if( ( status = PoPs_Bcast_int( smr, info, 158 if( ( status = PoPs_Bcast_int( smr, info, 159 160 if( ( status = PoPs_Bcast_int( smr, info, 161 if( ( status = PoPs_Bcast_int( smr, info, 162 if( ( status = PoPs_Bcast_int( smr, info, 163 if( ( status = PoPs_Bcast_double( smr, inf 164 165 if( info->mode == PoPs_Bcast_mode_pack ) { 166 n = -1; 167 if( pop->massUnit != NULL ) { 168 if( ( n = unitsDB_index( smr, pop- 169 } 170 } 171 if( ( status = PoPs_Bcast_int( smr, info, 172 if( ( status = PoPs_Bcast_charAllocate( sm 173 174 if( info->mode == PoPs_Bcast_mode_unpack ) 175 pop->aliasIndex = -1; /* Reset h 176 177 if( n < 0 ) { 178 pop->massUnit = NULL; } 179 else { 180 if( ( pop->massUnit = unitsDB_stri 181 } 182 if( PoPs_copyAddParticleIfNeeded( smr, 183 184 if( pop->name != NULL ) smr_freeMemory 185 } 186 187 return( 0 ); 188 189 err: 190 if( info->mode == PoPs_Bcast_mode_unpack ) 191 if( pop->name != NULL ) smr_freeMemory 192 } 193 return( -1 ); 194 } 195 /* 196 ============================================== 197 */ 198 static int PoPs_Bcast_int( statusMessageReport 199 200 if( info->mode == PoPs_Bcast_mode_pack ) { 201 info->int_array[info->int_count] = *va 202 else if( info->mode == PoPs_Bcast_mode_unp 203 *value = info->int_array[info->int_cou 204 } 205 info->int_count++; 206 return( 0 ); 207 } 208 /* 209 ============================================== 210 */ 211 static int PoPs_Bcast_charAllocate( statusMess 212 213 int i, n = 0, status; 214 215 if( info->mode != PoPs_Bcast_mode_unpack ) 216 n = (int) strlen( *value ) + 1; 217 if( ( status = PoPs_Bcast_int( smr, in 218 if( info->mode == PoPs_Bcast_mode_pack 219 for( i = 0; i < n; i++ ) info->cha 220 } } 221 else { 222 if( ( status = PoPs_Bcast_int( smr, in 223 if( ( *value = (char *) smr_malloc2( s 224 for( i = 0; i < n; i++ ) (*value)[i] = 225 } 226 info->char_count += n; 227 228 return( 0 ); 229 } 230 /* 231 ============================================== 232 */ 233 static int PoPs_Bcast_double( statusMessageRep 234 235 if( info->mode == PoPs_Bcast_mode_pack ) { 236 info->double_array[info->double_count] 237 else if( info->mode == PoPs_Bcast_mode_unp 238 *value = info->double_array[info->doub 239 } 240 info->double_count++; 241 return( 0 ); 242 } 243 #endif /* End of #ifdef PoPs_MPI */ 244