Exemplo n.º 1
0
void mpi_manager_2D::do_MPISendRecv(NumMatrix<double,2> &buff,
                                    int Destination) {
	//! Do a send-receive operation, where the send-buffer is overwritten
	/*! Origin and destination is the same in this case
	 */
	// Get size of buffer:
	int size = ((buff.getHigh(1) - buff.getLow(1) + 1)*
	            (buff.getHigh(0) - buff.getLow(0) + 1));

	// MPI_Request request[1] = {MPI_REQUEST_NULL};
	// MPI_Request request;
	MPI_Status status;

	//	int tag = rank;
	int SendTag = rank;
	int RecvTag = Destination;
	// int SendTag = rank + Destination;
	// int RecvTag = Destination + rank;


	// Now do the communication:
	MPI_Sendrecv_replace((double *) buff, size, MPI_DOUBLE, Destination,
	                     SendTag, Destination, RecvTag,
	                     comm2d, &status);


	// MPI_Waitall(1, request);
	

}
Exemplo n.º 2
0
void mpi_manager_2D::do_MPISendRecv(NumMatrix<double,2> &buff,
                                    int Source, int Destination) {
	//! Do a send-receive operation, where the send-buffer is overwritten
	/*! Get data from somewhere and send own data somewhere else. The original
	  data will be overwritten
	 */
	// Get size of buffer:
	int size = ((buff.getHigh(1) - buff.getLow(1) + 1)*
	            (buff.getHigh(0) - buff.getLow(0) + 1));

	// MPI_Request request[1] = {MPI_REQUEST_NULL};
	// MPI_Request request;
	MPI_Status status;

	//	int tag = rank;
	int SendTag = rank;
	int RecvTag = Source;
	// int SendTag = rank + Destination;
	// int RecvTag = Destination + rank;


	// Now do the communication:
	MPI_Sendrecv_replace((double *) buff, size, MPI_DOUBLE, Destination,
	                     SendTag, Source, RecvTag,
	                     comm2d, &status);


	// MPI_Waitall(1, request);
	

}
Exemplo n.º 3
0
int main(){
    vector<vector<int> > matrix = {
        {3, 0, 1, 4, 2},
        {5, 6, 3, 2, 1},
        {1, 2, 0, 1, 5},
        {4, 1, 0, 1, 7},
        {1, 0, 3, 0, 5}
    };

    NumMatrix * m = new NumMatrix(matrix);
    cout<<m->sumRegion(2,1,4,3)<<endl;
    cout<<m->sumRegion(1,1,2,2)<<endl;
    cout<<m->sumRegion(1,2,2,4)<<endl;
    return 0;
}
Exemplo n.º 4
0
int main() {
#if 0
  vector<vector<int>> ma {
    {3, 0, 1, 4, 2},
    {5, 6, 3, 2, 1},
    {1, 2, 0, 1, 5},
    {4, 1, 0, 1, 7},
    {1, 0, 3, 0, 5}
  };

  NumMatrix obj {ma};
  cout << obj.sumRegion(2, 1, 4, 3) << endl;
  obj.update(3, 2, 2);
  cout << obj.sumRegion(2, 1, 4, 3) << endl;
  obj.update(2, 2, 2);
  cout << obj.sumRegion(2, 1, 4, 3) << endl;
  obj.update(4, 3, 2);
  cout << obj.sumRegion(2, 1, 4, 3) << endl;
#endif

#if 1
  vector<vector<int>> ma {
    {0,-5,9,1,-8,5,8,1,1,5},
  };

  NumMatrix obj {ma};
  cout << obj.sumRegion(0, 5, 0, 9) << endl;
  obj.update(0, 3, -1);
  cout << obj.sumRegion(0, 3, 0, 6) << endl;
  
  obj.update(0, 1, 6);
  obj.update(0, 9, 3);
  obj.update(0, 7, 2);
  cout << obj.sumRegion(0, 4, 0, 7) << endl;
  obj.update(0, 4, -5);
  cout << obj.sumRegion(0, 8, 0, 9) << endl;
  obj.update(0, 7, 8);
#endif

  return 0;
}