void ExecutorCommon::init(){

    actuatorHandles[ActuatorType::RELOAD_CONFIG]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::reloadConfig);
    actuatorHandles[ActuatorType::GET_POPCORN]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::getPopcorn);
    actuatorHandles[ActuatorType::UNLOAD_POPCORN]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::unloadPopcorn);
    actuatorHandles[ActuatorType::KICK_RIGHT]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::kickRight);
    actuatorHandles[ActuatorType::KICK_LEFT]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::kickLeft);
    actuatorHandles[ActuatorType::UNKICK_RIGHT]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::unKickRight);
    actuatorHandles[ActuatorType::UNKICK_LEFT]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::unKickLeft);
    actuatorHandles[ActuatorType::GET_OBJECT]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::getObject);
    actuatorHandles[ActuatorType::UNLOAD_OBJECT]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::unloadObject);
    actuatorHandles[ActuatorType::RELOAD_CONFIG]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::reloadConfig);
    actuatorHandles[ActuatorType::GET_OBJECT_STOP]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::getObjectStop);
    actuatorHandles[ActuatorType::START_BRXON]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::startBrxon);
    actuatorHandles[ActuatorType::STOP_BRXON]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::stopBrxon);
    actuatorHandles[ActuatorType::START_BEACON]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::startBeacon);
    actuatorHandles[ActuatorType::STOP_BEACON]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::stopBeacon);
    actuatorHandles[ActuatorType::LEAVE_CARPET]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::leaveCarpet);
    actuatorHandles[ActuatorType::CARPET_LEAVE]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::carpetLeave);
    actuatorHandles[ActuatorType::CARPET_POSITION_1]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::carpetPosition1);
    actuatorHandles[ActuatorType::CARPET_POSITION_2]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::carpetPosition2);
    actuatorHandles[ActuatorType::CARPET_POSITION_OPEN]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::carpetPositionOpen);
    actuatorHandles[ActuatorType::CARPET_POSITION_CLOSE]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::carpetPositionClose);
    actuatorHandles[ActuatorType::CALLBACK_GET_LEFT]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::callbackGetLeft);
    actuatorHandles[ActuatorType::CALLBACK_GET_RIGHT]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::callbackGetRight);
    actuatorHandles[ActuatorType::START_DETECTION]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::startDetection);
    actuatorHandles[ActuatorType::STOP_DETECTION]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::stopDetection);

    //enemy detecotr
    actuatorHandles[ActuatorType::SENSOR_CALLBACK]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::sensorCommand);
    actuatorHandles[ActuatorType::BRKON_CALLBACK]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::brkonCommand);
    actuatorHandles[ActuatorType::BEACON_MALI_CALLBACK]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::beaconMaliCommand);
    actuatorHandles[ActuatorType::BEACON_VELIKI_CALLBACK]=static_cast<ActuatorCommandHandle>(&ExecutorCommon::beaconVelikiCommand);

    //added for new "Srednji mehanizam"




    suscribeToSensore();
    suscribe();
    mapping();

}
示例#2
0
/* Convert atom to name */
static int unatom(struct inode *atable, atom_t atom, char *name, unsigned size)
{
	if(DEBUG_MODE_K==1)
	{
		printf("\t\t\t\t%25s[K]  %25s  %4d  #in\n",__FILE__,__func__,__LINE__);
	}
	struct sb *sb = tux_sb(atable->i_sb);
	struct buffer_head *buffer;
	int err;

	loff_t where = unatom_dict_read(atable, atom);
	if (where < 0) {
		err = where;
		goto error;
	}

	buffer = blockread(mapping(atable), where >> sb->blockbits);
	if (!buffer) {
		err = -EIO;
		goto error;
	}
	tux_dirent *entry = bufdata(buffer) + (where & sb->blockmask);
	if (entry_atom(entry) != atom) {
		tux3_fs_error(sb, "atom %x reverse entry broken", atom);
		err = -EIO;
		goto error_blockput;
	}
	unsigned len = entry->name_len;
	if (size) {
		if (len > size) {
			err = -ERANGE;
			goto error_blockput;
		}
		memcpy(name, entry->name, len);
	}
	blockput(buffer);

	return len;

error_blockput:
	blockput(buffer);
error:
	return err;
}
示例#3
0
void InputMap::loadDefaults()
{
    QString profileName;
    QSettings settings;
    QString plugin;
    QVariant value;
    QString input;
    QString key;

    /* Editor universe */
    key = QString("/inputmap/editoruniverse/");
    value = settings.value(key);
    if (value.isValid() == true)
        setEditorUniverse(value.toInt());

    for (quint32 i = 0; i < m_universes; i++)
    {
        /* Plugin name */
        key = QString("/inputmap/universe%2/plugin/").arg(i);
        plugin = settings.value(key).toString();

        /* Plugin input */
        key = QString("/inputmap/universe%2/input/").arg(i);
        input = settings.value(key).toString();

        /* Input profile */
        key = QString("/inputmap/universe%2/profile/").arg(i);
        profileName = settings.value(key).toString();

        /* Do the mapping */
        if (plugin.length() > 0 && input.length() > 0)
        {
            /* Check that the same plugin & input are not mapped
               to more than one universe at a time. */
            quint32 m = mapping(plugin, input.toInt());
            if (m == InputMap::invalidUniverse() || m == i)
            {
                setPatch(i, plugin, input.toInt(),
                         profileName);
            }
        }
    }
}
 void BVH4BuilderTopLevel::split_sequential(BuildRecord& current, BuildRecord& leftChild, BuildRecord& rightChild)
 {
   /* calculate binning function */
   Mapping2<16> mapping(current.bounds);
   
   /* binning of centroids */
   Binner2<16> binner;
   binner.bin(&refs[0],current.begin,current.end,mapping);
   
   /* find best split */
   Split2 split; 
   binner.best(split,mapping);
   
   /* if we cannot find a valid split, enforce an arbitrary split */
   if (unlikely(split.pos == -1)) split_fallback2(&refs[0],current,leftChild,rightChild);
   
   /* partitioning of items */
   else binner.partition(&refs[0], current.begin, current.end, split, mapping, leftChild, rightChild);
 }
示例#5
0
文件: distcorr5.c 项目: eterps/pwrake
double mapping_withlintrans(double x0, double y0, double *x1, double *y1,
			    double xcen, double ycen, 
			    double b11, double b12, double b21, double b22,
			    int n, double a[])
{
  double xr,yr;
  double det;

  xr=xcen+b11*(x0-xcen)+b12*(y0-ycen);
  yr=ycen+b21*(x0-xcen)+b22*(y0-ycen);

  det=b11*b22-b21*b12;
  
  /* caution !! */
  /* b matrix is celestial => telescope */
  /* ie. det<1 for airmass */

  return det*mapping(xr,yr,x1,y1,xcen,ycen,n,a);
}
TEST(MeshLib, CoordinatesMappingLocalLowerDimQuadXYZ)
{
    auto ele = TestQuad4::createXYZ();
    MeshLib::ElementCoordinatesMappingLocal mapping(*ele, MeshLib::CoordinateSystem(*ele));
    auto matR(mapping.getRotationMatrixToGlobal());
    //debugOutput(ele, mapping);

    // results when using GeoLib::ComputeRotationMatrixToXY()
    double exp_R[3*3] = {  1, 0, 0,
                           0, 0.70710678118654757, -0.70710678118654757,
                           0, 0.70710678118654757,  0.70710678118654757};

    const double eps(std::numeric_limits<double>::epsilon());
    ASSERT_ARRAY_NEAR(exp_R, matR.data(), matR.size(), eps);
    CHECK_COORDS(ele,mapping);

    for (std::size_t n = 0; n < ele->getNumberOfNodes(); ++n)
        delete ele->getNode(n);
}
boost::optional<mapped_region_ptr> mapped_memory_cache::find(std::string const& uri, bool update_cache)
{
#ifdef MAPNIK_THREADSAFE
    std::lock_guard<std::mutex> lock(mutex_);
#endif

    using iterator_type = std::unordered_map<std::string, mapped_region_ptr>::const_iterator;
    boost::optional<mapped_region_ptr> result;
    iterator_type itr = cache_.find(uri);
    if (itr != cache_.end())
    {
        result.reset(itr->second);
        return result;
    }

    if (mapnik::util::exists(uri))
    {
        try
        {
            boost::interprocess::file_mapping mapping(uri.c_str(),boost::interprocess::read_only);
            mapped_region_ptr region(std::make_shared<boost::interprocess::mapped_region>(mapping,boost::interprocess::read_only));
            result.reset(region);
            if (update_cache)
            {
                cache_.emplace(uri, *result);
            }
            return result;
        }
        catch (std::exception const& ex)
        {
            MAPNIK_LOG_ERROR(mapped_memory_cache)
                << "Error loading mapped memory file: '"
                << uri << "' (" << ex.what() << ")";
        }
    }
    /*
    else
    {
        MAPNIK_LOG_WARN(mapped_memory_cache) << "Memory region does not exist file: " << uri;
    }
    */
    return result;
}
// This function will get all the mappings which have the same commandlistId's (substates) into aMappingArray
void CSsmCommandListResourceReaderImpl::CResourcePool::UpdateMappingArrayL(TInt aCommandListId, RArray<TMapping>& aMappingArray) const
	{
	aMappingArray.Reset();
	TMapping mapping(aCommandListId, 0, NULL);
	const TInt mappingCount = iMappings.Count();
	TInt mappingIndex = iMappings.FindL(mapping);

	for(; mappingIndex < mappingCount; ++mappingIndex)
		{
		aMappingArray.AppendL(iMappings[mappingIndex]);
		if ((mappingIndex >= (mappingCount - 1)) || (iMappings[mappingIndex].iCommandListId !=
		iMappings[mappingIndex + 1].iCommandListId))
			{
			//Breaking as it reached end of array or completed appending the mappings for
			//the given commandlist id
			break;
			}
		}
	DEBUGPRINT3(_L("Mapping Array for substate %04x Contains %d entries"), iMappings[mappingIndex].iCommandListId, aMappingArray.Count());
	}
