-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem.c
140 lines (121 loc) · 3.84 KB
/
mem.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* Copyright 2019, José-Manuel Herruzo <[email protected]>,
* Jesús Alastruey-Benedé <[email protected]>,
* Pablo Ibáñez-Marín <[email protected]>
*
* This file is part of the bvSFM sequence alignment package.
*
* bvSFM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* bvSFM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with bvSFM. If not, see <http://www.gnu.org/licenses/>.
*
* If you publish any work that uses this software, please cite the following paper:
*
* J.M. Herruzo, S. González-Navarro, P. Ibáñez, V. Viñals, J. Alastruey-Benedé, and Óscar Plata.
* Accelerating Sequence Alignments Based on FM-Index Using the Intel KNL Processor.
* IEEE/ACM Transactions on Computational Biology and Bioinformatics (TCBB 2019).
* DOI: 10.1109/TCBB.2018.2884701
*
* @article{herruzo2019TCBB,
* author = {José Manuel Herruzo, Sonia González-Navarro, Pablo Ibáñez, Víctor Viñals, Jesús Alastruey-Benedé, and Óscar Plata},
* journal = {IEEE/ACM Transactions on Computational Biology and Bioinformatics (TCBB 2019)},
* title = {Accelerating Sequence Alignments Based on FM-Index Using the Intel KNL Processor},
* year = {2019},
* doi = {10.1109/TCBB.2018.2884701}
* }
*
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <sched.h> // For sched_setaffinity
#include <unistd.h>
#if LIBNUMA
#include <numa.h>
#include <numaif.h>
#include "mem.h"
static void
print_oneline_file(char *filename)
{
size_t len = 0;
FILE * fp;
char *linep = NULL;
fp = fopen(filename, "r");
if (fp == NULL)
{
printf(" NA");
return;
}
if (-1 == getline(&linep, &len, fp))
printf(" NA");
else
{
size_t linelen = strlen(linep);
while ( (linep[linelen-1] == '\n') || (linep[linelen-1] == '\r') )
{
linep[linelen-1] = 0;
linelen--;
}
printf("%6s", linep);
}
free(linep);
fclose(fp);
}
void
hugepages_status()
{
// Get numa configuration
int numa_nodes;
char string[512];
// check if system supports NUMA API
int available = numa_available();
if (available == -1)
{
numa_nodes = 0;
return;
}
else
numa_nodes = numa_num_configured_nodes();
printf("Free hugepages 2MB 1GB\n");
for (int j=0; j < numa_nodes; j++)
{
printf("node %u: ", j);
sprintf(string, "/sys/devices/system/node/node%u/hugepages/hugepages-2048kB/free_hugepages", j);
print_oneline_file(string);
sprintf(string, "/sys/devices/system/node/node%u/hugepages/hugepages-1048576kB/free_hugepages", j);
print_oneline_file(string);
printf("\n");
}
// printf("\n\n");
}
int
mem_conf()
{
// uint64_t nodes_mask = 0;
int ncores = sysconf(_SC_NPROCESSORS_ONLN);
int core = sched_getcpu();
int node = 0, max_node = 0;
int available = numa_available();
// check if system supports NUMA API
if (available == -1) return 0;
max_node = numa_max_node();
printf("System info: %d %s, %d cores (%d cores/node)\n",
max_node+1, max_node == 0? "node":"nodes", ncores, ncores/(max_node+1));
node = numa_node_of_cpu(core);
printf("Process info: running in node %d, core %d.\n", node, core);
return node;
}
#endif