Ejemplo n.º 1
0
/**
 * Performs map reduce using mpi message passing.
 * Assumes numprocs is a power of 2. The result will
 * be stored in the map on process with rank 0.
 * @param map local map to reduce
 * @param rank mpi process rank
 * @param numprocs number of mpi processes.
 */
void mpiMapReduce(HashMap* map, int rank, int numprocs) {
  int s;
  int count;
  MPI_Status status;
  char* buffer;
  //printf("starting map reduce\n");
  for (s = numprocs / 2; s > 0; s = s/2) {
    if (rank < s) {
      // Get the number of elements being sent to us.
      //printf("getting next reduce for rank %d\n", rank);
      MPI_Probe(rank + s, 0, MPI_COMM_WORLD, &status);
      MPI_Get_count(&status, MPI_CHAR, &count);
      // receive from higher process. merge data.
      buffer = (char*)malloc(sizeof(char) * count);
      //printf("received %d bytes at %d from %d\n", count, rank, rank + s);
      MPI_Recv(buffer, count, MPI_CHAR, rank  + s, 0,
	       MPI_COMM_WORLD, MPI_STATUS_IGNORE);
      // do stuff with data
      addSerializedToMap(map, (unsigned char*) buffer, count);
      //printf("finished reduce at %d\n", rank);
      free(buffer);
    } else if (rank < 2 * s) {
      // serialize hashmap for sending.
      uint32_t nBytes;
      //printf("sending data from %d to %d\n", rank, rank - s);
      buffer = (char*)serializeMap(map, &nBytes);
      //printf("serialized map for sending in rank %d\n", rank);
      MPI_Send(buffer, nBytes, MPI_CHAR, rank - s, 0, MPI_COMM_WORLD);
      free(buffer);
    }
  }
}
Ejemplo n.º 2
0
QDomElement PListSerializer::serializeElement(QDomDocument &doc, const QVariant &variant) {
	if (variant.type() == QVariant::Map) {
		return serializeMap(doc, variant.toMap());
	}
	else if (variant.type() == QVariant::List) {
		 return serializeList(doc, variant.toList());
	}
	else {
		return serializePrimitive(doc, variant);
	}
}
Ejemplo n.º 3
0
bool Item::serializeAttr(PropWriteStream& propWriteStream) const
{
	if(isStackable() || isFluidContainer() || isSplash())
	{
		propWriteStream.addByte(ATTR_COUNT);
		propWriteStream.addByte((uint8_t)getSubType());
	}

	if(attributes && !attributes->empty())
	{
		propWriteStream.addByte(ATTR_ATTRIBUTE_MAP);
		serializeMap(propWriteStream);
	}

	return true;
}
Ejemplo n.º 4
0
 QString Serializer::serialize(QVariant v, int indent, bool parentIsArray) {
   if (!v.isValid())
     return QString(); // invalid
   if (v.type()==QVariant::List) 
     return serializeList(v.toList(), indent, parentIsArray);
   else if (v.type()==QVariant::Map)
     return serializeMap(v.toMap(), indent, parentIsArray);
   else if (v.type()==QVariant::String || v.type()==QVariant::ByteArray)
     return serializeString(v.toString());
   else if (v.type()==QVariant::Double)
     return serializeDouble(v.toDouble());
   else if (v.type()==QVariant::Bool)
     return v.toBool() ? "true" : "false";
   else if (v.type() == QVariant::ULongLong )
     return QString::number(v.value<qulonglong>());
   else if (v.canConvert<qlonglong>())
     return QString::number(v.value<qlonglong>());
   else if (v.canConvert<QString>())
     // this will catch QDate, QDateTime, QUrl, ...
     return serializeString(v.toString());
   else
     return QString();
 }
Ejemplo n.º 5
0
int main(int argc, char** argv) {
  HashMap* map = newMap(20, &stringHasher, &stringComparator, &stringCopy);
  char* str1 = "the";
  Key testKeyPtr = (Key)str1;
  incrementKeyValue(map, testKeyPtr);
  incrementKeyValue(map, testKeyPtr);
  incrementKeyValue(map, testKeyPtr);
  char* str2 = "blue";
  Key testKeyPtr2 = (Key)str2;
  incrementKeyValue(map, testKeyPtr2);
  incrementKeyValue(map, testKeyPtr2);
  incrementKeyValue(map, testKeyPtr2);
  printf("key = %d\n", get(map, testKeyPtr));
  printf("key2 = %d\n", get(map, testKeyPtr2));

  char* str3 = "a";
  Key testKeyPtr3 = (Key) str3;
  incrementKeyValue(map, testKeyPtr3);
  incrementKeyValue(map, testKeyPtr3);
  incrementKeyValue(map, testKeyPtr3);
  incrementKeyValue(map, testKeyPtr3);
  printf("key3 = \%d\n", get(map, testKeyPtr3));

  HashMap* map2 = newMap(20, &stringHasher, &stringComparator, &stringCopy);
  char* str4 = "blue";
  Key testKeyPtr4 = (Key) str4;
  incrementKeyValue(map2, testKeyPtr4);
  incrementKeyValue(map2, testKeyPtr4);

  char* str5 = "at";
  Key testKeyPtr5 = (Key) str5;
  incrementKeyValue(map2, testKeyPtr5);
  incrementKeyValue(map2, testKeyPtr5);
  printf("key4 = %d\n", get(map2, testKeyPtr4));
  printf("key5 = %d\n", get(map2, testKeyPtr5));

  char* str6 = "my";
  Key testKeyPtr6 = (Key) str6;
  incrementKeyValue(map2, testKeyPtr6);
  incrementKeyValue(map2, testKeyPtr6);
  incrementKeyValue(map2, testKeyPtr6);
  incrementKeyValue(map2, testKeyPtr6);
  printf("key6 = %d\n", get(map2, testKeyPtr6));

  printf("number of bytes in map1:%d\n", map->nBytes);
  char* data;
  uint32_t nBytes;
  data = serializeMap(map, &nBytes);
  printf("number of bytes in map2:%d\n", map2->nBytes);
  int i = 0;
  printf("printing raw bytes\n");
  for(i = 0;  i < nBytes + 4; i++) {
    printf("%c ", data[i]);
  }
  printf("\n");
  addSerializedToMap(map2, data);
  printf("number of bytes in reduced map2:%d\n", map2->nBytes);
  printf("key = %d\n", get(map2, testKeyPtr));
  printf("key2 = %d\n", get(map2, testKeyPtr2));
  printf("key3 = %d\n", get(map2, testKeyPtr3));
  printf("key4 = %d\n", get(map2, testKeyPtr4));
  printf("key5 = %d\n", get(map2, testKeyPtr5));
  printf("key6 = %d\n", get(map2, testKeyPtr6));
  deleteMap(map);
  deleteMap(map2);
}
Ejemplo n.º 6
0
void JoystickMapper::update()
{
    if (inputDevice != oldInputDevice)
    {
        // Build axis and button label
        vector<string> axes;
        vector<string> buttons;
        
        for (JoystickMapperItems::iterator i = items.begin();
             i != items.end();
             i++)
        {
            if (i->inputDevice == inputDevice)
            {
                switch (i->type)
                {
                    case JOYSTICKMAPPER_AXIS:
                    case JOYSTICKMAPPER_RELATIVEAXIS:
                        axes.push_back(i->label);
                        
                        break;
                        
                    case JOYSTICKMAPPER_BUTTON:
                        buttons.push_back(i->label);
                        
                        break;
                        
                    case JOYSTICKMAPPER_UNMAPPED:
                        axes.push_back(i->label);
                        buttons.push_back(i->label);
                        
                        break;
                        
                    default:
                        break;
                }
            }
        }
        
        // Update settings
        DeviceSettings settings;
        
        device->postMessage(this, DEVICE_GET_SETTINGS, &settings);
        
        for (DeviceSettings::iterator i = settings.begin();
             i != settings.end();
             i++)
        {
            if ((i->name.substr(0, 4) == "axis") && (i->type == "select"))
                i->options = strjoin(axes, ',');
            if ((i->name.substr(0, 6) == "button") && (i->type == "select"))
                i->options = strjoin(buttons, ',');
        }
        
        device->postMessage(this, DEVICE_SET_SETTINGS, &settings);
        
        inputDeviceMap[oldInputDevice] = serializeMap();
        
        device->postMessage(this, DEVICE_UPDATE, NULL);
        
        // Load map
        unserializeMap(inputDeviceMap[inputDevice]);
        
        // Reset values
        for (JoystickMapperMap::iterator i = usageIdMap.begin();
             i != usageIdMap.end();
             i++)
        {
            if ((i->second.type == JOYSTICKMAPPER_BUTTON) &&
                (i->second.value))
            {
                i->second.value = false;
                
                JoystickHIDEvent hidEvent;
                
                hidEvent.deviceId = deviceId;
                hidEvent.usageId = i->first;
                hidEvent.value = i->second.value;
                
                postNotification(this, JOYSTICK_DID_CHANGE, &hidEvent);
            }
        }
        
        oldInputDevice = inputDevice;
    }
}