Exemplo n.º 1
0
void communicateHfieldEW(int n){

	// since EW, no normal component ie Hx
	int i,j,k,index;
	MPI_Request recvRequestE, recvRequestW;	// The E/W alwayes points to the neighbour, be careful with the tags	

	MPI_Status recvStatusE, recvStatusW;

	double *sendBufferW, *sendBufferE, *recvBufferW, *recvBufferE;

	sendBufferE = sendBuffer1;
	sendBufferW = sendBuffer2;

	recvBufferE = recvBuffer1;
	recvBufferW = recvBuffer2;
	//printf("Processor %d nebW %d, nebE %d, nebN %d, nebS %d, nebT %d, nebB %d\n",sid, nebW, nebE, nebN, nebS, nebT, nebB);
	// async recv
	if (nebW != -1)		
		MPI_Irecv( recvBufferW, copyCountEW , MPI_DOUBLE, nebW,10, grid_comm, &recvRequestW );
	if (nebE != -1)		
		MPI_Irecv( recvBufferE, copyCountEW , MPI_DOUBLE, nebE,20, grid_comm, &recvRequestE );

		//send
	
	if (nebW != -1){		
		createSendBuffer(1, 1, 1, yLen, 1, zLen, sendBufferW, HYOFT,HZOFT);
		MPI_Send( sendBufferW, copyCountEW, MPI_DOUBLE, nebW, 20, grid_comm);
	}

	if (nebE != -1){		
		createSendBuffer(xLen, xLen, 1, yLen, 1, zLen, sendBufferE, HYOFT,HZOFT);
		MPI_Send( sendBufferE, copyCountEW, MPI_DOUBLE, nebE, 10, grid_comm);
	}
	
	if (nebW != -1){
		MPI_Wait(&recvRequestW,&recvStatusW);
		readRecvBuffer(0, 0, 1, yLen, 1, zLen, recvBufferW, HYOFT, HZOFT);
	}
		
	if (nebE != -1){
		MPI_Wait(&recvRequestE,&recvStatusE);
		readRecvBuffer(xLen+1, xLen+1, 1, yLen, 1, zLen, recvBufferE, HYOFT, HZOFT);
	}		
}
Exemplo n.º 2
0
void communicateEfieldTB(int n){

	// since TB, no normal component ie Ez
	int i,j,k,index;
	MPI_Request recvRequestB, recvRequestT;	// The E/W alwayes points to the neighbour, be careful with the tags	

	MPI_Status recvStatusB, recvStatusT;

	double *sendBufferB, *sendBufferT, *recvBufferB, *recvBufferT;

	sendBufferB = sendBuffer1;
	sendBufferT = sendBuffer2;

	recvBufferB = recvBuffer1;
	recvBufferT = recvBuffer2;

	// async recv
	if (nebB != -1)		
		MPI_Irecv( recvBufferB, copyCountTB , MPI_DOUBLE, nebB,10, grid_comm, &recvRequestB );
	if (nebT != -1)		
		MPI_Irecv( recvBufferT, copyCountTB , MPI_DOUBLE, nebT,20, grid_comm, &recvRequestT );

	//send
	
	if (nebB != -1){		
		createSendBuffer(1, xLen, 1, yLen, 1, 1, sendBufferB, EXOFT,EYOFT);
		MPI_Send( sendBufferB, copyCountTB, MPI_DOUBLE, nebB, 20, grid_comm);
	}

	if (nebT != -1){		
		createSendBuffer(1, xLen, 1, yLen, zLen, zLen, sendBufferT, EXOFT,EYOFT);
		MPI_Send( sendBufferT, copyCountTB, MPI_DOUBLE, nebT, 10, grid_comm);
	}
	// fill buffer	
	if (nebB != -1){
		MPI_Wait(&recvRequestB,&recvStatusB);
		readRecvBuffer(1, xLen, 1, yLen, 0, 0, recvBufferB, EXOFT, EYOFT);
	}
		
	if (nebT != -1){
		MPI_Wait(&recvRequestT,&recvStatusT);
		readRecvBuffer(1, xLen, 1, yLen, zLen+1, zLen+1, recvBufferT, EXOFT, EYOFT);
	}		
} // end communicateEfieldTB
Exemplo n.º 3
0
void communicateEfieldNS(int n){

	// since NS, no normal component ie Ey
	int i,j,k,index;
	MPI_Request recvRequestS, recvRequestN;	// The E/W alwayes points to the neighbour, be careful with the tags	

	MPI_Status recvStatusS, recvStatusN;

	double *sendBufferS, *sendBufferN, *recvBufferS, *recvBufferN;

	sendBufferS = sendBuffer1;
	sendBufferN = sendBuffer2;

	recvBufferS = recvBuffer1;
	recvBufferN = recvBuffer2;

	// async recv
	if (nebS != -1)		
		MPI_Irecv( recvBufferS, copyCountNS , MPI_DOUBLE, nebS,10, grid_comm, &recvRequestS );
	if (nebN != -1)		
		MPI_Irecv( recvBufferN, copyCountNS , MPI_DOUBLE, nebN,20, grid_comm, &recvRequestN );

		//send
	
	if (nebS != -1){		
		createSendBuffer(1, xLen, 1, 1, 1, zLen, sendBufferS, EXOFT,EZOFT);
		MPI_Send( sendBufferS, copyCountNS, MPI_DOUBLE, nebS, 20, grid_comm);
	}

	if (nebN != -1){		
		createSendBuffer(1, xLen, yLen, yLen, 1, zLen, sendBufferN, EXOFT,EZOFT);
		MPI_Send( sendBufferN, copyCountNS, MPI_DOUBLE, nebN, 10, grid_comm);
	}
	
	if (nebS != -1){
		MPI_Wait(&recvRequestS,&recvStatusS);
		readRecvBuffer(1, xLen, 0, 0, 1, zLen, recvBufferS, EXOFT, EZOFT);
	}
		
	if (nebN != -1){
		MPI_Wait(&recvRequestN,&recvStatusN);
		readRecvBuffer(1, xLen, yLen+1, yLen+1, 1, zLen, recvBufferN, EXOFT, EZOFT);
	}		
}// end communicateEfieldNS
Exemplo n.º 4
0
/*!
* This method transmits binary data over an open TCP or UDP connection.
* @param data The data to transmit.
* @param waitForResponse Expect/wait for a reply from the server, default = true.
* @return `true` if the data was successfully transmitted,
* otherwise `false`.
*/
bool Sodaq_WifiBee::transmitBinaryData(const uint8_t* data, const size_t length, const bool waitForResponse)
{
  createSendBuffer();
  sendEscapedBinary(data, length);
  transmitSendBuffer();

  bool result;
  result = skipTillPrompt(SENT_PROMPT, RESPONSE_TIMEOUT);

  if (result && waitForResponse) {
    if (skipTillPrompt(RECEIVED_PROMPT, SERVER_RESPONSE_TIMEOUT)) {
      readServerResponse();
    }
    else {
      clearBuffer();
    }
  }

  return result;
}
Exemplo n.º 5
0
/*!
* This method transmits ASCII data over an open TCP or UDP connection.
* @param data The data to transmit.
* @param waitForResponse Expect/wait for a reply from the server, default = true.
* @return `true` if the data was successfully transmitted,
* otherwise `false`.
*/
bool Sodaq_WifiBee::transmitAsciiData(const char* data, const bool waitForResponse)
{
  createSendBuffer();
  sendEscapedAscii(data);
  transmitSendBuffer();

  bool result;
  result = skipTillPrompt(SENT_PROMPT, RESPONSE_TIMEOUT);

  if (result && waitForResponse) {
    if (skipTillPrompt(RECEIVED_PROMPT, SERVER_RESPONSE_TIMEOUT)) {
      readServerResponse();
    }
    else {
      clearBuffer();
    }
  }

  return result;
}
Exemplo n.º 6
0
/*!
* This method constructs and sends a generic HTTP request.
* @param server The server/host to connect to (IP address or domain).
* @param port The port to connect to.
* @param The HTTP method to use. e.g. "GET", "POST" etc.
* @param location The resource location on the server/host.
* @param headers Any additional headers, each must be followed by a CRLF.
* HOST & Content-Length headers are added automatically.
* @param body The body (can be blank) to send with the request. Must not start with a CRLF.
* @param httpCode The HTTP response code is written to this parameter (if a response is received).
* @return `true` if a connection is established and the data is sent, `false` otherwise.
*/
bool Sodaq_WifiBee::HTTPAction(const char* server, const uint16_t port,
  const char* method, const char* location, const char* headers,
  const char* body, uint16_t& httpCode)
{
  bool result;

  // Open the connection
  result = openConnection(server, port, "net.TCP");

  if (result) {
    createSendBuffer();

    sendAscii(method);
    sendAscii(" ");
    sendAscii(location);
    sendAscii(" HTTP/1.1\\r\\n");

    sendAscii("HOST: ");
    sendAscii(server);
    sendAscii(":");

    char buff[11];
    itoa(port, buff, 10);
    sendAscii(buff);
    sendAscii("\\r\\n");

    if (strcmp(method, "GET") != 0) {
      sendAscii("Content-Length: ");
      itoa(strlen(body), buff, 10);
      sendAscii(buff);
      sendAscii("\\r\\n");
    }

    sendEscapedAscii(headers);
    sendAscii("\\r\\n");

    sendEscapedAscii(body);

    transmitSendBuffer();

    // Wait till we hear that it was sent
    result = skipTillPrompt(SENT_PROMPT, RESPONSE_TIMEOUT);

    // Wait till we get the data received prompt
    if (result) {
      if (skipTillPrompt(RECEIVED_PROMPT, SERVER_RESPONSE_TIMEOUT)) {
        while (skipTillPrompt(RECEIVED_PROMPT, NEXT_PACKET_TIMEOUT)) {
        }

        readServerResponse();
        parseHTTPResponse(httpCode);
      }
      else {
        clearBuffer();
      }
    }

    // The connection might have closed automatically
    closeConnection();
  }

  return result;
}