Пример #1
0
Файл: mem.c Проект: junkoda/fs
void* mem_use_remaining(Mem* const mem, size_t size)
{
  size= size_align(size);

  //printf("debug %lu %lu\n", mem->size_using, mem->size_alloc);
  
  if(size + mem->size_using > mem->size_alloc)
    msg_abort("Error: Unable to use %lu MB in Mem %s; %lu MB allocated, "
	      "%lu remaining.\n",
	      mbytes(size), mem->name, mbytes(mem->size_alloc),
	      mbytes(mem->size_alloc - mem->size_using));
  
  assert(mem->size_using % sizeof(float) == 0);
  float* p= mem->buf;
  size_t n= mem->size_using / sizeof(float); //printf("n= %lu\n", n);

  mem->size_using += size;
  msg_printf(msg_verbose, "Using %lu of %lu in memory %s\n",
	     mem->size_using, mem->size_alloc, mem->name);


  return p+n;
}
Пример #2
0
static int enable(struct cmd_struct *cmd, struct arg_struct *arg)
{
	int cnt;
	int err;
	char *bearer;
	struct tipc_nl_msg msg;
	struct cmd_option *opt;
	struct nlattr *attrs;
	__u32 domain = 0;
	__u32 priority = 0;

	/* One mandatory argument (bearer) */
	if (arg->argc < arg->loc + 1)
		return -EINVAL;

	bearer = arg->argv[arg->loc];
	(arg->loc)++;

	cnt = opt_parse(cmd, arg);
	if (cnt < 0)
		return -EINVAL;

	msg.nl_flags =  NLM_F_REQUEST;
	msg.nl_cmd = TIPC_NL_BEARER_ENABLE;
	err = msg_init(&msg);
	if (err)
		return err;

	attrs = nla_nest_start(msg.nl_msg, TIPC_NLA_BEARER);
	NLA_PUT_STRING(msg.nl_msg, TIPC_NLA_BEARER_NAME, bearer);

	opt = get_opt(cmd, "priority");
	if (opt) {
		struct nlattr *prop;

		priority = atoi(opt->val);
		prop = nla_nest_start(msg.nl_msg, TIPC_NLA_BEARER_PROP);
		NLA_PUT_U32(msg.nl_msg, TIPC_NLA_PROP_PRIO, priority);
		nla_nest_end(msg.nl_msg, prop);
	}

	opt = get_opt(cmd, "domain");
	if (opt) {
		domain = str2addr(opt->val);
		if (!domain) {
			msg_abort(&msg);
			return -1;
		}

		NLA_PUT_U32(msg.nl_msg, TIPC_NLA_BEARER_DOMAIN, domain);
	}

	nla_nest_end(msg.nl_msg, attrs);

	err = msg_send(&msg);
	if (err)
		return err;

	err = msg_recv(&msg, NULL);
	if (err)
		return err;

	log_info("Bearer %s enabled\n", bearer);

	return 0;

nla_put_failure:
	msg_abort(&msg);

	return -ENOBUFS;
}
Пример #3
0
// Setup variables for 2LPT initial condition
void lpt_init(const int nc, const void* mem, const size_t size)
{
  // nc: number of mesh per dimension

  ptrdiff_t local_nx, local_x_start;
  ptrdiff_t total_size=
    fftwf_mpi_local_size_3d(nc, nc, nc/2+1, MPI_COMM_WORLD,
			    &local_nx, &local_x_start);
  
  Local_nx= local_nx;
  Local_x_start= local_x_start;

  //
  // Allocate memory
  //

  if(mem == 0) {
    // allocate memory here
    size_t bytes= sizeof(fftwf_complex)*total_size;
    int allocation_failed= 0;

    // 1&2 displacement
    for(int axes=0; axes < 3; axes++) {
      cdisp[axes]= fftwf_alloc_complex(total_size);
      disp[axes] = (float*) cdisp[axes];
      
      cdisp2[axes]= fftwf_alloc_complex(total_size);
      disp2[axes] = (float*) cdisp2[axes];
      bytes += 2*sizeof(fftwf_complex)*total_size;
      
      allocation_failed = allocation_failed ||
	(cdisp[axes] == 0) || (cdisp2[axes] == 0);
    } 
    
    // 2LPT
    for(int i=0; i<6; i++) {
      cdigrad[i] = (fftwf_complex *) fftwf_alloc_complex(total_size);
      digrad[i] = (float*) cdigrad[i];
      
      bytes += sizeof(fftwf_complex)*total_size;
      allocation_failed = allocation_failed || (digrad[i] == 0);
    } 
    
   if(allocation_failed)
     msg_abort(2003, "Error: Failed to allocate memory for 2LPT."
	       "Tried to allocate %d Mbytes\n", (int)(bytes/(1024*1024)));
   
   msg_printf(info, "%d Mbytes allocated for LPT\n", (int)(bytes/(1024*1024)));
  }
  else {
    size_t bytes= 0;
    fftwf_complex* p= (fftwf_complex*) mem;
    
    for(int axes=0; axes<3; axes++) {
      cdisp[axes]= p;
      disp[axes]= (float*) p;
      bytes += sizeof(fftwf_complex)*total_size*2;

      p += total_size;
    }
    for(int i=0; i<6; i++) {
      cdigrad[i]= p;
      digrad[i]= (float*) p;
      bytes += sizeof(fftwf_complex)*total_size;
      p += total_size;
    }
    assert(bytes <= size);
  }

  //
  // FFTW3 plans
  //
  for(int i=0; i<6; ++i)
    Inverse_plan[i]=
      fftwf_mpi_plan_dft_c2r_3d(nc, nc, nc, cdigrad[i], digrad[i],
				MPI_COMM_WORLD, FFTW_ESTIMATE);

  Forward_plan=
    fftwf_mpi_plan_dft_r2c_3d(nc, nc, nc, digrad[3], cdigrad[3],
			      MPI_COMM_WORLD, FFTW_ESTIMATE);

  for(int i=0; i<3; ++i) {
    Disp_plan[i]=
      fftwf_mpi_plan_dft_c2r_3d(nc, nc, nc, cdisp[i], disp[i],
				MPI_COMM_WORLD, FFTW_ESTIMATE);
    Disp2_plan[i]=
      fftwf_mpi_plan_dft_c2r_3d(nc, nc, nc, cdisp2[i], disp2[i],
				MPI_COMM_WORLD, FFTW_ESTIMATE);
  }

  // FFTW_MPI_TRANSPOSED_IN/FFTW_MPI_TRANSPOSED_OUT would be faster
  // FFTW_MEASURE is probably better for multiple realization  

  // misc data
  Nmesh= nc;
  Nsample= nc;
  seedtable = malloc(Nmesh * Nmesh * sizeof(unsigned int)); assert(seedtable);
}