int attr_req_info::set_min_limit_value(

  const char *rescn,
  const char *val)

  {
  int ret;

  /* Just go through the list of keywords and set the appropriate value */
  if (!strncmp(rescn, LPROCS, strlen(LPROCS)))
    {
    min_lprocs = atoi(val);
    }
  else if (!strncmp(rescn, MEMORY, strlen(MEMORY)))
    {
    ret = to_size(val, &min_mem_value);
    if (ret != PBSE_NONE)
      return(ret);
    min_mem = min_mem_value.atsv_num << min_mem_value.atsv_shift;
    }
  else if (!strncmp(rescn, SWAP, strlen(SWAP)))
    {
    ret = to_size(val, &min_swap_value);
    if (ret != PBSE_NONE)
      return(ret);
    min_swap = min_swap_value.atsv_num << min_swap_value.atsv_shift;
    }
  else if (!strncmp(rescn, DISK, strlen(DISK)))
    {
    ret = to_size(val, &min_disk_value);
    if (ret != PBSE_NONE)
      return(ret);
    min_disk = min_disk_value.atsv_num << min_disk_value.atsv_shift;
    }
  else if (!strncmp(rescn, NODES, strlen(NODES)))
    {
    min_nodes = atoi(val);
    }
  else if (!strncmp(rescn, SOCKETS, strlen(SOCKETS)))
    {
    min_sockets = atoi(val);
    }
  else if (!strncmp(rescn, CORES, strlen(CORES)))
    {
    min_cores = atoi(val);
    }
  else if (!strncmp(rescn, NUMA_NODE, strlen(NUMA_NODE)))
    {
    min_numa_nodes = atoi(val);
    }
  else if (!strncmp(rescn, THREADS, strlen(THREADS)))
    {
    min_threads = atoi(val);
    }
  else
    return(PBSE_BAD_PARAMETER);

  return(PBSE_NONE);

  }
Example #2
0
Color TexturesRenderer::getFinalComposition(const TexturesDefinition *textures, LightingManager *lighting,
                                            const vector<double> &presence, const vector<Vector3> &location,
                                            const vector<Vector3> &normal, double precision, const Vector3 &eye) const {
    int n = textures->getLayerCount();
    assert(presence.size() == to_size(n));
    assert(location.size() == to_size(n));
    assert(normal.size() == to_size(n));
    Color result = COLOR_BLACK;
    // TODO share the same lighting status (no need to recompute shadows)
    int i;
    for (i = n - 1; i > 0; i--) {
        // Start at the top-most covering layer (layers underneath are only important for displacement, not color)
        if (presence[i] > 0.99999) {
            break;
        }
    }
    for (i = 0; i < n; i++) {
        double layer_presence = presence[i];
        if (layer_presence > 0.0) {
            TextureLayerDefinition *layer = textures->getTextureLayer(i);
            auto detail_normal = _getDetailNormal(location[i], normal[i], layer, precision, quality_normal5);
            Color layer_color = lighting->apply(eye, location[i], detail_normal, *layer->material);
            layer_color.a *= layer_presence;
            result.mask(layer_color);
        }
    }
    return result;
}
int attr_req_info::set_default_limit_value(

  const char *rescn,
  const char *val)

  {
  int ret;

  /* Just go through the list of keywords and set the appropriate value */
  if (!strncmp(rescn, LPROCS, strlen(LPROCS)))
    {
    default_lprocs = atoi(val);
    }
  else if (!strncmp(rescn, MEMORY, strlen(MEMORY)))
    {
    ret = to_size(val, &default_mem_value);
    if (ret != PBSE_NONE)
      return(ret);
    default_mem = default_mem_value.atsv_num << default_mem_value.atsv_shift;
    }
  else if (!strncmp(rescn, SWAP, strlen(SWAP)))
    {
    ret = to_size(val, &default_swap_value);
    if (ret != PBSE_NONE)
      return(ret);
    default_swap = default_swap_value.atsv_num << default_swap_value.atsv_shift;
    }
  else if (!strncmp(rescn, DISK, strlen(DISK)))
    {
    ret = to_size(val, &default_disk_value);
    if (ret != PBSE_NONE)
      return(ret);
    default_disk = default_disk_value.atsv_num << default_disk_value.atsv_shift;
    }
  else if (!strncmp(rescn, NODE, strlen(NODE)))
    {
    default_nodes = atoi(val);
    }
  else if (!strncmp(rescn, SOCKET, strlen(SOCKET)))
    {
    default_sockets = atoi(val);
    }
  else if (!strncmp(rescn, NUMA_NODE, strlen(NUMA_NODE)))
    {
    default_numa_nodes = atoi(val);
    }
  else
    return(PBSE_BAD_PARAMETER);

  return(PBSE_NONE);

  } // END set_default_limit_value()
