| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#include <p7_config.h> |
| 12 |
|
| 13 |
#ifdef HMMER_MPI |
| 14 |
#include <stdlib.h> |
| 15 |
#include <stdio.h> |
| 16 |
#include <string.h> |
| 17 |
|
| 18 |
#include "mpi.h" |
| 19 |
|
| 20 |
#ifndef __APPLE_ALTIVEC__ |
| 21 |
#include <altivec.h> |
| 22 |
#endif |
| 23 |
|
| 24 |
#include "easel.h" |
| 25 |
#include "esl_mpi.h" |
| 26 |
#include "esl_getopts.h" |
| 27 |
|
| 28 |
#include "hmmer.h" |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
int |
| 71 |
p7_oprofile_MPISend(P7_OPROFILE *om, int dest, int tag, MPI_Comm comm, char **buf, int *nalloc) |
| 72 |
{ |
| 73 |
int status; |
| 74 |
int code; |
| 75 |
int sz, n, pos; |
| 76 |
|
| 77 |
|
| 78 |
if (MPI_Pack_size(1, MPI_INT, comm, &n) != 0) ESL_XEXCEPTION(eslESYS, "mpi pack size failed"); |
| 79 |
if (om != NULL) { |
| 80 |
if ((status = p7_oprofile_MPIPackSize(om, comm, &sz)) != eslOK) return status; |
| 81 |
n += sz; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
if (*buf == NULL || n > *nalloc) { |
| 86 |
void *tmp; |
| 87 |
ESL_RALLOC(*buf, tmp, sizeof(char) * n); |
| 88 |
*nalloc = n; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
pos = 0; |
| 93 |
code = (om == NULL) ? eslEOD : eslOK; |
| 94 |
if (MPI_Pack(&code, 1, MPI_INT, *buf, n, &pos, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi pack failed"); |
| 95 |
if (om != NULL) { |
| 96 |
if ((status = p7_oprofile_MPIPack(om, *buf, n, &pos, comm)) != eslOK) return status; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
if (MPI_Send(*buf, n, MPI_PACKED, dest, tag, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi send failed"); |
| 101 |
return eslOK; |
| 102 |
|
| 103 |
ERROR: |
| 104 |
return status; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
int |
| 122 |
p7_oprofile_MPIPackSize(P7_OPROFILE *om, MPI_Comm comm, int *ret_n) |
| 123 |
{ |
| 124 |
int status; |
| 125 |
int n = 0; |
| 126 |
int K = om->abc->Kp; |
| 127 |
int len = 0; |
| 128 |
int cnt; |
| 129 |
int sz; |
| 130 |
|
| 131 |
int Q4 = p7O_NQF(om->M); |
| 132 |
int Q8 = p7O_NQW(om->M); |
| 133 |
int Q16 = p7O_NQB(om->M); |
| 134 |
int vsz = sizeof(vector float); |
| 135 |
|
| 136 |
|
| 137 |
if (MPI_Pack_size(5, MPI_CHAR, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; |
| 138 |
if (MPI_Pack_size(1, MPI_FLOAT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; |
| 139 |
if (MPI_Pack_size(vsz*Q16, MPI_CHAR, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += (K*sz); |
| 140 |
|
| 141 |
|
| 142 |
if (MPI_Pack_size(1, MPI_SHORT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += ((p7O_NXSTATES*p7O_NXTRANS+2)*sz); |
| 143 |
if (MPI_Pack_size(2, MPI_FLOAT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; |
| 144 |
if (MPI_Pack_size(K*vsz*Q8, MPI_CHAR, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; |
| 145 |
if (MPI_Pack_size(8*vsz*Q8, MPI_CHAR, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; |
| 146 |
|
| 147 |
|
| 148 |
if (MPI_Pack_size(1, MPI_FLOAT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += (p7O_NXSTATES*p7O_NXTRANS*sz); |
| 149 |
if (MPI_Pack_size(K*vsz*Q4, MPI_CHAR, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; |
| 150 |
if (MPI_Pack_size(8*vsz*Q4, MPI_CHAR, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; |
| 151 |
|
| 152 |
|
| 153 |
if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += ((p7_NOFFSETS+2)*sz); |
| 154 |
|
| 155 |
|
| 156 |
if (om->name != NULL) len += strlen(om->name) + 1; |
| 157 |
if (om->acc != NULL) len += strlen(om->acc) + 1; |
| 158 |
if (om->desc != NULL) len += strlen(om->desc) + 1; |
| 159 |
if (om->rf != NULL) len += strlen(om->rf) + 1; |
| 160 |
if (om->mm != NULL) len += strlen(om->mm) + 1; |
| 161 |
if (om->cs != NULL) len += strlen(om->cs) + 1; |
| 162 |
if (om->consensus != NULL) len += strlen(om->consensus) + 1; |
| 163 |
if (MPI_Pack_size(7, MPI_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; |
| 164 |
if (MPI_Pack_size(len, MPI_CHAR, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; |
| 165 |
cnt = p7_NEVPARAM + p7_NCUTOFFS + p7_MAXABET; |
| 166 |
if (MPI_Pack_size(cnt, MPI_FLOAT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; |
| 167 |
|
| 168 |
|
| 169 |
if (MPI_Pack_size(4, MPI_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; |
| 170 |
if (MPI_Pack_size(1, MPI_FLOAT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; |
| 171 |
|
| 172 |
*ret_n = n; |
| 173 |
return eslOK; |
| 174 |
|
| 175 |
ERROR: |
| 176 |
*ret_n = 0; |
| 177 |
return status; |
| 178 |
|
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
int |
| 207 |
p7_oprofile_MPIPack(P7_OPROFILE *om, char *buf, int n, int *pos, MPI_Comm comm) |
| 208 |
{ |
| 209 |
int K = om->abc->Kp; |
| 210 |
int atype = om->abc->type; |
| 211 |
int len; |
| 212 |
int x; |
| 213 |
|
| 214 |
int Q4 = p7O_NQF(om->M); |
| 215 |
int Q8 = p7O_NQW(om->M); |
| 216 |
int Q16 = p7O_NQB(om->M); |
| 217 |
int vsz = sizeof(vector float); |
| 218 |
|
| 219 |
|
| 220 |
if (MPI_Pack(&om->M, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 221 |
if (MPI_Pack(&atype, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 222 |
if (MPI_Pack(&om->L, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 223 |
if (MPI_Pack(&om->mode, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 224 |
if (MPI_Pack(&om->nj, 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 225 |
|
| 226 |
|
| 227 |
if (MPI_Pack(&om->tbm_b, 1, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 228 |
if (MPI_Pack(&om->tec_b, 1, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 229 |
if (MPI_Pack(&om->tjb_b, 1, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 230 |
if (MPI_Pack(&om->scale_b, 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 231 |
if (MPI_Pack(&om->base_b, 1, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 232 |
if (MPI_Pack(&om->bias_b, 1, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 233 |
for (x = 0; x < K; x++) |
| 234 |
if (MPI_Pack( om->rbv[x], vsz*Q16, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 235 |
|
| 236 |
|
| 237 |
if (MPI_Pack(&om->scale_w, 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 238 |
if (MPI_Pack(&om->base_w, 1, MPI_SHORT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 239 |
if (MPI_Pack(&om->ddbound_w, 1, MPI_SHORT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 240 |
if (MPI_Pack(&om->ncj_roundoff, 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 241 |
if (MPI_Pack( om->twv, 8*vsz*Q8, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 242 |
for (x = 0; x < p7O_NXSTATES; x++) |
| 243 |
if (MPI_Pack( om->xw[x], p7O_NXTRANS, MPI_SHORT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 244 |
for (x = 0; x < K; x++) |
| 245 |
if (MPI_Pack( om->rwv[x], vsz*Q8, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 246 |
|
| 247 |
|
| 248 |
if (MPI_Pack( om->tfv, 8*vsz*Q4, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 249 |
for (x = 0; x < p7O_NXSTATES; x++) |
| 250 |
if (MPI_Pack( om->xf[x], p7O_NXTRANS, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 251 |
for (x = 0; x < K; x++) |
| 252 |
if (MPI_Pack( om->rfv[x], vsz*Q4, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 253 |
|
| 254 |
|
| 255 |
if (MPI_Pack( om->offs, p7_NOFFSETS, MPI_LONG_LONG_INT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 256 |
if (MPI_Pack(&om->roff, 1, MPI_LONG_LONG_INT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 257 |
if (MPI_Pack(&om->eoff, 1, MPI_LONG_LONG_INT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 258 |
|
| 259 |
|
| 260 |
len = (om->name != NULL) ? strlen(om->name)+1 : 0; |
| 261 |
if (MPI_Pack(&len, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 262 |
if (len > 0) |
| 263 |
if (MPI_Pack( om->name, len, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 264 |
len = (om->acc != NULL) ? strlen(om->acc)+1 : 0; |
| 265 |
if (MPI_Pack(&len, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 266 |
if (len > 0) |
| 267 |
if (MPI_Pack( om->acc, len, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 268 |
len = (om->desc != NULL) ? strlen(om->desc)+1 : 0; |
| 269 |
if (MPI_Pack(&len, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 270 |
if (len > 0) |
| 271 |
if (MPI_Pack( om->desc, len, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 272 |
len = (om->rf != NULL) ? strlen(om->rf)+1 : 0; |
| 273 |
if (MPI_Pack(&len, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 274 |
if (len > 0) |
| 275 |
if (MPI_Pack( om->rf, len, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 276 |
len = (om->mm != NULL) ? strlen(om->mm)+1 : 0; |
| 277 |
if (MPI_Pack(&len, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 278 |
if (len > 0) |
| 279 |
if (MPI_Pack( om->mm, len, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 280 |
len = (om->cs != NULL) ? strlen(om->cs)+1 : 0; |
| 281 |
if (MPI_Pack(&len, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 282 |
if (len > 0) |
| 283 |
if (MPI_Pack( om->cs, len, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 284 |
len = (om->consensus != NULL) ? strlen(om->consensus)+1 : 0; |
| 285 |
if (MPI_Pack(&len, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 286 |
if (len > 0) |
| 287 |
if (MPI_Pack( om->consensus, len, MPI_CHAR, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 288 |
|
| 289 |
if (MPI_Pack( om->evparam, p7_NEVPARAM, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 290 |
if (MPI_Pack( om->cutoff, p7_NCUTOFFS, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 291 |
if (MPI_Pack( om->compo, p7_MAXABET, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_EXCEPTION(eslESYS, "pack failed"); |
| 292 |
|
| 293 |
if (*pos > n) ESL_EXCEPTION(eslEMEM, "buffer overflow"); |
| 294 |
return eslOK; |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
int |
| 337 |
p7_oprofile_MPIUnpack(char *buf, int n, int *pos, MPI_Comm comm, ESL_ALPHABET **abc, P7_OPROFILE **ret_om) |
| 338 |
{ |
| 339 |
int status; |
| 340 |
int M, K, atype; |
| 341 |
int len; |
| 342 |
int x; |
| 343 |
|
| 344 |
int Q4, Q8, Q16; |
| 345 |
int vsz = sizeof(vector float); |
| 346 |
|
| 347 |
P7_OPROFILE *om = NULL; |
| 348 |
|
| 349 |
if (MPI_Unpack(buf, n, pos, &M, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed"); |
| 350 |
if (MPI_Unpack(buf, n, pos, &atype, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed"); |
| 351 |
|
| 352 |
|
| 353 |
if (*abc == NULL) { |
| 354 |
if ((*abc = esl_alphabet_Create(atype)) == NULL) { status = eslEMEM; goto ERROR; } |
| 355 |
} else { |
| 356 |
if ((*abc)->type != atype) { status = eslEINCOMPAT; goto ERROR; } |
| 357 |
} |
| 358 |
|
| 359 |
Q4 = p7O_NQF(M); |
| 360 |
Q8 = p7O_NQW(M); |
| 361 |
Q16 = p7O_NQB(M); |
| 362 |
|
| 363 |
if ((om = p7_oprofile_Create(M, *abc)) == NULL) { status = eslEMEM; goto ERROR; } |
| 364 |
om->M = M; |
| 365 |
|
| 366 |
K = (*abc)->Kp; |
| 367 |
|
| 368 |
|
| 369 |
if (MPI_Unpack(buf, n, pos, &om->L, 1, MPI_INT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 370 |
if (MPI_Unpack(buf, n, pos, &om->mode, 1, MPI_INT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 371 |
if (MPI_Unpack(buf, n, pos, &om->nj, 1, MPI_FLOAT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 372 |
|
| 373 |
|
| 374 |
if (MPI_Unpack(buf, n, pos, &om->tbm_b, 1, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 375 |
if (MPI_Unpack(buf, n, pos, &om->tec_b, 1, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 376 |
if (MPI_Unpack(buf, n, pos, &om->tjb_b, 1, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 377 |
if (MPI_Unpack(buf, n, pos, &om->scale_b, 1, MPI_FLOAT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 378 |
if (MPI_Unpack(buf, n, pos, &om->base_b, 1, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 379 |
if (MPI_Unpack(buf, n, pos, &om->bias_b, 1, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 380 |
for (x = 0; x < K; x++) |
| 381 |
if (MPI_Unpack(buf, n, pos, om->rbv[x], vsz*Q16, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 382 |
|
| 383 |
|
| 384 |
if (MPI_Unpack(buf, n, pos, &om->scale_w, 1, MPI_FLOAT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 385 |
if (MPI_Unpack(buf, n, pos, &om->base_w, 1, MPI_SHORT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 386 |
if (MPI_Unpack(buf, n, pos, &om->ddbound_w, 1, MPI_SHORT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 387 |
if (MPI_Unpack(buf, n, pos, &om->ncj_roundoff, 1, MPI_FLOAT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 388 |
if (MPI_Unpack(buf, n, pos, om->twv, 8*vsz*Q8, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 389 |
for (x = 0; x < p7O_NXSTATES; x++) |
| 390 |
if (MPI_Unpack(buf, n, pos, om->xw[x], p7O_NXTRANS, MPI_SHORT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 391 |
for (x = 0; x < K; x++) |
| 392 |
if (MPI_Unpack(buf, n, pos, om->rwv[x], vsz*Q8, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 393 |
|
| 394 |
|
| 395 |
if (MPI_Unpack(buf, n, pos, om->tfv, 8*vsz*Q4, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 396 |
for (x = 0; x < p7O_NXSTATES; x++) |
| 397 |
if (MPI_Unpack(buf, n, pos, om->xf[x], p7O_NXTRANS, MPI_FLOAT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 398 |
for (x = 0; x < K; x++) |
| 399 |
if (MPI_Unpack(buf, n, pos, om->rfv[x], vsz*Q4, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 400 |
|
| 401 |
|
| 402 |
if (MPI_Unpack(buf, n, pos, om->offs, p7_NOFFSETS, MPI_LONG_LONG_INT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 403 |
if (MPI_Unpack(buf, n, pos, &om->roff, 1, MPI_LONG_LONG_INT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 404 |
if (MPI_Unpack(buf, n, pos, &om->eoff, 1, MPI_LONG_LONG_INT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 405 |
|
| 406 |
|
| 407 |
if (MPI_Unpack(buf, n, pos, &len, 1, MPI_INT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 408 |
if (len > 0) { |
| 409 |
ESL_ALLOC(om->name, len); |
| 410 |
if (MPI_Unpack(buf, n, pos, om->name, len, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 411 |
om->name[len-1] = '\0'; |
| 412 |
} |
| 413 |
if (MPI_Unpack(buf, n, pos, &len, 1, MPI_INT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 414 |
if (len > 0) { |
| 415 |
ESL_ALLOC(om->acc, len); |
| 416 |
if (MPI_Unpack(buf, n, pos, om->acc, len, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 417 |
om->acc[len-1] = '\0'; |
| 418 |
} |
| 419 |
if (MPI_Unpack(buf, n, pos, &len, 1, MPI_INT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 420 |
if (len > 0) { |
| 421 |
ESL_ALLOC(om->desc, len); |
| 422 |
if (MPI_Unpack(buf, n, pos, om->desc, len, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 423 |
om->desc[len-1] = '\0'; |
| 424 |
} |
| 425 |
if (MPI_Unpack(buf, n, pos, &len, 1, MPI_INT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 426 |
if (len > 0) { |
| 427 |
ESL_ALLOC(om->rf, len); |
| 428 |
if (MPI_Unpack(buf, n, pos, om->rf, len, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 429 |
om->rf[len-1] = '\0'; |
| 430 |
} |
| 431 |
if (MPI_Unpack(buf, n, pos, &len, 1, MPI_INT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 432 |
if (len > 0) { |
| 433 |
ESL_ALLOC(om->mm, len); |
| 434 |
if (MPI_Unpack(buf, n, pos, om->mm, len, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 435 |
om->mm[len-1] = '\0'; |
| 436 |
} |
| 437 |
if (MPI_Unpack(buf, n, pos, &len, 1, MPI_INT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 438 |
if (len > 0) { |
| 439 |
ESL_ALLOC(om->cs, len); |
| 440 |
if (MPI_Unpack(buf, n, pos, om->cs, len, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 441 |
om->cs[len-1] = '\0'; |
| 442 |
} |
| 443 |
if (MPI_Unpack(buf, n, pos, &len, 1, MPI_INT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 444 |
if (len > 0) { |
| 445 |
ESL_ALLOC(om->consensus, len); |
| 446 |
if (MPI_Unpack(buf, n, pos, om->consensus, len, MPI_CHAR, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 447 |
om->consensus[len-1] = '\0'; |
| 448 |
} |
| 449 |
|
| 450 |
if (MPI_Unpack(buf, n, pos, om->evparam, p7_NEVPARAM, MPI_FLOAT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 451 |
if (MPI_Unpack(buf, n, pos, om->cutoff, p7_NCUTOFFS, MPI_FLOAT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 452 |
if (MPI_Unpack(buf, n, pos, om->compo, p7_MAXABET, MPI_FLOAT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed"); |
| 453 |
|
| 454 |
*ret_om = om; |
| 455 |
return eslOK; |
| 456 |
|
| 457 |
ERROR: |
| 458 |
if (om != NULL) p7_oprofile_Destroy(om); |
| 459 |
return status; |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
int |
| 519 |
p7_oprofile_MPIRecv(int source, int tag, MPI_Comm comm, char **buf, int *nalloc, ESL_ALPHABET **abc, P7_OPROFILE **ret_om) |
| 520 |
{ |
| 521 |
int status; |
| 522 |
int code; |
| 523 |
P7_OPROFILE *om = NULL; |
| 524 |
int n; |
| 525 |
int pos; |
| 526 |
MPI_Status mpistatus; |
| 527 |
|
| 528 |
|
| 529 |
MPI_Probe(source, tag, comm, &mpistatus); |
| 530 |
MPI_Get_count(&mpistatus, MPI_PACKED, &n); |
| 531 |
|
| 532 |
|
| 533 |
if (*buf == NULL || n > *nalloc) { |
| 534 |
void *tmp; |
| 535 |
ESL_RALLOC(*buf, tmp, sizeof(char) * n); |
| 536 |
*nalloc = n; |
| 537 |
} |
| 538 |
|
| 539 |
|
| 540 |
MPI_Recv(*buf, n, MPI_PACKED, source, tag, comm, &mpistatus); |
| 541 |
|
| 542 |
|
| 543 |
pos = 0; |
| 544 |
if (MPI_Unpack(*buf, n, &pos, &code, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed"); |
| 545 |
if (code == eslEOD) { *ret_om = NULL; return eslEOD; } |
| 546 |
|
| 547 |
return p7_oprofile_MPIUnpack(*buf, *nalloc, &pos, comm, abc, ret_om); |
| 548 |
|
| 549 |
ERROR: |
| 550 |
if (om != NULL) p7_oprofile_Destroy(om); |
| 551 |
return status; |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
#ifdef p7MPI_BENCHMARK |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
#include <p7_config.h> |
| 568 |
|
| 569 |
#include <string.h> |
| 570 |
#include <math.h> |
| 571 |
|
| 572 |
#include "easel.h" |
| 573 |
#include "esl_getopts.h" |
| 574 |
#include "esl_alphabet.h" |
| 575 |
#include "esl_random.h" |
| 576 |
#include "esl_stopwatch.h" |
| 577 |
|
| 578 |
#include "hmmer.h" |
| 579 |
|
| 580 |
static ESL_OPTIONS options[] = { |
| 581 |
|
| 582 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 583 |
{ "-b", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "baseline timing: don't send any HMMs", 0 }, |
| 584 |
{ "--stall", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "arrest after start: for debugging MPI under gdb", 0 }, |
| 585 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 586 |
}; |
| 587 |
static char usage[] = "[-options] <hmmfile>"; |
| 588 |
static char banner[] = "benchmark driver for MPI communication"; |
| 589 |
|
| 590 |
int |
| 591 |
main(int argc, char **argv) |
| 592 |
{ |
| 593 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 1, argc, argv, banner, usage); |
| 594 |
char *hmmfile = esl_opt_GetArg(go, 1); |
| 595 |
ESL_ALPHABET *abc = esl_alphabet_Create(eslAMINO); |
| 596 |
P7_BG *bg = p7_bg_Create(abc); |
| 597 |
int my_rank; |
| 598 |
int nproc; |
| 599 |
char *buf = NULL; |
| 600 |
int nbuf = 0; |
| 601 |
int subtotalM = 0; |
| 602 |
int allM = 0; |
| 603 |
int stalling = esl_opt_GetBoolean(go, "--stall"); |
| 604 |
|
| 605 |
MPI_Init(&argc, &argv); |
| 606 |
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); |
| 607 |
MPI_Comm_size(MPI_COMM_WORLD, &nproc); |
| 608 |
|
| 609 |
while (stalling); |
| 610 |
|
| 611 |
|
| 612 |
if (my_rank == 0) |
| 613 |
{ |
| 614 |
ESL_STOPWATCH *w = esl_stopwatch_Create(); |
| 615 |
P7_HMMFILE *hfp = NULL; |
| 616 |
P7_OPROFILE *om = NULL; |
| 617 |
P7_HMM *hmm = NULL; |
| 618 |
|
| 619 |
|
| 620 |
if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile); |
| 621 |
|
| 622 |
esl_stopwatch_Start(w); |
| 623 |
while (p7_oprofile_ReadMSV(hfp, &abc, &om) == eslOK && |
| 624 |
p7_oprofile_ReadRest(hfp, om) == eslOK) |
| 625 |
{ |
| 626 |
if (!esl_opt_GetBoolean(go, "-b")) |
| 627 |
p7_oprofile_MPISend(om, 1, 0, MPI_COMM_WORLD, &buf, &nbuf); |
| 628 |
|
| 629 |
p7_hmm_Destroy(hmm); |
| 630 |
p7_oprofile_Destroy(om); |
| 631 |
} |
| 632 |
p7_oprofile_MPISend(NULL, 1, 0, MPI_COMM_WORLD, &buf, &nbuf); |
| 633 |
MPI_Reduce(&subtotalM, &allM, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); |
| 634 |
|
| 635 |
printf("total: %d\n", allM); |
| 636 |
esl_stopwatch_Stop(w); |
| 637 |
esl_stopwatch_Display(stdout, w, "CPU Time: "); |
| 638 |
esl_stopwatch_Destroy(w); |
| 639 |
} |
| 640 |
|
| 641 |
else |
| 642 |
{ |
| 643 |
P7_OPROFILE *om_recd = NULL; |
| 644 |
|
| 645 |
while (p7_oprofile_MPIRecv(0, 0, MPI_COMM_WORLD, &buf, &nbuf, &abc, &om_recd) == eslOK) |
| 646 |
{ |
| 647 |
subtotalM += om_recd->M; |
| 648 |
p7_oprofile_Destroy(om_recd); |
| 649 |
} |
| 650 |
MPI_Reduce(&subtotalM, &allM, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); |
| 651 |
} |
| 652 |
|
| 653 |
free(buf); |
| 654 |
p7_bg_Destroy(bg); |
| 655 |
esl_alphabet_Destroy(abc); |
| 656 |
esl_getopts_Destroy(go); |
| 657 |
MPI_Finalize(); |
| 658 |
exit(0); |
| 659 |
} |
| 660 |
|
| 661 |
#endif |
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
#ifdef p7MPI_TESTDRIVE |
| 669 |
|
| 670 |
static void |
| 671 |
utest_oprofileSendRecv(int my_rank, int nproc) |
| 672 |
{ |
| 673 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(42); |
| 674 |
ESL_ALPHABET *abc = esl_alphabet_Create(eslAMINO); |
| 675 |
P7_HMM *hmm = NULL; |
| 676 |
P7_BG *bg = NULL; |
| 677 |
P7_PROFILE *gm = NULL; |
| 678 |
P7_OPROFILE *om = NULL; |
| 679 |
P7_OPROFILE *om2 = NULL; |
| 680 |
int M = 200; |
| 681 |
int L = 400; |
| 682 |
char *wbuf = NULL; |
| 683 |
int wn = 0; |
| 684 |
int i; |
| 685 |
char errbuf[eslERRBUFSIZE]; |
| 686 |
|
| 687 |
p7_hmm_Sample(r, M, abc, &hmm); |
| 688 |
bg = p7_bg_Create(abc); |
| 689 |
gm = p7_profile_Create(hmm->M, abc); |
| 690 |
om = p7_oprofile_Create(hmm->M, abc); |
| 691 |
p7_ProfileConfig(hmm, bg, gm, L, p7_LOCAL); |
| 692 |
p7_oprofile_Convert(gm, om); |
| 693 |
p7_bg_SetLength (bg, L); |
| 694 |
|
| 695 |
if (my_rank == 0) |
| 696 |
{ |
| 697 |
for (i = 1; i < nproc; i++) |
| 698 |
{ |
| 699 |
ESL_DPRINTF1(("Master: receiving test profile\n")); |
| 700 |
p7_oprofile_MPIRecv(MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &wbuf, &wn, &abc, &om2); |
| 701 |
ESL_DPRINTF1(("Master: test profile received\n")); |
| 702 |
|
| 703 |
if (p7_oprofile_Compare(om, om2, 0.001, errbuf) != eslOK) |
| 704 |
p7_Die("Received profile not identical to what was sent\n%s", errbuf); |
| 705 |
|
| 706 |
p7_oprofile_Destroy(om2); |
| 707 |
} |
| 708 |
} |
| 709 |
else |
| 710 |
{ |
| 711 |
ESL_DPRINTF1(("Worker %d: sending test profile\n", my_rank)); |
| 712 |
p7_oprofile_MPISend(om, 0, 0, MPI_COMM_WORLD, &wbuf, &wn); |
| 713 |
ESL_DPRINTF1(("Worker %d: test profile sent\n", my_rank)); |
| 714 |
} |
| 715 |
|
| 716 |
free(wbuf); |
| 717 |
p7_profile_Destroy(gm); |
| 718 |
p7_oprofile_Destroy(om); |
| 719 |
p7_bg_Destroy(bg); |
| 720 |
p7_hmm_Destroy(hmm); |
| 721 |
esl_alphabet_Destroy(abc); |
| 722 |
esl_randomness_Destroy(r); |
| 723 |
return; |
| 724 |
} |
| 725 |
#endif |
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
#ifdef p7MPI_TESTDRIVE |
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
#include "esl_getopts.h" |
| 739 |
|
| 740 |
static ESL_OPTIONS options[] = { |
| 741 |
|
| 742 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 743 |
{ "--stall", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "arrest after start: for debugging MPI under gdb", 0 }, |
| 744 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 745 |
}; |
| 746 |
static char usage[] = "[-options]"; |
| 747 |
static char banner[] = "test driver for mpi.c"; |
| 748 |
|
| 749 |
int |
| 750 |
main(int argc, char **argv) |
| 751 |
{ |
| 752 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 0, argc, argv, banner, usage); |
| 753 |
int my_rank; |
| 754 |
int nproc; |
| 755 |
|
| 756 |
|
| 757 |
if (esl_opt_GetBoolean(go, "--stall")) pause(); |
| 758 |
|
| 759 |
MPI_Init(&argc, &argv); |
| 760 |
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); |
| 761 |
MPI_Comm_size(MPI_COMM_WORLD, &nproc); |
| 762 |
|
| 763 |
utest_oprofileSendRecv(my_rank, nproc); |
| 764 |
|
| 765 |
MPI_Finalize(); |
| 766 |
return 0; |
| 767 |
} |
| 768 |
|
| 769 |
#endif |
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
#else |
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
void p7_mpi_DoAbsolutelyNothing(void) { return; } |
| 780 |
#if defined p7MPI_TESTDRIVE || p7MPI_BENCHMARK || p7MPI_EXAMPLE |
| 781 |
int main(void) { return 0; } |
| 782 |
#endif |
| 783 |
#endif |
| 784 |
|
| 785 |
|