~ubuntu-branches/ubuntu/trusty/nwchem/trusty-proposed

« back to all changes in this revision

Viewing changes to src/tools/ga-5-2/armci/tcgmsg/ipcv5.0/snd_rcv_probe.c

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Daniel Leidert, Andreas Tille, Michael Banck
  • Date: 2013-07-04 12:14:55 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130704121455-5tvsx2qabor3nrui
Tags: 6.3-1
* New upstream release.
* Fixes anisotropic properties (Closes: #696361).
* New features include:
  + Multi-reference coupled cluster (MRCC) approaches
  + Hybrid DFT calculations with short-range HF 
  + New density-functionals including Minnesota (M08, M11) and HSE hybrid
    functionals
  + X-ray absorption spectroscopy (XAS) with TDDFT
  + Analytical gradients for the COSMO solvation model
  + Transition densities from TDDFT 
  + DFT+U and Electron-Transfer (ET) methods for plane wave calculations
  + Exploitation of space group symmetry in plane wave geometry optimizations
  + Local density of states (LDOS) collective variable added to Metadynamics
  + Various new XC functionals added for plane wave calculations, including
    hybrid and range-corrected ones
  + Electric field gradients with relativistic corrections 
  + Nudged Elastic Band optimization method
  + Updated basis sets and ECPs 

[ Daniel Leidert ]
* debian/watch: Fixed.

[ Andreas Tille ]
* debian/upstream: References

[ Michael Banck ]
* debian/upstream (Name): New field.
* debian/patches/02_makefile_flags.patch: Refreshed.
* debian/patches/06_statfs_kfreebsd.patch: Likewise.
* debian/patches/07_ga_target_force_linux.patch: Likewise.
* debian/patches/05_avoid_inline_assembler.patch: Removed, no longer needed.
* debian/patches/09_backported_6.1.1_fixes.patch: Likewise.
* debian/control (Build-Depends): Added gfortran-4.7 and gcc-4.7.
* debian/patches/10_force_gcc-4.7.patch: New patch, explicitly sets
  gfortran-4.7 and gcc-4.7, fixes test suite hang with gcc-4.8 (Closes:
  #701328, #713262).
* debian/testsuite: Added tests for COSMO analytical gradients and MRCC.
* debian/rules (MRCC_METHODS): New variable, required to enable MRCC methods.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if HAVE_CONFIG_H
 
2
#   include "config.h"
 
3
#endif
 
4
 
 
5
#if HAVE_STDIO_H
 
6
#   include <stdio.h>
 
7
#endif
 
8
 
 
9
extern void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *));
 
10
 
 
11
#include "srftoc.h"
 
12
#include "sndrcv.h"
 
13
#include "tcgmsgP.h"
 
14
 
 
15
extern long MatchShmMessage();
 
16
extern void msg_wait();
 
17
extern long DEBUG_;
 
18
 
 
19
#define INVALID_NODE -3333      /* used to stamp completed msg in the queue */
 
20
#define MAX_Q_LEN MAX_PROC           /* Maximum no. of outstanding messages */
 
21
static  volatile long n_in_msg_q = 0;   /* actual no. in the message q */
 
22
static  struct msg_q_struct{
 
23
    long   msg_id;
 
24
    long   node;
 
25
    long   type;
 
26
} msg_q[MAX_Q_LEN];
 
27
 
 
28
 
 
29
/**
 
30
 * Return 1/0 (TRUE/FALSE) if a message of the given type is available
 
31
 * from the given node.  If the node is specified as -1, then all nodes
 
32
 * will be examined.  Some attempt is made at ensuring fairness.
 
33
 *
 
34
 * If node is specified as -1 then this value is overwritten with the
 
35
 * node that we got the message from.
 
36
 */
 
37
long ProbeNode(long *type, long *node)
 
