Ejemplo n.º 1
0
static
void assert_lengths(libnet_t* l, int ip_len, int ip_ihl, int payload_s)
{
    uint8_t* pkt1 = NULL;
    uint32_t pkt1_sz = 0;
    struct libnet_ipv4_hdr* h1;
    uint8_t* payload = NULL;


    int r = libnet_pblock_coalesce(l, &pkt1, &pkt1_sz);
    assert(r >= 0);

    print_pblocks(l);

    libnet_diag_dump_hex(pkt1, 14, 1, stdout);
    libnet_diag_dump_hex(pkt1+14, pkt1_sz-14, 1, stdout);

    // check ip IHL value, total ip pkt length, and options value
    h1 = (struct libnet_ipv4_hdr*) (pkt1+14);
    assert_eq(h1->ip_hl, ip_ihl); 
    assert_eq(ntohs(h1->ip_len), ip_len);

    payload = ((uint8_t*) h1) + ip_ihl * 4;
    if(payload_s > 0) {
        assert(payload[0] == (uint8_t)'\x99');
        assert(payload[payload_s-1] == (uint8_t)'\x99');
    }
}
Ejemplo n.º 2
0
static void TestCollateNestedArrays()
{
    fprintf(stderr, "nesting... ");
    CollateJSONMode mode = kCollateJSON_Unicode;
    assert_eq(collateStrs("[[]]", "[]", mode), 1);
    assert_eq(collateStrs("[1,[2,3],4]", "[1,[2,3.1],4,5,6]", mode), -1);
}
Ejemplo n.º 3
0
void test_reindexed (Context const &context)
{
    typedef Tenh::AbstractIndex_c<'i'> i;
    typedef Tenh::AbstractIndex_c<'j'> j;
    typedef Tenh::AbstractIndex_c<'k'> k;
    typedef Tenh::AbstractIndex_c<'P'> P;
    typedef Tenh::Typle_t<i,j,P> DomainIndexTyple;
    typedef Tenh::Typle_t<j,P,k> CodomainIndexTyple;
    typedef Tenh::Reindex_e<DomainIndexTyple,CodomainIndexTyple> Reindex;

    assert((Tenh::TypesAreEqual_f<Reindex::Eval_f<Tenh::DimIndex_t<'i',42>>::T,Tenh::DimIndex_t<'j',42>>::V));
    assert((Tenh::TypesAreEqual_f<Reindex::Eval_f<Tenh::DimIndex_t<'j',8>>::T,Tenh::DimIndex_t<'P',8>>::V));
    assert((Tenh::TypesAreEqual_f<Reindex::Eval_f<Tenh::DimIndex_t<'P',3>>::T,Tenh::DimIndex_t<'k',3>>::V));

    static Tenh::AbstractIndexSymbol const OFFSET = 'k'; // this is the max of {'j','k','P'}

    // ensure that the reindexed<...>() function works on DimIndex_t types, using a
    // hacky, but effective, way to compare them (via type_as_string).
    assert_eq(type_string_of(Tenh::reindexed<DomainIndexTyple,CodomainIndexTyple>(Tenh::DimIndex_t<'i',10>())),
              type_string_of(Tenh::DimIndex_t<'j',10>())); // expected value
    assert_eq(type_string_of(Tenh::reindexed<DomainIndexTyple,CodomainIndexTyple>(Tenh::DimIndex_t<'j',20>())),
              type_string_of(Tenh::DimIndex_t<'P',20>())); // expected value
    assert_eq(type_string_of(Tenh::reindexed<DomainIndexTyple,CodomainIndexTyple>(Tenh::DimIndex_t<'k',30>())),
              type_string_of(Tenh::DimIndex_t<OFFSET+'k',30>())); // expected value
    assert_eq(type_string_of(Tenh::reindexed<DomainIndexTyple,CodomainIndexTyple>(Tenh::DimIndex_t<'P',40>())),
              type_string_of(Tenh::DimIndex_t<'k',40>())); // expected value
}
Ejemplo n.º 4
0
Archivo: tree.c Proyecto: rcr/rirc
static void
test_avl_get_height(void)
{
	struct test_avl t0 = { .node = { .height = 1 }};

	assert_eq(test_avl_list_AVL_GET_HEIGHT(&t0),  1);
	assert_eq(test_avl_list_AVL_GET_HEIGHT(NULL), 0);
}
Ejemplo n.º 5
0
//--------------------------------------------------------------------------
void VeThread::Init() noexcept
{
#	ifndef VE_USE_THREAD_LOCAL
#	ifdef VE_MEM_DEBUG
	assert_eq(pthread_key_create(&g_keyDeleteStack, nullptr), 0);
#	endif
	assert_eq(pthread_key_create(&s_keySingleton, nullptr), 0);
#	endif
	InitPerThread();
}
Ejemplo n.º 6
0
//--------------------------------------------------------------------------
void VeThread::Term() noexcept
{
	TermPerThread();
#	ifndef VE_USE_THREAD_LOCAL
	assert_eq(pthread_key_delete(s_keySingleton), 0);
#	ifdef VE_MEM_DEBUG
	assert_eq(pthread_key_delete(g_keyDeleteStack), 0);
#	endif
#	endif
}
Ejemplo n.º 7
0
void WriteSlice( 
    const QuadratureRules& QuadFuncs, 
    const dTensor3& qin, const int i, const int j, dTensorBC5& qout )
{

    const int sorder = dogParams.get_space_order();

    const int mx   = dogParamsCart2.get_mx();
    const int my   = dogParamsCart2.get_my();
    const int kmax = qout.getsize(5);

    const int NumElems = qin.getsize(1);

    assert_eq( kmax, QuadFuncs.get_kmax() );

    const int& kmax2d = QuadFuncs.get_kmax2d();

    // 4D weights, points and polynomials:
    const dTensor2& wgts = QuadFuncs.get_wgt();
    const dTensor3& spts = QuadFuncs.get_spts();
    const dTensor3& phi  = QuadFuncs.get_phi();

    const int& mpoints_unst = wgts.getsize(1);   
    const int& mpoints_cart = wgts.getsize(2);   
    assert_eq( mpoints_cart, qin.getsize(2) );

    const dTensor2& phi_unst  = QuadFuncs.get_phi_unst();
    for( int n=1; n <= NumElems; n++ )
    {

        // loop over each polynomial:
        for( int k=1; k <= kmax; k++ )
        {
            double tmp = 0.;
            for( int m1=1; m1 <= mpoints_unst; m1++ )
            {
                for( int m2=1; m2 <= mpoints_cart; m2++ )
                {
                    // Evaluate q at this point:
                    double q = 0.;
                    for( int k2=1; k2 <= kmax2d; k2++ )
                    {
                        q += phi_unst.get(m1,k2) * qin.get(n, m2, k2 );
                    }

                    // Compute phi*q, add this to the running total:
                    tmp += q * phi.get(m1,m2,k)*wgts.get(m1,m2);

                }
            }
            qout.set(i, j, n, 1, k, 0.5*tmp );
        }
    }

}
Ejemplo n.º 8
0
//--------------------------------------------------------------------------
void VeThread::InitPerThread() noexcept
{
#	ifdef VE_USE_THREAD_LOCAL
	s_pkSingleton = VE_NEW VeThreadLocalSingleton();
#	else
#	ifdef VE_MEM_DEBUG
	assert_eq(pthread_setspecific(g_keyDeleteStack, new vtd::vector<VeDeleteCallParams>()), 0);
#	endif
	assert_eq(pthread_setspecific(s_keySingleton, VE_NEW VeThreadLocalSingleton()), 0);
#	endif
}
Ejemplo n.º 9
0
static void TestCollateUnicodeStrings()
{
    /* Make sure that TDJSON never creates escape sequences we can't parse.
       That includes "\unnnn" for non-ASCII chars, and "\t", "\b", etc. */
    fprintf(stderr, "Unicode... ");
    CollateJSONMode mode = kCollateJSON_Unicode;
    assert_eq(collateStrs("\"fréd\"", "\"fréd\"", mode), 0);
    assert_eq(collateStrs("\"ømø\"",  "\"omo\"", mode), 1);
    assert_eq(collateStrs("\"\t\"",   "\" \"", mode), -1);
    assert_eq(collateStrs("\"\001\"", "\" \"", mode), -1);
}
Ejemplo n.º 10
0
/**
 * Check that this Ebwt, when restored via restore(), matches up with
 * the given array of reference sequences.  For sanity checking.
 */
