【问题标题】:read from file data and than search max value mpi从文件数据中读取,然后搜索最大值 mpi
【发布时间】:2014-07-19 21:43:25
【问题描述】:

我发现了这个关于使用 mpi 搜索最大值的示例。

http://inventorsworkshop.wikispaces.com/file/view/max.c

我的数据在这个文件中:

http://cti.ubm.ro/cpd/colocviu/2014/data.in

现在...问题是我如何调整程序以从我的文件中找到最大值?我需要编辑哪些代码部分?假设我可以将该文件保存在我的代码源附近。谢谢。

【问题讨论】:

    标签: arrays max mpi


    【解决方案1】:

    你需要改变这个位:

    if (rank == 0) {
    /* Initialize Array */
        printf("REM %d \n",rem);
        for(i=0;i<800;i++) {
            array[i] = i;
        }
    

    而不是for(i=0...,您需要按照以下方式做一些事情:

    FILE* myfile; 
    
    myfile = fopen("data.txt", "r"); 
    if ( myfile == NULL ) { 
        printf("Cannot open TEXT file\n");
        return 1; 
    }
    
    integer x;
    while (1 == fscanf(myfile, "%x", &i)) {
        printf("%d\n",x);
        array[i]=x;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-08
      • 2022-11-08
      • 2015-06-20
      • 1970-01-01
      • 2018-07-06
      • 1970-01-01
      • 2021-12-10
      相关资源
      最近更新 更多