38
{
 
39
    static long  next_node = 0;
 
40
 
 
41
    long  nproc = NNODES_();
 
42
    long  me = NODEID_();
 
43
    long  found = 0;
 
44
    long  cur_node;
 
45
    int   i, proclo, prochi;
 
46
 
 
47
    if (*node == me)
 
48
        Error("PROBE_ : cannot recv message from self, msgtype=", *type);
 
49
 
 
50
    if (*node == -1) {                /* match anyone */
 
51
 
 
52
        proclo = 0;
 
53
        prochi = nproc-1;
 
54
        cur_node = next_node;
 
55
 
 
56
    } else
 
57
        proclo = prochi = cur_node =  *node;
 
58
 
 
59
    for(i = proclo; i<= prochi; i++) {
 
60
 
 
61
        if (cur_node != me){                /* can't receive from self */
 
62
            found = MatchShmMessage(cur_node, *type); 
 
63
            if (found) break; 
 
64
        }
 
65
        cur_node = (cur_node +1)%nproc;
 
66
 
 
67
    }
 
68
 
 
69
    if(found) *node = cur_node;
 
70
 
 
71
    /* if wildcard node, determine which node we'll start with next time */
 
72
    if(*type == -1) next_node = (cur_node +1)%nproc;
 
73
    return(found);
 
74
}
 
75
 
 
76
 
 
77
/**
 
78
 * Return 1/0 (TRUE/FALSE) if a message of the given type is available
 
79
 * from the given node.  If the node is specified as -1, then all nodes
 
80
 * will be examined.  Some attempt is made at ensuring fairness.
 
81
 */
 
82
long PROBE_(long *type, long *node)
 
83
{
 
84
    long nnode = *node;
 
85
    long result;
 
86
 
 
87
    result = ProbeNode(type, &nnode);
 
88
 
 
89
    return(result);
 
90
}
 
91
 
 
92
 
 
93
/**
 
94
 * long *type        = user defined type of received message (input)
 
95
 * char *buf         = data buffer (output)
 
96
 * long *lenbuf      = length of buffer in bytes (input)
 
97
 * long *lenmes      = length of received message in bytes (output)
 
98
 *                     (exceeding receive buffer is hard error)
 
99
 * long *nodeselect  = node to receive from (input)
 
100
 *                     -1 implies that any pending message of the specified
 
101
 *                     type may be received
 
102
 * long *nodefrom    = node message is received from (output)
 
103
 * long *sync        = flag for sync(1) or async(0) receipt (input)
 
104
 */
 
105
void RCV_(long *type, void *buf, long *lenbuf, long *lenmes, long *nodeselect, long *nodefrom, long *sync)
 
106
{
 
107
    static long ttype;
 
108
    static long node;
 
109
    long   me = NODEID_();
 
110
    void msg_rcv();
 
111
 
 
112
    node = *nodeselect;
 
113
 
 
114
    ttype = *type;
 
115
 
 
116
    if (DEBUG_) {
 
117
        printf("RCV_: node %ld receiving from %ld, len=%ld, type=%ld, sync=%ld\n",
 
118
                (long)me, (long)*nodeselect, (long)*lenbuf, (long)*type, (long)*sync);
 
119
        fflush(stdout);
 
120
    }
 
121
 
 
122
    /* wait for a matching message */
 
123
    if(node==-1)   while(ProbeNode(type, &node) == 0);
 
124
    msg_rcv(ttype, buf, *lenbuf, lenmes, node); 
 
125
    *nodefrom = node;  
 
126
 
 
127
    if (DEBUG_) {
 
128
        (void) printf("RCV: me=%ld, from=%ld, len=%ld\n",
 
129
                      (long)me, (long)*nodeselect, (long)*lenbuf);
 
130
        (void) fflush(stdout);
 
131
    }
 
132
}
 
133
 
 
134
 
 
135
/**
 
136
 * long *type     = user defined integer message type (input)
 
137
 * char *buf      = data buffer (input)
 
138
 * long *lenbuf   = length of buffer in bytes (input)
 
139
 * long *node     = node to send to (input)
 
140
 * long *sync     = flag for sync(1) or async(0) communication (input)
 
141
 */
 
142
void SND_(long *type, void *buf, long *lenbuf, long *node, long *sync)
 
