---
title: 文件操作
description: "- 以聚合模式创建文件。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/userg_hyperio_0066.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/userg_hyperio_0066.html
indexId: 37d7f3ad40f2377651db2929907a6b6ab9bd46d5d0c76d82751c943e7814f19a58
---
# 文件操作

#### 函数定义

- 以聚合模式创建文件。
  int ncmpi_create(MPI_Comm comm, const char* name, int mode, MPI_Info info, int* idPoint);

- 读取文件。
  int ncmpi_open(MPI_Comm comm, const char* name, int mode, MPI_Info info, int* idPoint);

- 关闭文件。
  int ncmpi_close(int fileId);

- 退出定义模式。
  int ncmpi_enddef(int fileId);

- 进入独立数据模式。
  int ncmpi_begin_indep_data(int fileId);

- 退出独立数据模式。
  int ncmpi_end_indep_data(int fileId);

- 依据错误码打印错误信息。
  const char* ncmpi_strerror(int err);


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| fileId | 文件ID | 非负整数 | 输入 |
| \*name | 路径名称 | 非空，长度小于256字节 | 输入 |
| mode | 访问模式 | 非空 | 输入 |
| info | MPI信息 | 非空 | 输入 |
| \*idPoint | 返回文件ID的指针 | 非空 | 输出 |
| err | 错误码 | 整数 | 输入 |


#### 返回值

- 成功：返回NC_NOERR。
- 失败：返回错误码。


#### 错误码

| 错误码 | 描述 |
| --- | --- |
| NC\_EBADID | 无效fileId |
| NC\_EBAD\_FILE | 无效的文件名 |
| NC\_ENOMEM | 空指针或无效内存 |
