Ejemplo n.º 1
0
CursorView::CursorView()			// construct view
{
    struct List {
	CursorShape	shape;
	const char*	name;			// cursor name
    };
    static List list[] = {
	{ ArrowCursor,		"arrowCursor" },
	{ UpArrowCursor,	"upArrowCursor" },
	{ CrossCursor,		"crossCursor" },
	{ WaitCursor,		"waitCursor" },
	{ IbeamCursor,		"ibeamCursor" },
	{ SizeVerCursor,	"sizeVerCursor" },
	{ SizeHorCursor,	"sizeHorCursor" },
	{ SizeBDiagCursor,	"sizeBDiagCursor" },
	{ SizeFDiagCursor,	"sizeFDiagCursor" },
	{ SizeAllCursor,	"sizeAllCursor" },
	{ BlankCursor,		"blankCursor" },
	{ SplitVCursor,		"splitVCursor" },
	{ SplitHCursor,		"splitHCursor" },
	{ PointingHandCursor,	"pointingHandCursor" },
	{ ForbiddenCursor,	"forbiddenCursor" },
	{ WhatsThisCursor,	"whatsThisCursor" },
	{ BusyCursor,		"busyCursor" }
    };

    setCaption( "CursorView" );			// set window caption

    QGridLayout* grid = new QGridLayout( this, 5, 4, 20 );
    QLabel *label;

    int i=0;
    for ( int y=0; y<4; y++ ) {			// create the small labels
	for ( int x=0; x<4; x++ ) {
	    label = new QLabel( this );
	    label->setCursor( QCursor( list[i].shape ) );
	    label->setText( list[i].name );
	    label->setAlignment( AlignCenter );
	    label->setMargin( 10 );
	    label->setFrameStyle( QFrame::Box | QFrame::Raised );
	    grid->addWidget( label, x, y );
	    i++;
	}
    }


    label = new QLabel( this );
    label->setCursor( QCursor( list[i].shape ) );
    label->setText( list[i].name );
    label->setAlignment( AlignCenter );
    label->setMargin( 10 );
    label->setFrameStyle( QFrame::Box | QFrame::Raised );
    grid->addWidget( label, 4, 0 );


    
    QBitmap cb( cb_width, cb_height, cb_bits, TRUE );
    QBitmap cm( cm_width, cm_height, cm_bits, TRUE );
    QCursor custom( cb, cm );			// create bitmap cursor

    label = new QLabel( this );			// create the big label
    label->setCursor( custom );
    label->setText( "Custom bitmap cursor" );
    label->setAlignment( AlignCenter );
    label->setMargin( 10 );
    label->setFrameStyle( QFrame::Box | QFrame::Sunken );
    grid->addMultiCellWidget( label, 4, 4, 1, 3 );

}
void ConcurrentMarkThread::run() {
  initialize_in_thread();
  _vtime_start = os::elapsedVTime();
  wait_for_universe_init();

  G1CollectedHeap* g1h = G1CollectedHeap::heap();
  G1CollectorPolicy* g1_policy = g1h->g1_policy();
  G1MMUTracker *mmu_tracker = g1_policy->mmu_tracker();
  Thread *current_thread = Thread::current();

  while (!_should_terminate) {
    // wait until started is set.
    sleepBeforeNextCycle();
    {
      ResourceMark rm;
      HandleMark   hm;
      double cycle_start = os::elapsedVTime();
      char verbose_str[128];

      // We have to ensure that we finish scanning the root regions
      // before the next GC takes place. To ensure this we have to
      // make sure that we do not join the STS until the root regions
      // have been scanned. If we did then it's possible that a
      // subsequent GC could block us from joining the STS and proceed
      // without the root regions have been scanned which would be a
      // correctness issue.

      double scan_start = os::elapsedTime();
      if (!cm()->has_aborted()) {
        if (G1Log::fine()) {
          gclog_or_tty->date_stamp(PrintGCDateStamps);
          gclog_or_tty->stamp(PrintGCTimeStamps);
          gclog_or_tty->print_cr("[GC concurrent-root-region-scan-start]");
        }

        _cm->scanRootRegions();

        double scan_end = os::elapsedTime();
        if (G1Log::fine()) {
          gclog_or_tty->date_stamp(PrintGCDateStamps);
          gclog_or_tty->stamp(PrintGCTimeStamps);
          gclog_or_tty->print_cr("[GC concurrent-root-region-scan-end, %1.7lf]",
                                 scan_end - scan_start);
        }
      }

      double mark_start_sec = os::elapsedTime();
      if (G1Log::fine()) {
        gclog_or_tty->date_stamp(PrintGCDateStamps);
        gclog_or_tty->stamp(PrintGCTimeStamps);
        gclog_or_tty->print_cr("[GC concurrent-mark-start]");
      }

      int iter = 0;
      do {
        iter++;
        if (!cm()->has_aborted()) {
          _cm->markFromRoots();
        }

        double mark_end_time = os::elapsedVTime();
        double mark_end_sec = os::elapsedTime();
        _vtime_mark_accum += (mark_end_time - cycle_start);
        if (!cm()->has_aborted()) {
          if (g1_policy->adaptive_young_list_length()) {
            double now = os::elapsedTime();
            double remark_prediction_ms = g1_policy->predict_remark_time_ms();
            jlong sleep_time_ms = mmu_tracker->when_ms(now, remark_prediction_ms);
            os::sleep(current_thread, sleep_time_ms, false);
          }

          if (G1Log::fine()) {
            gclog_or_tty->date_stamp(PrintGCDateStamps);
            gclog_or_tty->stamp(PrintGCTimeStamps);
            gclog_or_tty->print_cr("[GC concurrent-mark-end, %1.7lf sec]",
                                      mark_end_sec - mark_start_sec);
          }

          CMCheckpointRootsFinalClosure final_cl(_cm);
          sprintf(verbose_str, "GC remark");
          VM_CGC_Operation op(&final_cl, verbose_str, true /* needs_pll */);
          VMThread::execute(&op);
        }
        if (cm()->restart_for_overflow() &&
            G1TraceMarkStackOverflow) {
          gclog_or_tty->print_cr("Restarting conc marking because of MS overflow "
                                 "in remark (restart #%d).", iter);
        }

        if (cm()->restart_for_overflow()) {
          if (G1Log::fine()) {
            gclog_or_tty->date_stamp(PrintGCDateStamps);
            gclog_or_tty->stamp(PrintGCTimeStamps);
            gclog_or_tty->print_cr("[GC concurrent-mark-restart-for-overflow]");
          }
        }
      } while (cm()->restart_for_overflow());

      double end_time = os::elapsedVTime();
      // Update the total virtual time before doing this, since it will try
      // to measure it to get the vtime for this marking.  We purposely
      // neglect the presumably-short "completeCleanup" phase here.
      _vtime_accum = (end_time - _vtime_start);

      if (!cm()->has_aborted()) {
        if (g1_policy->adaptive_young_list_length()) {
          double now = os::elapsedTime();
          double cleanup_prediction_ms = g1_policy->predict_cleanup_time_ms();
          jlong sleep_time_ms = mmu_tracker->when_ms(now, cleanup_prediction_ms);
          os::sleep(current_thread, sleep_time_ms, false);
        }

        CMCleanUp cl_cl(_cm);
        sprintf(verbose_str, "GC cleanup");
        VM_CGC_Operation op(&cl_cl, verbose_str, false /* needs_pll */);
        VMThread::execute(&op);
      } else {
        // We don't want to update the marking status if a GC pause
        // is already underway.
        _sts.join();
        g1h->set_marking_complete();
        _sts.leave();
      }

      // Check if cleanup set the free_regions_coming flag. If it
      // hasn't, we can just skip the next step.
      if (g1h->free_regions_coming()) {
        // The following will finish freeing up any regions that we
        // found to be empty during cleanup. We'll do this part
        // without joining the suspendible set. If an evacuation pause
        // takes place, then we would carry on freeing regions in
        // case they are needed by the pause. If a Full GC takes
        // place, it would wait for us to process the regions
        // reclaimed by cleanup.

        double cleanup_start_sec = os::elapsedTime();
        if (G1Log::fine()) {
          gclog_or_tty->date_stamp(PrintGCDateStamps);
          gclog_or_tty->stamp(PrintGCTimeStamps);
          gclog_or_tty->print_cr("[GC concurrent-cleanup-start]");
        }

        // Now do the concurrent cleanup operation.
        _cm->completeCleanup();

        // Notify anyone who's waiting that there are no more free
        // regions coming. We have to do this before we join the STS
        // (in fact, we should not attempt to join the STS in the
        // interval between finishing the cleanup pause and clearing
        // the free_regions_coming flag) otherwise we might deadlock:
        // a GC worker could be blocked waiting for the notification
        // whereas this thread will be blocked for the pause to finish
        // while it's trying to join the STS, which is conditional on
        // the GC workers finishing.
        g1h->reset_free_regions_coming();

        double cleanup_end_sec = os::elapsedTime();
        if (G1Log::fine()) {
          gclog_or_tty->date_stamp(PrintGCDateStamps);
          gclog_or_tty->stamp(PrintGCTimeStamps);
          gclog_or_tty->print_cr("[GC concurrent-cleanup-end, %1.7lf]",
                                 cleanup_end_sec - cleanup_start_sec);
        }
      }
      guarantee(cm()->cleanup_list_is_empty(),
                "at this point there should be no regions on the cleanup list");

      // There is a tricky race before recording that the concurrent
      // cleanup has completed and a potential Full GC starting around
      // the same time. We want to make sure that the Full GC calls
      // abort() on concurrent mark after
      // record_concurrent_mark_cleanup_completed(), since abort() is
      // the method that will reset the concurrent mark state. If we
      // end up calling record_concurrent_mark_cleanup_completed()
      // after abort() then we might incorrectly undo some of the work
      // abort() did. Checking the has_aborted() flag after joining
      // the STS allows the correct ordering of the two methods. There
      // are two scenarios:
      //
      // a) If we reach here before the Full GC, the fact that we have
      // joined the STS means that the Full GC cannot start until we
      // leave the STS, so record_concurrent_mark_cleanup_completed()
      // will complete before abort() is called.
      //
      // b) If we reach here during the Full GC, we'll be held up from
      // joining the STS until the Full GC is done, which means that
      // abort() will have completed and has_aborted() will return
      // true to prevent us from calling
      // record_concurrent_mark_cleanup_completed() (and, in fact, it's
      // not needed any more as the concurrent mark state has been
      // already reset).
      _sts.join();
      if (!cm()->has_aborted()) {
        g1_policy->record_concurrent_mark_cleanup_completed();
      }
      _sts.leave();

      if (cm()->has_aborted()) {
        if (G1Log::fine()) {
          gclog_or_tty->date_stamp(PrintGCDateStamps);
          gclog_or_tty->stamp(PrintGCTimeStamps);
          gclog_or_tty->print_cr("[GC concurrent-mark-abort]");
        }
      }

      // We now want to allow clearing of the marking bitmap to be
      // suspended by a collection pause.
      _sts.join();
      _cm->clearNextBitmap();
      _sts.leave();
    }

    // Update the number of full collections that have been
    // completed. This will also notify the FullGCCount_lock in case a
    // Java thread is waiting for a full GC to happen (e.g., it
    // called System.gc() with +ExplicitGCInvokesConcurrent).
    _sts.join();
    g1h->increment_old_marking_cycles_completed(true /* concurrent */);
    _sts.leave();
  }
  assert(_should_terminate, "just checking");

  terminate();
}
Ejemplo n.º 3
0
cdiagmat complexm(diagmat &Re)
{
	cdiagmat cm(Re.Sz);
	for (int i=0;i<Re.Sz;i++) cm(i)=complex(Re(i));
	return cm;
}
Ejemplo n.º 4
0
/*!
 * Shape Matching法
 *  - 目標位置を計算して,m_pNewPosをその位置に近づける
 * @param[in] dt タイムステップ幅
 */
