void diff_type_data_put<MV,S>::apply(const Teuchos::Ptr<MV>& mv,
					 const Teuchos::ArrayView<S>& data,
					 const size_t& ldx,
					 Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map )
    {
      typedef typename MV::scalar_t mv_scalar_t;
      
      int vals_length = data.size();
      Teuchos::Array<mv_scalar_t> data_tmp(vals_length);
      
      for ( int i = 0; i < vals_length; ++i ){
	data_tmp[i] = Teuchos::as<mv_scalar_t>(data[i]);
      }
      
      mv->put1dData(data_tmp(), ldx, distribution_map);
    }
Esempio n. 2
0
mpi_controller::mpi_job::mpi_job(size_t dat_s, MPI_Datatype dtype, int _dest,
        MPI_Comm _comm, void* dat):
    size(dat_s), type(dtype), dest(_dest), comm(_comm){
        int dat_size;
        MPI_Type_size(dtype, &dat_size);
        std::unique_ptr<char> data_tmp(new char[dat_size*dat_s+2*MPI_BSEND_OVERHEAD]);
        data = std::move(data_tmp);
        if(dat){
            char* cdat = (char*)dat;
            std::copy(cdat, cdat+dat_size*dat_s, data.get());
        }
    }
    void diff_type_data_put<MV,S>::apply(const Teuchos::Ptr<MV>& mv,
                                         const Teuchos::ArrayView<S>& data,
                                         const size_t& ldx,
                                         Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
                                         EDistribution distribution )
    {
      typedef typename MV::scalar_t mv_scalar_t;
      typedef typename Teuchos::Array<mv_scalar_t>::size_type size_type;

      TEUCHOS_TEST_FOR_EXCEPTION(
        mv.getRawPtr () == NULL, std::invalid_argument,
        "Amesos2::diff_type_data_put(4 args): mv is null.");

      const size_type vals_length = data.size ();
      Teuchos::Array<mv_scalar_t> data_tmp (vals_length);

      for (size_type i = 0; i < vals_length; ++i) {
        data_tmp[i] = Teuchos::as<mv_scalar_t> (data[i]);
      }

      mv->put1dData (data_tmp (), ldx, distribution_map, distribution);
    }
Esempio n. 4
0
   void cxios_write_data_k40(const char* fieldid, int fieldid_size, float* data_k4, int data_Xsize)
   {
      std::string fieldid_str;
      if (!cstr2string(fieldid, fieldid_size, fieldid_str)) return;

      CTimer::get("XIOS").resume();
      CTimer::get("XIOS send field").resume();
      CContext* context = CContext::getCurrent();
      if (!context->hasServer && !context->client->isAttachedModeEnabled())
        context->checkBuffersAndListen();

      CArray<float, 1> data_tmp(data_k4, shape(data_Xsize), neverDeleteData);
      CArray<double, 1> data(data_Xsize) ;
      data = data_tmp;
      CField::get(fieldid_str)->setData(data);
      CTimer::get("XIOS send field").suspend();
      CTimer::get("XIOS").suspend();
   }
Esempio n. 5
0
bool
FitsInput::read_native_scanline (int y, int z, void *data)
{
    // we return true just to support 0x0 images
    if (!m_naxes)
        return true;

    std::vector<unsigned char> data_tmp (m_spec.scanline_bytes ());
    long scanline_off = (m_spec.height - y) * m_spec.scanline_bytes ();
    fseek (m_fd, scanline_off, SEEK_CUR);
    size_t n = fread (&data_tmp[0], 1, m_spec.scanline_bytes(), m_fd);
    if (n != m_spec.scanline_bytes()) {
        if (feof (m_fd))
            error ("Hit end of file unexpectedly");
        else
            error ("read error");
        return false;   // Read failed
    }

    // in FITS image data is stored in big-endian so we have to switch to
    // little-endian on little-endian machines
    if (littleendian ()) {
        if (m_spec.format == TypeDesc::USHORT)
            swap_endian ((unsigned short*)&data_tmp[0],
                         data_tmp.size () / sizeof (unsigned short));
        else if (m_spec.format == TypeDesc::UINT)
            swap_endian ((unsigned int*)&data_tmp[0],
                         data_tmp.size () / sizeof (unsigned int));
        else if (m_spec.format == TypeDesc::FLOAT)
            swap_endian ((float*)&data_tmp[0],
                         data_tmp.size () / sizeof (float));
        else if (m_spec.format == TypeDesc::DOUBLE)
            swap_endian ((double*)&data_tmp[0],
                         data_tmp.size () / sizeof (double));
    }

    memcpy (data, &data_tmp[0], data_tmp.size ());

    // after reading scanline we set file pointer to the start of image data
    fsetpos (m_fd, &m_filepos);
    return true;
};
Esempio n. 6
0
   void cxios_read_data_k46(const char* fieldid, int fieldid_size, float* data_k4,
                            int data_0size, int data_1size, int data_2size,
                            int data_3size, int data_4size, int data_5size)
   {
      std::string fieldid_str;
      if (!cstr2string(fieldid, fieldid_size, fieldid_str)) return;

      CTimer::get("XIOS").resume();
      CTimer::get("XIOS recv field").resume();

      CContext* context = CContext::getCurrent();
      if (!context->hasServer && !context->client->isAttachedModeEnabled())
        context->checkBuffersAndListen();

      CArray<double, 6> data(data_0size, data_1size, data_2size, data_3size, data_4size, data_5size);
      CField::get(fieldid_str)->getData(data);
      CArray<float, 6> data_tmp(data_k4, shape(data_0size, data_1size, data_2size, data_3size, data_4size, data_5size), neverDeleteData);
      data_tmp = data;

      CTimer::get("XIOS recv field").suspend();
      CTimer::get("XIOS").suspend();
    }