File indexing completed on 2026-04-09 07:49:33
0001 #pragma once
0002
0003
0004
0005
0006
0007
0008
0009 #include <iostream>
0010 #include "SCurandChunk.h"
0011 #include "SYSRAP_API_EXPORT.hh"
0012
0013 struct SYSRAP_API SCurandSpec
0014 {
0015 typedef unsigned long long ULL ;
0016
0017 static constexpr const char* SEED_OFFSET = "0:0" ;
0018 static constexpr const char SEED_OFFSET_DELIM = ':' ;
0019
0020 static constexpr const char* CHUNKSIZES = "10x1M,9x10M,5x20M" ;
0021 static constexpr const char SIZEGROUP_DELIM = ',' ;
0022 static constexpr const char MUL_NUM_DELIM = 'x' ;
0023
0024 static int ParseSeedOffset(ULL& seed, ULL& offset, const char* _spec=nullptr );
0025 static int ParseChunkSizes( std::vector<ULL>& size, const char* _spec=nullptr );
0026 static std::string Desc(const std::vector<ULL>& size);
0027 };
0028
0029
0030 inline int SCurandSpec::ParseSeedOffset( ULL& seed, ULL& offset, const char* _spec )
0031 {
0032 const char* spec = _spec ? _spec : SEED_OFFSET ;
0033
0034 std::vector<std::string> elem ;
0035 sstr::Split( spec, SEED_OFFSET_DELIM, elem );
0036
0037 seed = elem.size() > 0 ? std::atoll( elem[0].c_str() ) : 0ull ;
0038 offset = elem.size() > 0 ? std::atoll( elem[1].c_str() ) : 0ull ;
0039
0040 return 0 ;
0041 }
0042
0043 inline int SCurandSpec::ParseChunkSizes(std::vector<ULL>& size, const char* _spec )
0044 {
0045 const char* spec = _spec ? _spec : CHUNKSIZES ;
0046
0047 std::vector<std::string> group ;
0048 sstr::Split(spec, SIZEGROUP_DELIM, group );
0049
0050 int num_group = group.size();
0051 for(int i=0 ; i < num_group ; i++)
0052 {
0053 const char* g = group[i].c_str();
0054
0055 std::vector<std::string> mul_num ;
0056 sstr::Split(g, MUL_NUM_DELIM, mul_num);
0057 assert( mul_num.size() == 2 );
0058 const char* MUL = mul_num[0].c_str();
0059 const char* NUM = mul_num[1].c_str();
0060
0061 ULL mul = std::atoll(MUL);
0062 ULL num = SCurandChunk::ParseNum(NUM);
0063
0064 for(ULL j=0 ; j < mul ; j++) size.push_back(num);
0065 }
0066 return 0 ;
0067 }
0068
0069 inline std::string SCurandSpec::Desc(const std::vector<ULL>& _size)
0070 {
0071 std::stringstream ss;
0072 ss << "SCurandSpec::Desc" << " size.size " << _size.size() << "[" ;
0073 ULL tot = 0 ;
0074 for(int i=0 ; i < int(_size.size()) ; i++ )
0075 {
0076 ULL num = _size[i];
0077 tot += num ;
0078 ss << SCurandChunk::FormatNum(num) << " " ;
0079 }
0080 ss << "] tot:" << SCurandChunk::FormatNum(tot) ;
0081 std::string str = ss.str();
0082 return str ;
0083 }
0084
0085
0086