Пример #1
0
void chpl_task_sleep(double secs) {
  double t, end_t;
  enter_();
  t = cur_time();
  end_t = t + secs;
  while (t < end_t) {
    myth_yield();
    t = cur_time();
  }
  return_from_();
}
Пример #2
0
int main(int argc, char** argv) {
  int N = 10000000;
  double t0 = cur_time();
  /*int np = check_primes(2, N); */
  if (argc != 3) {
    fprintf(stderr, "usage: %s NTHREADS JOBS", argv[0]);
    exit(1);
  }
  int npthread = atoi(argv[1]);
  int jobs = atoi(argv[2]);
  int np = parallel_prime_mutex(2, N, npthread, jobs);
  double t1 = cur_time();
  printf("%d primes in %f sec\n", np, t1 - t0);
  return 0;
}
	//private: real_type do_serve(customer_pointer const& ptr_customer, random_generator_type& rng)
	private: runtime_info_type do_serve(customer_pointer const& ptr_customer, random_generator_type& rng)
	{
		DCS_DEBUG_TRACE_L(3, "(" << this << ") BEGIN Service");//XXX

		// pre: make sure to not exceed the max # customer that can be served
		DCS_DEBUG_ASSERT( num_busy_ < ns_ );

		// pre: customer pointer must be a valid pointer
		DCS_DEBUG_ASSERT( ptr_customer );

		real_type cur_time(this->node().network().engine().simulated_time());
		real_type svc_time(0);

		typename traits_type::class_identifier_type class_id = ptr_customer->current_class();

        while ((svc_time = ::dcs::math::stats::rand(distrs_[class_id], rng)) < 0) ;

//		svc_time /= this->capacity_multiplier();

		runtime_info_type rt_info(ptr_customer, cur_time, svc_time);
		rt_info.server_id(num_busy_);
		rt_info.share(this->share());
		rt_info.capacity_multiplier(this->capacity_multiplier());

		servers_[num_busy_] = ptr_customer;
//		customers_servers_[ptr_customer->id()] = num_busy_;

		++num_busy_;

		DCS_DEBUG_TRACE_L(3, "(" << this << ") Generated service for customer: " << *ptr_customer << " - Service Demand: " << rt_info.service_demand() << " --> Runtime: " << svc_time);//XXX

		DCS_DEBUG_TRACE_L(3, "(" << this << ") END Service");//XXX

		return rt_info;
	}
Пример #4
0
static screen_t *
screen_init(const int _din, const int _sclk, const int _dc, const int _rst, const int _cs, const int contrast)
{
	screen_t *scretp;

	if (wiringPiSetup() == -1) {
		syslog(LOG_LOCAL0|LOG_ERR, "wiringPi-Error");
		return (NULL);
	}
	if (pcf8591Setup(200, 0x48) == -1) {
		syslog(LOG_LOCAL0|LOG_ERR, "wiringPi-Error");
		return (NULL);
  	}
  
	/* init and clear lcd */
	LCDInit(_sclk, _din, _dc, _cs, _rst, contrast);
	LCDclear();
  
	/* show logo */
	LCDshowLogo();

	if ((scretp = calloc(1, sizeof(screen_t))) == NULL) {
		return (NULL);
	}
	scretp->sc_contrast = contrast;
	snprintf(scretp->sc_line1_buf, sizeof(scretp->sc_line1_buf), "Pilab");
	cur_time(scretp->sc_line2_buf, sizeof(scretp->sc_line2_buf));
	return (scretp);
}
Пример #5
0
static void log_connection_close(void *data){
     	request_rec *r = (request_rec*) data;
	double end_time = cur_time();
	double total_time = end_time - output_start_time;
	
	ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
					"[mod_track] Total time from sending the first byte to competion of sending data  = %f ",total_time );
}
Пример #6
0
static int log_pre_conn(conn_rec *c, void *csd){

	start_time =  cur_time();

       // ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c,
       //               "PRE_ACCEPT= %f", start_time);

	return OK;
}
Пример #7
0
static int log_header_parser(request_rec *r){

        double end_time = cur_time();
        double total_time = end_time - start_time;

        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                      "[mod_track] Time elapsed since connection esablishment to start parsing header = %f ", total_time);

        return OK;
}
Пример #8
0
static int log_post_conn(request_rec *r){

	double end_time = cur_time();

	double total_time = end_time - start_time;

        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                      "[mod_track] Time elapsed since connection esablishment to completion of data arrival = %f ", total_time);

	return OK;
}
int main(int argc, char ** argv) {
  long nthreads = (argc > 1 ? atol(argv[1]) : 100000);
  arg_t arg[1] = { { 0, nthreads, 0 } };
  long i;
  for (i = 0; i < 3; i++) {
    double t0 = cur_time();
    myth_thread_t tid = myth_create(f, arg);
    myth_join(tid, 0);
    double t1 = cur_time();
    double dt = t1 - t0;
    if (arg->r == (nthreads - 1) * nthreads / 2) {
      printf("OK\n");
      printf("%ld thread creation/join in %.9f sec (%.3f per sec)\n",
	     nthreads, dt, nthreads / dt);
    } else {
      printf("NG\n");
      return 1;
    }
  }
  return 0;
}
Пример #10
0
static int log_output_start(ap_filter_t *f, apr_bucket_brigade *in){

    	request_rec *r = f->r;
    	output_start_time = cur_time();

	//     	ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
	//                    "OUTPUT_TIME_S= %f",output_start_time );

	ap_remove_output_filter(f);
	return ap_pass_brigade(f->next, in);

}
Пример #11
0
int main(int argc, char ** argv)
{
  int n_items       = (argc > 1 ? atoi(argv[1]) : 100000); /* 挿入/削除される要素数 */
  int n_enq_threads = (argc > 2 ? atoi(argv[2]) : 1);	   /* 挿入役のスレッド数 */
  int n_deq_threads = (argc > 3 ? atoi(argv[3]) : 1);	   /* 削除役のスレッド数 */
  int n_threads = n_enq_threads + n_deq_threads;
  thread_arg_t args = malloc(sizeof(struct thread_arg) * n_threads);
  queue_t q = new_queue();
  /* a : 答えのチェック用配列.
     (i) 最初はすべて0.
     (ii) deqするスレッドが値 x を取り出したら a[x] = 1 とする 
     (iii) 全要素が1になっていたら正解 */
  char * a = calloc(1, n_items);
  int i;
  double t0 = cur_time();
  /* スレッドを n_threads 個作る */
  for (i = 0; i < n_threads; i++) {
    args[i].idx = i;
    args[i].n_enq_threads = n_enq_threads;
    args[i].n_deq_threads = n_deq_threads;
    args[i].n_items = n_items;
    args[i].q = q;
    args[i].a = a;
    pthread_create(&args[i].tid, NULL, thread_func, (void *)&args[i]);
  }
  /* 終了待ち */
  for (i = 0; i < n_threads; i++) {
    pthread_join(args[i].tid, NULL);
  }
  /* すべての要素が取り出されているかチェック */
  for (i = 0; i < n_items; i++) {
    assert(a[i] == 1);
  }
  double t1 = cur_time();
  printf("OK: elapsed time: %f\n", t1 - t0);
  return 0;
}
Пример #12
0
void on_game_over(const bool IS_WIN)
{
    std::vector<Highscore_entry> entries = entries_sorted();

    final_score_ = new Highscore_entry(cur_time().time_str(Time_type::minute, true),
                                       map::player->name_a(),
                                       dungeon_master::xp(),
                                       dungeon_master::clvl(),
                                       map::dlvl,
                                       map::player->ins(),
                                       IS_WIN,
                                       player_bon::bg());

    entries.push_back(*final_score_);

    sort_entries(entries);

    write_file(entries);
}
Пример #13
0
 formatter(logger_base & l, level::type t) 
     : l(l)
     , t(t) 
 {
     str << cur_time() << " " << t;
 }