Example #4
0
int decode_size(

  struct attribute *patr,
  char             *name, /* attribute name */
  char             *rescn, /* resource name, unused here */
  char             *val) /* attribute value */

  {

  patr->at_val.at_size.atsv_num   = 0;
  patr->at_val.at_size.atsv_shift = 0;

  if ((val != NULL) && (val[0] != '\0'))
    {
    if (to_size(val, &patr->at_val.at_size) != 0)
      {
      return(PBSE_BADATVAL);
      }

    patr->at_flags |= ATR_VFLAG_SET | ATR_VFLAG_MODIFY;
    }
  else
    {
    patr->at_flags = (patr->at_flags & ~ATR_VFLAG_SET) | ATR_VFLAG_MODIFY;
    }

  return(0);
  }
Example #5
0
void GodRaysSampler::reset() {
    *bounds = SpaceSegment(Vector3(camera_location->x - max_length, low_altitude, camera_location->z - max_length),
                           Vector3(camera_location->x + max_length, high_altitude, camera_location->z + max_length));
    samples_x = round_to_int(bounds->getXDiff() / sampling_step) + 1;
    samples_y = round_to_int(bounds->getYDiff() / sampling_step) + 1;
    samples_z = round_to_int(bounds->getZDiff() / sampling_step) + 1;

    auto n = to_size(samples_x * samples_y * samples_z);
    delete[] data;
    data = new double[n];
    fill_n(data, n, -1.0);
}
Example #6
0
vector<Vector3> TexturesRenderer::getLayersDisplacement(const TexturesDefinition *textures, const Vector3 &location,
                                                        const Vector3 &normal, const vector<double> &presence) const {
    int n = textures->getLayerCount();
    assert(presence.size() == to_size(n));
    vector<Vector3> result;
    Vector3 displaced = location;
    for (int i = 0; i < n; i++) {
        double layer_presence = presence[i];
        if (layer_presence > 0.0) {
            TextureLayerDefinition *layer = textures->getTextureLayer(i);
            double displacement = _getLayerDisplacement(layer, location, normal, layer_presence);
            displaced = displaced.add(normal.scale(displacement * layer_presence));
        }
        result.push_back(displaced);
    }
    return result;
}
Example #7
0
int
decode_size(struct attribute *patr, char *name, char *rescn, char *val)
{
	int to_size(char *, struct size_value *);

	patr->at_val.at_size.atsv_num   = 0;
	patr->at_val.at_size.atsv_shift = 0;
	if ((val != (char *)0) && (strlen(val) != 0)) {
		errno = 0;
		if (to_size(val, &patr->at_val.at_size) != 0)
			return (PBSE_BADATVAL);
		if (errno != 0)
			return (PBSE_BADATVAL);
		patr->at_flags |= ATR_VFLAG_SET | ATR_VFLAG_MODIFY | ATR_VFLAG_MODCACHE;
	} else {
		patr->at_flags = (patr->at_flags & ~ATR_VFLAG_SET) |
			(ATR_VFLAG_MODIFY | ATR_VFLAG_MODCACHE);
	}
	return (0);
}
int attr_req_info::check_min_values(

  std::vector<std::string>& names, 
  std::vector<std::string>& values)

  {
  int ret;
  int           signed_value;
  unsigned long unsigned_value;
  int           lprocs = 1;

  for (unsigned int i = 0; i < names.size(); i++)
    {
    signed_value = 0;
    unsigned_value = 0;

    if (names[i].find("lprocs") == 0)
      lprocs = strtol(values[i].c_str(), NULL, 10);
    else if (names[i].find("thread_usage_policy") == 0)
      {
      if (values[i] == use_cores)
        {
        if ((this->min_cores > 0) &&
            (this->min_cores > lprocs))
          return(PBSE_MINLIMIT);
        }
      else if (this->min_cores > 0)
        return(PBSE_MINLIMIT);

      if ((this->min_threads > 0) &&
          (this->min_threads > lprocs))
        return(PBSE_MINLIMIT);

      lprocs = 1;
      }

    ret = this->get_signed_min_limit_value(names[i].c_str(), signed_value);
    if ((ret == PBSE_NONE) &&
        (signed_value != 0))
      {
      int val;

      val = atoi(values[i].c_str());
      if ((val != 0) && (val < signed_value))
        {
        return(PBSE_MINLIMIT);
        }
      }
        
    ret = this->get_unsigned_min_limit_value(names[i].c_str(), unsigned_value);
    if ((ret == PBSE_NONE) && (unsigned_value != 0))
      {
      unsigned long uval;
      struct size_value user_value;

      ret = to_size(values[i].c_str(), &user_value);
      if (ret != PBSE_NONE)
        return(ret);

      uval = user_value.atsv_num << user_value.atsv_shift;

      if ((uval != 0) && (uval < unsigned_value))
        {
        return(PBSE_MINLIMIT);
        }
      }
    }
 
  return(PBSE_NONE);
  } // END check_min_values()
