示例#1
0
int main (int argc, char ** argv) 
{
    char        filename [256];
    int         rank, size, i, j;
    int         NX = 100, gb, offset;  //local/global/offset
    double      t[NX];
    int         nblocks = 3;
    MPI_Comm    comm = MPI_COMM_WORLD;
    char g_str[100], o_str[100], l_str[100];
    // attributes (from C variables)
    int someints[5] = {5,4,3,2,1};
    double somedoubles[5] = {5.55555, 4.4444, 3.333, 2.22, 1.1};

    /* ADIOS variables declarations for matching gwrite_temperature.ch */
    uint64_t    adios_groupsize, adios_totalsize;

    MPI_Init (&argc, &argv);
    MPI_Comm_rank (comm, &rank);
    MPI_Comm_size (comm, &size);

    gb = nblocks * NX * size;
    sprintf (g_str, "%d", gb);
    sprintf (l_str, "%d", NX);

    strcpy (filename, "no_xml_write_byid.bp");

    adios_init_noxml (comm);
    adios_set_max_buffer_size (10);

    int64_t       m_adios_group;
    int64_t       m_adios_file;
    int64_t       var_ids[nblocks];

    adios_declare_group (&m_adios_group, "restart", "iter", adios_flag_yes);
    adios_select_method (m_adios_group, "MPI", "", "");

    for (i = 0; i < nblocks; i++)
    {
        offset = rank * nblocks * NX + i * NX;
        sprintf (o_str, "%d", offset);
        var_ids[i] = adios_define_var (m_adios_group, "temperature"
                                       ,"", adios_double
                                       ,l_str, g_str, o_str
        );
        adios_set_transform (var_ids[i], "none");

        // This is here just for fun
        uint64_t varsize = adios_expected_var_size(var_ids[i]);
        // adios_expected_var_size() works here because the definition of the variable
        // does not depend on any dimension variable (but defined with numerical dimensions)
        fprintf (stderr, "Temperature block %d is %" PRIu64 " bytes\n", i, varsize);
    }

    // add some attributes
    adios_define_attribute_byvalue (m_adios_group,
                                    "single_string","", adios_string,  1, "A single string attribute");
    char *strings[] = {"X","Yy","ZzZ"};
    adios_define_attribute_byvalue (m_adios_group,
                                    "three_strings","", adios_string_array,  3, strings);
    adios_define_attribute_byvalue (m_adios_group,
                                    "single_int",   "", adios_integer, 1, &someints);
    adios_define_attribute_byvalue (m_adios_group,
                                    "single_double","", adios_double,  1, &somedoubles);
    adios_define_attribute_byvalue (m_adios_group,
                                    "five_ints",    "", adios_integer, 5, &someints);
    adios_define_attribute_byvalue (m_adios_group,
                                    "five_double",  "", adios_double,  5, &somedoubles);



    adios_open (&m_adios_file, "restart", filename, "w", comm);

    adios_groupsize = nblocks * (4 + 4 + 4 + NX * 8);

    adios_group_size (m_adios_file, adios_groupsize, &adios_totalsize);
    /* now we will write the data for each sub block */
    for (i = 0; i < nblocks; i++)
    {
        offset = rank * nblocks * NX + i * NX;
        for (j = 0; j < NX; j++)
            t[j] = offset + j;

        adios_write_byid(m_adios_file, var_ids[i], t);
    }

    adios_close (m_adios_file);

    MPI_Barrier (comm);

    adios_finalize (rank);

    MPI_Finalize ();
    return 0;
}
示例#2
0
int main (int argc, char** argv) 
{
  fastbit_init(0);
  fastbit_set_verbose_level(0);

  ADIOS_FILE * f;
  //MPI_Comm    comm_dummy = 0;  // MPI_Comm is defined through adios_read.h 
  MPI_Comm comm_dummy = MPI_COMM_WORLD;

  int         rank, size;
  MPI_Init (&argc, &argv);			   
  MPI_Comm_rank (comm_dummy, &rank);
  MPI_Comm_size (comm_dummy, &size);

  adios_init_noxml (comm_dummy);
  
  if (argc < 2) {
    printf("Usage: index_fastbit fileName (attrName)");
    return 0;
  }

  f = adios_read_open_file (argv[1], ADIOS_READ_METHOD_BP, comm_dummy);
  if (f == NULL) {
    printf ("::%s\n", adios_errmsg());
    return -1;
  }
  
  /*
  adios_allocate_buffer (ADIOS_BUFFER_ALLOC_NOW, (f->file_size)*2/1048576 + 5); // +5MB for extra room in buffer
  adios_declare_group (&gAdios_group, gGroupNameFastbitIdx, "", adios_flag_yes);
  adios_select_method (gAdios_group, "MPI", "", "");
  */
  gIdxFileName = fastbit_adios_util_getFastbitIndexFileName(argv[1]);
  unlink(gIdxFileName);

      adios_allocate_buffer (ADIOS_BUFFER_ALLOC_NOW, 500); // +5MB for extra room in buffer
      adios_declare_group (&gAdios_group, gGroupNameFastbitIdx, "", adios_flag_yes);
      adios_select_method (gAdios_group, "MPI", "", "");

      adios_open (&gAdios_write_file, gGroupNameFastbitIdx, gIdxFileName, "w", MPI_COMM_WORLD);

#ifdef MULTI_BLOCK
      int testid = adios_define_var (gAdios_group, "pack", "", adios_integer , 0, 0, 0);
#endif
#ifdef BOX
      int testid = adios_define_var (gAdios_group, "elements", "", adios_integer , 0, 0, 0);
#endif
      //uint64_t estimatedbytes = (nb+nk+no)*adios_type_size(adios_double, NULL);
      int jobCounter = getJobCounter(f);
      uint64_t estimatedbytes =  getByteEstimationOnFile(f, rank);
      if (size > 1) {
	int maxJobsPP = jobCounter/size + 1;
        estimatedbytes = estimatedbytes * maxJobsPP /jobCounter +1048576;
      }

      estimatedbytes += 1048576;

      uint64_t adios_totalsize;      // adios_group_size needs to be call before any write_byid, Otherwise write_byid does nothing 
      adios_group_size (gAdios_write_file, estimatedbytes , &adios_totalsize);     

      printf("=> .. adios open output file: %s, rank %d allocated %" PRIu64 " bytes... \n", gIdxFileName, rank, adios_totalsize);
      // IMPORTANT: 
      // can only call open/close once in a process
      // otherwise data is tangled or only the data in the last open/close call is recorded

#ifdef MULTI_BLOCK
      adios_write_byid(gAdios_write_file, testid, &pack);
#endif
#ifdef BOX
      adios_write_byid(gAdios_write_file, testid, &recommended_index_ele);
#endif


  sumLogTime(-1);
  sumLogTimeMillis(-1);

  
  if (argc >= 3) {
     int i=2;
     while (i<argc) {
        const char* varName = argv[i];
	if(strstr(varName, "<binning prec") != NULL) {
	  if (gBinningOption == NULL) {
	    gBinningOption = argv[i];
	  }
	  if (argc == 3) {
	    buildIndexOnAllVar(f, rank, size);
	    break;
	  }
	  i++;
	  continue;
	} else {
	  ADIOS_VARINFO * v = adios_inq_var(f, varName);
	  if (v == NULL) {
	     printf("No such variable: %s\n", varName);
	     return 0;
	   }	
	  printf("building fastbit index on  variable: %s\n", varName);
	  buildIndex_mpi(f, v, rank, size);
	  adios_free_varinfo(v);
	  i++;
	}
     }
  } else {
    buildIndexOnAllVar(f, rank, size);
  }


  sumLogTime(0);
  sumLogTimeMillis(0);

  adios_close(gAdios_write_file);
  adios_read_close(f);

  //
  // writing file clean up
  //


  // read back:
  f = adios_read_open_file (gIdxFileName, ADIOS_READ_METHOD_BP, comm_dummy);
  if (f == NULL) {
    printf("No such file: %s \n", gIdxFileName);
    return 0;
  }

  int numVars = f->nvars;
  
  int i=0;
  int k=0;
  int j=0;
  for (i=0; i<numVars; i++) {
      char* varName = f->var_namelist[i];
      ADIOS_VARINFO* v = adios_inq_var(f, varName);

       adios_inq_var_blockinfo(f,v);      
      int timestep = 0;
      for (k=0; k<v->sum_nblocks; k++) {
	  verifyData(f, v, k, timestep);
      }

      adios_free_varinfo(v);
  }

  adios_read_close(f);

  if (rank == 0) {
    printf(" ==>  index file is at: %s\n", gIdxFileName);
  }

  // clean up
  MPI_Barrier (comm_dummy);
  adios_finalize (rank);
  MPI_Finalize ();
  free (gIdxFileName);

  fastbit_cleanup();
  return 0;
}
示例#3
0
    void operator()(ThreadParams& params, T_Scalar value)
    {
        log<picLog::INPUT_OUTPUT> ("ADIOS: write %1%D scalars: %2%") % simDim % name;

        ADIOS_CMD( adios_write_byid(params.adiosFileHandle, varId, &value) );
    }
