gpt4 book ai didi

c++ - IBM AIX 中的内存分配使用 xlc 编译器失败?

转载 作者:太空宇宙 更新时间:2023-11-04 02:37:31 27 4
gpt4 key购买 nike

在我的代码中有必要分配几个大数组。

但是,当我尝试使用 IBM xlc_r 时:

xlc_r -g -O -L。 -qarch=pwr7 -qtune=pwr7 -lesslsmp -lm -qsmp -qthreaded -qmaxmem=-1 2.c

int main()
{
int natom = 5000;
while(1)
{
double *z =(double*) malloc(natom*natom*natom* sizeof(double));
if(!z)
{
printf("error memory vector z\n\n");
exit(-1);
}
}
}

我收到 Killed 内存 vector z 错误。

这是 ulimit -a :

core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 102400
pipe size (512 bytes, -p) 64
stack size (kbytes, -s) unlimited
cpu time (seconds, -t) unlimited
max user processes (-u) 128
virtual memory (kbytes, -v) unlimited

分配更多内存是否需要任何标志?

最佳答案

不久前,我在一台 POWER775 AIX 机器上遇到了这个问题。您需要在编译时添加 -q64 标志,以便分配超过 2GiB 的内存。请注意,其他人关于使用 int 的评论可能与您的代码相关,这就是我下面的示例使用 size_t 的原因。

我建议您运行一个简单的分配测试来调查这一点。我为这种情况编写的测试程序如下。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char * argv[])
{
size_t max = (argc>1) ? (size_t)atol(argv[1]) : ((size_t)256*1024)*((size_t)1024*1024);
for (size_t n=1; n<=max; n*=2) {
printf("attempting malloc of %zu bytes \n", n);
fflush(0);
void * ptr = malloc(n);
if (ptr==NULL) {
printf("malloc of %zu bytes failed \n", n);
fflush(0);
return 1;
} else {
printf("malloc of %zu bytes succeeded \n", n);
fflush(0);
memset(ptr,0,n);
printf("memset of %zu bytes succeeded \n", n);
fflush(0);
free(ptr);
}
}
return 0;
}

相关的构建标志如下。

ifeq ($(TARGET),POWER7-AIX)
# Savba i.e. POWER775 AIX
CC = mpcc_r
OPT = -q64 -O3 -qhot -qsmp=omp -qtune=pwr7 -qarch=pwr7 -qstrict
CFLAGS = $(OPT) -qlanglvl=stdc99
endif

关于c++ - IBM AIX 中的内存分配使用 xlc 编译器失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35567428/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com