Ejemplo n.º 1
0
 void jacobi_kernel_wrapper(range const & y_range, size_t n, vector<double> & dst, vector<double> const & src) {
     for(size_t y = y_range.begin(); y < y_range.end(); ++y) {
               double * dst_ptr = &dst[y * n];
         const double * src_ptr = &src[y * n];
         jacobi_kernel( dst_ptr, src_ptr, n );
     }
 }
Ejemplo n.º 2
0
    void jacobi(
        std::size_t n
      , std::size_t iterations, std::size_t block_size
      , std::string output_filename)
    {
        typedef std::vector<double> vector;

        std::shared_ptr<vector> grid_new(new vector(n * n, 1));
        std::shared_ptr<vector> grid_old(new vector(n * n, 1));

        hpx::util::high_resolution_timer t;
        for(std::size_t i = 0; i < iterations; ++i)
        {
            // MSVC is unhappy if the OMP loop variable is unsigned
#pragma omp parallel for schedule(JACOBI_SMP_OMP_SCHEDULE)
            for(boost::int64_t y = 1; y < boost::int64_t(n-1); ++y)
            {
                      double * dst = &(*grid_new)[y * n];
                const double * src = &(*grid_new)[y * n];
                jacobi_kernel(
                    dst
                  , src
                  , n
                );
            }
            std::swap(grid_new, grid_old);
        }

        report_timing(n, iterations, t.elapsed());
        output_grid(output_filename, *grid_old, n);
   }
int main(void)
{
    float a[3][3] = {5,2,1,-1,4,2,2,-3,10};
    float b[3]={-12,20,3};
    float x[3]={0,0,0};
    float y[3]={0,0,0};
    //int size = sizeof(b) / sizeof(float);
    int times = 0;  //记录总次数

    times = jacobi_kernel(a, b, x, y, SIZE, ERROR);

    std::cout << "-----------result------------------" << std::endl;
    std::cout << "Total time: " << times << std::endl;
    for (int i=0; i<3; i++)
       std::cout << std::fixed << std::setprecision(6) << y[i] << std::endl;
    return 0;
}