source: CIVL/examples/contracts/contractsMPI/madre_computeDirectMoves.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*
2 * Determines how many blocks to send to each proc in the
3 * current phase.
4 *
5 * Preconditions:
6 * outgoing, incoming, totalOutgoing, and totalIncoming are all correct
7 * blocks are sorted.
8 *
9 * Postconditions:
10 * recvCount[] is updated with the number of direct blocks to
11 * receive from each proc in this phase, based on some heuristic;
12 * sendCount[] is updated to contain the number of direct blocks to
13 * send to each proc in this phase;
14 * totalSendCount = sum of sendCounts[];
15 * totalRecvCount = sum of recvCounts[];
16 *
17 * Current heuristic: greedy */
18static void computeDirectMoves(MADRE_Object madre) {
19 PH bred = (PH)madre->bred;
20 int *sortVector = MADRE_BMAN_getSortVector(bred->bman);
21 int totalRemaining = bred->numDead; /* remaining free space */
22 int i;
23 int requestCount = 0;
24
25 if (totalRemaining == 0 && bred->totalIncoming > 0 && bred->holdIndex < 0) {
26 /* use the holdBlock to avoid deadlock...*/
27 totalRemaining = 1;
28 }
29
30 /* post receives for quantities from my targets */
31 for (i = 0; i < madre->numProcs; i++) {
32 if (bred->outgoing[i] > 0) {
33 MPI_Irecv(bred->sendCounts + i, 1, MPI_INT, i, bred->tag, madre->comm,
34 bred->requests + requestCount);
35 requestCount++;
36 }
37 }
38 /* post send quantities to my sources */
39 bred->totalRecvCount = 0;
40 for (i = 0; i < madre->numProcs; i++) {
41 int requested = bred->incoming[i];
42
43 if (requested > 0) {
44 int granted = (requested < totalRemaining ? requested : totalRemaining);
45
46 totalRemaining -= granted;
47 bred->recvCounts[i] = granted;
48 MPI_Isend(bred->recvCounts + i, 1, MPI_INT, i, bred->tag, madre->comm,
49 bred->requests + requestCount);
50 requestCount++;
51 bred->totalRecvCount += granted;
52 }
53 }
54 /* wait for all requests to complete and update totalSendCount */
55 MPI_Waitall(requestCount, bred->requests, MPI_STATUSES_IGNORE);
56 bred->totalSendCount = 0;
57 for (i = 0; i < madre->numProcs; i++) {
58 bred->totalSendCount += bred->sendCounts[i];
59 }
60}
Note: See TracBrowser for help on using the repository browser.