~ubuntu-branches/ubuntu/saucy/nwchem/saucy

« 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, Michael Banck, Daniel Leidert
  • Date: 2012-02-09 20:02:41 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120209200241-jgk03qfsphal4ug2
Tags: 6.1-1
* New upstream release.

[ Michael Banck ]
* debian/patches/02_makefile_flags.patch: Updated.
* debian/patches/02_makefile_flags.patch: Use internal blas and lapack code.
* debian/patches/02_makefile_flags.patch: Define GCC4 for LINUX and LINUX64
  (Closes: #632611 and LP: #791308).
* debian/control (Build-Depends): Added openssh-client.
* debian/rules (USE_SCALAPACK, SCALAPACK): Removed variables (Closes:
  #654658).
* debian/rules (LIBDIR, USE_MPIF4, ARMCI_NETWORK): New variables.
* debian/TODO: New file.
* debian/control (Build-Depends): Removed libblas-dev, liblapack-dev and
  libscalapack-mpi-dev.
* debian/patches/04_show_testsuite_diff_output.patch: New patch, shows the
  diff output for failed tests.
* debian/patches/series: Adjusted.
* debian/testsuite: Optionally run all tests if "all" is passed as option.
* debian/rules: Run debian/testsuite with "all" if DEB_BUILD_OPTIONS
  contains "checkall".

[ Daniel Leidert ]
* debian/control: Used wrap-and-sort. Added Vcs-Svn and Vcs-Browser fields.
  (Priority): Moved to extra according to policy section 2.5.
  (Standards-Version): Bumped to 3.9.2.
  (Description): Fixed a typo.
* debian/watch: Added.
* debian/patches/03_hurd-i386_define_path_max.patch: Added.
  - Define MAX_PATH if not defines to fix FTBFS on hurd.
* debian/patches/series: Adjusted.

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