示例#9
0
Mapping* FGeoSession::mapping(const SiPrefix* o) {
    (void) o;
    String mn = "SiPrefix";
    
    if (hasMapping(mn)) {
        return mappingByName(mn);
    }

    Table* t = connection()->database()->table("core.si_prefixes");
    Mapping* m = createMapping(mn, t);

    m->createProperty("id", t->column("id"));
    m->createProperty("name", t->column("name"));
    m->createProperty("code", t->column("code"));
    m->createProperty("symbol", t->column("symbol"));
    m->createProperty("description", t->column("description"));
    m->createProperty("factor", t->column("factor"));
    
    return mapping(o);
}
示例#10
0
int main(int argc, char **argv) {
   MPI_Init(&argc, &argv);

#ifdef DEBUG
   printf("cache_node argc: %d\n", argc);
   for (int i = 0; i < argc; ++i) {
      printf("argv[%d]: %s\n", i, argv[i]);
   }
#endif

   std::string mapping(argv[1]);
   //replace_commas(mapping);
   std::vector<uint32_t> map_vec;
   stringlist_to_vector(map_vec, mapping);

   CacheNode cache_node(map_vec);

   MPI_Finalize();

   return 0;
}
示例#11
0
文件: dir.c 项目: Zkin/tux3
int tux_dir_is_empty(struct inode *dir)
{
	struct sb *sb = tux_sb(dir->i_sb);
	block_t block, blocks = dir->i_size >> sb->blockbits;
	__be64 self = cpu_to_be64(tux_inode(dir)->inum);
	struct buffer_head *buffer;

	for (block = 0; block < blocks; block++) {
		buffer = blockread(mapping(dir), block);
		if (!buffer)
			return -EIO;

		tux_dirent *entry = bufdata(buffer);
		tux_dirent *limit = bufdata(buffer) + sb->blocksize - TUX_REC_LEN(1);
		for (; entry <= limit; entry = next_entry(entry)) {
			if (!entry->rec_len) {
				blockput(buffer);
				tux_zero_len_error(dir, block);
				return -EIO;
			}
			if (is_deleted(entry))
				continue;
			if (entry->name[0] != '.')
				goto not_empty;
			if (entry->name_len > 2)
				goto not_empty;
			if (entry->name_len < 2) {
				if (entry->inum != self)
					goto not_empty;
			} else if (entry->name[1] != '.')
				goto not_empty;
		}
		blockput(buffer);
	}
	return 0;
not_empty:
	blockput(buffer);
	return -ENOTEMPTY;
}
void CSsmCommandListResourceReaderImpl::CInitialiser::ParseFileL(CResourceFile* aResourceFile)
	{
	// read root resource
	RResourceReader rootReader;
	const TInt KRootResourceId = 1;
	rootReader.OpenLC(aResourceFile, KRootResourceId);
	const TSsmResourceVersion version = static_cast<TSsmResourceVersion>(rootReader.ReadInt16L());
	if (version != ESsmInitialVersion)
		{
		SSMLOGLEAVE(KErrNotSupported);
		}
	const TInt reserved1 = rootReader.ReadInt16L(); // skip SSM_COMMAND_LIST_ROOT.reserved1
	const TInt commandListMappingResourceId = rootReader.ReadInt32L();
	if (commandListMappingResourceId <= 0)
		{
		DEBUGPRINT1(_L("Command list resource file contains no mappings"));
		SSMLOGLEAVE(KErrNotFound);
		}
	CleanupStack::PopAndDestroy(&rootReader);

	// read mapping resource
	RResourceReader mappingReader;
	mappingReader.OpenLC(aResourceFile, commandListMappingResourceId);
	const TInt mappingCount = mappingReader.ReadInt16L();
	if (!mappingCount)
		{
		DEBUGPRINT1(_L("Command list resource file contains no mappings"));
		SSMLOGLEAVE(KErrNotFound);
		}
	for (TInt i = 0; i < mappingCount; i++)
		{
		// add each mapping to the pool
		TUint commandListId = mappingReader.ReadUint32L();
		TInt resourceId = mappingReader.ReadInt32L();
		TMapping mapping(commandListId, resourceId, aResourceFile);
		iResourcePool.AppendL(mapping);
		}
	CleanupStack::PopAndDestroy(&mappingReader);
	}
示例#13
0
message message::extract_impl(size_t start, message_handler handler) const {
  auto s = size();
  for (size_t i = start; i < s; ++i) {
    for (size_t n = (s - i) ; n > 0; --n) {
      auto next_slice = slice(i, n);
      auto res = handler(next_slice);
      if (res) {
        std::vector<size_t> mapping(s);
        std::iota(mapping.begin(), mapping.end(), size_t{0});
        auto first = mapping.begin() + static_cast<ptrdiff_t>(i);
        auto last = first + static_cast<ptrdiff_t>(n);
        mapping.erase(first, last);
        if (mapping.empty()) {
          return message{};
        }
        message next{detail::decorated_tuple::make(vals_, std::move(mapping))};
        return next.extract_impl(i, handler);
      }
    }
  }
  return *this;
}
示例#14
0
bool OBJECT_WAREHOUSE_CLASS::addMappedValue(char *name_ptr, char *value_ptr, UINT16 group, UINT16 element, LOG_CLASS *logger_ptr, bool userDefined)

//  DESCRIPTION     : Method to add a Name / Value mapping to the mapping list.
//  PRECONDITIONS   :
//  POSTCONDITIONS  :
//  EXCEPTIONS      : 
//  NOTES           :
//<<===========================================================================
{
	if (logger_ptr)
	{
		logger_ptr->text(LOG_DEBUG, 1, "OBJECT_WAREHOUSE_CLASS::addMappedValue(name_ptr:= %s value_ptr:= %s)", name_ptr, value_ptr);
	}

	char *existingValue_ptr;

	// check if Value has already been defined
	if ((existingValue_ptr = getMappedValue(name_ptr, logger_ptr)) != NULL)
	{
		if (strcmp(existingValue_ptr, value_ptr) != 0)
		{
			// Name previously given to different Value
			// - modify the Name / Value mapping
			modifyMappedValue(name_ptr, value_ptr, group, element, logger_ptr);
		}
	}
	else
	{
		// instaniate a new Name / Value mapping
		WAREHOUSE_MAPPING_CLASS mapping(name_ptr, value_ptr, group, element, userDefined);

		// add Name / Value mapping
		mappingM.add(mapping);
	}

	// return result
	return true;
}
        virtual void operator()(utils::kernel_generation_stream & stream, std::size_t device_offset, statements_type const & statements) const {
          std::vector<detail::mapping_type> mapping(statements.size());

          ///Get Prototype, initialize mapping
          std::string prototype;
          std::set<std::string> already_generated;
          kernel_arguments(statements, prototype);

          {
            std::map<void *, std::size_t> memory;
            unsigned int current_arg = 0;
            std::size_t i = 0;
            for(statements_type::const_iterator it = statements.begin() ; it != statements.end() ; ++it)
              detail::traverse(it->first, it->second, detail::map_functor(memory,current_arg,mapping[i++]));
          }

          for(statements_type::const_iterator it = statements.begin() ; it != statements.end() ; ++it){
            detail::traverse(it->first, it->second, detail::prototype_generation_traversal(already_generated, prototype, vectorization(), mapping[std::distance(statements.begin(), it)]));
          }

          prototype.erase(prototype.size()-1); //Last comma pruned

          //Generate
          for(std::size_t n = 0 ; n < num_kernels() ; ++n){
            //stream << "__attribute__((vec_type_hint()))" << std::endl;
            stream << " __attribute__((reqd_work_group_size(" << local_size_1_ << "," << local_size_2_ << "," << 1 << ")))" << std::endl;
            stream << "__kernel " << "void " << "kernel_" << device_offset << "_" << n << "(" << std::endl;
            stream << prototype << std::endl;
            stream << ")" << std::endl;

            //core:
            stream << "{" << std::endl;
            stream.inc_tab();
            core(n, stream, statements, mapping);
            stream.dec_tab();
            stream << "}" << std::endl;
          }
        }
