如何使out_dotp.err停止引起错误
我需要帮助,我已经弄乱了这个代码了几个小时,它应该以矛盾的方式执行点产品操作,但我无法让它输出任何结果,而我所得到的只是令人难以置信的痛苦和此错误消息。谁能通过解决这个错误的可能解决来启发我可怜的折磨灵魂?我将永远感谢。
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char **argv){
int exe_mode, num_td, vec_size;
sscanf(argv[0], "%d", &exe_mode);
sscanf(argv[1], "%d", &num_td);
sscanf(argv[2], "%d", &vec_size);
srand(1);
int a[vec_size];
int b[vec_size];
int dot_prod = 0;
int i;
double start = omp_get_wtime();
//initializing the vectors
for( i = 0; i < vec_size; i++){
a[i] = (int) (rand() % vec_size - vec_size/2);
b[i] = (int) (rand() % vec_size - vec_size/2);
}
//Sequential execution
if (exe_mode == 1){
for( i = 0; i<vec_size;i++){
dot_prod += a[i] * b[i];
}
}
//Parallel execution
if (exe_mode == 2){
#pragma omp parallel for reduction(+: dot_prod) num_threads(num_td)
for(i=0; i<vec_size;i++){
dot_prod += a[i] * b[i];
}
}
//Parallel execution with vectorization
if (exe_mode == 3){
#pragma omp simd reduction(+: dot_prod)
for( i=0; i<vec_size;i++){
dot_prod += a[i] * b[i];
}
double runtime = omp_get_wtime()-start;
printf("%.4e\t%i\n", runtime ,dot_prod);
}
return 0;
}
I need help, I have been messing with this code for hours , it is supposed to perform the dot product operation in a paralel manner yet I cannot get it to output any result and all I get is excruciating pain and this error message. could anyone enlighten my poor tortured soul with a possible fix for this error? I will be eternally thankful.
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char **argv){
int exe_mode, num_td, vec_size;
sscanf(argv[0], "%d", &exe_mode);
sscanf(argv[1], "%d", &num_td);
sscanf(argv[2], "%d", &vec_size);
srand(1);
int a[vec_size];
int b[vec_size];
int dot_prod = 0;
int i;
double start = omp_get_wtime();
//initializing the vectors
for( i = 0; i < vec_size; i++){
a[i] = (int) (rand() % vec_size - vec_size/2);
b[i] = (int) (rand() % vec_size - vec_size/2);
}
//Sequential execution
if (exe_mode == 1){
for( i = 0; i<vec_size;i++){
dot_prod += a[i] * b[i];
}
}
//Parallel execution
if (exe_mode == 2){
#pragma omp parallel for reduction(+: dot_prod) num_threads(num_td)
for(i=0; i<vec_size;i++){
dot_prod += a[i] * b[i];
}
}
//Parallel execution with vectorization
if (exe_mode == 3){
#pragma omp simd reduction(+: dot_prod)
for( i=0; i<vec_size;i++){
dot_prod += a[i] * b[i];
}
double runtime = omp_get_wtime()-start;
printf("%.4e\t%i\n", runtime ,dot_prod);
}
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您没有检查引起SSCAN的第一个参数引起segfault的参数计数。我通过添加多个检查来修复这些零件:
Because you did not check argument count which caused segfault on the sscan's first parameter. I fixed those parts by adding multiple checks: