void ProxyPatch::boxClosed(int box) { if (box == 1) { // force Box // Note: delay the deletion of proxyDataMsg (of the // current step) until the next step. This is done // for the sake of atom migration (ProxyDataMsg) // as the ProxyPatch has to unregister the atoms // of the previous step in the AtomMap data structure // also denotes end of gbis phase 3 sendResults(); } else if ( box == 5) {//end phase 1 } else if ( box == 8) {//end phase 2 } else if (box == 9) { //nothing } else if (box == 10) { // LCPO do nothing } if ( ! --boxesOpen ) { DebugM(2,patchID << ": " << "Checking message buffer.\n"); if(proxyMsgBufferStatus == PROXYALLMSGBUFFERED) { CmiAssert(curProxyMsg != NULL); DebugM(3,"Patch " << patchID << " processing buffered proxy ALL data.\n"); receiveAll(curProxyMsg); }else if(proxyMsgBufferStatus == PROXYDATAMSGBUFFERED) { CmiAssert(curProxyMsg != NULL); DebugM(3,"Patch " << patchID << " processing buffered proxy data.\n"); receiveData(curProxyMsg); } } else { DebugM(3,"ProxyPatch " << patchID << ": " << boxesOpen << " boxes left to close.\n"); } }
void ProxyPatch::boxClosed(int box) { ProxyGBISP1ResultMsg *msg1; ProxyGBISP2ResultMsg *msg2; if (box == 1) { // force Box // Note: delay the deletion of proxyDataMsg (of the // current step) until the next step. This is done // for the sake of atom migration (ProxyDataMsg) // as the ProxyPatch has to unregister the atoms // of the previous step in the AtomMap data structure // also denotes end of gbis phase 3 sendResults(); } else if (box == 5) { //end phase 1 //this msg should only have nonzero atoms if flags.doNonbonded int msgAtoms = (flags.doNonbonded) ? numAtoms : 0; msg1 = new (msgAtoms, PRIORITY_SIZE) ProxyGBISP1ResultMsg; for (int i = 0; i < msgAtoms; i++) { msg1->psiSum[i] = psiSum[i]; } msg1->patch = patchID; msg1->psiSumLen = msgAtoms; msg1->origPe = CkMyPe(); SET_PRIORITY(msg1, flags.sequence, GB1_PROXY_RESULTS_PRIORITY + PATCH_PRIORITY(patchID)); ProxyMgr::Object()->sendResult(msg1); } else if (box == 8) { //end phase 2 //this msg should only have nonzero atoms if flags.doFullElectrostatics int msgAtoms = (flags.doFullElectrostatics) ? numAtoms : 0; msg2 = new (msgAtoms, PRIORITY_SIZE) ProxyGBISP2ResultMsg; for (int i = 0; i < msgAtoms; i++) { msg2->dEdaSum[i] = dEdaSum[i]; } msg2->patch = patchID; msg2->dEdaSumLen = msgAtoms; msg2->origPe = CkMyPe(); SET_PRIORITY(msg2, flags.sequence, GB2_PROXY_RESULTS_PRIORITY + PATCH_PRIORITY(patchID)); ProxyMgr::Object()->sendResult(msg2); } else if (box == 9) { //nothing } else if (box == 10) { // LCPO do nothing } if (!--boxesOpen) { DebugM(2, patchID << ": " << "Checking message buffer.\n"); if (proxyMsgBufferStatus == PROXYALLMSGBUFFERED) { CmiAssert(curProxyMsg != NULL); DebugM(3, "Patch " << patchID << " processing buffered proxy ALL data.\n"); receiveAll(curProxyMsg); } else if (proxyMsgBufferStatus == PROXYDATAMSGBUFFERED) { CmiAssert(curProxyMsg != NULL); DebugM(3, "Patch " << patchID << " processing buffered proxy data.\n"); receiveData(curProxyMsg); } } else { DebugM(3, "ProxyPatch " << patchID << ": " << boxesOpen << " boxes left to close.\n"); } }
void MainWindow::finish() { switch (QMessageBox::information(this, tr("Finish the exam"), tr("Are you sure you want to finish? Once you click Finish there is no going back."), tr("&Finish"), tr("&Cancel"), 0, 1)) { case 0: // Finish break; case 1: // Cancel return; break; } mainStackedWidget->setCurrentIndex(3); if (current_test_results_sent) { return; } current_test_results_sent = true; current_test_time_finished = QDateTime::currentDateTime().toString("yyyy.MM.dd-hh:mm"); sendResults(); if (rbtnFromFile->isChecked()) { loadResults(resultsTableWidget); } }
void CommunObject::decrypt(const QString &key, const QString &info) { qDebug() << "Key: " << key; qDebug() << "info: " << info; try { CryptoWrapper crypto(key, info); QString results; crypto.decrypt(results); emit sendResults(results); emit sendStatus("completed the Decryption operations"); qDebug() << "Results: " << results; } catch (...) { const QString message = "Error occurred while Decrypting"; emit sendStatus(message); qWarning() << message; } }
void MainWindow::updateTime() { if (current_test_time_remaining > 1) { timer.start(60000); current_test_time_remaining--; remainingTimeLcdNumber->display(current_test_time_remaining); remainingTimeProgressBar->setValue(current_test_time_remaining); } else { if (mainStackedWidget->currentIndex() != 2) { return; } if (current_test_results_sent) { return; } current_test_results_sent = true; current_test_time_finished = QDateTime::currentDateTime().toString("yyyy.MM.dd-hh:mm"); mainStackedWidget->setCurrentIndex(3); sendResults(); if (rbtnFromFile->isChecked()) { loadResults(resultsTableWidget); } QMessageBox::information(this, tr("Exam finished"), tr("You have run out of time. Your answers are being sent.")); } }
void GPControlView::gpControl_end(QString results) { FinnishDialog *msg = new FinnishDialog(this); msg->setResults(results); char *pseudo = getenv("USER"); if (pseudo != NULL) { msg->setPseudo(QString(pseudo)); } msg->setWindowTitle(tr("Finnish!")); msg->setModal(true); if (msg->exec() == QDialog::Accepted) { sendResults(msg->getPseudo()); } delete msg; on_abortbutton_clicked(); }
void DatabaseQuery::finishQuery() { // removeConnection(); // emit queryStatus(DatabaseQuery::Finished, m_currentIndex); qDebug() << "finishedQuery"; int count = m_results.count(); if (count > 0) { switch(runType()) { case Join: runJoin(); break; case Insert: case Query: qDebug() << "Query"; sendResults(); break; default: break; } } else { finish(); } }
int main(int argc, char**argv) { int sfd,ssfd; char num[10]; char clientID[22]; char filename[100]; int result; int taskSize; int exitCode; int numBytes; char *msg; char *taskID; char ACK[]="OK\n"; char lifetime[]="10\n"; Task *task; char *back; if (argc!=5) { fprintf(stdout,"usage: client <IP> <port> <port> <debug>"); exit(1); } if (strcmp(argv[4],"-debug")==0) flag=1; recover: if(flag == 1) fprintf(stdout,"con_server() to %s on port %s\n", argv[1], argv[2]); sfd=con_server(atoi(argv[2]), argv[1]); set_sockopt(sfd); if(flag == 1) fprintf(stdout,"con_server() to %s on port %s\n", argv[1], argv[3]); ssfd=con_server(atoi(argv[3]), argv[1]); if (flag==1) fprintf(stdout,"connection established!\n"); /*numBytes=send(sfd, lifetime, sizeof(lifetime), 0); if (numBytes<0) { fprintf(stdout, "main: send lifetime error\n"); fprintf(stdout,"main: error description: EOF\n"); recovery(sfd, ssfd); goto recover; }*/ while (1) { task = (Task *)malloc(sizeof(Task)); if (task==NULL) printf("failed to allocate memory in main loop\n"); memset(filename,'\0',sizeof(filename)); memset(clientID,'\0',sizeof(clientID)); memset(num, '\0', sizeof(num)); /*receive clientID*/ recv_wrapper(sfd, ssfd, clientID, 22); if (flag==1) { fprintf(stdout,"main: clientID: %s\n", clientID); } /*receive size of task*/ recv_wrapper(sfd, ssfd, num, 10); if (flag==1) { fprintf(stdout,"main: size_of_task: %s\n", num); } /*allocate memory for task description*/ taskSize=atoi(num); msg=malloc(sizeof(char)*(taskSize+1)); if (msg==NULL) { fprintf(stdout,"main: allocate memory failed\n"); exit (1); } memset(msg,'\0',taskSize+1); /*receive task description*/ recv_wrapper(sfd, ssfd, msg, taskSize); if (flag==1) { fprintf(stdout,"main:received: %s\n", msg); } /*send acknoledgement for the received task*/ numBytes=send(sfd, ACK,strlen(ACK),0); if (numBytes < 0) { fprintf(stdout,"main: Sent ACK %s failed\n", ACK); fprintf(stdout,"main: error description: EOF\n"); recovery(sfd, ssfd); goto recover; } else { if (flag == 1) fprintf(stdout,"main: Sent ACK %s successful (%d)\n", ACK, numBytes); } parseExec(msg, task); exitCode = run_task(task); /*send results back to Falkon service*/ numBytes = sendResults(task, ssfd, sfd); if (numBytes < 0) { fprintf(stdout,"main: Send results failed\n"); recovery(sfd, ssfd); goto recover; } //free(task->taskID); //free(task->command); //free(task->directory); free(task); free(msg); //exit(1); } }
int main(int argc, char**argv) { int sfd,ssfd; if (argc!=5) { fprintf(stdout,"usage: client <IP> <port> <port> <debug>"); exit(1); } if (strcmp(argv[4],"-debug")==0) flag=1; //commented out to hopefully make it work with static compiling /* char hostname[100]; struct hostent *h; gethostname(hostname, 100); fprintf(stdout,"hostname: %s\n", hostname); if ((h = gethostbyname(hostname))!=NULL) { fprintf(stdout,"ip address: %s\n", inet_ntoa(*((struct in_addr *)h->h_addr))); } */ recover: fprintf(stdout,"con_server() to %s on port %s\n", argv[1], argv[2]); sfd=con_server(atoi(argv[2]), argv[1]); set_sockopt(sfd); fprintf(stdout,"con_server() to %s on port %s\n", argv[1], argv[3]); ssfd=con_server(atoi(argv[3]), argv[1]); if (flag==1) fprintf(stdout,"connection established!\n"); char num[10]; char clientID[22]; char filename[100]; int result; char *msg; char *taskID; char lifetime[]="10\n"; pid_t pid; int n; /*n=send(sfd, lifetime, sizeof(lifetime), 0); if (n<0) { fprintf(stdout, "main: send lifetime error\n"); fprintf(stdout,"main: error description: EOF\n"); recovery(sfd, ssfd); goto recover; } char acknoledge[10]; memset(acknoledge, '\0', 10); read(sfd,acknoledge,sizeof(acknoledge)); printf("acknoledge: %s\n", acknoledge); fflush(stdout);*/ while (1) { memset(filename,'\0',sizeof(filename)); memset(clientID,'\0',sizeof(clientID)); memset(num, '\0', sizeof(num)); if (flag==1) { fprintf(stdout,"main: receiving from server\n"); fprintf(stdout,"main: sizeof clientID: %d\n", sizeof(clientID)); } int numBytes=0; int numBytesAll = 0; if (flag==1) { fprintf(stdout,"main:waiting to received %d bytes...\n", sizeof(clientID)); } while (numBytesAll < sizeof(clientID)) { numBytes = read(sfd,clientID,sizeof(clientID)); if (numBytes<0) { fprintf(stdout,"main: Receive clientID error after %d bytes received, when it was expecting %d...\n", numBytesAll, sizeof(clientID)); fprintf(stdout,"main: error description: %d\n", errno); recovery(sfd, ssfd); goto recover; } else if (numBytes==0) { fprintf(stdout,"main: Receive clientID error after %d bytes received, when it was expecting %d...\n", numBytesAll, sizeof(clientID)); fprintf(stdout,"main: error description: EOF\n"); recovery(sfd, ssfd); goto recover; } else { if (flag == 1) fprintf(stdout,"main: Received %d bytes...\n", numBytes); } numBytesAll += numBytes; if (numBytesAll == 3) { if (strncasecmp(clientID, "end", 3)==0) { fprintf(stdout, "main: receive end notice, exit\n"); //should shut down gracefully... closing all sockets... //exit(0); goto recover; } } } if (flag==1) { fprintf(stdout,"main:just received %d bytes...\n", numBytesAll); } fflush(stdout); if (flag==1) { fprintf(stdout,"main: clientID: %s\n", clientID); } numBytesAll = 0; if (flag==1) { fprintf(stdout,"main:waiting to received %d bytes...\n", sizeof(num)); } while (numBytesAll < sizeof(num)) { numBytes = read(sfd,num,sizeof(num)); if (numBytes<0) { fprintf(stdout,"main: Receive task size error after %d bytes received, when it was expecting %d...\n", numBytesAll, sizeof(num)); fprintf(stdout,"main: error description: %d\n", errno); recovery(sfd, ssfd); goto recover; } else if (numBytes==0) { fprintf(stdout,"main: Receive task size error after %d bytes received, when it was expecting %d...\n", numBytesAll, sizeof(clientID)); fprintf(stdout,"main: error description: EOF\n"); recovery(sfd, ssfd); goto recover; } else { if (flag == 1) fprintf(stdout,"main: Received %d bytes...\n", numBytes); } numBytesAll += numBytes; } if (flag==1) { fprintf(stdout,"main:just received %d bytes...\n", numBytesAll); } int taskSize=atoi(num); msg=malloc(sizeof(char)*(taskSize+1)); memset(msg,'\0',sizeof(msg)); if (msg==NULL) { fprintf(stdout,"main: allocate memory failed\n"); exit (1); } if (flag==1) { fprintf(stdout,"main:waiting to receive task description of %d bytes...\n", taskSize); //fprintf(fp,"main:received: %s\n", msg); } char buffer[10240]; numBytesAll = 0; while (numBytesAll < taskSize) { memset(buffer, 0, 10240); numBytes = read(sfd,buffer,taskSize); strcat(msg, buffer); if (numBytes<0) { fprintf(stdout,"main: Receive task failed after %d bytes received, when it was expecting %d...\n", numBytesAll, taskSize); fprintf(stdout,"main: error description: %d\n", errno); recovery(sfd, ssfd); goto recover; } else if (numBytes==0) { fprintf(stdout,"main: Receive task failed after %d bytes received, when it was expecting %d...\n", numBytesAll, sizeof(clientID)); fprintf(stdout,"main: error description: EOF\n"); recovery(sfd, ssfd); goto recover; } else { if (flag == 1) fprintf(stdout,"main: Received %d bytes...\n", numBytes); } numBytesAll += numBytes; } if (flag==1) { fprintf(stdout,"main:jst received %d bytes...\n", numBytesAll); } if (flag==1) { fprintf(stdout,"main:received: %s\n", msg); } //commented out ACK numBytes=send(sfd, ACK,strlen(ACK),0); if (numBytes < 0) { fprintf(stdout,"main: Sent ACK %s failed\n", ACK); fprintf(stdout,"main: error description: EOF\n"); recovery(sfd, ssfd); goto recover; } else { if (flag == 1) fprintf(stdout,"main: Sent ACK %s successful (%d)\n", ACK, numBytes); } fflush(stdout); taskID = getTaskID(msg); int exitCode; exitCode = parseExec(msg); free(msg); numBytes = sendResults(taskID, exitCode, argv, ssfd, sfd); if (numBytes < 0) { fprintf(stdout,"main: Send results failed\n"); //fprintf(stdout,"main: error description: EOF\n"); recovery(sfd, ssfd); goto recover; } } }
/** Run the OpenCL kernel */ short runOpenCL(struct benchmark *bench) { short j; #ifdef DEBUG printf("TEST OPENCL\n"); #endif /********************** Initializations **********************/ error=clGetPlatformIDs(1,&platform,NULL); if (error != CL_SUCCESS) { fprintf(stderr,"Error to get platform ID : %d\n",error); goto error; } error=clGetDeviceIDs(platform,CL_DEVICE_TYPE_GPU,1,&device,NULL); if (error != CL_SUCCESS) { fprintf(stderr,"Error to get device ID : %d\n",error); goto error; } if (error != CL_SUCCESS) { fprintf(stderr,"Can't get device info : %d\n",error); goto error; } context = clCreateContext(0,1,&device,NULL,NULL,&error); if (error != CL_SUCCESS) { fprintf(stderr,"Error to create context : %d\n",error); goto error; } size_t maxWorkItemDim; size_t maxWorkGroupSize; size_t workItemSize[10]; error = clGetDeviceInfo(device,CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS,sizeof(size_t),&maxWorkItemDim,NULL); if (error != CL_SUCCESS) { fprintf(stderr,"Can't get max work item dimensions : %d\n",error); goto errorContext; } error = clGetDeviceInfo(device,CL_DEVICE_MAX_WORK_ITEM_SIZES,maxWorkItemDim*sizeof(size_t),workItemSize,NULL); if (error != CL_SUCCESS) { fprintf(stderr,"Can't get mwork item sizes : %d\n",error); goto errorContext; } error = clGetDeviceInfo(device,CL_DEVICE_MAX_WORK_GROUP_SIZE,sizeof(size_t),&maxWorkGroupSize,NULL); if (error != CL_SUCCESS) { fprintf(stderr,"Can't get max work item dimensions : %d\n",error); goto errorContext; } queue = clCreateCommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE ,&error); if (error != CL_SUCCESS) { fprintf(stderr,"Error to create command queue : %d\n",error); goto errorContext; } /********************** Memory allocations **********************/ long i; #ifdef DEBUG printf("Create buffers\n"); #endif double createBufTime; createBufTime = createBuffers(context,bench); /********************** OpenCL kernel **********************/ cl_program program; char *fileContent; FILE *f; struct stat fState; char path[256]; strcpy(path,"Kernels/"); strcat(path,bench->kernel); stat(path,&fState); f=fopen(path,"r"); fileContent=malloc(fState.st_size*sizeof(char)); fread(fileContent,sizeof(char),fState.st_size,f); fclose(f); program=clCreateProgramWithSource(context,1,(const char**)&fileContent,&fState.st_size,&error); free(fileContent); if (error != CL_SUCCESS) { fprintf(stderr,"Can't create program : %d\n",error); goto errorBuffer; } /*error=clBuildProgram(program,1,&device,"-cl-fast-relaxed-math",NULL,NULL);*/ error=clBuildProgram(program,1,&device,"",NULL,NULL); if (error != CL_SUCCESS) { fprintf(stderr,"Can't build program : %d\n",error); goto errorProgram; } cl_kernel kernel=clCreateKernel(program,"mainKernel",&error); if (error != CL_SUCCESS) { fprintf(stderr,"Can't create kernel : %d\n",error); goto errorProgram; } /********************** Launching the kernel **********************/ #ifdef DEBUG printf("Set args\n"); #endif setArgs(kernel,bench); cl_ulong lStart; cl_ulong lEnd; double fTimeInSeconds; double fFLOPS; #ifdef DEBUG printf("Compute\n"); printf("%d\n",bench->worksizeDim); for(i=0;i<bench->worksizeDim;i++) { printf(" GLOBAL -> %d\n",bench->global_ws[i]); printf(" LOCAL -> %d\n",bench->local_ws[i]); } #endif double writeBufTime; writeBufTime=writeInputs(queue,bench); double computeTime=getCurrentTime(); error=clEnqueueNDRangeKernel(queue, kernel,bench->worksizeDim, NULL,bench->global_ws, bench->local_ws,0,NULL,&event); if (error != CL_SUCCESS) { fprintf(stderr,"Can't enqueue kernel : %d\n",error); goto errorKernel; } clFinish(queue); computeTime= getCurrentTime() - computeTime; #ifdef DEBUG printf("Read results\n"); #endif double readBufTime; readBufTime=readResults(queue,bench); error = clGetEventProfilingInfo(event,CL_PROFILING_COMMAND_START,sizeof(cl_ulong),&lStart,NULL); error |= clGetEventProfilingInfo(event,CL_PROFILING_COMMAND_END ,sizeof(cl_ulong),&lEnd,NULL); if (error != CL_SUCCESS) { fprintf(stderr,"Can't get profiling info : %d\n",error); goto errorEvent; } fTimeInSeconds = ((double)(lEnd-lStart)) / 1000000000.0; /* Send timing */ write(newsockfd,"t\n",2*sizeof(char)); sprintf(result,"%f\n",createBufTime); write(newsockfd,result,strlen(result)); sprintf(result,"%f\n",writeBufTime); write(newsockfd,result,strlen(result)); sprintf(result,"%f\n",fTimeInSeconds); write(newsockfd,result,strlen(result)); sprintf(result,"%f\n",readBufTime); write(newsockfd,result,strlen(result)); /*sprintf(result,"%f\n",computeTime); write(newsockfd,result,strlen(result)); */ /* Send results */ sendResults(bench); errorEvent: clReleaseEvent(event); errorKernel: clReleaseKernel(kernel); /********************** Cleanup **********************/ errorProgram: clReleaseProgram(program); errorBuffer: clReleaseCommandQueue(queue); releaseBuffers(bench); errorContext: clReleaseContext(context); /** HORRIBLE error processing. It may create memory leaks. It will have to be improved. */ error: return (error != CL_SUCCESS); }