小编Ofi*_*r N的帖子

在 MPI 中写入文本文件

我正在尝试使用 MPI 写入文本文件,但未创建该文件。我只需要在主人处写(等级 = 0),但没有任何效果。它仅在我在控制台中运行程序(并保存损坏的元素)而不是在 Mpich2 中运行并且我附加了代码时才起作用。谢谢你的帮助。

  /* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
 *  (C) 2001 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */

/* This is an interactive version of cpi */
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>


int main(int argc,char *argv[])
{

    int  namelen, numprocs, rank;
    char processor_name[MPI_MAX_PROCESSOR_NAME];
    MPI_Init(&argc,&argv);
    MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    MPI_Comm_size(MPI_COMM_WORLD,&numprocs);    
    MPI_Get_processor_name(processor_name,&namelen);
    MPI_Status status;
    FILE* f = fopen("test.txt","wb+");

    if (rank == 0) {
        for (int i=0; i < 5; i++){
            fprintf(f,"%d \n",i); …
Run Code Online (Sandbox Code Playgroud)

c parallel-processing mpi text-files

5
推荐指数
1
解决办法
4890
查看次数

标签 统计

c ×1

mpi ×1

parallel-processing ×1

text-files ×1