- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Triangle 软件(二维质量网格生成器和 Delaunay 三角器)( https://www.cs.cmu.edu/~quake/triangle.html ) 进行网格生成。它是开源的。
当我尝试使用包含 639,896,119 个节点、大小为 24 GB 的 .node 文件创建网格时,出现段错误。我不确定是内存的问题,我的机器是32 GB内存,所以我在504 GB内存的 super 计算机上运行它。它还给出了段错误。
.node文件是具有格式的文本文件
1 x1 y1 z1
2 x2 y2 z2
...
gdb 调试在函数 readnodes() 内的第 #14029 行给出了段错误。我用 printft() 来查看它何时崩溃,它最多可以读取 103,025,230 行。 readnoedes()是读取.node文件的每一行。
我在此处附加了 readnodes() 函数。发生分段的行已标记://帮助,gdb 在读取了很多行后在这里给出了段错误。
非常感谢任何帮助!
/*****************************************************************************/
/* */
/* readnodes() Read the vertices from a file, which may be a .node or */
/* .poly file. */
/* */
/*****************************************************************************/
#ifndef TRILIBRARY
#ifdef ANSI_DECLARATORS
void readnodes(struct mesh *m, struct behavior *b, char *nodefilename,
char *polyfilename, FILE **polyfile)
#else /* not ANSI_DECLARATORS */
void readnodes(m, b, nodefilename, polyfilename, polyfile)
struct mesh *m;
struct behavior *b;
char *nodefilename;
char *polyfilename;
FILE **polyfile;
#endif /* not ANSI_DECLARATORS */
{
FILE *infile;
vertex vertexloop;
char inputline[INPUTLINESIZE];
char *stringptr;
char *infilename;
REAL x, y;
int firstnode;
int nodemarkers;
int currentmarker;
int i, j;
if (b->poly) {
/* Read the vertices from a .poly file. */
if (!b->quiet) {
printf("Opening %s.\n", polyfilename);
}
*polyfile = fopen(polyfilename, "r");
if (*polyfile == (FILE *) NULL) {
printf(" Error: Cannot access file %s.\n", polyfilename);
triexit(1);
}
/* Read number of vertices, number of dimensions, number of vertex */
/* attributes, and number of boundary markers. */
stringptr = readline(inputline, *polyfile, polyfilename);
m->invertices = (int) strtol(stringptr, &stringptr, 0);
stringptr = findfield(stringptr);
if (*stringptr == '\0') {
m->mesh_dim = 2;
} else {
m->mesh_dim = (int) strtol(stringptr, &stringptr, 0);
}
stringptr = findfield(stringptr);
if (*stringptr == '\0') {
m->nextras = 0;
} else {
m->nextras = (int) strtol(stringptr, &stringptr, 0);
}
stringptr = findfield(stringptr);
if (*stringptr == '\0') {
nodemarkers = 0;
} else {
nodemarkers = (int) strtol(stringptr, &stringptr, 0);
}
if (m->invertices > 0) {
infile = *polyfile;
infilename = polyfilename;
m->readnodefile = 0;
} else {
/* If the .poly file claims there are zero vertices, that means that */
/* the vertices should be read from a separate .node file. */
m->readnodefile = 1;
infilename = nodefilename;
}
} else {
m->readnodefile = 1;
infilename = nodefilename;
*polyfile = (FILE *) NULL;
}
if (m->readnodefile) {
/* Read the vertices from a .node file. */
if (!b->quiet) {
printf("Opening %s.\n", nodefilename);
}
infile = fopen(nodefilename, "r");
if (infile == (FILE *) NULL) {
printf(" Error: Cannot access file %s.\n", nodefilename);
triexit(1);
}
/* Read number of vertices, number of dimensions, number of vertex */
/* attributes, and number of boundary markers. */
stringptr = readline(inputline, infile, nodefilename);
m->invertices = (int) strtol(stringptr, &stringptr, 0);
stringptr = findfield(stringptr);
if (*stringptr == '\0') {
m->mesh_dim = 2;
} else {
m->mesh_dim = (int) strtol(stringptr, &stringptr, 0);
}
stringptr = findfield(stringptr);
if (*stringptr == '\0') {
m->nextras = 0;
} else {
m->nextras = (int) strtol(stringptr, &stringptr, 0);
}
stringptr = findfield(stringptr);
if (*stringptr == '\0') {
nodemarkers = 0;
} else {
nodemarkers = (int) strtol(stringptr, &stringptr, 0);
}
}
if (m->invertices < 3) {
printf("Error: Input must have at least three input vertices.\n");
triexit(1);
}
if (m->mesh_dim != 2) {
printf("Error: Triangle only works with two-dimensional meshes.\n");
triexit(1);
}
if (m->nextras == 0) {
b->weighted = 0;
}
initializevertexpool(m, b);
/* Read the vertices. */
for (i = 0; i < m->invertices; i++) {
vertexloop = (vertex) poolalloc(&m->vertices);
stringptr = readline(inputline, infile, infilename);
if (i == 0) {
firstnode = (int) strtol(stringptr, &stringptr, 0);
if ((firstnode == 0) || (firstnode == 1)) {
b->firstnumber = firstnode;
}
}
stringptr = findfield(stringptr);
if (*stringptr == '\0') {
printf("Error: Vertex %d has no x coordinate.\n", b->firstnumber + i);
triexit(1);
}
x = (REAL) strtod(stringptr, &stringptr);
stringptr = findfield(stringptr);
if (*stringptr == '\0') {
printf("Error: Vertex %d has no y coordinate.\n", b->firstnumber + i);
triexit(1);
}
y = (REAL) strtod(stringptr, &stringptr);
vertexloop[0] = x; // HELP, gdb gave segmentation fault here after reading a lot lines.
vertexloop[1] = y;
/* Read the vertex attributes. */
for (j = 2; j < 2 + m->nextras; j++) {
stringptr = findfield(stringptr);
if (*stringptr == '\0') {
vertexloop[j] = 0.0;
} else {
vertexloop[j] = (REAL) strtod(stringptr, &stringptr);
}
}
if (nodemarkers) {
/* Read a vertex marker. */
stringptr = findfield(stringptr);
if (*stringptr == '\0') {
setvertexmark(vertexloop, 0);
} else {
currentmarker = (int) strtol(stringptr, &stringptr, 0);
setvertexmark(vertexloop, currentmarker);
}
} else {
/* If no markers are specified in the file, they default to zero. */
setvertexmark(vertexloop, 0);
}
setvertextype(vertexloop, INPUTVERTEX);
/* Determine the smallest and largest x and y coordinates. */
if (i == 0) {
m->xmin = m->xmax = x;
m->ymin = m->ymax = y;
} else {
m->xmin = (x < m->xmin) ? x : m->xmin;
m->xmax = (x > m->xmax) ? x : m->xmax;
m->ymin = (y < m->ymin) ? y : m->ymin;
m->ymax = (y > m->ymax) ? y : m->ymax;
}
}
if (m->readnodefile) {
fclose(infile);
}
/* Nonexistent x value used as a flag to mark circle events in sweepline */
/* Delaunay algorithm. */
m->xminextreme = 10 * m->xmin - 9 * m->xmax;
}
#endif /* not TRILIBRARY */
/*****************************************************************************/
/* */
/* poolalloc() Allocate space for an item. */
/* */
/*****************************************************************************/
#ifdef ANSI_DECLARATORS
VOID *poolalloc(struct memorypool *pool)
#else /* not ANSI_DECLARATORS */
VOID *poolalloc(pool)
struct memorypool *pool;
#endif /* not ANSI_DECLARATORS */
{
VOID *newitem;
VOID **newblock;
unsigned long alignptr;
/* First check the linked list of dead items. If the list is not */
/* empty, allocate an item from the list rather than a fresh one. */
if (pool->deaditemstack != (VOID *) NULL) {
newitem = pool->deaditemstack; /* Take first item in list. */
pool->deaditemstack = * (VOID **) pool->deaditemstack;
} else {
/* Check if there are any free items left in the current block. */
if (pool->unallocateditems == 0) {
/* Check if another block must be allocated. */
if (*(pool->nowblock) == (VOID *) NULL) {
/* Allocate a new block of items, pointed to by the previous block. */
newblock = (VOID **) trimalloc(pool->itemsperblock * pool->itembytes +
(int) sizeof(VOID *) +
pool->alignbytes);
*(pool->nowblock) = (VOID *) newblock;
/* The next block pointer is NULL. */
*newblock = (VOID *) NULL;
}
/* Move to the new block. */
pool->nowblock = (VOID **) *(pool->nowblock);
/* Find the first item in the block. */
/* Increment by the size of (VOID *). */
alignptr = (unsigned long) (pool->nowblock + 1);
/* Align the item on an `alignbytes'-byte boundary. */
pool->nextitem = (VOID *)
(alignptr + (unsigned long) pool->alignbytes -
(alignptr % (unsigned long) pool->alignbytes));
/* There are lots of unallocated items left in this block. */
pool->unallocateditems = pool->itemsperblock;
}
/* Allocate a new item. */
newitem = pool->nextitem;
/* Advance `nextitem' pointer to next free item in block. */
pool->nextitem = (VOID *) ((char *) pool->nextitem + pool->itembytes);
pool->unallocateditems--;
pool->maxitems++;
}
pool->items++;
return newitem;
}
/*****************************************************************************/
/* */
/* pooldealloc() Deallocate space for an item. */
/* */
/* The deallocated space is stored in a queue for later reuse. */
/* */
/*****************************************************************************/
#ifdef ANSI_DECLARATORS
void pooldealloc(struct memorypool *pool, VOID *dyingitem)
#else /* not ANSI_DECLARATORS */
void pooldealloc(pool, dyingitem)
struct memorypool *pool;
VOID *dyingitem;
#endif /* not ANSI_DECLARATORS */
{
/* Push freshly killed item onto stack. */
*((VOID **) dyingitem) = pool->deaditemstack;
pool->deaditemstack = dyingitem;
pool->items--;
}
@MitchWheat,这是 Valgrind 的输出。任何想法?
`Opening thames_5m.node.
==8904== Memcheck, a memory error detector
==8904== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==8904== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==8904== Command: ./triangle thames_5m.node
==8904==
==8904== Warning: set address range perms: large range [0x3aeef040, 0xff703730) (undefined)
==8904== Invalid write of size 8
==8904== at 0x419FE0: readnodes (triangle.c:14033)
==8904== by 0x41C17B: main (triangle.c:15727)
==8904== Address 0xff703730 is 0 bytes after a block of size 3,296,806,640 alloc'd
==8904== at 0x4A06A2E: malloc (vg_replace_malloc.c:270)
==8904== by 0x400CB9: trimalloc (triangle.c:1431)
==8904== by 0x4044F9: poolinit (triangle.c:3967)
==8904== by 0x40485B: initializevertexpool (triangle.c:4295)
==8904== by 0x419EB8: readnodes (triangle.c:14005)
==8904== by 0x41C17B: main (triangle.c:15727)
==8904==
==8904== Invalid write of size 8
==8904== at 0x419FE6: readnodes (triangle.c:14034)
==8904== by 0x41C17B: main (triangle.c:15727)
==8904== Address 0xff703738 is 8 bytes after a block of size 3,296,806,640 alloc'd
==8904== at 0x4A06A2E: malloc (vg_replace_malloc.c:270)
==8904== by 0x400CB9: trimalloc (triangle.c:1431)
==8904== by 0x4044F9: poolinit (triangle.c:3967)
==8904== by 0x40485B: initializevertexpool (triangle.c:4295)
==8904== by 0x419EB8: readnodes (triangle.c:14005)
==8904== by 0x41C17B: main (triangle.c:15727)
==8904==
==8904== Invalid write of size 8
==8904== at 0x41A036: readnodes (triangle.c:14041)
==8904== by 0x41C17B: main (triangle.c:15727)
==8904== Address 0xff703740 is 16 bytes after a block of size 3,296,806,640 alloc'd
==8904== at 0x4A06A2E: malloc (vg_replace_malloc.c:270)
==8904== by 0x400CB9: trimalloc (triangle.c:1431)
==8904== by 0x4044F9: poolinit (triangle.c:3967)
==8904== by 0x40485B: initializevertexpool (triangle.c:4295)
==8904== by 0x419EB8: readnodes (triangle.c:14005)
==8904== by 0x41C17B: main (triangle.c:15727)
==8904==
==8904== Invalid write of size 4
==8904== at 0x41A0A2: readnodes (triangle.c:14055)
==8904== by 0x41C17B: main (triangle.c:15727)
==8904== Address 0xff703748 is not stack'd, malloc'd or (recently) free'd
==8904==
==8904== Invalid write of size 4
==8904== at 0x41A0B1: readnodes (triangle.c:14057)
==8904== by 0x41C17B: main (triangle.c:15727)
==8904== Address 0xff70374c is not stack'd, malloc'd or (recently) free'd
==8904==
==8904==
==8904== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==8904== Access not within mapped region at address 0xFF704000
==8904== at 0x41A036: readnodes (triangle.c:14041)
==8904== by 0x41C17B: main (triangle.c:15727)
==8904== If you believe this happened as a result of a stack
==8904== overflow in your program's main thread (unlikely but
==8904== possible), you can try to increase the size of the
==8904== main thread stack using the --main-stacksize= flag.
==8904== The main thread stack size used in this run was 10485760.
==8904==
==8904== HEAP SUMMARY:
==8904== in use at exit: 3,296,807,208 bytes in 2 blocks
==8904== total heap usage: 2 allocs, 0 frees, 3,296,807,208 bytes allocated
==8904==
==8904== LEAK SUMMARY:
==8904== definitely lost: 0 bytes in 0 blocks
==8904== indirectly lost: 0 bytes in 0 blocks
==8904== possibly lost: 0 bytes in 0 blocks
==8904== still reachable: 3,296,807,208 bytes in 2 blocks
==8904== suppressed: 0 bytes in 0 blocks
==8904== Reachable blocks (those to which a pointer was found) are not shown.
==8904== To see them, rerun with: --leak-check=full --show-reachable=yes
==8904==
==8904== For counts of detected and suppressed errors, rerun with: -v
==8904== ERROR SUMMARY: 353 errors from 5 contexts (suppressed: 6 from 6)
1,1 Top
`
最佳答案
vertexloop
由自定义函数这样分配:
vertexloop = (vertex) poolalloc(&m->vertices);
您应该测试 vertexloop
是否为 NULL
并使用有意义的消息中止。
如果这告诉您无法分配内存,请调查poolalloc
以查看是否存在导致大型计算机上分配失败的任何限制,这些限制可能是操作系统通过配额施加的。使用 malloc
编写一个简单的分配测试并查看何时失败。
关于c - 使用大型输入文件时使用三角形软件出现分割错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35879793/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!