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

« back to all changes in this revision

Viewing changes to src/tools/ga-5-1/armci/src/memory/shmalloc.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: shmalloc.c,v 1.10 2002-06-20 23:34:17 vinod Exp $ */
 
6
#if HAVE_STDIO_H
 
7
#   include <stdio.h>
 
8
#endif
 
9
#if HAVE_STRING_H
 
10
#   include <string.h>
 
11
#endif
 
12
#include "armcip.h"
 
13
#include "message.h"
 
14
#include "kr_malloc.h"
 
15
 
 
16
static long *offset_arr;
 
17
 
 
18
void armci_shmalloc_exchange_offsets(context_t *ctx_local) 
 
19
{
 
20
    void **ptr_arr;
 
21
    void *ptr;
 
22
    armci_size_t bytes = 128;
 
23
    int i;    
 
24
    
 
25
    ptr_arr    = (void**)malloc(armci_nproc*sizeof(void*));
 
26
    offset_arr = (long*) malloc(armci_nproc*sizeof(long));
 
27
    if(!ptr_arr || !offset_arr) armci_die("armci_shmalloc_get_offsets: malloc failed", 0);
 
28
 
 
29
    /* get memory with same size on all procs */
 
30
    ptr = kr_malloc(bytes, ctx_local);
 
31
    if(!ptr) armci_die("armci_shmalloc_get_offsets: kr_malloc failed",bytes);
 
32
    
 
33
    bzero((char*)ptr_arr,armci_nproc*sizeof(void*));
 
34
    ptr_arr[armci_me] = ptr;
 
35
 
 
36
    /* now combine individual addresses into a single array */
 
37
    armci_exchange_address(ptr_arr, armci_nproc);
 
38
    
 
39
    /* identify offets */
 
40
    for (i=0; i<armci_nproc; i++) 
 
41
    {
 
42
       offset_arr[i] = (long) ((char*)ptr - (char*)ptr_arr[i]);
 
43
    }
 
44
       
 
45
    /* release memory */
 
46
    kr_free(ptr, ctx_local);
 
47
}
 
48
 
 
49
void armci_shmalloc_exchange_address(void **ptr_arr) 
 
50
{
 
51
    int i;
 
52
 
 
53
    /* now combine individual addresses into a single array */
 
54
    armci_exchange_address(ptr_arr, armci_nproc);
 
55
 
 
56
    /* since shmalloc may not give symmetric addresses (especially on Linux),
 
57
     * adjust addresses based on offset calculated during initialization */
 
58
    for (i=0; i<armci_nproc; i++) 
 
59
    {
 
60
       ptr_arr[i] = (char*)ptr_arr[i] + offset_arr[i];
 
61
    }
 
62
}
 
63
 
 
64
#ifdef MPI
 
65
 
 
66
extern int ARMCI_Absolute_id(ARMCI_Group *group,int group_rank);
 
67
 
 
68
/* group based exchange address */
 
69
void armci_shmalloc_exchange_address_grp(void **ptr_arr, ARMCI_Group *group) 
 
70
{
 
71
    int i, world_rank;
 
72
    int grp_nproc;
 
73
 
 
74
    ARMCI_Group_size(group, &grp_nproc);
 
75
    
 
76
    /* now combine individual addresses into a single array */
 
77
    armci_exchange_address_grp(ptr_arr, grp_nproc, group);
 
78
 
 
79
    /* since shmalloc may not give symmetric addresses (especially on Linux),
 
80
     * adjust addresses based on offset calculated during initialization */
 
81
    for (i=0; i<grp_nproc; i++) 
 
82
    {
 
83
       world_rank = ARMCI_Absolute_id(group,i);
 
84
       ptr_arr[i] = (char*)ptr_arr[i] + offset_arr[world_rank];
 
85
    }
 
86
}
 
87
#endif
 
88
 
 
89
/* get the remote process's pointer */
 
90
void* armci_shmalloc_remote_addr(void *ptr, int proc) 
 
91
{
 
92
    return (void*)((char*)ptr - offset_arr[proc]);
 
93
}
 
94
 
 
95
#if defined(CRAY_XT)
 
96
 
 
97
#define XT_SYMMETRIC_HEAP_SIZE ((size_t)1024)*1024*1024; /* 1 GB is default */
 
98
size_t get_xt_heapsize() 
 
99
{
 
100
    
 
101
    char *uval = getenv("XT_SYMMETRIC_HEAP_SIZE");
 
102
    char *token    = NULL;
 
103
    char *unit_str = NULL;
 
104
    size_t scale=1, size;
 
105
 
 
106
    if(uval != NULL) 
 
107
    {
 
108
       if((unit_str=strchr(uval, 'K')) != NULL) 
 
109
       {
 
110
          scale = 1024;
 
111
          token = strtok(uval, "K");
 
112
       }
 
113
       else if((unit_str=strchr(uval, 'M')) != NULL) 
 
114
       {
 
115
          scale = ((size_t)1024)*1024;
 
116
          token = strtok(uval, "M");
 
117
       }
 
118
       else if((unit_str=strchr(uval, 'G')) != NULL) 
 
119
       {
 
120
          scale = ((size_t)1024)*1024*1024;
 
121
          token = strtok(uval, "G");
 
122
       }
 
123
       else 
 
124
       {
 
125
          scale = 1;
 
126
          token = uval;
 
127
       }
 
128
       
 
129
       size = (size_t)atol(token);
 
130
       size *= scale; /* in bytes */
 
131
 
 
132
       if(size < 1024*1024)
 
133
          armci_die("get_xt_heapsize(): Symmetric heapsize should be > 1MB",0);
 
134
    }
 
135
    else 
 
136
    {
 
137
       size = XT_SYMMETRIC_HEAP_SIZE;
 
138
    }
 
139
    
 
140
    return size; 
 
141
}
 
142
#endif /* defined CRAY_XT */
 
143