void Ebwt::checkOrigs(
	const EList<SString<char> >& os,
	bool color,
	bool mirror) const
{
	SString<char> rest;
	restore(rest);
	uint32_t restOff = 0;
	size_t i = 0, j = 0;
	if(mirror) {
		// TODO: FIXME
		return;
	}
	while(i < os.size()) {
		size_t olen = os[i].length();
		int lastorig = -1;
		for(; j < olen; j++) {
			size_t joff = j;
			if(mirror) joff = olen - j - 1;
			if((int)os[i][joff] == 4) {
				// Skip over Ns
				lastorig = -1;
				if(!mirror) {
					while(j < olen && (int)os[i][j] == 4) j++;
				} else {
					while(j < olen && (int)os[i][olen-j-1] == 4) j++;
				}
				j--;
				continue;
			}
			if(lastorig == -1 && color) {
				lastorig = os[i][joff];
				continue;
			}
			if(color) {
				assert_neq(-1, lastorig);
				assert_eq(dinuc2color[(int)os[i][joff]][lastorig], rest[restOff]);
			} else {
				assert_eq(os[i][joff], rest[restOff]);
			}
			lastorig = (int)os[i][joff];
			restOff++;
		}
		if(j == os[i].length()) {
			// Moved to next sequence
			i++;
			j = 0;
		} else {
			// Just jumped over a gap
		}
	}
}
Ejemplo n.º 11
0
int main()
{
	FILE *f = openLog("unitTestLog.txt");
	cunit_init();	// Initiate CUnit
	Roots root;
	Terms terms;

	// First unit test, should
	//terms.a = "1", terms.b = "2", terms.c = "1";
	terms = validateInput("1", "2", "1");
	if (terms.input == 1)
	{
		root = eqnControl(terms.a, terms.b, terms.c);
		
		//fwrite(assert_neq("x1", root.x1, -2.0), f);
		assert_neq("x1", root.x1, -2.0);
		fprintf(f, "x1: %f assert not equal %f\n", (double)root.x1, -2.0);
		assert_neq("x2", root.x2, -2.0);
		fprintf(f, "x2: %f assert not equal %f\n", (double)root.x2, -2.0);
	}

	printf("-------------------------------\n");

	//terms.a = "2"; terms.b = "5"; terms.c = "-3";
	terms = validateInput("2", "5", "-3");
	if (terms.input == 1)
	{
		root = eqnControl(terms.a, terms.b, terms.c);
		assert_eq("x1", root.x1, 0.5);
		fprintf(f, "x1: %f assert equal %f\n", (double)root.x1, 0.5);
		assert_eq("x2", root.x2, -3.0);
		fprintf(f, "x2: %f assert equal %f\n", (double)root.x2, -3.0);
	}	

	printf("-------------------------------\n");
	//char terms.a, terms.b, terms.c;
	//terms.a = "a"; terms.b = "b"; terms.c = "c";
	terms = validateInput("a", "b", "c");
	if (terms.input == 1)
	{
		root = eqnControl(terms.a, terms.b, terms.c);
		assert_eq("x1", root.x1, 0.5);
		fprintf(f, "x1: %f assert equal %f\n", (double)root.x1, 0.5);
		assert_eq("x2", root.x2, -3.0);
		fprintf(f, "x2: %f assert equal %f\n", (double)root.x2, -3.0);
	}
	fclose(f);
}
Ejemplo n.º 12
0
/**
 * Reverse the 'src' list of RefRecords into the 'dst' list.  Don't
 * modify 'src'.
 */
