C 使用GSL解决柯西问题的问题
我试图用GSL解决柯西问题。我有一个带一个参数的基元函数。我认为问题可能出在我的参数上,但有错误C 使用GSL解决柯西问题的问题,c,openmp,gsl,C,Openmp,Gsl,我试图用GSL解决柯西问题。我有一个带一个参数的基元函数。我认为问题可能出在我的参数上,但有错误 gsl: driver.c:356: ERROR: integration limits and/or step direction not consistent Default GSL error handler invoked. 随时投球 这是代码 #include <stdio.h> #include <stdlib.h> #include <math.h>
gsl: driver.c:356: ERROR: integration limits and/or step direction not consistent
Default GSL error handler invoked.
随时投球
这是代码
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <omp.h>
// GSL lib includes
#include <gsl/gsl_sf_bessel.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_odeiv2.h>
struct Dots {
double param;
double x;
double y;
};
int ode_func (double x, const double y[], double f[], void *params)
{
double mu = *(int *)params;
f[0] = (x + 2 * y[0]) / (1 + mu * mu);
return GSL_SUCCESS;
}
void calc_cauchy_problem(double x_start, double x_end, double y_start,
int count, int param1, int param2) {
int dim = 1;
double x = x_start;
double y[1] = {y_start};
int param = param1;
int status = 0;
char filename[10];
omp_set_num_threads(1); // for debugging
#pragma omp parallel for private(param, status, x, y)
for (param = param1; param <= param2; param++) {
struct Dots ArrayOfDots[count];
gsl_odeiv2_system sys = {ode_func, NULL, dim, ¶m};
gsl_odeiv2_driver * d =
gsl_odeiv2_driver_alloc_y_new (&sys, gsl_odeiv2_step_rk8pd, 1e-6, 1e-6, 0.0);
for (int i = 1; i <= count; i++) {
double xi = i * x_start / count;
int status = gsl_odeiv2_driver_apply(d, &x, xi, y);
if (status != GSL_SUCCESS)
{
printf ("error, return value=%d\n", status);
break;
}
ArrayOfDots[i].param = param;
ArrayOfDots[i].x = xi;
ArrayOfDots[i].y = y[0];
printf("%d\n", omp_get_thread_num());
}
gsl_odeiv2_driver_free (d);
}
}
int main() {
double start_time = omp_get_wtime();
double x_start = 0;
double x_end = 10;
double y_start = 0;
const int count = 10;
int param1 = 1;
int param2 = 2;
calc_cauchy_problem(x_start, x_end, y_start, count, param1, param2);
printf("Elapsed time = %f\n", omp_get_wtime() - start_time);
return 0;
}
#包括
#包括
#包括
#包括
//GSL库包括
#包括
#包括
#包括
#包括
结构点{
双参数;
双x;
双y;
};
int ode_func(双x,常数双y[],双f[],void*参数)
{
双μ=*(int*)参数;
f[0]=(x+2*y[0])/(1+mu*mu);
返回GSL_成功;
}
无效计算柯西问题(双x开始,双x结束,双y开始,
整数计数,整数参数1,整数参数2){
int-dim=1;
双x=x_启动;
双y[1]={y_start};
int param=param1;
int status=0;
字符文件名[10];
omp_set_num_threads(1);//用于调试
#pragma omp并行专用(参数、状态、x、y)
对于(param=param1;param问题已解决,我认为这与struct Dots ArrayOfDots[count];
我在循环中使用它。这是没有问题的代码
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <omp.h>
// GSL lib includes
#include <gsl/gsl_sf_bessel.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_odeiv2.h>
int ode_func (double x, const double y[], double f[], void *params)
{
double mu = *(int *)params;
f[0] = (x + 2 * y[0]) / (1 + mu * mu);
return GSL_SUCCESS;
}
void calc_cauchy_problem(double x_start, double x_end, double y_start,
int count, int param1, int param2) {
#pragma omp parallel for
for(int param = param1; param < param2; param++) {
gsl_odeiv2_system sys = {ode_func, NULL, 1, ¶m};
gsl_odeiv2_driver * d =
gsl_odeiv2_driver_alloc_y_new (&sys, gsl_odeiv2_step_rk8pd,
1e-6, 1e-6, 0.0);
int i;
double x = x_start, x1 = x_end;
double y[1] = { y_start };
for (i = 1; i <= count; i++)
{
double xi = i * x1 / count;
int status = gsl_odeiv2_driver_apply (d, &x, xi, y);
if (status != GSL_SUCCESS)
{
printf ("error, return value=%d\n", status);
break;
}
// printf ("%d %d %.5e %.5e\n", omp_get_thread_num(), param, x, y[0]);
}
gsl_odeiv2_driver_free (d);
}
}
int main() {
double start_time = omp_get_wtime();
double x_start = 0;
double x_end = 10;
double y_start = 0;
const int count = 100000;
int param1 = 1;
int param2 = 20;
calc_cauchy_problem(x_start, x_end, y_start, count, param1, param2);
printf("Elapsed time = %f\n", omp_get_wtime() - start_time);
return 0;
}
#包括
#包括
#包括
#包括
//GSL库包括
#包括
#包括
#包括
#包括
int ode_func(双x,常数双y[],双f[],void*参数)
{
双μ=*(int*)参数;
f[0]=(x+2*y[0])/(1+mu*mu);
返回GSL_成功;
}
无效计算柯西问题(双x开始,双x结束,双y开始,
整数计数,整数参数1,整数参数2){
#pragma-omp并行
对于(int-param=param1;param 对于(i=1;i问题已解决,我认为这与struct Dots ArrayOfDots[count];
我在循环中使用它。这是没有问题的代码
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <omp.h>
// GSL lib includes
#include <gsl/gsl_sf_bessel.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_odeiv2.h>
int ode_func (double x, const double y[], double f[], void *params)
{
double mu = *(int *)params;
f[0] = (x + 2 * y[0]) / (1 + mu * mu);
return GSL_SUCCESS;
}
void calc_cauchy_problem(double x_start, double x_end, double y_start,
int count, int param1, int param2) {
#pragma omp parallel for
for(int param = param1; param < param2; param++) {
gsl_odeiv2_system sys = {ode_func, NULL, 1, ¶m};
gsl_odeiv2_driver * d =
gsl_odeiv2_driver_alloc_y_new (&sys, gsl_odeiv2_step_rk8pd,
1e-6, 1e-6, 0.0);
int i;
double x = x_start, x1 = x_end;
double y[1] = { y_start };
for (i = 1; i <= count; i++)
{
double xi = i * x1 / count;
int status = gsl_odeiv2_driver_apply (d, &x, xi, y);
if (status != GSL_SUCCESS)
{
printf ("error, return value=%d\n", status);
break;
}
// printf ("%d %d %.5e %.5e\n", omp_get_thread_num(), param, x, y[0]);
}
gsl_odeiv2_driver_free (d);
}
}
int main() {
double start_time = omp_get_wtime();
double x_start = 0;
double x_end = 10;
double y_start = 0;
const int count = 100000;
int param1 = 1;
int param2 = 20;
calc_cauchy_problem(x_start, x_end, y_start, count, param1, param2);
printf("Elapsed time = %f\n", omp_get_wtime() - start_time);
return 0;
}
#包括
#包括
#包括
#包括
//GSL库包括
#包括
#包括
#包括
#包括
int ode_func(双x,常数双y[],双f[],void*参数)
{
双μ=*(int*)参数;
f[0]=(x+2*y[0])/(1+mu*mu);
返回GSL_成功;
}
无效计算柯西问题(双x开始,双x结束,双y开始,
整数计数,整数参数1,整数参数2){
#pragma-omp并行
对于(int-param=param1;param 对于(i=1;i)这给人一种代码拼图的印象。你能把它变成一个吗?对不起,这个拼图:)。把它变成实码。这给人一种代码拼图的印象。你能把它变成一个吗?对不起,这个拼图:)。把它变成实码。