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

« back to all changes in this revision

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