Debian Codegraph @

src/mpisupport.c

raw symbols SCIP
1 /* mpisupport.c
2 * Optional support for MPI parallelization in Infernal.
3 *
4 * EPN, Mon Aug 27 12:38:13 2007
5 */
6
7 #include <esl_config.h>
8 #include <p7_config.h>
9 #include "config.h"
10
11 #ifdef HAVE_MPI
12
13 #include <assert.h>
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <string.h>
17
18 #include "mpi.h"
19
20 #include "easel.h"
21 #include "esl_mpi.h"
22
23 #include "hmmer.h"
24
25 #include "infernal.h"
26
27 static int expinfo_MPIPackSize(ExpInfo_t *exp, MPI_Comm comm, int *ret_n);
28 static int expinfo_MPIPack(ExpInfo_t *exp, char *buf, int n, int *position, MPI_Comm comm);
29 static int expinfo_MPIUnpack(char *buf, int n, int *pos, MPI_Comm comm, ExpInfo_t **ret_exp);
30
31 static int cm_hit_MPISend(CM_HIT *hit, int dest, int tag, MPI_Comm comm, char **buf, int *nalloc);
32 static int cm_hit_MPIPackSize(CM_HIT *hit, MPI_Comm comm, int *ret_n);
33 static int cm_hit_MPIPack(CM_HIT *hit, char *buf, int n, int *pos, MPI_Comm comm);
34 static int cm_hit_MPIUnpack(char *buf, int n, int *pos, MPI_Comm comm, CM_HIT *hit);
35 static int cm_hit_MPIRecv(int source, int tag, MPI_Comm comm, char **buf, int *nalloc, CM_HIT *hit);
36
37 /*****************************************************************
38 * 1. Communicating a CM.
39 *****************************************************************/
40
41 /* Function: cm_master_MPIBcast()
42 * Incept: EPN, Wed May 9 17:24:53 2007
43 *
44 * Purpose: Broadcasts CM <cm> from a master.
45 *
46 * If <cm> is NULL, broadcasts a end-of-data signal, to
47 * tell workers to shut down.
48 *
49 */
50 int
51 cm_master_MPIBcast(CM_t *cm, char *errbuf, int tag, MPI_Comm comm, char **buf, int *nalloc)
52 {
53 int status;
54 int code;
55 int sz, n, pos;
56
57 /* Figure out size */
58 if (MPI_Pack_size(1, MPI_INT, comm, &n) != 0) ESL_XEXCEPTION(eslESYS, "mpi pack size failed");
59 if (cm != NULL) {
60 if ((status = cm_nonconfigured_MPIPackSize(cm, comm, &sz)) != eslOK) return status;
61 n += sz;
62 }
63
64 /* Make sure the buffer is allocated appropriately */
65 if (*buf == NULL || n > *nalloc) {
66 void *tmp;
67 ESL_RALLOC(*buf, tmp, sizeof(char) * n);
68 *nalloc = n;
69 }
70
71 /* Pack the status code and CM into the buffer */
72 pos = 0;
73 code = (cm == NULL) ? eslEOD : eslOK;
74 if (MPI_Pack(&code, 1, MPI_INT, *buf, n, &pos, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi pack failed");
75 if (cm != NULL) {
76 if ((status = cm_nonconfigured_MPIPack(cm, errbuf, *buf, n, &pos, comm)) != eslOK) return status;
77 }
78
79 /* Broadcast the size of the packed CM */
80 if (MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD) != 0) ESL_EXCEPTION(eslESYS, "mpi broadcast failed");
81 /* Broadcast the packed CM */
82 if (MPI_Bcast (*buf, n, MPI_PACKED, 0, MPI_COMM_WORLD) != 0) ESL_EXCEPTION(eslESYS, "mpi broadcast failed");
83 return eslOK;
84
85 ERROR:
86 return status;
87 }
88
89 /* Function: cm_worker_MPIBcast()
90 * Incept: EPN, Mon Aug 27 14:44:11 2007
91 *
92 * Purpose: Receives a broadcasted buffer size and then a
93 * broadcasted work unit of that size that consists
94 * of a single CM <cm> tagged as <tag> from
95 * communicator <comm> (usually 0, a master).
96 *
97 * Work units are prefixed by a status code. If the unit's
98 * code is <eslOK> and no errors are encountered, this
99 * routine will return <eslOK> and a non-<NULL> <*ret_cm>.
100 * If the unit's code is <eslEOD> (a shutdown signal),
101 * this routine returns <eslEOD> and <*ret_cm> is <NULL>.
102 *
103 * If the packed CM is an end-of-data signal, return
104 * <eslEOD>, and <*ret_cm> is <NULL>.
105 *
106 * Returns: <eslOK> on success. <*ret_cm> contains the new CM; it
107 * is allocated here, and the caller is responsible for
108 * free'ing it. <*buf> may have been reallocated to a
109 * larger size, and <*nalloc> may have been increased.
110 *
111 *
112 * Throws: <eslESYS> if an MPI call fails; <eslEMEM> if an allocation fails.
113 * In either case, <*ret_msa> is NULL, and the <buf> and its size
114 * <*nalloc> remain valid.
115 * Xref: J1/72.
116 *
117 */
118 int
119 cm_worker_MPIBcast(char *errbuf, int tag, MPI_Comm comm, char **buf, int *nalloc, ESL_ALPHABET **abc, CM_t **ret_cm)
120 {
121 int status, code;
122 int n;
123 int pos;
124
125 /* Receive the buffer size broadcast */
126 if (MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD) != 0) ESL_EXCEPTION(eslESYS, "mpi broadcast failed.");
127
128 /* Make sure the buffer is allocated appropriately */
129 if (*buf == NULL || n > *nalloc) {
130 void *tmp;
131 ESL_RALLOC(*buf, tmp, sizeof(char) * n);
132 *nalloc = n;
133 }
134
135 /* Receive the CM broadcast */
136 if (MPI_Bcast (*buf, n, MPI_PACKED, 0, MPI_COMM_WORLD) != 0) ESL_EXCEPTION(eslESYS, "mpi broadcast failed.");
137
138 /* Unpack it - where the first integer is a status code, OK or EOD */
139 pos = 0;
140 if (MPI_Unpack (*buf, n, &pos, &code, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
141 if (code == eslEOD) { status = eslEOD; goto ERROR; }
142
143 return cm_nonconfigured_MPIUnpack(abc, errbuf, *buf, *nalloc, &pos, comm, ret_cm);
144
145 ERROR:
146 *ret_cm = NULL;
147 return status;
148 }
149
150 /* Function: cm_nonconfigured_MPIUnpack()
151 * Synopsis: Unpacks a CM <cm> (packed by cm_nonconfigured_MPIPack()) from an MPI buffer.
152 * Incept: EPN, Mon Aug 27 14:44:11 2007
153 *
154 * Purpose: Unpack a newly allocated CM from MPI packed buffer
155 * <buf>, starting from position <*pos>, where the total length
156 * of the buffer in bytes is <n>. Note that
157 * the full CM data structure was not packed, only
158 * the parts that could have been changed from their initial
159 * (default) values in CMFileRead() are packed. In this
160 * case it's safe to 'fill-in' the 'rest' of the CM with a ConfigCM()
161 * call, which saves us from broadcasting the 'rest' of the CM.
162 *
163 * Returns: <eslOK> on success. <*pos> is updated to the position of
164 * the next element in <buf> to unpack (if any). <*ret_cm>
165 * contains a newly allocated CM, which the caller is
166 * responsible for free'ing.
167 *
168 * Throws: <eslESYS> on an MPI call failure. <eslEMEM> on allocation failure.
169 * In either case, <*ret_cm> is <NULL>, and the state of <buf>
170 * and <*pos> is undefined and should be considered to be corrupted.
171 */
172 int
173 cm_nonconfigured_MPIUnpack(ESL_ALPHABET **abc, char *errbuf, char *buf, int n, int *pos, MPI_Comm comm, CM_t **ret_cm)
174 {
175 int status;
176 CM_t *cm = NULL;
177 P7_HMM *hmm = NULL;
178 ESL_ALPHABET *aabc = NULL;
179 int atype, i, K, M, nnodes;
180 float tmp_fp7_gfmu;
181 float tmp_fp7_gflambda;
182
183 cm = CreateCMShell();
184 if (cm == NULL) { status = eslEMEM; goto ERROR; }
185 if (MPI_Unpack(buf, n, pos, &(cm->M), 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
186 if (MPI_Unpack(buf, n, pos, &(cm->nodes), 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
187 if (MPI_Unpack(buf, n, pos, &(cm->clen), 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
188 if (MPI_Unpack(buf, n, pos, &atype, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
189 if (MPI_Unpack(buf, n, pos, &(cm->flags), 1, MPI_INT, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi unpack failed");
190 /* note: it's important cm->flags is set prior to CreateCMBody() call below, to properly allocate
191 * cm->rf, cm->consensus, cm->map, or not */
192
193 /* Set or verify the alphabet */
194 if (*abc == NULL) { /* still unknown: set it, pass control of it back to caller */
195 if ((*abc = esl_alphabet_Create(atype)) == NULL) { status = eslEMEM; goto ERROR; }
196 } else { /* already known: check it */
197 if ((*abc)->type != atype) { status = eslEINCOMPAT; goto ERROR; }
198 }
199
200 CreateCMBody(cm, cm->nodes, cm->M, cm->clen, (*abc));
201
202 /* For convenience below */
203 K = cm->abc->K;
204 M = cm->M;
205 nnodes = cm->nodes;
206
207 /* Unpack the rest of the CM */
208 /* note cm->flags is how it was immediately after CM is read from file, so the only flags that can possibly be raised are:
209 * CMH_ACC, CMH_DESC, CM_RF, CMH_GA, CMH_TC, CMH_NC, CMH_CHKSUM, CMH_MAP, CMH_CONS, CMH_EXPTAIL_STATS, CMH_FILTER_STATS,
210 * CMH_QDB, CMH_QDB_LOCAL, CMH_FP7, CM_IS_RSEARCH, CM_RSEARCHTRANS, CM_RSEARCH_EMIT */
211
212 if (MPI_Unpack(buf, n, pos, cm->e[0], M*K*K, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
213 if (MPI_Unpack(buf, n, pos, cm->t[0], M*MAXCONNECT, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
214 if (MPI_Unpack(buf, n, pos, cm->sttype, M+1, MPI_CHAR, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
215 if (MPI_Unpack(buf, n, pos, cm->stid, M+1, MPI_CHAR, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
216 if (MPI_Unpack(buf, n, pos, cm->ndidx, M, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
217 if (MPI_Unpack(buf, n, pos, cm->cfirst, M, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
218 if (MPI_Unpack(buf, n, pos, cm->cnum, M, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
219 if (MPI_Unpack(buf, n, pos, cm->plast, M, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
220 if (MPI_Unpack(buf, n, pos, cm->pnum, M, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
221 if (MPI_Unpack(buf, n, pos, cm->nodemap, nnodes, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
222 if (MPI_Unpack(buf, n, pos, cm->ndtype, nnodes, MPI_CHAR, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
223
224 if (MPI_Unpack(buf, n, pos, &(cm->nseq), 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
225 if (MPI_Unpack(buf, n, pos, &(cm->eff_nseq), 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
226 if (MPI_Unpack(buf, n, pos, &(cm->el_selfsc), 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
227 if (MPI_Unpack(buf, n, pos, &(cm->null2_omega), 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
228 if (MPI_Unpack(buf, n, pos, &(cm->null3_omega), 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
229 if (MPI_Unpack(buf, n, pos, &(cm->checksum), 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
230 if (MPI_Unpack(buf, n, pos, cm->null, K, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
231
232 if (MPI_Unpack(buf, n, pos, &(cm->W), 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
233 if (MPI_Unpack(buf, n, pos, &(cm->beta_W), 1,MPI_DOUBLE, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
234 if (MPI_Unpack(buf, n, pos, &(cm->tau), 1,MPI_DOUBLE, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
235 if (MPI_Unpack(buf, n, pos, &(cm->maxtau), 1,MPI_DOUBLE, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
236 if (MPI_Unpack(buf, n, pos, &(cm->ga), 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
237 if (MPI_Unpack(buf, n, pos, &(cm->nc), 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
238 if (MPI_Unpack(buf, n, pos, &(cm->tc), 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
239
240 /* name and all the optional stuff */
241 if ((status = esl_mpi_UnpackOpt(buf, n, pos, (void**)&(cm->name), NULL, MPI_CHAR, comm)) != eslOK) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
242 if ((status = esl_mpi_UnpackOpt(buf, n, pos, (void**)&(cm->acc), NULL, MPI_CHAR, comm)) != eslOK) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
243 if ((status = esl_mpi_UnpackOpt(buf, n, pos, (void**)&(cm->desc), NULL, MPI_CHAR, comm)) != eslOK) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
244 if ((status = esl_mpi_UnpackOpt(buf, n, pos, (void**)&(cm->comlog), NULL, MPI_CHAR, comm)) != eslOK) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
245 if ((status = esl_mpi_UnpackOpt(buf, n, pos, (void**)&(cm->ctime), NULL, MPI_CHAR, comm)) != eslOK) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
246
247 if (cm->flags & CMH_RF) { if (MPI_Unpack(buf, n, pos, cm->rf, cm->clen+2, MPI_CHAR, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed"); }
248 if (cm->flags & CMH_CONS) { if (MPI_Unpack(buf, n, pos, cm->consensus, cm->clen+2, MPI_CHAR, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed"); }
249 if (cm->flags & CMH_MAP) { if (MPI_Unpack(buf, n, pos, cm->map, cm->clen+1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed"); }
250
251 /* the E-value stats */
252 if (cm->flags & CMH_EXPTAIL_STATS) {
253 ESL_ALLOC(cm->expA, sizeof(ExpInfo_t *) * EXP_NMODES);
254 for(i = 0; i < EXP_NMODES; i++) {
255 if((status = expinfo_MPIUnpack(buf, n, pos, comm, &(cm->expA[i]))) != eslOK) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
256 }
257 }
258
259 /* Finally unpack any additional p7 filter stats, and the p7 models themselves */
260 if (cm->flags & CMH_FP7) {
261 if (MPI_Unpack(buf, n, pos, &tmp_fp7_gfmu, 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
262 if (MPI_Unpack(buf, n, pos, &tmp_fp7_gflambda, 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
263 if((status = p7_hmm_MPIUnpack(buf, n, pos, comm, &aabc, &hmm)) != eslOK) ESL_XEXCEPTION(status, "mpi unpack failed");
264 if((status = cm_SetFilterHMM(cm, hmm, tmp_fp7_gfmu, tmp_fp7_gflambda)) != eslOK) ESL_XEXCEPTION(eslESYS, "Unable to set filter HMM for CM");
265 }
266
267 /* Verify we're not configured */
268 if((status = cm_nonconfigured_Verify(cm, errbuf)) != eslOK) ESL_XEXCEPTION(status, errbuf);
269
270 *ret_cm = cm;
271 return eslOK;
272
273 ERROR:
274 if(cm != NULL) FreeCM(cm);
275 return status;
276 }
277
278 /* Function: cm_nonconfigured_MPIPack()
279 * Incept: EPN, Mon Aug 27 14:24:57 2007
280 *
281 * Purpose: Packs CM <cm> into an MPI packed message buffer <buf>
282 * of length <n> bytes, starting at byte position <*position>,
283 * for MPI communicator <comm>. Note that
284 * the full CM data structure is not packed, only
285 * the parts that could have been changed from their initial
286 * (default) values in CMFileRead() are packed. In this
287 * case it's safe to 'fill-in' the 'rest' of the CM with a ConfigCM()
288 * call, which saves us from broadcasting the 'rest' of the CM.
289 *
290 * The caller must know that <buf>'s allocation of <n>
291 * bytes is large enough to append the packed CM at
292 * position <*pos>. This typically requires a call to
293 * <cm_nonconfigured_MPIPackSize()> first, and reallocation if
294 * needed.
295 *
296 * Returns: <eslOK> on success; <buf> now contains the
297 * packed <cm>, and <*position> is set to the byte
298 * immediately following the last byte of the CM
299 * in <buf>.
300 *
301 * Throws: <eslFAIL> if <cm> is configured.
302 * <eslESYS> if an MPI call fails; or <eslEMEM> if the
303 * buffer's length <n> was overflowed in trying to pack
304 * <cm> into <buf>. In either case, the state of
305 * <buf> and <*position> is undefined, and both should
306 * be considered to be corrupted.
307 */
308 int
309 cm_nonconfigured_MPIPack(CM_t *cm, char *errbuf, char *buf, int n, int *pos, MPI_Comm comm)
310 {
311 int status;
312 int i;
313 int K = cm->abc->K;
314 int M = cm->M;
315 int nnodes = cm->nodes;
316 int clen = cm->clen;
317
318 /* Verify we're not configured */
319 if((status = cm_nonconfigured_Verify(cm, errbuf)) != eslOK) ESL_XEXCEPTION(status, errbuf);
320
321 if (MPI_Pack(&M, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
322 if (MPI_Pack(&nnodes, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
323 if (MPI_Pack(&clen, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
324 if (MPI_Pack((void *) &(cm->abc->type), 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
325 if (MPI_Pack(&(cm->flags), 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
326
327 /* note cm->flags is how it was immediately after CM is read from file, so the only flags that can possibly be raised are:
328 * CMH_ACC, CMH_DESC, CM_RF, CMH_GA, CMH_TC, CMH_NC, CMH_CHKSUM, CMH_MAP, CMH_CONS, CMH_EXPTAIL_STATS, CMH_FILTER_STATS,
329 * CMH_QDB, CMH_QDB_LOCAL, CMH_MLP7_STATS, CMH_AP7_STATS, CM_IS_RSEARCH, CM_RSEARCHTRANS, CM_RSEARCH_EMIT */
330
331 if (MPI_Pack(cm->e[0], M*K*K, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
332 if (MPI_Pack(cm->t[0], M*MAXCONNECT, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
333 if (MPI_Pack(cm->sttype, M+1, MPI_CHAR, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
334 if (MPI_Pack(cm->stid, M+1, MPI_CHAR, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
335 if (MPI_Pack(cm->ndidx, M, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
336 if (MPI_Pack(cm->cfirst, M, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
337 if (MPI_Pack(cm->cnum, M, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
338 if (MPI_Pack(cm->plast, M, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
339 if (MPI_Pack(cm->pnum, M, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
340 if (MPI_Pack(cm->nodemap, nnodes, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
341 if (MPI_Pack(cm->ndtype, nnodes, MPI_CHAR, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
342
343 if (MPI_Pack(&(cm->nseq), 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
344 if (MPI_Pack(&(cm->eff_nseq), 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
345 if (MPI_Pack(&(cm->el_selfsc), 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
346 if (MPI_Pack(&(cm->null2_omega), 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
347 if (MPI_Pack(&(cm->null3_omega), 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
348 if (MPI_Pack(&(cm->checksum), 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
349 if (MPI_Pack(cm->null, K, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
350
351 if (MPI_Pack(&(cm->W), 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
352 if (MPI_Pack(&(cm->beta_W), 1,MPI_DOUBLE, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
353 if (MPI_Pack(&(cm->tau), 1,MPI_DOUBLE, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
354 if (MPI_Pack(&(cm->maxtau), 1,MPI_DOUBLE, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
355 if (MPI_Pack(&(cm->ga), 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
356 if (MPI_Pack(&(cm->nc), 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
357 if (MPI_Pack(&(cm->tc), 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
358
359 /* name and all the optional stuff */
360 if ((status = esl_mpi_PackOpt(cm->name, -1, MPI_CHAR, buf, n, pos, comm)) != eslOK) ESL_XEXCEPTION(eslESYS, "pack failed");
361 if ((status = esl_mpi_PackOpt(cm->acc, -1, MPI_CHAR, buf, n, pos, comm)) != eslOK) ESL_XEXCEPTION(eslESYS, "pack failed");
362 if ((status = esl_mpi_PackOpt(cm->desc, -1, MPI_CHAR, buf, n, pos, comm)) != eslOK) ESL_XEXCEPTION(eslESYS, "pack failed");
363 if ((status = esl_mpi_PackOpt(cm->comlog, -1, MPI_CHAR, buf, n, pos, comm)) != eslOK) ESL_XEXCEPTION(eslESYS, "pack failed");
364 if ((status = esl_mpi_PackOpt(cm->ctime, -1, MPI_CHAR, buf, n, pos, comm)) != eslOK) ESL_XEXCEPTION(eslESYS, "pack failed");
365
366 if (cm->flags & CMH_RF) { if (MPI_Pack(cm->rf, cm->clen+2, MPI_CHAR, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed"); }
367 if (cm->flags & CMH_CONS) { if (MPI_Pack(cm->consensus, cm->clen+2, MPI_CHAR, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed"); }
368 if (cm->flags & CMH_MAP) { if (MPI_Pack(cm->map, cm->clen+1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed"); }
369
370 /* the E-value stats */
371 if (cm->flags & CMH_EXPTAIL_STATS) {
372 for(i = 0; i < EXP_NMODES; i++) {
373 if ((status = expinfo_MPIPack(cm->expA[i], buf, n, pos, comm)) != eslOK) ESL_XEXCEPTION(eslESYS, "pack failed");
374 }
375 }
376 if ((cm->flags & CMH_FP7) && (cm->fp7 != NULL)) {
377 if (MPI_Pack(&(cm->fp7_evparam[CM_p7_GFMU]), 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
378 if (MPI_Pack(&(cm->fp7_evparam[CM_p7_GFLAMBDA]), 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
379 if((status = p7_hmm_MPIPack(cm->fp7, buf, n, pos, comm)) != eslOK) ESL_XEXCEPTION(status, "pack failed");
380 }
381
382 if (*pos > n) ESL_XEXCEPTION(eslEMEM, "buffer overflow");
383 return eslOK;
384
385 ERROR:
386 return status;
387 }
388
389 /* Function: cm_nonconfigured_MPIPackSize()
390 *
391 * Synopsis: Calculates size needed to pack a CM that has
392 * just been read from a CM file by a CMFileRead()
393 * call, we'll need to pack far less than a fully
394 * configure CM in this case.
395 *
396 * Incept: EPN, Mon Aug 27 10:34:15 2007
397 * based on p7_hmm_MPIPackSize() from HMMER3.
398 *
399 * Purpose: Calculate an upper bound on the number of bytes
400 * that <cm_nonconfigured_MPIPack()> will need to pack a CM
401 * <cm> in a packed MPI message for MPI communicator
402 * <comm>; return that number of bytes in <*ret_n>.
403 *
404 * Returns: <eslOK> on success, and <*ret_n> contains the answer.
405 *
406 * Throws: <eslESYS> if an MPI call fails, and <*ret_n> is 0.
407 */
408 int
409 cm_nonconfigured_MPIPackSize(CM_t *cm, MPI_Comm comm, int *ret_n)
410 {
411 int status;
412 int i;
413 int n = 0;
414 int K = cm->abc->K;
415 int M = cm->M;
416 int nnodes = cm->nodes;
417 int sz;
418
419 if (MPI_Pack_size(1, MPI_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
420 n += 5*sz; /* M, nodes, clen, abc->type, flags */
421 if (MPI_Pack_size(M*K*K, MPI_FLOAT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
422 n += sz; /* e */
423 if (MPI_Pack_size(M*MAXCONNECT, MPI_FLOAT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
424 n += sz; /* t */
425 if (MPI_Pack_size(M+1, MPI_CHAR, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
426 n += 2*sz; /* sttype, stid */
427 if (MPI_Pack_size(M, MPI_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
428 n += 5*sz; /* ndidx, cfirst, cnum, plast, pnum */
429 if (MPI_Pack_size(nnodes, MPI_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
430 n += sz; /* nodemap */
431 if (MPI_Pack_size(nnodes, MPI_CHAR, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
432 n += sz; /* ndtype */
433 if (MPI_Pack_size(1, MPI_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
434 n += sz; /* nseq */
435 if (MPI_Pack_size(1, MPI_FLOAT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
436 n += 4*sz; /* eff_nseq, el_selfsc, null2_omega, null3_omega */
437 if (MPI_Pack_size(1, MPI_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
438 n += sz; /* checksum */
439 if (MPI_Pack_size(K, MPI_FLOAT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
440 n += sz; /* null */
441 if (MPI_Pack_size(M, MPI_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
442 n += 2*sz; /* dmin/dmax */
443 if (MPI_Pack_size(1, MPI_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
444 n += sz; /* W */
445 if (MPI_Pack_size(1, MPI_DOUBLE, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
446 n += 4*sz; /* beta_W, beta_qdb, tau, maxtau */
447 if (MPI_Pack_size(1, MPI_FLOAT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
448 n += 3*sz; /* ga, tc, nc */
449
450 if ((status = esl_mpi_PackOptSize(cm->name, -1, MPI_CHAR, comm, &sz)) != eslOK) ESL_XEXCEPTION(eslESYS, "pack size failed");
451 n += sz; /* name */
452 if ((status = esl_mpi_PackOptSize(cm->acc, -1, MPI_CHAR, comm, &sz)) != eslOK) ESL_XEXCEPTION(eslESYS, "pack size failed");
453 n += sz; /* acc */
454 if ((status = esl_mpi_PackOptSize(cm->desc, -1, MPI_CHAR, comm, &sz)) != eslOK) ESL_XEXCEPTION(eslESYS, "pack size failed");
455 n += sz; /* desc */
456 if ((status = esl_mpi_PackOptSize(cm->comlog, -1, MPI_CHAR, comm, &sz)) != eslOK) ESL_XEXCEPTION(eslESYS, "pack size failed");
457 n += sz; /* comlog */
458 if ((status = esl_mpi_PackOptSize(cm->ctime, -1, MPI_CHAR, comm, &sz)) != eslOK) ESL_XEXCEPTION(eslESYS, "pack size failed");
459 n += sz; /* ctime */
460
461 if (cm->flags & CMH_RF) if (MPI_Pack_size(cm->clen+2, MPI_CHAR, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
462 n += sz; /* rf */
463 if (cm->flags & CMH_CONS) if (MPI_Pack_size(cm->clen+2, MPI_CHAR, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
464 n += sz; /* consensus */
465 if (cm->flags & CMH_MAP) if (MPI_Pack_size(cm->clen+1, MPI_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
466 n += sz; /* map */
467
468 if (cm->flags & CMH_EXPTAIL_STATS) {
469 for(i = 0; i < EXP_NMODES; i++) {
470 if ((status = expinfo_MPIPackSize(cm->expA[i], comm, &sz)) != eslOK) ESL_XEXCEPTION(eslESYS, "pack size failed");
471 n += sz;
472 }
473 }
474
475 /* Finally, compute size for additional p7 filters */
476 if((cm->flags & CMH_FP7) && (cm->fp7 != NULL)) {
477 if (MPI_Pack_size(1, MPI_FLOAT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
478 n += 2*sz; /* tmp_fp7_gfmu and tmp_fp7_gflambda */
479 if ((status = p7_hmm_MPIPackSize(cm->fp7, comm, &sz)) != eslOK) ESL_XEXCEPTION(status, "p7_hmm_MPIPackSize() failed");
480 n += sz; /* cm->ap7A[i] p7 HMM */
481 }
482
483 *ret_n = n;
484 return eslOK;
485
486 ERROR:
487 *ret_n = 0;
488 return status;
489
490 }
491
492 /* Function: expinfo_MPIPackSize()
493 * Synopsis: Calculates number of bytes needed to pack a
494 * ExpInfo_t object. Follows 'Purpose'
495 * of other *_MPIPackSize() functions above.
496 *
497 * Incept: EPN, Wed Dec 12 05:00:01 2007
498 *
499 * Returns: <eslOK> on success, and <*ret_n> contains the answer.
500 *
501 * Throws: <eslESYS> if an MPI call fails, and <*ret_n> is set to 0.
502 *
503 * Note: The sizing calls here need to stay matched up with
504 * the calls in <expinfo_MPIPack()>.
505 */
506 int
507 expinfo_MPIPackSize(ExpInfo_t *exp, MPI_Comm comm, int *ret_n)
508 {
509 int status;
510 int sz;
511 int n = 0;
512
513 status = MPI_Pack_size(1, MPI_INT, comm, &sz); n += 2*sz; if (status != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
514 /* nrandhits, is_valid */
515 status = MPI_Pack_size(1, MPI_DOUBLE, comm, &sz); n += 6*sz; if (status != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
516 /* mu_orig, mu_extrap, lambda, tailp, cur_eff_dbsize, dbsize */
517
518 *ret_n = n;
519 return eslOK;
520
521 ERROR:
522 *ret_n = 0;
523 return status;
524 }
525
526 /* Function: expinfo_MPIPack()
527 * Synopsis: Packs ExpInfo_t <exp> into MPI buffer.
528 * See 'Purpose','Returns' and 'Throws'
529 * of other *_MPIPack()'s for more info.
530 *
531 * Incept: EPN, Wed Dec 12 05:03:40 2007
532 */
533 int
534 expinfo_MPIPack(ExpInfo_t *exp, char *buf, int n, int *position, MPI_Comm comm)
535 {
536 int status;
537
538 ESL_DPRINTF2(("#DEBUG: expinfo_MPIPack(): ready.\n"));
539
540 status = MPI_Pack((double *) &(exp->cur_eff_dbsize), 1, MPI_DOUBLE, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
541 status = MPI_Pack((double *) &(exp->lambda), 1, MPI_DOUBLE, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
542 status = MPI_Pack((double *) &(exp->mu_extrap), 1, MPI_DOUBLE, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
543 status = MPI_Pack((double *) &(exp->mu_orig), 1, MPI_DOUBLE, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
544 status = MPI_Pack((double *) &(exp->dbsize), 1, MPI_DOUBLE, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
545 status = MPI_Pack((int *) &(exp->nrandhits), 1, MPI_INT, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
546 status = MPI_Pack((double *) &(exp->tailp), 1, MPI_DOUBLE, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
547 status = MPI_Pack((int *) &(exp->is_valid), 1, MPI_INT, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
548 ESL_DPRINTF2(("#DEBUG: expinfo_results_MPIPack(): done. Packed %d bytes into buffer of size %d\n", *position, n));
549
550 if (*position > n) ESL_EXCEPTION(eslEMEM, "buffer overflow");
551 return eslOK;
552 }
553
554 /* Function: expinfo_MPIUnpack()
555 * Synopsis: Unpacks ExpInfo_t <exp> from an MPI buffer.
556 * Follows 'Purpose', 'Returns', 'Throws' of other
557 * *_MPIUnpack() functions above.
558 *
559 * Incept: EPN, Wed Dec 12 05:29:19 2007
560 */
561 int
562 expinfo_MPIUnpack(char *buf, int n, int *pos, MPI_Comm comm, ExpInfo_t **ret_exp)
563 {
564 int status;
565 ExpInfo_t *exp;
566
567 ESL_ALLOC(exp, sizeof(ExpInfo_t));
568 status = MPI_Unpack (buf, n, pos, &(exp->cur_eff_dbsize), 1, MPI_DOUBLE, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
569 status = MPI_Unpack (buf, n, pos, &(exp->lambda), 1, MPI_DOUBLE, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
570 status = MPI_Unpack (buf, n, pos, &(exp->mu_extrap), 1, MPI_DOUBLE, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
571 status = MPI_Unpack (buf, n, pos, &(exp->mu_orig), 1, MPI_DOUBLE, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
572 status = MPI_Unpack (buf, n, pos, &(exp->dbsize), 1, MPI_DOUBLE, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
573 status = MPI_Unpack (buf, n, pos, &(exp->nrandhits), 1, MPI_INT, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
574 status = MPI_Unpack (buf, n, pos, &(exp->tailp), 1, MPI_DOUBLE, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
575 status = MPI_Unpack (buf, n, pos, &(exp->is_valid), 1, MPI_INT, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
576
577 *ret_exp = exp;
578 return eslOK;
579
580 ERROR:
581 if(exp != NULL) free(exp);
582 *ret_exp = NULL;
583 return status;
584 }
585
586
587 /* Function: cm_dsq_MPISend()
588 *
589 * Incept: EPN, Tue Aug 28 15:20:16 2007
590 * EPN, Fri Jan 13 05:25:13 2012 [updated]
591 *
592 * Purpose: Sends a digitized sequence, its length and a sequence index
593 * as a work unit to MPI process <dest> (<dest> ranges from <0..nproc-1>),
594 * tagging the message with MPI tag <tag> for MPI communicator
595 * <comm>. The receiver uses <cm_dsq_MPIRecv()> to receive the dsq.
596 *
597 * Work units are prefixed by a status code. If <dsq> is
598 * <non-NULL>, the work unit is an <eslOK> code followed by
599 * the packed MSA. If <dsq> is NULL, the work unit is an
600 * <eslEOD> code, which <cm_dsq_MPIRecv()> knows how
601 * to interpret; this is typically used for an end-of-data
602 * signal to cleanly shut down worker processes.
603 *
604 * In order to minimize alloc/free cycles, caller passes a
605 * pointer to a working buffer <*buf> of size <*nalloc>
606 * characters. If necessary (i.e. if <dsq> is too big to
607 * fit), <*dsq> will be reallocated and <*nalloc> increased
608 * to the new size. As a special case, if <*dsq> is <NULL>
609 * and <*nalloc> is 0, the buffer will be allocated
610 * appropriately, but the caller is still responsible for
611 * free'ing it.
612 *
613 * Args: dsq - digitized seq to send
614 * L - length of dsq we're sending (dsq could extend further)
615 * idx - sequence index (serves as unique id) for the dsq we're sending
616 * dest - MPI destination (0..nproc-1)
617 * tag - MPI tag
618 * buf - pointer to a working buffer
619 * nalloc - current allocated size of <*buf>, in characters
620 *
621 * Returns: <eslOK> on success; <*buf> may have been reallocated and
622 * <*nalloc> may have been increased.
623 *
624 * Throws: <eslESYS> if an MPI call fails; <eslEMEM> if a malloc/realloc
625 * fails. In either case, <*buf> and <*nalloc> remain valid and useful
626 * memory (though the contents of <*buf> are undefined).
627 */
628 int
629 cm_dsq_MPISend(ESL_DSQ *dsq, int64_t L, int64_t idx, int dest, int tag, MPI_Comm comm, char **buf, int *nalloc)
630 {
631 int status;
632 int code;
633 int sz, n, pos;
634
635 /* First, figure out the size of the work unit */
636 if (MPI_Pack_size(1, MPI_INT, comm, &n) != 0) ESL_EXCEPTION(eslESYS, "mpi pack size failed"); /* status code */
637 if (dsq != NULL) {
638 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) ESL_EXCEPTION(eslESYS, "mpi pack size failed"); /* L */
639 n += sz;
640 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) ESL_EXCEPTION(eslESYS, "mpi pack size failed"); /* idx */
641 n += sz;
642 if (MPI_Pack_size(L+2, MPI_BYTE, comm, &sz) != 0) ESL_EXCEPTION(eslESYS, "mpi pack size failed"); /* dsq */
643 n += sz;
644 }
645 ESL_DPRINTF2(("#DEBUG: cm_dsq_MPISend(): dsq has size %d\n", n));
646
647 /* Make sure the buffer is allocated appropriately */
648 if (*buf == NULL || n > *nalloc) {
649 ESL_REALLOC(*buf, sizeof(char) * n);
650 *nalloc = n;
651 }
652 ESL_DPRINTF2(("#DEBUG: cm_dsq_MPISend(): buffer is ready\n"));
653
654 /* Pack the status code, L, idx, and dsq into the buffer */
655 pos = 0;
656 code = (dsq == NULL) ? eslEOD : eslOK;
657 if (MPI_Pack(&code, 1, MPI_INT, *buf, n, &pos, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi pack failed");
658 if (dsq != NULL) {
659 if (MPI_Pack(&L, 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi pack failed");
660 if (MPI_Pack(&idx, 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi pack failed");
661 if (MPI_Pack(dsq, L+2, MPI_BYTE, *buf, n, &pos, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi pack failed");
662 }
663 ESL_DPRINTF2(("#DEBUG: cm_dsq_MPISend(): dsq is packed into %d bytes\n", pos));
664
665 /* Send the packed profile to destination */
666 if (MPI_Send(*buf, n, MPI_PACKED, dest, tag, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi send failed");
667 ESL_DPRINTF2(("#DEBUG: cm_dsq_MPISend(): dsq is sent.\n"));
668 return eslOK;
669
670 ERROR:
671 return status;
672 }
673
674 /* Function: cm_dsq_MPIRecv()
675 *
676 * Incept: EPN, Tue Aug 28 15:29:34 2007
677 * EPN, Fri Jan 13 05:25:29 2012 [updated]
678 *
679 * Purpose: Receives a work unit that consists of a digitized sequence
680 * its length and an index from <source> (<0..nproc-1>, or
681 * <MPI_ANY_SOURCE>) tagged as <tag> from communicator <comm>.
682 *
683 * Work units are prefixed by a status code. If the unit's
684 * code is <eslOK> and no errors are encountered, this
685 * routine will return <eslOK> a non-<NULL> <*ret_dsq> and
686 * a valid <*ret_L> and <*ret_idx> (equal to whatever was
687 * received (could be -1)). If the unit's code is <eslEOD>
688 * (a shutdown signal), this routine returns <eslEOD>,
689 * <*ret_dsq> is <NULL> and <*ret_L> and <*ret_idx> are -1.
690 *
691 * To minimize alloc/free cycles in this routine, caller
692 * passes a pointer to a buffer <*buf> of size <*nalloc>
693 * characters. These are passed by reference, because when
694 * necessary, <*buf> will be reallocated and <*nalloc>
695 * increased to the new size. As a special case, if <*buf>
696 * is <NULL> and <*nalloc> is 0, the buffer will be
697 * allocated appropriately, but the caller is still
698 * responsible for free'ing it.
699 *
700 * If the packed dsq is an end-of-data signal, return
701 * <eslEOD>, and <*ret_dsq> is <NULL>.
702 *
703 * Returns: <eslOK> on success. <*ret_dsq> contains the new dsq; it
704 * is allocated here, and the caller is responsible for
705 * free'ing it. <*buf> may have been reallocated to a
706 * larger size, and <*nalloc> may have been increased.
707 *
708 *
709 * Throws: <eslESYS> if an MPI call fails; <eslEMEM> if an allocation fails.
710 * In either case, <*ret_dsq> is NULL, and the <buf> and its size
711 * <*nalloc> remain valid.
712 */
713 int
714 cm_dsq_MPIRecv(int source, int tag, MPI_Comm comm, char **buf, int *nalloc, ESL_DSQ **ret_dsq, int64_t *ret_L, int64_t *ret_idx)
715 {
716 int status, code;
717 ESL_DSQ *dsq = NULL;
718 int64_t L = -1;
719 int64_t idx = -1;
720 int n;
721 int pos;
722 MPI_Status mpistatus;
723
724 /* Probe first, because we need to know if our buffer is big enough. */
725 if (MPI_Probe(source, tag, comm, &mpistatus) != 0) ESL_XEXCEPTION(eslESYS, "mpi probe failed");
726 if (MPI_Get_count(&mpistatus, MPI_PACKED, &n) != 0) ESL_XEXCEPTION(eslESYS, "mpi get count failed");
727
728 /* Make sure the buffer is allocated appropriately */
729 if (*buf == NULL || n > *nalloc) {
730 void *tmp;
731 ESL_RALLOC(*buf, tmp, sizeof(char) * n);
732 *nalloc = n;
733 }
734
735 /* Receive the packed work unit */
736 ESL_DPRINTF2(("#DEBUG: cm_dsq_MPIRecv(): about to receive dsq.\n"));
737 if (MPI_Recv(*buf, n, MPI_PACKED, source, tag, comm, &mpistatus) != 0) ESL_XEXCEPTION(eslESYS, "mpi recv failed");
738 ESL_DPRINTF2(("#DEBUG: cm_dsq_MPIRecv(): dsq has been received.\n"));
739
740 /* Unpack it - where the first integer is a status code, OK or EOD */
741 ESL_DPRINTF2(("#DEBUG: cm_dsq_MPIRecv(): about to unpack dsq.\n"));
742 pos = 0;
743 if (MPI_Unpack (*buf, n, &pos, &code, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
744 if (code == eslEOD) { status = eslEOD; goto ERROR; }
745 if (MPI_Unpack (*buf, n, &pos, &L, 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
746 if (MPI_Unpack (*buf, n, &pos, &idx, 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
747 ESL_ALLOC(dsq, sizeof(ESL_DSQ) * (L+2));
748 if (MPI_Unpack (*buf, n, &pos, dsq, L+2, MPI_BYTE, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
749 dsq[0] = dsq[(L+1)] = eslDSQ_SENTINEL; /* overwrite */
750 ESL_DPRINTF2(("#DEBUG: cm_dsq_MPIRecv(): dsq has been unpacked.\n"));
751
752 *ret_L = L;
753 *ret_idx = idx;
754 *ret_dsq = dsq;
755
756 return eslOK;
757
758 ERROR:
759 if (dsq != NULL) free(dsq);
760 *ret_dsq = NULL;
761 *ret_L = -1;
762 *ret_idx = -1;
763 return status;
764 }
765
766 /* Function: cm_parsetree_MPIPackSize()
767 * Synopsis: Calculates number of bytes needed to pack a
768 * parsetree.
769 * Incept: EPN, Wed Aug 29 05:44:28 2007
770 *
771 * Purpose: Calculate an upper bound on the number of bytes
772 * that <cm_parsetree_MPIPack()> will need to pack
773 * a parsetree in a packed MPI message in
774 * communicator <comm>; return that number of bytes
775 * in <*ret_n>.
776 *
777 * Caller will generally use this result to determine how
778 * to allocate a buffer before starting to pack into it.
779 *
780 * Returns: <eslOK> on success, and <*ret_n> contains the answer.
781 *
782 * Throws: <eslESYS> if an MPI call fails, and <*ret_n> is set to 0.
783 *
784 * Note: The sizing calls here need to stay matched up with
785 * the calls in <cm_parsetree_MPIPack()>.
786 */
787 int
788 cm_parsetree_MPIPackSize(Parsetree_t *tr, MPI_Comm comm, int *ret_n)
789 {
790 int status;
791 int sz;
792 int n = 0;
793
794 status = MPI_Pack_size(1, MPI_INT, comm, &sz); n += sz; if (status != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); /* tr->n */
795 /* don't send tr->nalloc, it'll be set is as tr->n when this is unpacked */
796 status = MPI_Pack_size(1, MPI_INT, comm, &sz); n += sz; if (status != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); /* tr->memblock */
797 status = MPI_Pack_size(1, MPI_INT, comm, &sz); n += sz; if (status != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); /* tr->is_std */
798 status = MPI_Pack_size(1, MPI_INT, comm, &sz); n += sz; if (status != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); /* tr->pass_idx */
799 status = MPI_Pack_size(1, MPI_FLOAT,comm, &sz); n += sz; if (status != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); /* tr->trpenalty */
800
801 status = MPI_Pack_size(tr->n, MPI_INT, comm, &sz); n += sz; if (status != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); /* tr->emitl[] */
802 status = MPI_Pack_size(tr->n, MPI_INT, comm, &sz); n += sz; if (status != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); /* tr->emitr[] */
803 status = MPI_Pack_size(tr->n, MPI_INT, comm, &sz); n += sz; if (status != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); /* tr->state[] */
804 status = MPI_Pack_size(tr->n, MPI_CHAR, comm, &sz); n += sz; if (status != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); /* tr->mode[] */
805 status = MPI_Pack_size(tr->n, MPI_INT, comm, &sz); n += sz; if (status != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); /* tr->nxtl[] */
806 status = MPI_Pack_size(tr->n, MPI_INT, comm, &sz); n += sz; if (status != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); /* tr->nxtr[] */
807 status = MPI_Pack_size(tr->n, MPI_INT, comm, &sz); n += sz; if (status != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); /* tr->prv[] */
808
809 *ret_n = n;
810 return eslOK;
811
812 ERROR:
813 *ret_n = 0;
814 return status;
815 }
816
817 /* Function: cm_parsetree_MPIPack()
818 * Synopsis: Packs parsetree into MPI buffer.
819 * Incept: EPN, Wed Aug 29 05:22:32 2007
820 *
821 * Purpose: Packs parsetree <tr> into an
822 * MPI packed message buffer <buf> of length <n> bytes,
823 * starting at byte position
824 * <*position>, for MPI communicator <comm>.
825 *
826 * Returns: <eslOK> on success; <buf> now contains the
827 * packed <tr>, and <*position> is set to the byte
828 * immediately following the last byte of the results
829 * in <buf>.
830 *
831 * Throws: <eslESYS> if an MPI call fails; or <eslEMEM> if the
832 * buffer's length <n> is overflowed by trying to pack
833 * <rnode> into <buf>. In either case, the state of
834 * <buf> and <*position> is undefined, and both should
835 * be considered to be corrupted.
836 *
837 */
838 int
839 cm_parsetree_MPIPack(Parsetree_t *tr, char *buf, int n, int *position, MPI_Comm comm)
840 {
841 int status;
842
843 ESL_DPRINTF2(("#DEBUG: cm_parsetree_MPIPack(): ready.\n"));
844
845 status = MPI_Pack(&tr->n, 1, MPI_INT, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
846 status = MPI_Pack(&tr->memblock, 1, MPI_INT, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
847 status = MPI_Pack(&tr->is_std, 1, MPI_INT, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
848 status = MPI_Pack(&tr->pass_idx, 1, MPI_INT, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
849 status = MPI_Pack(&tr->trpenalty, 1, MPI_FLOAT,buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
850 status = MPI_Pack(tr->emitl, tr->n, MPI_INT, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
851 status = MPI_Pack(tr->emitr, tr->n, MPI_INT, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
852 status = MPI_Pack(tr->state, tr->n, MPI_INT, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
853 status = MPI_Pack(tr->mode, tr->n, MPI_CHAR, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
854 status = MPI_Pack(tr->nxtl, tr->n, MPI_INT, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
855 status = MPI_Pack(tr->nxtr, tr->n, MPI_INT, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
856 status = MPI_Pack(tr->prv, tr->n, MPI_INT, buf, n, position, comm); if (status != 0) ESL_EXCEPTION(eslESYS, "pack failed");
857
858 ESL_DPRINTF2(("#DEBUG: cm_parsetree_MPIPack(): done. Packed %d bytes into buffer of size %d\n", *position, n));
859
860 if (*position > n) ESL_EXCEPTION(eslEMEM, "buffer overflow");
861 return eslOK;
862 }
863
864 /* Function: cm_parsetree_MPIUnpack()
865 * Synopsis: Unpacks parsetree from an MPI buffer.
866 * Incept: EPN, Wed Aug 29 05:10:20 2007
867 *
868 * Purpose: Unpack a newly allocated parsetree node from MPI packed buffer
869 * <buf>, starting from position <*pos>, where the total length
870 * of the buffer in bytes is <n>.
871 *
872 * Returns: <eslOK> on success. <*pos> is updated to the position of
873 * the next element in <buf> to unpack (if any). <*ret_tr>
874 * contains a newly allocated parsetree, which the caller is
875 * responsible for free'ing.
876 *
877 * Throws: <eslESYS> on an MPI call failure. <eslEMEM> on allocation failure.
878 * In either case, <*ret_tr> is <NULL>, and the state of <buf>
879 * and <*pos> is undefined and should be considered to be corrupted.
880 */
881 int
882 cm_parsetree_MPIUnpack(char *buf, int n, int *pos, MPI_Comm comm, Parsetree_t **ret_tr)
883 {
884 int status;
885 Parsetree_t *tr = NULL;
886 int tr_n;
887
888 status = MPI_Unpack (buf, n, pos, &tr_n, 1, MPI_INT, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
889 tr = CreateParsetree(tr_n);
890 tr->n = tr_n;
891 tr->nalloc = tr_n;
892 status = MPI_Unpack (buf, n, pos, &tr->memblock, 1, MPI_INT, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
893 status = MPI_Unpack (buf, n, pos, &tr->is_std, 1, MPI_INT, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
894 status = MPI_Unpack (buf, n, pos, &tr->pass_idx, 1, MPI_INT, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
895 status = MPI_Unpack (buf, n, pos, &tr->trpenalty, 1, MPI_FLOAT, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
896
897 status = MPI_Unpack (buf, n, pos, tr->emitl, tr_n, MPI_INT, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
898 status = MPI_Unpack (buf, n, pos, tr->emitr, tr_n, MPI_INT, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
899 status = MPI_Unpack (buf, n, pos, tr->state, tr_n, MPI_INT, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
900 status = MPI_Unpack (buf, n, pos, tr->mode, tr_n, MPI_CHAR, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
901 status = MPI_Unpack (buf, n, pos, tr->nxtl, tr_n, MPI_INT, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
902 status = MPI_Unpack (buf, n, pos, tr->nxtr, tr_n, MPI_INT, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
903 status = MPI_Unpack (buf, n, pos, tr->prv, tr_n, MPI_INT, comm); if (status != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
904
905 *ret_tr = tr;
906 return eslOK;
907
908 ERROR:
909 if (tr != NULL)
910 FreeParsetree(tr);
911 *ret_tr = NULL;
912 return status;
913 }
914
915 /*****************************************************************
916 * Communicating CM_PIPELINE
917 *****************************************************************/
918
919 /* Function: cm_pipeline_MPISend()
920 * Synopsis: Send pipeline data as an MPI message.
921 * Incept: EPN, Thu Jun 2 14:36:01 2011
922 * MSF, Wed Sep 09 09:09:47 2009 [Janelia] (p7_pipeline_MPISend())
923 *
924 * Purpose: Sends pipeline statistics <pli> to MPI process <dest>
925 * (where <dest> ranges from 0..<nproc-1>), with MPI tag
926 * <tag> for MPI communicator <comm>.
927 *
928 * In order to minimize alloc/free cycles in this routine,
929 * caller passes a pointer to a working buffer <*buf> of
930 * size <*nalloc> characters. If necessary (i.e. if <pli> is
931 * too big to fit), <*buf> will be reallocated and <*nalloc>
932 * increased to the new size. As a special case, if <*buf>
933 * is <NULL> and <*nalloc> is 0, the buffer will be
934 * allocated appropriately, but the caller is still
935 * responsible for free'ing it.
936 *
937 * If <pli> is NULL, the pipeline statistics are initialized
938 * to zeros.
939 *
940 * Returns: <eslOK> on success.
941 */
942 int
943 cm_pipeline_MPISend(CM_PIPELINE *pli, int dest, int tag, MPI_Comm comm, char **buf, int *nalloc)
944 {
945 int status;
946 int sz, n, pos;
947 int pass_idx;
948
949 CM_PIPELINE bogus;
950
951 /* This will look wasteful, but the MPI spec doesn't guarantee that
952 * MPI_Pack_size(x, ...) + MPI_Pack_size(x, ... ) == MPI_Pack_size(2x, ...).
953 * Indeed there are some hints in the spec that that's *not* true.
954 * So we assume we must match our Pack_size calls exactly to our Pack calls.
955 */
956 n = 0;
957 if (MPI_Pack_size(1, MPI_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* mode */
958 if (MPI_Pack_size(1, MPI_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* Z_setby */
959 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* nseqs */
960 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* nmodels */
961 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* nnodes */
962 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* nmodels_hmmonly */
963 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* nnodes_hmmonly */
964 if (MPI_Pack_size(1, MPI_DOUBLE, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* Z */
965 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* cur_cm_idx */
966 if (MPI_Pack_size(1, MPI_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* cur_clan_idx */
967 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* cur_seq_idx */
968 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* cur_pass_idx */
969 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* cur_hit_idx */
970
971 for(pass_idx = 0; pass_idx < NPLI_PASSES; pass_idx++) {
972 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* npli_top */
973 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* npli_bot */
974 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* nres_top */
975 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* nres_bot */
976 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_past_msv */
977 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_past_vit */
978 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_past_fwd */
979 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_past_gfwd */
980 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_past_edef */
981 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_past_cyk */
982 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_past_ins */
983 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_output */
984 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_past_msvbias */
985 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_past_vitbias */
986 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_past_fwdbias */
987 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_past_gfwdbias */
988 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_past_edefbias */
989
990 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* pos_past_msv */
991 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* pos_past_vit */
992 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* pos_past_fwd */
993 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* pos_past_gfwd */
994 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* pos_past_edef */
995 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* pos_past_cyk */
996 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* pos_past_ins */
997 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* pos_output */
998 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* pos_past_msvbias */
999 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* pos_past_vitbias */
1000 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* pos_past_fwdbias */
1001 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* pos_past_gfwdbias */
1002 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* pos_past_edefbias */
1003
1004 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_overflow_fcyk */
1005 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_overflow_final */
1006 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_aln_hb */
1007 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* n_aln_dccyk */
1008 }
1009 /* Make sure the buffer is allocated appropriately */
1010 if (*buf == NULL || n > *nalloc) {
1011 void *tmp;
1012 ESL_RALLOC(*buf, tmp, sizeof(char) * n);
1013 *nalloc = n;
1014 }
1015
1016 /* if no pipeline was defined, return zeros for the stats */
1017 if (pli == NULL)
1018 {
1019 bogus.mode = CM_SEARCH_SEQS; /* that's 0. (some compilers complain if you set 0 directly. */
1020 bogus.Z_setby = CM_ZSETBY_SSIINFO; /* ditto. */
1021 bogus.nseqs = 0;
1022 bogus.nmodels = 0;
1023 bogus.nnodes = 0;
1024 bogus.nmodels_hmmonly = 0;
1025 bogus.nnodes_hmmonly = 0;
1026 bogus.Z = 0.0;
1027 bogus.cur_cm_idx = -1;
1028 bogus.cur_clan_idx = -1;
1029 bogus.cur_seq_idx = -1;
1030 bogus.cur_pass_idx = -1;
1031 for(pass_idx = 0; pass_idx < NPLI_PASSES; pass_idx++) {
1032 cm_pli_ZeroAccounting(&(bogus.acct[pass_idx]));
1033 }
1034 pli = &bogus;
1035 }
1036
1037 /* Pack the pipeline into the buffer */
1038 pos = 0;
1039 if (MPI_Pack(&pli->mode, 1, MPI_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1040 if (MPI_Pack(&pli->Z_setby, 1, MPI_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1041 if (MPI_Pack(&pli->nseqs, 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1042 if (MPI_Pack(&pli->nmodels, 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1043 if (MPI_Pack(&pli->nnodes, 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1044 if (MPI_Pack(&pli->nmodels_hmmonly, 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1045 if (MPI_Pack(&pli->nnodes_hmmonly, 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1046 if (MPI_Pack(&pli->Z, 1, MPI_DOUBLE, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1047 if (MPI_Pack(&pli->cur_cm_idx, 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1048 if (MPI_Pack(&pli->cur_clan_idx, 1, MPI_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1049 if (MPI_Pack(&pli->cur_seq_idx, 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1050 if (MPI_Pack(&pli->cur_pass_idx, 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1051
1052 for(pass_idx = 0; pass_idx < NPLI_PASSES; pass_idx++) {
1053 if (MPI_Pack(&(pli->acct[pass_idx].npli_top), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1054 if (MPI_Pack(&(pli->acct[pass_idx].npli_bot), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1055 if (MPI_Pack(&(pli->acct[pass_idx].nres_top), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1056 if (MPI_Pack(&(pli->acct[pass_idx].nres_bot), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1057 if (MPI_Pack(&(pli->acct[pass_idx].n_past_msv), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1058 if (MPI_Pack(&(pli->acct[pass_idx].n_past_vit), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1059 if (MPI_Pack(&(pli->acct[pass_idx].n_past_fwd), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1060 if (MPI_Pack(&(pli->acct[pass_idx].n_past_gfwd), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1061 if (MPI_Pack(&(pli->acct[pass_idx].n_past_edef), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1062 if (MPI_Pack(&(pli->acct[pass_idx].n_past_cyk), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1063 if (MPI_Pack(&(pli->acct[pass_idx].n_past_ins), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1064 if (MPI_Pack(&(pli->acct[pass_idx].n_output), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1065 if (MPI_Pack(&(pli->acct[pass_idx].n_past_msvbias), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1066 if (MPI_Pack(&(pli->acct[pass_idx].n_past_vitbias), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1067 if (MPI_Pack(&(pli->acct[pass_idx].n_past_fwdbias), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1068 if (MPI_Pack(&(pli->acct[pass_idx].n_past_gfwdbias), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1069 if (MPI_Pack(&(pli->acct[pass_idx].n_past_edefbias), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1070
1071 if (MPI_Pack(&(pli->acct[pass_idx].pos_past_msv), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1072 if (MPI_Pack(&(pli->acct[pass_idx].pos_past_vit), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1073 if (MPI_Pack(&(pli->acct[pass_idx].pos_past_fwd), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1074 if (MPI_Pack(&(pli->acct[pass_idx].pos_past_gfwd), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1075 if (MPI_Pack(&(pli->acct[pass_idx].pos_past_edef), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1076 if (MPI_Pack(&(pli->acct[pass_idx].pos_past_cyk), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1077 if (MPI_Pack(&(pli->acct[pass_idx].pos_past_ins), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1078 if (MPI_Pack(&(pli->acct[pass_idx].pos_output), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1079 if (MPI_Pack(&(pli->acct[pass_idx].pos_past_msvbias), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1080 if (MPI_Pack(&(pli->acct[pass_idx].pos_past_vitbias), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1081 if (MPI_Pack(&(pli->acct[pass_idx].pos_past_fwdbias), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1082 if (MPI_Pack(&(pli->acct[pass_idx].pos_past_gfwdbias), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1083 if (MPI_Pack(&(pli->acct[pass_idx].pos_past_edefbias), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1084
1085 if (MPI_Pack(&(pli->acct[pass_idx].n_overflow_fcyk), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1086 if (MPI_Pack(&(pli->acct[pass_idx].n_overflow_final), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1087 if (MPI_Pack(&(pli->acct[pass_idx].n_aln_hb), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1088 if (MPI_Pack(&(pli->acct[pass_idx].n_aln_dccyk), 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1089 }
1090
1091 /* Send the packed pipeline to destination */
1092 MPI_Send(*buf, n, MPI_PACKED, dest, tag, comm);
1093 return eslOK;
1094
1095 ERROR:
1096 return status;
1097 }
1098
1099
1100 /* Function: cm_pipeline_MPIRecv()
1101 * Synopsis: Receive pipeline data as an MPI message.
1102 * Incept: EPN, Thu Jun 2 14:41:46 2011
1103 * MSF, Wed Sep 09 09:09:47 2009 [Janelia] (p7_pipeline_MPIRecv()
1104 *
1105 * Purpose: Receive a pipeline from <source> (where <source> is usually
1106 * process 0, the master) with tag <tag> from communicator <comm>,
1107 * and return it in <*ret_pli>.
1108 *
1109 * To minimize alloc/free cycles in this routine, caller
1110 * passes a pointer to a buffer <*buf> of size <*nalloc>
1111 * characters. These are passed by reference because if
1112 * necessary, <buf> will be reallocated and <nalloc>
1113 * increased to the new size. As a special case, if <buf>
1114 * is <NULL> and <nalloc> is 0, the buffer will be
1115 * allocated appropriately, but the caller is still
1116 * responsible for free'ing it.
1117 *
1118 * Returns: <eslOK> on success. <*ret_pli> contains the new pipeline;
1119 * it is allocated here, and the caller is responsible for
1120 * free'ing it. <*buf> may have been reallocated to a
1121 * larger size, and <*nalloc> may have been increased.
1122 *
1123 */
1124 int
1125 cm_pipeline_MPIRecv(int source, int tag, MPI_Comm comm, char **buf, int *nalloc, ESL_GETOPTS *go, CM_PIPELINE **ret_pli)
1126 {
1127 int status;
1128 CM_PIPELINE *pli = NULL;
1129 int n;
1130 int pos;
1131 int pass_idx;
1132 MPI_Status mpistatus;
1133
1134 /* Probe first, because we need to know if our buffer is big enough.
1135 */
1136 MPI_Probe(source, tag, comm, &mpistatus);
1137 MPI_Get_count(&mpistatus, MPI_PACKED, &n);
1138
1139 /* Make sure the buffer is allocated appropriately */
1140 if (*buf == NULL || n > *nalloc) {
1141 void *tmp;
1142 ESL_RALLOC(*buf, tmp, sizeof(char) * n);
1143 *nalloc = n;
1144 }
1145
1146 /* Receive the packed pipeline */
1147 MPI_Recv(*buf, n, MPI_PACKED, source, tag, comm, &mpistatus);
1148
1149 /* Unpack it - watching out for the EOD signal of M = -1. */
1150 pos = 0; /* irrelevant, these are overwritten below */
1151 if ((pli = cm_pipeline_Create(go, NULL, 1, 1, 0, CM_ZSETBY_SSIINFO, CM_SEARCH_SEQS)) == NULL) { status = eslEMEM; goto ERROR; } /* mode will be immediately overwritten */
1152 if (MPI_Unpack(*buf, n, &pos, &(pli->mode), 1, MPI_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1153 if (MPI_Unpack(*buf, n, &pos, &(pli->Z_setby), 1, MPI_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1154 if (MPI_Unpack(*buf, n, &pos, &(pli->nseqs), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1155 if (MPI_Unpack(*buf, n, &pos, &(pli->nmodels), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1156 if (MPI_Unpack(*buf, n, &pos, &(pli->nnodes), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1157 if (MPI_Unpack(*buf, n, &pos, &(pli->nmodels_hmmonly), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1158 if (MPI_Unpack(*buf, n, &pos, &(pli->nnodes_hmmonly), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1159 if (MPI_Unpack(*buf, n, &pos, &(pli->Z), 1, MPI_DOUBLE, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1160 if (MPI_Unpack(*buf, n, &pos, &(pli->cur_cm_idx), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1161 if (MPI_Unpack(*buf, n, &pos, &(pli->cur_clan_idx), 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1162 if (MPI_Unpack(*buf, n, &pos, &(pli->cur_seq_idx), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1163 if (MPI_Unpack(*buf, n, &pos, &(pli->cur_pass_idx), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1164
1165 for(pass_idx = 0; pass_idx < NPLI_PASSES; pass_idx++) {
1166 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].npli_top), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1167 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].npli_bot), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1168 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].nres_top), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1169 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].nres_bot), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1170 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_past_msv), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1171 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_past_vit), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1172 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_past_fwd), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1173 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_past_gfwd), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1174 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_past_edef), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1175 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_past_cyk), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1176 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_past_ins), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1177 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_output), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1178 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_past_msvbias), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1179 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_past_vitbias), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1180 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_past_fwdbias), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1181 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_past_gfwdbias), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1182 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_past_edefbias), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1183
1184 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].pos_past_msv), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1185 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].pos_past_vit), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1186 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].pos_past_fwd), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1187 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].pos_past_gfwd), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1188 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].pos_past_edef), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1189 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].pos_past_cyk), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1190 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].pos_past_ins), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1191 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].pos_output), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1192 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].pos_past_msvbias), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1193 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].pos_past_vitbias), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1194 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].pos_past_fwdbias), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1195 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].pos_past_gfwdbias), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1196 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].pos_past_edefbias), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1197
1198 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_overflow_fcyk), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1199 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_overflow_final), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1200 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_aln_hb), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1201 if (MPI_Unpack(*buf, n, &pos, &(pli->acct[pass_idx].n_aln_dccyk), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1202 }
1203 *ret_pli = pli;
1204 return eslOK;
1205
1206 ERROR:
1207 if (pli != NULL) cm_pipeline_Destroy(pli, NULL);
1208 *ret_pli = NULL;
1209 return status;
1210 }
1211
1212 /*****************************************************************
1213 * Communicating CM_TOPHITS
1214 *****************************************************************/
1215
1216 /* Function: cm_tophits_MPISend()
1217 * Synopsis: Send the TOPHITS as an MPI work unit.
1218 * Incept: EPN, Thu Jun 2 08:45:05 2011
1219 * MSF, Mon Sep 21 22:22:00 2009 [Janelia] (p7_tophits_MPISend()
1220 *
1221 * Purpose: Sends the TOPHITS <th> as a work unit to MPI process
1222 * <dest> (where <dest> ranges from 0..<nproc-1>), tagged
1223 * with MPI tag <tag>, for MPI communicator <comm>, as
1224 * the sole workunit or result.
1225 *
1226 * After the TOPHITS <th> information has been sent, send
1227 * the each hit as an indepentant message.
1228 *
1229 * Returns: <eslOK> on success; <*buf> may have been reallocated and
1230 * <*nalloc> may have been increased.
1231 *
1232 * Throws: <eslESYS> if an MPI call fails; <eslEMEM> if a malloc/realloc
1233 * fails. In either case, <*buf> and <*nalloc> remain valid and useful
1234 * memory (though the contents of <*buf> are undefined).
1235 */
1236 int
1237 cm_tophits_MPISend(CM_TOPHITS *th, int dest, int tag, MPI_Comm comm, char **buf, int *nalloc)
1238 {
1239 int status;
1240 int sz, n, pos;
1241 int i;
1242
1243 CM_HIT *hit = NULL;
1244
1245 sz = 0;
1246 n = 0;
1247
1248 /* calculate the buffer size needed to hold the largest hit */
1249 hit = th->unsrt;
1250 for (i = 0; i < th->N; i++) {
1251 if ((status = cm_hit_MPIPackSize(hit, comm, &sz)) != eslOK) goto ERROR;
1252 n = ESL_MAX(n, sz);
1253 hit++;
1254 }
1255 if (MPI_Pack_size(3, MPI_LONG_LONG_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed");
1256 n = ESL_MAX(n, sz);
1257
1258 /* Make sure the buffer is allocated appropriately */
1259 if (*buf == NULL || n > *nalloc) {
1260 void *tmp;
1261 ESL_RALLOC(*buf, tmp, sizeof(char) * n);
1262 *nalloc = n;
1263 }
1264
1265 pos = 0;
1266 if (MPI_Pack(&th->N, 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1267 if (MPI_Pack(&th->nreported, 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1268 if (MPI_Pack(&th->nincluded, 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1269
1270 /* Send the packed tophits information */
1271 if (MPI_Send(*buf, n, MPI_PACKED, dest, tag, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi send failed");
1272 if (th->N == 0) return eslOK;
1273
1274 /* loop through the hit list sending to dest */
1275 hit = th->unsrt;
1276 for (i = 0; i < th->N; i++) {
1277 if ((status = cm_hit_MPISend(hit, dest, tag, comm, buf, nalloc)) != eslOK) goto ERROR;
1278 hit++;
1279 }
1280
1281 return eslOK;
1282
1283 ERROR:
1284 return status;
1285 }
1286
1287 /* Function: cm_tophits_MPIRecv()
1288 * Synopsis: Receives an TOPHITS as a work unit from an MPI sender.
1289 * Incept: EPN, Thu Jun 2 14:07:19 2011
1290 * MSF, Mon Sep 21 22:22:00 2009 [Janelia] (p7_tophits_MPIRecv())
1291 *
1292 * Purpose: Sends the TOPHITS <th> as a work unit to MPI process
1293 * <dest> (where <dest> ranges from 0..<nproc-1>), tagged
1294 * with MPI tag <tag>, for MPI communicator <comm>, as
1295 * the sole workunit or result.
1296 *
1297 * After the TOPHITS <th> information has been sent, send
1298 * the each hit as an indepentant message.
1299 *
1300 * Returns: <eslOK> on success; <*buf> may have been reallocated and
1301 * <*nalloc> may have been increased.
1302 *
1303 * Throws: <eslESYS> if an MPI call fails; <eslEMEM> if a malloc/realloc
1304 * fails. In either case, <*buf> and <*nalloc> remain valid and useful
1305 * memory (though the contents of <*buf> are undefined).
1306 */
1307 int
1308 cm_tophits_MPIRecv(int source, int tag, MPI_Comm comm, char **buf, int *nalloc, CM_TOPHITS **ret_th)
1309 {
1310 int n;
1311 int status;
1312 int pos;
1313 CM_TOPHITS *th = NULL;
1314 CM_HIT *hit = NULL;
1315 MPI_Status mpistatus;
1316
1317 uint64_t nhits;
1318 uint64_t inx;
1319
1320 /* Probe first, because we need to know if our buffer is big enough.
1321 */
1322 MPI_Probe(source, tag, comm, &mpistatus);
1323 MPI_Get_count(&mpistatus, MPI_PACKED, &n);
1324
1325 /* make sure we are getting the tag we expect and from whom we expect if from */
1326 if (tag != MPI_ANY_TAG && mpistatus.MPI_TAG != tag) {
1327 status = eslFAIL;
1328 goto ERROR;
1329 }
1330 if (source != MPI_ANY_SOURCE && mpistatus.MPI_SOURCE != source) {
1331 status = eslFAIL;
1332 goto ERROR;
1333 }
1334
1335 /* set the source and tag */
1336 tag = mpistatus.MPI_TAG;
1337 source = mpistatus.MPI_SOURCE;
1338
1339 /* Make sure the buffer is allocated appropriately */
1340 if (*buf == NULL || n > *nalloc) {
1341 void *tmp;
1342 ESL_RALLOC(*buf, tmp, sizeof(char) * n);
1343 *nalloc = n;
1344 }
1345
1346 /* Receive the packed top hits */
1347 MPI_Recv(*buf, n, MPI_PACKED, source, tag, comm, &mpistatus);
1348
1349 /* Unpack it - watching out for the EOD signal of M = -1. */
1350 pos = 0;
1351 if ((th = cm_tophits_Create()) == NULL) { status = eslEMEM; goto ERROR; }
1352 if (MPI_Unpack(*buf, n, &pos, &nhits, 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1353 if (MPI_Unpack(*buf, n, &pos, &th->nreported, 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1354 if (MPI_Unpack(*buf, n, &pos, &th->nincluded, 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1355
1356 /* loop through all of the hits sent */
1357 for (inx = 0; inx < nhits; inx++) {
1358 if ((status = cm_tophits_CreateNextHit(th, &hit)) != eslOK) goto ERROR;
1359 if ((status = cm_hit_MPIRecv(source, tag, comm, buf, nalloc, hit)) != eslOK) goto ERROR;
1360 }
1361
1362 *ret_th = th;
1363 return eslOK;
1364
1365 ERROR:
1366 if (th != NULL) cm_tophits_Destroy(th);
1367 *ret_th = NULL;
1368 return status;
1369 }
1370
1371
1372 /* Function: cm_hit_MPISend()
1373 */
1374 int
1375 cm_hit_MPISend(CM_HIT *hit, int dest, int tag, MPI_Comm comm, char **buf, int *nalloc)
1376 {
1377 int status;
1378 int pos;
1379 int n = *nalloc;
1380
1381 /* Pack the HIT into the buffer */
1382 pos = 0;
1383 if ((status = cm_hit_MPIPack(hit, *buf, n, &pos, comm)) != eslOK) goto ERROR;
1384
1385 /* Send the packed HIT to the destination. */
1386 if (MPI_Send(*buf, n, MPI_PACKED, dest, tag, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi send failed");
1387
1388 return eslOK;
1389
1390 ERROR:
1391 return status;
1392 }
1393
1394 /* Function: cm_hit_MPIRecv()
1395 */
1396 int
1397 cm_hit_MPIRecv(int source, int tag, MPI_Comm comm, char **buf, int *nalloc, CM_HIT *hit)
1398 {
1399 int n;
1400 int status;
1401 int pos;
1402 MPI_Status mpistatus;
1403
1404 /* Probe first, because we need to know if our buffer is big enough.
1405 */
1406 MPI_Probe(source, tag, comm, &mpistatus);
1407 MPI_Get_count(&mpistatus, MPI_PACKED, &n);
1408
1409 /* make sure we are getting the tag we expect and from whom we expect if from */
1410 if (tag != MPI_ANY_TAG && mpistatus.MPI_TAG != tag) {
1411 status = eslFAIL;
1412 goto ERROR;
1413 }
1414 if (source != MPI_ANY_SOURCE && mpistatus.MPI_SOURCE != source) {
1415 status = eslFAIL;
1416 goto ERROR;
1417 }
1418
1419 /* set the source and tag */
1420 tag = mpistatus.MPI_TAG;
1421 source = mpistatus.MPI_SOURCE;
1422
1423 /* Make sure the buffer is allocated appropriately */
1424 if (*buf == NULL || n > *nalloc) {
1425 void *tmp;
1426 ESL_RALLOC(*buf, tmp, sizeof(char) * n);
1427 *nalloc = n;
1428 }
1429
1430 /* Receive the packed top hits */
1431 MPI_Recv(*buf, n, MPI_PACKED, source, tag, comm, &mpistatus);
1432
1433 /* Unpack it - watching out for the EOD signal of M = -1. */
1434 pos = 0;
1435 if ((status = cm_hit_MPIUnpack(*buf, n, &pos, comm, hit)) != eslOK) goto ERROR;
1436
1437 return eslOK;
1438
1439 ERROR:
1440 return status;
1441 }
1442
1443 /* Function: cm_hit_MPIPackSize()
1444 * Synopsis: Calculates size needed to pack a HIT.
1445 * Incept: MSF, Mon Sep 21 22:22:00 2009 [Janelia]
1446 *
1447 * Purpose: Calculate an upper bound on the number of bytes
1448 * that <cm_hit_MPIPack()> will need to pack an CM_HIT
1449 * <hit> in a packed MPI message for MPI communicator
1450 * <comm>; return that number of bytes in <*ret_n>.
1451 *
1452 * Returns: <eslOK> on success, and <*ret_n> contains the answer.
1453 *
1454 * Throws: <eslESYS> if an MPI call fails, and <*ret_n> is 0.
1455 */
1456 int
1457 cm_hit_MPIPackSize(CM_HIT *hit, MPI_Comm comm, int *ret_n)
1458 {
1459 int status;
1460 int n = 0;
1461 int sz;
1462
1463 CM_ALIDISPLAY *ad = hit->ad;
1464
1465 /* CM_HIT data */
1466 if (MPI_Pack_size(8, MPI_LONG, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* start, stop, seq_idx, cm_idx, hit_idx, srcL, any_oidx, win_oidx */
1467 if (MPI_Pack_size(8, MPI_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* in_rc, root, mode, clan_idx, pass_idx, hmmonly, glocal, has_evalue */
1468 if (MPI_Pack_size(2, MPI_FLOAT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* score, bias */
1469 if (MPI_Pack_size(4, MPI_DOUBLE, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* pvalue, evalue, any_bitE, win_bitE */
1470 if (MPI_Pack_size(1, MPI_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* flags */
1471
1472 if ((status = esl_mpi_PackOptSize(hit->name, -1, MPI_CHAR, comm, &sz)) != eslOK) goto ERROR;
1473 n += sz;
1474 if ((status = esl_mpi_PackOptSize(hit->acc, -1, MPI_CHAR, comm, &sz)) != eslOK) goto ERROR;
1475 n += sz;
1476 if ((status = esl_mpi_PackOptSize(hit->desc, -1, MPI_CHAR, comm, &sz)) != eslOK) goto ERROR;
1477 n += sz;
1478
1479 /* CM_ALIDISPLAY data */
1480 if (MPI_Pack_size(16, MPI_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* offset info */
1481 if (MPI_Pack_size(7, MPI_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* N, N_el, cfrom_emit, cto_emit, cfrom_span, cto_span, clen */
1482 if (MPI_Pack_size(2, MPI_LONG, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* sequence info */
1483 if (MPI_Pack_size(1, MPI_DOUBLE, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* tau */
1484 if (MPI_Pack_size(4, MPI_FLOAT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* sc, avgpp, gc, matrix_Mb */
1485 if (MPI_Pack_size(1, MPI_DOUBLE, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* elapsed_secs */
1486 if (MPI_Pack_size(1, MPI_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* hmmonly */
1487 if (MPI_Pack_size(1, MPI_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* memsize */
1488 if (MPI_Pack_size(ad->memsize, MPI_CHAR, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* mem */
1489
1490 *ret_n = n;
1491 return eslOK;
1492
1493 ERROR:
1494 *ret_n = 0;
1495 return status;
1496
1497 }
1498
1499 /* Function: cm_hit_MPIPack()
1500 * Synopsis: Packs the HIT into MPI buffer.
1501 * Incept: MSF, Mon Sep 21 22:22:00 2009 [Janelia]
1502 *
1503 * Purpose: Packs HIT <hit> into an MPI packed message buffer <buf>
1504 * of length <n> bytes, starting at byte position <*position>,
1505 * for MPI communicator <comm>.
1506 *
1507 * The caller must know that <buf>'s allocation of <n>
1508 * bytes is large enough to append the packed HIT at
1509 * position <*pos>. This typically requires a call to
1510 * <cm_hit_MPIPackSize()> first, and reallocation if
1511 * needed.
1512 *
1513 * Returns: <eslOK> on success; <buf> now contains the
1514 * packed <hit>, and <*position> is set to the byte
1515 * immediately following the last byte of the HIT
1516 * in <buf>.
1517 *
1518 * Throws: <eslESYS> if an MPI call fails; or <eslEMEM> if the
1519 * buffer's length <n> was overflowed in trying to pack
1520 * <msa> into <buf>. In either case, the state of
1521 * <buf> and <*position> is undefined, and both should
1522 * be considered to be corrupted.
1523 */
1524 int
1525 cm_hit_MPIPack(CM_HIT *hit, char *buf, int n, int *pos, MPI_Comm comm)
1526 {
1527 int status;
1528 int offset;
1529
1530 CM_ALIDISPLAY *ad = hit->ad;
1531
1532 if (MPI_Pack(&hit->start, 1, MPI_LONG, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1533 if (MPI_Pack(&hit->stop, 1, MPI_LONG, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1534 if (MPI_Pack(&hit->in_rc, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1535 if (MPI_Pack(&hit->root, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1536 if (MPI_Pack(&hit->mode, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1537 if (MPI_Pack(&hit->cm_idx, 1, MPI_LONG, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1538 if (MPI_Pack(&hit->clan_idx, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1539 if (MPI_Pack(&hit->seq_idx, 1, MPI_LONG, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1540 if (MPI_Pack(&hit->pass_idx, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1541 if (MPI_Pack(&hit->hit_idx, 1, MPI_LONG, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1542 if (MPI_Pack(&hit->score, 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1543 if (MPI_Pack(&hit->bias, 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1544 if (MPI_Pack(&hit->pvalue, 1, MPI_DOUBLE, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1545 if (MPI_Pack(&hit->evalue, 1, MPI_DOUBLE, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1546 if (MPI_Pack(&hit->has_evalue, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1547 if (MPI_Pack(&hit->flags, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1548 if (MPI_Pack(&hit->srcL, 1, MPI_LONG, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1549 if (MPI_Pack(&hit->hmmonly, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1550 if (MPI_Pack(&hit->glocal, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1551 if (MPI_Pack(&hit->any_oidx, 1, MPI_LONG, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1552 if (MPI_Pack(&hit->win_oidx, 1, MPI_LONG, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1553 if (MPI_Pack(&hit->any_bitE, 1, MPI_DOUBLE, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1554 if (MPI_Pack(&hit->win_bitE, 1, MPI_DOUBLE, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1555
1556 if ((status = esl_mpi_PackOpt(hit->name, -1, MPI_CHAR, buf, n, pos, comm)) != eslOK) return status;
1557 if ((status = esl_mpi_PackOpt(hit->acc, -1, MPI_CHAR, buf, n, pos, comm)) != eslOK) return status;
1558 if ((status = esl_mpi_PackOpt(hit->desc, -1, MPI_CHAR, buf, n, pos, comm)) != eslOK) return status;
1559
1560 offset = (ad->rfline == NULL) ? -1 : ad->rfline - ad->mem;
1561 if (MPI_Pack(&offset, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1562 offset = (ad->ncline == NULL) ? -1 : ad->ncline - ad->mem;
1563 if (MPI_Pack(&offset, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1564 offset = (ad->csline == NULL) ? -1 : ad->csline - ad->mem;
1565 if (MPI_Pack(&offset, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1566 offset = (ad->model == NULL) ? -1 : ad->model - ad->mem;
1567 if (MPI_Pack(&offset, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1568 offset = (ad->mline == NULL) ? -1 : ad->mline - ad->mem;
1569 if (MPI_Pack(&offset, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1570 offset = (ad->aseq == NULL) ? -1 : ad->aseq - ad->mem;
1571 if (MPI_Pack(&offset, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1572 offset = (ad->ppline == NULL) ? -1 : ad->ppline - ad->mem;
1573 if (MPI_Pack(&offset, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1574 offset = (ad->aseq_el == NULL) ? -1 : ad->aseq_el - ad->mem;
1575 if (MPI_Pack(&offset, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1576 offset = (ad->rfline_el == NULL) ? -1 : ad->rfline_el - ad->mem;
1577 if (MPI_Pack(&offset, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1578 offset = (ad->ppline_el == NULL) ? -1 : ad->ppline_el - ad->mem;
1579 if (MPI_Pack(&offset, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1580 if (MPI_Pack(&ad->N, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1581 if (MPI_Pack(&ad->N_el, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1582 offset = (ad->cmname == NULL) ? -1 : ad->cmname - ad->mem;
1583 if (MPI_Pack(&offset, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1584 offset = (ad->cmacc == NULL) ? -1 : ad->cmacc - ad->mem;
1585 if (MPI_Pack(&offset, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1586 offset = (ad->cmdesc == NULL) ? -1 : ad->cmdesc - ad->mem;
1587 if (MPI_Pack(&offset, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1588
1589 if (MPI_Pack(&ad->cfrom_emit, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1590 if (MPI_Pack(&ad->cto_emit, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1591 if (MPI_Pack(&ad->cfrom_span, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1592 if (MPI_Pack(&ad->cto_span, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1593 if (MPI_Pack(&ad->clen, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1594 offset = (ad->sqname == NULL) ? -1 : ad->sqname - ad->mem;
1595 if (MPI_Pack(&offset, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1596 offset = (ad->sqacc == NULL) ? -1 : ad->sqacc - ad->mem;
1597 if (MPI_Pack(&offset, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1598 offset = (ad->sqdesc == NULL) ? -1 : ad->sqdesc - ad->mem;
1599 if (MPI_Pack(&offset, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1600 if (MPI_Pack(&ad->sqfrom, 1, MPI_LONG, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1601 if (MPI_Pack(&ad->sqto, 1, MPI_LONG, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1602
1603 if (MPI_Pack(&ad->sc, 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1604 if (MPI_Pack(&ad->avgpp, 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1605 if (MPI_Pack(&ad->gc, 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1606 if (MPI_Pack(&ad->tau, 1, MPI_DOUBLE, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1607 if (MPI_Pack(&ad->matrix_Mb, 1, MPI_FLOAT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1608 if (MPI_Pack(&ad->elapsed_secs, 1, MPI_DOUBLE, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1609 if (MPI_Pack(&ad->hmmonly, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1610
1611 if (MPI_Pack(&ad->memsize, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1612 if (MPI_Pack( ad->mem, ad->memsize, MPI_CHAR, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1613
1614 if (*pos > n) ESL_EXCEPTION(eslEMEM, "buffer overflow");
1615 return eslOK;
1616
1617 ERROR:
1618 return status;
1619 }
1620
1621 /* Function: cm_hit_MPIUnpack()
1622 * Synopsis: Unpacks an HIT from an MPI buffer.
1623 * Incept: EPN, Thu Jun 2 14:29:20 2011
1624 * MSF, Mon Sep 21 22:22:00 2009 [Janelia] (p7_hit_MPIUnpack())
1625 *
1626 * Purpose: Unpack a newly allocated HIT from MPI packed buffer
1627 * <buf>, starting from position <*pos>, where the total length
1628 * of the buffer in bytes is <n>.
1629 *
1630 * Returns: <eslOK> on success. <*pos> is updated to the position of
1631 * the next element in <buf> to unpack (if any). <*ret_hit>
1632 * contains a newly allocated HIT, which the caller is
1633 * responsible for free'ing.
1634 *
1635 * Throws: <eslESYS> on an MPI call failure. <eslEMEM> on allocation failure.
1636 * In either case, <*ret_hit> is <NULL>, and the state of <buf>
1637 * and <*pos> is undefined and should be considered to be corrupted.
1638 */
1639 int
1640 cm_hit_MPIUnpack(char *buf, int n, int *pos, MPI_Comm comm, CM_HIT *hit)
1641 {
1642 int status;
1643 int rfline, ncline, csline, model, mline, aseq, ppline, aseq_el, rfline_el, ppline_el;
1644 int cmname, cmacc, cmdesc;
1645 int sqname, sqacc, sqdesc;
1646
1647 CM_ALIDISPLAY *ad;
1648 ESL_ALLOC(ad, sizeof(CM_ALIDISPLAY));
1649
1650 if (MPI_Unpack(buf, n, pos, &hit->start, 1, MPI_LONG, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1651 if (MPI_Unpack(buf, n, pos, &hit->stop, 1, MPI_LONG, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1652 if (MPI_Unpack(buf, n, pos, &hit->in_rc, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1653 if (MPI_Unpack(buf, n, pos, &hit->root, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1654 if (MPI_Unpack(buf, n, pos, &hit->mode, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1655 if (MPI_Unpack(buf, n, pos, &hit->cm_idx, 1, MPI_LONG, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1656 if (MPI_Unpack(buf, n, pos, &hit->clan_idx, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1657 if (MPI_Unpack(buf, n, pos, &hit->seq_idx, 1, MPI_LONG, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1658 if (MPI_Unpack(buf, n, pos, &hit->pass_idx, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1659 if (MPI_Unpack(buf, n, pos, &hit->hit_idx, 1, MPI_LONG, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1660 if (MPI_Unpack(buf, n, pos, &hit->score, 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1661 if (MPI_Unpack(buf, n, pos, &hit->bias, 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1662 if (MPI_Unpack(buf, n, pos, &hit->pvalue, 1, MPI_DOUBLE, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1663 if (MPI_Unpack(buf, n, pos, &hit->evalue, 1, MPI_DOUBLE, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1664 if (MPI_Unpack(buf, n, pos, &hit->has_evalue, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1665 if (MPI_Unpack(buf, n, pos, &hit->flags, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1666 if (MPI_Unpack(buf, n, pos, &hit->srcL, 1, MPI_LONG, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1667 if (MPI_Unpack(buf, n, pos, &hit->hmmonly, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1668 if (MPI_Unpack(buf, n, pos, &hit->glocal, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1669 if (MPI_Unpack(buf, n, pos, &hit->any_oidx, 1, MPI_LONG, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1670 if (MPI_Unpack(buf, n, pos, &hit->win_oidx, 1, MPI_LONG, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1671 if (MPI_Unpack(buf, n, pos, &hit->any_bitE, 1, MPI_DOUBLE, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1672 if (MPI_Unpack(buf, n, pos, &hit->win_bitE, 1, MPI_DOUBLE, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1673
1674 if ((status = esl_mpi_UnpackOpt(buf, n, pos, (void**)&(hit->name), NULL, MPI_CHAR, comm)) != eslOK) goto ERROR;
1675 if ((status = esl_mpi_UnpackOpt(buf, n, pos, (void**)&(hit->acc), NULL, MPI_CHAR, comm)) != eslOK) goto ERROR;
1676 if ((status = esl_mpi_UnpackOpt(buf, n, pos, (void**)&(hit->desc), NULL, MPI_CHAR, comm)) != eslOK) goto ERROR;
1677
1678 if (MPI_Unpack(buf, n, pos, &rfline, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1679 if (MPI_Unpack(buf, n, pos, &ncline, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1680 if (MPI_Unpack(buf, n, pos, &csline, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1681 if (MPI_Unpack(buf, n, pos, &model, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1682 if (MPI_Unpack(buf, n, pos, &mline, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1683 if (MPI_Unpack(buf, n, pos, &aseq, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1684 if (MPI_Unpack(buf, n, pos, &ppline, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1685 if (MPI_Unpack(buf, n, pos, &aseq_el, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1686 if (MPI_Unpack(buf, n, pos, &rfline_el, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1687 if (MPI_Unpack(buf, n, pos, &ppline_el, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1688 if (MPI_Unpack(buf, n, pos, &ad->N, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1689 if (MPI_Unpack(buf, n, pos, &ad->N_el, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1690 if (MPI_Unpack(buf, n, pos, &cmname, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1691 if (MPI_Unpack(buf, n, pos, &cmacc, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1692 if (MPI_Unpack(buf, n, pos, &cmdesc, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1693 if (MPI_Unpack(buf, n, pos, &ad->cfrom_emit, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1694 if (MPI_Unpack(buf, n, pos, &ad->cto_emit, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1695 if (MPI_Unpack(buf, n, pos, &ad->cfrom_span, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1696 if (MPI_Unpack(buf, n, pos, &ad->cto_span, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1697 if (MPI_Unpack(buf, n, pos, &ad->clen, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1698 if (MPI_Unpack(buf, n, pos, &sqname, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1699 if (MPI_Unpack(buf, n, pos, &sqacc, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1700 if (MPI_Unpack(buf, n, pos, &sqdesc, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1701 if (MPI_Unpack(buf, n, pos, &ad->sqfrom, 1, MPI_LONG, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1702 if (MPI_Unpack(buf, n, pos, &ad->sqto, 1, MPI_LONG, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1703
1704 if (MPI_Unpack(buf, n, pos, &ad->sc, 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1705 if (MPI_Unpack(buf, n, pos, &ad->avgpp, 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1706 if (MPI_Unpack(buf, n, pos, &ad->gc, 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1707 if (MPI_Unpack(buf, n, pos, &ad->tau, 1, MPI_DOUBLE, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1708 if (MPI_Unpack(buf, n, pos, &ad->matrix_Mb, 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1709 if (MPI_Unpack(buf, n, pos, &ad->elapsed_secs, 1, MPI_DOUBLE, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1710 if (MPI_Unpack(buf, n, pos, &ad->hmmonly, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1711
1712 if (MPI_Unpack(buf, n, pos, &ad->memsize, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1713
1714 /* allocate the string pools for the alignments */
1715 ESL_ALLOC(ad->mem, ad->memsize);
1716 if (MPI_Unpack(buf, n, pos, ad->mem, ad->memsize, MPI_CHAR, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
1717
1718 ad->rfline = (rfline == -1) ? NULL : ad->mem + rfline;
1719 ad->ncline = (ncline == -1) ? NULL : ad->mem + ncline;
1720 ad->csline = (csline == -1) ? NULL : ad->mem + csline;
1721 ad->model = (model == -1) ? NULL : ad->mem + model;
1722 ad->mline = (mline == -1) ? NULL : ad->mem + mline;
1723 ad->aseq = (aseq == -1) ? NULL : ad->mem + aseq;
1724 ad->ppline = (ppline == -1) ? NULL : ad->mem + ppline;
1725 ad->aseq_el = (aseq_el == -1) ? NULL : ad->mem + aseq_el;
1726 ad->rfline_el = (rfline_el == -1) ? NULL : ad->mem + rfline_el;
1727 ad->ppline_el = (ppline_el == -1) ? NULL : ad->mem + ppline_el;
1728
1729 ad->cmname = (cmname == -1) ? NULL : ad->mem + cmname;
1730 ad->cmacc = (cmacc == -1) ? NULL : ad->mem + cmacc;
1731 ad->cmdesc = (cmdesc == -1) ? NULL : ad->mem + cmdesc;
1732
1733 ad->sqname = (sqname == -1) ? NULL : ad->mem + sqname;
1734 ad->sqacc = (sqacc == -1) ? NULL : ad->mem + sqacc;
1735 ad->sqdesc = (sqdesc == -1) ? NULL : ad->mem + sqdesc;
1736
1737 hit->ad = ad;
1738
1739 return eslOK;
1740
1741 ERROR:
1742 return status;
1743 }
1744
1745 /* Function: cm_alndata_MPISend()
1746 * Synopsis: Send alignment data as an MPI message.
1747 * Incept: EPN, Fri Jan 13 09:19:54 2012
1748 *
1749 * Purpose: Sends alignment data <data> to MPI process <dest>
1750 * (where <dest> ranges from 0..<nproc-1>), with MPI tag
1751 * <tag> for MPI communicator <comm>.
1752 *
1753 * In order to minimize alloc/free cycles in this routine,
1754 * caller passes a pointer to a working buffer <*buf> of
1755 * size <*nalloc> characters. If necessary (i.e. if <data> is
1756 * too big to fit), <*buf> will be reallocated and <*nalloc>
1757 * increased to the new size. As a special case, if <*buf>
1758 * is <NULL> and <*nalloc> is 0, the buffer will be
1759 * allocated appropriately, but the caller is still
1760 * responsible for free'ing it.
1761 *
1762 * If <include_sq> is TRUE, we pack up and include
1763 * <data->sq>, else we don't.
1764 *
1765 * Returns: <eslOK> on success.
1766 * <eslEINCOMPAT> if data is NULL, errbuf is filled.
1767 *
1768 * Throws: <eslESYS> on a MPI error, errbuf not filled.
1769 */
1770 int
1771 cm_alndata_MPISend(CM_ALNDATA *data, int include_sq, char *errbuf, int dest, int tag, MPI_Comm comm, char **buf, int *nalloc)
1772 {
1773 int status;
1774 int sz, n, pos;
1775 int has_ppstr;
1776 int has_tr;
1777 int64_t pplen; /* length of ppstr */
1778
1779 if(data == NULL) ESL_FAIL(eslEINCOMPAT, errbuf, "cm_alndata_MPISend(), data is NULL");
1780 has_ppstr = (data->ppstr == NULL) ? FALSE : TRUE;
1781 has_tr = (data->tr == NULL) ? FALSE : TRUE;
1782 pplen = has_ppstr? data->sq->L+1 : 0;
1783
1784 /* This will look wasteful, but the MPI spec doesn't guarantee that
1785 * MPI_Pack_size(x, ...) + MPI_Pack_size(x, ... ) == MPI_Pack_size(2x, ...).
1786 * Indeed there are some hints in the spec that that's *not* true.
1787 * So we assume we must match our Pack_size calls exactly to our Pack calls.
1788 */
1789 n = 0;
1790 /* first tally up size of everything that's mandatory */
1791 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* idx */
1792 if (MPI_Pack_size(1, MPI_FLOAT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* sc */
1793 if (MPI_Pack_size(1, MPI_FLOAT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* pp */
1794 if (MPI_Pack_size(1, MPI_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* spos */
1795 if (MPI_Pack_size(1, MPI_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* epos */
1796 if (MPI_Pack_size(1, MPI_FLOAT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* secs_band */
1797 if (MPI_Pack_size(1, MPI_FLOAT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* secs_aln */
1798 if (MPI_Pack_size(1, MPI_FLOAT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* secs_tot */
1799 if (MPI_Pack_size(1, MPI_FLOAT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* mb_tot */
1800 if (MPI_Pack_size(1, MPI_DOUBLE, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* tau */
1801 if (MPI_Pack_size(1, MPI_FLOAT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* thresh1 */
1802 if (MPI_Pack_size(1, MPI_FLOAT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* thresh2 */
1803 /* now the optional info */
1804 if (MPI_Pack_size(1, MPI_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* include_sq */
1805 if (MPI_Pack_size(1, MPI_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* has_tr */
1806 if (MPI_Pack_size(1, MPI_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* has_ppstr */
1807 if (include_sq) {
1808 if ((status = esl_sq_MPIPackSize(data->sq, comm, &sz)) != eslOK) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* sq */
1809 }
1810 if (has_tr) {
1811 if ((status = cm_parsetree_MPIPackSize(data->tr, comm, &sz)) != eslOK) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* tr */
1812 }
1813 if (has_ppstr) {
1814 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* pplen */
1815 if (MPI_Pack_size(pplen, MPI_CHAR, comm, &sz) != 0) { ESL_XEXCEPTION(eslESYS, "pack size failed"); } n += sz; /* ppstr */
1816 }
1817
1818 /* Make sure the buffer is allocated appropriately */
1819 if (*buf == NULL || n > *nalloc) {
1820 void *tmp;
1821 ESL_RALLOC(*buf, tmp, sizeof(char) * n);
1822 *nalloc = n;
1823 }
1824
1825 /* Pack it, in same order as above */
1826 pos = 0;
1827 /* mandatory values */
1828 if (MPI_Pack(&data->idx, 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1829 if (MPI_Pack(&data->sc, 1, MPI_FLOAT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1830 if (MPI_Pack(&data->pp, 1, MPI_FLOAT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1831 if (MPI_Pack(&data->spos, 1, MPI_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1832 if (MPI_Pack(&data->epos, 1, MPI_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1833 if (MPI_Pack(&data->secs_bands, 1, MPI_FLOAT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1834 if (MPI_Pack(&data->secs_aln, 1, MPI_FLOAT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1835 if (MPI_Pack(&data->secs_tot, 1, MPI_FLOAT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1836 if (MPI_Pack(&data->mb_tot, 1, MPI_FLOAT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1837 if (MPI_Pack(&data->tau, 1, MPI_DOUBLE, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1838 if (MPI_Pack(&data->thresh1, 1, MPI_FLOAT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1839 if (MPI_Pack(&data->thresh2, 1, MPI_FLOAT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1840 /* optional info */
1841 if (MPI_Pack(&include_sq, 1, MPI_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1842 if (MPI_Pack(&has_tr, 1, MPI_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1843 if (MPI_Pack(&has_ppstr, 1, MPI_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1844 if (include_sq) {
1845 if ((status = esl_sq_MPIPack(data->sq, *buf, n, &pos, comm)) != eslOK) ESL_XEXCEPTION(eslESYS, "pack failed");
1846 }
1847 if (has_tr) {
1848 if ((status = cm_parsetree_MPIPack(data->tr, *buf, n, &pos, comm) != eslOK)) ESL_XEXCEPTION(eslESYS, "pack failed");
1849 }
1850 if (has_ppstr) {
1851 if (MPI_Pack(&pplen, 1, MPI_LONG_LONG_INT, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1852 if (MPI_Pack(data->ppstr, pplen, MPI_CHAR, *buf, n, &pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
1853 }
1854
1855 /* Send the packed data to destination */
1856 MPI_Send(*buf, n, MPI_PACKED, dest, tag, comm);
1857 return eslOK;
1858
1859 ERROR:
1860 return status;
1861 }
1862
1863
1864 /* Function: cm_alndata_MPIUnpack()
1865 * Synopsis: Unpacks a CM_ALNDATA from an MPI buffer.
1866 * Incept: EPN, Fri Jan 13 10:30:05 2012
1867 *
1868 * Purpose: Allocate for and fill a new CM_ALNDATA object
1869 * from MPI packed buffer <buf>, starting from
1870 * position <*pos>, where the total length of the
1871 * buffer in bytes is <n>. Return it in
1872 * <*ret_data>. Caller is responsible for free'ing
1873 * it.
1874 *
1875 * Returns: <eslOK> on success. <*pos> is updated to the position of
1876 * the next element in <buf> to unpack (if any). <*ret_alndata>
1877 * contains a newly allocated HIT, which the caller is
1878 * responsible for free'ing.
1879 *
1880 * Throws: <eslESYS> on an MPI call failure. <eslEMEM> on allocation failure.
1881 * In either case, <*ret_data> is <NULL>, and the state of <buf>
1882 * and <*pos> is undefined and should be considered to be corrupted.
1883 */
1884 int
1885 cm_alndata_MPIUnpack(char *buf, int n, int *pos, MPI_Comm comm, ESL_ALPHABET *abc, CM_ALNDATA **ret_data)
1886 {
1887 int status;
1888 CM_ALNDATA *data = NULL;
1889 int has_sq;
1890 int has_tr;
1891 int has_ppstr;
1892 int64_t pplen; /* length of ppstr */
1893
1894 if ((data = cm_alndata_Create()) == NULL) { status = eslEMEM; goto ERROR; }
1895
1896 /* mandatory stuff */
1897 if (MPI_Unpack(buf, n, pos, &(data->idx), 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1898 if (MPI_Unpack(buf, n, pos, &(data->sc), 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1899 if (MPI_Unpack(buf, n, pos, &(data->pp), 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1900 if (MPI_Unpack(buf, n, pos, &(data->spos), 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1901 if (MPI_Unpack(buf, n, pos, &(data->epos), 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1902 if (MPI_Unpack(buf, n, pos, &(data->secs_bands), 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1903 if (MPI_Unpack(buf, n, pos, &(data->secs_aln), 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1904 if (MPI_Unpack(buf, n, pos, &(data->secs_tot), 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1905 if (MPI_Unpack(buf, n, pos, &(data->mb_tot), 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1906 if (MPI_Unpack(buf, n, pos, &(data->tau), 1, MPI_DOUBLE, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1907 if (MPI_Unpack(buf, n, pos, &(data->thresh1), 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1908 if (MPI_Unpack(buf, n, pos, &(data->thresh2), 1, MPI_FLOAT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1909 /* optional stuff */
1910 if (MPI_Unpack(buf, n, pos, &has_sq, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1911 if (MPI_Unpack(buf, n, pos, &has_tr, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1912 if (MPI_Unpack(buf, n, pos, &has_ppstr, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1913 if (has_sq) {
1914 if ((status = esl_sq_MPIUnpack(abc, buf, n, pos, comm, &(data->sq))) != eslOK) ESL_XEXCEPTION(eslESYS, "unpack failed");
1915
1916 }
1917 if (has_tr) {
1918 if ((status = cm_parsetree_MPIUnpack(buf, n, pos, comm, &(data->tr))) != eslOK) ESL_XEXCEPTION(eslESYS, "unpack failed");
1919 }
1920 if (has_ppstr) {
1921 if (MPI_Unpack(buf, n, pos, &pplen, 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1922 ESL_ALLOC(data->ppstr, sizeof(char) * pplen);
1923 if (MPI_Unpack(buf, n, pos, data->ppstr, pplen, MPI_CHAR, comm) != 0) ESL_XEXCEPTION(eslESYS, "unpack failed");
1924 }
1925 *ret_data = data;
1926 return eslOK;
1927
1928 ERROR:
1929 if (data != NULL) cm_alndata_Destroy(data, TRUE);
1930 *ret_data = NULL;
1931 return status;
1932 }
1933
1934 #else // ! HAVE_MPI
1935
1936 /* If we don't have MPI compiled in, provide some nothingness to:
1937 * a. prevent Mac OS/X ranlib from bitching about .o file that "has no symbols"
1938 * b. prevent compiler from bitching about "empty compilation unit"
1939 * c. compile blank drivers and automatically pass the automated tests (when we add any)
1940 */
1941 void cm_mpisupport_silence_hack(void) { return; }
1942 #endif