예제 #1
0
/* Add a new entry to the registry */
int registry_add(char *name,int object_type,void *data)
{
   registry_entry_t *entry;

   if (!name) 
      return(-1);

   REGISTRY_LOCK();

   /* check if we have already a reference for this name */
   if ((entry = registry_find_entry(name,object_type))) {
      REGISTRY_UNLOCK();
      return(-1);
   }

   /* create a new entry */
   if (!(entry = mp_alloc(&registry->mp,sizeof(*entry)))) {
      REGISTRY_UNLOCK();
      return(-1);
   }

   entry->name = name;
   entry->data = data;
   entry->object_type = object_type;
   entry->ref_count = 1;   /* consider object is referenced by the caller */
   registry_insert_entry(entry);

   REGISTRY_UNLOCK();
   return(0);
}
예제 #2
0
int get_chunk_body_buffer(struct worker_context *ctx, struct connection *conn, char **p_start, int *p_len)
{
	int flag = 0;
	struct body_buffer *buffer;
	if ( DLIST_EMPTY(&conn->_client._body) )
	{
		flag = 1;
	}
	else
	{
		__dlist_t *cur = DLIST_PRE(&conn->_client._body);
		buffer = GET_OWNER(cur, struct body_buffer, _list);
		if ( buffer->_data_len - buffer->_curpos == 0 )
		{
			flag = 1;
		}
	}
	if ( flag )
	{
		buffer = (struct body_buffer *)mp_alloc(ctx->_body_pool);
		if ( NULL == buffer )
		{
			WARNING("failed to alloc mem for body buffer.");
			return -1;
		}
		DLIST_INIT(&buffer->_list);
		buffer->_curpos = 0;
		buffer->_data_len = ctx->_data_len;
		DLIST_INSERT_B(&buffer->_list, &conn->_client._body);
	}
	*p_start = buffer->_data + buffer->_curpos;
	*p_len = buffer->_data_len - buffer->_curpos;
	return 0;
}
예제 #3
0
void func_worker_1(void* arg) {
    // Cast and load the parameter
    int worker_1_param = *((int*)arg);
    // Create the queuing ports
    spd_t * chan = mp_create_sport(MP_CHAN_1_ID, SOURCE, MP_CHAN_1_MSG_SIZE);
    if (chan == NULL) {
        DEBUGF(chan);
        abort();
    }
    volatile unsigned long long _SPM * time_sample = mp_alloc(MP_CHAN_1_MSG_SIZE);
    // Initialize the communication channels
    int retval = mp_init_ports();
    // TODO: check on retval

    slave= 1;

    for (unsigned long long start = get_cpu_usecs(); start + RUNTIME > get_cpu_usecs(); ) {
        *time_sample = get_cpu_usecs();
        mp_write(chan,time_sample);
    }

    int ret = 0;
    corethread_exit(&ret);
    return;
}
예제 #4
0
int bam_plp_push(bam_plp_t iter, const bam1_t *b)
{
	if (iter->error) return -1;
	if (b) {
		if (b->core.tid < 0) return 0;
		if (b->core.flag & iter->flag_mask) return 0;
		if (iter->tid == b->core.tid && iter->pos == b->core.pos && iter->mp->cnt > iter->maxcnt) return 0;
		bam_copy1(&iter->tail->b, b);
		iter->tail->beg = b->core.pos; iter->tail->end = bam_calend(&b->core, bam1_cigar(b));
		iter->tail->s = g_cstate_null; iter->tail->s.end = iter->tail->end - 1; // initialize cstate_t
		if (b->core.tid < iter->max_tid) {
			fprintf(stderr, "[bam_pileup_core] the input is not sorted (chromosomes out of order)\n");
			iter->error = 1;
			return -1;
		}
		if ((b->core.tid == iter->max_tid) && (iter->tail->beg < iter->max_pos)) {
			fprintf(stderr, "[bam_pileup_core] the input is not sorted (reads out of order)\n");
			iter->error = 1;
			return -1;
		}
		iter->max_tid = b->core.tid; iter->max_pos = iter->tail->beg;
		if (iter->tail->end > iter->pos || iter->tail->b.core.tid > iter->tid) {
			iter->tail->next = mp_alloc(iter->mp);
			iter->tail = iter->tail->next;
		}
	} else iter->is_eof = 1;
	return 0;
}
예제 #5
0
bam_plp_t bam_plp_init(bam_plp_auto_f func, void *data)
{
	bam_plp_t iter;
	iter = calloc(1, sizeof(struct __bam_plp_t));
	iter->mp = mp_init();
	iter->head = iter->tail = mp_alloc(iter->mp);
	iter->dummy = mp_alloc(iter->mp);
	iter->max_tid = iter->max_pos = -1;
	iter->flag_mask = BAM_DEF_MASK;
	iter->maxcnt = 8000;
	if (func) {
		iter->func = func;
		iter->data = data;
		iter->b = bam_init1();
	}
	return iter;
}
예제 #6
0
파일: lock.c 프로젝트: t-crest/patmos
LOCK_T * initialize_lock(unsigned remote) {
    LOCK_T * lock = (LOCK_T *)mp_alloc(sizeof(LOCK_T));
    lock->remote_entering = 0;
    lock->remote_number = 0;
    lock->local_entering = 0;
    lock->local_number = 0;  
    lock->remote_cpuid = remote;
    return lock;
}
예제 #7
0
struct sound_params *sg_create_sound_params(int type, void *params)
{
    if( !sound_params_mem )
        sound_params_mem = mp_create(sizeof(struct sound_params), 2);