示例#16
0
END_TEST

START_TEST (sequence_iteration)
{
    reset_errno();
    Node *r = model_document_root(model, 0);
    assert_noerr();
    assert_not_null(r);
    assert_node_kind(r, MAPPING);
    
    reset_errno();
    Node *s = mapping_get(mapping(r), (uint8_t *)"one", 3ul);
    assert_noerr();
    assert_not_null(s);
    assert_node_kind(s, SEQUENCE);
    assert_node_size(s, 2);
    
    size_t count = 0;
    reset_errno();
    assert_true(sequence_iterate(sequence(s), check_sequence, &count));
    assert_noerr();
    assert_uint_eq(2, count);
}
  /**
   * Create a couple of simple way strings and verify that the generated subline match is correct.
   */
  void runTest()
  {
    OsmMapPtr map(new OsmMap());

    NodePtr n1a = TestUtils::createNode(map, Status::Unknown1, 0, 0);
    NodePtr n1b = TestUtils::createNode(map, Status::Unknown1, 100, 0);
    NodePtr n1c = TestUtils::createNode(map, Status::Unknown1, 200, 0);
    WayPtr w1 = TestUtils::createWay(map, QList<NodePtr>() << n1a << n1b);
    WayPtr w2 = TestUtils::createWay(map, QList<NodePtr>() << n1b << n1c);

    NodePtr n2a = TestUtils::createNode(map, Status::Unknown1, 0, 10);
    NodePtr n2b = TestUtils::createNode(map, Status::Unknown1, 150, 10);
    NodePtr n2c = TestUtils::createNode(map, Status::Unknown1, 210, 10);
    WayPtr w3 = TestUtils::createWay(map, QList<NodePtr>() << n2a << n2b);
    WayPtr w4 = TestUtils::createWay(map, QList<NodePtr>() << n2c << n2b);

    WayStringPtr wstr1(new WayString());
    wstr1->append(WaySubline(WayLocation(map, w1, 0), WayLocation::createAtEndOfWay(map, w1)));
    wstr1->append(WaySubline(WayLocation(map, w2, 0), WayLocation::createAtEndOfWay(map, w2)));
    WayStringPtr wstr2(new WayString());
    wstr2->append(WaySubline(WayLocation(map, w3, 0), WayLocation::createAtEndOfWay(map, w3)));
    wstr2->append(WaySubline(WayLocation::createAtEndOfWay(map, w4), WayLocation(map, w4, 0)));

    WayMatchStringMappingPtr mapping(new NaiveWayMatchStringMapping(wstr1, wstr2));
    WaySublineMatchStringPtr wsms = WayMatchStringMappingConverter().
      toWaySublineMatchString(mapping);

    //LOG_VAR(TestUtils::toQuotedString(hoot::toString(wsms)));
    HOOT_STR_EQUALS("matches:\n"
      "subline 1: start: way(-1) index: 0 fraction: 0 end: way(-1) index: 1 fraction: 0\n"
      "subline 2: start: way(-3) index: 0 fraction: 0 end: way(-3) index: 0 fraction: 0.7\n"
      "subline 1: start: way(-2) index: 0 fraction: 0 end: way(-2) index: 0 fraction: 0.428571428571429\n"
      "subline 2: start: way(-3) index: 0 fraction: 0.7 end: way(-3) index: 1 fraction: 0\n"
      "reversed, subline 1: start: way(-2) index: 0 fraction: 0.428571428571429 end: way(-2) index: 1 fraction: 0\n"
      "subline 2: start: way(-4) index: 0 fraction: 0 end: way(-4) index: 1 fraction: 0",
      wsms);
  }
示例#18
0
int main()
{
	Process::cd("/tmp");
	File file("testMemoryMapping.XXXXXX");
	file.createUnique();
	file.unlinkOnExit();
	print("(parent) file.path() = \"%%\"\n", file.path());
	
	file.open(File::Read|File::Write);
	file.truncate(mapLength);
	print("(parent) acquiring write lock... \n");
	FileLock lock(&file, FileLock::Write);
	lock.acquire();
	
	print("(parent) mapping file and writing message... \n");
	{
		MemoryMapping mapping(&file, 0, mapLength);
		String message = "Hello, clone!";
		mem::cpy(reinterpret_cast<char*>(mapping.start()), message->data(), message->size());
	}
	
	print("(parent) cloning myself... \n");
	Ref<CloneFactory, Owner> factory = new CloneFactory(file.path());
	Ref<Process, Owner> fork = factory->produce();
	
	//print("(parent) sleeping 2 seconds... \n");
	//Thread::sleep(2);
	
	print("(parent) releasing write lock... \n");
	lock.release();
	
	int ret = fork->wait();
	print("(parent) clone terminated, ret = %%\n", ret);
	
	return 0;
}
示例#19
0
//->
void init_builtin_syslog()
{
    boost::shared_ptr< logging::core > core = logging::core::get();

    // Create a new backend
    boost::shared_ptr< sinks::syslog_backend > backend(new sinks::syslog_backend(
        keywords::facility = sinks::syslog::local0,             /*< the logging facility >*/
        keywords::use_impl = sinks::syslog::udp_socket_based    /*< the built-in socket-based implementation should be used >*/
    ));

    // Setup the target address and port to send syslog messages to
    backend->set_target_address("192.164.1.10", 514);

    // Create and fill in another level translator for "MyLevel" attribute of type string
    sinks::syslog::custom_severity_mapping< std::string > mapping("MyLevel");
    mapping["debug"] = sinks::syslog::debug;
    mapping["normal"] = sinks::syslog::info;
    mapping["warning"] = sinks::syslog::warning;
    mapping["failure"] = sinks::syslog::critical;
    backend->set_severity_mapper(mapping);

    // Wrap it into the frontend and register in the core.
    core->add_sink(boost::make_shared< sink_t >(backend));
}
void init_logging()
{
    // Create an event log sink
    boost::shared_ptr< sink_t > sink(new sink_t());

    sink->set_formatter
    (
        expr::format("%1%: [%2%] - %3%")
            % expr::attr< unsigned int >("LineID")
            % expr::attr< boost::posix_time::ptime >("TimeStamp")
            % expr::smessage
    );

    // We'll have to map our custom levels to the event log event types
    sinks::event_log::custom_event_type_mapping< severity_level > mapping("Severity");
    mapping[normal] = sinks::event_log::info;
    mapping[warning] = sinks::event_log::warning;
    mapping[error] = sinks::event_log::error;

    sink->locked_backend()->set_event_type_mapper(mapping);

    // Add the sink to the core
    logging::core::get()->add_sink(sink);
}
/*!
    Creates a content manager object for the scheme identified by \a scheme.
*/
QMailContentManager *QMailContentManagerFactory::create(const QString &scheme)
{
    return mapping(scheme);
}
示例#22
0
var tau::operator()(const var&v){
    var out;
    out.real=mapping(v.real);
    for_each_copy(v.dual->begin(),v.dual->end(),inserter(*(out.dual),out.dual->begin()),mul_make_pair<std::pair<int,double> >, primitive(v.real));
    return out;
}
示例#23
0
	result_type operator->() const { return mapping(Iterator::operator->()); }
