示例#1
0
void fft_3d_cuda(FFT_DATA *in, FFT_DATA *out, int flag, struct fft_plan_3d *plan)
{
#ifdef FFT_CUFFT
  plan->iterate++;
  my_times starttime,starttime2;
  my_times endtime,endtime2;

  int i,total,length,offset,num;
  double norm;
  FFT_DATA *data,*copy;
  // system specific constants


  // pre-remap to prepare for 1st FFTs if needed
  // copy = loc for remap result
  int nprocs=plan->nprocs;
if(nprocs>1)
{
  if(plan->init)
  my_gettime(CLOCK_REALTIME,&starttime);
  if (plan->pre_plan) {
    if (plan->pre_target == 0) copy = out;
    else copy = plan->copy;
    if(plan->init) remap_3d((double *) in, (double *) out, (double *) plan->scratch,plan->pre_plan);
    data = out;
  }
  else
    data = in;
}
  cufftResult retvalc;
  if(plan->init)
  {
        if(nprocs>1)
        {
      if(sizeof(FFT_CFLOAT)==sizeof(double))cudaMemcpy((void*) (plan->cudata2), (void*) data, plan->cudatasize/2,cudaMemcpyHostToDevice);
      if(sizeof(FFT_CFLOAT)==sizeof(float)) cudaMemcpy((void*) (plan->cudata2), (void*) data, plan->cudatasize,cudaMemcpyHostToDevice);
      initfftdata((double*)plan->cudata2,(FFT_CFLOAT*)plan->cudata,plan->nfast,plan->nmid,plan->nslow);
    }
  }
    if (flag == -1)
    {
      retvalc=cufft(plan->plan_3d, plan->cudata, plan->cudata2,CUFFT_FORWARD);
    }
    else
    {
      retvalc=cufft(plan->plan_3d, plan->cudata, plan->cudata2,CUFFT_INVERSE);
    }
    if(retvalc!=CUFFT_SUCCESS) {printf("ErrorCUFFT: %i\n",retvalc);exit(EXIT_FAILURE);}

    FFTsyncthreads();
#endif
}
示例#2
0
文件: act.c 项目: yeonsh/Amoeba
/*
 *	Return a fresh and locked slot in objs
 */