void reverseRefRecords(const vector<RefRecord>& src,
					   vector<RefRecord>& dst,
					   bool recursive,
					   bool verbose)
{
	dst.clear();
	{
		vector<RefRecord> cur;
		for(int i = src.size()-1; i >= 0; i--) {
			bool first = (i == (int)src.size()-1 || src[i+1].first);
			if(src[i].len) {
				cur.push_back(RefRecord(0, src[i].len, first));
				first = false;
			}
			if(src[i].off) cur.push_back(RefRecord(src[i].off, 0, first));
		}
		bool mergedLast;
		for(int i = 0; i < (int)cur.size(); i++) {
			mergedLast = false;
			assert(cur[i].off == 0 || cur[i].len == 0);
			if(i < (int)cur.size()-1 && cur[i].off != 0 && !cur[i+1].first) {
				dst.push_back(RefRecord(cur[i].off, cur[i+1].len, cur[i].first));
				i++;
				mergedLast = true;
			} else {
				dst.push_back(cur[i]);
			}
		}
	}
	if(verbose) {
		cout << "Source: " << endl;
		printRecords(cout, src);
		cout << "Dest: " << endl;
		printRecords(cout, dst);
	}
#ifndef NDEBUG
	if(!recursive) {
		vector<RefRecord> tmp;
		reverseRefRecords(dst, tmp, true);
		assert_eq(tmp.size(), src.size());
		for(size_t i = 0; i < src.size(); i++) {
			assert_eq(src[i].len, tmp[i].len);
			assert_eq(src[i].off, tmp[i].off);
			assert_eq(src[i].first, tmp[i].first);
		}
	}
#endif
}
Ejemplo n.º 13
0
void TimeTasks::start(int taskid)
{
  assert_eq(active_task+1,taskid);
  active_task = taskid;
  double now = MPI_Wtime();
  start_times[active_task] = now;
}
Ejemplo n.º 14
0
void StepLxW( double dt, const dTensorBC4& qold,
    const dTensorBC4& L, dTensorBC4& qnew )
{

    const int numel = qnew.numel();
    assert_eq(qold.numel(),numel);
    assert_eq(L.numel(),numel);

#pragma omp parallel for
    for(int v=0;v<numel;v++)
    {
        double tmp = qold.vget(v) + dt*L.vget(v);
        qnew.vset(v, tmp );
    }

}
Ejemplo n.º 15
0
void TimeTasks::start_communicate()
{
  if(!active_task) return;
  assert_eq(active_mode,COMPUTATION);
  t_start_communicate = MPI_Wtime();
  active_mode=COMMUNICATION;
}
Ejemplo n.º 16
0
void TimeTasks::end(int taskid)
{
  assert_eq(taskid,active_task);
  double now = MPI_Wtime();
  task_duration[active_task] = now - start_times[active_task];
  compute[active_task] = task_duration[active_task]-communicate[active_task];
}
Ejemplo n.º 17
0
// Initial data from the file qXXXX_restart.dat (where XXXX=nstart)
static double ReadStateArrayASCII(string fname, dTensorBC5& q)
{
    fname += ".dat";
    // ifstream restart_file(fname.c_str(), ios::in);
    FILE* restart_file = fopen(fname.c_str(), "r");
    //if(!restart_file.is_open())
    if(!restart_file) eprintf("could not open for reading: %s\n", fname.c_str());

    double t;
    int numconv = fscanf(restart_file,"%lf",&t);
    assert(numconv==1);
    const int mx   = q.getsize(1);
    const int my   = q.getsize(2);
    const int mz   = q.getsize(3);
    const int meqn = q.getsize(4);
    const int kmax = q.getsize(5);
    for (int ell=1; ell<=kmax; ell++)
      for (int m=1; m<=meqn; m++)
	for (int k=1; k<=mz; k++)   
	  for (int j=1; j<=my; j++)   
	    for (int i=1; i<=mx; i++)
	      {
		double datum;
		int numconv = fscanf(restart_file,"%lf",&datum);
		if(numconv!=1) eprintf("scan failed at "
				       "i=%d, j=%d, m=%d, k=%d in file %s", i,j,m,k,fname.c_str());
		q.set(i,j,k,m,ell, datum);
	      }
    
    double tmp;
    numconv = fscanf(restart_file,"%lf",&tmp);
    assert_eq(numconv,EOF);
    fclose(restart_file);
    return t;
}
Ejemplo n.º 18
0
static void TestPDFDict(skiatest::Reporter* reporter) {
    sk_sp<SkPDFDict> dict(new SkPDFDict);
    assert_emit_eq(reporter, *dict, "<<>>");

    dict->insertInt("n1", SkToSizeT(42));
    assert_emit_eq(reporter, *dict, "<</n1 42>>");

    dict.reset(new SkPDFDict);
    assert_emit_eq(reporter, *dict, "<<>>");

    dict->insertInt("n1", 42);
    assert_emit_eq(reporter, *dict, "<</n1 42>>");

    dict->insertScalar("n2", SK_ScalarHalf);

    SkString n3("n3");
    sk_sp<SkPDFArray> innerArray(new SkPDFArray);
    innerArray->appendInt(-100);
    dict->insertObject(n3, std::move(innerArray));
    assert_emit_eq(reporter, *dict, "<</n1 42\n/n2 .5\n/n3 [-100]>>");

    dict.reset(new SkPDFDict);
    assert_emit_eq(reporter, *dict, "<<>>");

    dict->insertInt("n1", 24);
    assert_emit_eq(reporter, *dict, "<</n1 24>>");

    dict->insertInt("n2", SkToSizeT(99));
    assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99>>");

    dict->insertScalar("n3", SK_ScalarHalf);
    assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5>>");

    dict->insertName("n4", "AName");
    assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName>>");

    dict->insertName("n5", SkString("AnotherName"));
    assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName\n"
                   "/n5 /AnotherName>>");

    dict->insertString("n6", "A String");
    assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName\n"
                   "/n5 /AnotherName\n/n6 (A String)>>");

    dict->insertString("n7", SkString("Another String"));
    assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName\n"
                   "/n5 /AnotherName\n/n6 (A String)\n/n7 (Another String)>>");

    dict.reset(new SkPDFDict("DType"));
    assert_emit_eq(reporter, *dict, "<</Type /DType>>");

    sk_sp<SkPDFArray> referencedArray(new SkPDFArray);
    Catalog catalog;
    catalog.numbers.addObject(referencedArray.get());
    REPORTER_ASSERT(reporter, catalog.numbers.getObjectNumber(
                            referencedArray.get()) == 1);
    dict->insertObjRef("n1", std::move(referencedArray));
    SkString result = emit_to_string(*dict, &catalog);
    assert_eq(reporter, result, "<</Type /DType\n/n1 1 0 R>>");
}
Ejemplo n.º 19
0
	bool happensBefore(Context &context, const core::StatementAddress& a, const core::StatementAddress& b, bool debug)
	{
		assert_eq(a.getRootNode(), b.getRootNode());

		// Instantiate analysis
		auto &analysis = context.getAnalysis<souffle::Sf_happens_before_analysis>(a.getRootNode(), debug);

		// Get ID of both statements
		int targetStartID = context.getNodeID(a);
		int targetEndID = context.getNodeID(b);

		// Get result
		auto &resultRel = analysis.rel_Result;

		// Filter for first value in result set
		auto tmp = resultRel.template equalRange<0>({{targetStartID,0}});

		// Filter for second value in result set
		for (auto it = tmp.begin(); it != tmp.end(); ++it) {
			// Found target end
			if ((*it)[1] == targetEndID) {
				// Check result size
				if (++it == tmp.end() || (*it)[1] != targetEndID)
					return true; // Only value, good!
				assert_fail() << "Happens-before analysis seems to be broken!";
				return false;
			}
		}

		return false;
	}
