Example #1
0
 void
 all_reduce_impl(const communicator& comm, const T* in_values, int n,
                 T* out_values, Op op, mpl::false_ /*is_mpi_op*/,
                 mpl::false_ /*is_mpi_datatype*/)
 {
   if (in_values == MPI_IN_PLACE) {
     // if in_values matches the in place tag, then the output
     // buffer actually contains the input data.
     // But we can just go back to the out of place 
     // implementation in this case.
     // it's not clear how/if we can avoid the copy.
     std::vector<T> tmp_in( out_values, out_values + n);
     reduce(comm, &(tmp_in[0]), n, out_values, op, 0);
   } else {
     reduce(comm, in_values, n, out_values, op, 0);
   }
   broadcast(comm, out_values, n, 0);
 }
Example #2
0
CORBA::Any_ptr
TAO_DynSequence_i::to_any (void)
{
  if (this->destroyed_)
    {
      throw ::CORBA::OBJECT_NOT_EXIST ();
    }

  TAO_OutputCDR out_cdr;
  out_cdr.write_ulong (this->component_count_);

  CORBA::TypeCode_var field_tc =
    this->get_element_type ();

  for (CORBA::ULong i = 0; i < this->component_count_; ++i)
    {
      // Recursive step
      CORBA::Any_var field_any =
        this->da_members_[i]->to_any ();

      TAO::Any_Impl *field_impl = field_any->impl ();
      TAO_OutputCDR field_out;
      TAO_InputCDR field_cdr (static_cast<ACE_Message_Block *> (0));

      if (field_impl->encoded ())
        {
          TAO::Unknown_IDL_Type * const field_unk =
            dynamic_cast<TAO::Unknown_IDL_Type *> (field_impl);

          if (!field_unk)
            throw CORBA::INTERNAL ();

          field_cdr = field_unk->_tao_get_cdr ();
        }
      else
        {
          field_impl->marshal_value (field_out);
          TAO_InputCDR tmp_in (field_out);
          field_cdr = tmp_in;
        }

      (void) TAO_Marshal_Object::perform_append (field_tc.in (),
                                                 &field_cdr,
                                                 &out_cdr);
    }

  TAO_InputCDR in_cdr (out_cdr);

  CORBA::Any_ptr retval = 0;
  ACE_NEW_THROW_EX (retval,
                    CORBA::Any,
                    CORBA::NO_MEMORY ());

  TAO::Unknown_IDL_Type *unk = 0;
  ACE_NEW_THROW_EX (unk,
                    TAO::Unknown_IDL_Type (this->type_.in (),
                                           in_cdr),
                    CORBA::NO_MEMORY ());

  retval->replace (unk);
  return retval;
}
Example #3
0
void
TAO_DynSequence_i::from_any (const CORBA::Any & any)
{
  if (this->destroyed_)
    {
      throw ::CORBA::OBJECT_NOT_EXIST ();
    }

  CORBA::TypeCode_var tc = any.type ();
  CORBA::Boolean equivalent =
    this->type_.in ()->equivalent (tc.in ());

  if (equivalent)
    {
      // Get the CDR stream of the Any, if there isn't one, make one.
      TAO::Any_Impl *impl = any.impl ();
      TAO_OutputCDR out;
      TAO_InputCDR cdr (static_cast<ACE_Message_Block *> (0));

      if (impl->encoded ())
        {
          TAO::Unknown_IDL_Type * const unk =
            dynamic_cast<TAO::Unknown_IDL_Type *> (impl);

          if (!unk)
            throw CORBA::INTERNAL ();

          cdr = unk->_tao_get_cdr ();
        }
      else
        {
          impl->marshal_value (out);
          TAO_InputCDR tmp_in (out);
          cdr = tmp_in;
        }


      CORBA::ULong arg_length;

      // If the any is a sequence, first 4 bytes of cdr hold the
      // length.
      cdr.read_ulong (arg_length);

      // If the array grows, we must do it now.
      if (arg_length > this->component_count_)
        {
          this->da_members_.size (arg_length);
        }

      CORBA::TypeCode_var field_tc =
        this->get_element_type ();

      for (CORBA::ULong i = 0; i < arg_length; ++i)
        {
          CORBA::Any field_any;
          TAO_InputCDR unk_in (cdr);
          TAO::Unknown_IDL_Type *field_unk = 0;
          ACE_NEW (field_unk,
                   TAO::Unknown_IDL_Type (field_tc.in (),
                                          unk_in));
          field_any.replace (field_unk);

          if (i < this->component_count_)
            {
              this->da_members_[i]->destroy ();
            }

          this->da_members_[i] =
            TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
              field_any._tao_get_typecode (),
              field_any,
              this->allow_truncation_ );

          // Move to the next field in the CDR stream.
          (void) TAO_Marshal_Object::perform_skip (field_tc.in (), &cdr);
        }

      // Destroy any dangling members.
      for (CORBA::ULong j = arg_length; j < this->component_count_; ++j)
        {
          this->da_members_[j]->destroy ();
        }

      // If the array shrinks, we must wait until now to do it.
      if (arg_length < this->component_count_)
        {
          this->da_members_.size (arg_length);
        }

      // Now we can update component_count_.
      this->component_count_ = arg_length;

      this->current_position_ = arg_length ? 0 : -1;
    }
  else
    {
      throw DynamicAny::DynAny::TypeMismatch ();
    }
}
Example #4
0
void
TAO_DynSequence_i::init (const CORBA::Any& any)
{
  CORBA::TypeCode_var tc = any.type ();

  CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc.in ());

  if (kind != CORBA::tk_sequence)
    {
      throw DynamicAny::DynAnyFactory::InconsistentTypeCode ();
    }

  this->type_ = tc;

  // Get the CDR stream of the Any, if there isn't one, make one.
  TAO::Any_Impl *impl = any.impl ();
  CORBA::ULong length;
  TAO_OutputCDR out;
  TAO_InputCDR cdr (static_cast<ACE_Message_Block *> (0));

  if (impl->encoded ())
    {
      TAO::Unknown_IDL_Type * const unk =
        dynamic_cast<TAO::Unknown_IDL_Type *> (impl);

      if (!unk)
        throw CORBA::INTERNAL ();

      cdr = unk->_tao_get_cdr ();
    }
  else
    {
      impl->marshal_value (out);
      TAO_InputCDR tmp_in (out);
      cdr = tmp_in;
    }

  // If the any is a sequence, first 4 bytes of cdr hold the
  // length.
  cdr.read_ulong (length);

  // Resize the array.
  this->da_members_.size (length);

  this->init_common ();

  // Get the type of the sequence elments.
  CORBA::TypeCode_var field_tc =
    this->get_element_type ();

  for (CORBA::ULong i = 0; i < length; ++i)
    {
      CORBA::Any field_any;
      TAO_InputCDR unk_in (cdr);
      TAO::Unknown_IDL_Type *field_unk = 0;
      ACE_NEW (field_unk,
               TAO::Unknown_IDL_Type (field_tc.in (), unk_in));
      field_any.replace (field_unk);

      // This recursive step will call the correct constructor
      // based on the type of field_any.
      this->da_members_[i] =
        TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
          field_any._tao_get_typecode (),
          field_any,
          this->allow_truncation_ );

      // Move to the next field in the CDR stream.
      (void) TAO_Marshal_Object::perform_skip (field_tc.in (), &cdr);
    }
}
Example #5
0
void generate_input_file(Configuration &conf)
{
    init_output_folder(conf);
    int in_start_line=1,in_end_line=1;
    int out_start_line=1,out_end_line=1;


    /**< Multi_Test_Case */
    if(conf.Multi_Test_Case)
    {
        in_start_line=2,in_end_line=2;
        out_start_line=1,out_end_line=1;
    }



    int current_file_number=1;

    ofstream in_fout;
    ofstream out_fout;
    ofstream slice_fout;

    char current_in_file_name[100];
    char current_out_file_name[100];
    char current_slice_file_name[100];

    sprintf(current_in_file_name,"..\\output\\%d.in",current_file_number);
    sprintf(current_out_file_name,"..\\output\\%d.out",current_file_number);
    sprintf(current_slice_file_name,"..\\output\\%d.slice",current_file_number);

    in_fout.open(current_in_file_name);

    /**< Multi_Test_Case */
    if(conf.Multi_Test_Case)
    {
        in_fout<<conf.CAPACITY_NUM<<endl;
    }

    out_fout.open(current_out_file_name);
    slice_fout.open(current_slice_file_name);

    string data_line;
    puts("------------------------------  Generating Data  ----------------------------");

    for(int i=0; i<conf.TEST_CASE_NUM; ++i)
    {
        ofstream tmp_in_fout("..\\bin\\tmp.in");
        create_one_test_case(tmp_in_fout);
        tmp_in_fout.close();

        create_tmp_out();

        if(i!=0 && i%conf.CAPACITY_NUM==0) // change to next file
        {
            printf("[successful] generate data : %2d\n",current_file_number);
            // close current file
            in_fout.close();
            out_fout.close();
            slice_fout.close();

            current_file_number++;


            in_start_line=1,in_end_line=1;
            out_start_line=1,out_start_line=1;

            /**< Multi_Test_Case */
            if(conf.Multi_Test_Case)
            {
                in_start_line=2,in_end_line=2;
                out_start_line=1,out_end_line=1;
            }

            sprintf(current_in_file_name,"..\\output\\%d.in",current_file_number);
            sprintf(current_out_file_name,"..\\output\\%d.out",current_file_number);
            sprintf(current_slice_file_name,"..\\output\\%d.slice",current_file_number);

            in_fout.open(current_in_file_name);


            /**< Multi_Test_Case */
            if(conf.Multi_Test_Case)
            {
                in_fout<<conf.CAPACITY_NUM<<endl;
            }

            out_fout.open(current_out_file_name);
            slice_fout.open(current_slice_file_name);
        }

        // write data to *.in , *.out , *.slice

        ifstream tmp_in("..\\bin\\tmp.in");
        ifstream tmp_out("..\\bin\\tmp.out");


        int cnt_tmp_in=0;
        int cnt_tmp_out=0;

        while(getline(tmp_in,data_line))
        {
            in_fout<<data_line<<endl;
            ++cnt_tmp_in;
        }

        while(getline(tmp_out,data_line))
        {
            out_fout<<data_line<<endl;
            ++cnt_tmp_out;
        }

        in_end_line=in_start_line+cnt_tmp_in-1;
        out_end_line=out_start_line+cnt_tmp_out-1;

        slice_fout<<in_start_line<<" "<<in_end_line<<" "<<out_start_line<<" "<<out_end_line<<endl;

        in_start_line=in_end_line+1;
        out_start_line=out_end_line+1;

        tmp_in.close();
        tmp_out.close();
    }

    printf("[successful] generate data : %2d\n",current_file_number);
    in_fout.close();
    out_fout.close();
    slice_fout.close();
    puts("-----------------------------------------------------------------------------");
}
Example #6
0
void
TAO_DynArray_i::from_any (const CORBA::Any& any)
{
  if (this->destroyed_)
    {
      throw ::CORBA::OBJECT_NOT_EXIST ();
    }

  CORBA::TypeCode_var tc = any.type ();
  CORBA::Boolean equivalent = this->type_.in ()->equivalent (tc.in ());

  if (equivalent)
    {
      // Get the CDR stream of the Any,if there isn't one, make one.
      TAO::Any_Impl *impl = any.impl ();
      TAO_OutputCDR out;
      TAO_InputCDR cdr (static_cast<ACE_Message_Block *> (0));

      if (impl->encoded ())
        {
          TAO::Unknown_IDL_Type * const unk =
            dynamic_cast<TAO::Unknown_IDL_Type *> (impl);

          if (!unk)
            throw CORBA::INTERNAL ();

          cdr = unk->_tao_get_cdr ();
        }
      else
        {
          impl->marshal_value (out);
          TAO_InputCDR tmp_in (out);
          cdr = tmp_in;
        }

      CORBA::ULong length = static_cast<CORBA::ULong> (this->da_members_.size ());
      CORBA::ULong arg_length = this->get_tc_length (tc.in ());

      if (length != arg_length)
        {
          throw DynamicAny::DynAny::TypeMismatch ();
        }

      CORBA::TypeCode_var field_tc = this->get_element_type ();

      for (CORBA::ULong i = 0; i < arg_length; ++i)
        {
          CORBA::Any field_any;
          TAO_InputCDR unk_in (cdr);
          TAO::Unknown_IDL_Type *field_unk = 0;
          ACE_NEW (field_unk,
                   TAO::Unknown_IDL_Type (field_tc.in (), unk_in));
          field_any.replace (field_unk);

          this->da_members_[i]->destroy ();

          this->da_members_[i] =
            TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
              field_any._tao_get_typecode (),
              field_any,
              this->allow_truncation_ );

          // Move to the next field in the CDR stream.
          (void) TAO_Marshal_Object::perform_skip (field_tc.in (), &cdr);
        }

      this->current_position_ = arg_length ? 0 : -1;
    }
  else
    {
      throw DynamicAny::DynAny::TypeMismatch ();
    }
}