0

EDIT: So as mentioned in comments, my question was not accurate enough. My exact task is to "create an application that counts number of characters saved in .txt file using MPI - application should be synchronous".

I got to the point where I'm opening a file, and after that closing it. But have no idea what to do next. I think I should use MPI_File_read, but don't really know how to use it to count characters.

This is my code right now:

#include "stdafx.h"
#include "mpi.h"

using namespace std;

int _tmain(int argc, char *argv[])
{
    int rank;
    MPI_Status status;
    MPI_File fh;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    MPI_File_open(MPI_COMM_WORLD, "file.txt", MPI_MODE_RDONLY, MPI_INFO_NULL, &fh);


    MPI_File_close(&fh);
    MPI_Finalize();
    return 0;
}
RaSiN
  • 62
  • 8
  • 2
    You should read this: https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong and ditch `TCHAR` `count` is also out of scope when you attempt to print it in your second example. – Retired Ninja Jan 20 '18 at 23:48
  • @RetiredNinja Thank you very much for pointing that out. As I told I'm new to programming, and still learning, so I really do appreciate pointing out my mistakes – RaSiN Jan 20 '18 at 23:54
  • @RetiredNinja Can I ask you why TCHAR is bad? Because it's default part of main in Visual Studio, and I don't really know – RaSiN Jan 21 '18 at 00:00
  • Mostly because at this point there is no reason to switch between multi-byte and Unicode builds, they should all be Unicode. Being able to do multi-byte targeted builds was useful when win9x was still around. – SoronelHaetir Jan 21 '18 at 00:49
  • @SoronelHaetir So I replaced TCHAR with CHAR. Thank you :) – RaSiN Jan 21 '18 at 00:56
  • i doubt your code even compiles (e.g. `count` is not defined if `1 == rank`). Try to explain in plain English what you want to do with MPI, so you can get more valuable help. – Gilles Gouaillardet Jan 21 '18 at 02:03
  • @GillesGouaillardet Yes, it doesn't compile right now. My task is exactly "Create application that counts characters saved in .txt file using MPI - synchronous communication". This is what first code does, now I am trying to figure out how to do the same thing using (to be exact) MS MPI. – RaSiN Jan 21 '18 at 02:08
  • a student was asked to measure the height of the Eiffel tower with a barometer. He replied he would drop the barometer from the top, measure the time if takes to hear the sound of the crash, and then deduce the answer. – Gilles Gouaillardet Jan 21 '18 at 03:27
  • in your case, is the number of characters different from the file size ? if not, then you can do that optimally with a one-liner. if yes, then a common approach would be to divide the work among ranks. and that being said, collective operations would likely be a better fit here. – Gilles Gouaillardet Jan 21 '18 at 03:32
  • It is different from the file size. I tried to start over and after opening a file I'm pretty much stuck. I'm trying to read it after opening, but how to actually count characters in that case. Don't really know what to do with that – RaSiN Jan 21 '18 at 03:44

0 Answers0