-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimp_func_p.c
executable file
·92 lines (80 loc) · 1.75 KB
/
imp_func_p.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdio.h>
#include <math.h>
#include <omp.h>
#define DIV 100 //分割数
#define MAXITER 10 //最大反復数
#define ZERO 0.0
#define ONE 1.0
#define TWO 2.0
#define THREE 3.0
#define FOUR 4.0
#define EIGHT 8.0
#define EPS 1.0E-15
double fxy(double x,double y){ //描画する陰関数
return x*x*x*x-FOUR*x*x+y*y;
}
double dfx(double x,double y){ //陰関数のx微分
return FOUR*x*x*x-EIGHT*x;
}
double dfy(double x,double y){ //陰関数のy微分
return TWO*y;
}
double newtonx(double x,double y){ //x軸方向のニュートン法
int i;
double x2;
for(i=0;i<MAXITER;i++){
x2=x-fxy(x,y)/dfx(x,y);
if(fabs(x2-x)<=EPS){
return x2;
}
if(fabs(x2)>TWO){
return x2;
}
x=x2;
}
return -THREE;
}
double newtony(double x,double y){ //y軸方向のニュートン法
int i;
double y2;
for(i=0;i<MAXITER;i++){
y2=y-fxy(x,y)/dfy(x,y);
if(fabs(y2-y)<=EPS){
return y2;
}
if(fabs(y2)>TWO){
return y2;
}
y=y2;
}
return -THREE;
}
int main(void){
int i,j;
double unit,x,y;
FILE *fp;
char filename[10];
unit=TWO/DIV; //分割幅
double t1,t2;
t1=omp_get_wtime();
#pragma omp parallel private(filename,fp,j,x,y)
{
sprintf(filename,"ans_%d",omp_get_thread_num());
fp=fopen(filename,"w");
#pragma omp for
for(i=-DIV;i<=DIV;i++){
for(j=-DIV;j<=DIV;j++){
x=newtonx(unit*i,unit*j);
if(fabs(x)<=TWO)
fprintf(fp,"%f %f\n",x,unit*j);
y=newtony(unit*i,unit*j);
if(fabs(y)<=TWO)
fprintf(fp,"%f %f\n",unit*i,y);
}
}
fclose(fp);
}
t2=omp_get_wtime();
printf("TIME=%10.5g\n",t2-t1);
return 0;
}