openmp降低大堆阵列会导致段故障

问题描述 投票:0回答:1

当我尝试减少一个大堆阵列以减少开放量时,它会段故障:

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

int main() {
  double *test = NULL;
  size_t size = (size_t)1024 * 1024 * 16; // large enough to overflow openmp threads' stack

  test = malloc(size * sizeof(double));

#pragma omp parallel reduction(+ : test[0 : size]) num_threads(2) 
  {
    test[0] = 0;
#pragma omp critical
    {
      printf("frame address: %p\n", __builtin_frame_address(0));
      printf("test: %p\n", test);
    }
  }
  free(test);
  printf("Allocated %zu doubles\n\n", size);
}
请注意,请注意

double *test

是在堆上分配的,因此不是this
和this.的重复。 th这个示例可与小尺寸数组一起使用,但段故障具有较大的数组。数组分配在堆上,系统内存就足够了。 SIMIMAR问题

但是,即使在堆上分配了数组,段错误仍然会发生。

在其他社区中也有同样的问题:

https://community.intel.com/t5/intel-fortran-compiler/segentation-fault-when-when-using-large-array-with-openmp/m-p/758829,

https://forums.oracle.com/ords/apexds/post/segentation-fault-with-with-large-arrays-andares-and-openmp-1728

,但我发现的所有解决方案都是关于增加OpenMP堆栈尺寸。

我认为应该有一个真正的解决方案,所以我在GCC的Bugzilla上发出错误:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id =118909

thanks to jakub jelinek,此错误的原因是,大多数编译器都在堆栈上分配私有数据,这对性能有益。如果您确实需要大型私有数据,则可以通过设置

OMP_STACKSIZE
c segmentation-fault openmp reduce
1个回答
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.