~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/nxtval.shm.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
/** @file
 
6
 * $Id: nxtval.shm.c,v 1.9 2005-02-21 21:51:40 manoj Exp $
 
7
 */
 
8
#if HAVE_STDIO_H
 
9
#   include <stdio.h>
 
10
#endif
 
11
 
 
12
#include "tcgmsgP.h"
 
13
 
 
14
long nxtval_counter=0;
 
15
long *nxtval_shmem = &nxtval_counter;
 
16
 
 
17
#define LEN 2
 
18
#define INCR 1   /* increment for NXTVAL */
 
19
#define BUSY -1L /* indicates somebody else updating counter*/
 
20
 
 
21
 
 
22
#if (defined(__i386__)  || defined(__x86_64__)) && defined(__GNUC__)
 
23
#   define TESTANDSET testandset
 
24
 
 
25
static inline int testandset(int *spinlock)
 
26
{
 
27
    int ret;
 
28
    __asm__ __volatile__("xchgl %0, %1"
 
29
            : "=r"(ret), "=m"(*spinlock)
 
30
            : "0"(1), "m"(*spinlock));
 
31
 
 
32
    return ret;
 
33
}
 
34
 
 
35
#elif defined(__APPLE__) && defined(__GNUC__)
 
36
#   define TESTANDSET(x) ( krspin_lock((long int *)(x)))
 
37
static int krspin_lock(long int *p)
 
38
{
 
39
    unsigned long tmp;
 
40
    int ret;
 
41
 
 
42
    __asm__ __volatile__(
 
43
    "b  1f        # spin_lock\n\
 
44
2:  lwzx    %0,0,%1\n\
 
45
    cmpwi   0,%0,0\n\
 
46
    bne+    2b\n\
 
47
1:  lwarx   %0,0,%1\n\
 
48
    cmpwi   0,%0,0\n\
 
49
    bne-    2b\n"
 
50
"   stwcx.  %2,0,%1\n\
 
51
    bne-    2b\n\
 
52
    isync"
 
53
    : "=&r"(tmp)
 
54
    : "r"(p), "r"(1)
 
55
    : "cr0", "memory");
 
56
    return ret == 0;
 
57
}
 
58
#endif
 
59
 
 
60
#ifdef TESTANDSET
 
61
#   define LOCK if(nproc>1)acquire_spinlock((int*)(nxtval_shmem+1))
 
62
#   define UNLOCK if(nproc>1)release_spinlock((int*)(nxtval_shmem+1))
 
63
 
 
64
static void acquire_spinlock(int *mutex)
 
65
{
 
66
    int loop=0, maxloop =10;
 
67
    while (TESTANDSET(mutex)){
 
68
        loop++;
 
69
        if(loop==maxloop){ usleep(1); loop=0; }
 
70
    }
 
71
}
 
72
 
 
73
static void release_spinlock(int *mutex)
 
74
{
 
75
    *mutex =0;
 
76
}
 
77
 
 
78
#endif /* TESTANDSET */
 
79
 
 
80
 
 
81
#ifndef LOCK
 
82
#   define LOCK  if(nproc>1)Error("nxtval: sequential version with silly mproc ", (long) *mproc);
 
83
#   define UNLOCK
 
84
#endif
 
85
 
 
86
 
 
87
/**
 
88
 * Get next value of shared counter.
 
89
 *
 
90
 * mproc > 0 ... returns requested value
 
91
 * mproc < 0 ... server blocks until abs(mproc) processes are queued
 
92
 *               and returns junk
 
93
 * mproc = 0 ... indicates to server that I am about to terminate
 
94
 */
 
95
long NXTVAL_(long *mproc)
 
96
{
 
97
    long shmem_swap();
 
98
    long local=0;
 
99
    long sync_type= INTERNAL_SYNC_TYPE;
 
100
    long nproc=  NNODES_(); 
 
101
    long server=nproc-1; 
 
102
 
 
103
    if (DEBUG_) {
 
104
        (void) printf("%2ld: nxtval: mproc=%ld\n",(long)NODEID_(),(long)*mproc);
 
105
        (void) fflush(stdout);
 
106
    }
 
107
 
 
108
    if (*mproc < 0) {
 
109
        SYNCH_(&sync_type);
 
110
        /* reset the counter value to zero */
 
111
        if( NODEID_() == server) *nxtval_shmem = 0;
 
112
        SYNCH_(&sync_type);
 
113
    }
 
114
    if (*mproc > 0) {
 
115
        LOCK;
 
116
        local = *nxtval_shmem;
 
117
        *nxtval_shmem += INCR;
 
118
        UNLOCK;
 
119
    }
 
120
 
 
121
    return local;
 
122
}