---
title: kml_fft(f/h)_mpi_plan_r2r
description: "建立单个连续数据序列n维R2R变换的plan。"
url: https://www.hikunpeng.com/document/detail/zh/hpchistory/hpckit/develop2400/kunpengaccel_kml_0358.html
sourcePath: /source/zh/hpchistory/hpckit/develop2400/kunpengaccel_kml_0358.html
indexId: 7756a11878234ed61c479c2927590b7fb6ee790ea81b641c604f34984827e4fd67
---
# kml_fft(f/h)_mpi_plan_r2r

建立单个连续数据序列n维R2R变换的plan。

#### 接口定义

C interface：

kml_fft_plan kml_fft_mpi_plan_r2r(int rank, const ptrdiff_t *n, double *in, double *out, const kml_fft_r2r_kind *kind, MPI_comm comm, unsigned flags);

kml_fftf_plan kml_fftf_mpi_plan_r2r(int rank, const ptrdiff_t *n, float *in, float *out, const kml_fftf_r2r_kind *kind, MPI_comm comm, unsigned flags);

kml_ffth_plan kml_ffth_mpi_plan_r2r(int rank, const ptrdiff_t *n, __fp16 *in, __fp16 *out, const kml_ffth_r2r_kind *kind, MPI_comm comm, unsigned flags);


#### 返回值

函数返回一个kml_fft(f)_plan类型的结构体指针。将该对象作为参数传入kml_fft(f)_execute函数中使用，将对当前提供的输入in和输出out执行FFT变换；另外，也可以通过将该对象作为参数传入kml_fft(f)_execute_r2r函数中以对新的输入in和输出out执行FFT变换。

如果函数返回非空指针，则表示plan执行成功，否则表示执行失败。


#### 参数

| 参数名 | 数据类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| rank | int | FFT变换的维度是rank，约束：1 ≤ rank ≤ 3。 | 输入 |
| n | const ptrdiff\_t \* | n是维度为rank的数组，包含FFT序列每一维度的大小，约束：n[i] ≥ 1, for i in 0 to rank \- 1。 | 输入 |
| in | 双精度：double\* 单精度：float\* 半精度：\_\_fp16\* | 输入待变换的数据。 | 输入 |
| out | 双精度：double\* 单精度：float\* 半精度：\_\_fp16\* | 输出快速傅里叶变换后的数据。 | 输出 |
| kind | 双精度：const kml\_fft\_r2r\_kind\* 单精度：const kml\_fftf\_r2r\_kind\* 半精度：const kml\_ffth\_r2r\_kind\* | kind是大小为rank的数组，包含FFT序列每一维度的R2R变换类型，kind[i] (for i in 0 to rank \- 1)有以下可选值： KML\_FFT\_R2HC KML\_FFT\_HC2R KML\_FFT\_DHT KML\_FFT\_REDFT00 KML\_FFT\_REDFT01 KML\_FFT\_REDFT10 KML\_FFT\_REDFT11 KML\_FFT\_RODFT00 KML\_FFT\_RODFT01 KML\_FFT\_RODFT10 KML\_FFT\_RODFT11 | 输入 |
| comm | MPI\_Comm | MPI句柄通信器。 | 输入 |
| flags | unsigned int | planning选项，未使用。 | 输入 |


#### 依赖

C: "kfft-mpi.h"


#### 示例

C interface：

```
const ptrdiff_t N0 = 4, N1 = 4;
kml_fft_plan plan;
ptrdiff_t alloc_local, local_n0, local_0_start;
MPI_Init(&argc, &argv);
MPI_Comm comm = MPI_COMM_WORLD;
kml_fft_mpi_init();
double *in = NULL;
double *out = NULL;
ptrdiff_t rank = 2;
kml_fft_r2r_kind kind0 = KML_FFT_R2HC;
kml_fft_r2r_kind kind1 = KML_FFT_R2HC;
ptrdiff_t *n = (ptrdiff_t *)kml_fft_malloc(sizeof(ptrdiff_t) * rank);
kml_fft_r2r_kind *kind = (kml_fft_r2r_kind *)kml_fft_malloc(sizeof(kml_fft_r2r_kind) * rank);
n[0] = N0;
n[1] = N1;
kind[0] = kind0;
kind[1] = kind1;
/* get local data size and allocate */
alloc_local = kml_fft_mpi_local_size(rank, n, comm, &local_n0, &local_0_start);
if (alloc_local == -1) {
printf("[%s][%d] allocate size fail!!!\n", __func__, __LINE__);
}
in = (double *)kml_fft_malloc(sizeof(double) * alloc_local);
if (in == NULL) {
printf("[%s][%d] malloc memory fail!!!\n", __func__, __LINE__);
}
out = (double *)kml_fft_malloc(sizeof(double) * alloc_local);
if (out == NULL) {
printf("[%s][%d] malloc memory fail!!!\n", __func__, __LINE__);
}
/* create plan for in-place forward DFT */
plan = kml_fft_mpi_plan_r2r(rank, n, in, out, comm, kind, KML_FFT_ESTIMATE);
/* compute transforms, in-place, as many times as desired */
kml_fft_execute_r2r(plan, in, out);
kml_fft_destroy_plan(plan);
kml_fft_mpi_cleanup();
MPI_Finalize();
```