Пример #14
0
static int
collect_article(register group_header * gh, article_number art_num)
{
    FILE           *art_file;
    news_header_buffer nhbuf, dgbuf;
    article_header  art_hdr;
    int             mode, count;
    cross_post_number *cp_ptr;
    long            age;

    count = 0;

    db_hdr.dh_number = art_num;

    /* get article header */

    art_hdr.a_number = art_num;
    art_hdr.hpos = 0;
    art_hdr.lpos = (off_t) 0;
    art_hdr.flag = 0;

    mode = FILL_NEWS_HEADER | FILL_OFFSETS | SKIP_HEADER;
    if ((gh->master_flag & (M_CONTROL | M_NEVER_DIGEST | M_ALWAYS_DIGEST)) == 0)
	mode |= DIGEST_CHECK;

#ifdef NNTP
    if ((gh->master_flag & M_ALWAYS_DIGEST) == 0)
	mode |= LAZY_BODY;
#endif

    if ((art_file = open_news_article(&art_hdr, mode, nhbuf, (char *) NULL)) == NULL) {

#ifdef NNTP
	if (nntp_failed) {

	    /*
	     * connection to nntp_server is broken stop collection of
	     * articles immediately
	     */
	    return -1;
	}
#endif

	/*
	 * it is not really necessary to save anything in the data file we
	 * simply use the index file to get the *first* available article
	 */
	return 0;
    }
    if (art_file == (FILE *) 1) {	/* empty file */
	if (!ignore_bad_articles)
	    return 0;
	news.ng_groups = NULL;
	art_file = NULL;
    } else if (max_article_age &&	/* == 0 if use_nntp */
	       (gh->master_flag & M_INCLUDE_OLD) == 0 &&
	       (age = m_time(art_file)) < max_article_age) {

	if (remove_bad_articles)
	    unlink(group_path_name);

	log_entry('O', "%sold article (%ld days): %s/%ld",
		  remove_bad_articles ? "removed " : "",
		  (cur_time() - age) / (24 * 60 * 60),
		  current_group->group_name, (long) art_num);
	bad_count++;
	fclose(art_file);
	return 0;
    }
    if (ignore_bad_articles && news.ng_groups == NULL) {
	char           *rem = "";

	if (!use_nntp && remove_bad_articles) {
	    unlink(group_path_name);
	    rem = "removed ";
	}
	log_entry('B', "%sbad article: %s/%ld", rem,
		  current_group->group_name, (long) art_num);
	if (art_file != NULL)
	    fclose(art_file);
	bad_count++;
	return 0;
    }
    /* map cross-postings into a list of group numbers */

    db_hdr.dh_cross_postings = 0;

    if (gh->master_flag & M_CONTROL) {
	/* we cannot trust the Newsgroups: line in the control group */
	/* so we simply ignore it (i.e. use "Newsgroups: control") */
	goto dont_digest;
    }
    if (news.ng_groups) {
	char           *curg, *nextg;
	group_header   *gh1;

	for (nextg = news.ng_groups, cp_ptr = db_data.dh_cross; *nextg;) {
	    curg = nextg;

	    if ((nextg = strchr(curg, ',')))
		*nextg++ = NUL;
	    else
		nextg = "";

	    if (strcmp(gh->group_name, curg) == 0)
		gh1 = gh;
	    else if ((gh1 = lookup(curg)) == NULL)
		continue;

	    *cp_ptr++ = NETW_CROSS_EXT(gh1->group_num);
	    if (++db_hdr.dh_cross_postings == DBUF_SIZE)
		break;
	}
    }
    if (db_hdr.dh_cross_postings == 1)
	db_hdr.dh_cross_postings = 0;	/* only current group */

    if (gh->master_flag & M_NEVER_DIGEST)
	goto dont_digest;

    /* split digest */

    if ((gh->master_flag & M_ALWAYS_DIGEST) || (news.ng_flag & N_DIGEST)) {
	int             any = 0, cont = 1;

	skip_digest_body(art_file);

	while (cont && (cont = get_digest_article(art_file, dgbuf)) >= 0) {

	    if (any == 0) {
		build_hdr(DH_DIGEST_HEADER);	/* write DIGEST_HEADER */
		count++;
		db_hdr.dh_cross_postings = 0;	/* no cross post in sub */
		any++;
	    }
	    build_hdr(DH_SUB_DIGEST);	/* write SUB_DIGEST */
	    count++;
	}

	if (any)
	    goto finish;
    }
    /* not a digest */

dont_digest:

    build_hdr(DH_NORMAL);	/* normal article */
    count++;

finish:

    if (gh->master_flag & M_AUTO_ARCHIVE) {

#ifdef NNTP
	FILE           *f;
	f = nntp_get_article(art_num, 0);
	do_auto_archive(gh, f, art_num);
	fclose(f);
#else
	do_auto_archive(gh, art_file, art_num);
#endif				/* NNTP */
    }
    fclose(art_file);

    return count;
}
Пример #15
0
/*
This is the main python handler that will transform and treat the client html request.
return 1 if we have found a python object to treat the requested uri
return 0 if not (page not found)
return -1 in case of problem
return -2 in case the request command is not implemented
*/
int python_handler(struct client *cli)
{
    PyObject *pydict, *pydummy;
    int ret;

    if (debug)
        printf("host=%s,port=%i:python_handler:HEADER:\n%s**\n", cli->remote_addr, cli->remote_port, cli->input_header);
    //  1)initialise environ
    PyObject *pyenviron_class=PyObject_GetAttrString(py_base_module, "Environ");
    if (!pyenviron_class)
    {
        printf("load Environ failed from base module");
        exit(1);
    }
    PyObject *pyenviron=PyObject_CallObject(pyenviron_class, NULL);
    if (!pyenviron)
    {
        printf("Failed to create an instance of Environ");
        exit(1);
    }
    Py_DECREF(pyenviron_class);
    //  2)transform headers into a dictionary and send it to environ.update_headers
    pydict=header_to_dict(cli);
    if (pydict==Py_None)
    {
        Py_DECREF(pyenviron);
        return -500;
    }
    update_environ(pyenviron, pydict, "update_headers");
    Py_DECREF(pydict);
    //  2bis) we check if the request method is supported
    PyObject *pysupportedhttpcmd = PyObject_GetAttrString(py_base_module, "supported_HTTP_command");
    pydummy = PyString_FromString(cli->cmd);
    if (PySequence_Contains(pysupportedhttpcmd,pydummy)!=1)
    {
        //return not implemented
        Py_DECREF(pysupportedhttpcmd);
        Py_DECREF(pydummy);
        Py_DECREF(pyenviron);
        return -501;
    }
    Py_DECREF(pydummy);
    //  2ter) we treat directly the OPTIONS command
    if (strcmp(cli->cmd,"OPTIONS")==0)
    {
        pydummy=PyString_FromFormat("HTTP/1.0 200 OK\r\nServer: %s\r\nAllow: ", VERSION) ;
        PyObject *pyitem;
        int index, max;
        max = PyList_Size(pysupportedhttpcmd);
        for (index=0; index<max; index++)
        {
            pyitem=PyList_GetItem(pysupportedhttpcmd, index);  // no need to decref pyitem
            PyString_Concat(&pydummy, PyObject_Str(pyitem));
            if (index<max-1)
                PyString_Concat(&pydummy, PyString_FromString(", "));
        }
        PyString_Concat(&pydummy, PyString_FromString("\r\nContent-Length: 0\r\n\r\n"));
        strcpy(cli->response_header,PyString_AsString(pydummy));
        cli->response_header_length=strlen(cli->response_header);
        cli->response_content=PyList_New(0);
        Py_DECREF(pyenviron);
        return 1;
    }
    Py_DECREF(pysupportedhttpcmd);
    //  3)find if the uri is registered
    if (handle_uri(cli)!=1)
    {
        if (py_generic_cb==NULL)
        {
            //printf("uri not found\n");
            Py_DECREF(pyenviron);
            return 0;
        }
        else
        {
            cli->wsgi_cb=py_generic_cb;
            Py_INCREF(cli->wsgi_cb);
            cli->uri_path=(char *)calloc(1, sizeof(char));
            strcpy(cli->uri_path,"");
        }
    }
    // 4) build path_info, ...
    pydict=py_build_method_variables(cli);
    update_environ(pyenviron, pydict, "update_uri");
    Py_DECREF(pydict);
    // 5) in case of POST, put it into the wsgi.input
    if (strcmp(cli->cmd,"POST")==0)
    {
        ret=manage_header_body(cli, pyenviron);
        if (ret < 0) {
            return ret;
        }
    }
    //  6) add some request info
    pydict=py_get_request_info(cli);
    update_environ(pyenviron, pydict, "update_from_request");
    Py_DECREF(pydict);
    // 7) build response object
    PyObject *pystart_response_class=PyObject_GetAttrString(py_base_module, "Start_response");
    PyObject *pystart_response=PyInstance_New(pystart_response_class, NULL, NULL);
    Py_DECREF(pystart_response_class);
    // 7b) add the current date to the response object
    PyObject *py_response_header=PyObject_GetAttrString(pystart_response,"response_headers");
    char *sftime;
    sftime=cur_time(date_format);
    pydummy = PyString_FromString(sftime);
    PyDict_SetItemString(py_response_header, "Date", pydummy);
    Py_DECREF(pydummy);
    Py_DECREF(py_response_header);
    free(sftime);
    pydummy = PyString_FromString(VERSION);
    PyDict_SetItemString(py_response_header, "Server", pydummy);
    Py_DECREF(pydummy);

    // 8) execute python callbacks with his parameters
    PyObject *pyarglist = Py_BuildValue("(OO)", pyenviron, pystart_response );
    cli->response_content = PyEval_CallObject(cli->wsgi_cb,pyarglist);
    if (cli->response_content!=NULL)
    {
        if ((PyFile_Check(cli->response_content)==0) && (PyIter_Check(cli->response_content)==1)) {
            //This is an Iterator object. We have to execute it first
            cli->response_content_obj = cli->response_content;
            cli->response_content = PyIter_Next(cli->response_content_obj);
        }
    }
    Py_DECREF(pyarglist);
    Py_XDECREF(cli->wsgi_cb);
    if (cli->response_content!=NULL)
    {
        PyObject *pydummy = PyObject_Str(pystart_response);
        strcpy(cli->response_header,PyString_AsString(pydummy));
        cli->response_header_length=strlen(cli->response_header);
        Py_DECREF(pydummy);
    }
    else
        //python call return is NULL
    {
        printf("Python error!!!\n");
        if (str_append3(cli->response_header,"HTTP/1.0 500 Not found\r\nContent-Type: text/html\r\nServer: ", VERSION, "\r\n\r\n", MAXHEADER)<0)
        {
            printf("ERROR!!!! Response header bigger than foreseen:%i", MAXHEADER);
            printf("HEADER TOP\n%s\nHEADER BOT\n", cli->response_header);
            return -1;
        }
        cli->response_header_length=strlen(cli->response_header);
        if (PyErr_Occurred())
        {
            //get_traceback();py_b
            PyObject *pyerrormsg_method=PyObject_GetAttrString(py_base_module,"redirectStdErr");
            PyObject *pyerrormsg=PyObject_CallFunction(pyerrormsg_method, NULL);
            Py_DECREF(pyerrormsg_method);
            Py_DECREF(pyerrormsg);
            PyErr_Print();
            PyObject *pysys=PyObject_GetAttrString(py_base_module,"sys");
            PyObject *pystderr=PyObject_GetAttrString(pysys,"stderr");
            Py_DECREF(pysys);
            /*             PyObject *pyclose_method=PyObject_GetAttrString(pystderr, "close");
                         PyObject *pyclose=PyObject_CallFunction(pyclose_method, NULL);
                         Py_DECREF(pyclose_method);
                         Py_DECREF(pyclose);*/
            PyObject *pygetvalue=PyObject_GetAttrString(pystderr, "getvalue");
            Py_DECREF(pystderr);
            PyObject *pyres=PyObject_CallFunction(pygetvalue, NULL);
            Py_DECREF(pygetvalue);
            printf("%s\n", PyString_AsString(pyres));
            //test if we must send it to the page
            PyObject *pysendtraceback = PyObject_GetAttrString(py_config_module,"send_traceback_to_browser");
            cli->response_content=PyList_New(0);
            if (pysendtraceback==Py_True) {
                pydummy = PyString_FromString("<h1>Error</h1><pre>");
                PyList_Append(cli->response_content, pydummy );
                Py_DECREF(pydummy);
                PyList_Append(cli->response_content, pyres);
                pydummy = PyString_FromString("</pre>");
                PyList_Append(cli->response_content, pydummy);
                Py_DECREF(pydummy);
            } else {
                PyObject *pyshortmsg = PyObject_GetAttrString(py_config_module,"send_traceback_short");
                PyList_Append(cli->response_content, pyshortmsg);
                Py_DECREF(pyshortmsg);
            }
            Py_DECREF(pyres);
            Py_DECREF(pysendtraceback);
        }
        else
        {
            cli->response_content=PyList_New(0);
            pydummy = PyString_FromString("Page not found.");
            PyList_Append(cli->response_content, pydummy );
            Py_DECREF(pydummy);
        }
    }
    Py_XDECREF(pystart_response);
    Py_XDECREF(pyenviron);
    return 1;
}
Пример #16
0
Файл: kill.c Проект: jheiss/nn
void
enter_kill_file(group_header * gh, char *pattern, register flag_type flag, int days)
{
    FILE           *killf;
    register kill_list_entry *kl;
    regexp         *re;
    char           *str;

    str = copy_str(pattern);

    if ((flag & KILL_CASE_MATCH) == 0)
        fold_string(str);

    if (flag & KILL_ON_REGEXP) {
        re = regcomp(pattern);
        if (re == NULL)
            return;
    } else
        re = NULL;

    killf = open_file(relative(nn_directory, KILL_FILE), OPEN_APPEND);
    if (killf == NULL) {
        msg("cannot create kill file");
        return;
    }
    if (days >= 0) {
        if (days == 0)
            days = 30;
        fprintf(killf, "%ld:", (long) (cur_time() + days DAYS));
    }
    if (gh)
        fputs(gh->group_name, killf);
    fputc(':', killf);

    if (flag & KILL_UNLESS_MATCH)
        fputc(EXT_KILL_UNLESS_MATCH, killf);
    if (flag & AUTO_KILL)
        fputc(EXT_AUTO_KILL, killf);
    if (flag & AUTO_SELECT)
        fputc(EXT_AUTO_SELECT, killf);
    if (flag & ON_FOLLOW_UP)
        fputc(EXT_ON_FOLLOW_UP, killf);
    if (flag & ON_NOT_FOLLOW_UP)
        fputc(EXT_ON_NOT_FOLLOW_UP, killf);
    if (flag & ON_ANY_REFERENCES)
        fputc(EXT_ON_ANY_REFERENCES, killf);
    if (flag & ON_SENDER)
        fputc(EXT_ON_SENDER, killf);
    if (flag & ON_SUBJECT)
        fputc(EXT_ON_SUBJECT, killf);
    if (flag & KILL_CASE_MATCH)
        fputc(EXT_KILL_CASE_MATCH, killf);
    if (flag & KILL_ON_REGEXP)
        fputc(EXT_KILL_ON_REGEXP, killf);
    fputc(':', killf);

    fput_pattern(pattern, killf);
    fputc(NL, killf);

    fclose(killf);
    rm_kill_file();

    kl = newobj(kill_list_entry, 1);

    latest_kl_entry.kill_pattern = kl->kill_pattern = str;
    latest_kl_entry.kill_regexp = kl->kill_regexp = re;
    latest_kl_entry.kill_flag = kl->kill_flag = flag;
    latest_kl_entry.next_kill = NULL;

    if (gh) {
        kl->next_kill = (kill_list_entry *) (gh->kill_list);
        gh->kill_list = (char *) kl;
    } else {
        kl->next_kill = global_kill_list;
        global_kill_list = kl;
    }
}
Пример #17
0
int main(){
		int gender;
		int wealthpercentile;
		int i,j,l;
		int deductgrid;
		int wealth;
		int wx;
		int grid;
		int temp_test;
		int Sstart;


		double alpha;
		int offset;
	    char filename[11]={"table.txt"};


		task_group tasks;

		time_t time_began,time_end;


		/*
		output variable 
		*/

		//memset(&CalcStruct[0],0,sizeof(CALCSTRUCT));

		gender=1;				//0 is female 1 is male
		deductgrid=DEDUCTGRID;
		//wealthpercentile=3;		//0-9 different wealth distribution 


		/*
		calculating declaration:
		this time run for gird*4 total size 
		from 4-8
		so the program make some adjustment
		
		*/


		cout<<"calculating declaration: this time run for gird*4 total size from 4-8 \n so the program make some adjustment"<<endl;



				
		cur_time();
		offset =0;
		Sstart=START;

		Parallel_LTCI  *LTCI[10];

		
		{
			

		for(gender=1;gender<2;gender++){
		// initilize the class of LTCI 
		for(wealthpercentile=Sstart;wealthpercentile<10-offset;wealthpercentile ++)
		{
		switch (wealthpercentile){
		case 0: wealth=40000;	alpha=0.98;	wx=0;		grid=20;	break;
		case 1: wealth=58450;	alpha=0.98;	wx=0;		grid=20;	break;
		case 2: wealth=93415;	alpha=0.91;	wx=20000;	grid=40;	break;
		case 3: wealth=126875;	alpha=0.82;	wx=30000;	grid=75;	break;
		case 4: wealth=169905;	alpha=0.70;	wx=10000;	grid=100;	break;
		case 5: wealth=222570;	alpha=0.60;	wx=50000;	grid=130;	break;
		case 6: wealth=292780;	alpha=0.52;	wx=20000;	grid=175;	break;
		case 7: wealth=385460;	alpha=0.41;	wx=40000;	grid=225;	break;
		case 8: wealth=525955;	alpha=0.35;	wx=40000;	grid=300;	break;
		case 9: wealth=789475;	alpha=0.26;	wx=75000;	grid=450;	break;


		}
		//wealth =wealth*224.937/172.192;


		LTCI[int(wealthpercentile)-Sstart]=new Parallel_LTCI(wealthpercentile,gender,deductgrid,wealth,wx,grid,alpha);
		

		}
		

			calcSetup();
			inputData(gender);


			for(i=0;i<10-Sstart-offset;i++){
				Setup(LTCI[i]);
				inData(gender,LTCI[i]);

			}



		cout<<"calculating for 0:female 1: male ------"<<gender<<endl;
		cout<<"deductile period is : \t"<<deductgrid<<endl;
		cout<<"**********************************************"<<endl;
		cout<<"**********************************************"<<endl;




		/*task for 1 to 4*/
		
		tasks.run([&gender,&LTCI,&offset,&Sstart](){
			   // int wealthpercentile; 
			for(int wealthpercentile=Sstart;wealthpercentile<5-offset;wealthpercentile++)
				LTCI[wealthpercentile-Sstart]->comput();



		});
		////	/*task for  4*/

		//tasks.run([&gender,&LTCI,&Sstart](){
		//	int wealthpercentile=4-Sstart; 				
		//	LTCI[wealthpercentile]->comput();

		//});



	//	/*task for  5*/
	
			tasks.run([&gender,&LTCI,&Sstart](){
				int wealthpercentile=5-Sstart; 				
				LTCI[wealthpercentile]->comput();

				});

		 /*task for  6*/
			tasks.run([&gender,&LTCI,&Sstart](){
				int wealthpercentile=6-Sstart; 				
				LTCI[wealthpercentile]->comput();

			});


	//		/*task for 7*/
		tasks.run([&gender,&LTCI,&Sstart](){
			int wealthpercentile=7-Sstart;

			LTCI[wealthpercentile]->comput();
		});

			/*task for 8*/
			tasks.run([&gender,&LTCI,&Sstart](){
				int wealthpercentile=8-Sstart;

				LTCI[wealthpercentile]->comput();
			});


			/*task for  9*/
			tasks.run_and_wait([&gender,&LTCI,&Sstart](){
				int wealthpercentile=9-Sstart;			
				LTCI[wealthpercentile]->comput();			

			});


		}
		// output some variables

		if(para.MWcount==0){if (gender==0) para.MW=1.058; else para.MW=0.5;}
		else if(para.MWcount==1){if (gender==0) para.MW=0.6; else para.MW=0.3;}
		else if(para.MWcount==2){if (gender==0) para.MW=1.358127; else para.MW=0.6418727;}
		else if(para.MWcount==3){if (gender==0) para.MW=1.358127; else para.MW=0.6418727;}
		else if(para.MWcount==4){if (gender==0) para.MW=1; else para.MW=1;}

		ofstream out(filename, ios::app);
		if (out.is_open())   
		{
// 			out<<"*********************************************************************"<<endl;
			out<<"deductile grid is :"<<deductgrid<<endl;
			for(i=0;i<10-offset-Sstart;i++) record_result(i,LTCI[i]);
// 			out<<"table  "<<endl;
// 			for(i=0;i<10-offset-Sstart;i++){
// 				out<<i+Sstart<<"0th : \t 1 \t 2 \t 3 \t 4"<<endl;
// 				out<<record.MUstar[i]/record.EPDVMedical[i]<<'\t';
// 				out<<record.Mstar[i]/record.EPDVMedical[i]<<"\t";
// 				out<<(record.MUstar[i] - record.Mstar[i])/record.Istarown[i]<<"\t";
// 				out<<(1-(record.Istarown[i]-(record.MUstar[i]-record.Mstar[i]))/(record.Istarown[i]/para.MW))<<"\t";
// 				out<<record.wequiv[i]<<"\t";
// 				out<<endl;
// 			}
			out<<"*********************************************************************"<<endl;
			out<<"----------------------------------------------------------------------"<<endl;
			out<<"---------------------------------raw data---------------------------- "<<endl;
			out<<"----------------------------------------------------------------------"<<endl;
			out<<"index for the data:  S_Madicaid \t S_Insurance \t S_Madicaid_NI \t S_Medcost \t S_wequiv \t S_medicare \t S_med_joint_NI \t S_med_joint \t S_OOP \t S_OOP_NI"<<endl;
			for(i=0;i<10-offset-Sstart;i++) out<<record.S_Madicaid[i]<<"\t";
			out<<endl;			
			for(i=0;i<10-offset-Sstart;i++) out<<record.S_Insurance[i]<<"\t";
			out<<endl;
			for(i=0;i<10-offset-Sstart;i++) out<<record.S_Madicaid_NI[i]<<"\t";
				out<<endl;	
			for(i=0;i<10-offset-Sstart;i++) out<<record.S_Medcost[i]<<"\t";
				out<<endl;	
			for(i=0;i<10-offset-Sstart;i++) out<<record.S_wequiv[i]<<"\t";
				out<<endl;
			for(i=0;i<10-offset-Sstart;i++) out<<record.S_medicare[i]<<"\t";
				out<<endl;
			for(i=0;i<10-offset-Sstart;i++) out<<record.S_med_joint_NI[i]<<"\t";
				out<<endl;
			for(i=0;i<10-offset-Sstart;i++) out<<record.S_med_joint[i]<<"\t";
				out<<endl;
			for(i=0;i<10-offset-Sstart;i++) out<<record.S_OOP[i]<<"\t";
				out<<endl;
			for(i=0;i<10-offset-Sstart;i++) out<<record.S_OOP_NI[i]<<"\t";
				out<<endl;
			out<<"EPDVMedical  wequive Mstar Istar  MUstar Istarnon "<<endl;
			for(i=0;i<10-offset-Sstart;i++) out<<record.EPDVMedical[i]<<"\t";
				out<<endl;
			for(i=0;i<10-offset-Sstart;i++) out<<record.wequiv[i]<<"\t";
				out<<endl;	
			for(i=0;i<10-offset-Sstart;i++) out<<record.Mstar[i]<<"\t";
				out<<endl;
			for(i=0;i<10-offset-Sstart;i++) out<<record.Istarown[i]<<"\t";
				out<<endl;	
			for(i=0;i<10-offset-Sstart;i++) out<<record.MUstar[i]<<"\t";
				out<<endl;
			for(i=0;i<10-offset-Sstart;i++) out<<record.Istarnone[i]<<"\t";
				out<<endl;	



			out.close();  

		}


		for(i=0;i<10-offset-START;i++) delete LTCI[i];


	}



		system("pause");
		return 0;


	}