Example #9
0
size_t get_size(const symbol_tablet &st, const char * const id)
{
  return to_size(to_array_type(st.lookup(id).type).size());
}
Example #10
0
/**
 *  This function is for the counter thread.
 *
 *  @param t argument
 *
 *  @return SUCCESS or FAIL
 */
static void *counter(void *t)
{
    int counter_id = assign_counter_id();
    int s = ALDER_STATUS_SUCCESS;
    alder_kmer_thread7_t *a = (alder_kmer_thread7_t*)t;
    assert(a != NULL);
    alder_log2("counter(%d)[%llu]: START", counter_id, a->i_ni);
    
    /* Numbers for decoding kmers. */
    alder_encode_number_t *m = alder_encode_number_create_for_kmer(a->k);
    alder_encode_number2_t *m2 = alder_encode_number2_createWithKmer(a->k);
    uint64_t *res_key = malloc(sizeof(*res_key) * m->s);
    if (m == NULL || m2 == NULL || res_key == NULL) {
        alder_loge(ALDER_ERR_MEMORY, "Fatal - counter(): not enough memory");
        pthread_exit(NULL);
    }
    memset(res_key, 0, sizeof(*res_key) * m->s);
    size_t ib = m2->b / 8;
    size_t jb = m2->b % 8;
    
#if !defined(NDEBUG)
    size_t debug_counter = 0;
#endif
    
    /* Let's read inputs, and skip writing table files. */
    size_t c_table = 1;
    uint64_t i_np = a->n_np;
    while (1) {
        
        ///////////////////////////////////////////////////////////////////////
        // Writer
        ///////////////////////////////////////////////////////////////////////
        if (c_table < 1) {
            s = write_tabfile(a, c_table, i_np);
            if (s != ALDER_STATUS_SUCCESS) {
                alder_loge(ALDER_ERR_FILE, "failed to write to the table");
                break;
            }
            c_table = 1;
        }
        
        /* Check if this is the final. */
        if (a->n_blockByReader[a->n_np] == a->n_blockByCounter[a->n_np]) {
            /* Exit! */
            break;
        }
        
        ///////////////////////////////////////////////////////////////////////
        // Reader
        ///////////////////////////////////////////////////////////////////////
        s = read_parfile(a, counter_id);
        if (s == NO_READ) {
            break;
        }
        
        ///////////////////////////////////////////////////////////////////////
        // Counter
        ///////////////////////////////////////////////////////////////////////
        assert(c_table == a->n_ht);
        
        /* setup of inbuf */
        uint8_t *inbuf = a->inbuf + counter_id * a->size_subinbuf;
        i_np = to_uint64(inbuf,INBUFFER_I_NP);
        size_t lenbuf = to_size(inbuf,INBUFFER_LENGTH);
        uint8_t *inbuf_body = inbuf + INBUFFER_BODY;
        
        while (a->main_i_np < i_np) {
            asm("");
        }
        if (lenbuf > 0) {
            assert(a->main_i_np == i_np);
        }
        
        /* setup of table */
        alder_hashtable_mcas_t *c_ht = NULL;
        c_table = 0;
        
        assert(c_table < a->n_ht);
        c_ht = a->ht[c_table];
        assert(lenbuf % m2->b == 0);
        uint64_t n_kmer = lenbuf / m2->b;
        size_t x = 0;
        for (uint64_t i_kmer = 0; i_kmer < n_kmer; i_kmer++) {
            a->n_i_kmer[counter_id]++;
            
#if !defined(NDEBUG)
            debug_counter++;
#endif
            
            /*****************************************************************/
            /*                         OPTIMIZATION                          */
            /*****************************************************************/
            /* Decode a kmer. */
            uint64_t *inbuf_body_uint64 = (uint64_t*)(inbuf_body + x);
            for (size_t i = 0; i < ib; i++) {
                m->n[i] = inbuf_body_uint64[i];
            }
            x += (8 * ib);
            if (jb > 0) {
                for (size_t j = 0; j < jb; j++) {
                    m2->n[ib].key8[j] = inbuf_body[x++];
                }
                m->n[ib] = m2->n[ib].key64;
            }
            /*****************************************************************/
            /*                         OPTIMIZATION                          */
            /*****************************************************************/
            
            s = alder_hashtable_mcas_increment(c_ht, m->n, res_key,
                                               a->isMultithreaded);
            
            if (s != ALDER_STATUS_SUCCESS) {
                alder_loge(ALDER_ERR, "Fatal - table is full!");
                assert(0);
                abort();
            }
        }
        assert(x == lenbuf);
        
        if (lenbuf > 0) {
            alder_kmer_thread7_increment_n_block(a, i_np);
            
            if (a->n_blockByCounter[i_np] == a->n_blockByReader[i_np]) {
                // No code.
                a->n_blockByCounter[a->n_np] += a->n_blockByCounter[i_np];
            } else {
                // Not the last bock, so won't write to a table file.
                c_table = a->n_ht;
            }
        } else {
            c_table = a->n_ht;
        }
        
        /* When parfile is zero... */
        if (a->n_blockByReader[i_np] == 0) { // && counter_id == 0) {
            int oval = a->n_blockByReader[i_np];
            int cval = oval + 1;
            cval = __sync_val_compare_and_swap(a->n_blockByReader + i_np,
                                               (int)oval, (int)cval);
            if (a->n_blockByReader[i_np] == 1) {
                a->main_i_np++;
            }
        }
    }
    XFREE(res_key);
    alder_encode_number_destroy(m);
    alder_encode_number2_destroy(m2);
    alder_log2("counter(%d)[%llu]: END", counter_id, a->i_ni);
    pthread_exit(NULL);
}
Example #11
0
/**
 *  This function reads a block of partition files.
 *
 *  @param a          counter
 *  @param counter_id counter id
 *
 *  @return SUCCESS or FAIL or ALDER_KMER_THREAD7_NO_READ
 */
