Beispiel #1
0
int        deck_remove_cards(Deck * deck, Card * remove_cards, int n){

        int i;
        int j;
        int card_to_be_removed;

        Card test_card;
        Queue * new_deck = init_q(deck->cards->size, sizeof(Card));
        
        if(new_deck == NULL)
                return -1;

        deck->realign(deck);
        
        for(i=0; i<deck->cards->size; i++){
                test_card = deck->pick_card(deck);
                card_to_be_removed = 0;
                for(j=0; j < n; j++){
                        if(card_comp(&test_card, remove_cards+j)==0){
                                card_to_be_removed = 1;
                                break;
                        }
                }

                if(card_to_be_removed == 0){
                        new_deck->nq(new_deck, &test_card);
                }
                
        }

        deck->cards->destroy(deck->cards);
        deck->cards = new_deck;
        
        return 0;
}
Beispiel #2
0
void __init xmd_ch_init(void)
{
	int i;
	int size = ARRAY_SIZE(hsi_all_channels);

#if MCM_DBG_LOG
	printk("\nmcm: xmd_ch_init++\n");
#endif  
	if (0 != mipi_hsi_mem_init())
		panic("\nmcm: memory initialization failed\n");
    
	spin_lock_init(&mem_lock);
  
	for (i=0; i<size; i++) {
		hsi_channels[i].state = hsi_all_channels[i].state;
		hsi_channels[i].name = hsi_all_channels[i].name;
		hsi_channels[i].write_happening = HSI_FALSE;
		hsi_channels[i].write_queued = HSI_FALSE;
		hsi_channels[i].read_queued = HSI_FALSE;
		hsi_channels[i].read_happening = HSI_FALSE;
		spin_lock_init(&hsi_channels[i].lock);
		init_waitqueue_head(&hsi_channels[i].write_wait);
		init_waitqueue_head(&hsi_channels[i].read_wait);
		init_q(i);
	}
  
	hsi_ll_init(1, hsi_ch_cb);
  
	//Create and initialize work q
	hsi_read_wq = create_workqueue("hsi-read-wq");
	hsi_write_wq = create_workqueue("hsi-write-wq");
}
Beispiel #3
0
void
tw_net_start(void)
{
  if (MPI_Comm_size(MPI_COMM_ROSS, &world_size) != MPI_SUCCESS)
    tw_error(TW_LOC, "Cannot get MPI_Comm_size(MPI_COMM_ROSS)");

  if( g_tw_mynode == 0)
    {
      printf("tw_net_start: Found world size to be %d \n", world_size );
    }

  // Check after tw_nnodes is defined
  if(tw_nnodes() == 1 && g_tw_npe == 1) {
      // force the setting of SEQUENTIAL protocol
      if (g_tw_synchronization_protocol == NO_SYNCH) {
          g_tw_synchronization_protocol = SEQUENTIAL;
      } else if(g_tw_synchronization_protocol == CONSERVATIVE || g_tw_synchronization_protocol == OPTIMISTIC) {
          g_tw_synchronization_protocol = SEQUENTIAL;
          fprintf(stderr, "Warning: Defaulting to Sequential Simulation, not enought PEs defined.\n");
      }
  }

  tw_pe_create(1);
  tw_pe_init(0, g_tw_mynode);

  //If we're in (some variation of) optimistic mode, we need this hash
  if (g_tw_synchronization_protocol == OPTIMISTIC ||
      g_tw_synchronization_protocol == OPTIMISTIC_DEBUG ||
      g_tw_synchronization_protocol == OPTIMISTIC_REALTIME) {
    g_tw_pe[0]->hash_t = tw_hash_create();
  } else {
    g_tw_pe[0]->hash_t = NULL;
  }

  if (send_buffer < 1)
    tw_error(TW_LOC, "network send buffer must be >= 1");
  if (read_buffer < 1)
    tw_error(TW_LOC, "network read buffer must be >= 1");

  init_q(&posted_sends, "MPI send queue");
  init_q(&posted_recvs, "MPI recv queue");

  g_tw_net_device_size = read_buffer;

  // pre-post all the Irecv operations
  recv_begin( g_tw_pe[0] );
}
Beispiel #4
0
void __init xmd_ch_init(void)
{
	int i;
	int size = ARRAY_SIZE(hsi_all_channels);

#if MCM_DBG_LOG
	printk("\nmcm: xmd_ch_init++\n");
#endif

	for (i=0; i<size; i++) {
		hsi_channels[i].state = hsi_all_channels[i].state;
		hsi_channels[i].name = hsi_all_channels[i].name;
		hsi_channels[i].write_happening = HSI_FALSE;
		hsi_channels[i].write_queued = HSI_FALSE;
		hsi_channels[i].read_queued = HSI_FALSE;
		hsi_channels[i].read_happening = HSI_FALSE;
		spin_lock_init(&hsi_channels[i].lock);
		init_waitqueue_head(&hsi_channels[i].write_wait);
		init_waitqueue_head(&hsi_channels[i].read_wait);
		init_q(i);
	}

	hsi_mem_init();

	//                                                  
	/* TI HSI driver (from HSI_DRIVER_VERSION 0.4.2) can suppport port 1 and 2, 
		but IMC XMD currently supports port 1 only */
	hsi_ll_init(XMD_SUPPORT_PORT, hsi_ch_cb);
	//                                                

	/* Create and initialize work q */
	hsi_read_wq = create_workqueue("hsi-read-wq");
	hsi_write_wq = create_workqueue("hsi-write-wq");
#if defined (HSI_LL_ENABLE_RX_BUF_RETRY_WQ)
	hsi_buf_retry_wq = create_workqueue("hsi_buf_retry_wq");
#endif
	INIT_WORK(&XMD_DLP_RECOVERY_wq, xmd_dlp_recovery_wq);

/*                                                                           */
#if 1
    for (i=0; i<size; i++) {
        INIT_WORK(&hsi_channels[i].read_work, hsi_read_work);
        INIT_WORK(&hsi_channels[i].write_work, hsi_write_work);
#if defined (HSI_LL_ENABLE_RX_BUF_RETRY_WQ)
        INIT_WORK(&hsi_channels[i].buf_retry_work, hsi_buf_retry_work);
#endif
    }
#endif
/*                                                                         */


//                                                  
#if defined (ENABLE_RECOVERY_WAKE_LOCK)
	wake_lock_init(&xmd_recovery_wake_lock, WAKE_LOCK_SUSPEND, "xmd-recovery-wake");
#endif
//                                                

	hsi_mcm_state = HSI_MCM_STATE_INITIALIZED;
}
Beispiel #5
0
/* Client will send 3 messages in total and wait to receive 2 messages, then shutsdown. */
int main(int argc, char** argv)
{
     int server_qid;
     int client_pid = getpid(); /* our own pid */
     int key;
     MESSAGE *msg;
     msg = (MESSAGE*) malloc(sizeof(MESSAGE) + MAX_SIZE - 1);

     if(argc != 2)
     {
	  fprintf(stderr, "Usage: %s <key>\n", argv[0]);
	  return 1;
     }
     
     //obtain the server through a common key.
     key = atoi(argv[1]);
     if((server_qid = init_q(key)) == -1)
     {
	  perror("Failed to get Server Message Queue");
	  return 1;
     }

     printf("Client: PID: %i \n", client_pid);
     printf("Client: Connected to Server Queue ID: %i ...\n", server_qid);
     printf("Sending Initial Message to server... \n");
     
     // put a message in the queue to notify the server we are listening
     msgprintf(server_qid, 1, client_pid, "Hi from Client!"); 
     printf("Client: Waiting for server response. \n");

     //wait for a reply (blocking read)
     int receive;
     if((receive = msgrcv(server_qid, msg, RECEIVE_SZ, client_pid, 0)) < 0)
     {
	  perror("Message Receive Failed.");
	  return 1;
     }
     
     //We should get a reply.
     printf("Client: Received Message from Server:\n\t%s\n", msg->message_text);

     while(1) //same as for (;;)
     {
       printf("Client: Sending Reply.. \n");
       msgprintf(server_qid, 1, client_pid, "Send me something!");
       if((receive = msgrcv(server_qid, msg, RECEIVE_SZ, client_pid , 0)) < 0)
	  {
	       perror("Message Receive Failed.");
	       return 1;
	  }
	  printf("Client: Received Message from Server:\n\t%s\n", msg->message_text);
	  
	  msgprintf(server_qid, 1, client_pid, "OK Thank you, shutting down.");
	  break; //client shuts down after receiving 2 messages. 
     }
     printf("Client: Shutting down client.\n");
     return 0;
}
Beispiel #6
0
void sem_init(struct Semaphore *s, int init_val)
{
  //s=malloc(sizeof(struct Semaphore));
  s->count=init_val;
  lock_init(&s->locksem);
  //s->t_q=malloc(sizeof(struct queue));
  init_q(&s->t_q);
  //printf(1,"Semaphore created\n");

}
Beispiel #7
0
iface_t *new_tcp_conn(int fd, iface_t *ifa)
{
    iface_t *newifa;
    struct if_tcp *oift=(struct if_tcp *) ifa->info;
    struct if_tcp *newift=NULL;
    pthread_t tid;

    if ((newifa = malloc(sizeof(iface_t))) == NULL)
        return(NULL);

    memset(newifa,0,sizeof(iface_t));
    if (((newift = malloc(sizeof(struct if_tcp))) == NULL) ||
        ((ifa->direction != IN) && ((newifa->q=init_q(oift->qsize)) == NULL))){
            if (newifa && newifa->q)
                free(newifa->q);
            if (newift)
                free(newift);
            free(newifa);
            return(NULL);
    }
    newift->fd=fd;
    newift->qsize=oift->qsize;
    newifa->id=ifa->id+(fd&IDMINORMASK);
    newifa->direction=ifa->direction;
    newifa->type=TCP;
    newifa->name=NULL;
    newifa->info=newift;
    newifa->cleanup=cleanup_tcp;
    newifa->write=write_tcp;
    newifa->read=read_tcp;
    newifa->lists=ifa->lists;
    newifa->ifilter=addfilter(ifa->ifilter);
    newifa->ofilter=addfilter(ifa->ofilter);
    newifa->checksum=ifa->checksum;
    if (ifa->direction == IN)
        newifa->q=ifa->lists->engine->q;
    else if (ifa->direction == BOTH) {
        if ((newifa->next=ifdup(newifa)) == NULL) {
            logwarn("Interface duplication failed");
            free(newifa->q);
            free(newift);
            free(newifa);
            return(NULL);
        }
        newifa->direction=OUT;
        newifa->pair->direction=IN;
        newifa->pair->q=ifa->lists->engine->q;
        link_to_initialized(newifa->pair);
        pthread_create(&tid,NULL,(void *)start_interface,(void *) newifa->pair);
    }

    link_to_initialized(newifa);
    pthread_create(&tid,NULL,(void *)start_interface,(void *) newifa);
    return(newifa);
}
static int rmnet_stop(struct net_device *dev)
{
	struct rmnet_private *p = netdev_priv(dev);
	struct xmd_ch_info *info = p->ch;
       int i = 0;

	pr_info("rmnet_stop()\n");
	netif_stop_queue(dev);
      //xmd_ch_close(info->chno);
       i = info->chno - 2;
       init_q(i);
	return 0;
}
Beispiel #9
0
void write_file(iface_t *ifa)
{
    struct if_file *ifc = (struct if_file *) ifa->info;
    senblk_t *sptr;

    /* ifc->fp will only be NULL if we're opening a FIFO.
     */
    if (ifc->fp == NULL) {
        if ((ifc->fp=fopen(ifc->filename,"w")) == NULL) {
            logerr(errno,"Failed to open FIFO %s for writing\n",ifc->filename);
            iface_thread_exit(errno);
        }
        if ((ifa->q =init_q(ifc->qsize)) == NULL) {
            logerr(errno,"Could not create queue for FIFO %s",ifc->filename);
            iface_thread_exit(errno);
        }
        if (setvbuf(ifc->fp,NULL,_IOLBF,0) !=0)
            iface_thread_exit(errno);
    }

    for(;;)  {
        if ((sptr = next_senblk(ifa->q)) == NULL) {
		    break;
        }

        if (senfilter(sptr,ifa->ofilter)) {
            senblk_free(sptr,ifa->q);
            continue;
        }
            
        if (ifc->usereturn == 0) {
            sptr->data[sptr->len-2] = '\n';
            sptr->data[sptr->len-1] = '\0';
        }
        if (fputs(sptr->data,ifc->fp) == EOF) {
            if (!(ifa->persist && errno == EPIPE) )
		        break;
            if (((ifc->fp=freopen(ifc->filename,"w",ifc->fp)) == NULL) ||
                    (setvbuf(ifc->fp,NULL,_IOLBF,0) !=0))
                break;
        }
        senblk_free(sptr,ifa->q);
    }
    iface_thread_exit(errno);
}
Beispiel #10
0
int travel(){
	int i,j;
	Point p;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			count[i][j] = wand[i][j] = visited[i][j] = 0;
		}
	}
	init_q();
	enqueue(hermione);
	visited[hermione.x][hermione.y] = 1;
	while(!empty_q()){
		p = dequeue();
		if(forest[p.x][p.y] == '*')
			break;
		isvalid(p);
	}
}
Beispiel #11
0
Deck * init_deck(int size, Deck * src_deck, int std_fill){
        
        int i, j;
        Card add_card;
        Deck * deck = (Deck*)malloc(sizeof(Deck));
        if(deck==NULL){
                free(deck);
                return NULL;
        }

        if(src_deck == NULL){
        
                deck->cards = init_q(size, sizeof(Card));

                deck->realign     = deck_realign;
                deck->shuffle     = deck_shuffle;
                deck->destroy     = deck_destroy;
                deck->print       = deck_print;
                deck->pick_card   = deck_pick_card;
                deck->return_card = deck_return_card;
                
                if(std_fill == 1 && size == 52){
                        for(i=0;i<4;i++){
                                add_card.suit = i;
                                for(j=0;j<13;j++){
                                        add_card.val = j;
                                        deck->return_card(deck,add_card);
                                }
                        }
                }        
        }

        else{
                memcpy(deck, src_deck, sizeof(Deck));
                deck->cards->data = (void*)malloc(sizeof(Card)*src_deck->cards->size);
                memcpy(deck->cards->data, src_deck->cards->data, sizeof(Card)*src_deck->cards->size);
        }

        return deck;
}
Beispiel #12
0
static int
task_main(int argc, char *argv[])
{
	work_q_item_t *work;

	/* Initialize global variables */
	g_key_offsets[0] = 0;

	for (unsigned i = 0; i < (DM_KEY_NUM_KEYS - 1); i++) {
		g_key_offsets[i + 1] = g_key_offsets[i] + (g_per_item_max_index[i] * k_sector_size);
	}

	unsigned max_offset = g_key_offsets[DM_KEY_NUM_KEYS - 1] + (g_per_item_max_index[DM_KEY_NUM_KEYS - 1] * k_sector_size);

	for (unsigned i = 0; i < dm_number_of_funcs; i++) {
		g_func_counts[i] = 0;
	}

	/* Initialize the item type locks, for now only DM_KEY_MISSION_STATE supports locking */
	px4_sem_init(&g_sys_state_mutex, 1, 1); /* Initially unlocked */

	for (unsigned i = 0; i < DM_KEY_NUM_KEYS; i++) {
		g_item_locks[i] = NULL;
	}

	g_item_locks[DM_KEY_MISSION_STATE] = &g_sys_state_mutex;

	g_task_should_exit = false;

	init_q(&g_work_q);
	init_q(&g_free_q);

	px4_sem_init(&g_work_queued_sema, 1, 0);

	/* See if the data manage file exists and is a multiple of the sector size */
	g_task_fd = open(k_data_manager_device_path, O_RDONLY | O_BINARY);

	if (g_task_fd >= 0) {

#ifndef __PX4_POSIX
		// XXX on Mac OS and Linux the file is not a multiple of the sector sizes
		// this might need further inspection.

		/* File exists, check its size */
		int file_size = lseek(g_task_fd, 0, SEEK_END);

		if ((file_size % k_sector_size) != 0) {
			PX4_WARN("Incompatible data manager file %s, resetting it", k_data_manager_device_path);
			PX4_WARN("Size: %u, sector size: %d", file_size, k_sector_size);
			close(g_task_fd);
			unlink(k_data_manager_device_path);
		}

#else
		close(g_task_fd);
#endif

	}

	/* Open or create the data manager file */
	g_task_fd = open(k_data_manager_device_path, O_RDWR | O_CREAT | O_BINARY, PX4_O_MODE_666);

	if (g_task_fd < 0) {
		PX4_WARN("Could not open data manager file %s", k_data_manager_device_path);
		px4_sem_post(&g_init_sema); /* Don't want to hang startup */
		return -1;
	}

	if ((unsigned)lseek(g_task_fd, max_offset, SEEK_SET) != max_offset) {
		close(g_task_fd);
		PX4_WARN("Could not seek data manager file %s", k_data_manager_device_path);
		px4_sem_post(&g_init_sema); /* Don't want to hang startup */
		return -1;
	}

	fsync(g_task_fd);

	/* see if we need to erase any items based on restart type */
	int sys_restart_val;

	const char *restart_type_str = "Unkown restart";

	if (param_get(param_find("SYS_RESTART_TYPE"), &sys_restart_val) == OK) {
		if (sys_restart_val == DM_INIT_REASON_POWER_ON) {
			restart_type_str = "Power on restart";
			_restart(DM_INIT_REASON_POWER_ON);

		} else if (sys_restart_val == DM_INIT_REASON_IN_FLIGHT) {
			restart_type_str = "In flight restart";
			_restart(DM_INIT_REASON_IN_FLIGHT);
		}
	}

	/* We use two file descriptors, one for the caller context and one for the worker thread */
	/* They are actually the same but we need to some way to reject caller request while the */
	/* worker thread is shutting down but still processing requests */
	g_fd = g_task_fd;

	PX4_INFO("%s, data manager file '%s' size is %d bytes",
		 restart_type_str, k_data_manager_device_path, max_offset);

	/* Tell startup that the worker thread has completed its initialization */
	px4_sem_post(&g_init_sema);

	/* Start the endless loop, waiting for then processing work requests */
	while (true) {

		/* do we need to exit ??? */
		if ((g_task_should_exit) && (g_fd >= 0)) {
			/* Close the file handle to stop further queuing */
			g_fd = -1;
		}

		if (!g_task_should_exit) {
			/* wait for work */
			px4_sem_wait(&g_work_queued_sema);
		}

		/* Empty the work queue */
		while ((work = dequeue_work_item())) {

			/* handle each work item with the appropriate handler */
			switch (work->func) {
			case dm_write_func:
				g_func_counts[dm_write_func]++;
				work->result =
					_write(work->write_params.item, work->write_params.index, work->write_params.persistence, work->write_params.buf,
					       work->write_params.count);
				break;

			case dm_read_func:
				g_func_counts[dm_read_func]++;
				work->result =
					_read(work->read_params.item, work->read_params.index, work->read_params.buf, work->read_params.count);
				break;

			case dm_clear_func:
				g_func_counts[dm_clear_func]++;
				work->result = _clear(work->clear_params.item);
				break;

			case dm_restart_func:
				g_func_counts[dm_restart_func]++;
				work->result = _restart(work->restart_params.reason);
				break;

			default: /* should never happen */
				work->result = -1;
				break;
			}

			/* Inform the caller that work is done */
			px4_sem_post(&work->wait_sem);
		}

		/* time to go???? */
		if ((g_task_should_exit) && (g_fd < 0)) {
			break;
		}
	}

	close(g_task_fd);
	g_task_fd = -1;

	/* The work queue is now empty, empty the free queue */
	for (;;) {
		if ((work = (work_q_item_t *)sq_remfirst(&(g_free_q.q))) == NULL) {
			break;
		}

		if (work->first) {
			free(work);
		}
	}

	destroy_q(&g_work_q);
	destroy_q(&g_free_q);
	px4_sem_destroy(&g_work_queued_sema);
	px4_sem_destroy(&g_sys_state_mutex);

	return 0;
}
Beispiel #13
0
iface_t *init_file (iface_t *ifa)
{
    struct if_file *ifc;
    struct kopts *opt;
    struct stat statbuf;
    int append=0;

    if ((ifc = (struct if_file *)malloc(sizeof(struct if_file))) == NULL) {
        logerr(errno,"Could not allocate memory");
        return(NULL);
    }

    memset ((void *)ifc,0,sizeof(struct if_file));

    ifc->qsize=DEFFILEQSIZE;
    ifa->info = (void *) ifc;

    for(opt=ifa->options;opt;opt=opt->next) {
        if (!strcasecmp(opt->var,"filename")) {
            if (strcmp(opt->val,"-"))
                if ((ifc->filename=strdup(opt->val)) == NULL) {
                    logerr(errno,"Failed to duplicate argument string");
                    return(NULL);
                }
        } else if (!strcasecmp(opt->var,"qsize")) {
            if (!(ifc->qsize=atoi(opt->val))) {
                logerr(0,"Invalid queue size specified: %s",opt->val);
                return(NULL);
            }
        } else if (!strcasecmp(opt->var,"append")) {
            if (!strcasecmp(opt->val,"yes")) {
                append++;
            } else if (!strcasecmp(opt->val,"no")) {
                append = 0;
            } else {
                logerr(0,"Invalid option \"append=%s\"",opt->val);
                return(NULL);
            }
        } else if (!strcasecmp(opt->var,"eol")) {
            if (!strcasecmp(opt->val,"rn"))
                ifc->usereturn=1;
            else if (!strcasecmp(opt->val,"n")) {
                ifc->usereturn=0;
            } else {
                logerr(0,"Invalid option \"eol=%s\": Must be \"n\" or \"rn\"",
                        opt->val);
                return(NULL);
            }
        } else {
            logerr(0,"Unknown interface option %s\n",opt->var);
            return(NULL);
        }
    }

    /* We do allow use of stdin and stdout, but not if they're connected to
     * a terminal. This allows re-direction in background mode
     */
    if (ifc->filename == NULL) {
        if (ifa->persist) {
            logerr(0,"Can't use persist mode with stdin/stdout");
            return(NULL);
        }

        if (((ifa->direction != IN) &&
                (((struct if_engine *)ifa->lists->engine->info)->flags &
                K_NOSTDOUT)) ||
                ((ifa->direction != OUT) &&
                (((struct if_engine *)ifa->lists->engine->info)->flags &
                K_NOSTDIN))) {
            logerr(0,"Can't use terminal stdin/stdout in background mode");
            return(NULL);
        }
        ifc->fp = (ifa->direction == IN)?stdin:stdout;
    } else {
        if (ifa->direction == BOTH) {
            logerr(0,"Bi-directional file I/O only supported for stdin/stdout");
            return(NULL);
        }

        if (stat(ifc->filename,&statbuf) < 0) {
            if (ifa->direction != OUT) {
                logerr(errno,"stat %s",ifc->filename);
                return(NULL);
            }
        }

        if (S_ISFIFO(statbuf.st_mode)) {
            /* Special rules for FIFOs. Opening here would hang for a reading
             * interface with no writer. Given that we're single threaded here,
             * that would be bad
             */
            if (access(ifc->filename,(ifa->direction==IN)?R_OK:W_OK) != 0) {
                logerr(errno,"Could not access %s",ifc->filename);
                return(NULL);
            }
        }
        else {
            if (ifa->persist) {
                logerr(0,"Can't use persist mode on %s: Not a FIFO",
                        ifc->filename);
                return(NULL);
            }
            if ((ifc->fp=fopen(ifc->filename,(ifa->direction==IN)?"r":
                    (append)?"a":"w")) == NULL) {
                logerr(errno,"Failed to open %s",ifc->filename);
                return(NULL);
            }
            if (ifa->direction == OUT)
                /* Make output line buffered */
                setlinebuf(ifc->fp);
        }
    }

    free_options(ifa->options);

    ifa->write=write_file;
    ifa->read=read_file;
    ifa->cleanup=cleanup_file;

    if (ifa->direction != IN && ifc->fp != NULL)
        if ((ifa->q =init_q(ifc->qsize)) == NULL) {
            logerr(0,"Could not create queue");
            cleanup_file(ifa);
            return(NULL);
        }

    if (ifa->direction == BOTH) {
        if ((ifa->next=ifdup(ifa)) == NULL) {
            logerr(0,"Interface duplication failed");
            cleanup_file(ifa);
            return(NULL);
        }
        ifa->direction=OUT;
        ifa->pair->direction=IN;
        ifc = (struct if_file *) ifa->pair->info;
        ifc->fp=stdin;
    }
    return(ifa);
}
Beispiel #14
0
int main(void)
{
    /* Local scalars */
    char compq, compq_i;
    lapack_int n, n_i;
    lapack_int ldt, ldt_i;
    lapack_int ldt_r;
    lapack_int ldq, ldq_i;
    lapack_int ldq_r;
    lapack_int ifst, ifst_i;
    lapack_int ilst, ilst_i;
    lapack_int info, info_i;
    lapack_int i;
    int failed;

    /* Local arrays */
    lapack_complex_double *t = NULL, *t_i = NULL;
    lapack_complex_double *q = NULL, *q_i = NULL;
    lapack_complex_double *t_save = NULL;
    lapack_complex_double *q_save = NULL;
    lapack_complex_double *t_r = NULL;
    lapack_complex_double *q_r = NULL;

    /* Iniitialize the scalar parameters */
    init_scalars_ztrexc( &compq, &n, &ldt, &ldq, &ifst, &ilst );
    ldt_r = n+2;
    ldq_r = n+2;
    compq_i = compq;
    n_i = n;
    ldt_i = ldt;
    ldq_i = ldq;
    ifst_i = ifst;
    ilst_i = ilst;

    /* Allocate memory for the LAPACK routine arrays */
    t = (lapack_complex_double *)
        LAPACKE_malloc( ldt*n * sizeof(lapack_complex_double) );
    q = (lapack_complex_double *)
        LAPACKE_malloc( ldq*n * sizeof(lapack_complex_double) );

    /* Allocate memory for the C interface function arrays */
    t_i = (lapack_complex_double *)
        LAPACKE_malloc( ldt*n * sizeof(lapack_complex_double) );
    q_i = (lapack_complex_double *)
        LAPACKE_malloc( ldq*n * sizeof(lapack_complex_double) );

    /* Allocate memory for the backup arrays */
    t_save = (lapack_complex_double *)
        LAPACKE_malloc( ldt*n * sizeof(lapack_complex_double) );
    q_save = (lapack_complex_double *)
        LAPACKE_malloc( ldq*n * sizeof(lapack_complex_double) );

    /* Allocate memory for the row-major arrays */
    t_r = (lapack_complex_double *)
        LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
    q_r = (lapack_complex_double *)
        LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );

    /* Initialize input arrays */
    init_t( ldt*n, t );
    init_q( ldq*n, q );

    /* Backup the ouptut arrays */
    for( i = 0; i < ldt*n; i++ ) {
        t_save[i] = t[i];
    }
    for( i = 0; i < ldq*n; i++ ) {
        q_save[i] = q[i];
    }

    /* Call the LAPACK routine */
    ztrexc_( &compq, &n, t, &ldt, q, &ldq, &ifst, &ilst, &info );

    /* Initialize input data, call the column-major middle-level
     * interface to LAPACK routine and check the results */
    for( i = 0; i < ldt*n; i++ ) {
        t_i[i] = t_save[i];
    }
    for( i = 0; i < ldq*n; i++ ) {
        q_i[i] = q_save[i];
    }
    info_i = LAPACKE_ztrexc_work( LAPACK_COL_MAJOR, compq_i, n_i, t_i, ldt_i,
                                  q_i, ldq_i, ifst_i, ilst_i );

    failed = compare_ztrexc( t, t_i, q, q_i, info, info_i, compq, ldq, ldt, n );
    if( failed == 0 ) {
        printf( "PASSED: column-major middle-level interface to ztrexc\n" );
    } else {
        printf( "FAILED: column-major middle-level interface to ztrexc\n" );
    }

    /* Initialize input data, call the column-major high-level
     * interface to LAPACK routine and check the results */
    for( i = 0; i < ldt*n; i++ ) {
        t_i[i] = t_save[i];
    }
    for( i = 0; i < ldq*n; i++ ) {
        q_i[i] = q_save[i];
    }
    info_i = LAPACKE_ztrexc( LAPACK_COL_MAJOR, compq_i, n_i, t_i, ldt_i, q_i,
                             ldq_i, ifst_i, ilst_i );

    failed = compare_ztrexc( t, t_i, q, q_i, info, info_i, compq, ldq, ldt, n );
    if( failed == 0 ) {
        printf( "PASSED: column-major high-level interface to ztrexc\n" );
    } else {
        printf( "FAILED: column-major high-level interface to ztrexc\n" );
    }

    /* Initialize input data, call the row-major middle-level
     * interface to LAPACK routine and check the results */
    for( i = 0; i < ldt*n; i++ ) {
        t_i[i] = t_save[i];
    }
    for( i = 0; i < ldq*n; i++ ) {
        q_i[i] = q_save[i];
    }

    LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, t_i, ldt, t_r, n+2 );
    if( LAPACKE_lsame( compq, 'v' ) ) {
        LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
    }
    info_i = LAPACKE_ztrexc_work( LAPACK_ROW_MAJOR, compq_i, n_i, t_r, ldt_r,
                                  q_r, ldq_r, ifst_i, ilst_i );

    LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, t_r, n+2, t_i, ldt );
    if( LAPACKE_lsame( compq, 'v' ) ) {
        LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
    }

    failed = compare_ztrexc( t, t_i, q, q_i, info, info_i, compq, ldq, ldt, n );
    if( failed == 0 ) {
        printf( "PASSED: row-major middle-level interface to ztrexc\n" );
    } else {
        printf( "FAILED: row-major middle-level interface to ztrexc\n" );
    }

    /* Initialize input data, call the row-major high-level
     * interface to LAPACK routine and check the results */
    for( i = 0; i < ldt*n; i++ ) {
        t_i[i] = t_save[i];
    }
    for( i = 0; i < ldq*n; i++ ) {
        q_i[i] = q_save[i];
    }

    /* Init row_major arrays */
    LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, t_i, ldt, t_r, n+2 );
    if( LAPACKE_lsame( compq, 'v' ) ) {
        LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
    }
    info_i = LAPACKE_ztrexc( LAPACK_ROW_MAJOR, compq_i, n_i, t_r, ldt_r, q_r,
                             ldq_r, ifst_i, ilst_i );

    LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, t_r, n+2, t_i, ldt );
    if( LAPACKE_lsame( compq, 'v' ) ) {
        LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
    }

    failed = compare_ztrexc( t, t_i, q, q_i, info, info_i, compq, ldq, ldt, n );
    if( failed == 0 ) {
        printf( "PASSED: row-major high-level interface to ztrexc\n" );
    } else {
        printf( "FAILED: row-major high-level interface to ztrexc\n" );
    }

    /* Release memory */
    if( t != NULL ) {
        LAPACKE_free( t );
    }
    if( t_i != NULL ) {
        LAPACKE_free( t_i );
    }
    if( t_r != NULL ) {
        LAPACKE_free( t_r );
    }
    if( t_save != NULL ) {
        LAPACKE_free( t_save );
    }
    if( q != NULL ) {
        LAPACKE_free( q );
    }
    if( q_i != NULL ) {
        LAPACKE_free( q_i );
    }
    if( q_r != NULL ) {
        LAPACKE_free( q_r );
    }
    if( q_save != NULL ) {
        LAPACKE_free( q_save );
    }

    return 0;
}
int main(int argc, char *argv[])
{
	int time = 10; /* cpu time */
	int t = 0; /* time interval */
	
	READY_QUEUE rq;
	QUEUE wq, oq;
	
	init_q(&wq);
	init_q(&oq);
	init_rq(&rq);

	struct run_task rt;
	rt.status = IDLE;
	rt.set = FALSE;
	rt.rproc = NULL;

	TASK *arr_prog;
	arr_prog = read_prog();

	int t1, t2, t3;
	while(TRUE){
	
		t1 = nex_arr_prog(arr_prog, time);
		t2 = nex_tslice(&rt);
		t3 = next_io(&wq);
		
		assert(t1 >= 0);
		assert(t2 >= 0);
		assert(t3 >= 0);
		t = min(t1, t2, t3);
		
		time += t;
		
		if(rt.status == RUNNING)
			update_run_task(&rt, t);
		update_io_time(&wq, t);
		
		/* after 1ms switch out, put the running process into correct queue */
		if(!rt.set && rt.status == SWITCH_OUT)
			settle_proc(&rt, &rq, &oq, time);

		if(rt.status == IDLE || rt.status == SWITCH_OUT){
			// put process on CPU cost 1 ms
			if(sched_compl_io(&wq))
				handle_compl_io(&rq, &wq, &oq, time);
			while(sched_new_prog(arr_prog, time)){
				push_rq(&rq, arr_prog);
				arr_prog = read_prog();
			}
			
			time += MIN_T;
			update_io_time(&wq, MIN_T);
		
			if(!put_proc_on_cpu(&rt, &rq)){
				rt.status = IDLE;
				if(!peek(&wq) && !arr_prog)
					break;
			}
		}
	
		if(sched_take_out_proc(&rt, &wq, arr_prog, time))
			take_out_proc(&rt);
	
		if(sched_compl_io(&wq))
			handle_compl_io(&rq, &wq, &oq, time);
	
		if(sched_nex_io(&rt))
			new_io(&wq, &rt);
		
		while(sched_new_prog(arr_prog, time)){
			push_rq(&rq, arr_prog);
			arr_prog = read_prog();
		}

	}

	printf("Current Time: %d\n", time);
	TASK *last;
	int num = 0;
	long tot_compl_time = 0;
	int min_compl_time = INF;
	int max_compl_time = 0;
	int tot_cpu_time = 0;
	int tmp_time = 0;
	while(len(&oq)){
		last = dequeue(&oq);
		assert(last->c_io <= 0);
		num++;
		tmp_time = last->t_finish - last->t_arrive;	
		assert(tmp_time > 0);
		tot_compl_time += tmp_time;
		if(tmp_time < min_compl_time)
			min_compl_time = tmp_time;
		if(tmp_time > max_compl_time)
			max_compl_time = tmp_time;
		tot_cpu_time += last->t_exec;
//		printf("Prog Name: %s\n", last->cmd);
//		printf("Finish Time: %d\n", last->t_finish);
	}
	printf("ACT = %f\n", ((double)tot_compl_time) / num);
	printf("Min = %d\n", min_compl_time);
	printf("Max = %d\n", max_compl_time);
	printf("Throughput = %f\n", num / ((double)(time / 1000)));
	printf("Utilization = %f\n",((double)tot_cpu_time) / time); 

	return 1;
}
Beispiel #16
0
iface_t *init_tcp(iface_t *ifa)
{
    struct if_tcp *ift;
    char *host,*port;
    struct addrinfo hints,*aptr,*abase;
    struct servent *svent;
    int err;
    int on=1,off=0;
    char *conntype = "c";
    unsigned char *ptr;
    int i;
    struct kopts *opt;

    host=port=NULL;
    

    if ((ift = malloc(sizeof(struct if_tcp))) == NULL) {
        logerr(errno,"Could not allocate memory");
        return(NULL);
    }

    ift->qsize=DEFTCPQSIZE;

    for(opt=ifa->options;opt;opt=opt->next) {
        if (!strcasecmp(opt->var,"address"))
            host=opt->val;
        else if (!strcasecmp(opt->var,"mode")) {
            if (strcasecmp(opt->val,"client") && strcasecmp(opt->val,"server")){
                logerr(0,"Unknown tcp mode %s (must be \'client\' or \'server\')",opt->val);
                return(NULL);
            }
            conntype=opt->val;
        } else if (!strcasecmp(opt->var,"port")) {
            port=opt->val;
        }  else if (!strcasecmp(opt->var,"qsize")) {
            if (!(ift->qsize=atoi(opt->val))) {
                logerr(0,"Invalid queue size specified: %s",opt->val);
                return(NULL);
            }
        } else  {
            logerr(0,"unknown interface option %s\n",opt->var);
            return(NULL);
        }
    }

    if (*conntype == 'c' && !host) {
        logerr(0,"Must specify address for tcp client mode\n");
        return(NULL);
    }

    if (!port) {
        if ((svent=getservbyname("nmea-0183","tcp")) != NULL)
            port=svent->s_name;
        else
            port = DEFTCPPORT;
    }

    memset((void *)&hints,0,sizeof(hints));

    hints.ai_flags=(*conntype == 's')?AI_PASSIVE:0;
    hints.ai_family=AF_UNSPEC;
    hints.ai_socktype=SOCK_STREAM;

    if ((err=getaddrinfo(host,port,&hints,&abase))) {
        logerr(0,"Lookup failed for host %s/service %s: %s",host,port,gai_strerror(err));
        return(NULL);
    }

    aptr=abase;

    do {
        if ((ift->fd=socket(aptr->ai_family,aptr->ai_socktype,aptr->ai_protocol)) < 0)
            continue;
        if (*conntype == 'c') {
            if (connect(ift->fd,aptr->ai_addr,aptr->ai_addrlen) == 0)
                break;
        } else {
            setsockopt(ift->fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof(on));
            if (aptr->ai_family == AF_INET6) {
                for (ptr=((struct sockaddr_in6 *)aptr->ai_addr)->sin6_addr.s6_addr,i=0;i<16;i++,ptr++)
                    if (*ptr)
                        break;
                if (i == sizeof(struct in6_addr)) {
                    if (setsockopt(ift->fd,IPPROTO_IPV6,IPV6_V6ONLY,
                            (void *)&off,sizeof(off)) <0) {
                        logerr(errno,"Failed to set ipv6 mapped ipv4 addresses on socket");
                    }
                }
            }
            if (bind(ift->fd,aptr->ai_addr,aptr->ai_addrlen) == 0)
                break;
            err=errno;
        }
        close(ift->fd);
     } while ((aptr = aptr->ai_next));

    if (aptr == NULL) {
        logerr(err,"Failed to open tcp %s for %s/%s",(*conntype == 's')?"server":"connection",host,port);
        return(NULL);
    }

    ift->sa_len=aptr->ai_addrlen;
    (void) memcpy(&ift->sa,aptr->ai_addr,sizeof(struct sockaddr));

    freeaddrinfo(abase);

    if ((*conntype == 'c') && (ifa->direction != IN)) {
    /* This is an unusual but supported combination */
        if ((ifa->q =init_q(ift->qsize)) == NULL) {
            logerr(errno,"Interface duplication failed");
            return(NULL);
        }
    }

    ifa->cleanup=cleanup_tcp;
    ifa->info = (void *) ift;
    if (*conntype == 'c') {
        ifa->read=read_tcp;
        ifa->write=write_tcp;
        if (ifa->direction == BOTH) {
            if ((ifa->next=ifdup(ifa)) == NULL) {
                logerr(errno,"Interface duplication failed");
                return(NULL);
            }
            ifa->direction=OUT;
            ifa->pair->direction=IN;
        }
    } else {
        ifa->write=tcp_server;
        ifa->read=tcp_server;
    }
    free_options(ifa->options);
    return(ifa);
}
Beispiel #17
0
int xmd_ch_reset(void)
{
	int ch_i;
	int size = ARRAY_SIZE(hsi_all_channels);

//                                                  
#if defined (ENABLE_RECOVERY_WAKE_LOCK)
	wake_lock_timeout(&xmd_recovery_wake_lock, RECOVERY_WAKELOCK_TIME);
#endif
//                                                

//                                                  
#if 0
	if(	hsi_mcm_state == HSI_MCM_STATE_ERR_RECOVERY) {
#if MCM_DBG_ERR_RECOVERY_LOG
		printk("\nmcm: xmd_ch_reset already HSI_MCM_STATE_ERR_RECOVERY in progress\n");
#endif
		return -1;
	}

	hsi_mcm_state = HSI_MCM_STATE_ERR_RECOVERY;
#endif
//                                                

//                                                  
#if defined(CONFIG_MACH_LGE)
	/*Modem Reset */
	printk("\nmcm: [MIPI-HSI] ifx_pmu_reset.\n");

	ifx_pmu_reset();	//RIP-11203
#endif
//                                                

#if MCM_DBG_ERR_RECOVERY_LOG
	printk("\nmcm: HSI DLP Error Recovery initiated.\n");
#endif

	for (ch_i=0; ch_i < size; ch_i++) {
		if (hsi_channels[ch_i].write_happening == HSI_TRUE) {
			hsi_channels[ch_i].write_happening = HSI_FALSE;
			wake_up(&hsi_channels[ch_i].write_wait);
		}
	}
	flush_workqueue(hsi_write_wq);
	hsi_ll_reset();
	flush_workqueue(hsi_read_wq);

	for (ch_i=0; ch_i < size; ch_i++) {
		init_q(ch_i);
	}

//                                                  
#if defined(CONFIG_MACH_LGE)
	/* TODO: Fine tune to required value. */
	msleep(5000);
#endif
//                                                

#if MCM_DBG_ERR_RECOVERY_LOG
	printk("\nmcm: HSI DLP Error Recovery completed waiting for CP ready indication from RIL.\n");
#endif
	/* Change MCM state to initilized when CP ready
		indication from tty ctrl channel is issued */

	return 0;
}
Beispiel #18
0
iface_t *init_file (iface_t *ifa)
{
    struct if_file *ifc;
    struct kopts *opt;
    struct stat statbuf;
    int ret;
    int append=0;
    uid_t uid=-1;
    gid_t gid=-1;
    struct passwd *owner;
    struct group *group;
    mode_t tperm,perm=0;
    char *cp;

    if ((ifc = (struct if_file *)malloc(sizeof(struct if_file))) == NULL) {
        logerr(errno,"Could not allocate memory");
        return(NULL);
    }

    memset ((void *)ifc,0,sizeof(struct if_file));

    ifc->qsize=DEFFILEQSIZE;
    ifc->fd=-1;
    ifa->info = (void *) ifc;

    for(opt=ifa->options;opt;opt=opt->next) {
        if (!strcasecmp(opt->var,"filename")) {
            if (strcmp(opt->val,"-"))
                if ((ifc->filename=strdup(opt->val)) == NULL) {
                    logerr(errno,"Failed to duplicate argument string");
                    return(NULL);
                }
        } else if (!strcasecmp(opt->var,"qsize")) {
            if (!(ifc->qsize=atoi(opt->val))) {
                logerr(0,"Invalid queue size specified: %s",opt->val);
                return(NULL);
            }
        } else if (!strcasecmp(opt->var,"append")) {
            if (!strcasecmp(opt->val,"yes")) {
                append++;
            } else if (!strcasecmp(opt->val,"no")) {
                append = 0;
            } else {
                logerr(0,"Invalid option \"append=%s\"",opt->val);
                return(NULL);
            }
        } else if (!strcasecmp(opt->var,"owner")) {
            if ((owner=getpwnam(opt->val)) == NULL) {
                logerr(0,"No such user '%s'",opt->val);
                return(NULL);
            }
            uid=owner->pw_uid;
        } else if (!strcasecmp(opt->var,"group")) {
            if ((group=getgrnam(opt->val)) == NULL) {
                logerr(0,"No such group '%s'",opt->val);
                return(NULL);
            }
            gid=group->gr_gid;
        }
        else if (!strcasecmp(opt->var,"perm")) {
            for (cp=opt->val;*cp;cp++) {
                if (*cp >= '0' && *cp < '8') {
                    perm <<=3;
                    perm += (*cp-'0');
                } else {
                    perm = 0;
                    break;
                }
            }
            perm &= ACCESSPERMS;
            if (perm == 0) {
                logerr(0,"Invalid permissions for tty device \'%s\'",opt->val);
                return 0;
            }
        } else {
            logerr(0,"Unknown interface option %s\n",opt->var);
            return(NULL);
        }
    }

    /* We do allow use of stdin and stdout, but not if they're connected to
     * a terminal. This allows re-direction in background mode
     */
    if (ifc->filename == NULL) {
        if (flag_test(ifa,F_PERSIST)) {
            logerr(0,"Can't use persist mode with stdin/stdout");
            return(NULL);
        }

        if (((ifa->direction != IN) &&
                (((struct if_engine *)ifa->lists->engine->info)->flags &
                K_NOSTDOUT)) ||
                ((ifa->direction != OUT) &&
                (((struct if_engine *)ifa->lists->engine->info)->flags &
                K_NOSTDIN))) {
            logerr(0,"Can't use terminal stdin/stdout in background mode");
            return(NULL);
        }
        ifc->fd = (ifa->direction == IN)?STDIN_FILENO:STDOUT_FILENO;
    } else {
        if (ifa->direction == BOTH) {
            logerr(0,"Bi-directional file I/O only supported for stdin/stdout");
            return(NULL);
        }

        if ((ret=stat(ifc->filename,&statbuf)) < 0) {
            if (ifa->direction != OUT) {
                logerr(errno,"stat %s",ifc->filename);
                return(NULL);
            }
        }
        if ((ret == 0) && S_ISFIFO(statbuf.st_mode)) {
            /* Special rules for FIFOs. Opening here would hang for a reading
             * interface with no writer. Given that we're single threaded here,
             * that would be bad
             */
            if (access(ifc->filename,(ifa->direction==IN)?R_OK:W_OK) != 0) {
                logerr(errno,"Could not access %s",ifc->filename);
                return(NULL);
            }
        }
        else {
            if (flag_test(ifa,F_PERSIST)) {
                logerr(0,"Can't use persist mode on %s: Not a FIFO",
                        ifc->filename);
                return(NULL);
            }
            if (perm)
                tperm=umask(0);

            errno=0;
            if (ifa->direction != IN && (ifc->fd=open(ifc->filename,
                        O_WRONLY|O_CREAT|O_EXCL|((append)?O_APPEND:0),
                        (perm)?perm:0664)) >= 0) {
                if (gid != 0 || uid != -1) {
                    if (chown(ifc->filename,uid,gid) < 0) {
                        logerr(errno, "Failed to set ownership or group on output file %s",ifc->filename);
                        return(NULL);
                    }
                }
            } else {
                if (errno && errno != EEXIST) {
                    logerr(errno,"Failed to create file %s",ifc->filename);
                    return(NULL);
                }
                if ((ifc->fd=open(ifc->filename,(ifa->direction==IN)?O_RDONLY:
                        (O_WRONLY|((append)?O_APPEND:O_TRUNC)))) < 0) {
                    logerr(errno,"Failed to open file %s",ifc->filename);
                    return(NULL);
                }
            }
            /* reset umask: not really necessary */
            if (perm)
                (void) umask(tperm);
        }
    }

    free_options(ifa->options);

    ifa->write=write_file;
    ifa->read=file_read_wrapper;
    ifa->readbuf=read_file;
    ifa->cleanup=cleanup_file;

    if (ifa->direction != IN && ifc->fd >= 0)
        if ((ifa->q =init_q(ifc->qsize)) == NULL) {
            logerr(0,"Could not create queue");
            cleanup_file(ifa);
            return(NULL);
        }

    if (ifa->direction == BOTH) {
        if ((ifa->next=ifdup(ifa)) == NULL) {
            logerr(0,"Interface duplication failed");
            cleanup_file(ifa);
            return(NULL);
        }
        ifa->direction=OUT;
        ifa->pair->direction=IN;
        ifc = (struct if_file *) ifa->pair->info;
        ifc->fd=STDIN_FILENO;
    }
    return(ifa);
}
Beispiel #19
0
int main(void)
{
    /* Local scalars */
    char vect, vect_i;
    char uplo, uplo_i;
    lapack_int n, n_i;
    lapack_int kd, kd_i;
    lapack_int ldab, ldab_i;
    lapack_int ldab_r;
    lapack_int ldq, ldq_i;
    lapack_int ldq_r;
    lapack_int info, info_i;
    lapack_int i;
    int failed;

    /* Local arrays */
    double *ab = NULL, *ab_i = NULL;
    double *d = NULL, *d_i = NULL;
    double *e = NULL, *e_i = NULL;
    double *q = NULL, *q_i = NULL;
    double *work = NULL, *work_i = NULL;
    double *ab_save = NULL;
    double *d_save = NULL;
    double *e_save = NULL;
    double *q_save = NULL;
    double *ab_r = NULL;
    double *q_r = NULL;

    /* Iniitialize the scalar parameters */
    init_scalars_dsbtrd( &vect, &uplo, &n, &kd, &ldab, &ldq );
    ldab_r = n+2;
    ldq_r = n+2;
    vect_i = vect;
    uplo_i = uplo;
    n_i = n;
    kd_i = kd;
    ldab_i = ldab;
    ldq_i = ldq;

    /* Allocate memory for the LAPACK routine arrays */
    ab = (double *)LAPACKE_malloc( ldab*n * sizeof(double) );
    d = (double *)LAPACKE_malloc( n * sizeof(double) );
    e = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
    q = (double *)LAPACKE_malloc( ldq*n * sizeof(double) );
    work = (double *)LAPACKE_malloc( n * sizeof(double) );

    /* Allocate memory for the C interface function arrays */
    ab_i = (double *)LAPACKE_malloc( ldab*n * sizeof(double) );
    d_i = (double *)LAPACKE_malloc( n * sizeof(double) );
    e_i = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
    q_i = (double *)LAPACKE_malloc( ldq*n * sizeof(double) );
    work_i = (double *)LAPACKE_malloc( n * sizeof(double) );

    /* Allocate memory for the backup arrays */
    ab_save = (double *)LAPACKE_malloc( ldab*n * sizeof(double) );
    d_save = (double *)LAPACKE_malloc( n * sizeof(double) );
    e_save = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
    q_save = (double *)LAPACKE_malloc( ldq*n * sizeof(double) );

    /* Allocate memory for the row-major arrays */
    ab_r = (double *)LAPACKE_malloc( (kd+1)*(n+2) * sizeof(double) );
    q_r = (double *)LAPACKE_malloc( n*(n+2) * sizeof(double) );

    /* Initialize input arrays */
    init_ab( ldab*n, ab );
    init_d( n, d );
    init_e( (n-1), e );
    init_q( ldq*n, q );
    init_work( n, work );

    /* Backup the ouptut arrays */
    for( i = 0; i < ldab*n; i++ ) {
        ab_save[i] = ab[i];
    }
    for( i = 0; i < n; i++ ) {
        d_save[i] = d[i];
    }
    for( i = 0; i < (n-1); i++ ) {
        e_save[i] = e[i];
    }
    for( i = 0; i < ldq*n; i++ ) {
        q_save[i] = q[i];
    }

    /* Call the LAPACK routine */
    dsbtrd_( &vect, &uplo, &n, &kd, ab, &ldab, d, e, q, &ldq, work, &info );

    /* Initialize input data, call the column-major middle-level
     * interface to LAPACK routine and check the results */
    for( i = 0; i < ldab*n; i++ ) {
        ab_i[i] = ab_save[i];
    }
    for( i = 0; i < n; i++ ) {
        d_i[i] = d_save[i];
    }
    for( i = 0; i < (n-1); i++ ) {
        e_i[i] = e_save[i];
    }
    for( i = 0; i < ldq*n; i++ ) {
        q_i[i] = q_save[i];
    }
    for( i = 0; i < n; i++ ) {
        work_i[i] = work[i];
    }
    info_i = LAPACKE_dsbtrd_work( LAPACK_COL_MAJOR, vect_i, uplo_i, n_i, kd_i,
                                  ab_i, ldab_i, d_i, e_i, q_i, ldq_i, work_i );

    failed = compare_dsbtrd( ab, ab_i, d, d_i, e, e_i, q, q_i, info, info_i,
                             ldab, ldq, n, vect );
    if( failed == 0 ) {
        printf( "PASSED: column-major middle-level interface to dsbtrd\n" );
    } else {
        printf( "FAILED: column-major middle-level interface to dsbtrd\n" );
    }

    /* Initialize input data, call the column-major high-level
     * interface to LAPACK routine and check the results */
    for( i = 0; i < ldab*n; i++ ) {
        ab_i[i] = ab_save[i];
    }
    for( i = 0; i < n; i++ ) {
        d_i[i] = d_save[i];
    }
    for( i = 0; i < (n-1); i++ ) {
        e_i[i] = e_save[i];
    }
    for( i = 0; i < ldq*n; i++ ) {
        q_i[i] = q_save[i];
    }
    for( i = 0; i < n; i++ ) {
        work_i[i] = work[i];
    }
    info_i = LAPACKE_dsbtrd( LAPACK_COL_MAJOR, vect_i, uplo_i, n_i, kd_i, ab_i,
                             ldab_i, d_i, e_i, q_i, ldq_i );

    failed = compare_dsbtrd( ab, ab_i, d, d_i, e, e_i, q, q_i, info, info_i,
                             ldab, ldq, n, vect );
    if( failed == 0 ) {
        printf( "PASSED: column-major high-level interface to dsbtrd\n" );
    } else {
        printf( "FAILED: column-major high-level interface to dsbtrd\n" );
    }

    /* Initialize input data, call the row-major middle-level
     * interface to LAPACK routine and check the results */
    for( i = 0; i < ldab*n; i++ ) {
        ab_i[i] = ab_save[i];
    }
    for( i = 0; i < n; i++ ) {
        d_i[i] = d_save[i];
    }
    for( i = 0; i < (n-1); i++ ) {
        e_i[i] = e_save[i];
    }
    for( i = 0; i < ldq*n; i++ ) {
        q_i[i] = q_save[i];
    }
    for( i = 0; i < n; i++ ) {
        work_i[i] = work[i];
    }

    LAPACKE_dge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
    if( LAPACKE_lsame( vect, 'u' ) || LAPACKE_lsame( vect, 'v' ) ) {
        LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
    }
    info_i = LAPACKE_dsbtrd_work( LAPACK_ROW_MAJOR, vect_i, uplo_i, n_i, kd_i,
                                  ab_r, ldab_r, d_i, e_i, q_r, ldq_r, work_i );

    LAPACKE_dge_trans( LAPACK_ROW_MAJOR, kd+1, n, ab_r, n+2, ab_i, ldab );
    if( LAPACKE_lsame( vect, 'u' ) || LAPACKE_lsame( vect, 'v' ) ) {
        LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
    }

    failed = compare_dsbtrd( ab, ab_i, d, d_i, e, e_i, q, q_i, info, info_i,
                             ldab, ldq, n, vect );
    if( failed == 0 ) {
        printf( "PASSED: row-major middle-level interface to dsbtrd\n" );
    } else {
        printf( "FAILED: row-major middle-level interface to dsbtrd\n" );
    }

    /* Initialize input data, call the row-major high-level
     * interface to LAPACK routine and check the results */
    for( i = 0; i < ldab*n; i++ ) {
        ab_i[i] = ab_save[i];
    }
    for( i = 0; i < n; i++ ) {
        d_i[i] = d_save[i];
    }
    for( i = 0; i < (n-1); i++ ) {
        e_i[i] = e_save[i];
    }
    for( i = 0; i < ldq*n; i++ ) {
        q_i[i] = q_save[i];
    }
    for( i = 0; i < n; i++ ) {
        work_i[i] = work[i];
    }

    /* Init row_major arrays */
    LAPACKE_dge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
    if( LAPACKE_lsame( vect, 'u' ) || LAPACKE_lsame( vect, 'v' ) ) {
        LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, q_i, ldq, q_r, n+2 );
    }
    info_i = LAPACKE_dsbtrd( LAPACK_ROW_MAJOR, vect_i, uplo_i, n_i, kd_i, ab_r,
                             ldab_r, d_i, e_i, q_r, ldq_r );

    LAPACKE_dge_trans( LAPACK_ROW_MAJOR, kd+1, n, ab_r, n+2, ab_i, ldab );
    if( LAPACKE_lsame( vect, 'u' ) || LAPACKE_lsame( vect, 'v' ) ) {
        LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, n, q_r, n+2, q_i, ldq );
    }

    failed = compare_dsbtrd( ab, ab_i, d, d_i, e, e_i, q, q_i, info, info_i,
                             ldab, ldq, n, vect );
    if( failed == 0 ) {
        printf( "PASSED: row-major high-level interface to dsbtrd\n" );
    } else {
        printf( "FAILED: row-major high-level interface to dsbtrd\n" );
    }

    /* Release memory */
    if( ab != NULL ) {
        LAPACKE_free( ab );
    }
    if( ab_i != NULL ) {
        LAPACKE_free( ab_i );
    }
    if( ab_r != NULL ) {
        LAPACKE_free( ab_r );
    }
    if( ab_save != NULL ) {
        LAPACKE_free( ab_save );
    }
    if( d != NULL ) {
        LAPACKE_free( d );
    }
    if( d_i != NULL ) {
        LAPACKE_free( d_i );
    }
    if( d_save != NULL ) {
        LAPACKE_free( d_save );
    }
    if( e != NULL ) {
        LAPACKE_free( e );
    }
    if( e_i != NULL ) {
        LAPACKE_free( e_i );
    }
    if( e_save != NULL ) {
        LAPACKE_free( e_save );
    }
    if( q != NULL ) {
        LAPACKE_free( q );
    }
    if( q_i != NULL ) {
        LAPACKE_free( q_i );
    }
    if( q_r != NULL ) {
        LAPACKE_free( q_r );
    }
    if( q_save != NULL ) {
        LAPACKE_free( q_save );
    }
    if( work != NULL ) {
        LAPACKE_free( work );
    }
    if( work_i != NULL ) {
        LAPACKE_free( work_i );
    }

    return 0;
}
Beispiel #20
0
void write_file(iface_t *ifa)
{
    struct if_file *ifc = (struct if_file *) ifa->info;
    senblk_t *sptr;
    int usereturn=flag_test(ifa,F_NOCR)?0:1;
    int data=0;
    int cnt=1;
    struct iovec iov[2];

    /* ifc->fd will only be < 0 if we're opening a FIFO.
     */
    if (ifc->fd < 0) {
        if ((ifc->fd=open(ifc->filename,O_WRONLY)) < 0) {
            logerr(errno,"Failed to open FIFO %s for writing\n",ifc->filename);
            iface_thread_exit(errno);
        }
        if ((ifa->q =init_q(ifc->qsize)) == NULL) {
            logerr(errno,"Could not create queue for FIFO %s",ifc->filename);
            iface_thread_exit(errno);
        }
    }

    if (ifa->tagflags) {
        if ((iov[0].iov_base=malloc(TAGMAX)) == NULL) {
                logerr(errno,"Disabing tag output on interface id %u (%s)",
                        ifa->id,(ifa->name)?ifa->name:"unlabelled");
                ifa->tagflags=0;
        } else {
            cnt=2;
            data=1;
        }
    }


    for(;;)  {
        if ((sptr = next_senblk(ifa->q)) == NULL) {
            break;
        }

        if (senfilter(sptr,ifa->ofilter)) {
            senblk_free(sptr,ifa->q);
            continue;
        }

        if (!usereturn) {
            sptr->data[sptr->len-2] = '\n';
            sptr->len--;
        }

        if (ifa->tagflags)
            if ((iov[0].iov_len = gettag(ifa,iov[0].iov_base,sptr)) == 0) {
                logerr(errno,"Disabing tag output on interface id %u (%s)",
                        ifa->id,(ifa->name)?ifa->name:"unlabelled");
                ifa->tagflags=0;
                cnt=1;
                data=0;
                free(iov[0].iov_base);
            }

        iov[data].iov_base=sptr->data;
        iov[data].iov_len=sptr->len;
        if (writev(ifc->fd,iov,cnt) <0) {
            if (!(flag_test(ifa,F_PERSIST) && errno == EPIPE) )
                break;
            if ((ifc->fd=open(ifc->filename,O_WRONLY)) < 0)
                break;
        }
        senblk_free(sptr,ifa->q);
    }

    if (cnt == 2)
        free(iov[0].iov_base);

    iface_thread_exit(errno);
}
Beispiel #21
0
int proc_engine_options(iface_t *e_info,struct kopts *options)
{
    struct kopts *optr;
    size_t qsize=DEFQUEUESZ;
    struct if_engine *ifg = (struct if_engine *) e_info->info;

    if (e_info->options) {
        for (optr=e_info->options;optr->next;optr=optr->next);
        optr->next=options;
    } else {
        e_info->options = options;
    }

    for (optr=e_info->options;optr;optr=optr->next) {
        if (!strcasecmp(optr->var,"qsize")) {
            if(!(qsize = atoi(optr->val))) {
                fprintf(stderr,"Invalid queue size: %s\n",optr->val);
                exit(1);
            }
        } else if (!strcasecmp(optr->var,"mode")) {
            if (!strcasecmp(optr->val,"background"))
                ifg->flags|=K_BACKGROUND;
            else if (!strcasecmp(optr->val,"foreground"))
                ifg->flags &= ~K_BACKGROUND;
            else
                fprintf(stderr,"Warning: unrecognized mode \'%s\' specified\n",optr->val);
        } else if (!strcasecmp(optr->var,"logto")) {
            if ((ifg->logto = string2facility(optr->val)) < 0) {
                fprintf(stderr,"Unknown log facility \'%s\' specified\n",optr->val);
                exit(1);
            }
        } else if (!strcasecmp(optr->var,"graceperiod")) {
            if (((graceperiod=(time_t) strtoumax(optr->val,NULL,0)) == 0) &&
                    (errno)) {
                fprintf(stderr,"Bad value for graceperiod: %s\n",optr->val);
                exit(1);
            }
        } else if (!strcasecmp(optr->var,"checksum")) {
            if (!strcasecmp(optr->val,"yes"))
                e_info->checksum=1;
            else if (!strcasecmp(optr->val,"no"))
                e_info->checksum=0;
            else {
                fprintf(stderr,"Checksum option must be either \'yes\' or \'no\'\n");
                exit(1);
            }
        } else if (!strcasecmp(optr->var,"strict")) {
            if (!strcasecmp(optr->val,"yes"))
                e_info->strict=1;
            else if (!strcasecmp(optr->val,"no"))
                e_info->strict=0;
            else {
                fprintf(stderr,"Strict option must be either \'yes\' or \'no\'\n");
                exit(1);
            }
        } else if (!strcasecmp(optr->var,"failover")) {
            if (addfailover(&e_info->ofilter,optr->val) != 0) {
                fprintf(stderr,"Failed to add failover %s\n",optr->val);
                exit(1);
            }
        } else {
            fprintf(stderr,"Warning: Unrecognized option \'%s\'\n",optr->var);
            exit(0);
        }
    }

    if ((e_info->q = init_q(qsize)) == NULL) {
        perror("failed to initiate queue");
        exit(1);
    }
    return(0);
}
Beispiel #22
0
void sem_init(struct Semaphore *s) {
	s->count = 0;
	lock_init(&s->lock);
	init_q(&s->q);
}