Example #1
0
MTEST_THREAD_RETURN_TYPE run_test(void *arg)
{
    int thread_id = (int)(long) arg;
    int i, j, peer;
    MPI_Status status[WINDOW];
    MPI_Request req[WINDOW];
    double start, end;
    int err;
    int local_num_threads = -1;

    if (tp[thread_id].use_proc_null)
        peer = MPI_PROC_NULL;
    else
        peer = (rank % 2) ? rank - 1 : rank + 1;

    err = MTest_thread_lock(&num_threads_lock);
    if (err) ABORT_MSG("unable to acquire lock, aborting\n");
    local_num_threads = num_threads;
    err = MTest_thread_unlock(&num_threads_lock);
    if (err) ABORT_MSG("unable to release lock, aborting\n");

    MTest_thread_barrier(num_threads);

    start = MPI_Wtime();

    if (tp[thread_id].use_blocking_comm) {
        if ((rank % 2) == 0) {
            for (i = 0; i < LOOPS; i++)
                for (j = 0; j < WINDOW; j++)
                    MPI_Send(sbuf, tp[thread_id].msg_size, MPI_CHAR, peer, 0, MPI_COMM_WORLD);
        }
        else {
            for (i = 0; i < LOOPS; i++)
                for (j = 0; j < WINDOW; j++)
                    MPI_Recv(rbuf, tp[thread_id].msg_size, MPI_CHAR, peer, 0, MPI_COMM_WORLD,
                             &status[0]);
        }
    }
    else {
        for (i = 0; i < LOOPS; i++) {
            if ((rank % 2) == 0) {
                for (j = 0; j < WINDOW; j++)
                    MPI_Isend(sbuf, tp[thread_id].msg_size, MPI_CHAR, peer, 0, MPI_COMM_WORLD,
                              &req[j]);
            }
            else {
                for (j = 0; j < WINDOW; j++)
                    MPI_Irecv(rbuf, tp[thread_id].msg_size, MPI_CHAR, peer, 0, MPI_COMM_WORLD,
                              &req[j]);
            }
            MPI_Waitall(WINDOW, req, status);
        }
    }

    end = MPI_Wtime();
    tp[thread_id].latency = 1000000.0 * (end - start) / (LOOPS * WINDOW);

    MTest_thread_barrier(num_threads);
    return MTEST_THREAD_RETVAL_IGN;
}
Example #2
0
template <class ZT> int svpcvp(Options &o, ZZ_mat<ZT> &b, const vector<Z_NR<ZT>> &target)
{
  if (target.empty())
  {
    ABORT_MSG("mpz required for SVP");
  }
  else
  {
    ABORT_MSG("mpz required for CVP");
  }
}
Example #3
0
 void hdf5ToText (const boost::filesystem::path& input, const StreamOrPathOutput& output, const boost::optional<std::string>& typeOverwrite, bool thetaMax180, bool noPhi) {
   HDF5::File file = HDF5::File::open (input, H5F_ACC_RDONLY);
   boost::shared_ptr<DataFiles::File> fileInfo;
   if (typeOverwrite) {
     fileInfo = boost::make_shared<DataFiles::File> ();
     fileInfo->Type = *typeOverwrite;
   } else {
     fileInfo = HDF5::matlabDeserialize<DataFiles::File> (file);
   }
   //Core::OStream::getStderr () << fileInfo->Type << std::endl;
   if (fileInfo->Type == "JonesFarField") {
     //boost::shared_ptr<DataFiles::JonesFarFieldFile<double> > data = HDF5::matlabDeserialize<DataFiles::JonesFarFieldFile<double> > (file);
     //boost::shared_ptr<DataFiles::JonesFarField<double> > farField = data.FarField;
     boost::shared_ptr<DataFiles::JonesFarField<double> > farField = HDF5::matlabDeserialize<DataFiles::JonesFarField<double> > (file, "JonesFarField");
     if (thetaMax180)
       farField = removeThetaLarger180 (farField);
     JonesCalculus<double>::storeTxt (getStream (output), farField, !noPhi);
   } else if (fileInfo->Type == "MuellerFarField") {
     //boost::shared_ptr<DataFiles::MuellerFarFieldFile<double> > data = HDF5::matlabDeserialize<DataFiles::MuellerFarFieldFile<double> > (file);
     //boost::shared_ptr<DataFiles::MuellerFarField<double> > muellerFarField = data.MuellerFarField;
     boost::shared_ptr<DataFiles::MuellerFarField<double> > muellerFarField = HDF5::matlabDeserialize<DataFiles::MuellerFarField<double> > (file, "MuellerFarField");
     if (thetaMax180)
       muellerFarField = removeThetaLarger180 (muellerFarField);
     MuellerCalculus<double>::storeTxt (getStream (output), muellerFarField, noPhi);
   } else if (fileInfo->Type == "DDAField") {
     HDF5::matlabDeserialize<DataFiles::DDAFieldFile<double> > (file)->writeTxt (getStream (output));
   } else if (fileInfo->Type == "Geometry") {
     HDF5::matlabDeserialize<DataFiles::DDADipoleListGeometryFile> (file)->writeTxt (getStream (output));
   } else if (fileInfo->Type == "CrossSection") {
     HDF5::matlabDeserialize<DataFiles::CrossSectionFile> (file)->writeTxt (getStream (output));
   } else {
     ABORT_MSG ("Unknown file type '" + fileInfo->Type + "'");
   }
 }