示例#4
0
void processData(void* data, uint64_t dataCount, int rank, int timestep, char* selName, FastBitDataType ft, ADIOS_VARINFO* v)
{
      char bmsVarName[100];
      char keyVarName[100];
      char offsetName[100];

      int64_t       var_ids_bms;
      int64_t       var_ids_key;
      int64_t       var_ids_offset;
             
      sprintf(bmsVarName, "bms-%d-%d-%s", v->varid, timestep, selName);
      sprintf(keyVarName, "key-%d-%d-%s", v->varid, timestep, selName);
      sprintf(offsetName, "offset-%d-%d-%s", v->varid, timestep, selName);
      

      double* keys = NULL;
      int64_t *offsets = NULL;
      uint32_t *bms = NULL;
      uint64_t nk=0, no=0, nb=0;
      
      const char* datasetName = "test";
      logTime("  data collected, fastbit start indexing"); 
      logTimeMillis("  data collected, fastbit start indexing"); 
	    //fastbit_adios_util_printData(data, v->type, blockBytes/adios_type_size(v->type, v->value));
      
      fastbitIndex(datasetName, data, dataCount, ft, &keys, &nk, &offsets, &no, &bms, &nb);

      logTime("  indexed on block");
      logTimeMillis("  indexed on block");
      
      printf("  RANK:%d, index created =  %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", on var:%d, timestep: %d, block %s\n", rank, nb, nk, no, v->varid, timestep, selName);
      sum_nb += nb; sum_nk += nk, sum_no += no;

      
      defineFastbitVar(1, bmsVarName, &var_ids_bms, adios_unsigned_integer, &nb,0,0);    			    
      defineFastbitVar(1, keyVarName, &var_ids_key, adios_double, &nk, 0, 0);
      defineFastbitVar(1, offsetName, &var_ids_offset, adios_long, &no, 0, 0); 

      printf("bms[0] = %" PRIu64 ", bms[1]=%" PRIu64 " \n", bms[0], bms[1]);
      //var_ids_bms = defineAdiosVar(bmsVarName, adios_unsigned_integer, nb, 0, 0);
      //var_ids_key = defineAdiosVar(keyVarName, adios_double, nk, 0, 0);
      //var_ids_offset = defineAdiosVar(offsetName, adios_long, no, 0, 0);


      logTime("  write starts");
      logTimeMillis("  write starts");

      adios_write_byid(gAdios_write_file, var_ids_bms, bms);
      adios_write_byid(gAdios_write_file, var_ids_key, keys);
      adios_write_byid(gAdios_write_file, var_ids_offset, offsets);

      logTime("  write ends");
      logTimeMillis("  write ends");
      sumLogTime(1);
      sumLogTimeMillis(1);
      
      free(data);	 
      data = NULL;
      free(bms); bms = NULL;
      free(keys); keys = NULL;
      free(offsets); offsets = NULL;

     
}