Timothy  0.9
Tissue Modelling Framework
 All Data Structures Files Functions Variables Typedefs Macros
utils.c File Reference

contains various utility functions More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <mpi.h>
#include <unistd.h>
#include "global.h"
Include dependency graph for utils.c:

Go to the source code of this file.

Functions

int checkEndiannes ()
 
void swap_Nbyte (char *data, int n, int m)
 
void stopRun (int ierr, char *name, char *file, int line)
 
size_t getMemoryPerProcess (int32_t lsize)
 
void getLocalRankAndSize (int rank, int size, int32_t *lrank, int32_t *lsize)
 

Detailed Description

contains various utility functions

Definition in file utils.c.

Function Documentation

int checkEndiannes ( )

This function checks the endiannes of the system

Definition at line 45 of file utils.c.

References endian.

46 {
47  volatile uint32_t i = 0x01234567;
48  /* return 0 for big endian, 1 for little endian. */
49  endian = (*((uint8_t *) (&i))) == 0x67;
50  return 0;
51 }
int endian
Definition: global.h:157

Here is the caller graph for this function:

void getLocalRankAndSize ( int  rank,
int  size,
int32_t *  lrank,
int32_t *  lsize 
)

This function detects number of processes on each node and assignes local node ranks for each process. Assumptions: number of processes per node is equal accross nodes. This functions is system dependent. Supported platforms: linux, AIX, Blue Gene/Q.

Definition at line 193 of file utils.c.

References s.

195 {
196  int i;
197  int32_t r, s;
198 #if defined(__bg__) && defined(__bgq__)
199  s = Kernel_ProcessCount();
200  r = Kernel_MyTcoord();
201 #else
202  int pnamelen;
203  char pname[MPI_MAX_PROCESSOR_NAME];
204  char pnametable[size][MPI_MAX_PROCESSOR_NAME];
205  MPI_Get_processor_name(pname, &pnamelen);
206  MPI_Allgather(pname, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, pnametable,
207  MPI_MAX_PROCESSOR_NAME, MPI_CHAR, MPI_COMM_WORLD);
208  r = 0;
209  s = 0;
210  for (i = 0; i < size; i++)
211  if (!strcmp(pnametable[rank], pnametable[i])) {
212  if (i < rank)
213  r++;
214  s++;
215  }
216 #endif
217  *lrank = r;
218  *lsize = s;
219 }
float s
Definition: global.h:186

Here is the caller graph for this function:

size_t getMemoryPerProcess ( int32_t  lsize)

This function detects the amount of addressable memory available for each process. Assumptions: each process allocates similar amount of data. This functions is system dependent. Supported platforms: linux, AIX, Blue Gene/Q.

Definition at line 167 of file utils.c.

168 {
169 #if defined(__bg__) && defined(__bgq__)
170  Personality_t pers;
171  int32_t msize;
172  Kernel_GetPersonality(&pers, sizeof(pers));
173  msize = pers.DDR_Config.DDRSizeMB;
174 #else
175 #if defined(_AIX)
176  int msize = sysconf(_SC_AIX_REALMEM) / 1024;
177 #endif /* aix */
178 #if defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
179  long psize = sysconf(_SC_PAGE_SIZE);
180  long npages = sysconf(_SC_PHYS_PAGES);
181  long msize = psize * npages / (1024 * 1024);
182 #endif /*linux */
183 #endif /* bgq */
184  return msize / lsize;
185 }

Here is the caller graph for this function:

void stopRun ( int  ierr,
char *  name,
char *  file,
int  line 
)

This function is used to handle various critical errors.

Definition at line 72 of file utils.c.

References MPIrank.

73 {
74  switch (ierr) {
75  case 100:
76  fprintf(stderr, "Bad %s dimensions at %s, line %d\n", name, file,
77  line);
78  break;
79  case 101:
80  if (MPIrank == 0)
81  fprintf(stderr,
82  "Number of processes must be a power of two at %s, line %d\n",
83  file, line);
84  break;
85  case 102:
86  if (MPIrank == 0) {
87  fprintf(stderr,
88  "Bad or missing Program parameters, at %s, line %d\n", file,
89  line);
90  fprintf(stderr, "Usage:\n");
91  fprintf(stderr, "mpiexec -n NPROC ./timothy -p <ParameterFile>\n");
92  }
93  break;
94  case 103:
95  fprintf(stderr, "Failed %s MPI message at %s, line %d.\n", name, file,
96  line);
97  break;
98  case 106:
99  fprintf(stderr,
100  "Failed to allocate memory for %s array at %s, line %d\n",
101  name, file, line);
102  break;
103  case 107:
104  fprintf(stderr, "Too many exported particles. Adjust parameters.\n");
105  break;
106  case 108:
107  fprintf(stderr,
108  "Size of float does not divide the statistics table size.\n");
109  break;
110  case 109:
111  fprintf(stderr, "Max. number of cells per process exceeded.\n");
112  break;
113  case 110:
114  fprintf(stderr, "Too many exported cells on process %d. Abort.\n",
115  MPIrank);
116  break;
117  case 111:
118  fprintf(stderr,
119  "Error while reading simulation parameters. MAXMOVE out of range.\n");
120  break;
121  case 112:
122  fprintf(stderr, "Error in Zoltan library at %s, line %d.\n", file,
123  line);
124  break;
125  case 113:
126  fprintf(stderr,
127  "Error while opening povray output file at %s, line %d.\n",
128  file, line);
129  break;
130  case 114:
131  fprintf(stderr, "Field parameter %s missing at %s, line %d.\n", name,
132  file, line);
133  break;
134  case 115:
135  fprintf(stderr,
136  "Number of cells in the restart file is larger than MAXCELLS parameter at %s, line %d.\n",
137  file, line);
138  break;
139  case 116:
140  fprintf(stderr, "Bad value for parameter %s at %s, line %d.\n", name,
141  file, line);
142  break;
143  case 666:
144  fprintf(stderr, "Some devilish error at %s, line %d (lcf)\n", file,
145  line);
146  break;
147  case 898:
148  fprintf(stderr, "Error. tree_create_child_node()\n");
149  break;
150  case 999:
151  break;
152  default:
153  if (MPIrank == 0)
154  fprintf(stderr, "Error at %s, line %d\n", file, line);
155  break;
156  }
157  fflush(stderr);
158  MPI_Finalize();
159  exit(1);
160 }
int MPIrank
Definition: global.h:134

Here is the caller graph for this function:

void swap_Nbyte ( char *  data,
int  n,
int  m 
)

This function swaps endiannes within a table of n elements of a given size m (given in bytes).

Definition at line 57 of file utils.c.

References m.

58 {
59  int i, j;
60  char old_data[16];
61 
62  for (j = 0; j < n; j++) {
63  memcpy(&old_data[0], &data[j * m], m);
64  for (i = 0; i < m; i++)
65  data[j * m + i] = old_data[m - i - 1];
66  }
67 }
float m
Definition: global.h:188

Here is the caller graph for this function: