Since my school's server can only be accessed with my school IP, sorry for no screenshots. I'll explain detailed.
Below is main file(Not important).
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
/** distributing numbers to each node(e.g. distributing 1~100 numbers to 7 nodes: node 1 get 1, 8, 15, 22, ... node 2 get 2, 9, ...) **/
qu = new mpi_que[size];
for (int i = 1; i <= size; i++) {
qu[i-1].setId(i);
qu[i-1].allocate(repeat_number, size - 1);
}
if (myid == MASTER_ID) // 0
Master();
else
Slave();
MPI_Finalize();
and this is Slave function.
void Slave() {
//printf("I am Slave %d out of %d\n", myid, size - 1);
Sand s(w, h);
while (!qu[myid - 1].isFinished()) {
int id_now = qu[myid - 1].current_id();
int seed = time(NULL) + id_now;
/** Do some Jobs**/
string filename = "./data/avalanche" + ToString(w) + "x" + ToString(h) + "_drop" + ToString(count) + "_id" + ToString(id_now) + ".binary";
writemod(aftershock, aftershock_length, filename);
qu[myid - 1].finishOneJob();
}
}
qu is global pointer which I made. I don't think error occurs here. what qu does is changing id_now's value every loop, and so filename changes each loop.
Below is writemod function.
#define WRITE_VAR(_stream, v) (_stream.write( (char *)(&(v)), sizeof(v) ))
void writemod(afterBig a[], int len, string path) {
ofstream outFile((path).c_str(), ios::binary);
WRITE_VAR(outFile, len);
for (int i = 0; i < len; i++) {
WRITE_VAR(outFile, a[i].big_size);
WRITE_VAR(outFile, a[i].after_size);
}
outFile.close();
}
Anyway, what happens when I run this file is that
if I run this file, all output file data seems to go to [jobname].o[jobid] file(default output text file). It's 8.7Gb so I can't even open it with emacs to see what have happened.