---
title: kml_fft(f)_mpi_plan_create_r2c
description: "建立单个连续数据序列3维R2C变换的plan。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0370.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0370.html
indexId: 17189edae5f8d4f86e96478c5b68fb6266c33f40d0367497739590f6f48ad05361
---
# kml_fft(f)_mpi_plan_create_r2c

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

#### 接口定义

C interface：

kml_fft_plan kml_fft_mpi_plan_create_r2c(int backend, const int *inbox_low, const int *inbox_high, const int *inbox_order, const int *outbox_low, const int *outbox_high, const int *outbox_order, MPI_Comm comm, const kml_fft_mpi_options options);

kml_fftf_plan kml_fftf_mpi_plan_create_r2c(int backend, const int *inbox_low, const int *inbox_high, const int *inbox_order, const int *outbox_low, const int *outbox_high, const int *outbox_order, MPI_Comm comm, const kml_fftf_mpi_options options);


#### 返回值

函数返回一个kml_fft(f)_plan类型的结构体指针。将该对象作为参数传入kml_fft(f)_ mpi_execute_dft_r2c_ext函数、kml_fft(f)_mpi_forward_r2c函数中使用，且不需要在plan创建阶段指定in、out buffer。

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


#### 参数

| 参数名 | 数据类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| backend | int | 底层库类型，当前仅支持BACKEND\_KFFT。 | 输入 |
| inbox\_low | const int \* | 是长度为3的一维数组，输入数据在三个维度的切分范围下限，\-1≤inbox\_low[i]≤n[i]\-1 for i in 0、1、2。 | 输入 |
| inbox\_high | const int \* | 是长度为3的一维数组，输入数据在三个维度的切分范围上限，\-1≤inbox\_high[i]≤n[i]\-1 for i in 0、1、2，且0≤（inbox\_high[i]\-inbox\_low[i]+1）≤n[i] for i in 0、1、2。 | 输入 |
| inbox\_order | const int \* | 是长度为3的一维数组，输入数据维度的顺序，取值为0、1、2的任意顺序组合，输入NULL，默认order为0、1、2。 | 输入 |
| outbox\_low | const int \* | 是长度为3的一维数组，输出数据在三个维度的切分范围下限，\-1≤outbox\_low[i]≤n[i]\-1 for i in 0、1、2。 | 输入 |
| outbox\_high | const int \* | 是长度为3的一维数组，输出数据在三个维度的切分范围上限，\-1≤outbox\_high[i]≤n[i]\-1 for i in 0、1、2，且 0≤(outbox\_high[i] \- outbox\_low[i] + 1)≤n[i] for i in 0、1、2。 | 输入 |
| outbox\_order | const int \* | 是长度为3的一维数组，输出数据维度的顺序，取值为0、1、2的任意顺序组合，输入NULL，默认order为0、1、2。 | 输入 |
| comm | MPI\_Comm | 通信域。 | 输入 |
| options | 双精度：const kml\_fft\_mpi\_options 单精度： const kml\_fftf\_mpi\_options | 3DFFT分解算法、通信算法flag。 | 输入 |


#### 依赖

C: "kfft-mpi.h"


#### 示例

C interface：

```
const int n0 = 4, n1 = 4, n2 = 4;
kml_fft_plan plan;
int provided;
MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
MPI_Comm comm = MPI_COMM_WORLD;
double *in = NULL;
kml_fft_complex *out = NULL;
/* get local data size and allocate */
ptrdiff_t low[3] = {0};
ptrdiff_t high[3] = {0};
ptrdiff_t alloc_local = kml_fft_mpi_local_size_3d_ext(n0, n1, n2, comm, SCALFFT_DECOMPOSE_TYPE_PENCIL, low, high);
if (alloc_local == -1) {
printf("[%s][%d] allocate size fail.\n", __func__, __LINE__);
}
in = (double*)kml_fft_malloc(sizeof(double) * alloc_local * 2);
if (in == NULL) {
printf("[%s][%d] malloc memory fail.\n", __func__, __LINE__);
}
out = (kml_fft_complex *)kml_fft_malloc(sizeof(kml_fft_complex) * alloc_local);
if (out == NULL) {
printf("[%s][%d] malloc memory fail.\n", __func__, __LINE__);
}
/* create plan */
int low_int[3] = {low[0], low[1], low[2]};
int high_int[3] = {high[0], high[1], high[2]};
kml_fft_mpi_options options = {
.a2a_algo    = A2A_ALGO_AUTO_TUNING,
.decomp_type = SCALFFT_DECOMPOSE_TYPE_PENCIL
};
plan = kml_fft_mpi_plan_create_r2c(BACKEND_KFFT, low_int, high_int, NULL, low_int, high_int, NULL, comm, options);
/* execute plan */
int scale = 0;
kml_fft_mpi_execute_dft_r2c_ext(plan, in, out, scale);
// kml_fft_mpi_forward_r2c(plan, in, out, scale);
kml_fft_destroy_plan_ext(plan);
kml_fft_free(in);
kml_fft_free(out);
MPI_Finalize();
```