示例#24
0
cmph_t *fch_new(cmph_config_t *mph, double c)
{
	cmph_t *mphf = NULL;
	fch_data_t *fchf = NULL;
	cmph_uint32 iterations = 100;
	cmph_uint8 restart_mapping = 0;
	fch_buckets_t * buckets = NULL;
	cmph_uint32 * sorted_indexes = NULL;
	fch_config_data_t *fch = (fch_config_data_t *)mph->data;
	fch->m = mph->key_source->nkeys;
	//DEBUGP("m: %f\n", fch->m);
	if (c <= 2) c = 2.6; // validating restrictions over parameter c.
	fch->c = c;
	//DEBUGP("c: %f\n", fch->c);
	fch->h1 = NULL;
	fch->h2 = NULL;
	fch->g = NULL;
	do
	{	  
		if (mph->verbosity)
		{
			fprintf(stderr, "Entering mapping step for mph creation of %u keys\n", fch->m);
		}
		if (buckets) fch_buckets_destroy(buckets);
		buckets = mapping(mph);
		if (mph->verbosity)
		{
			fprintf(stderr, "Starting ordering step\n");
		}
		if (sorted_indexes) free (sorted_indexes);
		sorted_indexes = ordering(buckets);
		if (mph->verbosity)
		{
			fprintf(stderr, "Starting searching step.\n");
		}
		restart_mapping = searching(fch, buckets, sorted_indexes);
		iterations--;
		
        } while(restart_mapping && iterations > 0);
	if (buckets) fch_buckets_destroy(buckets);
	if (sorted_indexes) free (sorted_indexes);
	if (iterations == 0) return NULL;
	mphf = (cmph_t *)malloc(sizeof(cmph_t));
	mphf->algo = mph->algo;
	fchf = (fch_data_t *)malloc(sizeof(fch_data_t));
	fchf->g = fch->g;
	fch->g = NULL; //transfer memory ownership
	fchf->h1 = fch->h1;
	fch->h1 = NULL; //transfer memory ownership
	fchf->h2 = fch->h2;
	fch->h2 = NULL; //transfer memory ownership
	fchf->p2 = fch->p2;
	fchf->p1 = fch->p1;
	fchf->b = fch->b;
	fchf->c = fch->c;
	fchf->m = fch->m;
	mphf->data = fchf;
	mphf->size = fch->m;
	//DEBUGP("Successfully generated minimal perfect hash\n");
	if (mph->verbosity)
	{
		fprintf(stderr, "Successfully generated minimal perfect hash function\n");
	}
	return mphf;
}
示例#25
0
int main(int argc, char ** argv)
{
    fftw_complex *z;
    fftw_plan plan;
    gsl_rng *r;
    const  gsl_rng_type *T;
    struct parms parms;
    double *phi, avg, ran, std;
    double *philocal;
    int Nx, Ny, Nz, size, rank, xnn;
    int i, j, n1, n2, irank, i0, j0;
    char filename[64];
    FILE *file;
    void   initrng(void);
    double uniform(void);
    MPI_Status status;

    Nx = atoi(argv[1]);
    Ny = atoi(argv[2]);
    Nz = atoi(argv[3]);
    avg = atof(argv[4]);
    std = atof(argv[5]);
    parms.Nx = Nx;  parms.Ny = Ny;  parms.Nz = Nz;
    //  MPI
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size (MPI_COMM_WORLD, &size);
    if (rank == 0){
        //  RNG setup
        gsl_rng_env_setup();
        T = gsl_rng_default;
        r = gsl_rng_alloc (T);
        printf ("r is a '%s' generator\n", gsl_rng_name (r));
        for (i=0; i < 1000000; i++)
            ran = avg + gsl_ran_gaussian(r,std); 
        xnn = Nx*Ny*Nz;
        phi = (double *) calloc(Nx*Ny*Nz, sizeof(double));
        for (i = 0; i < Nx*Ny*Nz; i++){
            ran = avg + gsl_ran_gaussian(r,std);
            phi[i] = (ran);
        }
    }


    parms.Nx = Nx;  parms.Ny = Ny;    parms.Nz = Nz;
    parms.rank = rank-1; parms.size = size-1;        //Slave COMM
    parms = mapping(parms);
    philocal = (double *) calloc(parms.nx*parms.ny, sizeof(double));
    
    if (rank == 0){
        for (irank = 0; irank < parms.size; irank++){
            parms.rank = irank;
            parms = mapping(parms);
            for (i = 0; i < parms.nx; i++)
            for (j = 0; j < parms.ny; j++){
                i0 = parms.x0 + i;        // Global coords
                j0 = parms.y0 + j;
                n1 = i*parms.ny + j;        //Local index
                n2 = i0*parms.Ny + j0;        //Global index
                philocal[n1] = phi[n2];
            }
            n1 = parms.nx*parms.ny;
            MPI_Send(philocal, n1, MPI_DOUBLE, irank+1, 0, MPI_COMM_WORLD);
        }
    }
    else{
        n1 = parms.nx*parms.ny;        //Fill local height
        MPI_Recv(philocal, n1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &status);

        sprintf(filename, "%s.%02d", "phi.dat", parms.rank);
        file = fopen(filename, "w");
        fprintf(file, "%5d %5d %5d %5d %5d    0    0.0\n", parms.Nx, parms.Ny, parms.nx, parms.ny, parms.Nz);
        for (i = 0; i < parms.nx; i++)
        for (j = 0; j < parms.ny; j++){
            fprintf(file, " % .3e", philocal[i*parms.ny+j]);
            if ((i*parms.ny+j+1)%10 == 0) fprintf(file, "\n");
        }
    fclose(file);
    }
    MPI_Finalize();
    return 0;
}
int main(int argc, char** argv)
{
	int verbose = 0;
	int node = -1;
	int access = O_RDONLY; // or O_RDWR;
	int count = 1;
	bool long_format = false;
	bool benchmark = false;
	const char* short_format = " %8x";
	static struct option long_options[] = {
	   {"node",	required_argument, 0, 'n' },
	   {"read",		no_argument, 0, 'r' },
	   {"verbose",	no_argument, 0, 'v' },
	   {"write",	no_argument, 0, 'w' },
	   {0,          0,           0, 0 }
	};
	try
	{
		dyplo::HardwareContext ctrl;
		int option_index = 0;
		for (;;)
		{
			int c = getopt_long(argc, argv, "bc:dln:rvw",
							long_options, &option_index);
			if (c < 0)
				break;
			switch (c)
			{
			case 'b':
				benchmark = true;
				break;
			case 'c':
				count = strtol(optarg, NULL, 0);
				break;
			case 'd':
				short_format = " %8d";
				break;
			case 'l':
				long_format = true;
				break;
			case 'n':
				node = strtol(optarg, NULL, 0);
				break;
			case 'r':
				access = O_RDONLY;
				break;
			case 'v':
				++verbose;
				break;
			case 'w':
				access = O_RDWR;
				break;
			case '?':
				usage(argv[0]);
				return 1;
			}
		}
		
		dyplo::File file(node < 0 ? ctrl.openControl(access) : ctrl.openConfig(node, access));

		if (access == O_RDONLY)
		{
			for (int index = optind; index < argc; ++index)
			{
				unsigned int addr = strtol(argv[index], NULL, 0);
				off_t page_location = addr & ~(PAGE_SIZE-1);
				unsigned int page_offset = addr & (PAGE_SIZE-1);
				size_t size = addr + (count * sizeof(unsigned int)) - page_location;
				
				if (verbose) printf("Addr: %#x (%d) offset=%#x+%#x - %#zx (%zu)\n",
					addr, addr, (unsigned int)page_location, page_offset, size, size);
				
				dyplo::MemoryMap mapping(file, page_location, size, PROT_READ);
				volatile unsigned int* data = (unsigned int*)(((char*)mapping.memory) + page_offset);
				
				if (benchmark)
				{
					unsigned int loops = 0;
					Stopwatch timer;
					if (count > 1)
					{
						size_t blocksize = count * sizeof(unsigned int);
						unsigned int dest[count];
						timer.start();
						do
						{
							for (unsigned int repeat = 64*1024u; repeat != 0; --repeat)
							{
								memcpy(dest, (void*)data, blocksize);
							}
							++loops;
							timer.stop();
						} while (timer.elapsed_us() < 1000000);
					}
					else
					{
						count = 1;
						timer.start();
						do
						{
							unsigned int dest;
							for (unsigned int repeat = 64*1024u; repeat != 0; --repeat)
							{
								dest += *data; /* force memory access */
							}
							++loops;
							timer.stop();
						} while (timer.elapsed_us() < 1000000);
					}
					unsigned int elapsed_us = timer.elapsed_us();
					unsigned int bytes = loops * count * (64u * 1024u * sizeof(unsigned int));
					printf("loops=%u us=%u bytes=%u hence %u MB/s\n",
						loops, elapsed_us, bytes, bytes / elapsed_us);
				}
				else
				{
					if (long_format)
					{
						for (int i = 0; i < count; ++i)
						{
							unsigned int value = data[i];
							printf("@0x%04x: %#10x (%d)\n",	(unsigned int)(addr+(i*sizeof(unsigned int))), value, (int)value);
						}
					}
					else
					{
						int j = 0;
						int lines = (count+3)/4;
						for (int line = 0; line < lines; ++line)
						{
							printf("@0x%04x: ", (unsigned int)(addr + (j*sizeof(unsigned int))));
							for (int i = j; i < count && i < j+4; ++i)
							{
								unsigned int value = data[i];
								printf(short_format, value);
							}
							printf("\n");
							j += 4;
						}
					}
				}
			}
		}
		else
		{
			if (argc - optind < 2)
				throw std::runtime_error("Too few arguments for write mode, need address and value(s)");
			unsigned int addr = strtol(argv[optind], NULL, 0);
			++optind;
			unsigned int values = argc - optind;
			off_t page_location = addr & ~(PAGE_SIZE-1);
			unsigned int page_offset = addr & (PAGE_SIZE-1);
			size_t size = addr + (values * sizeof(unsigned int)) - page_location;
				if (verbose) printf("Addr: %#x (%d) offset=%#x+%#x - %#zx (%zu)\n", addr, addr, (unsigned int)page_location, page_offset, size, size);
			dyplo::MemoryMap mapping(file, page_location, size, PROT_READ|PROT_WRITE);
			volatile unsigned int* data = (unsigned int*)(((char*)mapping.memory) + page_offset);
			unsigned int value[values];
			const size_t blocksize = values * sizeof(unsigned int);
			for (int index = 0; index < values; ++index)
				value[index] = strtoul(argv[optind+index], NULL, 0);
			if (verbose)
			{
				printf("transfer size: %d words, %zd bytes\n", values, blocksize);
				for (int index = 0; index < values; ++index)
					printf("%x (%d)\n", value[index], (int)value[index]);
			}
			if (benchmark)
			{
				unsigned int loops = 0;
				Stopwatch timer;
				timer.start();
				do
				{
					for (unsigned int repeat = 64*1024u; repeat != 0; --repeat)
					{
						memcpy((void*)data, value, blocksize);
					}
					++loops;
					timer.stop();
				} while (timer.elapsed_us() < 1000000);
				unsigned int elapsed_us = timer.elapsed_us();
				unsigned int bytes = loops * blocksize * (64u * 1024u);
				printf("loops=%u us=%u bytes=%u hence %u MB/s\n",
					loops, elapsed_us, bytes, bytes / elapsed_us);
			}
			else
			{
				memcpy((void*)data, value, blocksize);
			}
		}
	}
	catch (const std::exception& ex)
	{
		std::cerr << "ERROR:\n" << ex.what() << std::endl;
		return 1;
	}
	return 0;
}
示例#27
0
void parseFile(FILE *f, Normalizer2DataBuilder &builder) {
    IcuToolErrorCode errorCode("gennorm2/parseFile()");
    char line[300];
    uint32_t startCP, endCP;
    while(NULL!=fgets(line, (int)sizeof(line), f)) {
        char *comment=(char *)strchr(line, '#');
        if(comment!=NULL) {
            *comment=0;
        }
        u_rtrim(line);
        if(line[0]==0) {
            continue;  // skip empty and comment-only lines
        }
        if(line[0]=='*') {
            const char *s=u_skipWhitespace(line+1);
            if(0==strncmp(s, "Unicode", 7)) {
                s=u_skipWhitespace(s+7);
                builder.setUnicodeVersion(s);
            }
            continue;  // reserved syntax
        }
        const char *delimiter;
        int32_t rangeLength=
            u_parseCodePointRangeAnyTerminator(line, &startCP, &endCP, &delimiter, errorCode);
        if(errorCode.isFailure()) {
            fprintf(stderr, "gennorm2 error: parsing code point range from %s\n", line);
            exit(errorCode.reset());
        }
        delimiter=u_skipWhitespace(delimiter);
        if(*delimiter==':') {
            const char *s=u_skipWhitespace(delimiter+1);
            char *end;
            unsigned long value=strtoul(s, &end, 10);
            if(end<=s || *u_skipWhitespace(end)!=0 || value>=0xff) {
                fprintf(stderr, "gennorm2 error: parsing ccc from %s\n", line);
                exit(U_PARSE_ERROR);
            }
            for(UChar32 c=(UChar32)startCP; c<=(UChar32)endCP; ++c) {
                builder.setCC(c, (uint8_t)value);
            }
            continue;
        }
        if(*delimiter=='-') {
            if(*u_skipWhitespace(delimiter+1)!=0) {
                fprintf(stderr, "gennorm2 error: parsing remove-mapping %s\n", line);
                exit(U_PARSE_ERROR);
            }
            for(UChar32 c=(UChar32)startCP; c<=(UChar32)endCP; ++c) {
                builder.removeMapping(c);
            }
            continue;
        }
        if(*delimiter=='=' || *delimiter=='>') {
            UChar uchars[Normalizer2Impl::MAPPING_LENGTH_MASK];
            int32_t length=u_parseString(delimiter+1, uchars, LENGTHOF(uchars), NULL, errorCode);
            if(errorCode.isFailure()) {
                fprintf(stderr, "gennorm2 error: parsing mapping string from %s\n", line);
                exit(errorCode.reset());
            }
            UnicodeString mapping(FALSE, uchars, length);
            if(*delimiter=='=') {
                if(rangeLength!=1) {
                    fprintf(stderr,
                            "gennorm2 error: round-trip mapping for more than 1 code point on %s\n",
                            line);
                    exit(U_PARSE_ERROR);
                }
                builder.setRoundTripMapping((UChar32)startCP, mapping);
            } else {
                for(UChar32 c=(UChar32)startCP; c<=(UChar32)endCP; ++c) {
                    builder.setOneWayMapping(c, mapping);
                }
            }
            continue;
        }
        fprintf(stderr, "gennorm2 error: unrecognized data line %s\n", line);
        exit(U_PARSE_ERROR);
    }
}
示例#28
0
int main (int argc, char **argv)
{
  //   double *A_local;
   int A_descrip[DESC_SIZE];
   //   double *B_local;
   int B_descrip[DESC_SIZE];
   //   double *C_local;
   int C_descrip[DESC_SIZE];

   int nproc_rows;
   int nproc_cols;
   int m, n, k;
   int blacs_grid;

   int myproc, nprocs;
   char myname[MPI_MAX_PROCESSOR_NAME];
   double *a, *b, *c;

   /* Get input parameters */
   m = GLOBAL_M;
   n = GLOBAL_N;
   k = GLOBAL_K; // 32  

   MPI_Init(&argc, &argv);
   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
   MPI_Comm_rank(MPI_COMM_WORLD, &myproc);

   /* Ensure we have at least two processors */
   if (nprocs < 2) 
   {
       printf("Too few processors!\n");
       exit (1);
   }

   if(gethostname (myname, MPI_MAX_PROCESSOR_NAME) != 0 )
      printf("Error: gethostname failed!\n");
   else if(HELLO)
      printf("Hello from %2d of %2d on %s\n", myproc, nprocs, myname);

   /* Set to HIGH frequency */
   mapping(myproc%7, DVFS_HIGH);

   Cblacs_get(0, 0, &blacs_grid);

   int ldumap=PROC_NODE;
   nproc_rows=PROC_NODE;
   nproc_cols=PROC_NODE;
   /* ROW MAJOR TILING */
   if(MAJOR==1)
   {
      int usermap[64]=  {0,  1,  8,  9,  16, 17, 24, 25,
                         2,  3,  10, 11, 18, 19, 26, 27,
                         4,  5,  12, 13, 20, 21, 28, 29,
                         6,  7,  14, 15, 22, 23, 30, 31,
                         32, 33, 40, 41, 48, 49, 56, 57,
                         34, 35, 42, 43, 50, 51, 58, 59,
                         36, 37, 44, 45, 52, 53, 60, 61,
                         38, 39, 46, 47, 54, 55, 62, 63};

      Cblacs_gridmap(&blacs_grid, usermap, ldumap, nproc_rows, nproc_cols);
   }
   else if (MAJOR==2)	
    /* COLUMN MAJOR TILING*/
   {
      int usermap[64]={0,  1,  2,  3,  8,  9,  10, 11,
                       4,  5,  6,  7,  12, 13, 14, 15,
                       16, 17, 18, 19, 24, 25, 26, 27,
                       20, 21, 22, 23, 28, 29, 30, 31,
                       32, 33, 34, 35, 40, 41, 42, 43,
                       36, 37, 38, 39, 44, 45, 46, 47,
                       48, 49, 50, 51, 56, 57, 58, 59,
                       52, 53, 54, 55, 60, 61, 62, 63};
    

      Cblacs_gridmap(&blacs_grid, usermap, ldumap, nproc_rows, nproc_cols);
   }
   else if(MAJOR==0)
      Cblacs_gridinit(&blacs_grid, "R", nproc_rows, nproc_cols);
   //   Cblacs_pcoord(blacs_grid, myproc, &my_process_row, &my_process_col);

   int local_m = m/nproc_rows;
   int local_n = n/nproc_cols;
   int local_k = k/nproc_cols;

   if(myproc==SHOW1)
     printf("local m n k = %d %d %d\n",local_m, local_n, local_k);

   a = (double *) malloc (local_m*local_k * sizeof(double));
   b = (double *) malloc (local_k*local_n * sizeof(double));
   c = (double *) malloc (local_m*local_n * sizeof(double));

   //   A_local = (double *) malloc (local_m*local_k * sizeof(double));
   //   B_local = (double *) malloc (local_k*local_n * sizeof(double));
   //   C_local = (double *) malloc (local_m*local_n * sizeof(double));

   if(!a||!b||!c)//||!A_local||!B_local||!C_local)
   {
     printf("out of memory!\n");
     exit(-1);
   }

   Build_descrip(myproc, "A", A_descrip, m, k, local_m, local_k, blacs_grid, local_m);//MAX(local_m, local_k));
   Build_descrip(myproc, "B", B_descrip, k, n, local_k, local_n, blacs_grid, local_k);//MAX(local_k, local_n));
   Build_descrip(myproc, "C", C_descrip, m, n, local_m, local_n, blacs_grid, local_m);//MAX(local_m, local_n));

   if(myproc==SHOW1)
   {
     printf("\nA_descrip = [ %d, %d, %d, %d, %d, %d, %d, %d, %d]\n", 
     A_descrip[0], A_descrip[1], A_descrip[2], A_descrip[3], A_descrip[4], A_descrip[5], A_descrip[6], A_descrip[7], A_descrip[8]);
     printf("\nB_descrip = [ %d, %d, %d, %d, %d, %d, %d, %d, %d]\n", 
     B_descrip[0], B_descrip[1], B_descrip[2], B_descrip[3], B_descrip[4], B_descrip[5], B_descrip[6], B_descrip[7], B_descrip[8]);
     printf("\nC_descrip = [ %d, %d, %d, %d, %d, %d, %d, %d, %d]\n\n", 
     C_descrip[0], C_descrip[1], C_descrip[2], C_descrip[3], C_descrip[4], C_descrip[5], C_descrip[6], C_descrip[7], C_descrip[8]);
   }

       
   int ij = 1;
   char tran = 'N';
   double alpha = 1.0, beta = 1.0;
   double exetime=0;

   MPI_Barrier(MPI_COMM_WORLD);
  
   if(MEASURE && myproc==0)
   {
      system("/apps/power-bench/mclient -H 10.1.255.100 -d /tmp");
      system("/apps/power-bench/mclient -H 10.1.255.100 -l pdgemm.ptr");
      system("/apps/power-bench/mclient -H 10.1.255.100 -s pdgemm");
   }

    
   //   Zeros(A_local, local_m, local_k); 
   //   Zeros(B_local, local_k, local_n); 
   //   Zeros(C_local, local_m, local_n); 
   //   if(myproc%8==0)
   //   RndMatrix(A_local, local_m, local_k, myproc);
      //  if(myproc<8) 
   //   RndMatrix(B_local, local_k, local_n, myproc); 

   MPI_Barrier(MPI_COMM_WORLD);
   //   exetime0 = -MPI_Wtime();
   // ScaLAPACK pdgemm 

   if(!myproc)
     printf("\nM = %d, N = %d, K = %d\n", m, n, k); 
   /*
   pdgemm_(&tran, &tran, &m, &n, &k,
           &alpha, A_local, &ij, &ij, A_descrip,
                   B_local, &ij, &ij, B_descrip,
           &beta,  C_local, &ij, &ij, C_descrip);

  
   MPI_Barrier(MPI_COMM_WORLD);
   exetime0 += MPI_Wtime();
   
   CpyMatrix(A_local, a, local_m, local_k);
   CpyMatrix(B_local, b, local_k, local_n);
   Zeros(c, local_m, local_n); 
   */

   //   if(myproc%8==0)
      RndMatrix(a, local_m, local_k, myproc);
      //  if(myproc<8) 
      RndMatrix(b, local_k, local_n, myproc); 
      Zeros(c, local_m, local_n); 

   MPI_Barrier(MPI_COMM_WORLD);
   exetime = -MPI_Wtime();
   // My pdgemm 
   pdgemm(&tran, &tran, &m, &n, &k, &alpha, a, &ij, &ij, A_descrip, b, &ij, &ij, B_descrip, &beta, c, &ij, &ij, C_descrip);    
   //printf("MYPDGEMM finish\n");
   MPI_Barrier(MPI_COMM_WORLD);
   exetime += MPI_Wtime();
   

   if(MEASURE && myproc==0)
   {
      system("/apps/power-bench/mclient -H 10.1.255.100 -e session");
      system("/apps/power-bench/mclient -H 10.1.255.100 -e log");
   }

   mapping(myproc%7, DVFS_LOW);
   mapping(0, DVFS_HIGH);
   

   if(myproc == SHOW1)
   {
       sleep(1);
       //printf("Total execution time of my_pdgemm is %.3f.\n", exetime);
       printf("Total execution time of pdgemm is %.3f.\n", exetime);

       int i, j;
       /*
       printf("My PDGEMM ID AAA = %d :\n",myproc);   
       for(i=0;i<DISP_SIZE;i++)
       {
         for(j=0;j<DISP_SIZE;j++)
         	 printf("%8.5lf   ", a[i*DISP_SIZE+j]);
           printf("\n");
        }
      
       printf("My PDGEMM ID BBB = %d :\n",myproc);   
       for(i=0;i<DISP_SIZE;i++)
       {
         for(j=0;j<DISP_SIZE;j++)
         	 printf("%8.5lf   ", b[i*DISP_SIZE+j]);
           printf("\n");
        }
       */
       /*
       printf("My PDGEMM ID CCC = %d :\n",myproc);   
       for(i=0;i<DISP_SIZE;i++)
       {
         for(j=0;j<DISP_SIZE;j++)
         	 printf("%10.5lf\t", c[i*DISP_SIZE+j]);
           printf("\n");
        }
       */
       /*      
   }
   if(myproc == SHOW2)
   {
     sleep(3);
       printf("Total execution time of my_pdgemm is %.3f.\n", exetime);
       printf("Total execution time of pdgemm is %.3f.\n", exetime0);

       int i, j;
            
       printf("PDGEMM ID AAA = %d :\n",myproc);   
       for(i=0;i<DISP_SIZE;i++)
       {
         for(j=0;j<DISP_SIZE;j++)
         	 printf("%8.5lf   ", A_local[i*DISP_SIZE+j]);
           printf("\n");
        }
       
      
       printf("PDGEMM ID BBB = %d :\n",myproc);   
       for(i=0;i<DISP_SIZE;i++)
       {
         for(j=0;j<DISP_SIZE;j++)
         	 printf("%8.5lf   ", B_local[i*DISP_SIZE+j]);
           printf("\n");
        }
       */
       printf("PDGEMM ID CCC = %d :\n",myproc);   
       for(i=0;i<DISP_SIZE;i++)
       {
         for(j=0;j<DISP_SIZE;j++)
         	 printf("%10.5lf\t", c[i*DISP_SIZE+j]);
           printf("\n");
        }
   }

   //   double diffa, diffb, diffc, diff_total=0.0;

   //diffa=diff_norm(A_local, a, local_m, local_k);
   //diffb=diff_norm(B_local, b, local_k, local_n);
   //diffc=diff_norm(C_local, c, local_m, local_n);
   //MPI_Reduce(&diffa, &diff_total, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
   //   sleep(1);
   /*
   if(!myproc)
      printf("The total normal difference between my pdgemm A and ScaLAPACK pdgemm A is %e.\n", diff_total);
   MPI_Reduce(&diffb, &diff_total, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
   sleep(1);
   if(!myproc)
      printf("The total normal difference between my pdgemm B and ScaLAPACK pdgemm B is %e.\n", diff_total);
   MPI_Reduce(&diffc, &diff_total, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
   sleep(1);
   if(!myproc)
      printf("The total normal difference between my pdgemm C and ScaLAPACK pdgemm C is %e.\n", diff_total);
   */

   free(a); free(b); free(c);
   //free(A_local);free(B_local);free(C_local);
   Cblacs_exit(1);
   /* Clean-up and close down */ 
   MPI_Barrier(MPI_COMM_WORLD);
   //MPI_Comm_free(&my_row_comm); 
   //MPI_Comm_free(&my_column_comm);  
   MPI_Finalize();
   return 0;
}
示例#29
0
void pdgemm(char *TRANSA, char *TRANSB,
            int *M, int *N, int *K,
            double *ALPHA,
            double *a, int *IA, int *JA, int *DESCA,
            double *b, int *IB, int *JB, int *DESCB,
            double *BETA,
            double *c, int *IC, int *JC, int *DESCC)
{
  //   int my_row, my_column;
   int bk = BLOCK_SIZE;
   int n;
   int i, j, k, round;
   int r_rank, c_rank, g_rank, g_size;
   double *tempA, *tempB;
   double *tmpA, *tmpB;
   double t_bc, t_calc, t_tot, t_bar;
   double tt_bc, tt_calc, tt_tot, tt_bar;
   double sum, g_sum;
   int num_bk, loops, roots;
   int pk, last=0;
   int nprow, npcol, myrow, mycol;
   int *position, *coordinate;
   MPI_Comm my_row_comm, my_column_comm;

   /* Get the rank of the global communicator */
   MPI_Comm_rank(MPI_COMM_WORLD, &g_rank);
   MPI_Comm_size(MPI_COMM_WORLD, &g_size);

   Cblacs_gridinfo( (ctxt = DESCC[DCTXT]), &nprow, &npcol, &myrow, &mycol);

   //   printf("nprow = %d, npcol = %d, myrow = %d, mycol = %d\n", nprow, npcol, myrow, mycol);

   pk = PIPE_SIZE;
   if(nprow == npcol)
      n = DESCA[DN]/nprow; // local size
   else 
   { 
     printf("The grid of process should be square.\n");
     exit(-1);
   }

   coordinate = (int *)malloc(2*sizeof(int));
   position = (int *)malloc(g_size*sizeof(int));
   

   //MPI_Allgather(pos, 1, MPI_INT, position, g_size, MPI_INT, MPI_COMM_WORLD);
   for(i=0; i<g_size; i++)
     position[i]=i;   
   MPI_Barrier(MPI_COMM_WORLD);
   //  CreatTiling(position);
   //CreateReduceCommunicator(position, coordinate, &my_row_comm, &my_column_comm);
   //my_row = coordinate[0];
   //my_column = coordinate[1];

   /* Create my row and column communicators */   
   MPI_Comm_split(MPI_COMM_WORLD, mycol, myrow, &my_column_comm);
   MPI_Comm_split(MPI_COMM_WORLD, myrow, mycol, &my_row_comm);

   /* Get the rank of the local row communicator */
   //MPI_Comm_rank(ctxtr->scp->comm, &r_rank);
   MPI_Comm_rank(my_row_comm, &r_rank);
   /* Get the rank of the local column communicator */
   MPI_Comm_rank(my_column_comm, &c_rank);
   //MPI_Comm_rank(ctxtc->scp->comm, &c_rank);
   if(r_rank == 0 )
     printf("my c_rank = %d\n", c_rank);


   tempA = (double *) malloc (n*bk * sizeof(double));
   tempB = (double *) malloc (bk*n * sizeof(double));

   //const enum CBLAS_ORDER Order=CblasRowMajor;
   //const enum CBLAS_TRANSPOSE TA=CblasNoTrans;
   //const enum CBLAS_TRANSPOSE TB=CblasNoTrans;

   sum = g_sum = 0.0;
   tt_bc = tt_calc = tt_tot = t_bar = 0.0;
   tt_tot = tt_bc = tt_calc = tt_bar = 0.0;
   num_bk =(n/bk);
   last = n%bk;

   tmpA = (double *) malloc (n*last * sizeof(double));
   tmpB = (double *) malloc (last*n * sizeof(double));

   if(last==0)
      loops = rows*num_bk;
   else 
   {
      num_bk++;
      loops = rows*num_bk;
   }
   

   if(TIMER)
      t_tot = MPI_Wtime();

      for(round=0; round<loops; round++)
      {
        k = (round%num_bk)*bk;
        roots = round/num_bk;


	if(*TRANSA == 'N')
	{
         if(r_rank == roots)
         {
           if(last!=0 && (round+1)%num_bk==0) // the last block of this process
	   {
              for(i=0; i<last; i++)
   	        for(j=0; j<n; j++)
		{
		  tmpA[i*n+j] = a[(k+i)*n+j];
		}
	   }
           else 
	   {
              for(i=0; i<bk; i++)
	        for(j=0; j<n; j++)
		{
		  tempA[i*n+j] = a[(k+i)*n+j];
		}
           }
	 }

         if(c_rank == roots)
         {
           if(last!=0 && (round+1)%num_bk==0) // the last block of this process
	   {
              for(i=0; i<n; i++)
	        for(j=0; j<last; j++)
		{
		  tmpB[i*last+j] = b[i*n+(k+j)];
		}
	   }
           else
	   {
              for(i=0; i<n; i++)
	        for(j=0; j<bk; j++)
		{
		  tempB[i*bk+j] = b[i*n+(k+j)];
		}
	   }
         }
	}
        else if( *TRANSA == 'T')
	{
         if(r_rank == roots)
         {
           if(last!=0 && (round+1)%num_bk==0) // the last block of this process
	   {
              for(i=0; i<n; i++)
   	        for(j=0; j<last; j++)
		{
		   tmpA[i*last+j] = a[i*n+(k+j)];
       		}
	   }
	   else
	   {
              for(i=0; i<n; i++)
	        for(j=0; j<bk; j++)
		{
		   tempA[i*bk+j] = a[i*n+(k+j)];
       		}
	   }
         }
         if(c_rank == roots)
         {
           if(last!=0 && (round+1)%num_bk==0) // the last block of this process
	   {       
              for(i=0; i<last; i++)
	        for(j=0; j<n; j++)
		{
		  tmpB[i*n+j] = b[(k+i)*n+j];
       		}
	   }
	   else
	   {
             for(i=0; i<bk; i++)
	        for(j=0; j<n; j++)
		{
		  tempB[i*n+j] = b[(k+i)*n+j];
       		}
	   }
         }
	}
   
         if(TIMER)
            t_bc = MPI_Wtime();

         /* Broadcast to right */
         if(PIPE)
	 {
           if(last!=0 && (round+1)%num_bk==0) // the last block of this process
              MY_Bcast(tmpA, n*last,  MPI_DOUBLE, roots, my_row_comm, r_rank, columns, pk);
	   else
              MY_Bcast(tempA, n*bk,  MPI_DOUBLE, roots, my_row_comm, r_rank, columns, pk);
	 }
         else
         {
           if(last!=0 && (round+1)%num_bk==0) // the last block of this process
              MPI_Bcast(tmpA, last*n, MPI_DOUBLE, roots, my_row_comm);
	   else
              MPI_Bcast(tempA, bk*n, MPI_DOUBLE, roots, my_row_comm);
	 }
	 
         /* Broadcast below */
         
         if(PIPE)
	 {
           if(last!=0 && (round+1)%num_bk==0) // the last block of this process
	      MY_Bcast(tmpB, last*n, MPI_DOUBLE, roots, my_column_comm, c_rank, rows, pk);
	   else
              MY_Bcast(tempB, bk*n, MPI_DOUBLE, roots, my_column_comm, c_rank, rows, pk);
	 }
         else
	 {
            if(last!=0 && (round+1)%num_bk==0) // the last block of this process
               MPI_Bcast(tmpB, n*last, MPI_DOUBLE, roots, my_column_comm);
	    else
               MPI_Bcast(tempB, n*bk, MPI_DOUBLE, roots, my_column_comm);
         }
	 
         if(TIMER)
         {
            t_bc = MPI_Wtime() - t_bc;
            tt_bc += t_bc;
            t_calc = MPI_Wtime();
         }

         if(DVFS_ENABLE) 
            mapping(g_rank%8, DVFS_HIGH);



         /* Do the multiplication */
         if(*TRANSA == 'N') 
         {
           if(last!=0 && (round+1)%num_bk==0) // the last block of this process
              dgemm_(TRANSA, TRANSB, &n, &n, &last, ALPHA, tmpA, &n, tmpB, &last, BETA, c, &n);
	   else
              dgemm_(TRANSA, TRANSB, &n, &n, &bk, ALPHA, tempA, &n, tempB, &bk, BETA, c, &n);
	 }
         else if(*TRANSA == 'T') 
         {
           if(last!=0 && (round+1)%num_bk==0) // the last block of this process              
              dgemm_(TRANSA, TRANSB, &n, &n, &last, ALPHA, tmpA, &last, tmpB, &n, BETA, c, &n);
	   else
              dgemm_(TRANSA, TRANSB, &n, &n, &bk, ALPHA, tempA, &bk, tempB, &n, BETA, c, &n);
	 }

	 //	          dgemm_(TRANSA, TRANSB, &n, &n, &bk, ALPHA, tempA, &n, tempB, &bk, BETA, c, &n);
	 //	 cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, n, n, bk, alpha, tempA, bk, tempB, n, beta, c, n);

         /* check the calculate results*/
     
         if(DVFS_ENABLE) 
            mapping(g_rank%8, DVFS_LOW);

         if(TIMER)
         { 
            t_calc = MPI_Wtime() - t_calc;
            tt_calc += t_calc;
         }
      }
         
   if(TIMER)
   {
      t_tot = MPI_Wtime() - t_tot;
      tt_tot += t_tot;
   
      MPI_Reduce(&tt_tot, &t_tot, 1, MPI_DOUBLE, MPI_MAX,  0, MPI_COMM_WORLD);
      MPI_Reduce(&tt_bc, &t_bc, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
      MPI_Reduce(&tt_calc, &t_calc, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);

   
            if(g_rank == 0)
         printf("tot = %10.6f, bc = %10.6f, calc = %10.6f\n", t_tot, t_bc, t_calc);
   }

   MPI_Barrier(MPI_COMM_WORLD);

   free(tmpA);free(tmpB);
   //   free(a); free(b); free(c);
   free(tempA); free(tempB);
}
示例#30
0
void pdgemm(char *TRANSA, char *TRANSB,
            int *M, int *N, int *K,
            double *ALPHA,
            double *a, int *IA, int *JA, int *DESCA,
            double *b, int *IB, int *JB, int *DESCB,
            double *BETA,
            double *c, int *IC, int *JC, int *DESCC)
{
   int m, n, k;
   int i, j, round;
   int r_rank, c_rank, g_rank, g_size;
   double *tempA, *tempB;
   double t_bc, t_calc, t_tot, t_bar;
   double tt_bc, tt_calc, tt_tot, tt_bar;
   double sum, g_sum;
   int roots;
   int pk;
   int nprow, npcol, myrow, mycol;
   MPI_Comm my_row_comm, my_column_comm;

   /* Get the rank of the global communicator */
   MPI_Comm_rank(MPI_COMM_WORLD, &g_rank);
   MPI_Comm_size(MPI_COMM_WORLD, &g_size);

   Cblacs_gridinfo( (ctxt = DESCC[DCTXT]), &nprow, &npcol, &myrow, &mycol);

   rows = nprow;
   columns = npcol;

   pk = PIPE_SIZE;

      m = DESCA[DM]/nprow;
      n = DESCB[DN]/nprow;
      k = DESCA[DN]/npcol; // local m n k size

      //      printf("nprow = %d, npcol = %d\n\n",nprow, npcol);

   MPI_Barrier(MPI_COMM_WORLD);
   //         printf("---step 1:myrow = %d, mycol = %d\n\n",myrow, mycol);
   
   /* Create my row and column communicators */   
   MPI_Comm_split(MPI_COMM_WORLD, mycol, myrow, &my_column_comm);
   MPI_Comm_split(MPI_COMM_WORLD, myrow, mycol, &my_row_comm);

   /* Get the rank of the local row communicator */
   MPI_Comm_rank(my_row_comm, &r_rank);
   /* Get the rank of the local column communicator */
   MPI_Comm_rank(my_column_comm, &c_rank);
   
   tempA = (double *) malloc (m*k * sizeof(double));
   tempB = (double *) malloc (k*n * sizeof(double));

   //const enum CBLAS_ORDER Order=CblasRowMajor;
   //const enum CBLAS_TRANSPOSE TA=CblasNoTrans;
   //const enum CBLAS_TRANSPOSE TB=CblasNoTrans;

   sum = g_sum = 0.0;
   tt_bc = tt_calc = tt_tot = t_bar = 0.0;
   tt_tot = tt_bc = tt_calc = tt_bar = 0.0;

   if(TIMER)
      t_tot = MPI_Wtime();

   /* FT part, sum of A columnwise and B rowwise */
   // A part //
   if(mycol < 7)
   {
     if(myrow < 7)
     {
       for(i=0; i<m; i++)
	 for(j=0; j<k; j++)
	   {
	     tempA[i*k+j] = a[i*k+j];
	   }
     }
     //     if(mycol == 6)
     //  printf("a = %f\n", a[0]);
     MPI_Reduce(tempA, a, m*k, MPI_DOUBLE, MPI_SUM, 7, my_column_comm);
     //if(mycol == 6 && myrow == 7)
     //  printf("A = %f\n", a[0]);
   }

   if(myrow < 7)
   {
     if(mycol < 7)
       {
	 for(i=0; i<k; i++)
	   for(j=0; j<n; j++)
	     {
	       tempB[i*n+j] = b[i*n+j];
	     }
       }
     MPI_Reduce(tempB, b, k*n, MPI_DOUBLE, MPI_SUM, 7, my_row_comm);
   }
				

   //   printf("rows = %d, columns = %d\n",rows, columns);
   //   printf("---step 3:myrow = %d, mycol = %d\n\n",myrow, mycol);         
     for(round=0; round<nprow; round++)
      {
     
	//	if(myrow == mycol)
	//	printf("round = %d\n", round);
	//      if(myrow == 5 || mycol == 5)
           

	roots = round;

         if(r_rank == roots)
         {
              for(i=0; i<m; i++)
	        for(j=0; j<k; j++)
		{
		  tempA[i*k+j] = a[i*k+j];
		}
	 }

         if(c_rank == roots)
         {
              for(i=0; i<k; i++)
	        for(j=0; j<n; j++)
		{
		  tempB[i*n+j] = b[i*n+j];
		}
         }


         if(TIMER)
            t_bc = MPI_Wtime();

         /* Broadcast to right */
         if(PIPE)
	 {
              MY_Bcast(tempA, m*k,  MPI_DOUBLE, roots, my_row_comm, r_rank, columns, pk);
	 }
         else
         {
              MPI_Bcast(tempA, k*m, MPI_DOUBLE, roots, my_row_comm);
	 }

	 //   if(c_rank == 5)
	 //    printf("round = %d, :myrow = %d, mycol = %d\n\n", round, myrow, mycol);         
	 
         /* Broadcast below */
         
         if(PIPE)
	 {
              MY_Bcast(tempB, k*n, MPI_DOUBLE, roots, my_column_comm, c_rank, rows, pk);
	 }
         else
	 {
               MPI_Bcast(tempB, n*k, MPI_DOUBLE, roots, my_column_comm);
         }
	 
         if(TIMER)
         {
            t_bc = MPI_Wtime() - t_bc;
            tt_bc += t_bc;
            t_calc = MPI_Wtime();
         }

         if(DVFS_ENABLE) 
            mapping(g_rank%rows, DVFS_HIGH);

         /* Do the multiplication */
         dgemm_(TRANSA, TRANSB, &m, &n, &k, ALPHA, tempA, &m, tempB, &k, BETA, c, &m);

         if(DVFS_ENABLE) 
            mapping(g_rank%rows, DVFS_LOW);

         if(TIMER)
         { 
            t_calc = MPI_Wtime() - t_calc;
            tt_calc += t_calc;
         }
      }
      

   if(TIMER)
   {
      t_tot = MPI_Wtime() - t_tot;
      tt_tot += t_tot;
   
      MPI_Reduce(&tt_tot, &t_tot, 1, MPI_DOUBLE, MPI_MAX,  0, MPI_COMM_WORLD);
      MPI_Reduce(&tt_bc, &t_bc, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
      MPI_Reduce(&tt_calc, &t_calc, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);

   
      if(g_rank == 0)
         printf("tot = %10.6f, bc = %10.6f, calc = %10.6f\n", t_tot, t_bc, t_calc);
   }

   //	if(myrow==0 && mycol==0) 
   //   	  printf("myrow = %d, mycol = %d\n\n",myrow, mycol);

   //   printf("Test0\n");
   MPI_Barrier(MPI_COMM_WORLD);

   free(tempA); free(tempB);
   MPI_Comm_free(&my_row_comm); 
   MPI_Comm_free(&my_column_comm);

   //   printf("pdgemm done!\n");

   return;
}