Beispiel #1
0
main()
{
	char *me = "inheritb";
	int context_original, context_1, context_2;
	int ptid, tid, gptid, cc;
	char buf[100];
	char machine[25];
	int i=0;

	gethostname( machine, 25 );

	printf( "%d:%s: t%x on machine <%s> with context %d.\n",
			i++, me, pvm_mytid(), machine, pvm_getcontext() );

	context_original = pvm_getcontext(); /* retrieve initial context */

	context_1 = pvm_newcontext();		 /* get new context 1 */
	pvm_setcontext( context_1 );		 /* activate new context 1 */

	printf( "%d:%s: t%x on machine <%s> with new #1 context %d ",
			i++, me, pvm_mytid(), machine, pvm_getcontext() );
	printf( "--> spawn 1st inherit2.\n" );

	/* start 1st inherit2 worker @ context 1 */
	pvm_spawn( "inherit2", (char **) 0, PvmTaskDefault, "", 1, &tid );

	context_2 = pvm_newcontext();		 /* get new context 2 */
	pvm_setcontext(context_2);			 /* activate new context 2 */

	printf( "%d:%s: t%x on machine <%s> with new #2 context %d ",
			i++, me, pvm_mytid(), machine, pvm_getcontext() );
	printf( "--> spawn 2nd inherit2.\n" );

	/* start 2nd inherit2 worker @ context 2 */
	pvm_spawn( "inherit2", (char **) 0, PvmTaskDefault, "", 1, &tid );

	/* receive from inherit2 worker 2 @ context 2 */
	cc = pvm_recv( -1, -1 );
	pvm_bufinfo( cc, (int *) 0, (int *) 0, &tid );
	pvm_upkstr( buf );
	printf( "%d:%s: t%x %s <-- received from 2nd inherit2.\n",
			i++, me, tid, buf);

	/* reactivate initial context 1*/
	pvm_setcontext(context_1);

	printf( "%d:%s: t%x on machine <%s> with new #1 context %d.\n",
			i++, me, pvm_mytid(), machine, pvm_getcontext() );

	/* receive from inherit2 worker 1 @ context 1 */
	cc = pvm_recv( -1, -1 );
	pvm_bufinfo( cc, (int *) 0, (int *) 0, &tid );
	pvm_upkstr( buf );
	printf( "%d:%s: t%x %s <-- received from 1st inherit2.\n",
			i++, me, tid, buf );

	pvm_exit();
	exit( 0 );
}
Beispiel #2
0
int main(void){
    int tid; /*this task id */
    int bufid, master, bytes, msgtag, source;
    char * graph_text = NULL;
    int **matrix;
    int degree, edges;
    int len;
    int i;
    int greycodeLength;
    
    tid = pvm_mytid();          /*enroll in pvm */
    master = pvm_parent();      /*get the master id */

    while (1){    
        /*Get the first graph */
        pvm_initsend(PvmDataDefault);
        pvm_pkstr("");                                        /*Just put something in the buffer */
        pvm_send(master, MSGREQTASK);                         /* Request a task */
        bufid = pvm_recv(master, MSGTASK);                    /* Get the task */
        pvm_bufinfo(bufid, &bytes, &msgtag, &source);  /* Get the size of the text */
        graph_text = malloc(bytes);                           
        pvm_upkstr(graph_text);                               /* Unpack the text */

        len = strlen(graph_text);
        if(graph_text[len - 1] == '\n')
            graph_text[len - 1] = '\0';
            

        matrix = create_matrix(graph_text, &degree);          /*Generate the appropriate matrix */
        populate_matrix(graph_text, matrix, &edges, degree);

        greycodeLength = 1 << degree;
        // Initialize code (where the greycode is stored)
        int * vals = calloc(2 * greycodeLength, sizeof(int));
        int ** code = malloc(greycodeLength * sizeof(int *)); 

       for(i = 0; i < greycodeLength; i++){                     /*assign rows within the allocated space */ 
          code[i] = vals + i*2;
        }
	
        /*** DO GREYCODE ALGORITHM ON THE MATRIX ***/
        if(greycode(degree, matrix, code) == 1){                      /*If we found a code */
            pvm_initsend(PvmDataDefault);
            pvm_pkstr(graph_text);
            pvm_send(master, MSGCODE);
        } else{                                               /*Didnt find a code */
            pvm_initsend(PvmDataDefault);
            pvm_pkstr(graph_text);
            pvm_send(master,MSGNOCODE);
        }

        destroy_matrix(matrix);                               /* Free the memory associated with the matrix */
        destroy_matrix(code);
	    free(graph_text);
    }
 
    pvm_exit();
    exit(0);

}
Beispiel #3
0
int receive_str(char *str)
{
   int info;

   PVM_FUNC(info, pvm_upkstr(str));

   return(info);
}
Beispiel #4
0
char* BBSClient::upkstr() {
	int len;
	char* s;
	if( pvm_upkint(&len, 1, 1)) { perror("upkstr"); }
	s = new char[len+1];
	pvm_upkstr(s);
	return s;
}
Beispiel #5
0
char* BBSDirect::upkstr() {
	int len;
	char* s;
//	printf("upkstr from %d\n", pvm_getrbuf());
	if( pvm_upkint(&len, 1, 1)) { perror("upkstr"); }
	s = new char[len+1];
	pvm_upkstr(s);
//	printf("upkstr returning |%s|\n", s);
	return s;
}
Beispiel #6
0
char* RecvStr(int tid, int MsgType)
{
  int   info, BufId, NBytes, MsgTag, MasterTid;
  char *s1, tmp_char[200];

  BufId = pvm_recv(tid, MsgType);
  info  = pvm_bufinfo( BufId, &NBytes, &MsgTag, &MasterTid);
  pvm_upkstr(tmp_char);
  s1 = (char *)malloc(strlen(tmp_char)+1);
  strcpy(s1, tmp_char);
  return(s1);
}
Beispiel #7
0
main()
{
	int cc, tid;
	char buf[100];

	printf("i'm t%x\n", pvm_mytid());

	cc = pvm_spawn("hello_other", (char**)0, 0, "", 1, &tid);

	if (cc == 1) {
		cc = pvm_recv(-1, -1);
		pvm_bufinfo(cc, (int*)0, (int*)0, &tid);
		pvm_upkstr(buf);
		printf("from t%x: %s\n", tid, buf);

	} else
		printf("can't start hello_other\n");

	pvm_exit();
	exit(0);
}
Beispiel #8
0
main() {
    int mytid, tid_master;
    char slave_name[NAMESIZE];
    char current_pass[NAMESIZE];
    char hash[NAMESIZE];
    char current_hash[NAMESIZE];
    char znalazl = 0 ;
    gethostname(slave_name, NAMESIZE+1);

    mytid = pvm_mytid();

    int inst = pvm_joingroup(GRP) ;

    int tid = pvm_gettid(GRP ,inst);

    int info = pvm_barrier(GRP,SLAVENUM + 1);

    pvm_recv( -1, MSG_MSTR );
    pvm_upkint(&tid_master, 1, 1 );
    pvm_upkstr(hash);
    //pvm_upkint(&k, 1, 1 );

    char poczatek = 97 + inst-1;
    char c1,c2,c3,c4,c5;
    for(c1 = poczatek ; c1 <= 'z' ; c1++) {
        for(c2 = 'a' ; c2 <= 'z' ; c2++) {
            for(c3 = 'a' ; c3 <= 'z' ; c3++) {
                for(c4 = 'a' ; c4 <= 'z' ; c4++) {
                    for(c5 = 'a' ; c5 <= 'z' ; c5++) {
                        current_hash[0] = c1 ;
                        current_hash[1] = c2 ;
                        current_hash[2] = c3 ;
                        current_hash[3] = c4 ;
                        current_hash[4] = c5 ;
                        current_hash[6] = 0 ;
                        current_hash = crypt(current_pass,"aa");
                        if(strcmp(current_hash,hash)==0) {
                            znalazl = 1;
                            break;
                        }
                        if(znalazl)
                            break ;
                    }
                    if(znalazl)
                        break ;
                }
                if(znalazl)
                    break ;
            }
            if(znalazl)
                break ;
        }
        if(znalazl)
            break ;
    }

    pvm_initsend(PvmDataDefault);
    //pvm_pkint(&k, 1, 1);
    pvm_pkstr(slave_name);
    if(znalazl) {
        pvm_pkstr("znalazlem");
    }
    else {
        pvm_pkstr("nie znalazlem");
    }
    pvm_pkstr(slave_name);
    pvm_send(tid_master, MSG_SLV);


    pvm_exit();




}
Beispiel #9
0
int main(int argc, char *argv[])
{
	/*
		argv[1] - ilość narciarzy
	*/
	time_t t;
	srand((unsigned)time(&t));

	int number_of_skiers = 0;
	if (argc >= 2) {
		number_of_skiers = atoi(argv[1]);
	} else {
		number_of_skiers = rand() % 50 + 10;
	}

	printf("Liczba narciarzy: %d\n", number_of_skiers);

	int *skiers_weights;
	skiers_weights = malloc(sizeof(int) * number_of_skiers);



	int min_skier_weight = SKIERS_MAX_WEIGHT;
	int sum_skiers_weights = 0;

	int i;

	int weights_arg_index = -1;
	for (i = 0; i < argc; i++) {
		if (!strcmp(argv[i], "weights")) {
			weights_arg_index = i;
			break;
		}
	}

	for(i=0; i<number_of_skiers; i++) {
		if (weights_arg_index == -1)
			skiers_weights[i] = rand() % (SKIERS_MAX_WEIGHT - SKIERS_MIN_WEIGHT + 1) + SKIERS_MIN_WEIGHT;
		else
			skiers_weights[i] = atoi(argv[weights_arg_index + 1 + i]);
		sum_skiers_weights += skiers_weights[i];
		if (skiers_weights[i] < min_skier_weight) {
			min_skier_weight = skiers_weights[i];
		}
	}

	for(i=0; i<number_of_skiers; i++) {
		printf("Narciarz %d ma wage: %d\n", i, skiers_weights[i]);
	}
	printf("Min waga: %d\n", min_skier_weight);
	printf("Sum waga: %d\n", sum_skiers_weights);

	int min_perc_sum = 0.2 * sum_skiers_weights;
	int max_perc_sum = 0.4 * sum_skiers_weights;

	int first_lift_capacity;
	int second_lift_capacity;

	do {
		first_lift_capacity = rand() % (max_perc_sum - min_perc_sum) + min_perc_sum;
	} while (first_lift_capacity < min_skier_weight);

	do {
		second_lift_capacity = rand() % (max_perc_sum - min_perc_sum) + min_perc_sum;
	} while (second_lift_capacity < min_skier_weight);

	// read lifts capacities from console
	int lifts_arg_index = -1;
	for (i = 0; i < argc; i++) {
		if (!strcmp(argv[i], "lifts")) {
			lifts_arg_index = i;
			break;
		}
	}
	if (lifts_arg_index != -1) {
		first_lift_capacity = atoi(argv[lifts_arg_index + 1]);
		second_lift_capacity = atoi(argv[lifts_arg_index + 2]);
	}

	printf("Pierwszy wyciag: %d\n", first_lift_capacity);
	printf("Drugi wyciag: %d\n", second_lift_capacity);


	int mytid;
	int tids[number_of_skiers];		/* slave task ids */
	char slave_name[NAMESIZE];
	int nproc, j, who;

	mytid = pvm_mytid();
	pvm_catchout(stdout);

	nproc=pvm_spawn(SLAVENAME, NULL, PvmTaskDefault, "", number_of_skiers, tids);

	for( i=0 ; i<nproc ; i++ )
	{
		pvm_initsend(PvmDataDefault);
		pvm_pkint(&mytid, 1, 1);
		pvm_pkint(&number_of_skiers, 1, 1);
		for (j=0; j<nproc; j++) {
			pvm_pkint(&tids[j], 1, 1);
		}
		for (j=0; j<nproc; j++) {
			pvm_pkint(&skiers_weights[j], 1, 1);
		}
		pvm_pkint(&first_lift_capacity, 1, 1);
		pvm_pkint(&second_lift_capacity, 1, 1);
		pvm_send(tids[i], MSG_MSTR);
	}

	int current_skier_weight;

	for( i=0 ; i<nproc ; i++ )
	{
		pvm_recv( -1, MSG_SLV );
		pvm_upkint(&who, 1, 1 );
		pvm_upkstr(slave_name );
		pvm_upkint(&current_skier_weight, 1, 1);
		printf("%d: weight %d\n",who, current_skier_weight);
	}

	int msgnum = 1;
	while (1) {
		pvm_recv(-1, MSG_DIAG);
		char diag_str[200];
		pvm_upkstr(diag_str);
		printf("[%d] %s\n", msgnum, diag_str);
		msgnum++;
	}

	pvm_exit();
}
Beispiel #10
0
int main(int argc, char** argv){
  int parent_tid = pvm_parent();
  int my_tid = pvm_mytid();
  DEBUGA("[TID  %d] Slave starting ...",my_tid);
  /* Checking number of arguments */
  if(argc<=3){
    printf("Error in arguments");
    exit(1);
  }


  /* Getting password from arguments */
  int number_of_threads = atoi(argv[3]);
  int posi = atoi(argv[4]);
  int pass_size = atoi(argv[1]);

  char * password = malloc(sizeof(char)*(pass_size+1));
  password[0] = '\0';
  strncat(password,argv[2],pass_size);
  password[pass_size] = '\0';

  DEBUGA("[TID  %d] Password %s Size %d",my_tid,password,pass_size);


  char * temp_password = malloc(sizeof(char)*(pass_size+1));
  char * interval_start = malloc(sizeof(char)*(pass_size+1));
  char * interval_end = malloc(sizeof(char)*(pass_size+1));
  char * recv_buffer = malloc(sizeof(char)*MAX_SIZE);
  recv_buffer[0] = '\0';
  unsigned long long interval_size;

  int buf_size,mes_tag,mes_tid,buf_id;

    
  /* Ask parent for new interval */
  pvm_initsend(PvmDataDefault);
  pvm_pkint(&my_tid,1,1);
  pvm_send(parent_tid,NEED_INTERVAL);
  buf_id = pvm_recv(parent_tid,-1);
  pvm_bufinfo(buf_id,&buf_size,&mes_tag,&mes_tid);

  if(mes_tag == NEW_INTERVAL){
    pvm_upkstr(recv_buffer);
  }
  else if(mes_tag == NO_NEW_INTERVAL){
    exit(1);
  }
  else{
    exit(1);
  }
 
  /* Extract data from buffer */
  interval_start[0] = '\0';
  interval_end[0] = '\0';
  temp_password[0]='\0';
  strncpy(interval_start,recv_buffer,pass_size);
  interval_start[pass_size] = '\0';
  strncpy(interval_end,recv_buffer+pass_size,pass_size);
  interval_end[pass_size] = '\0';
  
  pthread_mutex_lock(&mutex_i_manager);
  init_interval_manager(&i_manager,
			interval_start,
			interval_end,
			password,
			posi);
  pthread_mutex_unlock(&mutex_i_manager);


  /* Creating threads ... */
  pthread_t * threads = malloc(sizeof(pthread_t)*number_of_threads);
  pthread_attr_t attr;
  int c_thread = 0;
  for(c_thread = 0; c_thread < number_of_threads ; ++c_thread){
    pthread_create(&threads[c_thread],&attr,find_password_thread,(void*)NULL);
  }

    
  while(1){
    

    pthread_mutex_lock(&mutex_action);
    pthread_mutex_unlock(&mutex_slave_waiting);
    pthread_cond_wait(&cond_action,&mutex_action);
    pthread_mutex_lock(&mutex_slave_waiting);

    if(action == NEW_INTERVAL){
      pvm_initsend(PvmDataDefault);
      pvm_pkint(&my_tid,1,1);
      pvm_send(parent_tid,NEED_INTERVAL);
      buf_id = pvm_recv(parent_tid,-1);
      pvm_bufinfo(buf_id,&buf_size,&mes_tag,&mes_tid);
      
      if(mes_tag == NEW_INTERVAL){
	pvm_upkstr(recv_buffer);
	interval_start[0] = '\0';
	interval_end[0] = '\0';
	strncpy(interval_start,recv_buffer,pass_size);
	interval_start[pass_size] = '\0';
	strncpy(interval_end,recv_buffer+pass_size,pass_size);
	interval_end[pass_size] = '\0';
	DEBUGA("New interval start interval : %s end interval : %s",interval_start,interval_end);
	pthread_mutex_lock(&mutex_i_manager);
	set_new_interval(&i_manager,interval_start,interval_end);
	pthread_mutex_unlock(&mutex_i_manager);

      }
      else if(mes_tag == NO_NEW_INTERVAL){
	
      }
      else{
      }
    }
    else if (action == FOUND_PASSWORD){
      pthread_mutex_lock(&mutex_f_password);
      pthread_mutex_lock(&mutex_f_c_password);
      
      DEBUGA("[TID  %d] Found Password",my_tid);
      pvm_initsend( PvmDataDefault );
      pvm_pkstr(found_char_password);
      pvm_send(parent_tid,FOUND_PASSWORD);
      pthread_mutex_unlock(&mutex_f_password);
      pthread_mutex_unlock(&mutex_f_c_password);
      break;

    }
    pthread_mutex_unlock(&mutex_action);
    

  }


 
  
  pvm_send(parent_tid,CHILD_TERMINATE);
  DEBUGA("[TID  %d] Terminating slave",my_tid);

  free(password);
  free(temp_password);
  free(interval_start);
  free(interval_end);
  free(recv_buffer);

  return EXIT_SUCCESS;
}
Beispiel #11
0
int 
main(void)
{
  struct p7trace_s *tr;         /* traceback of an alignment               */
  int      master_tid;		/* PVM TID of our master */
  char    *hmmfile;	        /* file to read HMM(s) from                */
  HMMFILE *hmmfp;               /* opened hmmfile for reading              */
  struct plan7_s *hmm;
  char    *seq;
  char    *dsq;
  int      len;
  int      nhmm;		/* number of HMM to work on                */
  float    sc;
  int      my_idx = -1;		/* my index, 0..nslaves-1 */
  float    globT;		/* T parameter: keep only hits > globT bits */
  double   globE;		/* E parameter: keep hits < globE E-value   */
  double   pvalue;		/* Z*pvalue = Evalue                        */
  int      Z;			/* nseq to base E value calculation on      */
  int      send_trace;		/* TRUE if score is significant             */
  int      do_xnu;		/* TRUE to do XNU filter on seq             */
  int      do_forward;		/* TRUE to use Forward() scores not Viterbi */
  int      do_null2;		/* TRUE to correct scores w/ ad hoc null2   */
  int      alphatype;		/* alphabet type, hmmAMINO or hmmNUCLEIC    */
  int      code;		/* return code after initialization         */

  
  /* Register leave_pvm() cleanup function so any exit() call
   * first calls pvm_exit().
   */
  if (atexit(leave_pvm) != 0) { pvm_exit(); Die("slave couldn't register leave_pvm()"); }

  /*****************************************************************
   * initialization.
   * Master broadcasts to us: 
   *     1) len of HMM file name        (int)
   *     2) name of HMM file            (string)
   *     3) length of sequence string   (int) 
   *     4) sequence                    (string)
   *     5) globT threshold
   *     6) globE threshold
   *     7) Z 
   *     8) do_xnu flag
   *     9) do_forward flag
   *    10) do_null2 flag
   *    11) alphabet type
   * We receive the broadcast and open the files.    
   ******************************************************************/

  master_tid = pvm_parent();	/* who's our master? */

  pvm_recv(master_tid, HMMPVM_INIT);
  pvm_upkint(&len, 1, 1);
  hmmfile = MallocOrDie(sizeof(char *) * (len+1));
  pvm_upkstr(hmmfile);
  pvm_upkint(&len, 1, 1);
  seq = MallocOrDie(sizeof(char *) * (len+1));
  pvm_upkstr(seq);
  pvm_upkfloat(&globT, 1, 1);
  pvm_upkdouble(&globE, 1, 1);
  pvm_upkint(&Z, 1, 1);
  pvm_upkint(&do_xnu, 1, 1);
  pvm_upkint(&do_forward, 1, 1);
  pvm_upkint(&do_null2, 1, 1);
  pvm_upkint(&alphatype, 1, 1);

  SetAlphabet(alphatype);
				/* Open HMM file (maybe in HMMERDB) */
  code = HMMPVM_OK;
  if ((hmmfp = HMMFileOpen(hmmfile, "HMMERDB")) == NULL)
    code = HMMPVM_NO_HMMFILE;
  else if (hmmfp->gsi == NULL)
    code = HMMPVM_NO_INDEX;
  
  /* report our status.
   */
  pvm_initsend(PvmDataDefault);
  pvm_pkint(&code, 1, 1);	
  pvm_send(master_tid, HMMPVM_RESULTS);

  dsq = DigitizeSequence(seq, len);
  if (do_xnu) XNU(dsq, len);

  /*****************************************************************
   * Main loop.
   * Receive an integer 0..nhmm-1 for which HMM to search against.
   * If we receive a -1, we shut down. 
   *****************************************************************/ 
  
  for (;;) 
    {
      pvm_recv(master_tid, HMMPVM_WORK);
      pvm_upkint(&nhmm, 1, 1);
      if (my_idx < 0) my_idx = nhmm; /* first time thru, remember what index we are. */

      if (nhmm == -1) break;	/* shutdown signal */

      /* move to our assigned HMM in the HMM file, and read it
       */
      HMMFilePositionByIndex(hmmfp, nhmm);
      if (! HMMFileRead(hmmfp, &hmm)) Die("unexpected end of HMM file"); 
      if (hmm == NULL)                Die("unexpected failure to parse HMM file"); 
      P7Logoddsify(hmm, TRUE);
      
      /* Score sequence, do alignment (Viterbi), recover trace
       */
      if (P7ViterbiSize(len, hmm->M) <= RAMLIMIT)
	{
	  SQD_DPRINTF1(("P7Viterbi(): Estimated size %d Mb\n", P7ViterbiSize(len, hmm->M)));
	  sc = P7Viterbi(dsq, len, hmm, &tr);
	}
      else
	{
	  SQD_DPRINTF1(("P7SmallViterbi() called; %d Mb > %d\n", P7ViterbiSize(len, hmm->M), RAMLIMIT));
	  sc = P7SmallViterbi(dsq, len, hmm, &tr);
	}

      if (do_forward) sc  = P7Forward(dsq, len, hmm, NULL);
      if (do_null2)   sc -= TraceScoreCorrection(hmm, tr, dsq);
	
      pvalue = PValue(hmm, sc);
      send_trace = (sc > globT && pvalue * (float) Z < globE) ? 1 : 0;

      /* return output
       */
      pvm_initsend(PvmDataDefault);
      pvm_pkint(&my_idx, 1, 1);	/* tell master who we are */
      pvm_pkstr(hmm->name);	/* double check that we did the right thing */
      pvm_pkfloat(&sc, 1, 1);
      pvm_pkdouble(&pvalue, 1, 1);
      pvm_pkint(&send_trace, 1, 1); /* flag for whether a trace structure is coming */
      if (send_trace) PVMPackTrace(tr);
      pvm_send(master_tid, HMMPVM_RESULTS);

      /* cleanup
       */
      FreePlan7(hmm);
      P7FreeTrace(tr);
    }

  /*********************************************** 
   * Cleanup, return.
   ***********************************************/

  HMMFileClose(hmmfp);
  free(seq);
  free(dsq);
  free(hmmfile);
  return 0;
}
Beispiel #12
0
void WorkersLoop(int startupflags)
{
  double theta;
  long daytime, newtinc;
  Entity et;
  Vector sunpos;
  VarDesc *v;
  int i, j, k;
  char varname[80];
  while (1)  {
    switch (GetCommand())  {
    case DO_TIME_STEP :
      if (plausible)  {
	daytime = ((int)(timeofday*3600.)+actime) % 86400;
	ActualiseValuesInTime(actime);	/* Actualise Border values */
	for (et = maxentity; et--; )
	  CalculateLayerAverage(g[et], pstat, avg+et*nz);
	SetAvgMountains();
	CalcMeanHydrostaticPressure();
	InterpolateToFaces();			/* Interpolate wind speeds from center to faces */
	InterpolateToCenter(-1., pressuretype == NONHYDROSTATIC);
	if (tstart == actime)  Continuity();
	CheckTimeStep(&tinc, &chemtinc, 0.8);
	if (pressuretype == NONHYDROSTATIC)
	  ApplyBuoyancy(tinc);			/* Calculate Buoyancy */
	if (pressuretype != NOPRESSURE)  {		/* Calc wind acceleration */
	  switch (pressuretype)  {			/* Calculate Pressure field */
	  case HYDROSTATIC    : CalcHydrostaticPressure(); break;
	  case NONHYDROSTATIC : SolveForPressure(tinc); break;
	  }
	  ApplyPressure(tinc);
	}
	Continuity();				/* Mass conservation */
	InterpolateToCenter(1., pressuretype == NONHYDROSTATIC);
	if (coriolistype != NOCORIOLIS)  ApplyCoriolis(tinc);
	if (filtertype != NO_FILTER)  {
	  SetBoundary(WWIND+1);   /* Set Boundary for Wind only */
	  switch (filtertype)  {
	  case PEPPER_FILTER :
	    for (i = nz; i--; )
	      for (et = HUMIDITY; et--; )
		ApplyFilter(g[et]+i*layer, pstat+i*layer, spatialfilter);
	    break;
	  case SHAPIRO_FILTER :
	    for (i = nz; i--; )
	      for (et = HUMIDITY; et--; )
		ShapiroFilter(g[et]+i*layer, pstat+i*layer, 3, spatialfilter);
	    break;
	  case DIFFUSION_FILTER :
	    for (i = nz; i--; )
	      for (et = HUMIDITY; et--; )
		ShapiroFilter(g[et]+i*layer, pstat+i*layer, 1, spatialfilter);
	    break;
	  }
	}
	SetBoundary(WWIND+1);
	CheckTimeStep(&newtinc, &chemtinc, 1.);
	if (newtinc < tinc)  {
	  tinc = newtinc;
	}
	chemtinc = (chemtime <= actime ? chemtinc : 0);
	if (advection || windadvection)
	  switch (advectiontype)  {
	  case MPDATA_A : Advect(tinc, chemtinc); break;
	  case PPM_A    : PPM_Transport(tinc, chemtinc, smiord); break;
	  }
	if (dampinglayer)  DampTop();
	if (groundinterface || shortwaveradiation)  {
	  GroundInterface(timeofday + (double)actime / 3600., dayofyear, tinc, &sunpos);
	  sunelevation = (sunpos.z > 0. ? 57.29578 * asin(sunpos.z) : 0.);
	}
	if (cloudwater)  CloudPhysics();
	if (turbtype == TTTT)  {
	  if (groundinterface)
	    CalcGroundTurbulence(tinc);
	  CalcTransilientTurbulence(tinc);
	}
	else if (turbtype == KEPS_T)  {
	  CalcKEpsilon(tinc);
	  if (groundinterface)
	    CalcGroundTurbulence(tinc);
	  CalcKTurb(tinc, chemtinc);
	}
	Emit(tinc);
	Deposit(tinc);
	if (!(radiationtype && shortwaveradiation) &&
	    // When using the two-stream module, ChemicalTimeStep
	    // mus be called from within ShortWaveRadiation!
	    nsubs && actime % tchem == 0)  ChemicalTimeStep(tchem, &sunpos);
	SetBoundary(chemtinc ? maxentity : SUBS);
    
	// Call ModuleManager
	McInterface::modmanager.DoCalc(actime+tinc);

	actime += tinc; chemtime += chemtinc;
	if (dumpnow || (dumptime && (actime % dumptime == 0)))  {
	  MakeAFullDump();
	  dumpnow = 0;
	}
      }  /* if (plausible) */
      SendStatus(plausible);
      break;
    case SENDGRIDVAL :
      pvm_upkint((int *)&et, 1, 1);
      pvm_upkint(&i, 1, 1);
      pvm_upkint(&j, 1, 1);
      pvm_upkint(&k, 1, 1);
      pvm_initsend(PvmDataRaw);
      pvm_pkdouble(g[et]+i*row+j+k*layer, 1, 1);
      pvm_send(myparent, VALUES);
      break;
    case SENDMESHVAL :
      pvm_upkstr(varname);
      v = GetNamedVar(varname);
      pvm_upkint(&i, 1, 1);
      pvm_upkint(&j, 1, 1);
      pvm_upkint(&k, 1, 1);
      pvm_initsend(PvmDataRaw);
      if (v->storetype == PROC_VAL)  {
	theta = v->v.proc(k, i, j, v);
	pvm_pkdouble(&theta, 1, 1);
      }
      else
	pvm_pkdouble(GetNamedVar(varname)->v.d+i*row+j+k*layer, 1, 1);
      pvm_send(myparent, VALUES);
      break;
    case SENDGRID :
      pvm_upkint((int *)&et, 1, 1);
      SendMeshToMaster(g[et], 0, ALL_DIM);
      break;
    case SENDMESH :
      pvm_upkstr(varname);
      v = GetNamedVar(varname);
      if (v->storetype == PROC_VAL)  {
	for (k = nz; k--; )
	  for (i = nx+1; i--; )
	    for (j = ny+1; j--; )
	      flux[0][i*row+j+k*layer] = v->v.proc(k, i, j, v);
	SendMeshToMaster(flux[0], 0, v->dims);
	memset(flux[0], 0, mesh * sizeof(double));
      }
      else
	SendMeshToMaster(v->v.d, 0, v->dims);
      break;
    case SENDGROUND :
      SendGroundToMaster();
      break;
    case EXIT :
      pvm_exit();
      exit (0);
    }
  }
}
Beispiel #13
0
void RecvBorderTime(void)
{
  BorderTimeDesc *bt, *last = NULL;
  char varname[80];
  int nbt, mem, i, dff;
  bordertime = NULL;
  pvm_upkint(&nbt, 1, 1);
  while (nbt--)  {
    bt = (BorderTimeDesc *)malloc(sizeof(BorderTimeDesc));
    pvm_upkint((int *)&bt->vartype, 1, 1);
    pvm_upkint((int *)&bt->section, 1, 1);
    pvm_upkint(&bt->bigdim, 1, 1);
    pvm_upkint(&bt->ntime, 1, 1);
    pvm_upkint(&bt->itime, 1, 1);
    pvm_upkint(&bt->cdfid, 1, 1);
    pvm_upkint(&bt->vid, 1, 1);
    pvm_upkstr(varname);
    pvm_upkint((int *)&bt->actualvar.v.et, 1, 1);
    pvm_upkushort(&bt->actualvar.dims, 1, 1);
    pvm_upkint((int *)&bt->actualvar.storetype, 1, 1);
    pvm_upkint(&bt->actualvar.id, 1, 1);
    pvm_upkint(&bt->actualvar.ncoord, 1, 1);
    pvm_upkint((int *)&bt->nextvar.v.et, 1, 1);
    pvm_upkushort(&bt->nextvar.dims, 1, 1);
    pvm_upkint((int *)&bt->nextvar.storetype, 1, 1);
    bt->timetable = (long *)malloc(bt->ntime * sizeof(long));
    pvm_upklong(bt->timetable, bt->ntime, 1);
    pvm_upkuint((uint *)bt->coords, 4, 1);
    for (i = 0; i < 4; i++)  {
      pvm_upkint(&dff, 1, 1);
      bt->dimptr[i] = bt->coords + dff;
    }
    switch (bt->section)  {
      case NORTH_BORDER :
            bt->actualvar.v.d = northborder + GetNamedVar(varname)->v.et*nz*xrow;
	    break;
      case SOUTH_BORDER :
            bt->actualvar.v.d = southborder + GetNamedVar(varname)->v.et*nz*xrow;
	    break;
      case WEST_BORDER  :
            bt->actualvar.v.d = westborder + GetNamedVar(varname)->v.et*nz*row;
	    break;
      case EAST_BORDER  :
            bt->actualvar.v.d = eastborder + GetNamedVar(varname)->v.et*nz*row;
	    break;
      case EMISSIONS    :
            bt->actualvar.v.d = GetEmVarWithID(bt->actualvar.id)->v.d;
	    break;
      default	        :
            bt->actualvar.v = GetNamedVar(varname)->v;
            break;
    }
    switch (bt->vartype)  {
      case XWALL_VAR :
	 mem = xrow*nz;
	 break;
      case WALL_VAR :
	 mem = row*nz;
	 break;
      case LAYER_VAR :
      case GROUND_VAR :
	 mem = layer;
	 break;
      case PROFILE_VAR :
	 mem = nz;
	 break;
      case MESH_VAR :
	 mem = mesh;
	 break;
      case COORD_VAR :
	 mem = bt->actualvar.ncoord;
	 break;
    }
    bt->actualdata.d = bt->actualvar.v.d;
    bt->nextdata = (double *)calloc(mem, sizeof(double));
    bt->nextvar.v.d = bt->nextdata;
    bt->nextvar.ncoord = bt->actualvar.ncoord;
    *(bordertime ? &last->next : &bordertime) = bt;
    last = bt;
  } 
  if (last)  last->next = NULL;
}
Beispiel #14
0
int main(int argc, char ** argv){
    TAILQ_INIT(&head);
    int nproc, numt, i, nhost, narch;
    int num_tasks = 0;
    struct pvmhostinfo *hostp;
    struct stat s;
    FILE * codefile = fopen("./codes", "w");

    if(argc != 2){
        exit_prog("USAGE: ./taskgen directory\n",1);
    }
    else {
        stat(argv[1], &s);
        if(s.st_mode & S_IFDIR){
            char path[PATH_MAX+1];
            realpath(argv[1],path);
            printf("Loading graphs from %s...", path);
            fflush(stdout);
            load_graph_dir(path, &num_tasks);
            printf("done. Found %d tasks.\n", num_tasks);
        }
        else{
            printf("%s is not a directory. Please check arguments.\n", argv[1]);
            exit_prog(NULL, 1);
        }
    }

    pvm_config(&nhost, &narch, &hostp);                         /*Set number of slaves to start */
    nproc = nhost * 3;                                          /*3 processes per host */

    printf("Spawning %d worker tasks on %d machines...", nproc, nhost);

    int tids[nproc];                                            /*hold the task ids of the workers */

    int flags = PvmTaskDefault;
   // flags += PvmTaskDebug;

    numt =pvm_spawn("worker", (char**)0, flags, "", nproc, tids);   /*start up the workers */

    if(numt < nproc){                                           /*Error Checking */
        printf("\n Trouble spawing slaves. Error codes are:\n");
        for(i = numt; i < nproc; i++){
            printf("TID %d: %d\n", i, tids[i]);
        }
        for(i = 0; i < numt; i++){
            pvm_kill(tids[i]);
        }
        exit_prog("Failure.\n",1);
    }
    printf("done. Connected.\n");
    
    /* Main loop */
    int bufid, bytes, msgtype, source;
    int sent_tasks, comp_tasks, found_codes = 0;
    int finished = 0;
    int percent_comp = 0;
    char * buf;
    while(!finished){    
        bufid = pvm_recv(-1, -1);                               /*Accept any message from any task BLOCKING CALL*/
        pvm_bufinfo(bufid, &bytes, &msgtype, &source);
        switch(msgtype){
            case MSGREQTASK:
                if(!TAILQ_EMPTY(&head)){
                    send_task(source);                              /*send out the message */
                    sent_tasks++;
                }
                break;
            case MSGCODE:
                buf = malloc(bytes);
                pvm_upkstr(buf);
                fprintf(codefile, "%s\n", buf);
                fflush(codefile);
                comp_tasks++;
                found_codes++;
                break;
            case MSGNOCODE:
                comp_tasks++;
                break;
            default:
                printf("Incorrect MSGTYPE received from task %d. Received: %d\n", source, msgtype);
                break;
            }
        
        if(((float)comp_tasks/num_tasks * 100) > percent_comp + 1){
                printf("Tasks Complete: %d    Tasks Sent: %d    Percent Complete: %.2f\n", 
                comp_tasks, sent_tasks, (float)comp_tasks/num_tasks * 100);
                percent_comp = (float)comp_tasks/num_tasks * 100;
        }
    
        if(comp_tasks == num_tasks){
            finished = 1;
        }
        
    }
 
    printf("All tasks complete.\n");

    exit_prog(NULL, 0);
    return 0;
}
Beispiel #15
0
int main (int argc, char* argv[])
{
	if(argc !=4)
	{
		printf("usage : ./craquage p r m\n");
		return EXIT_FAILURE;
	}
	
	//Initialisation des variables
	int nb_esclaves = atoi(argv[1]);
	int* tids = (int*) calloc(nb_esclaves, sizeof(int));
	int longueur_mdp = atoi(argv[2]);
	char* mdp = (char*) calloc(strlen(argv[3])+1, sizeof(char));
	strcpy(mdp, argv[3]);

	//declaration de type de tres long entiers (avec bibliotheque GMP)
	mpz_t debut_sequence, pas_reel, pas, fin_exec;
	mpz_init(debut_sequence);
	mpz_init(pas_reel);
	mpz_init(pas);
	mpz_init(fin_exec);

	//recuperation du chemin de l executable
	char* chemin = getcwd(NULL, 1000);
	strcat(chemin, "/craquage_esclave");

	//creation des arguments pour l esclave
	char *argv_esclave[3];
	argv_esclave[2]=NULL;
	argv_esclave[0] = (char*) calloc(strlen(argv[2])+1, sizeof(char));
	strcpy(argv_esclave[0],argv[2]);
	 
	argv_esclave[1] = (char*) calloc(strlen(argv[3])+1, sizeof(char));
	strcpy(argv_esclave[1],argv[3]);
	//printf("strlen %lu, %lu\n", (long unsigned)strlen(argv[2]),(long unsigned) strlen(argv[3]));
	//printf("nb_esclaves %d\n", nb_esclaves);
	
	int i;
	int trouve = 0;
	int fini = 0;
	int size;
	int nb_envoi = 0;
	int nb_pas = nb_esclaves*longueur_mdp;
	int nb_changement = 0;
	char* envoi_char;
		
	int bufid, info, bytes, type, source;
	char * solution;
	pvm_catchout(stderr);
	struct timeval tv1, tv2;
	gettimeofday(&tv1, NULL);
	pvm_spawn(chemin, argv_esclave, PvmTaskDefault,"", nb_esclaves, tids);

	//calcul du pas, fin_exec (= fin execution)
	mpz_set_ui(debut_sequence, 0);
	mpz_ui_pow_ui(fin_exec, 15, longueur_mdp+1);	
	mpz_sub_ui(fin_exec, fin_exec, 15);
	mpz_cdiv_q_ui(fin_exec, fin_exec, 14);
	
	mpz_set(pas, fin_exec);
	mpz_cdiv_q_ui(pas, pas, nb_pas);
	
	if(mpz_cmp_ui(pas, 0)==0)
	  {
	    mpz_set_ui(pas,1); 
	  }

	//gmp_printf("fin_exec: %Zd\npas:%Zd\ndebut_sequence:%Zd\n",fin_exec, pas, debut_sequence);
	
	//boucle principale
	while(!trouve && fini!=nb_esclaves)
	  {
	    //Attente de reception de donnees d un esclave
	    bufid = pvm_recv( -1, -1 );
	    info = pvm_bufinfo( bufid, &bytes, &type, &source );
	    
	    if (info < 0)
	      {
		printf("Erreur de reception : %d\n", info);
		exit(1);
	      }
	    
	    //selon le tag du message, demande de donnees ou solution trouvee
	    switch(type)
	      {
	      case(0)://mot de passe trouve
		solution = calloc(bytes, sizeof(char));
		pvm_upkstr(solution);
		printf("\nLa solution est : %s\n\n", solution);
		trouve = 1;
		break;	
		
	      case(1)://esclave veut plus de donnees
		//prendre en compte la fin des donnees dans le calcul du pas
		if(nb_changement <= 2  && nb_envoi>=(3*nb_pas/4))
		  {
		    mpz_cdiv_q_ui(pas, pas, 2);
		    nb_envoi = 0;
		    nb_pas/=2;
		    nb_changement++;
		  }
		//gmp_printf("fin_exec: %Zd pas:%Zd debut_sequence:%Zd\n",fin_exec, pas, debut_sequence);
		if(mpz_cmp(debut_sequence, fin_exec)< 0){
		  mpz_sub(pas_reel, fin_exec, debut_sequence);
		  if(mpz_cmp(pas, pas_reel)<0)
		    {
		      mpz_set(pas_reel, pas);
		    }
		 		  
		  //envoi des donnes a l esclave
		  pvm_initsend(PvmDataDefault);
		  size = gmp_asprintf(&envoi_char, "%Zd", debut_sequence);
		  pvm_pkint(&size, 1, 1);
		  pvm_pkbyte(envoi_char,size+1, 1);
		  free(envoi_char);
		 
		  size = gmp_asprintf(&envoi_char, "%Zd", pas_reel);
		  pvm_pkint(&size, 1, 1);
		  pvm_pkbyte(envoi_char,size+1 , 1);
		  free(envoi_char);
		  pvm_send(source,0);
		  
		  if(mpz_cmp(pas_reel,pas)!=0)
		    {
		      mpz_set(debut_sequence,fin_exec);
		    }
		  else
		    {
		      mpz_add(debut_sequence, debut_sequence,pas);
		    }
		  nb_envoi++;
		}
		else{
		  fini++ ;
		  printf("Pas de solution pour %d esclave(s)\n", fini);
		}		
		
		break;
		
	      default:
		break;
	      }
	  }
	// suppression des esclave
	for(i=0; i<nb_esclaves;i++)
	  {
	    info = pvm_kill(tids[i]);
	    //printf("Suppression de l esclave %d: retour de pvm_kill: %d\n",i ,info);
	  }
	
	pvm_exit();
	gettimeofday(&tv2, NULL);
	printf("%d %ld\n",longueur_mdp,(tv2.tv_sec-tv1.tv_sec)*1000 + (tv2.tv_usec-tv1.tv_usec)/1000); 
	
	mpz_clear(debut_sequence);
	mpz_clear(pas_reel);
	mpz_clear(pas);
	mpz_clear(fin_exec);
	free(tids);
	free(mdp);
	free(argv_esclave[0]);
	free(argv_esclave[1]);
	
	return EXIT_SUCCESS;
}