/*! Waits for any receive to completes and returns the associated rank. If there are no active recevies, the call returns MPI_UNDEFINED. \param if set to true \result The rank of the completed receive or MPI_UNDEFINED if there was no active receives. */ int DataCommunicator::waitAnyRecv() { // Wait for a receive to complete int id; MPI_Waitany(m_recvRequests.size(), m_recvRequests.data(), &id, MPI_STATUS_IGNORE); if (id == MPI_UNDEFINED) { return MPI_UNDEFINED; } // If the buffer is a double buffer, swap it RecvBuffer &recvBuffer = m_recvBuffers[id]; if (recvBuffer.isDouble()) { recvBuffer.swap(); } // Rank of the request int rank = m_recvRanks[id]; // Restart the recevie if (areRecvsContinuous()) { startRecv(rank); } // Return the rank associated to the completed receive return rank; }
int32_t measureTH(void){ uint8_t* pTH_Data; static uint32_t tempMeasureRslt[(MAX_TH_MEASURE_BIT_NUM + 2) >> 1]; if (sendStartTrigger() < 0){ return (-1); } if (waitTH_Response() < 0){ return (-1); } if (startRecv(tempMeasureRslt) < 0){ return (-1); } pTH_Data = handleTH_Data((uint16_t*)tempMeasureRslt); if (NULL == pTH_Data){ return (-1); }else{ IS_GLOBAL_PARA_ACCESSABLE; tSensoreData.unHumidity = (((uint16_t)(*pTH_Data)) << BIT_NUM_PER_BYTE) + *(pTH_Data + 1); if ((*(pTH_Data + 2) & 0x80) == 0x80){ tSensoreData.nTemperature = 1 - (int16_t)((((uint16_t)(*(pTH_Data + 2) & 0x7F)) << BIT_NUM_PER_BYTE) + *(pTH_Data + 3)); }else{ tSensoreData.nTemperature = (((uint16_t)(*(pTH_Data + 2) & 0x7F)) << BIT_NUM_PER_BYTE) + *(pTH_Data + 3); } RELEASE_GLOBAL_PARA_ACCESS; return 0; } }
void DepthBuilderP2PNoBlock::synchAction() { Status status; if (isRecvActive && recvRequest.Test(status)) { assert(0 <= requestedVertex && requestedVertex <= graph->numLocalVertex); //printf("%d: write depth [ %ld] to %d\n", rank, depth[requestedVertex], status.Get_source()); sendVertex(depth[requestedVertex], status.Get_source(), DEPTH_SEND_TAG); isRecvActive = false; } startRecv(); }
/*! Set recevie information for the specified rank \param rank is the rank of the processor associated to the receive \param length is the length, expressed in bytes, of the data to be received */ void DataCommunicator::setRecv(int rank, long length) { // Clear the recv associated to the rank clearRecv(rank); // Set recv info int id = m_recvIds.size(); m_recvIds[rank] = id; m_recvRanks.push_back(rank); m_recvRequests.push_back(MPI_REQUEST_NULL); m_recvBuffers.emplace_back(length); // If the receives are continous start the receive if (areRecvsContinuous()) { startRecv(rank); } }
/*! Waits for the receive associate to the sepcified rank to complete. \param rank is the rank associated to the receive to wait for \param */ void DataCommunicator::waitRecv(int rank) { // Wait for the receive to complete int id = m_recvIds.at(rank); auto request = m_recvRequests[id]; if (request == MPI_REQUEST_NULL) { return; } MPI_Wait(&m_recvRequests[id], MPI_STATUS_IGNORE); // If the buffer is a double buffer, swap it RecvBuffer &recvBuffer = m_recvBuffers[id]; if (recvBuffer.isDouble()) { recvBuffer.swap(); } // Restart the recevie if (areRecvsContinuous()) { startRecv(rank); } }
chatServer::chatServer(QWidget *parent) : QMainWindow(parent), ui(new Ui::chatServer) { ui->setupUi(this); numOfClients = 0; // connect gui to app connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(exitApp())); // create a mailbox for the server thread = new QThread(); const char *mid = "/mailbox0"; QString id = "Server"; server = new msgSendRecv(id, mid); connect(this, SIGNAL(started()), server, SLOT(startRecv())); connect(server, SIGNAL(messageRecv(QString)), this, SLOT(displayMsg(QString))); server->moveToThread(thread); thread->start(); // start reading the mailbox emit started(); }
/*! Starts receiving the data from all the ranks */ void DataCommunicator::startAllRecvs() { for (int rank : m_recvRanks) { startRecv(rank); } }
int main(int argc, char **argv) { unsigned int *data_samples; int i; int size; pd_device_t dev; void *memr, *mems; float throughput; struct timeval tv1,tv2; int mintime, curtime; printf("====================================\n"); printf("= DMA Throughput Test =\n"); printf("====================================\n\n"); if(argc != 2){ printf("Usage: %s [buffer size]\n",argv[0]); return -1; } size = atoi(argv[1]); if(size > 524288){ printf("Wohaa, easy there. Maximum buffer size is 262144\n"); return -1; } if(size % 4 != 0){ printf("Buffer size must be divisible by 4 bytes\n"); return -1; } printf("Buffer size: %d\n\n",size); if(pd_open(0,&dev) != 0){ printf("Failed to open file \n"); return -1; } printf("Device file opened successfuly\n"); // Allocate send and receive buffers posix_memalign( (void**)&memr, 16, size); posix_memalign( (void**)&mems, 16, size); //for(i=0;i<size/4;i++) // ((unsigned int*)mems)[i] = i; //for(i=0;i<size/4;i++) // ((unsigned int*)memr)[i] = 9; //-------------------------- if(initDMA(&dev) < 0) printf("Init DMA failed\n"); /* gettimeofday(&tv1,NULL); if(setupSend(&dev, (void*)mems, size) < 0) printf("Setup Send failed\n"); gettimeofday(&tv2,NULL); printf(">> Time taken to setup send transfer:%d\n", tv2.tv_usec - tv1.tv_usec); //-------------------------- gettimeofday(&tv1,NULL); if(setupRecv(&dev, memr, size) < 0) printf("Setup Recv failed\n"); gettimeofday(&tv2,NULL); printf(">> Time taken to setup receive transfer:%d\n", tv2.tv_usec - tv1.tv_usec); //-------------------------- gettimeofday(&tv1,NULL); if(startSend(&dev, 0) < 0) printf("DMA Send failed\n"); if(checkSend() < 0) printf("Check DMA send failed\n"); gettimeofday(&tv2,NULL); printf(">> Time taken to complete and check send transfer:%d\n", tv2.tv_usec - tv1.tv_usec); printf(">> Throughput: %f MB/s\n",(float)size/((float)(tv2.tv_usec - tv1.tv_usec))); //-------------------------- gettimeofday(&tv1,NULL); if(startRecv() < 0) printf("DMA Recv failed\n"); if(checkRecv() < 0) printf("Check DMA recv failed\n"); gettimeofday(&tv2,NULL); printf(">> Time taken to complete and check recv transfer:%d\n", tv2.tv_usec - tv1.tv_usec); printf(">> Throughput: %f MB/s\n",(float)size/((float)(tv2.tv_usec - tv1.tv_usec))); */ //-------------------------- // Send and receive in simultaneous mintime = 9999; for(i=0;i<NRUNS;i++){ gettimeofday(&tv1,NULL); if(setupSend(&dev, (void*)mems, size,1) < 0) printf("Setup Send failed\n"); if(setupRecv(&dev, (void*)memr, size) < 0) printf("Setup Recv failed\n"); gettimeofday(&tv2,NULL); printf("Time taken to setup receive AND send transfer:%d\n", tv2.tv_usec - tv1.tv_usec); //-------------------------- gettimeofday(&tv1,NULL); if(startRecv(&dev, 0) < 0) printf("DMA Recv failed\n"); if(startSend(&dev, 0) < 0) printf("DMA Send failed\n"); if(checkRecv() < 0) printf("Check DMA recv failed\n"); if(checkSend() < 0) printf("Check DMA send failed\n"); gettimeofday(&tv2,NULL); curtime = tv2.tv_usec - tv1.tv_usec; printf("Time taken to complete and check send AND receive transfer:%d\n", curtime); printf("Throughput: %f MB/s\n",(float)2*size/((float)(curtime))); freeSend(&dev); freeRecv(&dev); if(curtime < mintime) mintime = curtime; } stopDMA(&dev); //for(i=0;i<size/4;i++) // printf("%d ",((unsigned int*)memr)[i]); free(memr); free(mems); printf("Maximum throughput for %d points: %f MB/s\n",size,(float)2*size/((float)(mintime))); return 0; }
int main(int argc, char **argv) { unsigned int *data_samples; int i,val,j; int size, new_size; pd_device_t dev; void *memr, *mems, *mem_new; float throughput; struct timeval tv1,tv2; int mintime, curtime, vsize; printf("====================================\n"); printf("= Pattern Tests =\n"); printf("====================================\n\n"); if(pd_open(0,&dev) != 0){ printf("Failed to open file \n"); return -1; } printf("Device file opened successfuly\n"); // Allocate send and receive buffers size = 4*1024*1024; // 32x32 matrix with 4 byte entries posix_memalign( (void**)&memr, 16, size); posix_memalign( (void**)&mems, 16, size); //for(i=0;i < size/4; i++){ // ((int*)mems)[i] = i; // printf("%d ",((int*)mems)[i]); //} /* vsize = 1; for(i=1; i < 16; i++) { mintime = 99999; for(j=0; j < 500; j++) { gettimeofday(&tv1,NULL); compressData(mems, &mem_new, &new_size, 0, 4, 120, vsize); gettimeofday(&tv2,NULL); curtime = tv2.tv_usec - tv1.tv_usec; if (curtime < mintime) mintime = curtime; free(mem_new); } printf("Total Size: %d, Time elapsed: %d\n", new_size, mintime); vsize *= 2; } return; */ // Each 5x5 subblock will hold the same value val = 0; for(i=0; i < size/4; i++){ if (i % 16 == 0 && i!=0) val ++; val = val % 2; ((int *)mems)[i] = val; } // Test matrix for(i=0; i < size/4; i++){ if (i%32 == 0 && i!=0) printf("\n"); printf("%d ", ((int*)mems)[i]); } //-------------------------- if(initDMA(&dev) < 0) printf("Init DMA failed\n"); // Send and receive in simultaneous gettimeofday(&tv1,NULL); #ifdef SEND if(setupSend(&dev, (void*)mems, size,1) < 0) printf("Setup Send failed\n"); if(applyBlocking_send(16, 32, 4) < 0) printf("Apply Blocking send failed\n"); #endif if(setupRecv(&dev, (void*)memr, size) < 0) printf("Setup Recv failed\n"); //int applyLinear_recv(int offset, int hsize, int stride, int total_size); // if(applyBlocking_recv(16, 32, 4) < 0) if(applyLinear_recv(0,128,128,4096) < 0) printf("Apply Blocking recv failed\n"); gettimeofday(&tv2,NULL); printf("Time taken to setup receive AND send transfer:%d\n", tv2.tv_usec - tv1.tv_usec); //-------------------------- gettimeofday(&tv1,NULL); #ifdef SEND //if(startSend(&dev, 0) < 0) // printf("DMA Send failed\n"); #endif // printf("Press any key to continue ;)\n"); // getchar(); if(startRecv(&dev, 0) < 0) printf("DMA Recv failed\n"); if(startSend(&dev, 0) < 0) printf("DMA Send failed\n"); if(checkRecv() < 0) printf("Check DMA recv failed\n"); #ifdef SEND if(checkSend() < 0) printf("Check DMA send failed\n"); #endif gettimeofday(&tv2,NULL); curtime = tv2.tv_usec - tv1.tv_usec; printf("Time taken to complete and check send AND receive transfer:%d\n", curtime); printf("Throughput: %f MB/s\n",(float)2*size/((float)(curtime))); // Test matrix for(i=0; i < size/4; i++){ if (i%32 == 0 && i!=0) printf("\n"); printf("%d ", ((int*)memr)[i]); } freeSend(&dev); freeRecv(&dev); stopDMA(&dev); //for(i=0;i<size/4;i++) // printf("%d ",((unsigned int*)memr)[i]); free(memr); free(mems); return 0; }