Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F122018940
Test.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Jul 15, 08:35
Size
3 KB
Mime Type
text/x-c
Expires
Thu, Jul 17, 08:35 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
27424634
Attached To
rTSUNAMIPROJECT PHPC-TSUNAMI-PROJECT
Test.cpp
View Options
//
// Created by Arnaud Pannatier on 11.05.18.
//
#include <iostream>
#include "grid.h"
#include "reader.h"
#include <mpi.h>
#include <sstream>
int main(int argc, char *argv[]){
// initialize MPI
MPI_Init(&argc, &argv);
int prank, psize;
// Usefull to debug
MPI_Comm_rank(MPI_COMM_WORLD, &prank);
MPI_Comm_size(MPI_COMM_WORLD, &psize);
printf("I’m process %d out of %d\n", prank+1, psize);
int size = 25;
// computation of the local size of the grid the remainder is spread equally
// on the first processors
int local_x = size / psize + (prank < size % psize ? 1 : 0);
int local_y = size;
// adding the ghosts lines if needed
if (psize > 1)
local_x += (prank == 0 || prank == psize - 1) ? 1 : 2;
// computing the offsets of the local grid in the global one
int offset_x = (size / psize) * prank + (prank < size % psize ? prank : size % psize);
int offset_y = 0;
// resizing the different grids
int x_start = (prank == 0 ? 0 : 1);
int x_end = (prank == psize - 1 ? local_x : local_x - 1);
int write_x = local_x;
int write_y = local_y;
// removing the ghosts lines if needed
if (psize > 1)
write_x -= (prank == 0 || prank == psize - 1) ? 1 : 2;
//std::cout << " Start : " << (offset_y ) + local_y* (offset_x - x_start) << std::endl;
// Grid A(local_x,local_y);
// for(std::size_t x(0);x<local_x;x++) {
// for (std::size_t y (0); y < local_y; y++) {
// double store = (offset_y + y)+ local_y* (offset_x + x - x_start);
// //std::cout << store << " " << std::endl;
// A(x,y) = store;
// }
// }
//std::vector<double> woGhost = A.RemoveGhostCellsAndPrepareToWrite(psize,prank,local_x, local_y);
//std::vector<double> toPrint = Reader::PrepareVectorForColumnMajor(woGhost, write_x, write_y);
// if(prank ==0){
// for(int x(0); x < local_x;x++){
// for(int y(0); y<local_y;y++){
// //std::cout << A(x,y) << " - - " << &A(x,y) << " - ";
// }
// }
// }
// std::cout << "YOOO : " << toPrint[1] << std::endl;
//Reader::ParallelwriteGridInColumnMajorFile (&toPrint[0],"ParallelWriting2.bin", write_x,write_y,offset_x, MPI_COMM_WORLD);
//Reader::ParallelwriteGridInColumnMajorFile (&toPrint[0],"ParallelWriting5.bin", write_x,write_y,offset_x, MPI_COMM_WORLD);
//Reader::writeGridInFile (A,"ParallelWriting5.bin",write_x,write_y);
//std::cout << A << std::endl;
Grid A = Reader::ParallelReadFromColumnMajorFile ("ParallelWriting4.bin", write_x, write_y, offset_x, MPI_COMM_WORLD);
//
// std::cout << "Process : " << prank+1 << " - Start : " << A(0,0) << " - End : " << A(write_x-1, write_y-1) << std::endl;
// std::stringstream Values;
// Values << "Process : " << prank+1 <<" Values : ";
// for(std::size_t x(0);x<write_x;x++) {
// for (std::size_t y (0); y < write_y; y++) {
// Values << A(x,y) << " - ";
// }
// }
// Values << std::endl;
// std::cout << Values.str() << std::endl;
// std::cout<< "Read x :" << write_x << std::endl;
// std::cout << "Offset x : " << offset_x << std::endl;
// Grid A = Reader::ParallelReadFromColumnMajorFile("ParallelWriting.bin", write_x, write_y, offset_x, MPI_COMM_WORLD);
//
if(prank ==1) {
std::cout << A << std::endl;
}
// Close MPI
MPI_Finalize();
//Grid B = Reader::readGridFromFile ("ParallelWriting5.bin", 25,25);
//if(prank ==0)
//std::cout << B << std::endl;
return 0;
}
Event Timeline
Log In to Comment