/* SADScript function definition of PyInter stuff */ int tfPyEvalString(integer4 *isp1, integer4 *kx, integer4 *irtc) { integer8 ia; char *argv = argv0; if(!initialized) { /* Initialize the Python interpreter if required. */ initialized = 1; Py_Initialize(); PySys_SetArgv(1, &argv); } if(isp != *isp1 + 1) { *irtc = itfmessage(9, "General::narg", "\"1\""); return -1; } if((ktfmask & ktastk(isp)) != ktfstring) { *irtc = itfmessage(9, "General::wrongtype", "\"Character-string\""); return -1; } ia = (ktamask & ktastk(isp)); #if SAD_REQUIRE_STRING_TERMINATION jlist(ilist(1, ia) + 1, ia + 1) = '\0'; #endif /* Execute some Python statements (in module __main__) */ PyRun_SimpleString(&jlist(1, ia + 1)); *kx = ktfoper + mtfnull; *irtc = 0; return 0; }
static int tfNetSemGive(integer4 *isp1, integer8 *kx, integer4 *irtc) { integer8 ia; real8 vx; int status, semaphore; if(isp != *isp1 + 2) { *irtc = itfmessage(9, "General::narg", "\"2\""); return -1; } if(ktfnonstringq(ktastk( *isp1 + 1))) { *irtc = itfmessage(9, "General::wrongtype", "\"Character-string for #1\""); return -1; } if(ktfnonrealq(ktastk( isp))) { *irtc = itfmessage(9, "General::wrongtype", "\"Real Number for #2\""); return -1; } ia = ktfaddr(ktastk(*isp1 + 1)); #if SAD_REQUIRE_STRING_TERMINATION jlist(ilist(1, ia) + 1, ia + 1) = '\0'; #endif semaphore = rtastk( isp); status = netSemGive(&jlist(1, ia + 1), semaphore); vx = status; *kx = kfromr(vx); *irtc = 0; return 0; }
static int ReadLink(integer4 *isp1, integer8 *kx, integer4 *irtc) { integer8 ia; integer4 nc; char *expanded, buf[MAXPATHLEN]; if(isp != *isp1 + 1) { *irtc = itfmessage(9, "General::narg", "\"1\""); return -1; } if((ktfmask & ktastk( *isp1 + 1)) != ktfstring) { *irtc = itfmessage(9, "General::wrongtype", "\"String\""); return -1; } ia = (ktamask & ktastk(*isp1 + 1)); #if SAD_REQUIRE_STRING_TERMINATION jlist(ilist(1, ia) + 1, ia + 1) = '\0'; #endif expanded = expand_tilde(&jlist(1, ia + 1)); if(expanded == NULL) { *kx = ktfoper + mtfnull;; *irtc = 0; #ifdef SAD_THROW_EXCEPTION switch(errno) { case ENOMEM: *irtc = itfsyserr(9); break; default: *irtc = itfmessage(9, "System::error", "\"No such home directory\""); } #ifdef SAD_NOBREAK_EXCEPTION *irtc = 0; #endif #endif return 1; } nc = readlink(expanded, buf, sizeof(buf)); free(expanded); if(nc < 0) { *kx = ktfoper + mtfnull;; *irtc = 0; #ifdef SAD_THROW_EXCEPTION *irtc = itfsyserr(9); #ifdef SAD_NOBREAK_EXCEPTION *irtc = 0; #endif #endif return 1; } *kx = ktfstring + ktsalocbl(-1, buf, nc); *irtc = 0; return 0; }
static int MkSecureTemp(integer4 *isp1, integer8 *kx, integer4 *irtc) { integer8 ka1, ka2 = 0; int fd, nc, slen; char *template; if(!(*isp1 < isp && isp < *isp1 + 3)) { *irtc = itfmessage(9, "General::narg", "\"1 or 2\""); return -1; } if((ktfmask & ktastk(*isp1 + 1)) != ktfstring) { *irtc = itfmessage(9, "General::wrongtype", "\"String\""); return -1; } ka1 = ktamask & ktastk(*isp1 + 1); #if SAD_REQUIRE_STRING_TERMINATION jlist(ilist(1, ka1) + 1, ka1 + 1) = '\0'; #endif nc = itastk(1, ka1); slen = 0; if(nc < 1) { *kx = kxfailed; *irtc = 0; return -1; } if(isp == *isp1 + 2) { if((ktfmask & ktastk(*isp1 + 2)) != ktfstring) { *irtc = itfmessage(9, "General::wrongtype", "\"String\""); return -1; } ka2 = (ktamask & ktastk(*isp1 + 2)); #if SAD_REQUIRE_STRING_TERMINATION jlist(ilist(1, ka2) + 1, ka2 + 1) = '\0'; #endif slen = ktastk(ka2); }
/* SADScript function definition of FileIO stuff */ static int ExpandTilde(integer4 *isp1, integer8 *kx, integer4 *irtc) { integer8 ia; char *expanded; if(isp != *isp1 + 1) { *irtc = itfmessage(9, "General::narg", "\"1\""); return -1; } if((ktfmask & ktastk(*isp1 + 1)) != ktfstring) { *irtc = itfmessage(9, "General::wrongtype", "\"String\""); return -1; } ia = (ktamask & ktastk(*isp1 + 1)); #if SAD_REQUIRE_STRING_TERMINATION jlist(ilist(1, ia) + 1, ia + 1) = '\0'; #endif expanded = expand_tilde(&jlist(1, ia + 1)); if(expanded == NULL) { switch(errno) { case ENOMEM: *irtc = itfsyserr(9); break; default: *irtc = itfmessage(9, "System::error", "\"No such home directory\""); } return 1; } *kx = ktfstring + ktsalocb(-1, expanded); free(expanded); *irtc = 0; return 0; }
void assembleTransposeMatrix ( MatrixEpetra<Real>& globalMatrix, Real coefficient, MatrixElemental& localMatrix, const CurrentFE& currentFE1, const CurrentFE& currentFE2, const DofType1& dof1, const DofType2& dof2, Int iblock, Int jblock, Int iOffset , Int jOffset ) { MatrixElemental::matrix_type localView (localMatrix.block ( jblock, iblock ) ); localView *= coefficient; Int i, j; UInt k1, k2; UInt elementID1 = currentFE1.currentLocalId(); UInt elementID2 = currentFE2.currentLocalId(); std::vector<Int> ilist (currentFE1.nbFEDof() ); std::vector<Int> jlist (currentFE2.nbFEDof() ); std::vector<Real*> matPtr (currentFE1.nbFEDof() ); for ( k1 = 0 ; k1 < currentFE1.nbFEDof() ; k1++ ) { i = k1; ilist[k1] = dof1.localToGlobalMap ( elementID1, i ) + iOffset ; matPtr[k1] = & (localView (0, i) ); } for ( k2 = 0 ; k2 < currentFE2.nbFEDof() ; k2++ ) { j = k2; jlist[k2] = dof2.localToGlobalMap ( elementID2, j ) + jOffset ; } assert (localView.indexij ( Int (1), Int (0) ) == 1); globalMatrix.addToCoefficients ( currentFE1.nbFEDof(), currentFE2.nbFEDof(), ilist, jlist, &matPtr[0], Epetra_FECrsMatrix::ROW_MAJOR ); }
void ConeSplitMerge<Item>::split_merge(std::vector<ProtoJet<Item> >& jcv, float shared_ET_fraction, float pT_min_leading_protojet, float pT_min_second_protojet, int MergeMax, float pT_min_noMergeMax) { while(!_members.empty()) { /* { std::cout << std::endl; std::cout << " --------------- list of protojets ------------------ " <<std::endl; for ( PJMMAP::iterator it = _members.begin(); it != _members.end(); ++it) { std::cout << " pT y phi " << (*it).pT() << " " << (*it).y() << " " << (*it).phi() << " " << (*it).info().seedET() << " " << (*it).info().nbMerge() << " " << (*it).info().nbSplit() << std::endl; } std::cout << " ----------------------------------------------------- " <<std::endl; } */ // select highest Et jet typename PJMMAP::iterator itmax= _members.begin(); ProtoJet<Item> imax((*itmax).first); const std::list<const Item*>& ilist(imax.LItems()); _members.erase(itmax); // does jet share items? bool share= false; float shared_ET = 0.; typename PJMMAP::iterator jtmax; typename PJMMAP::iterator jt; for(jt = _members.begin(); jt != _members.end(); ++jt) { const std::list<const Item*>& jlist((*jt).first.LItems()); typename std::list<const Item*>::const_iterator tk; int count; for(tk = ilist.begin(), count = 0; tk != ilist.end(); ++tk, ++count) { typename std::list<const Item*>::const_iterator where= find(jlist.begin(),jlist.end(),*tk); if(where != jlist.end()) { share= true; shared_ET += (*tk)->pT(); } } if(share) { jtmax = jt; break; } } if(!share) { // add jet to the final jet list jcv.push_back(imax); //std::cout << " final jet " << imax.pT() << " "<< imax.info().nbMerge() << " " << imax.info().nbSplit() << std::endl; } else { // find highest Et neighbor ProtoJet<Item> jmax((*jtmax).first); // drop neighbor _members.erase(jtmax); //std::cout << " split or merge ? " << imax.pT() << " " << shared_ET << " " << jmax.pT() << " " << s << " " << (jmax.pT())*s << std::endl; // merge if( shared_ET > (jmax.pT())*shared_ET_fraction && (imax.pT() > pT_min_leading_protojet || jmax.pT() > pT_min_second_protojet) && (imax.info().nbMerge() < MergeMax || imax.pT() > pT_min_noMergeMax)) { // add neighbor's items to imax const std::list<const Item*>& jlist(jmax.LItems()); typename std::list<const Item*>::const_iterator tk; typename std::list<const Item*>::const_iterator iend= ilist.end(); bool same = true; // is jmax just the same as imax ? for(tk = jlist.begin(); tk != jlist.end(); ++tk) { typename std::list<const Item*>::const_iterator where= find(ilist.begin(),iend,*tk); if(where == iend) { imax.addItem(*tk); same = false; } } if ( ! same ) { // recalculate //float old_pT = imax.pT(); imax.updateJet(); imax.merged(); //std::cout << " jet merge :: " << old_pT << " " << jmax.pT() << " " << imax.pT() << " "<< imax.info().nbMerge() << " " << imax.info().nbSplit() << std::endl; } } //split and assign removed shared cells from lowest pT protojet else if(shared_ET > (jmax.pT())*shared_ET_fraction) { // here we need to pull the lists, because there are items to remove std::list<const Item*> ilist(imax.LItems()); std::list<const Item*> jlist(jmax.LItems()); typename std::list<const Item*>::iterator tk; for(tk = jlist.begin(); tk != jlist.end(); ) { typename std::list<const Item*>::iterator where= find(ilist.begin(),ilist.end(),*tk); if(where != ilist.end()) { tk = jlist.erase(tk); } else ++tk; } jmax.erase(); for ( typename std::list<const Item*>::const_iterator it = jlist.begin(); it != jlist.end(); ++it) jmax.addItem(*it); // recalculated jet quantities jmax.updateJet(); jmax.splitted(); //std::cout << " jet split 1 :: " << jmax.pT() << " "<< jmax.info().nbMerge() << " " << jmax.info().nbSplit() << std::endl; _members.insert(std::make_pair(jmax,jmax.pT())); } // split and assign shared cells to nearest protojet else { // here we need to pull the lists, because there are items to remove std::list<const Item*> ilist(imax.LItems()); std::list<const Item*> jlist(jmax.LItems()); typename std::list<const Item*>::iterator tk; for(tk = jlist.begin(); tk != jlist.end(); ) { typename std::list<const Item*>::iterator where= find(ilist.begin(),ilist.end(),*tk); if(where != ilist.end()) { float yk = (*tk)->y(); float phik = (*tk)->phi(); float di= RD2(imax.y(),imax.phi(),yk,phik); float dj= RD2(jmax.y(),jmax.phi(),yk,phik); if(dj > di) { tk = jlist.erase(tk); //std::cout << " shared item " << (*tk)->pT() << " removed from neighbour jet " << std::endl; } else { ilist.erase(where); ++tk; //std::cout << " shared item " << (*tk)->pT() << " removed from leading jet " << std::endl; } } else ++tk; } // recalculate jets imax and jmax // first erase all items imax.erase(); // put items that are left for ( typename std::list<const Item*>::const_iterator it = ilist.begin(); it != ilist.end(); ++it) imax.addItem(*it); // recalculated jet quantities imax.updateJet(); imax.splitted(); //std::cout << " jet split 2 :: " << imax.pT() << " "<< imax.info().nbMerge() << " " << imax.info().nbSplit() << std::endl; // first erase all items jmax.erase(); // put items that are left for ( typename std::list<const Item*>::const_iterator it = jlist.begin(); it != jlist.end(); ++it) jmax.addItem(*it); // recalculated jet quantities jmax.updateJet(); jmax.splitted(); //std::cout << " jet split " << jmax.pT() << " "<< jmax.info().nbMerge() << " " << jmax.info().nbSplit() << std::endl; _members.insert(std::make_pair(jmax,jmax.pT())); } _members.insert(std::make_pair(imax,imax.pT())); } } // while }
static int FromFileDate(integer4 *isp1, integer8 *kx, integer4 *irtc) { integer8 ia; real8 vx; char *expanded; struct stat buf; if(isp != *isp1 + 1) { *irtc = itfmessage(9, "General::narg", "\"1\""); return -1; } if((ktfmask & ktastk( *isp1 + 1)) != ktfstring) { *irtc = itfmessage(9, "General::wrongtype", "\"String\""); return -1; } ia = (ktamask & ktastk(*isp1 + 1)); #if SAD_REQUIRE_STRING_TERMINATION jlist(ilist(1, ia) + 1, ia + 1) = '\0'; #endif expanded = expand_tilde(&jlist(1, ia + 1)); if(expanded == NULL) { *kx = ktfoper + mtfnull;; *irtc = 0; #ifdef SAD_THROW_EXCEPTION switch(errno) { case ENOMEM: *irtc = itfsyserr(9); break; default: *irtc = itfmessage(9, "System::error", "\"No such home directory\""); } #ifdef SAD_NOBREAK_EXCEPTION *irtc = 0; #endif #endif return 1; } if(stat(expanded, &buf) != 0) { free(expanded); *kx = ktfoper + mtfnull; *irtc = 0; #ifdef SAD_THROW_EXCEPTION *irtc = itfsyserr(9); #ifdef SAD_NOBREAK_EXCEPTION *irtc = 0; #endif #endif return 1; } free(expanded); vx = buf.st_mtime + SAD_EPOCH_OFFSET; *kx = kfromr(vx); *irtc = 0; return 0; }
static int tfNetSemInfo(integer4 *isp1, integer8 *kx, integer4 *irtc) { integer8 ia; real8 vx; int status, semaphore, select; char buffer[MSG_LEN]; if(isp != *isp1 + 3) { *irtc = itfmessage(9, "General::narg", "\"3\""); return -1; } if(ktfnonstringq(ktastk( *isp1 + 1))) { *irtc = itfmessage(9, "General::wrongtype", "\"Character-string for #1\""); return -1; } if(ktfnonrealq(ktastk( *isp1 + 2))) { *irtc = itfmessage(9, "General::wrongtype", "\"Real Number for #2\""); return -1; } if(ktfrealq(ktastk(isp))){ select = rtastk( isp); } else if(ktfstringq(ktastk(isp))){ ia = ktfaddr(ktastk(isp)); #if SAD_REQUIRE_STRING_TERMINATION jlist(ilist(1, ia) + 1, ia + 1) = '\0'; #endif if(strcmp("Owner", &jlist(1, ia + 1)) == 0) { select = OWNER; goto l1; } if(strcmp("Waiter", &jlist(1, ia + 1)) == 0) { select = WAITER; goto l1; } *irtc = itfmessage(9, "General::wrongtype", "\"Character-string " "\\\"Owner\\\" or \\\"Waiter\\\" for #3\""); return -1; } else{ *irtc = itfmessage(9, "General::wrongtype", "\"Real Number or Character-string for #3\""); return -1; } l1: ia = ktfaddr(ktastk(*isp1 + 1)); #if SAD_REQUIRE_STRING_TERMINATION jlist(ilist(1, ia) + 1, ia + 1) = '\0'; #endif semaphore = rtastk(*isp1 + 2); status = netSemInfo(&jlist(1, ia + 1), semaphore, select, buffer); if(status == 0) { *kx = ktfstring +ktsalocb(-1, buffer); } else { *kx = ktfoper + mtfnull; } *irtc = 0; return 0; }