    struct sound_params * sc = mp_alloc(sound_params_mem);
    sg_set_params(sc, type, params);
    return sc;
}
예제 #8
0
void func_worker_1(void* arg) {
  mp_init();
  
  spd_t * sport2 = mp_create_sport(CHAN_ID_TWO,SINK,SAMPLE_SIZE*sizeof(short));
  spd_t * sport1 = mp_create_sport(CHAN_ID_ONE,SOURCE,SAMPLE_SIZE*sizeof(short));
  if (sport1 == NULL || sport2 == NULL) {
    //exit(1);
  }
  volatile short _SPM * sample = mp_alloc(SAMPLE_SIZE*sizeof(short));

  for (int i = 0; i < SAMPLE_SIZE; ++i) {
    sample[i] = i;
  }

  mp_init_ports();


  while(done == 0);

  for (int i = 0; i < ITERATIONS; ++i) {
      int ret = mp_read(sport2,sample);
      for (int i = 0; i < SAMPLE_SIZE; ++i) {
        if(sample[i] != i) {
          break;
        }
      }
      for (int i = 0; i < 100000; ++i)
      {
        asm volatile (""::);
      }
  }

  //for (int i = 0; i < ITERATIONS/2; ++i) {
  for (int i = 0; i < ITERATIONS*20; ++i) {
    mp_write(sport1,sample);
    for (int i = 0; i < SAMPLE_SIZE; ++i) {
      sample[i] = i;
    }
    //for (int i = 0; i < 100000; ++i) {
    //  asm volatile (""::);
    //}
    mp_write(sport1,sample);
    for (int i = 0; i < SAMPLE_SIZE; ++i) {
      sample[SAMPLE_SIZE-1-i] = i;
    }
    //for (int i = 0; i < 100000; ++i) {
    //  asm volatile (""::);
    //}
  }

  
  
  int ret = 0;
  corethread_exit(&ret);
  return;
}
예제 #9
0
파일: object.c 프로젝트: NZOI/moe-cms
struct odes *
obj_new(struct mempool *pool)
{
  struct odes *o = mp_alloc(pool, sizeof(struct odes));
  o->pool = pool;
  o->attrs = NULL;
  o->cached_attr = NULL;
  o->parent = NULL;
  return o;
}
예제 #10
0
파일: object.c 프로젝트: NZOI/moe-cms
static struct oattr *
oa_new_ref(struct odes *o, uns x, byte *v)
{
  struct oattr *a = mp_alloc(o->pool, sizeof(struct oattr));

  a->next = a->same = NULL;
  a->attr = x;
  a->val = v;
  return a;
}
예제 #11
0
/* Initialize registry */
int registry_init(void)
{
   registry_entry_t *p;
   pthread_mutexattr_t attr;
   size_t len;
   int i;

   registry = malloc(sizeof(*registry));
   assert(registry != NULL);

   pthread_mutexattr_init(&attr);
   pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
   pthread_mutex_init(&registry->lock,&attr);

   /* initialize registry memory pool */
   mp_create_fixed_pool(&registry->mp,"registry");

   registry->ht_name_entries = REGISTRY_HT_NAME_ENTRIES;
   registry->ht_type_entries = REGISTRY_MAX_TYPES;

   /* initialize hash table for names, with sentinels */
   len = registry->ht_name_entries * sizeof(registry_entry_t);
   registry->ht_names = mp_alloc(&registry->mp,len);
   assert(registry->ht_names != NULL);

   for(i=0;i<registry->ht_name_entries;i++) {
      p = &registry->ht_names[i];
      p->hname_next = p->hname_prev = p;
   }

   /* initialize hash table for types, with sentinels */
   len = registry->ht_type_entries * sizeof(registry_entry_t);
   registry->ht_types = mp_alloc(&registry->mp,len);
   assert(registry->ht_types != NULL);

   for(i=0;i<registry->ht_type_entries;i++) {
      p = &registry->ht_types[i];
      p->htype_next = p->htype_prev = p;
   }

   return(0);
}
예제 #12
0
파일: object.c 프로젝트: NZOI/moe-cms
static struct oattr *
oa_new_son(struct odes *o, uns x, struct odes *son)
{
  struct oattr *a = mp_alloc(o->pool, sizeof(struct oattr));

  a->next = a->same = NULL;
  a->attr = x;
  a->son = son;
  son->parent = o;
  return a;
}
예제 #13
0
void
mp_basket_add (mem_pool_t * mp, basket_t * bsk, void *token)
{
  basket_t *newn = (basket_t *) mp_alloc (mp, sizeof (basket_t));
  if (bsk->bsk_count == 0)
    basket_init (bsk);

  newn->bsk_pointer = token;
  LISTPUTBEFORE (bsk, newn, bsk_next, bsk_prev);
  bsk->bsk_count++;
}
예제 #14
0
bam_lplbuf_t *bam_lplbuf_init(bam_pileup_f func, void *data)
{
	bam_lplbuf_t *tv;
	tv = (bam_lplbuf_t*)calloc(1, sizeof(bam_lplbuf_t));
	tv->mp = mp_init();
	tv->head = tv->tail = mp_alloc(tv->mp);
	tv->func = func;
	tv->user_data = data;
	tv->plbuf = bam_plbuf_init(tview_func, tv);
	return (bam_lplbuf_t*)tv;
}
예제 #15
0
파일: object.c 프로젝트: NZOI/moe-cms
static struct oattr *
oa_new(struct odes *o, uns x, byte *v)
{
  uns l = strlen(v)+1;
  struct oattr *a = mp_alloc(o->pool, sizeof(struct oattr) + l);

  a->next = a->same = NULL;
  a->attr = x;
  a->val = (byte*) (a+1);
  memcpy(a->val, v, l);
  return a;
}
예제 #16
0
파일: mempool.c 프로젝트: maczpc/csf
inline void *
mp_calloc(size_t number, size_t size)
{
	void *ptr;
	size_t num_size;

	num_size = number * size;
	ptr = mp_alloc(num_size);
	if (ptr != NULL)
		memset(ptr, 0, num_size);
	return ptr;
}
예제 #17
0
int main(int argc, char *argv[])
{
	int *h_mem = NULL;
	int cnt = 0;
	struct mp_mem_head_t *p_mem_head = NULL;
	struct mp_node_t *pp_node_array[NEW_NODE_NUM];
	struct mp_node_t *p_node = NULL;

	p_mem_head = mp_alloc(&h_mem, ALLOC_NODE_NUM);
	for (cnt = 0; cnt < NEW_NODE_NUM; cnt++) {
		pp_node_array[cnt] = mp_new_node(h_mem);
		if (pp_node_array[cnt] == NULL) {
			mp_clean(h_mem);
			return -1;
		}
	}
	for (cnt = 0; cnt < NEW_NODE_NUM; cnt += 3) {
		mp_del_node(h_mem, pp_node_array[cnt]);
	}
	mp_del_node(h_mem, pp_node_array[NEW_NODE_NUM - 1]);
	for (cnt = 0; cnt < NEW_NODE_NUM; cnt++) {
		pp_node_array[cnt] = mp_new_node(h_mem);
	}
//	pp_node_array[3] = mp_new_node(h_mem);
//	pp_node_array[6] = mp_new_node(h_mem);
//	pp_node_array[9] = mp_new_node(h_mem);
//	pp_node_array[12] = mp_new_node(h_mem);
//	pp_node_array[15] = mp_new_node(h_mem);
	p_node = (struct mp_node_t *)(p_mem_head + 1);
	for (cnt = 0; cnt < ALLOC_NODE_NUM; cnt++, p_node++) {
		printf("node: %p\tprev: %p\tnext: %p\tused: %d\n",
				p_node, p_node->p_prev, p_node->p_next, p_node->used);
	}
#if 0
	for (cnt = 0; cnt < NEW_NODE_NUM; cnt++) {
		if (pp_node_array[cnt] != NULL) {
			printf("p_node: %p, p_node prev: %p, p_node next: %p\n",
					pp_node_array[cnt],
					pp_node_array[cnt]->p_prev,
					pp_node_array[cnt]->p_next);
		}
	}
#endif
	printf("------------- memory pool info ------------\n");
	printf("first %p, tail %p, used: %d\n",
			p_mem_head->p_node_first,
			p_mem_head->p_node_tail,
			p_mem_head->used_node_num);
	mp_clean(h_mem);
	return 0;
}
예제 #18
0
struct triangle_parameters *sg_create_triangle_parameters(float frequency,
                                                          float sample_rate)
{
    if( !triangle_parameter_mp )
        triangle_parameter_mp = mp_create(sizeof(struct triangle_parameters), 16);

    struct triangle_parameters *p = mp_alloc(triangle_parameter_mp);
    p->frequency = frequency;
    p->ticks_per_rev = sample_rate/frequency;
    p->counter = 0;
    p->sample_rate = sample_rate;
    p->current_value = 0;
    p->slope = 1 / (p->ticks_per_rev/4.0);
    return p;
}
예제 #19
0
struct sine_parameters *sg_create_sine_parameters(float frequency,
                                                  float sample_rate)
{
    if( !sine_parameter_mp )
        sine_parameter_mp = mp_create(sizeof(struct sine_parameters), 16);

    struct sine_parameters *p = mp_alloc(sine_parameter_mp);
    p->frequency = frequency;
    p->ticks_per_rev = sample_rate/frequency;
    p->rev = (sample_rate/frequency) / (2*PI);
    p->counter = 0;
    p->sample_rate = sample_rate;
    p->current_value = 0;
    return p;
}
예제 #20
0
struct sawtooth_parameters *sg_create_sawtooth_parameters(float frequency,
                                                          float sample_rate)
{
    if( !sawtooth_parameter_mp )
        sawtooth_parameter_mp = mp_create(sizeof(struct sawtooth_parameters), 16);

    struct sawtooth_parameters *p = mp_alloc(sawtooth_parameter_mp);
    p->frequency = frequency;
    p->ticks_per_rev = sample_rate/frequency;
    p->counter = 0;
    p->sample_rate = sample_rate;
    p->current_value = -1;
    p->slope = 2.0 / p->ticks_per_rev;
    return p;
}
예제 #21
0
static void
load(const char *filename, uint flags, void *img_data, uint img_size, uintptr_t group, TextureLoaded sync_cb, void *cb_data)
{
        assert(sync_cb != NULL);
        SDL_mutexP(storage_mutex);
        {
                /* See if task for this filename already exists. */
                Task *task;
                HASH_FIND_STR(task_hash, filename, task);
                if (task == NULL) {
                        task = mp_alloc(&mp_tasks);
                        
                        /* Set task filename and add to hash. */
                        assert(*filename != '\0' && strlen(filename) < sizeof(task->filename));
                        strcpy(task->filename, filename);
                        HASH_ADD_STR(task_hash, filename, task);
                        
                        /* Set source buffer and size. */
                        task->img_data = img_data;
                        task->img_size = img_size;
                        
                        if (texture_is_loaded(filename, flags)) {
                                /* Already loaded: add to finished_tasks. */
                                DL_PREPEND(finished_tasks, task);
                                num_finished++;
                        } else {
                                /*
                                 * Insert into active list and signal task
                                 * processing thread.
                                 */
                                task->active = 1;
                                DL_PREPEND(active_tasks, task);
                                SDL_CondSignal(checktask_cond);
                        }
                } else if (task->active) {
                        /* Move to the front of active task queue. */
                        DL_DELETE(active_tasks, task);
                        DL_PREPEND(active_tasks, task);
                }
                
                /* Set/change group, flags, callback and its data pointer. */
                task->group = (group != 0) ? group : (uintptr_t)sync_cb;
                task->sync_cb = sync_cb;
                task->cb_data = cb_data;
                task->flags = flags;                
        }
        SDL_mutexV(storage_mutex);        
}
예제 #22
0
struct square_wave_parameters *sg_create_square_wave_parameters(float frequency,
                                                                float duty_cycle,
                                                                float sample_rate)
{
    if( !square_wave_parameter_mem )
        square_wave_parameter_mem = mp_create(sizeof(struct square_wave_parameters), 16);

    struct square_wave_parameters *p = mp_alloc(square_wave_parameter_mem);
    p->frequency = frequency;
    p->ticks_per_rev = sample_rate/frequency;
    p->counter = 0;
    p->sample_rate = sample_rate;
    p->current_value = 0;
    p->duty_cycle = duty_cycle;
    return p;
}
예제 #23
0
/*
 * @brief    initialize system monitor
 * @param    none
 * @return   status
 * @note     only monitor daemon can call this function
 */