Example #4
0
  template <class ftype> const LinAlg::GpuFFTPlanFactory<ftype>& getPlanFactory (const boost::program_options::variables_map& map, UNUSED const OpenCL::StubPool& pool) {
    std::map<std::string, const LinAlg::GpuFFTPlanFactory<ftype>* > factories;
    factories["cl"] = &LinAlg::getGpuFFTPlanClFactory<ftype> ();
#ifdef ADDITIONAL_OPENCL_FFT_FACTORIES
    ADDITIONAL_OPENCL_FFT_FACTORIES
#endif

      std::string name;
    if (map.count ("opencl-fft")) {
      name = map["opencl-fft"].as<std::string> ();
    } else {
      name = "cl";
    }

    typename std::map<std::string, const LinAlg::GpuFFTPlanFactory<ftype>* >::const_iterator ir = factories.find (name);
    if (ir == factories.end ()) {
      std::string valid;
      typedef std::pair<std::string, const LinAlg::GpuFFTPlanFactory<ftype>* > PairType;
      BOOST_FOREACH (PairType pair, factories) {
        if (valid != "")
          valid += ", ";
        valid += pair.first;
      }
      ABORT_MSG ("Unknown OpenCL fft implementation `" + name + "', known ones are " + valid);
    } else {
Example #5
0
  void Object::checkType () const {
    if (!isValid ())
      return;
    H5I_type_t type = getType ();
    switch (type) {
    case H5I_GROUP:
    case H5I_DATATYPE:
    case H5I_DATASET:
      break;

    default:
      ABORT_MSG ("Not a object");
    }
  }
Example #6
0
bool Option<bool>::parse(const char* value, std::size_t value_len) {
	assert(value_len == 1);
	char first = value[0];
	if (first == '-') {
		set_value(false);
		return true;
	}
	if (first == '+') {
		set_value(true);
		return true;
	}
	ABORT_MSG("ERROR", "boolean option not valid: " << value);
	return false;
}
Example #7
0
 void MatlabObject::checkScalar () const {
   ASSERT (!isStruct ());
   ASSERT (!isEmpty ());
   size_t ndims = size ().size ();
   if (ndims == 0) {
     return;
   } else if (ndims == 1) {
     ASSERT (size ()[0] == 1);
   } else if (ndims == 2) {
     ASSERT (size ()[0] == 1 && size ()[1] == 1);
   } else {
     ABORT_MSG ("ndims is larger than 2");
   }
 }
Example #8
0
 size_t MatlabObject::get1dLength () const {
   size_t ndims = size ().size ();
   if (isEmpty ()) {
     if (!isNullDataSpace ()) {
       ASSERT (ndims <= 2);
       BOOST_FOREACH (size_t s, size ())
         ASSERT (s == 0 || s == 1);
     }
     return 0;
   } else { 
     if (ndims == 1) {
       return size ()[0];
     } else if (ndims == 2) {
       if (size ()[0] == 1)
         return size ()[1];
       else if (size ()[1] == 1)
         return size ()[0];
       else
         ABORT_MSG ("got 2d-dataspace with both dimensions != 1");
     } else {
       ABORT_MSG ("ndims is neither 1 nor 2");
     }
   }
 }
Example #9
0
void resaveHdf5 (const boost::filesystem::path& input, const boost::filesystem::path& output, const boost::optional<std::string>& typeOverwrite, bool thetaMax180) {
    HDF5::File inputFile = HDF5::File::open (input, H5F_ACC_RDONLY);
    boost::shared_ptr<DataFiles::File> fileInfo;
    if (typeOverwrite) {
        fileInfo = boost::make_shared<DataFiles::File> ();
        fileInfo->Type = *typeOverwrite;
    } else {
        fileInfo = HDF5::matlabDeserialize<DataFiles::File> (inputFile);
    }
    //Core::OStream::getStderr () << fileInfo->Type << std::endl;
    if (fileInfo->Type == "JonesFarField") {
        //boost::shared_ptr<DataFiles::JonesFarFieldFile<double> > data = HDF5::matlabDeserialize<DataFiles::JonesFarFieldFile<double> > (inputFile);
        //boost::shared_ptr<DataFiles::JonesFarField<double> > farField = data.FarField;
        boost::shared_ptr<DataFiles::JonesFarField<double> > farField = HDF5::matlabDeserialize<DataFiles::JonesFarField<double> > (inputFile, "JonesFarField");
        if (thetaMax180)
            farField = removeThetaLarger180 (farField);

        HDF5::File outputFile = HDF5::createMatlabFile (output);
        HDF5::matlabSerialize (outputFile, "JonesFarField", farField);
        if (inputFile.rootGroup ().exists ("Parameters"))
            HDF5::Group::copyObject (inputFile.rootGroup (), "Parameters", outputFile.rootGroup (), "Parameters");
        if (inputFile.rootGroup ().exists ("Geometry"))
            HDF5::Group::copyObject (inputFile.rootGroup (), "Geometry", outputFile.rootGroup (), "Geometry");
        HDF5::matlabSerialize (outputFile, "Type", "JonesFarField");
    } else if (fileInfo->Type == "MuellerFarField") {
        //boost::shared_ptr<DataFiles::MuellerFarFieldFile<double> > data = HDF5::matlabDeserialize<DataFiles::MuellerFarFieldFile<double> > (inputFile);
        //boost::shared_ptr<DataFiles::MuellerFarField<double> > muellerFarField = data.MuellerFarField;
        boost::shared_ptr<DataFiles::MuellerFarField<double> > muellerFarField = HDF5::matlabDeserialize<DataFiles::MuellerFarField<double> > (inputFile, "MuellerFarField");
        if (thetaMax180)
            muellerFarField = removeThetaLarger180 (muellerFarField);

        HDF5::File outputFile = HDF5::createMatlabFile (output);
        HDF5::matlabSerialize (outputFile, "MuellerFarField", muellerFarField);
        if (inputFile.rootGroup ().exists ("Parameters"))
            HDF5::Group::copyObject (inputFile.rootGroup (), "Parameters", outputFile.rootGroup (), "Parameters");
        if (inputFile.rootGroup ().exists ("Geometry"))
            HDF5::Group::copyObject (inputFile.rootGroup (), "Geometry", outputFile.rootGroup (), "Geometry");
        HDF5::matlabSerialize (outputFile, "Type", "MuellerFarField");
    } else if (fileInfo->Type == "DDAField") {
        HDF5::matlabSerialize (output, *HDF5::matlabDeserialize<DataFiles::DDAFieldFile<double> > (inputFile));
    } else if (fileInfo->Type == "Geometry") {
        HDF5::matlabSerialize (output, *HDF5::matlabDeserialize<DataFiles::DDADipoleListGeometryFile> (inputFile));
    } else if (fileInfo->Type == "CrossSection") {
        HDF5::matlabSerialize (output, *HDF5::matlabDeserialize<DataFiles::CrossSectionFile> (inputFile));
    } else {
        ABORT_MSG ("Unknown file type '" + fileInfo->Type + "'");
    }
}
Example #10
0
std::string WindowsError::errnumToString (ErrorNumType errnum) {
    std::stringstream str;
    char* lpMsgBuf;
    if (!FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errnum, MAKELANGID (LANG_NEUTRAL, SUBLANG_NEUTRAL), (char*) &lpMsgBuf, 0, NULL)) {
        DWORD err2 = GetLastError ();
        str << "FormatMessage () for " << errnum << " returned " << err2;
        ABORT_MSG (str.str ());
    }
    Core::WindowsLocalRefHolder<char> refHolder (lpMsgBuf);
    size_t len = strlen (lpMsgBuf);
    if (len && lpMsgBuf[len - 1] == '\n') {
        lpMsgBuf[len - 1] = 0;
        if ((len > 1) && lpMsgBuf[len - 2] == '\r')
            lpMsgBuf[len - 2] = 0;
    }
    str << lpMsgBuf << " (" << errnum << ")";
    return str.str ();
}
 void CompoundType::checkType () const {
   if (!isValid ())
     return;
   if (getClass () != H5T_COMPOUND)
     ABORT_MSG ("Not a compound datatype");
 }
Example #12
0
template <class ZT> int hkz(Options &o, ZZ_mat<ZT> &b) { ABORT_MSG("mpz required for HKZ"); }
 void OpaqueType::checkType () const {
   if (!isValid ())
     return;
   if (getClass () != H5T_OPAQUE)
     ABORT_MSG ("Not a opaque datatype");
 }
Example #14
0
 void DataSet::checkType () const {
   if (!isValid ())
     return;
   if (getType () != H5I_DATASET)
     ABORT_MSG ("Not a dataset");
 }
Example #15
0
template <class ZT> int bkz(Options &, ZZ_mat<ZT> &) { ABORT_MSG("mpz required for BKZ"); }
Example #16
0
  DevicePattern DevicePattern::parse (const std::string& str) {
    DevicePattern r;
    std::string s = str;

    r.list_ = false;
    if (endsWith (s, ":list")) {
      s = s.substr (0, s.length () - strlen (":list"));
      r.list_ = true;
    } else if (s == "list") {
      s = "all";
      r.list_ = true;
    }

    size_t dotpos = s.find (".");
    if (dotpos == std::string::npos) {
      if (s.length () > 0 && s[0] >= '0' && s[0] <= '9') {
        r.hasPlatform_ = true;
        r.platform_ = boost::lexical_cast<size_t> (s);
        r.type_ = CL_DEVICE_TYPE_ALL;
        return r;
      } else {
        r.hasPlatform_ = false;
      }
    } else {
      r.hasPlatform_ = true;
      r.platform_ = boost::lexical_cast<size_t> (s.substr (0, dotpos));
      s = s.substr (dotpos + 1);
    }

    if (s.length () > 0 && s[0] >= '0' && s[0] <= '9') {
      r.type_ = 0;

      size_t pos = 0;
      size_t pos_old = 0;
      s += ",";
      while ((pos = s.find (",", pos)) != std::string::npos) {
        r.devices_.push_back (boost::lexical_cast<size_t> (s.substr (pos_old, pos - pos_old)));
        pos = pos + 1;
        pos_old = pos;
      }
    } else {
      if (s == "all") {
        r.type_ = CL_DEVICE_TYPE_ALL;
        return r;
      }

      if (s == "auto") {
        r.type_ = 0;
        return r;
      }

      r.type_ = 0;
      size_t pos = 0;
      size_t pos_old = 0;
      s += ",";
      while ((pos = s.find (",", pos)) != std::string::npos) {
        std::string t = s.substr (pos_old, pos - pos_old);
        if (t == "cpu") {
          r.type_ |= CL_DEVICE_TYPE_CPU;
        } else if (t == "gpu") {
          r.type_ |= CL_DEVICE_TYPE_GPU;
        } else if (t == "accelerator") {
          r.type_ |= CL_DEVICE_TYPE_ACCELERATOR;
        } else {
          ABORT_MSG ("Unknown device type `" + t + "'");
        }
        pos = pos + 1;
        pos_old = pos;
      }
    }

    return r;
  }
Example #17
0
void DataType::checkType () const {
    if (!isValid ())
        return;
    if (getType () != H5I_DATATYPE)
        ABORT_MSG ("Not a datatype");
}
Example #18
0
  MatlabObject::MatlabObject (const HDF5::Object& o) {
    HDF5::Object object = o;

    bool hasEmptyAttribute;

    for (;;) {
      isOctaveNewFormat_ = object.getType () == H5I_GROUP && object.existsAttribute ("OCTAVE_NEW_FORMAT");
      if (!isOctaveNewFormat_) {
        hasEmptyAttribute = object.existsAttribute ("MATLAB_empty");
        break;
      }

      HDF5::Group grp = (HDF5::Group) object;
      HDF5::DataSet typeDs = (HDF5::DataSet) grp.open ("type", setEFilePrefix ());

      ASSERT (typeDs.getSpace ().getSimpleExtentType () == H5S_SCALAR);
      HDF5::DataSpace s = HDF5::DataSpace::create (H5S_SCALAR);

      HDF5::StringType ty = (HDF5::StringType) typeDs.getDataType ();
      ASSERT (!(Exception::check ("H5Tis_variable_str", H5Tis_variable_str (ty.handle ())) != 0));

      /*
        const char* str = NULL;
        HDF5::DataType t = getH5Type<const char*> ();
        typeDs.read (&str, t, s, s);
        std::string str2 (str);
        typeDs.vlenReclaim (&str, t, s);
      */

      size_t size = H5Tget_size (ty.handle ());
      HDF5::Exception::check ("H5Tget_size", size ? 0 : -1);
      std::vector<char> str (size);
      typeDs.read (str.data (), ty, s, s);
      std::string str2 (str.begin (), str.end ());

      size_t pos = str2.find ('\0');
      if (pos != std::string::npos)
        str2 = str2.substr (0, pos);

      if (str2 != "cell") { 
        hasEmptyAttribute = grp.existsAttribute ("OCTAVE_EMPTY_MATRIX");
        object = grp.open ("value", setEFilePrefix ());
        octaveType_ = str2;
        break;
      } else {
        HDF5::DataSet dimsDs = (HDF5::DataSet) grp.open ("value/dims", setEFilePrefix ());
        HDF5::DataSpace dimsSp = dimsDs.getSpace ();
        ASSERT (dimsSp.getSimpleExtentType () == H5S_SIMPLE);
        ASSERT (dimsSp.getSimpleExtentNdims () == 1);
        hsize_t dim;
        dimsSp.getSimpleExtentDims (&dim);
        ASSERT (dim == 2);
        
        int64_t dims[2];
        dimsDs.read (dims, HDF5::getH5Type<int64_t> (), dimsSp);
        ASSERT (dims[0] == 1);
        ASSERT (dims[1] == 1);

        object = grp.open ("value/_0", setEFilePrefix ());
      }
    }

    H5I_type_t type = object.getType ();

    if (type == H5I_DATASET) {
      isStruct_ = false;
      dataSet_ = (HDF5::DataSet) object;
      if (hasEmptyAttribute) {
        isEmpty_ = true;
        isNullDataSpace_ = false;

        HDF5::DataSpace dataSpace = dataSet_.getSpace ();
        ASSERT (dataSpace.getSimpleExtentType () == H5S_SIMPLE);
        ASSERT (dataSpace.getSimpleExtentNdims () == 1);
        hsize_t ndims;
        dataSpace.getSimpleExtentDims (&ndims);
        ASSERT (ndims > 0);

        std::vector<uint64_t> values (Core::checked_cast<size_t> (ndims));
        dataSet_.read (values.data (), getH5Type<uint64_t> (), dataSpace);

        bool foundZero = false;
        for (size_t i = 0; i < ndims; i++)
          if (!values[i])
            foundZero = true;
        ASSERT (foundZero);

        size_.resize (Core::checked_cast<size_t> (ndims));
        for (size_t i = 0; i < ndims; i++) {
          ASSERT (values[i] <= std::numeric_limits<size_t>::max ());
          size_[i] = Core::checked_cast<size_t> (values[i]);
        }
      } else {
        dataSpace_ = dataSet_.getSpace ();
        H5S_class_t extentType = dataSpace_.getSimpleExtentType ();
        //ASSERT (extentType == H5S_SIMPLE || extentType == H5S_NULL);
        ASSERT (extentType == H5S_SIMPLE || extentType == H5S_NULL || extentType == H5S_SCALAR);
        if (extentType == H5S_SIMPLE) {
          isNullDataSpace_ = false;
          size_t dim = dataSpace_.getSimpleExtentNdims ();
          size_.resize (dim);
          std::vector<hsize_t> dims (dim);
          dataSpace_.getSimpleExtentDims (dims.data ());
          isEmpty_ = false;
          for (size_t i = 0; i < dim; i++) {
            ASSERT (dims[i] >= std::numeric_limits<size_t>::min () && dims[i] <= std::numeric_limits<size_t>::max ());
            size_[dim - 1 - i] = Core::checked_cast<size_t> (dims[i]);
            if (!dims[i])
              isEmpty_ = true;
          }
          if (isEmpty_) {
            dataSpace_ = HDF5::DataSpace ();
          }
        } else if (extentType == H5S_SCALAR) {
          isNullDataSpace_ = false;
          isEmpty_ = false;
          //size_.resize (0);
          size_.resize (1);
          size_[0] = 1;
        } else { // H5S_NULL
          isEmpty_ = true;
          isNullDataSpace_ = true;
          size_.resize (1);
          size_[0] = 0;
        }
      }
      if (isEmpty_)
        dataSet_ = HDF5::DataSet ();
    } else if (type == H5I_GROUP) {
      isStruct_ = true;
      group_ = (HDF5::Group) object;
    } else {
      ABORT_MSG ("Unknown object type");
    }
  }
Example #19
0
  cl::Context createContext (std::string arg, const Core::OStream& out) {
    DevicePattern pattern = DevicePattern::parse (arg);
    PlatformList list = PlatformList::getPlatformList ();

    std::vector<DeviceEntry> devices;
    if (pattern.hasPlatform ()) {
      if (pattern.platform () >= list.platforms ().size ())
        ABORT_MSG ("Invalid platform id " + boost::lexical_cast<std::string> (pattern.platform ()));
      devices = list.platforms ()[pattern.platform ()]->getDevices (pattern.typeOrAll ());
    } else {
      devices = list.getDevices (pattern.typeOrAll ());
    }

    if (pattern.devices ().size () > 0) {
      std::vector<DeviceEntry> devices2;
      size_t platform = pattern.platform ();
      for (size_t i = 0; i < pattern.devices ().size (); i++) {
        size_t devid = pattern.devices ()[i];
        bool found = false;
        for (size_t j = 0; j < devices.size () && !found; j++) {
          ASSERT (devices[j].platform ().id () == platform);
          if (devices[j].id () == devid) {
            found = true;
            devices2.push_back (devices[j]);
          }
        }
        if (!found)
          ABORT_MSG ("Invalid device id " + boost::lexical_cast<std::string> (devid) + " for platform id " + boost::lexical_cast<std::string> (platform));
      }
      devices = devices2;
    } else if (pattern.type () == 0) {
      devices = getAuto (devices);
    } else {
    }

    if (pattern.list ()) {
      std::stringstream str;
      size_t lastPl = (size_t) (ssize_t) -1;
      for (size_t i = 0; i < devices.size (); i++) {
        const DeviceEntry& dev = devices[i];
        if (dev.platform ().id () != lastPl) {
          lastPl = dev.platform ().id ();
          str << dev.platform ().toString () << std::endl;
        }
        str << " " << dev.toString () << std::endl;
      }
      throw Core::HelpResultException (str.str ());
    }

    if (pattern.devices ().size () == 0 && devices.size () > 0) {
      devices.erase (devices.begin () + 1, devices.end ());
    }

    if (devices.size () == 0)
      ABORT_MSG ("No matching device found");

    if (devices.size () == 1) {
      out << "Using device " << devices[0].toString () << std::endl;
    } else {
      out << "Using devices:" << std::endl;
      for (size_t i = 0; i < devices.size (); i++)
        out << " " << devices[i].toString () << std::endl;
    }

    std::vector<cl::Device> clDevs;
    for (size_t i = 0; i < devices.size (); i++)
      clDevs.push_back (devices[i].device ());

    cl::Context context (clDevs);
    return context;
  }
Example #20
0
void loops(void)
{
    int i, nt;
    double latency, mrate, avg_latency, agg_mrate;
    int err;
    
    err = MTest_thread_lock_create(&num_threads_lock);
    if (err) ABORT_MSG("unable to create lock, aborting\n");

    for (nt = 1; nt <= MAX_THREADS; nt++) {
        err = MTest_thread_lock(&num_threads_lock);
        if (err) ABORT_MSG("unable to acquire lock, aborting\n");

        num_threads = 1;
        MPI_Barrier(MPI_COMM_WORLD);
        MTest_thread_barrier_init();

        for (i = 1; i < nt; i++) {
            err = MTest_Start_thread(run_test, (void *)(long)i);
            if (err) {
                /* attempt to continue with fewer threads, we may be on a
                 * thread-constrained platform like BG/P in DUAL mode */
                break;
            }
            ++num_threads;
        }

        err = MTest_thread_unlock(&num_threads_lock);
        if (err) ABORT_MSG("unable to release lock, aborting\n");

        if (nt > 1 && num_threads <= 1) {
            ABORT_MSG("unable to create any additional threads, aborting\n");
        }

        run_test((void *) 0); /* we are thread 0 */
        err = MTest_Join_threads();
        if (err) {
            printf("error joining threads, err=%d", err);
            MPI_Abort(MPI_COMM_WORLD, 1);
        }

        MTest_thread_barrier_free();

        latency = 0;
        for (i = 0; i < num_threads; i++)
            latency += tp[i].latency;
        latency /= num_threads; /* Average latency */
        mrate = num_threads / latency; /* Message rate */

        /* Global latency and message rate */
        MPI_Reduce(&latency, &avg_latency, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
        avg_latency /= size;
        MPI_Reduce(&mrate, &agg_mrate, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);

        if (!rank && verbose) {
            printf("Threads: %d; Latency: %.3f; Mrate: %.3f\n",
                   num_threads, latency, mrate);
        }
    }

    err = MTest_thread_lock_free(&num_threads_lock);
    if (err) ABORT_MSG("unable to free lock, aborting\n");
}
Example #21
0
  template <class F> boost::shared_ptr<std::vector<std::complex<F> > > IterativeSolverBase<F>::getPolVec (const std::vector<ctype>& einc, ftype eps, std::ostream& log, const std::vector<ctype>& start, Core::ProfilingDataPtr prof) {
    this->inprodR_ = initGeneral (einc, log, start, prof);
    log << "inprodR = " << this->inprodR_ << std::endl;

    this->epsB = eps * eps / this->residScale;
    this->prev_err = std::sqrt (this->residScale * this->inprodR_);
    this->count = 0;
    this->counter = 0;

    this->inprodRInit = this->inprodR_;
    this->needNewline = false;
    this->initTime = Core::getCurrentTime ();

    {
      Core::ProfileHandle _p1 (prof, "itsolv");
      init (log, prof);
      while (inprodR_ >= epsB /* && count + 1 <= maxIter && counter <= maxResIncrease */) {
        if (this->count >= maxIter) {
          ABORT_MSG ("Too many iterations");
        } else if (this->counter > this->maxResIncrease) {
          ABORT_MSG ("Too many iterations w/o increase");
        }
        ftype inprodRplus1 = iteration (count, log, false, prof);
        count++;
        { // LoopUpdate
          if (inprodRplus1 <= inprodR_) {
            inprodR_ = inprodRplus1;
            counter = 0;
          } else {
            counter++;
          }
          ftype err = std::sqrt (residScale * inprodRplus1);
          ftype progr = 1 - err / prev_err;
          std::stringstream progStr;
          ftype prog = (std::log (this->inprodR_) - std::log (this->inprodRInit)) / (std::log (epsB) - std::log (this->inprodRInit));
          Core::TimeSpan now = Core::getCurrentTime ();
          Core::TimeSpan remain = (now - this->initTime) * static_cast<double> ((1 - prog) / prog);
          progStr << "RE_" << std::setfill ('0') << std::setw (5) << count << " = " << std::scientific << std::setfill (' ') << std::setw (12) << err << "  ";
          if (counter == 0)
            progStr << "+ ";
          else if (progr > 0)
            progStr << "-+";
          else
            progStr << "- ";
          progStr << "  [" << std::fixed << std::setprecision (2) << std::setw (6) << prog * 100 << "%]  [" << std::setfill (' ') << std::setw (12) << remain.toString () << "]";
          if (this->needNewline)
            Core::OStream::getStderr () << "\n";
          Core::OStream::getStderr () << progStr.str ();
          /*
            this->needNewline = count <= 1
            || (count < 100 && count % 10 == 0)
            || (count <= 1000 && count % 100 == 0);
          */
          this->needNewline = false;
          Core::OStream::getStderr () << "\r" << std::flush;
          log << progStr.str () << std::endl;
          prev_err = err;
        }
      }
      Core::OStream::getStderr () << std::endl;
    }

    return getResult (log, prof);
  }