并行处理fftw库

fftw并行处理需要在并行处理之前(for循环)开辟空间、制定plan。以封装逆傅里叶为例,操作步骤:首先封装一个并行处理所需要的结构体

typedef struct plan_thread

{

         fftw_complex* input;

         fftw_complex* output;

        fftw_plan plan;

}planThreads;

.h里面

planThreads* init_omp_threads_ifft(int N);

void fftw_execute_ifft(planThreads* m_vecPlan);//需要归一化处理

void free_destroy(planThreads* m_vecPlan);

.c 使用openMP并行多线程

planThreads* init_omp_threads_ifft(int N)

{

        int thread_num = omp_get_max_threads();//获取最大线程

        if(!fftw_init_threads())

        {

                perror("init threads fail\n");

        }

        planThreads *m_vecPlan;

        fftw_plan_with_nthreads(thread_num );//设置线程数

        m_vecPlan = (planThreads*)malloc(sizeof(planThreads)*thread_num);

        for(int i = 0; i<thread_num;i++)

        {

                m_vecPlan[i].input = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*N);

                m_vecPlan[i].output = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*N);

                m_vecPlan[i].plan = fftw_plan_dft_1d(N,m_vecPlan[i].input,m_vecPlan[i].output,FFTW_BACKWARD,FFTW_ESTIMATE)

        }

        return  m_vecPlan;

}

int curThread = omp_get_thread_num();

fftw_execute(m_vecPlan[curThread ].plan);//需要获得当前的线程,赋值和取值也是如此

void free_destroy(planThreads* m_vecPlan)

{

        for(int i = 0;i < opm_get_max_threads();i++)

        {

                fftw_free(m_vecPlan.input);

                fftw_free(m_vecPlan.output);

                fftw_destroy_plan(m_vecPlan[i].plan);

        }

}

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值