/*! \brief Receives drop events * * This method recieve drop events. It is currently used to * move PeerWidgets arount :) * * \sa dragEnterEvent() */ void XletSwitchBoard::dropEvent(QDropEvent *event) { // qDebug() << Q_FUNC_INFO; if (event->mimeData()->hasFormat(USERID_MIMETYPE)) { QString userid = event->mimeData()->data(USERID_MIMETYPE); if (m_peerhash.contains(userid)) { PeerItem *peeritem = m_peerhash[userid]; BasePeerWidget *peerwidget = peeritem->getWidget(); if (peerwidget) { m_layout->setItemPosition(peerwidget, m_layout->getPosInGrid(event->pos())); } else { peerwidget = addPeerWidget(peeritem, m_layout->getPosInGrid(event->pos())); } updateGeometry(); event->acceptProposedAction(); savePositions(); update(); } } else if (event->mimeData()->hasFormat(NUMBER_MIMETYPE)) { QString number = event->mimeData()->data(NUMBER_MIMETYPE); BasePeerWidget *w = getExternalPhonePeerWidget(number); if (w) { m_layout->setItemPosition(w, m_layout->getPosInGrid(event->pos())); updateGeometry(); event->acceptProposedAction(); savePositions(); update(); } } }
/*! \brief constructor * * initialize layout, attributes, etc. */ XletSwitchBoard::XletSwitchBoard(QWidget *parent) : XLet(parent), m_drawGrid(false), m_trace_box(false), m_group_to_resize(0) { setTitle(tr("Switchboard")); m_layout = new PeersLayout(this); setObjectName("scroller"); // in order for the style settings to be set accordingly setAccessibleName(tr("Switchboard")); setAcceptDrops(true); reloadGroups(); reloadExternalPhones(); connect(b_engine, SIGNAL(userUpdated(UserInfo *)), this, SLOT(updateUser(UserInfo *))); connect(b_engine, SIGNAL(updatePeerAgent(double, const QString &, const QString &, const QVariant &)), this, SLOT(updatePeerAgent(double, const QString &, const QString &, const QVariant &))); // savePositions() needs m_peerhash to be non-empty in order to be useful, // thus we call it before removePeers() connect(b_engine, SIGNAL(delogged()), this, SLOT(savePositions())); connect(b_engine, SIGNAL(delogged()), this, SLOT(removePeers())); setMouseTracking(true); }
ChaserTargetInteractWidget::ChaserTargetInteractWidget( kte::chaser_target_data* aPSceneData, QWidget* parent, Qt::WindowFlags flags) : QDockWidget(tr("Interact"), parent, flags), Ui::ChaserTargetInteract(), pSceneData(aPSceneData) { QScrollArea* dock_scroll = new QScrollArea(this); dock_scroll->setWidgetResizable(true); QWidget* dock_wid = new QWidget(this); dock_scroll->setWidget(dock_wid); this->QDockWidget::setWidget(dock_scroll); setupUi(dock_wid); connect(actionJointChange, SIGNAL(triggered()), this, SLOT(onJointChange())); connect(actionTargetChange, SIGNAL(triggered()), this, SLOT(onTargetChange())); connect(load_traj_button, SIGNAL(clicked()), this, SLOT(loadTargetTrajectory())); connect(load_button, SIGNAL(clicked()), this, SLOT(loadPositions())); connect(save_button, SIGNAL(clicked()), this, SLOT(savePositions())); };
// ###################################################################### void Logger::run(nub::soft_ref<MbariResultViewer> rv, MbariImage<PixRGB <byte> >& img, MbariVisualEvent::VisualEventSet& eventSet, const Dims scaledDims) { // adjust scaling if needed Dims d = img.getDims(); itsScaleW = (float)d.w()/(float)scaledDims.w(); itsScaleH = (float)d.h()/(float)scaledDims.h(); // initialize property vector and FOE estimator MbariVisualEvent::PropertyVectorSet pvs; // this is a list of all the events that have a token in this frame std::list<MbariVisualEvent::VisualEvent *> eventFrameList; // this is a complete list of all those events that are ready to be written std::list<MbariVisualEvent::VisualEvent *> eventListToSave; // get event frame list for this frame and those events that are ready to be saved // this is a list of all the events that have a token in this frame eventFrameList = eventSet.getEventsForFrame(img.getFrameNum()); // this is a complete list of all those events that are ready to be written eventListToSave = eventSet.getEventsReadyToSave(img.getFrameNum()); // write out eventSet? if (itsSaveEventsName.getVal().length() > 0 ) saveVisualEvent(eventSet, eventFrameList); // write out summary ? if (itsSaveSummaryEventsName.getVal().length() > 0) saveVisualEventSummary(Version::versionString(), eventListToSave); // flag events that have been saved for delete std::list<MbariVisualEvent::VisualEvent *>::iterator i; for (i = eventListToSave.begin(); i != eventListToSave.end(); ++i) (*i)->flagWriteComplete(); // write out positions? if (itsSavePositionsName.getVal().length() > 0) savePositions(eventFrameList); MbariVisualEvent::PropertyVectorSet pvsToSave = eventSet.getPropertyVectorSetToSave(); // write out property vector set? if (itsSavePropertiesName.getVal().length() > 0) saveProperties(pvsToSave); // TODO: this is currently not used...look back in history to where this got cut-out // need to obtain the property vector set? if (itsLoadPropertiesName.getVal().length() > 0) pvs = eventSet.getPropertyVectorSet(); // get a list of events for this frame eventFrameList = eventSet.getEventsForFrame(img.getFrameNum()); // write out eventSet to XML? if (itsSaveXMLEventSetName.getVal().length() > 0) { saveVisualEventSetToXML(eventFrameList, img.getFrameNum(), img.getMetaData().getTC(), itsFrameRange); } const int circleRadiusRatio = 40; const int circleRadius = img.getDims().w() / circleRadiusRatio; Image< PixRGB<byte> > output = rv->createOutput(img, eventSet, circleRadius, itsScaleW, itsScaleH); // write ? if (itsSaveOutput.getVal()) itsOfs->writeFrame(GenericFrame(output), "results", FrameInfo("results", SRC_POS)); // display output ? rv->display(output, img.getFrameNum(), "Results"); // need to save any event clips? if (itsSaveEventNumsAll) { //save all events std::list<MbariVisualEvent::VisualEvent *>::iterator i; for (i = eventFrameList.begin(); i != eventFrameList.end(); ++i) saveSingleEventFrame(img, img.getFrameNum(), *i); } else { // need to save any particular event clips? uint csavenum = numSaveEventClips(); for (uint idx = 0; idx < csavenum; ++idx) { uint evnum = getSaveEventClipNum(idx); if (!eventSet.doesEventExist(evnum)) continue; MbariVisualEvent::VisualEvent *event = eventSet.getEventByNumber(evnum); if (event->frameInRange(img.getFrameNum())) saveSingleEventFrame(img, img.getFrameNum(), event); } } //flag events that have been saved for delete otherwise takes too much memory for (i = eventListToSave.begin(); i != eventListToSave.end(); ++i) (*i)->flagForDelete(); while (!eventFrameList.empty()) eventFrameList.pop_front(); while (!eventListToSave.empty()) eventListToSave.pop_front(); }
int main(int argc, char **argv){ int amountForFirst; int amountFound; unsigned amountNumbers; int amountPcs; int amountPerPC; int counter; int rank; int target; int totalFound; char *content; int *founds; int **numbers; int *slaveNumbers; MPI_Status status; if(argc != 3) goto ERROR; MPI_Init(&argc, &argv); amountForFirst = 0; amountFound = 0; amountNumbers = 0; amountPcs = 0; amountPerPC = 0; counter = 0; rank = 0; target = 0; totalFound = 0; content = NULL; founds = NULL; numbers = NULL; slaveNumbers = NULL; memset(&status, 0, sizeof(MPI_Status)); MPI_Comm_size(MPI_COMM_WORLD, &amountPcs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); target = atoi(argv[2]); if(rank == 0){ if(getContent(argv[1], &content)){ amountNumbers = splitNumbers(content, amountPcs, &amountForFirst, &amountPerPC, &numbers); if(amountNumbers){ for(counter = 1; counter < amountPcs; counter++){ MPI_Send(&amountPerPC, 1, MPI_INT, counter, 0, MPI_COMM_WORLD); MPI_Send(numbers[counter], amountPerPC, MPI_INT, counter, 0, MPI_COMM_WORLD); } /* Search and save in node 0 */ if(searchNumber(numbers[0], amountForFirst, target, &founds, &amountFound)){ if(!savePositions(founds, amountFound, 0)) goto ERROR; printf("Rank %d found %d\n", rank, amountFound); }else{ goto ERROR; } totalFound += amountFound; /* Receive founds in other nodes and save. */ for(counter = 1; counter < amountPcs; counter++){ amountFound = 0; free(founds); MPI_Recv(&amountFound, 1, MPI_INT, counter, 0, MPI_COMM_WORLD, &status); totalFound += amountFound; founds = (int*) calloc(amountFound, sizeof(int)); if(!founds) goto ERROR; MPI_Recv(founds, amountFound, MPI_INT, counter, 0, MPI_COMM_WORLD, &status); if(!savePositions(founds, amountFound, amountForFirst + (counter * amountPerPC))) goto ERROR; printf("Rank %d found %d\n", status.MPI_SOURCE, amountFound); } printf("Total found: %d\n", totalFound); }else{ goto ERROR; } }else{ goto ERROR; } }else{ MPI_Recv(&amountPerPC, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &status); slaveNumbers = (int*) calloc(amountPerPC, sizeof(int)); if(!slaveNumbers) goto ERROR; MPI_Recv(slaveNumbers, amountPerPC, MPI_INT, 0, 0, MPI_COMM_WORLD, &status); if(searchNumber(slaveNumbers, amountPerPC, target, &founds, &amountFound)){ MPI_Send(&amountFound, 1, MPI_INT, 0, 0, MPI_COMM_WORLD); MPI_Send(slaveNumbers, amountFound, MPI_INT, 0, 0, MPI_COMM_WORLD); }else{ goto ERROR; } } goto END; ERROR: printf("%d - Deu ruim!!!\n", rank); END: if(content) free(content); if(founds) free(founds); if(slaveNumbers) free(slaveNumbers); memset(&status, 0, sizeof(MPI_Status)); for(counter = 0; counter < amountPcs; counter++){ if(numbers){ if(numbers[counter]) free(numbers[counter]); } } if(numbers) free(numbers); MPI_Finalize(); return 0; }
/*! * Save the positions in the grid of the peer widgets. */ XletSwitchBoard::~XletSwitchBoard() { savePositions(); saveGroups(); removePeers(); }
void GREX::cmd(const string&key,void*val){ if(false){ }else if(key=="initialized"){ CHECK_NULL(val,key); *static_cast<int*>(val)=initialized; }else if(key=="setMPIIntracomm"){ CHECK_NOTINIT(initialized,key); intracomm.Set_comm(val); }else if(key=="setMPIIntercomm"){ CHECK_NOTINIT(initialized,key); intercomm.Set_comm(val); plumedMain.multi_sim_comm.Set_comm(val); }else if(key=="setMPIFIntracomm"){ CHECK_NOTINIT(initialized,key); intracomm.Set_fcomm(val); }else if(key=="setMPIFIntercomm"){ CHECK_NOTINIT(initialized,key); intercomm.Set_fcomm(val); plumedMain.multi_sim_comm.Set_fcomm(val); }else if(key=="init"){ CHECK_NOTINIT(initialized,key); initialized=true; std::string s; // note that for PEs!=root this is automatically 0 (comm defaults to MPI_COMM_SELF) myreplica=intercomm.Get_rank(); intracomm.Sum(myreplica); Tools::convert(myreplica,s); plumedMain.setSuffix("."+s); }else if(key=="prepare"){ CHECK_INIT(initialized,key); if(intracomm.Get_rank()==0) return; intracomm.Bcast(partner,0); calculate(); }else if(key=="setPartner"){ CHECK_INIT(initialized,key); partner=*static_cast<int*>(val); }else if(key=="savePositions"){ CHECK_INIT(initialized,key); savePositions(); }else if(key=="calculate"){ CHECK_INIT(initialized,key); if(intracomm.Get_rank()!=0) return; intracomm.Bcast(partner,0); calculate(); }else if(key=="getLocalDeltaBias"){ CHECK_INIT(initialized,key); CHECK_NULL(val,key); double x=localDeltaBias/(atoms.getMDUnits().getEnergy()/atoms.getUnits().getEnergy()); atoms.double2MD(x,val); }else if(key=="cacheLocalUNow"){ CHECK_INIT(initialized,key); CHECK_NULL(val,key); double x; atoms.MD2double(val,x); localUNow=x*(atoms.getMDUnits().getEnergy()/atoms.getUnits().getEnergy()); intracomm.Sum(localUNow); }else if(key=="cacheLocalUSwap"){ CHECK_INIT(initialized,key); CHECK_NULL(val,key); double x; atoms.MD2double(val,x); localUSwap=x*(atoms.getMDUnits().getEnergy()/atoms.getUnits().getEnergy()); intracomm.Sum(localUSwap); }else if(key=="getForeignDeltaBias"){ CHECK_INIT(initialized,key); CHECK_NULL(val,key); double x=foreignDeltaBias/(atoms.getMDUnits().getEnergy()/atoms.getUnits().getEnergy()); atoms.double2MD(x,val); }else if(key=="shareAllDeltaBias"){ CHECK_INIT(initialized,key); if(intracomm.Get_rank()!=0) return; allDeltaBias.assign(intercomm.Get_size(),0.0); allDeltaBias[intercomm.Get_rank()]=localDeltaBias; intercomm.Sum(allDeltaBias); }else{ // multi word commands std::vector<std::string> words=Tools::getWords(key); int nw=words.size(); if(false){ } else if(nw==2 && words[0]=="getDeltaBias"){ CHECK_INIT(initialized,key); CHECK_NULL(val,key); plumed_massert(allDeltaBias.size()==static_cast<unsigned>(intercomm.Get_size()), "to retrieve bias with cmd(\"GREX getDeltaBias\"), first share it with cmd(\"GREX shareAllDeltaBias\")"); unsigned rep; Tools::convert(words[1],rep); plumed_massert(rep<allDeltaBias.size(),"replica index passed to cmd(\"GREX getDeltaBias\") is out of range"); double d=allDeltaBias[rep]/(atoms.getMDUnits().getEnergy()/atoms.getUnits().getEnergy()); atoms.double2MD(d,val); } else{ plumed_merror("cannot interpret cmd(\"GREX " + key + "\"). check plumed developers manual to see the available commands."); }; }; }