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"
Go to the source code of this file.
contains various utility functions
Definition in file utils.c.
This function checks the endiannes of the system
Definition at line 45 of file utils.c.
References endian.
47 volatile uint32_t i = 0x01234567;
49 endian = (*((uint8_t *) (&i))) == 0x67;
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.
198 #if defined(__bg__) && defined(__bgq__)
199 s = Kernel_ProcessCount();
200 r = Kernel_MyTcoord();
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);
210 for (i = 0; i < size; i++)
211 if (!strcmp(pnametable[rank], pnametable[i])) {
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.
169 #if defined(__bg__) && defined(__bgq__)
172 Kernel_GetPersonality(&pers,
sizeof(pers));
173 msize = pers.DDR_Config.DDRSizeMB;
176 int msize = sysconf(_SC_AIX_REALMEM) / 1024;
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);
184 return msize / lsize;
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.
76 fprintf(stderr,
"Bad %s dimensions at %s, line %d\n", name, file,
82 "Number of processes must be a power of two at %s, line %d\n",
88 "Bad or missing Program parameters, at %s, line %d\n", file,
90 fprintf(stderr,
"Usage:\n");
91 fprintf(stderr,
"mpiexec -n NPROC ./timothy -p <ParameterFile>\n");
95 fprintf(stderr,
"Failed %s MPI message at %s, line %d.\n", name, file,
100 "Failed to allocate memory for %s array at %s, line %d\n",
104 fprintf(stderr,
"Too many exported particles. Adjust parameters.\n");
108 "Size of float does not divide the statistics table size.\n");
111 fprintf(stderr,
"Max. number of cells per process exceeded.\n");
114 fprintf(stderr,
"Too many exported cells on process %d. Abort.\n",
119 "Error while reading simulation parameters. MAXMOVE out of range.\n");
122 fprintf(stderr,
"Error in Zoltan library at %s, line %d.\n", file,
127 "Error while opening povray output file at %s, line %d.\n",
131 fprintf(stderr,
"Field parameter %s missing at %s, line %d.\n", name,
136 "Number of cells in the restart file is larger than MAXCELLS parameter at %s, line %d.\n",
140 fprintf(stderr,
"Bad value for parameter %s at %s, line %d.\n", name,
144 fprintf(stderr,
"Some devilish error at %s, line %d (lcf)\n", file,
148 fprintf(stderr,
"Error. tree_create_child_node()\n");
154 fprintf(stderr,
"Error at %s, line %d\n", file, line);
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.
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];