Пример #18
0
int
do_collect(void)
{
    register group_header *gh;
    long            col_article_count, temp;
    int             col_group_count;
    time_t          start_time;

    start_time = cur_time();
    col_article_count = col_group_count = 0;
    current_group = NULL;	/* for init_group */
    temp = 0;

    Loop_Groups_Header(gh) {
	if (s_hangup) {
	    temp = -1;
	    break;
	}
	if (gh->master_flag & M_IGNORE_GROUP)
	    continue;

	if (gh->master_flag & M_MUST_CLEAN)
	    clean_group(gh);

	if (gh->last_db_article == gh->last_a_article) {
	    if (gh->master_flag & M_BLOCKED)
		goto unblock_group;
	    continue;
	}
	if (!init_group(gh)) {
	    if ((gh->master_flag & M_NO_DIRECTORY) == 0) {
		log_entry('R', "%s: no directory", gh->group_name);
		gh->master_flag |= M_NO_DIRECTORY;
	    }
	    gh->last_db_article = gh->last_a_article;
	    gh->first_db_article = gh->last_a_article;	/* OBS: not first */
	    gh->master_flag &= ~(M_EXPIRE | M_BLOCKED);
	    db_write_group(gh);
	    continue;
	}
	if (gh->master_flag & M_NO_DIRECTORY) {
	    /* The directory has been created now */
	    gh->master_flag &= ~M_NO_DIRECTORY;
	    clean_group(gh);
	}
	temp = collect_group(gh);

#ifdef NNTP
	if (temp < 0) {
	    /* connection broken */
	    gh->master_flag &= ~M_EXPIRE;	/* remains blocked */
	    db_write_group(gh);
	    break;
	}
#endif

	if (temp > 0) {
	    col_article_count += temp;
	    col_group_count++;
	}
unblock_group:
	gh->master_flag &= ~(M_EXPIRE | M_BLOCKED);
	db_write_group(gh);
    }

    if (col_article_count > 0)
	log_entry('C', "Collect: %ld art, %d gr, %ld s",
		  col_article_count, col_group_count,
		  cur_time() - start_time);

    return temp > 0;		/* return true IF we got articles */
}
	//TODO: Test-Me!!
	private: void do_update_service()
	{
		DCS_DEBUG_TRACE_L(3, "(" << this << ") BEGIN Do-Update-Service (Clock: " << this->node().network().engine().simulated_time() << ")");//XXX

		// Check if there is at least one busy server.
		if (num_busy_ > 0)
		{
			typedef typename server_container::const_iterator iterator;

			real_type new_share(this->share());
			real_type new_multiplier(this->capacity_multiplier());

			// Check if we really need to update currently running customers
			if (::dcs::math::float_traits<real_type>::approximately_equal(old_share_, new_share)
				&& ::dcs::math::float_traits<real_type>::approximately_equal(old_multiplier_, new_multiplier))
			{
				// Share is not changed -> avoid to update customers and reschedule their end-of-service events

				DCS_DEBUG_TRACE_L(3, "(" << this << ") Share/Multiplier not changed: " << old_share_ << " vs. " << new_share << " / " << old_multiplier_ << " vs. " << new_multiplier);

				return;
			}

			real_type cur_time(this->node().network().engine().simulated_time());
			iterator end_it(servers_.end());
			for (iterator it = servers_.begin(); it != end_it; ++it)
			{
				uint_type sid(it->first);
				customer_pointer ptr_customer(it->second);

				// paranoid-check: null
				DCS_DEBUG_ASSERT( ptr_customer );

				DCS_DEBUG_TRACE_L(3, "(" << this << ") Running Customer ID: " << ptr_customer->id());

				runtime_info_type& rt_info(this->info(ptr_customer));

				// paranoid-check: paranoid check
				DCS_DEBUG_ASSERT( rt_info.server_id() == sid );

				DCS_DEBUG_TRACE_L(3, "Updating Customer: " << rt_info.get_customer() << " - Service demand: " << rt_info.service_demand() << " - Multiplier: " << this->capacity_multiplier() << " - old share: " << rt_info.share() << " - old runtime: " << rt_info.runtime() << " - old completed work: " << rt_info.completed_work() << " - old residual-work: " << rt_info.residual_work() << " (Clock: " << this->node().network().engine().simulated_time() << ")");//XXX

				// Increment the accumulated work done by this customer to date...
				rt_info.accumulate_work(cur_time);
				// ... Update the capacity multiplier,...
				rt_info.capacity_multiplier(new_multiplier);
				// ... Update the share,...
				rt_info.share(new_share);
				// ... Compute the new residual work
				real_type new_residual_time(rt_info.residual_work()/new_multiplier);
				// ... And reschedule the end-of-service
				this->node().reschedule_service(*ptr_customer, new_residual_time);

				DCS_DEBUG_TRACE_L(3, "Updated Customer: " << rt_info.get_customer() << " - Service demand: " << rt_info.service_demand() << " - Multiplier: " << this->capacity_multiplier() << " - new share: " << rt_info.share() << " - new runtime: " << rt_info.runtime() << " - new completed work: " << rt_info.completed_work() << " - new residual-work: " << rt_info.residual_work() << " (Clock: " << this->node().network().engine().simulated_time() << ")");//XXX
			}

			old_share_ = new_share;
			old_multiplier_ = new_multiplier;
		}

		DCS_DEBUG_TRACE_L(3, "(" << this << ") END Do-Update-Service (Clock: " << this->node().network().engine().simulated_time() << ")");//XXX
	}
