~ubuntu-branches/ubuntu/utopic/nwchem/utopic

« back to all changes in this revision

Viewing changes to src/tools/ga-5-1/armci/src/util/threads.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
 
/* $Id: threads.c,v 1.1.2.5 2007-08-28 21:29:46 manoj Exp $ */
6
 
 
7
 
#if 0
8
 
#   define PRNDBG3(m,a1,a2,a3) \
9
 
           fprintf(stderr,"DBG %d: " m,armci_me,a1,a2,a3);fflush(stderr)
10
 
#   define PRNDBG(m) PRNDBG3(m,0,0,0)
11
 
#   define PRNDBG1(m,a1) PRNDBG3(m,a1,0,0)
12
 
#   define PRNDBG2(m,a1,a2) PRNDBG3(m,a1,a2,0)
13
 
#else
14
 
#   define PRNDBG(m)
15
 
#   define PRNDBG1(m,a1)
16
 
#   define PRNDBG2(m,a1,a2)
17
 
#   define PRNDBG3(m,a1,a2,a3)
18
 
#endif
19
 
 
20
 
 
21
 
#if HAVE_STDIO_H
22
 
#   include <stdio.h>
23
 
#endif
24
 
#include "armcip.h"
25
 
 
26
 
armci_user_threads_t armci_user_threads;
27
 
 
28
 
void armci_init_threads()
29
 
{
30
 
    int i, bytes;
31
 
    char *uval = getenv("ARMCI_MAX_THREADS");
32
 
    
33
 
    armci_user_threads.max   = 1;
34
 
    armci_user_threads.avail = 0;
35
 
 
36
 
    if (uval != NULL) sscanf(uval, "%d", &armci_user_threads.max);
37
 
    
38
 
    if (armci_user_threads.max < 1 ||
39
 
        armci_user_threads.max > ARMCI_THREADS_LIMIT)
40
 
    {
41
 
       printf("Error: Only 1-%d threads are supported. ",ARMCI_THREADS_LIMIT);
42
 
       printf("Set ARMCI_MAX_THREADS appropriately\n"); fflush(stdout);
43
 
       armci_die("armci_init_threads: failed", 0);
44
 
    }
45
 
 
46
 
    bytes = sizeof(thread_id_t) * armci_user_threads.max;
47
 
    if ( !(armci_user_threads.ids = (thread_id_t*) malloc(bytes)) )
48
 
    {
49
 
       armci_die("armci_init_threads: armci_user_threads.ids malloc failed",
50
 
                 armci_user_threads.max);
51
 
    }
52
 
    memset(armci_user_threads.ids, 0, bytes);
53
 
 
54
 
#if 0 /* spinlock has void return value */
55
 
    if (THREAD_LOCK_INIT(armci_user_threads.lock)     ||
56
 
        THREAD_LOCK_INIT(armci_user_threads.buf_lock) ||
57
 
        THREAD_LOCK_INIT(armci_user_threads.net_lock))
58
 
        armci_die("armci_init_threads:locks initialization failed", 0);
59
 
#else
60
 
    THREAD_LOCK_INIT(armci_user_threads.lock);
61
 
    THREAD_LOCK_INIT(armci_user_threads.buf_lock);
62
 
    THREAD_LOCK_INIT(armci_user_threads.net_lock);
63
 
#endif
64
 
    
65
 
#if 0
66
 
    /* using one lock per socket for now, it might be feasible (and usefull)
67
 
     * to use two (one for sending and one for receiving) */
68
 
    armci_user_threads.sock_locks = malloc(armci_nclus *sizeof(thread_lock_t));
69
 
    for (i = 0; i < armci_nclus; i++)
70
 
       if (THREAD_LOCK_INIT(armci_user_threads.sock_locks[i]))
71
 
          armci_die("armci_init_threads:sock locks initialization failed", i);
72
 
#endif
73
 
}
74
 
 
75
 
void armci_finalize_threads()
76
 
{
77
 
    THREAD_LOCK_DESTROY(armci_user_threads.lock);
78
 
    THREAD_LOCK_DESTROY(armci_user_threads.net_lock);
79
 
    THREAD_LOCK_DESTROY(armci_user_threads.buf_lock);
80
 
    free(armci_user_threads.ids);
81
 
}
82
 
 
83
 
/* calling armci_thread_idx for every function that accesses thread-private data
84
 
 * might be expensive -- needs optiomization */
85
 
INLINE int armci_thread_idx()
86
 
{
87
 
    int i, n = ARMCI_MIN(armci_user_threads.avail, armci_user_threads.max);
88
 
    thread_id_t id = THREAD_ID_SELF();
89
 
 
90
 
    for (i = 0; i < n; i++) if (id == armci_user_threads.ids[i]) {
91
 
        /*PRNDBG2("thread id=%ld already registered, idx=%d\n", id, i);*/
92
 
        return i;
93
 
    }
94
 
 
95
 
    /* see this thread for the first time */
96
 
    return armci_register_thread(id);
97
 
}
98
 
 
99
 
INLINE int armci_register_thread(thread_id_t id)
100
 
{
101
 
    int i;
102
 
 
103
 
    THREAD_LOCK(armci_user_threads.lock);
104
 
 
105
 
    i = armci_user_threads.avail;
106
 
    armci_user_threads.avail++;
107
 
 
108
 
    THREAD_UNLOCK(armci_user_threads.lock);
109
 
 
110
 
    if (i < armci_user_threads.max)
111
 
        armci_user_threads.ids[i] = id;
112
 
    else
113
 
        armci_die("armci_thread_idx: too many threads, adjust ARMCI_MAX_THREADS",
114
 
                  armci_user_threads.avail);
115
 
 
116
 
    PRNDBG2("registered a new thread: idx=%d, id=%ld\n", i, id);
117
 
    return i;
118
 
}
119