Created
June 21, 2020 13:23
-
-
Save riku1314/2b001502bdcd6d1c1f3895c4b7ea3146 to your computer and use it in GitHub Desktop.
B-1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern void make_matrix(unsigned int size, int flag,double **a,double **b,unsigned int number) | |
{ | |
int i,j; | |
*a=(double*)malloc(sizeof(double)*size); | |
*b=(double*)malloc(sizeof(double)*size); | |
for(i=0;i<size;i++){ | |
for(j=0;j<size;j++){ | |
a[i][j]=flag; | |
b[i][j]=flag; | |
} | |
} | |
} | |
extern void check_matrix(unsigned int size, double **c, unsigned int number) | |
{ | |
int i,j; | |
*c=(double*)malloc(sizeof(double)*size); | |
for(i=0;i<size;i++){ | |
for(j=0;j<size;j++){ | |
printf("%2d",c[i][j]); | |
} | |
putchar('\n'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include<omp.h> | |
#include "jikken.h" | |
int main(int argc, char *argv[]) | |
{ | |
/* ここに変数を定義します */ | |
int size; | |
int i,j,k; | |
double start=0,end=0; | |
unsigned int number=1931165; | |
int flag=1; | |
if ((argc != 2) || (size=atoi(argv[1]))<=0) { | |
fprintf(stderr,"Invalid Argument\n"); | |
exit(1); | |
} | |
double **a; | |
double **b; | |
double **c; | |
make_matrix(size,flag,a,b,number); | |
/* ここまで実行すると、size に行列サイズが代入されます。*/ | |
/* これより下にプログラムを作成してください。*/ | |
start=omp_get_wtime(); | |
#pragma omp parallel for | |
for(i=0;i<size;i++){ | |
for(j=0;j<size;j++){ | |
c[i][j]=0; | |
for(k=0;k<size;k++){ | |
c[i][j]+=a[i][k]*b[k][j]; | |
} | |
} | |
} | |
end=omp_get_wtime(); | |
check_matrix(size,c,number); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment