Пример #1
0
void Simulation3D::simulate(bool dump, unsigned int dump_periodicity, unsigned int total_dumps) {
  unsigned int n_dumps = 0;
  timeval t1, t2;
  gettimeofday(& t1, NULL);

  unsigned int steps_per_timing = 100;
  unsigned long* timings = new unsigned long[nSteps / steps_per_timing];
  double* center_e_fields = new double[nSteps];

  std::cout << std::setprecision(10);
  for(currentStep=0; currentStep <= nSteps; currentStep++) {
    if (currentStep % dump_periodicity == 0 && n_dumps < total_dumps && dump) {
      std::ostringstream filename(std::ios::out);
      filename << dumpDir << "/dump3D_" << currentStep / dump_periodicity << "dt" << 10.0/nSteps << "dx" << dx << ".h5";
      this->dumpFields(filename.str());
      n_dumps++;
    }
    if (currentStep % steps_per_timing == 0 && world.rank() == 0) {
      gettimeofday(& t2, NULL);
      if(currentStep > 0)
	timings[currentStep / steps_per_timing - 1] =
	  1000000*(t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec);
	// std::cout << 1000000*(t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) << std::endl;
      t1=t2;
    }
    if (xLine.rank() == 1 && yLine.rank() == 1) { // FIXME - GENERALIZE
      center_e_fields[currentStep] = E[(blockSize*blockSize*blockSize/2 + blockSize*blockSize/2 + blockSize/2)*3];
    }
    if(currentStep < nSteps)
      this->timeStep();
  }

  if(world.rank() == 0)
    dumpTimings(timings, nSteps / steps_per_timing, steps_per_timing);

  if(xLine.rank() == 1 && yLine.rank() == 1)
    dumpCenterFields(center_e_fields, nSteps);

  delete[] timings;
  delete[] center_e_fields;
}
Пример #2
0
int main (int argc, char* argv[]) {
  if (argc < 3) {
    std::cout << "Need HOST and PORT as command line arguments." << std::endl;
    return 1;
  }
  if (argc >= 4) {
    N = atoi(argv[3]);
  }
  std::string resulturl;
  if (argc >= 5) {
    resulturl = argv[4];
  }

  std::cout << "ArangoDB latency test, calling " << N 
            << " times GET /_api/document/c/mykey" << std::endl;

  std::vector<uint64_t> timings;
  timings.reserve(N);

  std::string url = std::string("http://") + argv[1] + ":" + argv[2];
  std::string urlcomplete;

  curl_global_init(CURL_GLOBAL_DEFAULT);
  CURL* h = curl_easy_init();

  // Delete the collection c:
  std::cout << "Dropping collection c..." << std::endl;
  curl_easy_setopt(h, CURLOPT_CUSTOMREQUEST, "DELETE");
  urlcomplete = url + "/_api/collection/c";
  curl_easy_setopt(h, CURLOPT_URL, urlcomplete.c_str());
  curl_easy_perform(h);
  curl_easy_setopt(h, CURLOPT_CUSTOMREQUEST, NULL);
  std::cout << "\ndone." << std::endl;

  std::cout << "Creating collection c..." << std::endl;
  strcpy(buffer, "{\"name\": \"c\", \"numberOfShards\":13}");
  urlcomplete = url + "/_api/collection";
  curl_easy_setopt(h, CURLOPT_URL, urlcomplete.c_str());
  struct curl_slist *headers=NULL;
  headers = curl_slist_append(headers, "Content-Type: application/json");
  curl_easy_setopt(h, CURLOPT_HTTPHEADER, headers);
  curl_easy_setopt(h, CURLOPT_POSTFIELDS, buffer);
  curl_easy_setopt(h, CURLOPT_POSTFIELDSIZE, strlen(buffer));
  curl_easy_perform(h);
  curl_slist_free_all(headers);
  headers = NULL;
  std::cout << "\ndone." << std::endl;

  std::cout << "Creating one document..." << std::endl;
  strcpy(buffer, "{\"_key\":\"mykey\", \"name\":\"Neunhöffer\", \"firstName\":\"Max\"}");
  urlcomplete = url + "/_api/document?collection=c";
  curl_easy_setopt(h, CURLOPT_URL, urlcomplete.c_str());
  headers = curl_slist_append(headers, "Content-Type: application/json");
  curl_easy_setopt(h, CURLOPT_HTTPHEADER, headers);
  curl_easy_setopt(h, CURLOPT_POSTFIELDS, buffer);
  curl_easy_setopt(h, CURLOPT_POSTFIELDSIZE, strlen(buffer));
  curl_easy_perform(h);
  curl_slist_free_all(headers);
  std::cout << "\ndone." << std::endl;

  curl_easy_setopt(h, CURLOPT_HTTPGET, 1);
  curl_easy_setopt(h, CURLOPT_HTTPHEADER, NULL);
  curl_easy_setopt(h, CURLOPT_TCP_NODELAY, 1);

  std::cout << "Now racing..." << std::endl;
  timePointType t = timeNow();
  urlcomplete = url + "/_api/document/c/mykey";
  curl_easy_setopt(h, CURLOPT_URL, urlcomplete.c_str());
  curl_easy_setopt(h, CURLOPT_WRITEFUNCTION, write_data);
  timePointType t3, t4;
  for (int i = 0; i < N; i++) {
    pos = 0;
    t3 = timeNow();
    int success = curl_easy_perform(h);
    t4 = timeNow();
    timings.push_back(timeDiff(t3,t4));
    buffer[pos] = 0;
  }
  curl_easy_cleanup(h);
  timePointType t2 = timeNow();
  uint64_t d = timeDiff(t,t2);
  std::cout << "Total time: " << d << " ns" << std::endl;
  analyzeTimings("arangoTestDocument" + std::to_string(getpid()) 
                 + ".times", timings, N);
  dumpTimings("arangoTestDocument" + std::to_string(getpid()) 
              + ".times", timings);
  if (! resulturl.empty()) {
    submitTimings(resulturl, "readDocument", timings, N-1);
  }
  return 0;
}