int
new_obj()
{
    int n;

    for (n = 0; n < MAX_OBJ; ++n) {
	if (!obj_in_use(&objs[n])) {
	    /* Lock it */
	    mu_lock(&objs[n].or_lock);
	    if (!obj_in_use(&objs[n])) {
		(void) memset((_VOIDSTAR) &objs[n].or, 0, sizeof(objs[n].or));
		objs[n].or.or_nextpoll = objs[n].or.or_nextboot = my_gettime();
		return n;
	    }
	    mu_unlock(&objs[n].or_lock);
	}
    }
    MON_EVENT("No free slot in objs[]");
    return -1;
} /* new_obj */
示例#3
0
void *read_message(void *arg)
{
    int fd = *((int *)arg);                //获得连接套接字
    int count;                             //接收到的实际字符数
    
    char write_buf[MAX];                   //写入文件缓冲
    
    struct message r_buf;                  //接收缓冲区
   
    while(1)
    {
       // sleep(1);
        memset(&r_buf,0,sizeof(r_buf));

	    if((count = read(fd,&r_buf,sizeof(r_buf))) > 0)              //接收到字符才执行
        {
            /*检查chat聊天窗口是否满*/
            
            mvwprintw(tips_win, 1, 1, "                                                       ");
            /*根据接收到的相应的动作定义执行相应操作*/        
            switch(r_buf.action)
            {
                case REGIST_OK:                       
                {
                    regist_back = REGIST_OK;
                    printf("\t\t\t\t您获得靓号ID  %s\n",r_buf.id);
                    break;
                }

                case MULTI_NAME:
                {
                    regist_back = MULTI_NAME;
                    printf("\t\t\t\t该用户名已经注册\n");
                    printf("\t\t\t\t请重新注册、、、、\n");
                    break;
                }

                case LOG_OK:
                {
                    msg.state = LINE;
                    strcpy(msg.name,r_buf.name);
                    printf("\t\t\t\t登陆成功。。\n");
                    break;
                }

                case NOT_EXIST:
                {
                    printf("\t\t\t\t用户不存在。。。\n");
                    break;
                }

                case PASSWORD_ERROR:
                {
                    printf("\t\t\t\t密码错误。。。\n");
                    break;
                }

                case CHAT:                            //收到消息打印出提示并将消息写入聊天记录
                {
                    my_gettime();
                    wprintw(chat_win, ">>>%s %s talk to you : %s\n",c_time,r_buf.name,r_buf.msg);
                    wrefresh(chat_win);
                    
                    memset(write_buf,0,sizeof(write_buf));
                    sprintf(write_buf, ">>>%s %s talk to you : %s",c_time,r_buf.name,r_buf.msg);
                    write_line(write_buf);

                    break;
                }

                case LEFT_MSG:                       //收到离线消息打印提示并写入文件
                {
                    wprintw(chat_win, ">>>there is a unread message\n");
                    wprintw(chat_win, ">>>unread message: %s talk to you : %s\n",r_buf.name,r_buf.msg);
                    wrefresh(chat_win);

                    memset(write_buf,0,sizeof(write_buf));
                    sprintf(write_buf, "unread message: %s talk to you : %s",r_buf.name,r_buf.msg);
                    write_line(write_buf);
                    break;
                }

                case CHAT_OK:
                {
                    mvwprintw(tips_win, 1 , 2 , "chat send ok");
                    wrefresh(tips_win);
             //     printf("发送成功。。\n");
                    break;
                }

                case CHAT_NOT_EXIST:
                {
                    mvwprintw(tips_win, 1 , 2 , "the man haven't regist !!!");
                    wrefresh(tips_win);
              //      printf("聊天对象还没注册哦、、、\n");
                    break;
                }

                case CHAT_NOTLINE:
                {  
                    mvwprintw(tips_win, 1 , 2 , "the man isn't online,the msg have been left!");
                    wrefresh(tips_win);
               //     printf("聊天对象还未上线哦、、、\n"); 
                    break;
                }
     
                case BROAD_OK:
                {
                    mvwprintw(tips_win, 1 , 2 , "broad ok !!!");
                    wrefresh(tips_win);
               //     printf("广播成功咯。。\n");
                    break;
                }

                case BROAD:
                {
                    my_gettime();
                    wprintw(chat_win, ">>>%s %s broadcast that : %s\n",c_time,r_buf.name,r_buf.msg);
                    wrefresh(chat_win);
                    
                    memset(write_buf,0,sizeof(write_buf));
                    sprintf(write_buf, "%s %s broadcast that: %s",c_time,r_buf.toname,r_buf.msg);
                    write_line(write_buf);                   
                  //  printf("%s 对大家大吼一声 : %s\n",r_buf.name,r_buf.msg);
                    break;
                }

                case RNAME_OK:
                {
                    mvwprintw(tips_win, 1 , 2 , "change name ok !!!");
                    wrefresh(tips_win);
                //    printf("修改名称成功!!\n");
                    break;
                }

                case CPWD_OK:
                {
                    mvwprintw(tips_win, 1 , 2 , "change password ok !!!");
                    wrefresh(tips_win);
                  //  printf("修改密码成功!!!\n");
                    break;
                }

                case LOGOFF_OK:
                {
                    
                    break;
                }

                case SHOW_BACK:
                {
                    mvwprintw(show_win, line_show++, 4 , "%s    ",r_buf.toname);
                    wrefresh(show_win);

                    break;
                }

                case BAN_OK:
                {
                    mvwprintw(tips_win, 1 , 2 , "ban ok !!!");
                    wrefresh(tips_win);
                 //   printf("禁言成功!!\n");
                    break;
                }

                case BAN_NOTLINE:
                {
                    mvwprintw(tips_win, 1 , 2 , "ban person isn't online!!!");
                    wrefresh(tips_win);
                 //   printf("禁言对象不在线!!\n");
                    break;
                }

                case BAN_NOTEXIST:
                {
                    mvwprintw(tips_win, 1 , 2 , "ban person isn't exist");
                    wrefresh(tips_win);
                  //  printf("禁言对象不存在!!\n");
                    break;
                }

                case KICK_OK:
                {
                    mvwprintw(tips_win, 1 , 2 , "kick person OK!!!");
                    wrefresh(tips_win);
                 //   printf("踢人成功,对方已被强制下线!!\n");
                    break;
                }

                case KICK_NOTLINE:
                {
                   
                    mvwprintw(tips_win, 1 , 2 , "kick person isn't online!!!");
                    wrefresh(tips_win);
                 //   printf("对方不在线,踢人失败!!\n");
                    break;
                }

                case KICK_NOTEXIST:
                {
                    mvwprintw(tips_win, 1 , 2 , "kick person isn't exist");
                    wrefresh(tips_win);
                 //   printf("对方不存在,踢人失败!!\n");
                    break;
                }

                case BANED:
                {
                    msg.state = CHAT_BAN;
                    mvwprintw(tips_win, 1 , 2 , "you are baned by admin,you can't chat ");
                    wrefresh(tips_win);
                 //   printf("您已被管理员禁言,将不能发送任何聊天!\n");
                    break;
                }

                case KICKED:
                {
                    mvwprintw(tips_win, 1 , 2 , "you are kicked ");
                    wrefresh(tips_win);
                    refresh();
                  
                    endwin();

                    msg.state = NOTLINE;

                    system("clear");
                    printf("\n\n\n\n你已被管理员踢出房间!!!");
                    
                    exit(1);
                //    printf("您已被管理员踢出聊天房间!\n");
                    break;
                }

                case RIDED:
                {
                    msg.state = LINE;
                    mvwprintw(tips_win, 1 , 2 , "the admin allow you chat now ");
                    wrefresh(tips_win);
               //     printf("您已被管理员解除禁言\n");
                    break;
                }

                case RID_OK:
                {
                    mvwprintw(tips_win, 1 , 2 , "rid person ok!! ");
                    wrefresh(tips_win);
                //    printf("解除禁言成功!\n");
                    break;
                }

                case RID_NOTLINE:
                {
                    mvwprintw(tips_win, 1 , 2 , "the person isn't online ");
                    wrefresh(tips_win);
                 //   printf("您解除的对象已不在线。。\n");
                    break;
                }

                case RID_NOTEXIST:
                {  
                    mvwprintw(tips_win, 1 , 2 , "the person isn't exist ");
                    wrefresh(tips_win);
                //    printf("您解除的对象不存在。。\n");
                    break;
                }

                case SEND_FILE:                    //对方发文件来 打开文件并在后面追加一行
                {
                    my_gettime();
                    mvwprintw(tips_win, 1 , 2 , "%s %s send file %s to you",c_time,r_buf.name,r_buf.file_name);
                    wrefresh(tips_win);
                    
                    if((fp = fopen(r_buf.file_name,"a+")) == NULL)
                    {
                        mvwprintw(tips_win, 1, 2, "                                                   ");
                        mvwprintw(tips_win, 1 , 2 , "open file error");
                        wrefresh(tips_win);
                    }
                    
                    fputs(r_buf.msg,fp);

                 //   fputc('\n',fp);

                    fclose(fp);

                    break;
                }

                case SEND_OK:
                {  
                    mvwprintw(tips_win, 1 , 2 , "send OK!! ");
                    wrefresh(tips_win);
                    break;
                }
                case SEND_NOT_EXIST:
                {                      
                    mvwprintw(tips_win, 1, 2 , "the person isn't exist");
                    wrefresh(tips_win);
                    break;
                }
                case SEND_NOTLINE:
                {  
                    mvwprintw(tips_win, 1 , 2 , "the person is not online");
                    wrefresh(tips_win);
                    break;
                }

                case ADS_OK:
                {  
                    mvwprintw(tips_win, 1 , 2 , "Advertise ok!!");
                    wrefresh(tips_win);
                    break;
                }

                case ADS:
                {  
                    strcpy(ads_buf,r_buf.msg);

                    break;
                }

                case CILENT_CHANGE:
                {
                    show();
                    break;
                }



                /*
                
                case HI_OK:
                {
                    printf("快捷表情发送成功!\n");
                    break;
                }

                case HI_1:
                {
                    printf("%s 对大家做了个表情  →_→  (怀疑)\n",r_buf.name);
                    break;
                }

                case HI_2:
                {
                    printf("%s 对大家做了个表情  >_<|||   (尴尬)\n",r_buf.name);
                    break;
                }
                case HI_3:
                {
                    printf("%s 对大家做了个表情  O(∩_∩)O   (微笑)\n",r_buf.name);
                    break;
                }

                case HI_4:
                {
                    printf("%s 对大家做了个表情  (+﹏+)  (感动)\n",r_buf.name);
                    break;
                }

                case HI_5:
                {
                    printf("%s 对大家做了个表情  (*^﹏^*)    (羞涩)\n",r_buf.name);
                    break;
                }

                case HI_6:
                {
                    printf("%s 对大家做了个表情 大骂 (((m -_-)mb (什么龟)\n",r_buf.name);
                    break;
                }

                */


            }

            clear_flag = CLEAR_START;
        }
    }

}
示例#4
0
int
main(int argc, char **argv)
{
	struct timespec ts_a, ts_b;
	double elapsed;
	char *file_path;
	char *queue_model_str;
	unsigned num_messages;
	unsigned num_threads;
	fstrm_iothr_queue_model queue_model;

	if (argc != 5) {
		fprintf(stderr, "Usage: %s <FILE> <QUEUE MODEL> <NUM THREADS> <NUM MESSAGES>\n", argv[0]);
		fprintf(stderr, "\n");
		fprintf(stderr, "FILE is a filesystem path.\n");
		fprintf(stderr, "QUEUE MODEL is the string 'SPSC' or 'MPSC'.\n");
		fprintf(stderr, "NUM THREADS is an integer.\n");
		fprintf(stderr, "NUM MESSAGES is an integer.\n");
		return EXIT_FAILURE;
	}
	file_path = argv[1];
	queue_model_str = argv[2];
	num_threads = atoi(argv[3]);
	num_messages = atoi(argv[4]);
	if (num_threads < 1) {
		fprintf(stderr, "%s: Error: invalid number of threads\n", argv[0]);
		return EXIT_FAILURE;
	}
	if (num_messages < 1) {
		fprintf(stderr, "%s: Error: invalid number of messages\n", argv[0]);
		return EXIT_FAILURE;
	}

	if (strcasecmp(queue_model_str, "SPSC") == 0) {
		queue_model = FSTRM_IOTHR_QUEUE_MODEL_SPSC;
	} else if (strcasecmp(queue_model_str, "MPSC") == 0) {
		queue_model = FSTRM_IOTHR_QUEUE_MODEL_MPSC;
	} else {
		fprintf(stderr, "%s: Error: invalid queue model\n", argv[0]);
		return EXIT_FAILURE;
	}

	printf("testing fstrm_iothr with file= %s "
	       "queue_model= %s "
	       "num_threads= %u "
	       "num_messages= %u\n",
	       file_path, queue_model_str, num_threads, num_messages);

	struct fstrm_file_options *fopt;
	fopt = fstrm_file_options_init();
	fstrm_file_options_set_file_path(fopt, file_path);
	struct fstrm_writer *w = fstrm_file_writer_init(fopt, NULL);
	assert(w != NULL);
	fstrm_file_options_destroy(&fopt);

	struct fstrm_iothr_options *iothr_opt;
	iothr_opt = fstrm_iothr_options_init();

	if (queue_model == FSTRM_IOTHR_QUEUE_MODEL_SPSC) {
		fstrm_iothr_options_set_num_input_queues(iothr_opt, num_threads);
	} else if (queue_model == FSTRM_IOTHR_QUEUE_MODEL_MPSC) {
		fstrm_iothr_options_set_num_input_queues(iothr_opt, 1);
	} else {
		assert(0); /* not reached */
	}
	fstrm_iothr_options_set_queue_model(iothr_opt, queue_model);

	struct fstrm_iothr *iothr = fstrm_iothr_init(iothr_opt, &w);
	assert(iothr != NULL);
	fstrm_iothr_options_destroy(&iothr_opt);

	struct consumer test_consumer;
	struct producer test_producers[num_threads];

	for (unsigned i = 0; i < num_threads; i++) {
		test_producers[i].iothr = iothr;
		test_producers[i].num_messages = num_messages;
	}

	if (queue_model == FSTRM_IOTHR_QUEUE_MODEL_SPSC) {
		for (unsigned i = 0; i < num_threads; i++) {
			test_producers[i].ioq = fstrm_iothr_get_input_queue(iothr);
			assert(test_producers[i].ioq != NULL);
		}
	} else if (queue_model == FSTRM_IOTHR_QUEUE_MODEL_MPSC) {
		struct fstrm_iothr_queue *ioq = fstrm_iothr_get_input_queue(iothr);
		assert(ioq != NULL);
		for (unsigned i = 0; i < num_threads; i++)
			test_producers[i].ioq = ioq;
	} else {
		assert(0); /* not reached */
	}

	my_gettime(CLOCK_MONOTONIC, &ts_a);

	printf("creating %u producer threads\n", num_threads);
	for (unsigned i = 0; i < num_threads; i++)
		pthread_create(&test_producers[i].thr, NULL, thr_producer, &test_producers[i]);

	printf("joining %u producer threads\n", num_threads);
	for (unsigned i = 0; i < num_threads; i++)
		pthread_join(test_producers[i].thr, (void **) NULL);

	printf("destroying fstrm_iothr object\n");
	fstrm_iothr_destroy(&iothr);

	my_gettime(CLOCK_MONOTONIC, &ts_b);
	my_timespec_sub(&ts_a, &ts_b);
	elapsed = my_timespec_to_double(&ts_b);
	printf("completed in %.2f seconds\n", elapsed);

	int res = consume_input(&test_consumer, file_path);
	if (res != EXIT_SUCCESS)
		return res;

	struct producer_stats pstat_sum;
	memset(&pstat_sum, 0, sizeof(pstat_sum));
	for (unsigned i = 0; i < num_threads; i++) {
		pstat_sum.count_generated += test_producers[i].pstat.count_generated;
		pstat_sum.count_submitted += test_producers[i].pstat.count_submitted;
		pstat_sum.bytes_generated += test_producers[i].pstat.bytes_generated;
		pstat_sum.bytes_submitted += test_producers[i].pstat.bytes_submitted;
	}
	printf("count_generated= %" PRIu64 "\n", pstat_sum.count_generated);
	printf("bytes_generated= %" PRIu64 "\n", pstat_sum.bytes_generated);
	printf("count_submitted= %" PRIu64 "\n", pstat_sum.count_submitted);
	printf("bytes_submitted= %" PRIu64 "\n", pstat_sum.bytes_submitted);

	printf("count_received= %" PRIu64 " (%.3f)\n",
	       test_consumer.cstat.count_received,
	       (test_consumer.cstat.count_received + 0.0) / (pstat_sum.count_generated + 0.0)
	);
	printf("bytes_received= %" PRIu64 " (%.3f)\n",
	       test_consumer.cstat.bytes_received,
	       (test_consumer.cstat.bytes_received + 0.0) / (pstat_sum.bytes_generated + 0.0)
	);

	assert(pstat_sum.count_submitted == test_consumer.cstat.count_received);
	assert(pstat_sum.bytes_submitted == test_consumer.cstat.bytes_received);

	putchar('\n');

	return EXIT_SUCCESS;
}