void rxShapeMatching::shapeMatching(double dt)
{
	if(m_iNumVertices <= 1) return;

	Vec3 cm(0.0), cm_org(0.0);	// 重心
	double mass = 0.0f;	// 総質量

	// 重心座標の計算
	for(int i = 0; i < m_iNumVertices;++i){
		double m = m_pMass[i];
		if(m_pFix[i]) m *= 300.0;	// 固定点の質量を大きくする
		mass += m;

		Vec3 np(m_pNewPos[i*SM_DIM+0], m_pNewPos[i*SM_DIM+1], m_pNewPos[i*SM_DIM+2]);
		Vec3 op(m_pOrgPos[i*SM_DIM+0], m_pOrgPos[i*SM_DIM+1], m_pOrgPos[i*SM_DIM+2]);

		cm += np*m;
		cm_org += op*m;
	}

	cm /= mass;
	cm_org /= mass;

	rxMatrix3 Apq(0.0), Aqq(0.0);
	Vec3 p, q;

	// Apq = Σmpq^T
	// Aqq = Σmqq^T
	for(int i = 0; i < m_iNumVertices; ++i){

		Vec3 np(m_pNewPos[i*SM_DIM+0], m_pNewPos[i*SM_DIM+1], m_pNewPos[i*SM_DIM+2]);
		Vec3 op(m_pOrgPos[i*SM_DIM+0], m_pOrgPos[i*SM_DIM+1], m_pOrgPos[i*SM_DIM+2]);

		p = np-cm;
		q = op-cm_org;
		double m = m_pMass[i];

		Apq(0,0) += m*p[0]*q[0];
		Apq(0,1) += m*p[0]*q[1];
		Apq(0,2) += m*p[0]*q[2];
		Apq(1,0) += m*p[1]*q[0];
		Apq(1,1) += m*p[1]*q[1];
		Apq(1,2) += m*p[1]*q[2];
		Apq(2,0) += m*p[2]*q[0];
		Apq(2,1) += m*p[2]*q[1];
		Apq(2,2) += m*p[2]*q[2];

		Aqq(0,0) += m*q[0]*q[0];
		Aqq(0,1) += m*q[0]*q[1];
		Aqq(0,2) += m*q[0]*q[2];
		Aqq(1,0) += m*q[1]*q[0];
		Aqq(1,1) += m*q[1]*q[1];
		Aqq(1,2) += m*q[1]*q[2];
		Aqq(2,0) += m*q[2]*q[0];
		Aqq(2,1) += m*q[2]*q[1];
		Aqq(2,2) += m*q[2]*q[2];
	}

	rxMatrix3 R, S;
	PolarDecomposition(Apq, R, S);

	if(true/*m_bLinearDeformation*/){
		// Linear Deformations
		rxMatrix3 A;
		A = Apq*Aqq.Inverse();	// A = Apq*Aqq^-1

		// 体積保存のために√(det(A))で割る
		if(m_bVolumeConservation){
			double det = fabs(A.Determinant());
			if(det > RX_FEQ_EPS){
				det = 1.0/sqrt(det);
				if(det > 2.0) det = 2.0;
				A *= det;
			}
		}

		// 回転行列Rの代わりの行列RL=βA+(1-β)Rを計算
		rxMatrix3 RL = m_dBeta*A+(1.0-m_dBeta)*R;

		// 目標座標を計算し,現在の頂点座標を移動
		for(int i = 0; i < m_iNumVertices; ++i){
			if(m_pFix[i]) continue;

			Vec3 np(m_pNewPos[i*SM_DIM+0], m_pNewPos[i*SM_DIM+1], m_pNewPos[i*SM_DIM+2]);
			Vec3 op(m_pOrgPos[i*SM_DIM+0], m_pOrgPos[i*SM_DIM+1], m_pOrgPos[i*SM_DIM+2]);

			q = op-cm_org;
			Vec3 gp = RL*q+cm;

			for(int j = 0; j < SM_DIM; j++)
			{
				m_pGoalPos[i*SM_DIM+j] = gp[j];
				m_pNewPos[i*SM_DIM+j] += (m_pGoalPos[i*SM_DIM+j]-np[j])*m_dAlpha;
			}
		}
	}
	else{
		//// Quadratic Deformations
		//double Atpq[3][9];
		//for(int j = 0; j < 9; ++j){
		//	Atpq[0][j] = 0.0;
		//	Atpq[1][j] = 0.0;
		//	Atpq[2][j] = 0.0;
		//}
		//rxMatrixN<double,9> Atqq;
		//Atqq.SetValue(0.0);

		//for(int i = 0; i < m_iNumVertices; ++i){
		//	p = m_pNewPos[i]-cm;
		//	q = m_pOrgPos[i]-cm_org;

		//	// q~の計算
		//	double qt[9];
		//	qt[0] = q[0];      qt[1] = q[1];      qt[2] = q[2];
		//	qt[3] = q[0]*q[0]; qt[4] = q[1]*q[1]; qt[5] = q[2]*q[2];
		//	qt[6] = q[0]*q[1]; qt[7] = q[1]*q[2]; qt[8] = q[2]*q[0];

		//	// A~pq = Σmpq~ の計算
		//	double m = m_vMass[i];
		//	for(int j = 0; j < 9; ++j){
		//		Atpq[0][j] += m*p[0]*qt[j];
		//		Atpq[1][j] += m*p[1]*qt[j];
		//		Atpq[2][j] += m*p[2]*qt[j];
		//	}

		//	// A~qq = Σmq~q~ の計算
		//	for(int j = 0; j < 9; ++j){
		//		for(int k = 0; k < 9; ++k){
		//			Atqq(j,k) += m*qt[j]*qt[k];
		//		}
		//	}
		//}

		//// A~qqの逆行列算出
		//Atqq.Invert();

		//double At[3][9];
		//for(int i = 0; i < 3; ++i){
		//	for(int j = 0; j < 9; j++){
		//		At[i][j] = 0.0f;
		//		for(int k = 0; k < 9; k++){
		//			At[i][j] += Atpq[i][k]*Atqq(k,j);
		//		}

		//		// βA~+(1-β)R~
		//		At[i][j] *= m_dBeta;
		//		if(j < 3){
		//			At[i][j] += (1.0f-m_dBeta)*R(i,j);
		//		}
		//	}
		//}

		// // a00a11a22+a10a21a02+a20a01a12-a00a21a12-a20a11a02-a10a01a22
		//double det = At[0][0]*At[1][1]*At[2][2]+At[1][0]*At[2][1]*At[0][2]+At[2][0]*At[0][1]*At[1][2]
		//			-At[0][0]*At[2][1]*At[1][2]-At[2][0]*At[1][1]*At[0][2]-At[1][0]*At[0][1]*At[2][2];

		//// 体積保存のために√(det(A))で割る
		//if(m_bVolumeConservation){
		//	if(det != 0.0f){
		//		det = 1.0f/sqrt(fabs(det));
		//		if(det > 2.0f) det = 2.0f;
		//		for(int i = 0; i < 3; ++i){
		//			for(int j = 0; j < 3; ++j){
		//				At[i][j] *= det;
		//			}
		//		}
		//	}
		//}


		//// 目標座標を計算し,現在の頂点座標を移動
		//for(int i = 0; i < m_iNumVertices; ++i){
		//	if(m_pFix[i]) continue;
		//	q = m_pOrgPos[i]-cm_org;

		//	for(int k = 0; k < 3; ++k){
		//		m_pGoalPos[i][k] = At[k][0]*q[0]+At[k][1]*q[1]+At[k][2]*q[2]
		//						  +At[k][3]*q[0]*q[0]+At[k][4]*q[1]*q[1]+At[k][5]*q[2]*q[2]+
		//						  +At[k][6]*q[0]*q[1]+At[k][7]*q[1]*q[2]+At[k][8]*q[2]*q[0];
		//	}

		//	m_pGoalPos[i] += cm;
		//	m_pNewPos[i] += (m_pGoalPos[i]-m_pNewPos[i])*m_dAlpha;
		//}

	}
}
ChunkVersion forceShardFilteringMetadataRefresh(OperationContext* opCtx,
                                                const NamespaceString& nss,
                                                bool forceRefreshFromThisThread) {
    invariant(!opCtx->lockState()->isLocked());
    invariant(!opCtx->getClient()->isInDirectClient());

    auto* const shardingState = ShardingState::get(opCtx);
    invariant(shardingState->canAcceptShardedCommands());

    auto routingInfo =
        uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfoWithRefresh(
            opCtx, nss, forceRefreshFromThisThread));
    auto cm = routingInfo.cm();

    if (!cm) {
        // No chunk manager, so unsharded.

        // Exclusive collection lock needed since we're now changing the metadata
        AutoGetCollection autoColl(opCtx, nss, MODE_IX, MODE_X);
        CollectionShardingRuntime::get(opCtx, nss)
            ->setFilteringMetadata(opCtx, CollectionMetadata());

        return ChunkVersion::UNSHARDED();
    }

    // Optimistic check with only IS lock in order to avoid threads piling up on the collection X
    // lock below
    {
        AutoGetCollection autoColl(opCtx, nss, MODE_IS);
        auto optMetadata = CollectionShardingState::get(opCtx, nss)->getCurrentMetadataIfKnown();

        // We already have newer version
        if (optMetadata) {
            const auto& metadata = *optMetadata;
            if (metadata->isSharded() &&
                metadata->getCollVersion().epoch() == cm->getVersion().epoch() &&
                metadata->getCollVersion() >= cm->getVersion()) {
                LOG(1) << "Skipping refresh of metadata for " << nss << " "
                       << metadata->getCollVersion() << " with an older " << cm->getVersion();
                return metadata->getShardVersion();
            }
        }
    }

    // Exclusive collection lock needed since we're now changing the metadata
    AutoGetCollection autoColl(opCtx, nss, MODE_IX, MODE_X);
    auto* const css = CollectionShardingRuntime::get(opCtx, nss);

    {
        auto optMetadata = CollectionShardingState::get(opCtx, nss)->getCurrentMetadataIfKnown();

        // We already have newer version
        if (optMetadata) {
            const auto& metadata = *optMetadata;
            if (metadata->isSharded() &&
                metadata->getCollVersion().epoch() == cm->getVersion().epoch() &&
                metadata->getCollVersion() >= cm->getVersion()) {
                LOG(1) << "Skipping refresh of metadata for " << nss << " "
                       << metadata->getCollVersion() << " with an older " << cm->getVersion();
                return metadata->getShardVersion();
            }
        }
    }

    CollectionMetadata metadata(std::move(cm), shardingState->shardId());
    const auto newShardVersion = metadata.getShardVersion();

    css->setFilteringMetadata(opCtx, std::move(metadata));
    return newShardVersion;
}
Ejemplo n.º 6
0
EXPORTABLE(int) myserver_main (char *cmd, MsCgiData* data)
{
  try
    {
      MscgiManager cm(data);
      program_name = cmd;
      if (strlen (cmd) == 0)
        {
          cm.write ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
                    "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\r\n"
                    "\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\r\n"
                    "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\r\n"
                    "<head>\r\n<title>MyServer</title>\r\n"
                    "<meta http-equiv=\"content-type\" content=\"text/html;charset=UTF-8\" />\r\n"
                    "</head>\r\n<body style=\"color: #666699;\">\r\n"
                    "<div style=\"text-align: center;\">\r\n"
                    "<br />\r\n<img src=\"/logo.png\" alt=\"\" style=\"border: 0px;\" />\r\n"
                    "<br /><br />\r\n"
                    "<form action=\"math_sum.mscgi\" method=\"get\" enctype=\"text/plain\">\r\n"
                    "<div>\r\n<input type=\"text\" name=\"a\" size=\"20\" />\r\n"
                    "<br /><br />\r\n+<br /><br />\r\n"
                    "<input type=\"text\" name=\"b\" size=\"20\" />\r\n"
                    "<br /><br />\r\n<input type=\"submit\" value=\"Compute!\" />\r\n"
                    "</div>\r\n</form>\r\n<br />\r\n</div>\r\n</body>\r\n</html>");
        }
      else
        {
          u_long dim = 120;
          char lb[120];
          int a = 0;
          int b = 0;
          char *tmp;
          int validNumbers = 1;
          int iRes;
          char res[22]; // a 64-bit number has a maximum of 20 digits and 1 for the sign
          cm.write ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
                    "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\r\n"
                    "\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\r\n"
                    "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\r\n"
                    "<head>\r\n<title>MyServer</title>\r\n"
                    "<meta http-equiv=\"content-type\" content=\"text/html;charset=UTF-8\" />\r\n"
                    "</head>"
                    "<body style=\"color: #666699;\">\r\n<div style=\"text-align: center;\">\r\n"
                    "<br /><br />\r\n<img src=\"/logo.png\" alt=\"\" style=\"border: 0px;\" />\r\n"
                    "<br /><br />\r\n");

          tmp = cm.getParam ("a");
          if(tmp && !isNumber (tmp))
            validNumbers = 0;

          tmp = cm.getParam ("b");
          if (tmp && !isNumber(tmp))
            validNumbers = 0;

          if (validNumbers)
            {
              tmp = cm.getParam ("a");
              if (tmp && tmp[0] != '\0')
                {
                  if (strlen (tmp) > 11)
                    tmp[11] = '\0';
                  a = atoi (tmp);
                  cm.write (tmp);
                }
              else
                cm.write ("0");

              cm.write (" + ");

              tmp = cm.getParam ("b");
              if (tmp && tmp[0] != '\0')
                {
                  if (strlen (tmp) > 11)
                    tmp[11] = '\0';
                  b = atoi (tmp);
                  cm.write (tmp);
                }
              else
                cm.write("0");

              cm.write(" = ");
              iRes = a + b;
#ifdef	WIN32
              _i64toa(iRes, res, 10);
#else
              sprintf(res,"%i", (int) iRes);
#endif
              cm.write (res);
            }
          else
            {
              cm.write ("Invalid input format");
            }

          cm.getenv ("SERVER_NAME", lb, &dim);
          cm.write ("\r\n<br />\r\nRunning on: ");
          cm.write (lb);
          cm.write ("(");
          cm.getenv ("HTTP_HOST", lb, &dim);
          cm.write (lb);

          cm.write (")\r\n</div>\r\n</body>\r\n</html>");
        }

      cm.clean ();
    }
  catch (exception & e)
    {
      return 1;
    }
  return 0;
}
Ejemplo n.º 7
0
void resultCombiner(const char * name_dv1, const char * name_cm1, const int length1, const char * name_dv2, const char * name_cm2, const int length2, int ftr = 1, const char * outputNameStub = "output")
{
    TVectorD dv1(length1), dv2(length2);
    TMatrixT<double> cm1(length1, length1), cm2(length2, length2);
    double binLimits1[length1][2], binLimits2[length2][2], ccCov1[length1], ccCov2[length1];

    readDataVector(name_dv1, dv1, binLimits1, ftr, ccCov1);
    printf("Read data vector 1 (%d)\n",length1);

    readDataVector(name_dv2, dv2, binLimits2, ftr, ccCov2);
    printf("Read data vector 2 (%d)\n",length2);

    readCovMatrix(name_cm1, cm1);
    printf("Read covariance matrix 1\n");

    readCovMatrix(name_cm2, cm2);
    printf("Read covariance matrix 2\n");

    std::vector<double*> binLimits;
    std::vector<std::vector<int > > preU;
    int i1 = 0, i2 = 0;
    while(i1 < length1 || i2 < length2)
    {
        if(i1 < length1 && i2 < length2)
        {
            if((binLimits1[i1][1] + binLimits1[i1][0])/2 > binLimits2[i2][0] && (binLimits1[i1][1] + binLimits1[i1][0])/2 < binLimits2[i2][1])
            {
                binLimits.push_back(binLimits1[i1]);
                std::vector<int> tmp;
                tmp.push_back(i1);
                tmp.push_back(i2);
                preU.push_back(tmp);
                i1++;
                i2++;
            }
            else if((binLimits1[i1][1] + binLimits1[i1][0])/2 <= binLimits2[i2][0])
            {
                binLimits.push_back(binLimits1[i1]);
                std::vector<int> tmp;
                tmp.push_back(i1);
                tmp.push_back(-1);
                preU.push_back(tmp);
                i1++;
            }
            else
            {
                binLimits.push_back(binLimits2[i2]);
                std::vector<int> tmp;
                tmp.push_back(-1);
                tmp.push_back(i2);
                preU.push_back(tmp);
                i2++;
            }
        }
        else if(i1 < length1 && i2 >= length2)
        {
            binLimits.push_back(binLimits1[i1]);
            std::vector<int> tmp;
            tmp.push_back(i1);
            tmp.push_back(-1);
            preU.push_back(tmp);
            i1++;
        }
        else
        {
            binLimits.push_back(binLimits2[i2]);
            std::vector<int> tmp;
            tmp.push_back(-1);
            tmp.push_back(i2);
            preU.push_back(tmp);
            i2++;
        }
    }

    TVectorD dv(length1 + length2);
    for(int i = 0; i < length1 + length2; i++)
    {
        dv[i] = (i < length1) ? dv1[i] : dv2[i - length1];
    }

    TMatrixT<double> cm(length1 + length2, length1 + length2), U(length1 + length2, preU.size());
    for(int i = 0; i < length1; i++)
    {
        for(int j = 0; j < length1; j++)
        {
            cm[i][j] = cm1[i][j];
        }
    }
    for(int i = length1; i < length1 + length2; i++)
    {
        for(int j = length1; j < length1 + length2; j++)
        {
            cm[i][j] = cm2[i - length1][j - length1];
        }
    }

    for(unsigned int i = 0; i < preU.size(); i++)
    {
        if(preU[i][0] >= 0) U[preU[i][0]][i] = 1;
        if(preU[i][1] >= 0) U[preU[i][1] + length1][i] = 1;
        if(ftr > 1 && preU[i][0] >= 0 && preU[i][1] >= 0)  cm[preU[i][0]][preU[i][1] + length1] = cm[preU[i][1] + length1][preU[i][0]] = ccCov1[preU[i][0]]*ccCov2[preU[i][1]];
    }
    
    //    cm.Print();

    TMatrixT<double> Ut(U);
    Ut.T();

    TMatrixT<double> cmInv(cm);
    cmInv.Invert();
    TMatrixT<double> step1 = Ut * cmInv * U;
    TMatrixT<double> step2 = Ut * cmInv;
    TMatrixT<double> lambda = step1.Invert() * step2;
    TVectorD bV = lambda*dv;
    TMatrixT<double> bcm = (Ut * cmInv * U).Invert();

    printf("Done with combination.\n");

    //write output
    FILE *file;
    char bVoutName[128], CMoutName[128];
    sprintf(bVoutName, "%s_data.txt", outputNameStub);

    file = fopen(bVoutName, "w");
    if(file)
    {
        fprintf(file, "#\n#%9s %9s %9s %15s %15s\n", "Bin", "Y_min", "Y_max", "Value", "Uncertainty");
        for(int i = 0; i < bV.GetNoElements(); i++)
        {
            fprintf(file, " %9i %9.2f %9.2f %15e %15e\n", i + 1, binLimits[i][0], binLimits[i][1], bV[i], sqrt(bcm[i][i]));
        }
        fclose(file);
    }

    sprintf(CMoutName, "%s_covMat.txt", outputNameStub);

    file = fopen(CMoutName, "w");
    if(file)
    {
        fprintf(file, "#\n#%9s %9s %15s\n", "Bin i", "Bin j", "Value");
        for(int i = 0; i < bcm.GetNrows(); i++)
        {
            for(int j = 0; j < bcm.GetNcols(); j++)
            {
                fprintf(file, " %9i %9i %15e\n", i + 1, j + 1, bcm[i][j]);
            }
        }
        fclose(file);
    }
    printf("Output complete.\n");
}
void ConcurrentMarkThread::run_service() {
    _vtime_start = os::elapsedVTime();

    G1CollectedHeap* g1h = G1CollectedHeap::heap();
    G1CollectorPolicy* g1_policy = g1h->g1_policy();

    while (!_should_terminate) {
        // wait until started is set.
        sleepBeforeNextCycle();
        if (_should_terminate) {
            break;
        }

        assert(GCId::current() != GCId::undefined(), "GC id should have been set up by the initial mark GC.");
        {
            ResourceMark rm;
            HandleMark   hm;
            double cycle_start = os::elapsedVTime();

            // We have to ensure that we finish scanning the root regions
            // before the next GC takes place. To ensure this we have to
            // make sure that we do not join the STS until the root regions
            // have been scanned. If we did then it's possible that a
            // subsequent GC could block us from joining the STS and proceed
            // without the root regions have been scanned which would be a
            // correctness issue.

            if (!cm()->has_aborted()) {
                GCConcPhaseTimer(_cm, "Concurrent Root Region Scanning");
                _cm->scanRootRegions();
            }

            // It would be nice to use the GCTraceConcTime class here but
            // the "end" logging is inside the loop and not at the end of
            // a scope. Mimicking the same log output as GCTraceConcTime instead.
            jlong mark_start = os::elapsed_counter();
            log_info(gc)("Concurrent Mark (%.3fs)", TimeHelper::counter_to_seconds(mark_start));

            int iter = 0;
            do {
                iter++;
                if (!cm()->has_aborted()) {
                    GCConcPhaseTimer(_cm, "Concurrent Mark");
                    _cm->markFromRoots();
                }

                double mark_end_time = os::elapsedVTime();
                jlong mark_end = os::elapsed_counter();
                _vtime_mark_accum += (mark_end_time - cycle_start);
                if (!cm()->has_aborted()) {
                    delay_to_keep_mmu(g1_policy, true /* remark */);
                    log_info(gc)("Concurrent Mark (%.3fs, %.3fs) %.3fms",
                                 TimeHelper::counter_to_seconds(mark_start),
                                 TimeHelper::counter_to_seconds(mark_end),
                                 TimeHelper::counter_to_millis(mark_end - mark_start));

                    CMCheckpointRootsFinalClosure final_cl(_cm);
                    VM_CGC_Operation op(&final_cl, "Pause Remark", true /* needs_pll */);
                    VMThread::execute(&op);
                }
                if (cm()->restart_for_overflow()) {
                    log_debug(gc)("Restarting conc marking because of MS overflow in remark (restart #%d).", iter);
                    log_info(gc)("Concurrent Mark restart for overflow");
                }
            } while (cm()->restart_for_overflow());

            double end_time = os::elapsedVTime();
            // Update the total virtual time before doing this, since it will try
            // to measure it to get the vtime for this marking.  We purposely
            // neglect the presumably-short "completeCleanup" phase here.
            _vtime_accum = (end_time - _vtime_start);

            if (!cm()->has_aborted()) {
                delay_to_keep_mmu(g1_policy, false /* cleanup */);

                CMCleanUp cl_cl(_cm);
                VM_CGC_Operation op(&cl_cl, "Pause Cleanup", false /* needs_pll */);
                VMThread::execute(&op);
            } else {
                // We don't want to update the marking status if a GC pause
                // is already underway.
                SuspendibleThreadSetJoiner sts_join;
                g1h->collector_state()->set_mark_in_progress(false);
            }

            // Check if cleanup set the free_regions_coming flag. If it
            // hasn't, we can just skip the next step.
            if (g1h->free_regions_coming()) {
                // The following will finish freeing up any regions that we
                // found to be empty during cleanup. We'll do this part
                // without joining the suspendible set. If an evacuation pause
                // takes place, then we would carry on freeing regions in
                // case they are needed by the pause. If a Full GC takes
                // place, it would wait for us to process the regions
                // reclaimed by cleanup.

                GCTraceConcTime(Info, gc) tt("Concurrent Cleanup");
                GCConcPhaseTimer(_cm, "Concurrent Cleanup");

                // Now do the concurrent cleanup operation.
                _cm->completeCleanup();

                // Notify anyone who's waiting that there are no more free
                // regions coming. We have to do this before we join the STS
                // (in fact, we should not attempt to join the STS in the
                // interval between finishing the cleanup pause and clearing
                // the free_regions_coming flag) otherwise we might deadlock:
                // a GC worker could be blocked waiting for the notification
                // whereas this thread will be blocked for the pause to finish
                // while it's trying to join the STS, which is conditional on
                // the GC workers finishing.
                g1h->reset_free_regions_coming();
            }
            guarantee(cm()->cleanup_list_is_empty(),
                      "at this point there should be no regions on the cleanup list");

            // There is a tricky race before recording that the concurrent
            // cleanup has completed and a potential Full GC starting around
            // the same time. We want to make sure that the Full GC calls
            // abort() on concurrent mark after
            // record_concurrent_mark_cleanup_completed(), since abort() is
            // the method that will reset the concurrent mark state. If we
            // end up calling record_concurrent_mark_cleanup_completed()
            // after abort() then we might incorrectly undo some of the work
            // abort() did. Checking the has_aborted() flag after joining
            // the STS allows the correct ordering of the two methods. There
            // are two scenarios:
            //
            // a) If we reach here before the Full GC, the fact that we have
            // joined the STS means that the Full GC cannot start until we
            // leave the STS, so record_concurrent_mark_cleanup_completed()
            // will complete before abort() is called.
            //
            // b) If we reach here during the Full GC, we'll be held up from
            // joining the STS until the Full GC is done, which means that
            // abort() will have completed and has_aborted() will return
            // true to prevent us from calling
            // record_concurrent_mark_cleanup_completed() (and, in fact, it's
            // not needed any more as the concurrent mark state has been
            // already reset).
            {
                SuspendibleThreadSetJoiner sts_join;
                if (!cm()->has_aborted()) {
                    g1_policy->record_concurrent_mark_cleanup_completed();
                } else {
                    log_info(gc)("Concurrent Mark abort");
                }
            }

            // We now want to allow clearing of the marking bitmap to be
            // suspended by a collection pause.
            // We may have aborted just before the remark. Do not bother clearing the
            // bitmap then, as it has been done during mark abort.
            if (!cm()->has_aborted()) {
                GCConcPhaseTimer(_cm, "Concurrent Bitmap Clearing");
                _cm->clearNextBitmap();
            } else {
                assert(!G1VerifyBitmaps || _cm->nextMarkBitmapIsClear(), "Next mark bitmap must be clear");
            }
        }

        // Update the number of full collections that have been
        // completed. This will also notify the FullGCCount_lock in case a
        // Java thread is waiting for a full GC to happen (e.g., it
        // called System.gc() with +ExplicitGCInvokesConcurrent).
        {
            SuspendibleThreadSetJoiner sts_join;
            g1h->increment_old_marking_cycles_completed(true /* concurrent */);
            g1h->register_concurrent_cycle_end();
        }
    }
}
Ejemplo n.º 9
0
/* Compute analytic dynamics */
void computeAnalyticOutputs(std::map<const std::string, bool> &outs,
    struct PARAMETERS * p) {

  // energy spacing in bulk
  std::complex <double> dE ((p->kBandTop-p->kBandEdge)/(p->Nk-1), 0);
  // bulk-QD coupling
  std::complex <double> Vee (p->Vnobridge[0], 0);
  // rate constant (can be defined also as K/2)
  std::complex <double> K = std::complex <double> (3.1415926535,0)*pow(Vee,2)/dE;
  // time
  std::complex <double> t (0, 0);
  // energy differences
  std::complex <double> wnm (0, 0);
  std::complex <double> wnnp (0, 0);
  std::complex <double> wnpm (0, 0);
  // coefficients
  std::complex <double> cm (0, 0);
  std::complex <double> cn (0, 0);
  std::complex <double> cn_term1 (0, 0);
  std::complex <double> cn_term2 (0, 0);
  std::complex <double> cn_diag (0, 0);
  std::complex <double> cn_offdiag (0, 0);
  double cn_tot;
  // complex numbers are dumb
  std::complex <double> C0 (0.0, 0.0);
  std::complex <double> C1 (1.0, 0.0);
  std::complex <double> NEGC1 (-1.0, 0.0);
  std::complex <double> CI (0.0, 1.0);
  std::complex <double> NEGCI (0.0, -1.0);

  // unpack params a bit
  int Nk = p->Nk;
  int Nc = p->Nc;
  int Ik = p->Ik;
  int Ic = p->Ic;
  int N = p->NEQ;
  double * energies = &(p->energies[0]);
  double * startWfn = &(p->startWfn[0]);

  // Create matrix of energy differences
  std::vector<std::complex <double>> Elr (Nk*Nc, std::complex <double> (0.0, 0.0));
  for (int ii = 0; ii < Nk; ii++) {
    for (int jj = 0; jj < Nc; jj++) {
      // array follows convention that first index is for QC state
      // e.g. Elr[i*Nc + j] = E_{ij}
      Elr[ii*Nc + jj] = std::complex <double> (energies[Ik + ii] - energies[Ic + jj], 0);
    }
  }
#ifdef DEBUG_ANALYTIC
  std::cout << std::endl;
  std::cout << "Energy gaps:" << std::endl;
  for (int ii = 0; ii < Nc*Nk; ii++) {
    std::cout << Elr[ii] << " ";
  }
  std::cout << std::endl;
  std::cout << std::endl;
#endif

  // Create matrix of prefactors for each QC (n) state
  std::complex <double> pref;
  std::vector<std::complex <double>> prefQC (Nk*Nc, std::complex <double> (0.0, 0.0));
  for (int ii = 0; ii < Nk; ii++) {
    // V*c_l/(E_{lr} + i\kappa)
    pref = Vee*(std::complex <double> (startWfn[Ik + ii], startWfn[Ik + N + ii]));
    std::cout << startWfn[Ik + ii] << "," << pref << " ";
    for (int jj = 0; jj < Nc; jj++) {
      prefQC[ii*Nc + jj] = pref/(Elr[ii*Nc + jj] + CI*K);
    }
  }
#ifdef DEBUG_ANALYTIC
  std::cout << std::endl;
  for (int ii = 0; ii < Nc*Nk; ii++) {
    std::cout << prefQC[ii] << " ";
  }
  std::cout << std::endl;
  std::cout << std::endl;
#endif

  // calculate wavefunction coefficients on electron-accepting side over time
  std::vector<std::complex <double>> crt (Nc*p->numOutputSteps, std::complex <double> (0.0, 0.0));

  int timeIndex = 0;
  for (std::complex <double> t = C0; std::real(t) <= p->tout;
       t += std::complex <double> (p->tout/p->numOutputSteps, 0.0), timeIndex++) {
    for (int ii = 0; ii < Nc; ii++) {
      // TODO add bit for multiple state terms
      for (int jj = 0; jj < Nk; jj++) {
	crt[timeIndex*Nc + ii] += prefQC[jj]*(exp(NEGCI*Elr[jj*Nc + ii]*t) - exp(NEGC1*K*t));
      }
    }
  }
  
  // calculate populations on electron-accepting side over time
  std::vector<double> Prt (Nc*p->numOutputSteps, 0.0);
  for (int ii = 0; ii <= p->numOutputSteps; ii++) {
    for (int jj = 0; jj < Nc; jj++) {
      Prt[ii*Nc + jj] = pow(real(crt[ii*Nc + jj]), 2) + pow(imag(crt[ii*Nc + jj]), 2);
    }
  }

  if (isOutput(outs, "analytic_tcprob.out")) {
    std::ofstream output("analytic_tcprob.out");
    for (int ii = 0; ii <= p->numOutputSteps; ii++) {
      output << p->times[ii];
      for (int jj = 0; jj < Nc; jj++) {
	output << " " << Prt[ii*Nc + jj];
	output << " " << real(crt[ii*Nc + jj]) << " " << imag(crt[ii*Nc + jj]);
      }
      output << std::endl;
    }
    output.close();
  }

  return;
}
Ejemplo n.º 10
0
static int bch_dec(int c[255], int n, int t)
{
	int i, j, tmp;
	int s[4], a[6], b[6], temp[6], deg_a, deg_b;
	int sig[5], deg_sig;
	int errloc[4], errcnt;

	memset(s, 0, 4*sizeof(int));
	for (j=0; j<n; j++)
		for (i=0; i<t*2; i++)
			s[i] = cm(i+1, s[i]) ^ (c[j]&1);

	memset(a, 0, 6*sizeof(int));
	memset(b, 0, 6*sizeof(int));
	a[0] = 1;
	deg_a = t*2;
	for (i=0; i<t*2; i++) b[i] = s[t*2-1-i];
		deg_b = t*2-1;

	a[t*2+1] = 1;
	b[t*2+1] = 0;
	while (deg_b >= t) {
		if (b[0] == 0) {
			memmove(b, b+1, 5*sizeof(int));
			b[5] = 0;
			deg_b--;
        }
        else {
			for (i=t*2+1; i>deg_a; i--)
				b[i] = gm(b[i], b[0]) ^ gm(a[i], a[0]);
			for (i=deg_a; i>deg_b; i--) {
				b[i] = gm(b[i], b[0]);
				a[i] = gm(a[i], b[0]);
			}
			for (; i>0; i--)
				a[i] = gm(a[i], b[0]) ^ gm(b[i], a[0]);
				memmove(a, a+1, 5*sizeof(int));
				a[5] = 0;
				deg_a--;

			if (deg_a < deg_b) {
				memcpy(temp, a, 6*sizeof(int));
				memcpy(a, b, 6*sizeof(int));
				memcpy(b, temp, 6*sizeof(int));

				tmp = deg_a;
				deg_a = deg_b;
				deg_b = tmp;
			}
		}
	}

	deg_sig = t*2 - deg_a;
	memcpy(sig, a+deg_a+1, (deg_sig+1)*sizeof(int));

	errcnt = 0;
	for (j=0; j<255; j++) {
		tmp = 0;
		for (i=0; i<=deg_sig; i++) {
			sig[i] = cm(i, sig[i]);
			tmp ^= sig[i];
		}

		if (tmp == 0) {
			errloc[errcnt] = j - (255-n);
			if (errloc[errcnt] >= 0)
			errcnt++;
		}
	}

	if (errcnt<deg_sig) {
		return -1;
	}

	for (i=0; i<errcnt; i++) {
		c[errloc[i]] ^= 1;
		__D("fix error at %4d\n", errloc[i]);
	}

	return errcnt;
}