#include "cuda_runtime.h"
#include <cuda.h>
#include <stdlib.h>
#include <iostream>
#include <sys/time.h>
#include <chrono>
#define M 1000000 // M个点等分[-1, 1]
#define N 100 // Legendre polynomial的阶数
// https://people.sc.fsu.edu/~jburkardt/cpp_src/legendre_polynomial/legendre_polynomial.cpp
// https://people.sc.fsu.edu/~jburkardt/cpp_src/legendre_polynomial/legendre_polynomial.html
double *p_polynomial_value ( int m, int n, double x[] )
{
int i;
int j;
double *v;
if ( n < 0 ) return NULL;
v = new double[m*(n+1)];
for ( i = 0; i < m; i++ ) v[i+0*m] = 1.0;
if ( n < 1 ) return v;
for ( i = 0; i < m; i++ ) v[i+1*m] = x[i];
for ( j = 2; j <= n; j++ )
{
for ( i = 0; i < m; i++ )
{
v[i+j*m] = ( ( double ) ( 2 * j - 1 ) * x[i] * v[i+(j-1)*m]
- ( double
CUDA for循环计算递归函数,以勒让德多项式(Legendre polynomial)为例(2)
于 2022-02-10 22:40:23 首次发布