143
{
 
144
    long me = NODEID_();
 
145
    long msg_async_snd();
 
146
 
 
147
    /*asynchronous communication not supported under LAPI */
 
148
#ifdef LAPI
 
149
    long block = 1;
 
150
#else
 
151
    long block = *sync;
 
152
#endif
 
153
 
 
154
    if (DEBUG_) {
 
155
        (void)printf("SND_: node %ld sending to %ld, len=%ld, type=%ld, sync=%ld\n",
 
156
                     (long)me, (long)*node, (long)*lenbuf, (long)*type, (long)*sync);
 
157
        (void) fflush(stdout);
 
158
    }
 
159
 
 
160
    if (block)
 
161
        msg_wait(msg_async_snd(*type, buf, *lenbuf, *node));
 
162
 
 
163
    else {
 
164
 
 
165
        if (n_in_msg_q >= MAX_Q_LEN)
 
166
            Error("SND: overflowing async Q limit", n_in_msg_q);
 
167
 
 
168
        msg_q[n_in_msg_q].msg_id = msg_async_snd(*type, buf, *lenbuf, *node);
 
169
        msg_q[n_in_msg_q].node   = *node;
 
170
        msg_q[n_in_msg_q].type   = *type;
 
171
        n_in_msg_q++;
 
172
    }
 
173
 
 
174
    if (DEBUG_) {
 
175
        (void) printf("SND: me=%ld, to=%ld, len=%ld \n",
 
176
                      (long)me, (long)*node, (long)*lenbuf);
 
177
        (void) fflush(stdout);
 
178
    }
 
179
}
 
180
 
 
181
 
 
182
int compare_msg_q_entries(const void* entry1, const void* entry2)
 
183
{
 
184
    /* nodes are nondistiguishable unless one of them is INVALID_NODE */
 
185
    if( ((struct msg_q_struct*)entry1)->node ==
 
186
            ((struct msg_q_struct*)entry2)->node)                 return 0;
 
187
    if( ((struct msg_q_struct*)entry1)->node == INVALID_NODE) return 1;
 
188
    if( ((struct msg_q_struct*)entry2)->node == INVALID_NODE) return -1;
 
189
    return 0;
 
190
}
 
191
 
 
192
 
 
193
/**
 
194
 * Wait for all messages (send/receive) to complete between
 
195
 * this node and node *nodesel or everyone if *nodesel == -1.
 
196
 */
 
197
void WAITCOM_(long *nodesel)
 
198
{
 
199
    long i, found = 0;
 
200
 
 
201
    for (i=0; i<n_in_msg_q; i++) if(*nodesel==msg_q[i].node || *nodesel ==-1){
 
202
 
 
203
        if (DEBUG_) {
 
204
            (void) printf("WAITCOM: %ld waiting for msgid %ld, #%ld\n",
 
205
                          (long)NODEID_(), (long)msg_q[i].msg_id, (long)i);
 
206
            (void) fflush(stdout);
 
207
        }
 
208
 
 
209
        msg_wait(msg_q[i].msg_id);
 
210
 
 
211
        msg_q[i].node = INVALID_NODE;
 
212
        found = 1;
 
213
 
 
214
    }else if(msg_q[i].node == INVALID_NODE)Error("WAITCOM: invalid node entry",i);
 
215
 
 
216
    /* tidy up msg_q if there were any messages completed  */
 
217
    if(found){
 
218
 
 
219
        /* sort msg queue only to move the completed msg entries to the end*/
 
220
        /* comparison tests against the INVALID_NODE key */
 
221
        qsort(msg_q, n_in_msg_q, sizeof(struct msg_q_struct),compare_msg_q_entries);
 
222
 
 
223
        /* update msg queue length, = the number of outstanding msg entries left*/
 
224
        for(i = 0; i< n_in_msg_q; i++)if(msg_q[i].node == INVALID_NODE) break;
 
225
        if(i == n_in_msg_q) Error("WAITCOM: inconsitency in msg_q update", i);
 
226
        n_in_msg_q = i;
 
227
 
 
228
    }
 
229
}