HRESULT monitor_init(VOID)
{
	HRESULT ret = E_FAIL;
	struct mp_mem_head_t *p_mem_head = NULL;

	M_DAEMON_PRINT(LOG_DEBUG, "enter\n");
	p_mem_head = (struct mp_mem_head_t *)h_mem;

	cnt_init++;
	if (cnt_init != 1) {
		M_DAEMON_PRINT(LOG_INFO,
			"warning: daemon has already been initialized\n");
		return S_OK;
	}
#ifndef __BIONIC__
	shmid = mp_shm_alloc(&h_mem, PUBLIC_SHM_KEY, MODULE_NUMBER_MAX);
	if (h_mem == NULL)
		return E_FAIL;
	mp_shm_init(h_mem, MODULE_NUMBER_MAX);
	M_DAEMON_PRINT(LOG_WARN, "shmid: %d, h_mem: %p\n", shmid, h_mem);

	semid = mp_sem_create(PUBLIC_SEM_KEY);
	M_DAEMON_PRINT(LOG_WARN, "semid: %d\n", semid);
	M_DAEMON_ASSERT(semid != -1);
#else
        mp_alloc(&h_mem, MODULE_NUMBER_MAX);
#endif
	ret = M_OSAL_Init();
	M_DAEMON_ASSERT(ret == S_OK);

	ret = M_OSAL_Task_Create_Advanced(&h_daemon, daemon_thread, NULL,
			M_OSAL_TASK_PRIORITY_DEFAULT, MSG_NUMBER_MAX);
	M_DAEMON_ASSERT(ret == S_OK);

	M_DAEMON_PRINT(LOG_DEBUG, "leave, shmid: %d, h_mem: %p\n",
			shmid, h_mem);
	return ret;
}
예제 #24
0
파일: mempool.c 프로젝트: 0xxon/rbldnsd
void *mp_memdup(struct mempool *mp, const void *buf, unsigned len) {
  void *b = mp_alloc(mp, len, 0);
  if (b)
    memcpy(b, buf, len);
  return b;
}
예제 #25
0
파일: main.c 프로젝트: goma/goma
int
main(int argc, char **argv)
     
     /*
      * Initial main driver for GOMA. Derived from a (1/93) release of
      * the rf_salsa program by
      *        
      *        Original Authors: John  Shadid (1421)
      *		                 Scott Hutchinson (1421)
      *        		         Harry Moffat (1421)
      *       
      *        Date:		12/3/92
      * 
      *
      *        Updates and Changes by:
      *                           Randy Schunk (9111)
      *                           P. A. Sackinger (9111)
      *                           R. R. Rao       (9111)
      *                           R. A. Cairncross (Univ. of Delaware)
      *        Dates:           2/93 - 6/96
      *
      *       Modified for continuation
      *                           Ian Gates
      *       Dates:            2/98 - 10/98
      *       Dates:            7/99 - 8/99
      * 
      * Last modified: Wed  June 26 14:21:35 MST 1994 [email protected]
      * Hello.
      * 
      * Note: Many modifications from an early 2/93 pre-release
      *	      version of rf_salsa were made by various persons 
      *       in order to test ideas about moving/deforming meshes...
      */ 
{
  /* Local Declarations */

  double time_start, total_time;   /* timing variables */
#ifndef PARALLEL
  /*  struct tm *tm_ptr;               additional serial timing variables */
  time_t now;
#endif

  int error;
  int i;
  int j;

  char	**ptmp;
  char *yo;

  struct Command_line_command **clc=NULL; /* point to command line structure */
  int           nclc = 0;		/* number of command line commands */

/********************** BEGIN EXECUTION ***************************************/

#ifdef FP_EXCEPT
  feenableexcept ((FE_OVERFLOW | FE_DIVBYZERO | FE_INVALID));
#endif

/* assume number of commands is less than or equal to the number of 
 * arguments in the command line minus 1 (1st is program name) */

  /*
  *  Get the name of the executable, yo
  */
  yo = argv[0];

#ifdef PARALLEL
  MPI_Init(&argc, &argv);
  time_start = MPI_Wtime();
#endif /* PARALLEL */
#ifndef PARALLEL
  (void)time(&now);
  time_start = (double)now;
#endif /* PARALLEL */

  time_goma_started = time_start;

  Argv = argv;

  Argc = argc;

#ifdef PARALLEL
  /*
   * Determine the parallel processing status, if any. We need to know
   * pretty early if we're "one of many" or the only process.
   */

  error = MPI_Comm_size(MPI_COMM_WORLD, &Num_Proc);
  error = MPI_Comm_rank(MPI_COMM_WORLD, &ProcID);

  /*
   * Setup a default Proc_config so we can use utility routines 
   * from Aztec
   */

  AZ_set_proc_config(Proc_Config, MPI_COMM_WORLD);

  /* set the output limit flag if need be */

  if( Num_Proc > DP_PROC_PRINT_LIMIT ) Unlimited_Output = FALSE;

#ifdef HAVE_MPE_H
  error = MPE_Init_log();
#endif /* HAVE_MPE_H */

  Dim = 0;			/* for any hypercube legacy code...  */

#endif /* PARALLEL */
  
#ifndef PARALLEL
  Dim        = 0;
  ProcID     = 0;
  Num_Proc   = 1;
#endif /* PARALLEL */


  /*
  *   HKM - Change the ieee exception handling based on the machine and
  *         the level of debugging/speed desired. This call currently causes
  *         core dumps for floating point exceptions.
  */

  handle_ieee();
  
  log_msg("--------------");
  log_msg("GOMA begins...");

  /*
   * Some initial stuff that only the master process does.
   */

  if ( ProcID == 0 )
    {
      if (argc > 1)
	{
	  log_msg("Preprocessing command line options.");
	  clc = (struct Command_line_command **) 
	    smalloc( argc * sizeof(struct Command_line_command *));
	  for (i=0; i<argc; i++)
	    {
	      clc[i] = (struct Command_line_command *) 
		smalloc(sizeof(struct Command_line_command));
	      clc[i]->type   = 0; /* initialize command line structure */
	      clc[i]->i_val  = 0;
	      clc[i]->r_val  = 0.;
	      clc[i]->string = (char *) 
		smalloc(MAX_COMMAND_LINE_LENGTH*sizeof(char));
	      for ( j=0; j<MAX_COMMAND_LINE_LENGTH; j++)
		{
		  clc[i]->string[j] = '\0';
		}
#ifdef DEBUG
	      fprintf(stderr, "clc[%d]->string is at 0x%x\n", i, clc[i]->string);
	      fprintf(stderr, "clc[%d]         is at 0x%x\n", i, clc[i]);
#endif
	    }
	}

      strcpy(Input_File, "input");
      strcpy(Echo_Input_File , "echo_input");

      if (argc > 1) translate_command_line(argc, argv, clc, &nclc);
	  	  
	  ECHO("OPEN", Echo_Input_File);
      
	  echo_command_line( argc, argv, Echo_Input_File );
      print_code_version();
      ptmp = legal_notice;
      while ( strcmp(*ptmp, LAST_LEGAL_STRING) != 0 )
	{
	  fprintf(stderr, "%s", *ptmp++);
	}
    }

  /*
   *  Allocate the uniform problem description structure and
   *  the problem description structures on all processors
   */
  error = pd_alloc();
  EH(error, "pd_alloc problem");

#ifdef DEBUG
  fprintf(stderr, "P_%d at barrier after pd_alloc\n", ProcID);
#ifdef PARALLEL
  error = MPI_Barrier(MPI_COMM_WORLD);
#endif
#endif

  log_msg("Allocating mp, gn, ...");

  error = mp_alloc();
  EH(error, "mp_alloc problem");

  error = gn_alloc();
  EH(error, "gn_alloc problem");

  error = ve_alloc();
  EH(error, "ve_alloc problem");

  error = elc_alloc();
  EH(error, "elc_alloc problem");

  error = elc_rs_alloc();
  EH(error, "elc_alloc problem");

  error = cr_alloc();
  EH(error, "cr_alloc problem");

  error = evp_alloc();
  EH(error, "evp_alloc problem");

  error = tran_alloc();
  EH(error, "tran_alloc problem");

  error = eigen_alloc();
  EH(error, "eigen_alloc problem");

  error = cont_alloc();
  EH(error, "cont_alloc problem");

  error = loca_alloc();
  EH(error, "loca_alloc problem");

  error = efv_alloc();
  EH(error, "efv_alloc problem");

#ifdef DEBUG
  fprintf(stderr, "P_%d at barrier before read_input_file()\n", ProcID);
#ifdef PARALLEL
  error = MPI_Barrier(MPI_COMM_WORLD);
#endif
#endif

  /*
   * Read ASCII input file, data files, related exodusII FEM databases.
   */	
  if ( ProcID == 0 )
    {
      log_msg("Reading input file ...");
      read_input_file(clc, nclc); /* Read ascii input file get file names */

      /* update inputed data to account for command line arguments that
       * might override the input deck...
       */
      log_msg("Overriding any input file specs w/ any command line specs...");
      if (argc > 1) apply_command_line(clc, nclc);

#ifdef DEBUG
      DPRINTF(stderr, "apply_command_line() is done.\n");
#endif
    }

  /*
   * The user-defined material properties, etc. available to goma users
   * mean that some dynamically allocated data needs to be communicated.
   *
   * To handle this, sizing information from the input file scan is
   * broadcast in stages so that the other processors can allocate space
   * accordingly to hold the data.
   *
   * Note: instead of handpacking a data structure, use MPI derived datatypes
   * to gather and scatter. Pray this is done efficiently. Certainly it costs
   * less from a memory standpoint.
   */

#ifdef PARALLEL

  /*
   *  Make sure the input file was successully processed before moving on
   */
  check_parallel_error("Input file error");


  /*
   * This is some sizing information that helps fit a little bit more
   * onto the ark later on.
   */

#ifdef DEBUG
  fprintf(stderr, "P_%d at barrier before noahs_raven()\n", ProcID);
  error = MPI_Barrier(MPI_COMM_WORLD);
#endif

  noahs_raven();

#ifdef DEBUG
  fprintf(stderr, "P_%d at barrier before MPI_Bcast of Noahs_Raven\n", ProcID);
  error = MPI_Barrier(MPI_COMM_WORLD);
#endif

  MPI_Bcast(MPI_BOTTOM, 1, Noahs_Raven->new_type, 0, MPI_COMM_WORLD);

#ifdef DEBUG
  fprintf(stderr, "P_%d at barrier after Bcast/before raven_landing()\n", 
	  ProcID);
  error = MPI_Barrier(MPI_COMM_WORLD);
#endif  
  /*
   * Get the other processors ready to handle ark data.
   */

  raven_landing();

#ifdef DEBUG
  fprintf(stderr, "P_%d at barrier before noahs_ark()\n", ProcID);
  error = MPI_Barrier(MPI_COMM_WORLD);
#endif
  
  
  /*
   * This is the main body of communicated information, including some
   * whose sizes were determined because of advanced legwork by the raven.
   */

  noahs_ark();
  MPI_Bcast(MPI_BOTTOM, 1, Noahs_Ark->new_type, 0, MPI_COMM_WORLD);

  /*
   * Chemkin was initialized on processor zero during the input file
   * process. Now, distribute it to all processors
   */
#ifdef USE_CHEMKIN
  if (Chemkin_Needed) {
    chemkin_initialize_mp();
  }
#endif 

  /*
   * Once the ark has landed, there are additional things that will need to
   * be sent by dove. Example: BC_Types[]->u-BC arrays.
   *
   */

  ark_landing();

  noahs_dove();
  MPI_Bcast(MPI_BOTTOM, 1, Noahs_Dove->new_type, 0, MPI_COMM_WORLD);


#endif          /* End of ifdef PARALLEL */


  /*
   * We sent the packed line to all processors that contained geometry
   * creation commands.  Now we need to step through it and create
   * geometry as we go (including possibly reading an ACIS .sat file).
   *
   */

  /* Check to see if BRK File option exists and if so check if file exits */
  if (Brk_Flag == 1) {
    check_for_brkfile(Brk_File);
  }
  check_parallel_error("Error encountered in check for brkfile");

  /* Now break the exodus files */
  if (Num_Proc > 1 && ProcID == 0 && Brk_Flag == 1) {
    call_brk();
  }
  check_parallel_error("Error in brking exodus files");
  MPI_Barrier(MPI_COMM_WORLD);

  /*
   * For parallel execution, assume the following variables will be changed
   * to reflect the multiple file aspect of the problem.
   *
   *	FEM file = file.exoII		--> file_3of15.exoII
   *
   *	Output EXODUS II file = out.exoII --> out_3of15.exoII
   *
   */


  /*
   * Allocate space for structures holding the EXODUS II finite element
   * database information and for the Distributed Processing information.
   *
   * These are mostly skeletons with pointers that get allocated in the
   * rd_exoII and rd_dpi routines. Remember to free up those arrays first
   * before freeing the major pointers.
   */

  EXO_ptr = alloc_struct_1(Exo_DB, 1);
  init_exo_struct(EXO_ptr);
  DPI_ptr = alloc_struct_1(Dpi, 1);
  init_dpi_struct(DPI_ptr);  

  log_msg("Reading mesh from EXODUS II file...");
  error = read_mesh_exoII(EXO_ptr, DPI_ptr);

  /*
   *   Missing files on any processor are detected at a lower level
   *   forcing a return to the higher level
   *         rd_exo -->  rd_mesh  -->  main
   *   Shutdown now, if any of the exodus files weren't found
   */
  if (error < 0) {
#ifdef PARALLEL
    MPI_Finalize();
#endif
    return(-1);
  }

  /*
   * All of the MPI_Type_commit() calls called behind the scenes that build
   * the dove, ark and raven really allocated memory. Let's free it up now that
   * the initial information has been communicated.
   */

#ifdef PARALLEL
  MPI_Type_free(&(Noahs_Raven->new_type));
  MPI_Type_free(&(Noahs_Ark->new_type));
  MPI_Type_free(&(Noahs_Dove->new_type));
#endif   

  /*
   * Setup the rest of the Problem Description structure that depends on
   * the mesh that was read in from the EXODUS II file...
   * 
   * Note that memory allocation and some setup has already been performed
   * in mm_input()...
   */

  error = setup_pd();
  EH( error, "Problem setting up Problem_Description.");
  /*
   * Let's check to see if we need the large elasto-plastic global tensors
   * and allocate them if so 
   */
  error = evp_tensor_alloc(EXO_ptr);
  EH( error, "Problems setting up evp tensors");
  
  /*
   * Now that we know about what kind of problem we're solving and the
   * mesh information, let's allocate space for elemental assembly structures
   *
   */
#ifdef DEBUG
  DPRINTF(stderr, "About to assembly_alloc()...\n");
#endif
  log_msg("Assembly allocation...");

  error = assembly_alloc(EXO_ptr);
  EH( error, "Problem from assembly_alloc");

  if (Debug_Flag)  {
    DPRINTF(stderr, "%s:  setting up EXODUS II output files...\n", yo);
  }

  /*
   * These are not critical - just niceties. Also, they should not overburden
   * your db with too much of this - they're capped verbiage compliant routines.
   */

  add_qa_stamp(EXO_ptr);

  add_info_stamp(EXO_ptr);

#ifdef DEBUG
  fprintf(stderr, "added qa and info stamps\n");
#endif

  /*
   * If the output EXODUS II database file is different from the input
   * file, then we'll need to replicate all the basic mesh information.
   * But, remember that if we're parallel, that the output file names must
   * be multiplexed first...
   */
  if ( Num_Proc > 1 )
    {
      multiname(ExoFileOut,     ProcID, Num_Proc);      
      multiname(Init_GuessFile, ProcID, Num_Proc);

      if ( strcmp( Soln_OutFile, "" ) != 0 )
	{
	  multiname(Soln_OutFile, ProcID, Num_Proc);
	}

      if( strcmp( ExoAuxFile, "" ) != 0 )
        {
          multiname(ExoAuxFile, ProcID, Num_Proc);
        }

      if( efv->Num_external_field != 0 )
        {
          for( i=0; i<efv->Num_external_field; i++ )
            {
              multiname(efv->file_nm[i], ProcID, Num_Proc);
            }
        }
    }


  /***********************************************************************/
  /***********************************************************************/
  /***********************************************************************/
  /*
   *   Preprocess the exodus mesh
   *        -> Allocate pointers to structures containing element
   *           side bc info, First_Elem_Side_BC_Array, and
   *           element edge info, First_Elem_Edge_BC_Array.
   *        -> Determine Unique_Element_Types[] array
   */
#ifdef DEBUG
  fprintf(stderr, "pre_process()...\n");
#endif
  log_msg("Pre processing of mesh...");
#ifdef PARALLEL
  error = MPI_Barrier(MPI_COMM_WORLD);
#endif
  pre_process(EXO_ptr);

  /***********************************************************************/
  /***********************************************************************/
  /***********************************************************************/
  /*
   * Load up a few key indeces in the bfd prototype basis function structures
   * and make sure that each active eqn/vbl has a bf[v] that points to the
   * right bfd[]...needs pre_process to find out the number of unique
   * element types in the problem.
   */

#ifdef DEBUG
  fprintf(stderr, "bf_init()...\n");
#endif
  log_msg("Basis function initialization...");
  error = bf_init(EXO_ptr);
  EH( error, "Problem from bf_init");

  /*
   * check for parallel errors before continuing
   */
  check_parallel_error("Error encountered in problem setup");

  /***********************************************************************/
  /***********************************************************************/
  /***********************************************************************/  
  /*
   * Allocate space for each communication exchange description.
   */
#ifdef PARALLEL
#ifdef DEBUG
  fprintf(stderr, "P_%d: Parallel cx allocation\n", ProcID);
#endif
  if (DPI_ptr->num_neighbors > 0) {
    cx = alloc_struct_1(Comm_Ex, DPI_ptr->num_neighbors);
    Request = alloc_struct_1(MPI_Request, 
			     Num_Requests * DPI_ptr->num_neighbors);
    Status = alloc_struct_1(MPI_Status, 
			    Num_Requests * DPI_ptr->num_neighbors);
  }
#endif

  /***********************************************************************/
  /***********************************************************************/
  /***********************************************************************/
  /*
   *                           SET UP THE PROBLEM
   *
   * Setup node-based structures
   * Finalise how boundary conditions are to be handled
   * Determine what unknowns are at each owned node and then tell
   *  neighboring processors about your nodes
   * Set up communications pattern for fast unknown updates between
   *  processors.
   */
  (void) setup_problem(EXO_ptr, DPI_ptr);

  /*
   * check for parallel errors before continuing
   */
  check_parallel_error("Error encountered in problem setup");

  /***********************************************************************/
  /***********************************************************************/
  /***********************************************************************/
  /*
   *               CREATE BRK_FILE IF ONE DOES NOT EXIST
   *
   * If no Brk_File exists but the option was configured in the input or
   * optional command we create one now and exit from goma.
   */
  if ( Brk_Flag == 2 ) {
    write_brk_file(Brk_File, EXO_ptr);
    exit(0);
  }
  
  /***********************************************************************/
  /***********************************************************************/
  /***********************************************************************/
  /*
   *                     WRITE OUT INITIAL INFO TO EXODUS FILE
   */

  /*
   *  Only have to initialize the exodus file if we are using different
   *  files for the output versus the input mesh
   */
  if (strcmp(ExoFile, ExoFileOut)) {
    /*
     * Temporarily we'll need to renumber the nodes and elements in the
     * mesh to be 1-based. After writing, return to the 0 based indexing
     * that is more convenient in C.
     */
#ifdef DEBUG
    fprintf(stderr, "1-base; wr_mesh; 0-base\n");
#endif
    one_base(EXO_ptr);
    wr_mesh_exo(EXO_ptr, ExoFileOut, 0);
    zero_base(EXO_ptr);

    /*
     * If running on a distributed computer, augment the plain finite
     * element information of EXODUS with the description of how this
     * piece fits into the global problem.
     */
    if (Num_Proc > 1) {
#ifdef PARALLEL
#ifdef DEBUG
      fprintf(stderr, "P_%d at barrier before wr_dpi()\n", ProcID);
      fprintf(stderr, "P_%d ExoFileOut = \"%s\"\n", ProcID, ExoFileOut);
      error = MPI_Barrier(MPI_COMM_WORLD);
#endif
#endif
      wr_dpi(DPI_ptr, ExoFileOut, 0);
    }
  }

  /***********************************************************************/
  /***********************************************************************/
  /***********************************************************************/
  /*
   *                           SOLVE THE PROBLEM
   */

  if (Debug_Flag) {
    switch (Continuation) {
    case ALC_ZEROTH:
        P0PRINTF("%s: continue_problem (zeroth order) ...\n", yo);
        break;
    case  ALC_FIRST:
        P0PRINTF("%s: continue_problem (first order) ...\n", yo);
        break;
    case HUN_ZEROTH:
        P0PRINTF("%s: hunt_problem (zeroth order) ...\n", yo);
        break;
    case  HUN_FIRST:
        P0PRINTF("%s: hunt_problem (first order) ...\n", yo);
        break;
    case LOCA:
        P0PRINTF("%s: do_loca ...\n", yo);
        break;
    default:
        P0PRINTF("%s: solve_problem...\n", yo);
        break;
    }
  }  
#ifdef DEBUG
  switch (Continuation) {
  case ALC_ZEROTH:
      DPRINTF(stderr, "%s: continue_problem (zeroth order) ...\n", yo);
      break;
  case  ALC_FIRST:
      DPRINTF(stderr, "%s: continue_problem (first order) ...\n", yo);
      break;
  case HUN_ZEROTH:
      DPRINTF(stderr, "%s: hunt_problem (zeroth order) ...\n", yo);
      break;
  case  HUN_FIRST:
      DPRINTF(stderr, "%s: hunt_problem (first order) ...\n", yo);
      break;
  case LOCA:
      DPRINTF(stderr, "%s: do_loca ...\n", yo);
      break;
  default:
      DPRINTF(stderr, "%s: solve_problem...\n", yo);
      break;
  }
#endif

    
  if( TimeIntegration == TRANSIENT)
        {
        Continuation = ALC_NONE;
        if (Debug_Flag) {
          P0PRINTF("%s: solve_problem...TRANSIENT superceded Continuation...\n", yo);
          }
#ifdef DEBUG
   DPRINTF(stderr, "%s: solve_problem...TRANSIENT superceded Continuation...\n", yo);
#endif
        solve_problem(EXO_ptr, DPI_ptr, NULL);
        }  

  switch (Continuation) {
  case ALC_ZEROTH:
  case ALC_FIRST:
    log_msg("Solving continuation problem");
    continue_problem(cx, EXO_ptr, DPI_ptr);
    break;
  case HUN_ZEROTH:
  case HUN_FIRST:
    log_msg("Solving hunt problem");
    hunt_problem(cx, EXO_ptr, DPI_ptr);
    break;
  case LOCA:
    log_msg("Solving continuation problem with LOCA");
    error = do_loca(cx, EXO_ptr, DPI_ptr);
    break;
  default:
    log_msg("Solving problem");
    if (loca_in->Cont_Alg == LOCA_LSA_ONLY)
      {
        error = do_loca(cx, EXO_ptr, DPI_ptr);
      }
    else if(TimeIntegration != TRANSIENT)
      {
        solve_problem(EXO_ptr, DPI_ptr, NULL);
      }
    break;
  }

#ifdef PARALLEL
   MPI_Barrier(MPI_COMM_WORLD);
#endif

  if (ProcID == 0 && Brk_Flag == 1 && Num_Proc > 1) {
    fix_output();
  }
  
  /***********************************************************************/
  /***********************************************************************/
  /***********************************************************************/
  /*
   *  PRINT A MESSAGE TO STDOUT SAYING WE ARE DONE
   */
  P0PRINTF("\n-done\n\n");

  /***********************************************************************/
  /***********************************************************************/
  /***********************************************************************/
  /*
   *       FREE MEMORY ALLOCATED BY THE PROGRAM
   */
  /*
   * free the element block / element based structures
   */
  free_element_blocks(EXO_ptr);

  /*
   * free nodal based structures
   */
  free_nodes();
#ifdef FREE_PROBLEM
  free_problem ( EXO_ptr, DPI_ptr );
#endif

  /*
   * Free command line stuff
   */
  if ( ProcID == 0 )
    {
      if ( argc > 1 ) 
	{
	  for (i=0; i<argc; i++)
	    {
#ifdef DEBUG
	      fprintf(stderr, "clc[%d]->string &= 0x%x\n", i, clc[i]->string);
	      fprintf(stderr, "clc[%d]         &= 0x%x\n", i, clc[i]);
#endif
	      safer_free((void **) &(clc[i]->string));
	      safer_free((void **) (clc + i));
	    }
	  safer_free((void **) &clc);
	}
    }

  /*
   * Free exodus database structures
   */
  free_exo(EXO_ptr);
  safer_free((void **) &EXO_ptr);

  if ( Num_Proc > 1 )
  {
    free_dpi(DPI_ptr);
  }
  else
  {
    free_dpi_uni(DPI_ptr);
  }

  safer_free((void **) &DPI_ptr);

  /*
   * Remove front scratch file [/tmp/lu.'pid'.0]
   */
  if (Linear_Solver == FRONT) 	
    {
  unlerr = unlink(front_scratch_directory);
  WH(unlerr, "Unlink problem with front scratch file");
    }


#ifdef PARALLEL
  total_time = ( MPI_Wtime() - time_start )/ 60. ;
  DPRINTF(stderr, "\nProc 0 runtime: %10.2f Minutes.\n\n",total_time);
  MPI_Finalize();
#endif  
#ifndef PARALLEL
  (void)time(&now);
  total_time = (double)(now) - time_start;
  fprintf(stderr, "\nProc 0 runtime: %10.2f Minutes.\n\n",total_time/60);
#endif  
  fflush(stdout);
  fflush(stderr);
  log_msg("GOMA ends normally.");
  return (0);
}
예제 #26
0
파일: jas_main.c 프로젝트: rbarraud/goma
int
goma_init_(dbl *time1, int *nnodes, int *nelems,
           int *nnv_in, int *nev_in, int *i_soln, int *i_post)
     
     /*
      * Initial main driver for GOMA. Derived from a (1/93) release of
      * the rf_salsa program by
      *        
      *        Original Authors: John  Shadid (1421)
      *		                 Scott Hutchinson (1421)
      *        		         Harry Moffat (1421)
      *       
      *        Date:		12/3/92
      * 
      *
      *        Updates and Changes by:
      *                           Randy Schunk (9111)
      *                           P. A. Sackinger (9111)
      *                           R. R. Rao       (9111)
      *                           R. A. Cairncross (Univ. of Delaware)
      *        Dates:           2/93 - 6/96
      *
      *       Modified for continuation
      *                           Ian Gates
      *       Dates:            2/98 - 10/98
      *       Dates:            7/99 - 8/99
      * 
      * Last modified: Wed  June 26 14:21:35 MST 1994 [email protected]
      * Hello.
      * 
      * Note: Many modifications from an early 2/93 pre-release
      *	      version of rf_salsa were made by various persons 
      *       in order to test ideas about moving/deforming meshes...
      */ 
{
  /* Local Declarations */

  double time_start, total_time;   /* timing variables */
#ifndef PARALLEL
  struct tm *tm_ptr;               /* additional serial timing variables */
  time_t the_time;
#endif

  int error;
  int i;
  int j;
  static int first_goma_call=TRUE;

  char	**ptmp;
  static const char *yo="goma_init";

  struct Command_line_command **clc=NULL; /* point to command line structure */
  int           nclc = 0;		/* number of command line commands */

/********************** BEGIN EXECUTION ***************************************/
  
/* assume number of commands is less than or equal to the number of 
 * arguments in the command line minus 1 (1st is program name) */

  /*
  *  Get the name of the executable, yo
  */

#ifdef PARALLEL
if( first_goma_call ) {
	Argc = 1;
	Argv = (char **) smalloc( Argc*sizeof(char *) );
	Argv[0] = (char *) yo;
	MPI_Init(&Argc, &Argv);  /*PRS will have to fix this.  Too late TAB already did. */
  }
  time_start = MPI_Wtime();
#else /* PARALLEL */
  (void) time(&the_time);
  tm_ptr = gmtime(&the_time);
  time_start = (double)  ( tm_ptr->tm_sec
               + 60. * (   60. * ( tm_ptr->tm_yday * 24. + tm_ptr->tm_hour )
                                                         + tm_ptr->tm_min  )
                         );
#endif /* PARALLEL */
  *time1 = time_start;

/*   Argv = argv; */

/*   Argc = argc; */

  time_goma_started = time_start;

#ifdef PARALLEL
  /*
   * Determine the parallel processing status, if any. We need to know
   * pretty early if we're "one of many" or the only process.
   */

  error = MPI_Comm_size(MPI_COMM_WORLD, &Num_Proc);
  error = MPI_Comm_rank(MPI_COMM_WORLD, &ProcID);

  /*
   * Setup a default Proc_config so we can use utility routines 
   * from Aztec
   */

  AZ_set_proc_config(Proc_Config, MPI_COMM_WORLD);

  /* set the output limit flag if need be */

  if( Num_Proc > DP_PROC_PRINT_LIMIT ) Unlimited_Output = FALSE;

#ifdef HAVE_MPE_H
  error = MPE_Init_log();
#endif /* HAVE_MPE_H */

  Dim = 0;			/* for any hypercube legacy code...  */

#endif /* PARALLEL */
  
#ifndef PARALLEL
  Dim        = 0;
  ProcID     = 0;
  Num_Proc   = 1;
#endif /* PARALLEL */


  /*
  *   HKM - Change the ieee exception handling based on the machine and
  *         the level of debugging/speed desired. This call currently causes
  *         core dumps for floating point exceptions.
  */

  handle_ieee();
  
  log_msg("--------------");
  log_msg("GOMA begins...");

#ifdef USE_CGM
  cgm_initialize();
#endif
  /*
   * Some initial stuff that only the master process does.
   */

/*PRS: Disable this command line stuff for the jas coupled version */
/*-----------------------------------------------------------------*/
/*   if ( ProcID == 0 ) */
/*     { */
/*       if (argc > 1) */
/* 	{ */
/* 	  log_msg("Preprocessing command line options."); */
/* 	  clc = (struct Command_line_command **)  */
/* 	    smalloc( argc * sizeof(struct Command_line_command *)); */
/* 	  for (i=0; i<argc; i++) */
/* 	    { */
/* 	      clc[i] = (struct Command_line_command *)  */
/* 		smalloc(sizeof(struct Command_line_command)); */
/* 	      clc[i]->type   = 0; /\* initialize command line structure *\/ */
/* 	      clc[i]->i_val  = 0; */
/* 	      clc[i]->r_val  = 0.; */
/* 	      clc[i]->string = (char *)  */
/* 		smalloc(MAX_COMMAND_LINE_LENGTH*sizeof(char)); */
/* 	      for ( j=0; j<MAX_COMMAND_LINE_LENGTH; j++) */
/* 		{ */
/* 		  clc[i]->string[j] = '\0'; */
/* 		} */
/* #ifdef DEBUG */
/* 	      fprintf(stderr, "clc[%d]->string is at 0x%x\n", i, clc[i]->string); */
/* 	      fprintf(stderr, "clc[%d]         is at 0x%x\n", i, clc[i]); */
/* #endif */
/* 	    } */
/* 	} */

/* PRS For the JAS version we will use the default input file name "input" */
      strcpy(Input_File, "input");

/* if (argc > 1) translate_command_line(argc, argv, clc, &nclc); */
      
/*       print_code_version(); */
/*       ptmp = legal_notice; */
/*       while ( strcmp(*ptmp, LAST_LEGAL_STRING) != 0 ) */
/* 	{ */
/* 	  fprintf(stderr, "%s", *ptmp++); */
/* 	} */
/* } */

  /*
   *  Allocate the uniform problem description structure and
   *  the problem description structures on all processors
   */
  error = pd_alloc();
  EH(error, "pd_alloc problem");

#ifdef DEBUG
  fprintf(stderr, "P_%d at barrier after pd_alloc\n", ProcID);
#ifdef PARALLEL
  error = MPI_Barrier(MPI_COMM_WORLD);
#endif
#endif

  log_msg("Allocating mp, gn, ...");

  error = mp_alloc();
  EH(error, "mp_alloc problem");

  error = gn_alloc();
  EH(error, "gn_alloc problem");

  error = ve_alloc();
  EH(error, "ve_alloc problem");

  error = elc_alloc();
  EH(error, "elc_alloc problem");

  error = elc_rs_alloc();
  EH(error, "elc_alloc problem");

  error = cr_alloc();
  EH(error, "cr_alloc problem");

  error = evp_alloc();
  EH(error, "evp_alloc problem");

  error = tran_alloc();
  EH(error, "tran_alloc problem");

  error = libio_alloc();
  EH(error, "libio_alloc problem");

  error = eigen_alloc();
  EH(error, "eigen_alloc problem");

  error = cont_alloc();
  EH(error, "cont_alloc problem");

  error = loca_alloc();
  EH(error, "loca_alloc problem");

  error = efv_alloc();
  EH(error, "efv_alloc problem");

#ifdef DEBUG
  fprintf(stderr, "P_%d at barrier before read_input_file()\n", ProcID);
#ifdef PARALLEL
  error = MPI_Barrier(MPI_COMM_WORLD);
#endif
#endif

/*PRS AGAIN, NO COMMAND LINE OVERRIDES IN THIS JAS3D VERSION */
  /*
   * Read ASCII input file, data files, related exodusII FEM databases.
   */	
   if ( ProcID == 0 ) 
       { 
         log_msg("Reading input file ..."); 
         read_input_file(clc, nclc); 

       }

  /*
   * The user-defined material properties, etc. available to goma users
   * mean that some dynamically allocated data needs to be communicated.
   *
   * To handle this, sizing information from the input file scan is
   * broadcast in stages so that the other processors can allocate space
   * accordingly to hold the data.
   *
   * Note: instead of handpacking a data structure, use MPI derived datatypes
   * to gather and scatter. Pray this is done efficiently. Certainly it costs
   * less from a memory standpoint.
   */

#ifdef PARALLEL

  /*
   *  Make sure the input file was successully processed before moving on
   */
  check_parallel_error("Input file error");


  /*
   * This is some sizing information that helps fit a little bit more
   * onto the ark later on.
   */

#ifdef DEBUG
  fprintf(stderr, "P_%d at barrier before noahs_raven()\n", ProcID);
  error = MPI_Barrier(MPI_COMM_WORLD);
#endif

  noahs_raven();

#ifdef DEBUG
  fprintf(stderr, "P_%d at barrier before MPI_Bcast of Noahs_Raven\n", ProcID);
  error = MPI_Barrier(MPI_COMM_WORLD);
#endif

  MPI_Bcast(MPI_BOTTOM, 1, Noahs_Raven->new_type, 0, MPI_COMM_WORLD);

#ifdef DEBUG
  fprintf(stderr, "P_%d at barrier after Bcast/before raven_landing()\n", 
	  ProcID);
  error = MPI_Barrier(MPI_COMM_WORLD);
#endif  
  /*
   * Get the other processors ready to handle ark data.
   */

  raven_landing();

#ifdef DEBUG
  fprintf(stderr, "P_%d at barrier before noahs_ark()\n", ProcID);
  error = MPI_Barrier(MPI_COMM_WORLD);
#endif
  
  
  /*
   * This is the main body of communicated information, including some
   * whose sizes were determined because of advanced legwork by the raven.
   */

  noahs_ark();
  MPI_Bcast(MPI_BOTTOM, 1, Noahs_Ark->new_type, 0, MPI_COMM_WORLD);

  /*
   * Chemkin was initialized on processor zero during the input file
   * process. Now, distribute it to all processors
   */
#ifdef USE_CHEMKIN
  if (Chemkin_Needed) {
    chemkin_initialize_mp();
  }
#endif 

  /*
   * Once the ark has landed, there are additional things that will need to
   * be sent by dove. Example: BC_Types[]->u-BC arrays.
   *
   */

  ark_landing();

  noahs_dove();
  MPI_Bcast(MPI_BOTTOM, 1, Noahs_Dove->new_type, 0, MPI_COMM_WORLD);


#endif          /* End of ifdef PARALLEL */


  /*
   * We sent the packed line to all processors that contained geometry
   * creation commands.  Now we need to step through it and create
   * geometry as we go (including possibly reading an ACIS .sat file).
   *
   */
#ifdef USE_CGM
  create_cgm_geometry();
#endif

  /*
   * For parallel execution, assume the following variables will be changed
   * to reflect the multiple file aspect of the problem.
   *
   *	FEM file = file.exoII		--> file_3of15.exoII
   *
   *	Output EXODUS II file = out.exoII --> out_3of15.exoII
   *
   */


  /*
   * Allocate space for structures holding the EXODUS II finite element
   * database information and for the Distributed Processing information.
   *
   * These are mostly skeletons with pointers that get allocated in the
   * rd_exoII and rd_dpi routines. Remember to free up those arrays first
   * before freeing the major pointers.
   */

  EXO_ptr = alloc_struct_1(Exo_DB, 1);
  init_exo_struct(EXO_ptr);
  DPI_ptr = alloc_struct_1(Dpi, 1);
  init_dpi_struct(DPI_ptr);  

  log_msg("Reading mesh from EXODUS II file...");
  error = read_mesh_exoII(EXO_ptr, DPI_ptr);

  /*
   *   Missing files on any processor are detected at a lower level
   *   forcing a return to the higher level
   *         rd_exo -->  rd_mesh  -->  main
   *   Shutdown now, if any of the exodus files weren't found
   */
  if (error < 0) {
#ifdef PARALLEL
    MPI_Finalize();
#endif
    return(-1);
  }

  /*
   * All of the MPI_Type_commit() calls called behind the scenes that build
   * the dove, ark and raven really allocated memory. Let's free it up now that
   * the initial information has been communicated.
   */

#ifdef PARALLEL
  MPI_Type_free(&(Noahs_Raven->new_type));
  MPI_Type_free(&(Noahs_Ark->new_type));
  MPI_Type_free(&(Noahs_Dove->new_type));
#endif   

  /*
   * Setup the rest of the Problem Description structure that depends on
   * the mesh that was read in from the EXODUS II file...
   * 
   * Note that memory allocation and some setup has already been performed
   * in mm_input()...
   */

  error = setup_pd();
  EH( error, "Problem setting up Problem_Description.");
  /*
   * Let's check to see if we need the large elasto-plastic global tensors
   * and allocate them if so 
   */
  error = evp_tensor_alloc(EXO_ptr);
  EH( error, "Problems setting up evp tensors");
  
  /*
   * Now that we know about what kind of problem we're solving and the
   * mesh information, let's allocate space for elemental assembly structures
   *
   */
#ifdef DEBUG
  DPRINTF(stderr, "About to assembly_alloc()...\n");
#endif
  log_msg("Assembly allocation...");

  error = assembly_alloc(EXO_ptr);
  EH( error, "Problem from assembly_alloc");

  if (Debug_Flag)  {
    DPRINTF(stderr, "%s:  setting up EXODUS II output files...\n", yo);
  }

  /*
   * These are not critical - just niceties. Also, they should not overburden
   * your db with too much of this - they're capped verbiage compliant routines.
   */

  add_qa_stamp(EXO_ptr);

  add_info_stamp(EXO_ptr);

#ifdef DEBUG
  fprintf(stderr, "added qa and info stamps\n");
#endif

  /*
   * If the output EXODUS II database file is different from the input
   * file, then we'll need to replicate all the basic mesh information.
   * But, remember that if we're parallel, that the output file names must
   * be multiplexed first...
   */
  if ( Num_Proc > 1 )
    {
      multiname(ExoFileOut,     ProcID, Num_Proc);      
      multiname(Init_GuessFile, ProcID, Num_Proc);

      if ( strcmp( Soln_OutFile, "" ) != 0 )
	{
	  multiname(Soln_OutFile,   ProcID, Num_Proc);
	}

      if( strcmp( ExoAuxFile, "" ) != 0 )
        {
          multiname(ExoAuxFile,     ProcID, Num_Proc);
        }

      if( efv->Num_external_field != 0 )
        {
          for( i=0; i<efv->Num_external_field; i++ )
            {
              multiname(efv->file_nm[i], ProcID, Num_Proc);
            }
        }

    }



  /***********************************************************************/
  /***********************************************************************/
  /***********************************************************************/
  /*
   *   Preprocess the exodus mesh
   *        -> Allocate pointers to structures containing element
   *           side bc info, First_Elem_Side_BC_Array, and
   *           element edge info, First_Elem_Edge_BC_Array.
   *        -> Determine Unique_Element_Types[] array
   */
#ifdef DEBUG
  fprintf(stderr, "pre_process()...\n");
#endif
  log_msg("Pre processing of mesh...");
#ifdef PARALLEL
  error = MPI_Barrier(MPI_COMM_WORLD);
#endif
  pre_process(EXO_ptr);

  /***********************************************************************/
  /***********************************************************************/
  /***********************************************************************/
  /*
   * Load up a few key indeces in the bfd prototype basis function structures
   * and make sure that each active eqn/vbl has a bf[v] that points to the
   * right bfd[]...needs pre_process to find out the number of unique
   * element types in the problem.
   */

#ifdef DEBUG
  fprintf(stderr, "bf_init()...\n");
#endif
  log_msg("Basis function initialization...");
  error = bf_init(EXO_ptr);
  EH( error, "Problem from bf_init");

  /*
   * check for parallel errors before continuing
   */
  check_parallel_error("Error encountered in problem setup");

  /***********************************************************************/
  /***********************************************************************/
  /***********************************************************************/  
  /*
   * Allocate space for each communication exchange description.
   */
#ifdef PARALLEL
#ifdef DEBUG
  fprintf(stderr, "P_%d: Parallel cx allocation\n", ProcID);
#endif
  if (DPI_ptr->num_neighbors > 0) {
    cx = alloc_struct_1(Comm_Ex, DPI_ptr->num_neighbors);
    Request = alloc_struct_1(MPI_Request, 
			     Num_Requests * DPI_ptr->num_neighbors);
    Status = alloc_struct_1(MPI_Status, 
			    Num_Requests * DPI_ptr->num_neighbors);
  }
#endif

  /***********************************************************************/
  /***********************************************************************/
  /***********************************************************************/
  /*
   *                           SET UP THE PROBLEM
   *
   * Setup node-based structures
   * Finalise how boundary conditions are to be handled
   * Determine what unknowns are at each owned node and then tell
   *  neighboring processors about your nodes
   * Set up communications pattern for fast unknown updates between
   *  processors.
   */
  (void) setup_problem(EXO_ptr, DPI_ptr);

  /*
   * check for parallel errors before continuing
   */
  check_parallel_error("Error encountered in problem setup");
  
  /***********************************************************************/
  /***********************************************************************/
  /***********************************************************************/
  /*
   *                     WRITE OUT INITIAL INFO TO EXODUS FILE
   */

  /*
   *  Only have to initialize the exodus file if we are using different
   *  files for the output versus the input mesh
   */
  if (strcmp(ExoFile, ExoFileOut)) {
    /*
     * Temporarily we'll need to renumber the nodes and elements in the
     * mesh to be 1-based. After writing, return to the 0 based indexing
     * that is more convenient in C.
     */
#ifdef DEBUG
    fprintf(stderr, "1-base; wr_mesh; 0-base\n");
#endif
    one_base(EXO_ptr);
    wr_mesh_exo(EXO_ptr, ExoFileOut, 0);
    zero_base(EXO_ptr);

    /*
     * If running on a distributed computer, augment the plain finite
     * element information of EXODUS with the description of how this
     * piece fits into the global problem.
     */
    if (Num_Proc > 1) {
#ifdef PARALLEL
#ifdef DEBUG
      fprintf(stderr, "P_%d at barrier before wr_dpi()\n", ProcID);
      fprintf(stderr, "P_%d ExoFileOut = \"%s\"\n", ProcID, ExoFileOut);
      error = MPI_Barrier(MPI_COMM_WORLD);
#endif
#endif
      wr_dpi(DPI_ptr, ExoFileOut, 0);
    }
  }

  if (Num_Import_NV > 0 || Num_Import_EV > 0) printf
    (" Goma will import %d nodal and %d element variables.\n",
     Num_Import_NV, Num_Import_EV);
  if (Num_Export_XS > 0 || Num_Export_XP > 0) printf
    (" Goma will export %d solution and %d post-processing variables.\n",
     Num_Export_XS, Num_Export_XP);

  /* Return counts to calling program */
  *nnodes = EXO_ptr->num_nodes;
  *nelems = EXO_ptr->num_elems;
  *nnv_in = Num_Import_NV;
  *nev_in = Num_Import_EV;
  *i_soln = Num_Export_XS;
  *i_post = Num_Export_XP;

  return (0); /* Back to  animas*/
}
예제 #27
0
static int tview_func(uint32_t tid, uint32_t pos, int n, const bam_pileup1_t *pl, void *data)
{
	bam_lplbuf_t *tv = (bam_lplbuf_t*)data;
	freenode_t *p;
	int i, l, max_level;
	// allocate memory if necessary
	if (tv->max < n) { // enlarge
		tv->max = n;
		kroundup32(tv->max);
		tv->cur_level = (int*)realloc(tv->cur_level, sizeof(int) * tv->max);
		tv->pre_level = (int*)realloc(tv->pre_level, sizeof(int) * tv->max);
	}
	tv->n_cur = n;
	// update cnt
	for (p = tv->head; p->next; p = p->next)
		if (p->cnt > 0) --p->cnt;
	// calculate cur_level[]
	max_level = 0;
	for (i = l = 0; i < n; ++i) {
		const bam_pileup1_t *p = pl + i;
		if (p->is_head) {
			if (tv->head->next && tv->head->cnt == 0) { // then take a free slot
				freenode_t *p = tv->head->next;
				tv->cur_level[i] = tv->head->level;
				mp_free(tv->mp, tv->head);
				tv->head = p;
				--tv->n_nodes;
			} else tv->cur_level[i] = ++tv->max_level;
		} else {
			tv->cur_level[i] = tv->pre_level[l++];
			if (p->is_tail) { // then return a free slot
				tv->tail->level = tv->cur_level[i];
				tv->tail->next = mp_alloc(tv->mp);
				tv->tail = tv->tail->next;
				++tv->n_nodes;
			}
		}
		if (tv->cur_level[i] > max_level) max_level = tv->cur_level[i];
		((bam_pileup1_t*)p)->level = tv->cur_level[i];
	}
	assert(l == tv->n_pre);
	tv->func(tid, pos, n, pl, tv->user_data);
	// sort the linked list
	if (tv->n_nodes) {
		freenode_t *q;
		if (tv->n_nodes + 1 > tv->m_aux) { // enlarge
			tv->m_aux = tv->n_nodes + 1;
			kroundup32(tv->m_aux);
			tv->aux = (freenode_t**)realloc(tv->aux, sizeof(void*) * tv->m_aux);
		}
		for (p = tv->head, i = l = 0; p->next;) {
			if (p->level > max_level) { // then discard this entry
				q = p->next;
				mp_free(tv->mp, p);
				p = q;
			} else {
				tv->aux[i++] = p;
				p = p->next;
			}
		}
		tv->aux[i] = tv->tail; // add a proper tail for the loop below
		tv->n_nodes = i;
		if (tv->n_nodes) {
			ks_introsort(node, tv->n_nodes, tv->aux);
			for (i = 0; i < tv->n_nodes; ++i) tv->aux[i]->next = tv->aux[i+1];
			tv->head = tv->aux[0];
		} else tv->head = tv->tail;
	}
	// clean up
	tv->max_level = max_level;
	memcpy(tv->pre_level, tv->cur_level, tv->n_cur * 4);
	// squeeze out terminated levels
	for (i = l = 0; i < n; ++i) {
		const bam_pileup1_t *p = pl + i;
		if (!p->is_tail)
			tv->pre_level[l++] = tv->pre_level[i];
	}
	tv->n_pre = l;
/*
	fprintf(stderr, "%d\t", pos+1);
	for (i = 0; i < n; ++i) {
		const bam_pileup1_t *p = pl + i;
		if (p->is_head) fprintf(stderr, "^");
		if (p->is_tail) fprintf(stderr, "$");
		fprintf(stderr, "%d,", p->level);
	}
	fprintf(stderr, "\n");
*/
	return 0;
}
예제 #28
0
int main() {

    puts("Master");
    corethread_t worker_1 = 1; // For now the core ID
    int worker_1_param = 1;

    corethread_create(&worker_1,&func_worker_1,(void*)&worker_1_param);

    // Create the queuing ports
    spd_t * chan = mp_create_sport(MP_CHAN_1_ID, SINK, MP_CHAN_1_MSG_SIZE);

    volatile unsigned long long _SPM * time_sample = mp_alloc(MP_CHAN_1_MSG_SIZE);

    if (chan == NULL || time_sample == NULL) {
        DEBUGF(chan);
        abort();
    }

    // Initialize the communication channels
    int retval = mp_init_ports();
    // TODO: check on retval

    puts("Initialized ports");

    while(slave != 1) {
        ;
    }

    puts("Slave is ready");

    unsigned long long min_time_diff = -1;
    unsigned long long max_time_diff = 0;
    unsigned long long accum_time_diff = 0;
    unsigned long long cnt_time_diff = 0;
    unsigned long long percent = 0;
    int done = 0;
    unsigned long long start = get_cpu_usecs();
    while(!done) {
        int success = mp_read(chan,time_sample);
        unsigned long long time_diff = get_cpu_usecs() - (*time_sample);
        if (success == 0) {
            printf("No sample received\n");
        } else if ((*time_sample) == 0) {
            printf("Received empty sample, newest: %u, sample size: %u\n",chan->newest,chan->sample_size);
        } else {
            if (time_diff > 2000 ) {
                // Time difference is larger than a micro second
                printf("Time sample: %llu\tdiff: %llu\n",*time_sample,time_diff);
            }
            cnt_time_diff++;
            if (time_diff < min_time_diff) {
                min_time_diff = time_diff;
            }
            if (time_diff > max_time_diff) {
                max_time_diff = time_diff;
            }
            accum_time_diff += time_diff;
        }

        if (start + percent < get_cpu_usecs()) {
            percent += RUNTIME/10;
            printf("+");
            fflush(stdout);
        }
        if ( start + RUNTIME < get_cpu_usecs())  {
            done = 1;
        }
    }
    printf("\n");

    printf("Status:\n\tMin time diff: %llu\n\tMax time diff: %llu\n\tAvg time diff: %llu\n", min_time_diff,max_time_diff,accum_time_diff/cnt_time_diff);

    int* res;
    corethread_join(worker_1,&res);

    return *res;
}
예제 #29
0
int main() {
  
  corethread_t worker_1 = SLAVE_CORE; // For now the core ID
     
  corethread_create(&worker_1,&func_worker_1,(void*)&worker_1);
  puts("Corethread created");

  unsigned short int local_phase = 0;
  min_time = ULONG_MAX;
  max_time = 0;
  accum_time = 0;
  cnt_time = 0;

  unsigned long long int start = 0;
  unsigned long long int stop = 0;

  spd_t * sport1 = mp_create_sport(CHAN_ID_ONE,SINK,SAMPLE_SIZE*sizeof(short));
  spd_t * sport2 = mp_create_sport(CHAN_ID_TWO,SOURCE,SAMPLE_SIZE*sizeof(short));
  if (sport1 == NULL || sport2 == NULL) {
    //exit(1);
  }
  volatile short _SPM * sample = mp_alloc(SAMPLE_SIZE*sizeof(short));

  mp_init_ports();

  done = 1;

  int balance = 0;
  for (int i = 0; i < SAMPLE_SIZE; ++i) {
    sample[i] = i;
  }
  for (int i = 0; i < ITERATIONS/2; ++i) {
    mp_write(sport2,sample);
    for (int i = 0; i < SAMPLE_SIZE; ++i) {
      sample[i] = i;
    }
  }

  for (int i = 0; i < ITERATIONS/2; ++i) {
    mp_write(sport2,sample);
    for (int i = 0; i < SAMPLE_SIZE; ++i) {
      sample[SAMPLE_SIZE-1-i] = i;
    }
  }



  for (int i = 0; i < ITERATIONS; ++i) {
    start = get_cpu_usecs();
    int ret = mp_read(sport1,sample);
    stop = get_cpu_usecs();
    if (ret == 0)
    {
      puts("No value written yet.");
    } else {
      unsigned long long int exe_time = stop - start;
      min_time = (exe_time < min_time) ? exe_time : min_time;
      max_time = (exe_time > max_time) ? exe_time : max_time;
      accum_time += exe_time;
      cnt_time++;
      if (sample[0] == 0) {
        balance++;
        for (int i = 0; i < SAMPLE_SIZE; ++i) {
          if(sample[i] != i) {
            printf("Error: sample[%i] = %i\n",i,sample[i]);
            break;
          }
        }
      } else if (sample[0] == SAMPLE_SIZE-1) {
        balance--;
        for (int i = 0; i < SAMPLE_SIZE; ++i) {
          if(sample[SAMPLE_SIZE-1-i] != i) {
            printf("Error: sample[%i] = %i\n",i,sample[i]);
            break;
          }
        }
      } else {
        printf("Wrong sample values sample[0] = %i\n",sample[0]);
      }
    }
  }

  printf("Local phase: %d\n",local_phase);
  
  inval_dcache();

  int* res;
  corethread_join(worker_1,&res);

  printf("Balance: %i\n",balance);
  printf("Min time: %llu\tMax time: %llu\tAccumulated time: %llu\nCount time: %llu\tAverage time: %llu\n", min_time,max_time,accum_time,cnt_time,accum_time/cnt_time);

  puts("Corethread joined");

  return *res;  
}
예제 #30
0
파일: mempool.c 프로젝트: maczpc/csf
inline void *
mp_malloc(size_t size)
{
	return mp_alloc(size);
}