コード例 #1
0
ファイル: c1_Canonicalizer.cpp プロジェクト: lmsf/jdk9-dev
void Canonicalizer::do_ArrayLength    (ArrayLength*     x) {
  NewArray*  na;
  Constant*  ct;
  LoadField* lf;

  if ((na = x->array()->as_NewArray()) != NULL) {
    // New arrays might have the known length.
    // Do not use the Constant itself, but create a new Constant
    // with same value Otherwise a Constant is live over multiple
    // blocks without being registered in a state array.
    Constant* length;
    if (na->length() != NULL &&
        (length = na->length()->as_Constant()) != NULL) {
      assert(length->type()->as_IntConstant() != NULL, "array length must be integer");
      set_constant(length->type()->as_IntConstant()->value());
    }

  } else if ((ct = x->array()->as_Constant()) != NULL) {
    // Constant arrays have constant lengths.
    ArrayConstant* cnst = ct->type()->as_ArrayConstant();
    if (cnst != NULL) {
      set_constant(cnst->value()->length());
    }

  } else if ((lf = x->array()->as_LoadField()) != NULL) {
    ciField* field = lf->field();
    if (field->is_static_constant()) {
      assert(PatchALot || ScavengeRootsInCode < 2, "Constant field loads are folded during parsing");
      ciObject* c = field->constant_value().as_object();
      if (!c->is_null_object()) {
        set_constant(c->as_array()->length());
      }
    }
  }
}
コード例 #2
0
ファイル: c1_Canonicalizer.cpp プロジェクト: lizhekang/TCJDK
void Canonicalizer::do_ShiftOp        (ShiftOp*         x) {
  ValueType* t = x->x()->type();
  ValueType* t2 = x->y()->type();
  if (t->is_constant()) {
    switch (t->tag()) {
    case intTag   : if (t->as_IntConstant()->value() == 0)         { set_constant(0); return; } break;
    case longTag  : if (t->as_LongConstant()->value() == (jlong)0) { set_constant(jlong_cast(0)); return; } break;
    default       : ShouldNotReachHere();
    }
    if (t2->is_constant()) {
      if (t->tag() == intTag) {
        int value = t->as_IntConstant()->value();
        int shift = t2->as_IntConstant()->value() & 31;
        jint mask = ~(~0 << (32 - shift));
        if (shift == 0) mask = ~0;
        switch (x->op()) {
          case Bytecodes::_ishl:  set_constant(value << shift); return;
          case Bytecodes::_ishr:  set_constant(value >> shift); return;
          case Bytecodes::_iushr: set_constant((value >> shift) & mask); return;
        }
      } else if (t->tag() == longTag) {
        jlong value = t->as_LongConstant()->value();
        int shift = t2->as_IntConstant()->value() & 63;
        jlong mask = ~(~jlong_cast(0) << (64 - shift));
        if (shift == 0) mask = ~jlong_cast(0);
        switch (x->op()) {
          case Bytecodes::_lshl:  set_constant(value << shift); return;
          case Bytecodes::_lshr:  set_constant(value >> shift); return;
          case Bytecodes::_lushr: set_constant((value >> shift) & mask); return;
        }
      }
コード例 #3
0
ファイル: c1_Canonicalizer.cpp プロジェクト: lizhekang/TCJDK
void Canonicalizer::do_ArrayLength    (ArrayLength*     x) {
  NewArray* array = x->array()->as_NewArray();
  if (array != NULL && array->length() != NULL) {
    Constant* length = array->length()->as_Constant();
    if (length != NULL) {
      // do not use the Constant itself, but create a new Constant
      // with same value Otherwise a Constant is live over multiple
      // blocks without being registered in a state array.
      assert(length->type()->as_IntConstant() != NULL, "array length must be integer");
      set_constant(length->type()->as_IntConstant()->value());
    }
  } else {
    LoadField* lf = x->array()->as_LoadField();
    if (lf != NULL) {
      ciField* field = lf->field();
      if (field->is_constant() && field->is_static()) {
        // final static field
        ciObject* c = field->constant_value().as_object();
        if (c->is_array()) {
          ciArray* array = (ciArray*) c;
          set_constant(array->length());
        }
      }
    }
  }
}
コード例 #4
0
ファイル: c1_Canonicalizer.cpp プロジェクト: lizhekang/TCJDK
void Canonicalizer::do_NegateOp(NegateOp* x) {
  ValueType* t = x->x()->type();
  if (t->is_constant()) {
    switch (t->tag()) {
      case intTag   : set_constant(-t->as_IntConstant   ()->value()); return;
      case longTag  : set_constant(-t->as_LongConstant  ()->value()); return;
      case floatTag : set_constant(-t->as_FloatConstant ()->value()); return;
      case doubleTag: set_constant(-t->as_DoubleConstant()->value()); return;
      default       : ShouldNotReachHere();
    }
  }
}
コード例 #5
0
ファイル: theme.cpp プロジェクト: nitpum/godot
bool Theme::_set(const StringName& p_name, const Variant& p_value) {

    String sname=p_name;

    if (sname.find("/")!=-1) {

        String type=sname.get_slicec('/',1);
        String node_type=sname.get_slicec('/',0);
        String name=sname.get_slicec('/',2);

        if (type=="icons") {

            set_icon(name,node_type,p_value);
        } else if (type=="styles") {

            set_stylebox(name,node_type,p_value);
        } else if (type=="fonts") {

            set_font(name,node_type,p_value);
        } else if (type=="colors") {

            set_color(name,node_type,p_value);
        } else if (type=="constants") {

            set_constant(name,node_type,p_value);
        } else
            return false;

        return true;
    }

    return false;

}
コード例 #6
0
TEST(BasicSial,DISABLED_exit_statement_test) {
    std::string job("exit_statement_test");
    sip::DataManager::scope_count=0;
    double x = 3.456;
    double y = -0.1;
    int norb = 3;
    {
        init_setup(job.c_str());
        set_scalar("x",x);
        set_scalar("y",y);
        set_constant("norb",norb);
        std::string tmp = job + ".siox";
        const char* nm= tmp.c_str();
        add_sial_program(nm);
        int segs[]  = {2,3,4,2,3,4,2,3,4,2,3,4,2,3,4};
        set_aoindex_info(15,segs);
        finalize_setup();
    }
    std::stringstream output;
    TestControllerParallel controller(job, true, VERBOSE_TEST, "", output);
    controller.initSipTables();
    controller.run();
    if(attr->is_worker()) {
        EXPECT_DOUBLE_EQ(12, controller.int_value("counter_j"));
        EXPECT_DOUBLE_EQ(4, controller.int_value("counter_i"));
        EXPECT_EQ(0, sip::DataManager::scope_count);
        EXPECT_TRUE(controller.worker_->all_stacks_empty());
        EXPECT_EQ(0, controller.worker_->num_blocks_in_blockmap());
    }
}
コード例 #7
0
void Canonicalizer::do_ShiftOp        (ShiftOp*         x) {
  ValueType* t = x->x()->type();
  if (t->is_constant()) {
    switch (t->tag()) {
      case intTag   : if (t->as_IntConstant()->value() == 0)  set_constant(0); return;
      case longTag  : if (t->as_LongConstant()->value() == (jlong)0) set_constant(jlong_cast(0)); return;
      default       : ShouldNotReachHere();
    }
  }
  ValueType* t2 = x->y()->type();
  if (t2->is_constant()) {
    switch (t2->tag()) {
      case intTag   : if (t2->as_IntConstant()->value() == 0)  set_canonical(x->x()); return;
      default       : ShouldNotReachHere();
    }
  }
}
コード例 #8
0
ファイル: test_sial.cpp プロジェクト: BB-Goldstein/aces4
void basic_pardo_test(int max_dims, int lower[], int upper[],
		bool expect_success = true) {
	assert(max_dims <= 6);
	for (int num_dims = 1; num_dims <= 6; ++num_dims) {
		std::stringstream job_ss;
		job_ss << "pardo_loop_" << num_dims << "d";
		std::string job = job_ss.str();

		//total number of iters for this sial program
		int num_iters = 1;
		for (int j = 0; j < num_dims; ++j) {
			num_iters *= ((upper[j] - lower[j]) + 1);
		}

		//create .dat file
		if (attr->global_rank() == 0) {
			init_setup(job.c_str());
			//add values for upper and lower bounds
			for (int i = 0; i < num_dims; ++i) {
				std::stringstream lower_ss, upper_ss;
				lower_ss << "lower" << i;
				upper_ss << "upper" << i;
				set_constant(lower_ss.str().c_str(), lower[i]);
				set_constant(upper_ss.str().c_str(), upper[i]);
			}
			std::string tmp = job + ".siox";
			const char* nm = tmp.c_str();
			add_sial_program(nm);
			finalize_setup();
		}

		TestControllerParallel controller(job, true, VERBOSE_TEST,
				"This is a test of " + job, std::cout, expect_success);
		controller.initSipTables();
		controller.run();
		if (attr->global_rank() == 0) {
			double total = controller.worker_->scalar_value("total");
			if (VERBOSE_TEST) {
				std::cout << "num_iters=" << num_iters << ", total=" << total
						<< std::endl;
			}
			EXPECT_EQ(num_iters, int(total));
		}
	}
}
コード例 #9
0
TEST(Sial,put_test) {
    barrier();
    std::string job("put_test");
    int norb = 3;
    int segs[] = {2,3,2};
    if (attr->global_rank() == 0) {
        init_setup(job.c_str());
        set_constant("norb", norb);
        set_constant("norb_squared", norb*norb);
        std::string tmp = job + ".siox";
        const char* nm = tmp.c_str();
        add_sial_program(nm);
        set_aoindex_info(3, segs);
        finalize_setup();
    }
    barrier();
    std::stringstream output;
    TestControllerParallel controller(job, true, VERBOSE_TEST, " ", output);
    controller.initSipTables();
    if (attr->is_worker()) {
        std::cout << "creating and starting a worker" << std::endl << std::flush;
        controller.runWorker();
        EXPECT_TRUE(controller.worker_->all_stacks_empty());
        std::vector<int> index_vec;
        for (int i = 0; i < norb; ++i) {
            for (int j = 0; j < norb; ++j) {
                int k = (i*norb + j)+1;
                index_vec.push_back(k);
                double * local_block = controller.local_block("result",index_vec);
                double value = local_block[0];
                double expected = k*k*segs[i]*segs[j];
                std::cout << "k,value= " << k << " " << value << std::endl;
                ASSERT_DOUBLE_EQ(expected, value);
                index_vec.clear();
            }
        }
    } else {
        std::cout << "creating and starting a server" << std::endl << std::flush;
        controller.runServer();
    }


}
コード例 #10
0
ファイル: test_sial.cpp プロジェクト: BB-Goldstein/aces4
TEST(Sial,persistent_distributed_array_mpi){
	std::string job("persistent_distributed_array_mpi");
	double x = 3.456;
	int norb = 2;
	int segs[]  = {2,3};

	if (attr->global_rank() == 0){
		init_setup(job.c_str());
		set_scalar("x",x);
		set_constant("norb",norb);
		std::string tmp = job + "1.siox";
		const char* nm= tmp.c_str();
		add_sial_program(nm);
		std::string tmp1 = job + "2.siox";
		const char* nm1= tmp1.c_str();
		add_sial_program(nm1);
		set_aoindex_info(2,segs);
		finalize_setup();
	}


	std::stringstream output;
	TestControllerParallel controller(job, true, true, "", output);

	//run first program
	controller.initSipTables();
	controller.run();
	controller.print_timers(std::cout);
	std::cout << "Rank " << attr->global_rank() << " in persistent_distributed_array_mpi starting second program" << std::endl << std::flush;

	//run second program
	controller.initSipTables();
	controller.run();
	if (attr->is_worker()) {
		int i,j;
		for (i=1; i <= norb ; ++i ){
			for (j = 1; j <= norb; ++j){
			    double firstval = (i-1)*norb + j;
			    std::vector<int> indices;
			    indices.push_back(i);
			    indices.push_back(j);
			    double * block_data = controller.local_block(std::string("a"),indices);
			    size_t block_size = segs[i-1] * segs[j-1];
			    for (size_t count = 0; count < block_size; ++count){
			    	ASSERT_DOUBLE_EQ(3*firstval, block_data[count]);
			    	firstval++;
			    }
			}
		}
	}
	controller.print_timers(std::cout);

}
コード例 #11
0
void Canonicalizer::do_Intrinsic      (Intrinsic*       x) {
  switch (x->id()) {
  case ciMethod::_floatToRawIntBits   : {
    FloatConstant* c = x->argument_at(0)->type()->as_FloatConstant();
    if (c != NULL) {
      JavaValue v;
      v.set_jfloat(c->value());
      set_constant(v.get_jint());
    }
    break;
  }
  case ciMethod::_intBitsToFloat      : {
    IntConstant* c = x->argument_at(0)->type()->as_IntConstant();
    if (c != NULL) {
      JavaValue v;
      v.set_jint(c->value());
      set_constant(v.get_jfloat());
    }
    break;
  }
  case ciMethod::_doubleToRawLongBits : {
    DoubleConstant* c = x->argument_at(0)->type()->as_DoubleConstant();
    if (c != NULL) {
      JavaValue v;
      v.set_jdouble(c->value());
      set_constant(v.get_jlong());
    }
    break;
  }
  case ciMethod::_longBitsToDouble    : {
    LongConstant* c = x->argument_at(0)->type()->as_LongConstant();
    if (c != NULL) {
      JavaValue v;
      v.set_jlong(c->value());
      set_constant(v.get_jdouble());
    }
    break;
  }
  }
}
コード例 #12
0
ファイル: Image_controls.cpp プロジェクト: Opioid/Substitute
void Image_controls::on_scalar_constant_spin_box__valueChanged(double arg1)
{
	set_constant(static_cast<float>(arg1));

	if (0 == ui->image_source_combo_box_->currentIndex())
	{
		update_constant();
	}
	else
	{
		ui->image_source_combo_box_->setCurrentIndex(0);
	}
}
コード例 #13
0
ファイル: test_sial.cpp プロジェクト: BB-Goldstein/aces4
TEST(Sial,broadcast_static){
	std::string job("broadcast_static");
	int norb = 3;
	int segs[] = {2,3,2};
	int root = 0;
	if (attr->global_rank() == 0) {
		init_setup(job.c_str());
		set_constant("norb", norb);
		set_constant("root", root);
		std::string tmp = job + ".siox";
		const char* nm = tmp.c_str();
		add_sial_program(nm);
		set_aoindex_info(3, segs);
		finalize_setup();
	}
	std::stringstream output;

	TestControllerParallel controller(job, true, VERBOSE_TEST, "", output);
	controller.initSipTables();
	controller.run();
	if (attr->is_worker()) {
	double * a = controller.static_array("a");
	int expected[] = {1, 2, 1, 2, 3, 1, 2,
			3, 4, 4, 5, 6, 3, 4,
			1, 2, 1, 2, 3, 1, 2,
			3, 4, 4, 5, 6, 3, 4,
			5, 6, 7, 8, 9, 5, 6,
			1, 2, 1, 2, 3, 1, 2,
			3, 4, 4, 5, 6, 3, 4};
	int side = 2+3+2; //size of one side, from seg sizes in segs array above
	int size = side*side;
	int i = 0;
	for (i; i < size; ++i){
		ASSERT_DOUBLE_EQ(expected[i], a[i]);
	}
}

}
コード例 #14
0
ファイル: test_sial.cpp プロジェクト: BB-Goldstein/aces4
TEST(Sial,get_mpi){
	std::string job("get_mpi");
	//create setup_file
	double x = 3.456;
	int norb = 4;
	int segs[]  = {2,3,4,1};

	if (attr->global_rank() == 0){
		init_setup(job.c_str());
		set_scalar("x",x);
		set_constant("norb",norb);
		std::string tmp = job + ".siox";
		const char* nm= tmp.c_str();
		add_sial_program(nm);
		set_aoindex_info(4,segs);
		finalize_setup();
	}

	std::stringstream output;
	TestControllerParallel controller(job, true, VERBOSE_TEST, "", output);
	controller.initSipTables();
	controller.run();

	if(attr->global_rank()==0){
		// Test a(1,1)
		// Get the data for local array block "b"
		int a_slot = controller.worker_->array_slot(std::string("a"));

		sip::index_selector_t a_indices_1;
		a_indices_1[0] = 1; a_indices_1[1] = 1;
		for (int i = 2; i < MAX_RANK; i++) a_indices_1[i] = sip::unused_index_value;
		sip::BlockId a_bid_1(a_slot, a_indices_1);
		std::cout << a_bid_1 << std::endl;
		sip::Block::BlockPtr a_bptr_1 = controller.worker_->get_block_for_reading(a_bid_1);
		sip::Block::dataPtr a_data_1 = a_bptr_1->get_data();
		std::cout << " Comparing block " << a_bid_1 << std::endl;
		for (int i=0; i<segs[0]; i++){
			for (int j=0; j<segs[0]; j++){
				ASSERT_DOUBLE_EQ(42*3, a_data_1[i*segs[0] + j]);
			}
		}
	}
}
コード例 #15
0
ファイル: test_sial.cpp プロジェクト: BB-Goldstein/aces4
/* TODO check what this test does.  */
TEST(Sip,message_number_wraparound){

	std::string job("message_number_wraparound_test");

	if (attr->global_rank() == 0){
		init_setup(job.c_str());
		set_constant("norb",1);
		std::string tmp = job + ".siox";
		const char* nm= tmp.c_str();
		add_sial_program(nm);
		int segs[]  = {1};
		set_aoindex_info(1,segs);
		finalize_setup();
	}

	std::stringstream output;
	TestControllerParallel controller(job, true, VERBOSE_TEST, "", output);
	controller.initSipTables();
	controller.run();
}
コード例 #16
0
ファイル: test_sial.cpp プロジェクト: BB-Goldstein/aces4
TEST(Sial,put_accumulate_mpi){
	std::string job("put_accumulate_mpi");
	double x = 3.456;
	int norb = 4;
	if (attr->global_rank() == 0){
		init_setup(job.c_str());
		set_scalar("x",x);
		set_constant("norb",norb);
		std::string tmp = job + ".siox";
		const char* nm= tmp.c_str();
		add_sial_program(nm);
		int segs[]  = {2,3,4,1};
		set_aoindex_info(4,segs);
		finalize_setup();
	}
	std::stringstream output;
	TestControllerParallel controller(job, true, VERBOSE_TEST, "", output);
	controller.initSipTables();
	controller.run();

}
コード例 #17
0
ファイル: test_sial.cpp プロジェクト: BB-Goldstein/aces4
TEST(Sial,all_rank_print){
	std::string job("all_rank_print_test");
	std::cout << "JOBNAME = " << job << std::endl;
	double x = 3.456;
	int norb = 2;
	if (attr->global_rank() == 0){
		init_setup(job.c_str());
		set_scalar("x",x);
		set_constant("norb",norb);
		std::string tmp = job + ".siox";
		const char* nm= tmp.c_str();
		add_sial_program(nm);
		int segs[]  = {2,3};
		set_aoindex_info(2,segs);
		finalize_setup();
	}

	std::stringstream output;
	TestControllerParallel controller(job, true, VERBOSE_TEST, "", output);
	controller.initSipTables();
	controller.run();
}
コード例 #18
0
ファイル: Image_controls.cpp プロジェクト: Opioid/Substitute
void Image_controls::on_color_constant_button__clicked()
{
	rendering::Color3 rgb = rendering::linear_to_sRGB(constant_);

	QColor qcolor = QColorDialog::getColor(QColor::fromRgbF(rgb.r, rgb.g, rgb.b), this, "Color constant");

	if (qcolor.isValid())
	{
		rgb = rendering::Color3(qcolor.redF(), qcolor.greenF(), qcolor.blueF());

		set_constant(rendering::sRGB_to_linear(rgb));

		if (0 == ui->image_source_combo_box_->currentIndex())
		{
			update_constant();
		}
		else
		{
			ui->image_source_combo_box_->setCurrentIndex(0);
		}
	}
}
コード例 #19
0
ファイル: c1_Canonicalizer.cpp プロジェクト: lizhekang/TCJDK
void Canonicalizer::do_Op2(Op2* x) {
  if (x->x() == x->y()) {
    switch (x->op()) {
    case Bytecodes::_isub: set_constant(0); return;
    case Bytecodes::_lsub: set_constant(jlong_cast(0)); return;
    case Bytecodes::_iand: // fall through
    case Bytecodes::_land: // fall through
    case Bytecodes::_ior:  // fall through
    case Bytecodes::_lor : set_canonical(x->x()); return;
    case Bytecodes::_ixor: set_constant(0); return;
    case Bytecodes::_lxor: set_constant(jlong_cast(0)); return;
    }
  }

  if (x->x()->type()->is_constant() && x->y()->type()->is_constant()) {
    // do constant folding for selected operations
    switch (x->type()->tag()) {
      case intTag:
        { jint a = x->x()->type()->as_IntConstant()->value();
          jint b = x->y()->type()->as_IntConstant()->value();
          switch (x->op()) {
            case Bytecodes::_iadd: set_constant(a + b); return;
            case Bytecodes::_isub: set_constant(a - b); return;
            case Bytecodes::_imul: set_constant(a * b); return;
            case Bytecodes::_idiv:
              if (b != 0) {
                if (a == min_jint && b == -1) {
                  set_constant(min_jint);
                } else {
                  set_constant(a / b);
                }
                return;
              }
              break;
            case Bytecodes::_irem:
              if (b != 0) {
                if (a == min_jint && b == -1) {
                  set_constant(0);
                } else {
                  set_constant(a % b);
                }
                return;
              }
              break;
            case Bytecodes::_iand: set_constant(a & b); return;
            case Bytecodes::_ior : set_constant(a | b); return;
            case Bytecodes::_ixor: set_constant(a ^ b); return;
          }
        }
        break;
      case longTag:
        { jlong a = x->x()->type()->as_LongConstant()->value();
          jlong b = x->y()->type()->as_LongConstant()->value();
          switch (x->op()) {
            case Bytecodes::_ladd: set_constant(a + b); return;
            case Bytecodes::_lsub: set_constant(a - b); return;
            case Bytecodes::_lmul: set_constant(a * b); return;
            case Bytecodes::_ldiv:
              if (b != 0) {
                set_constant(SharedRuntime::ldiv(b, a));
                return;
              }
              break;
            case Bytecodes::_lrem:
              if (b != 0) {
                set_constant(SharedRuntime::lrem(b, a));
                return;
              }
              break;
            case Bytecodes::_land: set_constant(a & b); return;
            case Bytecodes::_lor : set_constant(a | b); return;
            case Bytecodes::_lxor: set_constant(a ^ b); return;
          }
        }
        break;
      // other cases not implemented (must be extremely careful with floats & doubles!)
    }
  }
  // make sure constant is on the right side, if any
  move_const_to_right(x);

  if (x->y()->type()->is_constant()) {
    // do constant folding for selected operations
    switch (x->type()->tag()) {
      case intTag:
        if (x->y()->type()->as_IntConstant()->value() == 0) {
          switch (x->op()) {
            case Bytecodes::_iadd: set_canonical(x->x()); return;
            case Bytecodes::_isub: set_canonical(x->x()); return;
            case Bytecodes::_imul: set_constant(0); return;
              // Note: for div and rem, make sure that C semantics
              //       corresponds to Java semantics!
            case Bytecodes::_iand: set_constant(0); return;
            case Bytecodes::_ior : set_canonical(x->x()); return;
          }
        }
        break;
      case longTag:
        if (x->y()->type()->as_LongConstant()->value() == (jlong)0) {
          switch (x->op()) {
            case Bytecodes::_ladd: set_canonical(x->x()); return;
            case Bytecodes::_lsub: set_canonical(x->x()); return;
            case Bytecodes::_lmul: set_constant((jlong)0); return;
              // Note: for div and rem, make sure that C semantics
              //       corresponds to Java semantics!
            case Bytecodes::_land: set_constant((jlong)0); return;
            case Bytecodes::_lor : set_canonical(x->x()); return;
          }
        }
        break;
    }
  }
}
コード例 #20
0
TEST(SimpleMPI,persistent_distributed_array_mpi) {

    sip::GlobalState::reset_program_count();
    sip::SIPMPIAttr &sip_mpi_attr = sip::SIPMPIAttr::get_instance();
    int my_rank = sip_mpi_attr.global_rank();

    std::cout << "****************************************\n";
    sip::DataManager::scope_count=0;
    //create setup_file
    std::string job("persistent_distributed_array_mpi");
    std::cout << "JOBNAME = " << job << std::endl;
    double x = 3.456;
    int norb = 2;
    int segs[]  = {2,3};


    if (attr.global_rank() == 0) {
        init_setup(job.c_str());
        set_scalar("x",x);
        set_constant("norb",norb);
        std::string tmp = job + "1.siox";
        const char* nm= tmp.c_str();
        add_sial_program(nm);
        std::string tmp1 = job + "2.siox";
        const char* nm1= tmp1.c_str();
        add_sial_program(nm1);
        set_aoindex_info(2,segs);
        finalize_setup();
    }

    sip::SIPMPIUtils::check_err(MPI_Barrier(MPI_COMM_WORLD));

    setup::BinaryInputFile setup_file(job + ".dat");
    setup::SetupReader setup_reader(setup_file);

    std::cout << "SETUP READER DATA:\n" << setup_reader<< std::endl;


    //get siox name from setup, load and print the sip tables
    std::string prog_name = setup_reader.sial_prog_list_.at(0);
    std::string siox_dir(dir_name);
    setup::BinaryInputFile siox_file(siox_dir + prog_name);
    sip::SipTables sipTables(setup_reader, siox_file);
    if (!sip_mpi_attr.is_server()) {
        std::cout << "SIP TABLES" << '\n' << sipTables << std::endl;
    }

    if (sip_mpi_attr.global_rank()==0) {
        std::cout << "\n\n\n\n>>>>>>>>>>>>starting SIAL PROGRAM  "<< job << std::endl;
    }

    //create worker and server
    sip::DataDistribution data_distribution(sipTables, sip_mpi_attr);
    sip::GlobalState::set_program_name(prog_name);
    sip::GlobalState::increment_program();
    sip::WorkerPersistentArrayManager wpam;
    sip::ServerPersistentArrayManager spam;

    std::cout << "rank " << my_rank << " reached first barrier" << std::endl << std::flush;
    MPI_Barrier(MPI_COMM_WORLD);
    std::cout << "rank " << my_rank << " passed first barrier" << std::endl << std::flush;

    if (sip_mpi_attr.is_server()) {
        sip::SIPServer server(sipTables, data_distribution, sip_mpi_attr, &spam);
        std::cout << "at first barrier in prog 1 at server" << std::endl << std::flush;
        MPI_Barrier(MPI_COMM_WORLD);
        std::cout<<"passed first barrier at server, starting server" << std::endl;
        server.run();
        spam.save_marked_arrays(&server);
        std::cout << "Server state after termination" << server << std::endl;
    } else {
        sip::SialxTimer sialxTimer(sipTables.max_timer_slots());
        sip::Interpreter runner(sipTables, sialxTimer,  &wpam);
        std::cout << "at first barrier in prog 1 at worker" << std::endl << std::flush;
        MPI_Barrier(MPI_COMM_WORLD);
        std::cout << "after first barrier; starting worker for "<< job  << std::endl;
        runner.interpret();
        wpam.save_marked_arrays(&runner);
        std::cout << "\n end of prog1 at worker"<< std::endl;

    }

    std::cout << std::flush;
    if (sip_mpi_attr.global_rank()==0) {
        std::cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << std::endl << std::flush;
        std::cout << "SETUP READER DATA FOR SECOND PROGRAM:\n" << setup_reader<< std::endl;
    }

    std::string prog_name2 = setup_reader.sial_prog_list_.at(1);
    setup::BinaryInputFile siox_file2(siox_dir + prog_name2);
    sip::SipTables sipTables2(setup_reader, siox_file2);

    if (sip_mpi_attr.global_rank()==0) {
        std::cout << "SIP TABLES FOR " << prog_name2 << '\n' << sipTables2 << std::endl;
    }

    sip::DataDistribution data_distribution2(sipTables2, sip_mpi_attr);
    sip::GlobalState::set_program_name(prog_name);
    sip::GlobalState::increment_program();
    std::cout << "rank " << my_rank << " reached second barrier in test" << std::endl << std::flush;
    MPI_Barrier(MPI_COMM_WORLD);
    std::cout << "rank " << my_rank << " passed second barrier in test" << std::endl << std::flush;

    if (sip_mpi_attr.is_server()) {
        sip::SIPServer server(sipTables2, data_distribution2, sip_mpi_attr, &spam);
        std::cout << "barrier in prog 2 at server" << std::endl << std::flush;
        MPI_Barrier(MPI_COMM_WORLD);
        std::cout<< "rank " << my_rank << "starting server for prog 2" << std::endl;
        server.run();
        std::cout<< "rank " << my_rank  << "Server state after termination of prog2" << server << std::endl;
    } else {
        sip::SialxTimer sialxTimer2(sipTables2.max_timer_slots());
        sip::Interpreter runner(sipTables2, sialxTimer2,  &wpam);
        std::cout << "rank " << my_rank << "barrier in prog 2 at worker" << std::endl << std::flush;
        MPI_Barrier(MPI_COMM_WORLD);
        std::cout << "rank " << my_rank << "starting worker for prog2"<< job  << std::endl;
        runner.interpret();
        std::cout << "\nSIAL PROGRAM 2 TERMINATED"<< std::endl;


        // Test contents of blocks of distributed array "b"

        // Get the data for local array block "b"
        int b_slot = runner.array_slot(std::string("lb"));

        // Test b(1,1)
        sip::index_selector_t b_indices_1;
        b_indices_1[0] = 1;
        b_indices_1[1] = 1;
        for (int i = 2; i < MAX_RANK; i++) b_indices_1[i] = sip::unused_index_value;
        sip::BlockId b_bid_1(b_slot, b_indices_1);
        std::cout << b_bid_1 << std::endl;
        sip::Block::BlockPtr b_bptr_1 = runner.get_block_for_reading(b_bid_1);
        sip::Block::dataPtr b_data_1 = b_bptr_1->get_data();
        std::cout << " Comparing block " << b_bid_1 << std::endl;
        double fill_seq_1_1 = 1.0;
        for (int i=0; i<segs[0]; i++) {
            for (int j=0; j<segs[0]; j++) {
                ASSERT_DOUBLE_EQ(fill_seq_1_1, b_data_1[i*segs[0] + j]);
                fill_seq_1_1++;
            }
        }

        // Test b(2, 2)
        sip::index_selector_t b_indices_2;
        b_indices_2[0] = 2;
        b_indices_2[1] = 2;
        for (int i = 2; i < MAX_RANK; i++) b_indices_2[i] = sip::unused_index_value;
        sip::BlockId b_bid_2(b_slot, b_indices_2);
        std::cout << b_bid_2 << std::endl;
        sip::Block::BlockPtr b_bptr_2 = runner.get_block_for_reading(b_bid_2);
        sip::Block::dataPtr b_data_2 = b_bptr_2->get_data();
        std::cout << " Comparing block " << b_bid_2 << std::endl;
        double fill_seq_2_2 = 4.0;
        for (int i=0; i<segs[1]; i++) {
            for (int j=0; j<segs[1]; j++) {
                ASSERT_DOUBLE_EQ(fill_seq_2_2, b_data_2[i*segs[1] + j]);
                fill_seq_2_2++;
            }
        }

        // Test b(2,1)
        sip::index_selector_t b_indices_3;
        b_indices_3[0] = 2;
        b_indices_3[1] = 1;
        for (int i = 2; i < MAX_RANK; i++) b_indices_3[i] = sip::unused_index_value;
        sip::BlockId b_bid_3(b_slot, b_indices_3);
        std::cout << b_bid_3 << std::endl;
        sip::Block::BlockPtr b_bptr_3 = runner.get_block_for_reading(b_bid_3);
        sip::Block::dataPtr b_data_3 = b_bptr_3->get_data();
        std::cout << " Comparing block " << b_bid_3 << std::endl;
        double fill_seq_2_1 = 3.0;
        for (int i=0; i<segs[1]; i++) {
            for (int j=0; j<segs[0]; j++) {
                ASSERT_DOUBLE_EQ(fill_seq_2_1, b_data_3[i*segs[0] + j]);
                fill_seq_2_1++;
            }
        }


    }

    std::cout << "rank " << my_rank << " reached third barrier in test" << std::endl << std::flush;
    MPI_Barrier(MPI_COMM_WORLD);
    std::cout << "rank " << my_rank << " passed third barrier in test" << std::endl << std::flush;

}
コード例 #21
0
ファイル: luaiso8583.c プロジェクト: jmptrader/iso8583-2
int luaopen_iso8583(lua_State *L)
{

	luaL_newmetatable(L, "iso8583");
	lua_pushvalue(L, -1);
	lua_setfield(L, -2, "__index");

	luaL_register(L, NULL, iso8583lib_m);

	luaL_register(L, "iso8583", iso8583lib_f);

#define set_constant(name, value) lua_pushstring(L, name); lua_pushinteger(L, value); lua_settable(L, -3);

	set_constant("LEFT",   ISO8583_L);
	set_constant("RIGHT",  ISO8583_R);
	set_constant("L",	   ISO8583_L);
	set_constant("R",      ISO8583_R);

	set_constant("ZIP",    ISO8583_Z);
	set_constant("UNZIP",  ISO8583_U);
	set_constant("Z",      ISO8583_Z);
	set_constant("U",      ISO8583_U);

	set_constant("FIX",    ISO8583_FIX);
	set_constant("LLVAR",  ISO8583_LLVAR);
	set_constant("LLLVAR", ISO8583_LLLVAR);

	return 1;
}
コード例 #22
0
ファイル: modele_pism.cpp プロジェクト: seifer08ms/icebin
/** GCM-specific contract */
void IceModel_PISM::setup_contracts_modele()
{
	// Get arguments we need from coupler
	auto coupler(dynamic_cast<GCMCoupler_ModelE const *>(this->coupler));
	auto params(dynamic_cast<GCMPerIceSheetParams_ModelE const *>(this->gcm_per_ice_sheet_params.get()));


	printf("BEGIN IceModel_PISM::setup_contracts_modele\n");
	IceModel &model(*this);

	// =========== Transfer  constants
	transfer_constant("standard_gravity", "constant::grav");
	transfer_constant("beta_CC", "seaice::dtdp", -1.0);
	transfer_constant("water_melting_point_temperature", "constant::tf");
	transfer_constant("water_latent_heat_fusion", "constant::lhm");
	transfer_constant("water_specific_heat_capacity", "constant::shw");

	transfer_constant("ice_density", "constant::rhoi");
	transfer_constant("ice_thermal_conductivity", "seaice::alami0");
	transfer_constant("ice_specific_heat_capacity", "constant::shi");
	transfer_constant("fresh_water_density", "constant::rhow");
	transfer_constant("sea_water_density", "constant::rhows");
	transfer_constant("standard_gravity", "constant::grav");
	transfer_constant("ideal_gas_constant", "constant::gasc");

	Z2LI = coupler->gcm_constants.get_as("landice::z2li", "m");

	// To set this, see (in ModelE): Function SHCGS in ocnfuntab.f is
	// used for the Russell ocean. I. The simple models use SHW=4185.
	// This probably doesn't matter much at this point (May 2014)
	//	    transfer_constant("sea_water_specific_heat_capacity", "");

	/* The following constants were not transferred 
	pism_config:fill_value = -2e9;
	pism_config:fill_value_doc = "_FillValue used when saving diagnostic quantities";
	*/

	// In PISM and ModelE Clausius-Clapeyron equation, surfce_pressure is the DIFFERENCE
	// from 1atm.  Thus, surface_pressure=0 implies the ice sheet existing at 1atm
	set_constant("surface_pressure", 0, "Pa");		// Match ModelE thermodynam

	// No need to set enthalpy_reference_temperature.  pism::EnthalpyConverter is used (below)
	// to convert enthalpy values between ModelE and PISM.
	// transfer_constant("enthalpy_reference_temperature", "enthalpy_reference_temperature");


	// ============ GCM -> Ice
	CouplingContract &ice_input(contract[IceModel::INPUT]);

	// ------ Decide on the coupling contract for this ice sheet
	ice_input.add_field("wflux", "kg m-2 s-1", contracts::ELEVATION,
		"Downward water flux out of surface model's bottom layer");
	ice_input.add_field("massxfer", "kg m-2 s-1", contracts::ELEVATION,
		"Mass of ice being transferred Stieglitz --> Glint2");
	ice_input.add_field("enthxfer", "W m-2", contracts::ELEVATION,
		"Enthalpy of ice being transferred Stieglitz --> Glint2");
	ice_input.add_field("deltah", "W m-2", contracts::ELEVATION,
		"Change of enthalpy of top layer in PISM");

	// Figure out the conversion between GCM and PISM enthalpy
	// ModelE's reference state is 1atm, 0C, 100% liquid water.
	// The enthalpy for that reference state would be the top end
	// of PISM's EnthalpyInterval.
	// NOTE: Pressure in PISM is RELATIVE to atmospheric pressure.
	//       Thus, p=0 is the correct to use at the top surface of
	//       the ice sheet (where ModelE operates).
	GLINT2EnthalpyConverter enth(*config);
	double const pressure = 0;
	double E_s, E_l;
	enth.getEnthalpyInterval(pressure, E_s, E_l);
	double const enth_modele_to_pism = E_l;		// (J/kg): Add to convert ModelE specific enthalpies (J/kg) to PISM specific enthalpies (J/kg)
	// NOTE: enth_modele_to_pism == 437000 J/kg
	if (pism_rank == 0) printf("enth_modele_to_pism = %g\n", enth_modele_to_pism);

	bool ok = true;

	double const RHOW = coupler->gcm_constants.get_as("constant::rhow", "kg m-3");
	double const byRHOW = 1.0 / RHOW;

	// ------------- Convert the contract to a var transformer
	{VarTransformer &vt(var_transformer[IceModel::INPUT]);
	vt.set_names(VarTransformer::INPUTS, &coupler->gcm_outputs);
	vt.set_names(VarTransformer::OUTPUTS, &ice_input);
	vt.set_names(VarTransformer::SCALARS, &coupler->ice_input_scalars);
	vt.allocate();

	ok = ok && vt.set("wflux", "wflux", "unit", RHOW);
	ok = ok && vt.set("hflux", "hflux", "unit", 1.0);
	ok = ok && vt.set("massxfer", "massxfer", "unit", RHOW);
	ok = ok && vt.set("enthxfer", "enthxfer", "unit", 1.0);
	ok = ok && vt.set("enthxfer", "massxfer", "unit", enth_modele_to_pism*RHOW);
	ok = ok && vt.set("volxfer", "volxfer", "unit", 1.0);
	}

	// ============== Ice -> GCM
	CouplingContract &ice_output(contract[IceModel::OUTPUT]);

	// Glint2 requires that all ice models return elev2, so that it can regrid in the vertical.

	ice_output.add_field("usurf", "m", contracts::ICE|contracts::INITIAL, "ice upper surface elevation");	// See ice_surface_elevation in iceModel.cc

	ice_output.add_field("M1", "kg m-2", contracts::ICE|contracts::INITIAL, "");
	ice_output.add_field("M2", "kg m-2", contracts::ICE|contracts::INITIAL, "");
	ice_output.add_field("H1", "J m-2", contracts::ICE|contracts::INITIAL, "");
	ice_output.add_field("H2", "J m-2", contracts::ICE|contracts::INITIAL, "");
	ice_output.add_field("V1", "m^3 m-2", contracts::ICE|contracts::INITIAL, "");
	ice_output.add_field("V2", "m^3 m-2", contracts::ICE|contracts::INITIAL, "");

	ice_output.add_field("basal_frictional_heating", "W m-2", contracts::ICE, "");
	ice_output.add_field("strain_heating", "W m-2", contracts::ICE, "");
	ice_output.add_field("geothermal_flux", "W m-2", contracts::ICE, "");
	ice_output.add_field("upward_geothermal_flux", "W m-2", contracts::ICE, "");

	ice_output.add_field("calving.mass", "kg m-2 s-1", contracts::ICE, "");
	ice_output.add_field("calving.enth", "W m-2", contracts::ICE, "");
	ice_output.add_field("glint2_smb.mass", "kg m-2 s-1", contracts::ICE, "");
	ice_output.add_field("glint2_smb.enth", "W m-2", contracts::ICE, "");
	ice_output.add_field("glint2_surface_temp", "K", contracts::ICE, "");
	ice_output.add_field("pism_smb.mass", "kg m-2 s-1", contracts::ICE, "");
	ice_output.add_field("pism_smb.enth", "W m-2", contracts::ICE, "");

	// basal_runoff (GCM input) = melt_grounded + melt_floatig (PISM outputs)
	ice_output.add_field("melt_grounded.mass", "kg m-2 s-1", contracts::ICE, "");
	ice_output.add_field("melt_grounded.enth", "W m-2", contracts::ICE, "");
	ice_output.add_field("melt_floating.mass", "kg m-2 s-1", contracts::ICE, "");
	ice_output.add_field("melt_floating.enth", "W m-2", contracts::ICE, "");

	ice_output.add_field("internal_advection.mass", "kg m-2 s-1", contracts::ICE, "");
	ice_output.add_field("internal_advection.enth", "W m-2", contracts::ICE, "");
	ice_output.add_field("epsilon.mass", "kg m-2 s-1", contracts::ICE, "");
	ice_output.add_field("epsilon.enth", "W m-2", contracts::ICE, "");

	ice_output.add_field("unit", "", 0, "Dimensionless identity");

	std::cout << "========= Ice Model Outputs (" << model.name << ") modele_pism.cpp:" << std::endl;
	std::cout << ice_output << std::endl;

	// ------- Variable and unit conversions, Ice -> GCM
	{VarTransformer &vt(var_transformer[IceModel::OUTPUT]);

	// NOTE: coupler->gcm_inputs is set up through calls to add_gcm_input_xx() in LANDICE_COM.f
	vt.set_names(VarTransformer::INPUTS, &ice_output);
	vt.set_names(VarTransformer::OUTPUTS, &coupler->gcm_inputs);
	vt.set_names(VarTransformer::SCALARS, &coupler->ice_input_scalars);
	vt.allocate();

//	ok = ok && vt.set("elev2", "usurf", "unit", 1.0);
	ok = ok && vt.set("elev1", "usurf", "unit", 1.0);

	// Top layer state from ice model
	ok = ok && vt.set("M1", "M1", "unit", byRHOW);	// Divide by RHOW to convert to m water equiv
	ok = ok && vt.set("H1", "H1", "unit", 1.0);
	ok = ok && vt.set("H1", "M1", "unit", -enth_modele_to_pism*byRHOW);
	ok = ok && vt.set("V1", "V1", "unit", 1.0);

	// Second-top layer state from ice model
	ok = ok && vt.set("M1", "M1", "unit", byRHOW);	// Divide by RHOW to convert to m water equiv
	ok = ok && vt.set("H1", "H1", "unit", 1.0);
	ok = ok && vt.set("H1", "M1", "unit", -enth_modele_to_pism*byRHOW);
	ok = ok && vt.set("V1", "V1", "unit", 1.0);


	ok = ok && vt.set("basal_frictional_heating", "basal_frictional_heating", "unit", 1.0);
	ok = ok && vt.set("strain_heating", "strain_heating", "unit", 1.0);

	ok = ok && vt.set("geothermal_flux", "geothermal_flux", "unit", 1.0);
	ok = ok && vt.set("upward_geothermal_flux", "upward_geothermal_flux", "unit", 1.0);

	ok = ok && vt.set("basal_runoff.mass", "melt_grounded.mass", "unit", 1.0);
	ok = ok && vt.set("basal_runoff.enth", "melt_grounded.enth", "unit", 1.0);
	ok = ok && vt.set("basal_runoff.enth", "melt_grounded.mass", "unit", -enth_modele_to_pism);

	ok = ok && vt.set("basal_runoff.mass", "melt_floating.mass", "unit", 1.0);
	ok = ok && vt.set("basal_runoff.enth", "melt_floating.enth", "unit", 1.0);
	ok = ok && vt.set("basal_runoff.enth", "melt_floating.mass", "unit", -enth_modele_to_pism);

	ok = ok && vt.set("calving.mass", "calving.mass", "unit", 1.0);
	ok = ok && vt.set("calving.enth", "calving.enth", "unit", 1.0);
	ok = ok && vt.set("calving.enth", "calving.mass", "unit", -enth_modele_to_pism);


	ok = ok && vt.set("internal_advection.mass", "internal_advection.mass", "unit", 1.0);
	ok = ok && vt.set("internal_advection.enth", "internal_advection.enth", "unit", 1.0);
	ok = ok && vt.set("internal_advection.enth", "internal_advection.mass", "unit", -enth_modele_to_pism);


	ok = ok && vt.set("epsilon.mass", "epsilon.mass", "unit", 1.0);
	ok = ok && vt.set("epsilon.enth", "epsilon.enth", "unit", 1.0);
	ok = ok && vt.set("epsilon.enth", "epsilon.mass", "unit", -enth_modele_to_pism);

	}

	// Catch all our errors at once
	if (!ok) throw std::exception();
	printf("END IceModel_PISM::setup_contracts_modele\n");
}