static __attribute__ ((noinline)) int
read_parfile(alder_kmer_thread7_t *a, int counter_id)
{
    int s = ALDER_STATUS_SUCCESS;
    pthread_mutex_lock(&mutex_read);
    
    if (a->reader_lenbuf == 0) {
        if (a->reader_i_parfile > 0) {
            close_parfile(a);
        }
        if (a->reader_i_parfile < a->n_np) {
            s = open_parfile(a, a->reader_i_parfile);
            if (s != ALDER_STATUS_SUCCESS) {
                return s;
            }
            a->reader_i_parfile++;
        } else {
            // No more input file to read.
            pthread_mutex_unlock(&mutex_read);
            return NO_READ;
        }
    }
    
    /* Read a block of input buffer. */
    ssize_t lenbuf = 0;
    uint8_t *inbuf = a->inbuf + counter_id * a->size_subinbuf;
    uint8_t *inbuf_body = inbuf + INBUFFER_BODY;
    size_t cur_next_lenbuf = a->next_lenbuf;
    if (a->next_lenbuf > 0) {
        memcpy(inbuf_body, a->next_inbuf, a->next_lenbuf);
        inbuf_body += a->next_lenbuf;
    }
    lenbuf = read(fileno(a->fpin), inbuf_body, a->size_readbuffer);
    assert(lenbuf == 0 || lenbuf >= a->b);
    if (lenbuf > 0 && a->b > 1) {
        assert(cur_next_lenbuf + lenbuf >= a->b);
        a->next_lenbuf = (cur_next_lenbuf + lenbuf) % a->b;
        memcpy(a->next_inbuf, inbuf_body + lenbuf - a->next_lenbuf, a->next_lenbuf);
        a->reader_lenbuf = cur_next_lenbuf + lenbuf - a->next_lenbuf;
    } else if (lenbuf > 0 && a->b == 1) {
        a->next_lenbuf = 0;
        a->reader_lenbuf = lenbuf;
    } else if (lenbuf == 0) {
        assert(cur_next_lenbuf == 0);
        a->reader_lenbuf = lenbuf;
    } else {
        // Error in reading.
        assert(0);
        abort();
    }
    assert(a->reader_i_parfile <= a->n_np);
    
    to_uint64(inbuf,INBUFFER_I_NP) = a->reader_i_parfile - 1;
    to_size(inbuf,INBUFFER_LENGTH) = a->reader_lenbuf;
    assert(a->reader_lenbuf % a->b == 0);
    
    /* Progress */
    a->n_byte += lenbuf;
    
    pthread_mutex_unlock(&mutex_read);
    return ALDER_STATUS_SUCCESS;
}