gpt4 book ai didi

c - 使用 omp parallel for 但不是顺序时出现段错误

转载 作者:行者123 更新时间:2023-12-04 13:12:17 24 4
gpt4 key购买 nike

我在使用#pragma omp parallel for 时遇到问题

基本上,我有数百个 DNA 序列,我想针对一种称为 NNLS 的算法运行这些序列。

我认为并行执行会大大加快速度,因此我应用了#pragma 运算符。

当我按顺序运行它时没有问题,结果很好,但是当我使用#pragma omp parallel 运行它时,我在算法中遇到了一个段错误(有时在不同的点)。

#pragma omp parallel for
for(int i = 0; i < dir_count; i++ ) {

int z = 0;
int w = 0;
struct dirent *directory_entry;
char filename[256];

directory_entry = readdir(input_directory_dh);

if(strcmp(directory_entry->d_name, "..") == 0 || strcmp(directory_entry->d_name, ".") == 0) {
continue;
}

sprintf(filename, "%s/%s", input_fasta_directory, directory_entry->d_name);

double *count_matrix = load_count_matrix(filename, width, kmer);

//normalize_matrix(count_matrix, 1, width)
for(z = 0; z < width; z++)
count_matrix[z] = count_matrix[z] * lambda;

// output our matricies if we are in debug mode
printf("running NNLS on %s, %d, %d\n", filename, i, z);
double *trained_matrix_copy = malloc(sizeof(double) * sequences * width);
for(w = 0; w < sequences; w++) {
for(z = 0; z < width; z++) {
trained_matrix_copy[w*width + z] = trained_matrix[w*width + z];
}
}

double *solution = nnls(trained_matrix_copy, count_matrix, sequences, width, i);


normalize_matrix(solution, 1, sequences);
for(z = 0; z < sequences; z++ ) {
solutions(i, z) = solution[z];
}

printf("finished NNLS on %s\n", filename);

free(solution);
free(trained_matrix_copy);
}

gdb 总是在我的线程中以不同的品脱退出,所以我不知道出了什么问题。

我试过的:
  • 分配每个矩阵的副本,这样它们就不会相互重叠
  • #pragma 片段
  • 混合使用私有(private)/共享运算符
  • 使用不同的输入序列
  • 在调用 NNLS 之前写出我的 trained_matrix 和 count_matrix,确保它们看起来不错。 (他们这样做!)

  • 我有点没主意了。有人有什么建议吗?

    最佳答案

    解决方案:确保在多线程时不要在函数中使用静态变量(该死的 f2c 翻译器)

    关于c - 使用 omp parallel for 但不是顺序时出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16285577/

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