Пример #20
0
int main(int argc, char *argv[])
{
#if ! SLOWER
	double start_time, end_time; // , speed;
#endif
#if ! defined size
 	int size = getint("Enter length of random mRNA sequence (2200 is average for human mRNA): ");  // Average (human) mRNA length is 2200; there's one that's 5000, though
#endif

        int i, j, k=-1;
	MAX_N_DECLS();
	char *options;
#if VERBOSE
#if CHECK_DEPENDENCES
	options = " [DV]";
#else
	options = " [V]";
#endif
#else
#if CHECK_DEPENDENCES
	options = " [D]";
#else
	options = "";
#endif
#endif

	printf("Running Nussinov RNA algorithm%s for sequence of length %d, random data with seed %d.\n",
	       options, size, SEED);

	if (size > MAX_SIZE) {
		fprintf(stderr, "size (%d) < MAX_SIZE (%d)\n", MAX_SIZE, size);
		exit(1);
	}

	/* seed it with a constant so we can check/compare the results */
	srand(SEED);
	for (i = 0; i < size; i++)
		seq[i] = rand() % 4;
	
#if ! SLOWER
	start_time = cur_time();
#endif

// "OPTION 1"
#pragma scop
	for (i = size-1; i >= 0; i--) {
		for (j=i+1; j<size; j++) {
#if VERBOSE
			fprintf(VERBOSE_OUT, "i, j, k = %d, %d, %d\n", i, j, k); /* outer k is -1 to indicate no k */
#endif
			MAX_N_START(i, j);
#if FOUR_WAY_MAX_WITH_REDUNDANCY
			if (j-1>=0)   MAX_N(i, j, N(i, j-1));
			if (i+1<size) MAX_N(i, j, N(i+1, j));
#endif
			if (j-1>=0 && i+1<size) {
			  if (i<j-1) MAX_N(i, j, N(i+1, j-1)+match(seq[i], seq[j]));  /* don't allow adjacent elements to bond */
			  else       MAX_N(i, j, N(i+1, j-1));
			}

			{
			int k;  /* local k to allow N macro to look at k and get -1 above and real k here */
			for (k=i+ZERO_IF_NO_REDUNDANCY; k<j; k++) {
#if VERBOSE
				fprintf(VERBOSE_OUT, "i, j, k = %d, %d, %d\n", i, j, k);
#endif
				MAX_N(i, j, N(i, k)+N(k+1, j));
			}
			} /* end of local k */
			MAX_N_END(i, j);
		}
	}
#pragma endscop

#if !SLOWER
	end_time = cur_time();
	printf("done.\nTime elapsed: %fs\n", end_time-start_time);
#endif
	printf("N(0, size-1) = %d\n", N(0, size-1));

	if (size <= PRINT_SIZE) {
		for (i=0; i<size; i++)
			printf("%3s ", base_print[seq[i]]);
		printf("\n");
		for(i = 0; i < size; i++) {
			for(j = 0; j < size; j++) printf("%3d ", debug_N(i, j));
			printf("\n");
		}
	}

	eassert(k == -1);

	return 0;
}
Пример #21
0
Файл: kill.c Проект: jheiss/nn
static int
compile_kill_file(void)
{
    FILE           *killf, *compf, *patternf, *dropf;
    comp_kill_header header;
    comp_kill_entry entry;
    time_t          now, age;
    long            cur_line_start;
    char            line[512];
    register char  *cp, *np;
    register int    c;
    group_header   *gh;
    flag_type       flag, fields[10];
    int             any_errors, nfield, nf, len;

    any_errors = 0;
    header.ckh_entries = header.ckh_regexp_size = 0;

    killf = open_file(relative(nn_directory, KILL_FILE),
                      OPEN_READ | DONT_CREATE);
    if (killf == NULL)
        return 0;

    dropf = NULL;

    compf = open_file(relative(nn_directory, COMPILED_KILL), OPEN_CREATE);
    if (compf == NULL)
        goto err1;

    new_temp_file();
    if ((patternf = open_file(temp_file, OPEN_CREATE)) == NULL)
        goto err2;

    msg("Compiling kill file");

    fseek(compf, sizeof(header), 0);

    now = cur_time();

next_entry:

    for (;;) {
        cur_line_start = ftell(killf);

        if (fgets(line, 512, killf) == NULL)
            break;

        cp = line;
        while (*cp && isascii(*cp) && isspace(*cp))
            cp++;
        if (*cp == NUL || *cp == '#' || !isascii(*cp))
            continue;

        if ((np = strchr(cp, ':')) == NULL)
            goto bad_entry;

        /* optional "age:" */

        if (np != cp && isdigit(*cp)) {
            *np++ = NUL;
            age = (time_t) atol(cp);
            if (age < now)
                goto drop_entry;
            cp = np;
            if ((np = strchr(cp, ':')) == NULL)
                goto bad_entry;
        }
        /* "group-name:"  or "/regexp:" or ":" for all groups */

        flag = COMP_KILL_ENTRY;

        if (np == cp) {
            entry.ck_group = -1;
            np++;
        } else {
            *np++ = NUL;
            if (*cp == '/') {
                entry.ck_group = (long) ftell(patternf);
                cp++;
                len = strlen(cp) + 1;
                if (fwrite(cp, sizeof(char), len, patternf) != len)
                    goto err3;
                flag |= GROUP_REGEXP | GROUP_REGEXP_HDR;
            } else {
                if ((gh = lookup(cp)) == NULL || (gh->master_flag & M_IGNORE_GROUP)) {
                    tprintf("Unknown/ignored group in kill file: %s\n", cp);
                    any_errors++;
                    goto drop_entry;
                }
                entry.ck_group = gh->group_num;
            }
        }

        /* flags */

        cp = np;
        nfield = 0;

        for (;;) {
            switch (*cp++) {
            case EXT_AND_MATCH:
            case EXT_OR_MATCH:
                fields[nfield++] = flag;
                flag &= ~(AND_MATCH | ON_SUBJECT | ON_SENDER |
                          KILL_CASE_MATCH | KILL_ON_REGEXP |
                          GROUP_REGEXP_HDR);
                flag |= (cp[-1] == EXT_AND_MATCH) ? AND_MATCH : OR_MATCH;
                continue;
            case EXT_AUTO_KILL:
                flag |= AUTO_KILL;
                continue;
            case EXT_AUTO_SELECT:
                flag |= AUTO_SELECT;
                continue;
            case EXT_ON_FOLLOW_UP:
                flag |= ON_FOLLOW_UP;
                continue;
            case EXT_ON_NOT_FOLLOW_UP:
                flag |= ON_NOT_FOLLOW_UP;
                continue;
            case EXT_ON_ANY_REFERENCES:
                flag |= ON_ANY_REFERENCES;
                continue;
            case EXT_ON_SUBJECT:
                flag |= ON_SUBJECT;
                continue;
            case EXT_ON_SENDER:
                flag |= ON_SENDER;
                continue;
            case EXT_KILL_CASE_MATCH:
                flag |= KILL_CASE_MATCH;
                continue;
            case EXT_KILL_UNLESS_MATCH:
                flag |= KILL_UNLESS_MATCH;
                continue;
            case EXT_KILL_ON_REGEXP:
                flag |= KILL_ON_REGEXP;
                continue;
            case ':':
                break;
            case NL:
                goto bad_entry;
            default:
                tprintf("Ignored flag '%c' in kill file\n", cp[-1]);
                any_errors++;
                continue;
            }
            break;
        }

        fields[nfield++] = flag;

        for (nf = 0; --nfield >= 0; nf++) {
            entry.ck_flag = flag = fields[nf];
            np = cp;
            if ((cp = get_pattern(np, &len, nfield)) == NULL)
                goto bad_entry;

            if ((flag & KILL_CASE_MATCH) == 0)
                fold_string(np);

            entry.ck_pattern_index = ftell(patternf);

            if (fwrite((char *) &entry, sizeof(entry), 1, compf) != 1)
                goto err3;

            if (fwrite(np, sizeof(char), len, patternf) != len)
                goto err3;

            header.ckh_entries++;
            if (flag & GROUP_REGEXP)
                header.ckh_regexp_size++;
        }
    }

    header.ckh_pattern_size = ftell(patternf);

    fclose(patternf);
    patternf = open_file(temp_file, OPEN_READ | OPEN_UNLINK);
    if (patternf == NULL)
        goto err2;

    header.ckh_pattern_offset = ftell(compf);

    while ((c = getc(patternf)) != EOF)
        putc(c, compf);

    fclose(patternf);

    rewind(compf);

    header.ckh_magic = COMP_KILL_MAGIC;
    header.ckh_db_check = master.db_created;

    if (fwrite((char *) &header, sizeof(header), 1, compf) != 1)
        goto err2;

    fclose(compf);
    fclose(killf);
    if (dropf != NULL)
        fclose(dropf);

    if (any_errors) {
        tputc(NL);
        any_key(0);
    }
    return 1;

bad_entry:
    tprintf("Incomplete kill file entry:\n%s", line);
    fl;
    any_errors++;

drop_entry:
    if (dropf == NULL) {
        dropf = open_file(relative(nn_directory, KILL_FILE),
                          OPEN_UPDATE | DONT_CREATE);
        if (dropf == NULL)
            goto next_entry;
    }
    fseek(dropf, cur_line_start, 0);
    fwrite("# ", sizeof(char), 2, dropf);
    goto next_entry;

err3:
    fclose(patternf);
    unlink(temp_file);
err2:
    fclose(compf);
    rm_kill_file();
err1:
    fclose(killf);
    if (dropf != NULL)
        fclose(dropf);

    msg("cannot compile kill file");
    return 0;
}