Ejemplo n.º 20
0
	/** Test {@link Minimizable::calculateFunctionAndDerivative} in 0-dimensional case. */
	void MinimizableTest::test0dim () {
		const AutoVector minVec( 0 );
		TestMinimizable minimizable( minVec );
		const AutoVector x( 0 );
		double f;
		AutoVector df( 0 );
		minimizable.calculateFunction( x, f );
		assert_eq( "function value", 0.0, f );

		minimizable.calculateDerivative( x, df );
		assert_eq( "derivative dimension", 0, df.countDimensions() );

		minimizable.calculateFunctionAndDerivative( x, f, df );
		assert_eq( "again function value", 0.0, f );
		assert_eq( "again derivative dimension", 0, df.countDimensions() );
	}
Ejemplo n.º 21
0
// Read in q(:,:,n, 1:meqn=1, 1:kmax4d) into qout(:, :, 1:npts_unst, 1:kmax2d )
void ReadSlice( 
    const QuadratureRules& QuadFuncs, 
    const dTensorBC5& qin, const int n, dTensorBC4& qout )
{

    const int mx            = qout.getsize(1);  assert_eq( mx, dogParamsCart2.get_mx() );
    const int my            = qout.getsize(2);  assert_eq( my, dogParamsCart2.get_my() );
    const int mpoints_unst  = qout.getsize(3);
    const int kmax2d        = qout.getsize(4);

    const int kmax = qin.getsize(5);

    // 2D weights, points and polynomials:
    const dTensor1& wgts_cart = QuadFuncs.get_wgt_cart();
    const dTensor2& spts_cart = QuadFuncs.get_spts_cart();
    const dTensor2& phi_cart  = QuadFuncs.get_phi_cart();

    const int mpoints_cart = spts_cart.getsize(1);

    // 4D weights, points and polynomials:
    const dTensor2& wgts = QuadFuncs.get_wgt();
    const dTensor3& spts = QuadFuncs.get_spts();
    const dTensor3& phi  = QuadFuncs.get_phi();

    // This loop is assumed to be 'fast', because it is in 2D, and not 4D
    for( int i=1; i <= mx; i++ )
    for( int j=1; j <= my; j++ )
    for( int m1=1; m1 <= mpoints_unst; m1++ )
    {
        for( int k2=1; k2 <= kmax2d; k2++ )
        {
            double tmp = 0.;
            for( int m2=1; m2 <= mpoints_cart; m2++ )
            {
                // evaluate q at this point:
                double q = 0.;
                for( int  k=1; k <= kmax; k++ )
                {
                    q += qin.get(i,j,n, 1, k ) * phi.get(m1,m2,k);
                }
                tmp += q * phi_cart.get(m2,k2) * wgts_cart.get(m2);
            }
            qout.set(i, j, m1, k2, 0.25*tmp );
        }
    }

}
Ejemplo n.º 22
0
void WriteSlice( 
    const QuadratureRules& QuadFuncs, 
    const dTensorBC4& qin, const int n, dTensorBC5& qout )
{

    const int mx = qin.getsize(1);  assert_eq( mx, dogParamsCart2.get_mx() );
    const int my = qin.getsize(2);  assert_eq( my, dogParamsCart2.get_my() );
    const int kmax2d = qin.getsize(4);
    const int kmax = qout.getsize(5);

    // 4D weights, points and polynomials:
    const dTensor2& wgts = QuadFuncs.get_wgt();
    const dTensor3& spts = QuadFuncs.get_spts();
    const dTensor3& phi  = QuadFuncs.get_phi();

    const int& mpoints_unst = wgts.getsize(1);   
    const int& mpoints_cart = wgts.getsize(2);   

    const dTensor2& phi_cart  = QuadFuncs.get_phi_cart();

    for( int i=1; i <= mx; i++ )
    for( int j=1; j <= my; j++ )
    {

        // loop over each polynomial:
        for( int k=1; k <= kmax; k++ )
        {
            double tmp = 0.;
            for( int m2=1; m2 <= mpoints_cart; m2++ )
            {
                for( int m1=1; m1 <= mpoints_unst; m1++ )
                {
                    // Evaluate q at this point:
                    double q = 0.;
                    for( int k2=1; k2 <= kmax2d; k2++ )
                    {
                        q += phi_cart.get(m2,k2) * qin.get(i,j, m1, k2 );
                    }

                    // Compute phi*q, add this to the running total:
                    tmp += q * phi.get(m1,m2,k)*wgts.get(m1,m2);
                }
            }
            qout.set(i, j, n, 1, k, 0.5*tmp );
        }
    }
}
Ejemplo n.º 23
0
void TimeTasks::print_cycle_times(int cycle)
{
  if(!is_output_thread()) return;
  FILE* file = stdout;
  // we could report average for all processes
  //if(!MPIdata::get_rank())
  {
    fflush(file);
    fprintf(file,"=== times for cycle %d for rank %d === \n",
      cycle,
      MPIdata::get_rank());
    fprintf(file, TIMING_PREFIX "total  comput commun task\n");
    for(int e=NONE+1; e<LAST; e++)
    {
      fprintf(file, TIMING_PREFIX "%6.3f %6.3f %6.3f %s\n",
      get_time(e),
      get_compute(e),
      communicate[e],
      get_taskname(e));
    }

    // report total times
    //
    // get total time spent on exclusive tasks
    //
    double total_task_duration = 0.;
    for (int i = NONE + 1; i < LAST; i++) {
      total_task_duration += task_duration[i];
    }
    // get total time spent in exclusive tasks spent communicating
    //
    double total_communicate = 0.;
    for (int i = NONE + 1; i < LAST; i++) {
      total_communicate += communicate[i];
    }
    const double total_computing_time = total_task_duration - total_communicate;
    fprintf(file, TIMING_PREFIX "%6.3f %6.3f %6.3f %s\n",
      total_task_duration,
      total_computing_time,
      total_communicate,
      "[total times]");

    fprintf(file, TIMING_PREFIX "time   subtask\n");
    for(int e=LAST+1; e<NUMBER_OF_TASKS; e++)
    {
      // do not show tasks that are not executed
      double elapsed_time = get_time(e);
      if(!elapsed_time)
        continue;

      assert_eq(stack_depth[e],0);
      fprintf(file, TIMING_PREFIX "%6.3f %s\n",
      elapsed_time,
      get_taskname(e));
    }
    
    fflush(file);
  }
}
Ejemplo n.º 24
0
test_case(p1, CarryOut) {
  assert_eq(F, CarryOut(F, F, F));
  assert_eq(F, CarryOut(T, F, F));
  assert_eq(F, CarryOut(F, T, F));
  assert_eq(T, CarryOut(T, T, F));
  assert_eq(F, CarryOut(F, F, T));
  assert_eq(T, CarryOut(T, F, T));
  assert_eq(T, CarryOut(F, T, T));
  assert_eq(T, CarryOut(T, T, T));
}
Ejemplo n.º 25
0
test_case(p1, Sum3) {
  assert_eq(F, Sum(F, F, F));
  assert_eq(T, Sum(T, F, F));
  assert_eq(T, Sum(F, T, F));
  assert_eq(F, Sum(T, T, F));
  assert_eq(T, Sum(F, F, T));
  assert_eq(F, Sum(T, F, T));
  assert_eq(F, Sum(F, T, T));
  assert_eq(T, Sum(T, T, T));
}
Ejemplo n.º 26
0
test_case(p1, Mux) {
  assert_eq(F, Mux(T, F, F));
  assert_eq(T, Mux(T, T, F));
  assert_eq(F, Mux(T, F, T));
  assert_eq(T, Mux(T, T, T));
  assert_eq(F, Mux(F, F, F));
  assert_eq(F, Mux(F, T, F));
  assert_eq(T, Mux(F, F, T));
  assert_eq(T, Mux(F, T, T));
}
Ejemplo n.º 27
0
void TimeTasks::addto_communicate()
{
  if(!active_task) return;
  assert_eq(active_mode,COMMUNICATION);
  assert_ne(t_start_communicate,0.);
  communicate[active_task] += MPI_Wtime()-t_start_communicate;
  t_start_communicate = 0.;
  active_mode=COMPUTATION;
}
Ejemplo n.º 28
0
 static void writeArrayToBinaryFileStream(std::ofstream& fileStream,
         const T* array, const size_t sizeOfArray) {
     assert_gt(sizeOfArray, 0);
     auto bufferSize = (std::streamsize)(sizeOfArray * sizeof(T));
     auto previousNumberOfBytes = fileStream.tellp();
     assert_true(fileStream.write(reinterpret_cast<const char*>(array), bufferSize));
     auto currentNumberOfBytes = fileStream.tellp();
     assert_eq(bufferSize, currentNumberOfBytes - previousNumberOfBytes);
 }
Ejemplo n.º 29
0
int main()
{
	Coef coefs;
	int ret;
	char *input = "1 a 1";
	cunit_init();
	ret = input_val(&coefs, input);
	assert_eq("ret", ret, 0);
}
Ejemplo n.º 30
0
	/** Test {@link Minimizable::calculateFunctionAndDerivative} in 1-dimensional case. */
	void MinimizableTest::test1dim () {
		AutoVector minVec( 1 );
		minVec.set( 0, 0.0 );
		TestMinimizable minimizable( minVec );
		AutoVector x( 1 );
		double f;
		AutoVector df( 1 );

		x.set( 0, 1.0 );
		minimizable.calculateFunction( x, f );
		assert_eq( "function value", 1.0, f );

		minimizable.calculateDerivative( x, df );
		assert_eq( "derivative", 2.0, df.get( 0 ) );

		minimizable.calculateFunctionAndDerivative( x, f, df );
		assert_eq( "again function value", 1.0, f );
		assert_eq( "again derivative", 2.0, df.get( 0 ) );
	}