Exemplo n.º 1
0
// write log
void my_log(int loglev,const char * format, ... )
{
	if (loglev>LOG_LEVEL) return;
	
	char temp[1024];
    memset(temp, 0, 1024);
    
    va_list args;
    va_start( args, format );
    vsprintf(temp, format, args );
    va_end( args );
    
    char currTime[256];
	memset(currTime, 0, 256);
    currenttime(currTime);
	
	char logpath[256];
	memset(logpath, 0, 256);
	filepath(logpath);
	
	FILE * pf = fopen(logpath, "a+");

	if (pf)
	{
		fputs(currTime, pf);
		fputs(temp, pf);
		fputs("\n", pf);
		
		fclose(pf);
	}
	
	

}
Exemplo n.º 2
0
void bidiag_gkl_restart(
    int locked, int l, int n,
    CAX && Ax, CATX && Atx, CD && D, CE && E, CRho && rho, CP && P, CQ && Q, int s_indx, int t_s_indx) {
  // enhancements version from SLEPc
  const double eta = 1.e-10;
  double t_start = 0.0, t_end = 0.0;
  double local_start = 0.0, local_end = 0.0; 
  double t_total3 = 0.0, t_total4 = 0.0, t_total5 = 0.0, t_total6 = 0.0, t_total7 = 0.0;
  
  int rank, nprocs;
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
  
  // Step 1
  int recv_len = (int)P.dim0() * nprocs;
  vec_container<double> tmp(Ax.dim0());
  vec_container<double> recv_tmp(recv_len);
  
  auto m_Ax = make_gemv_ax(&Ax);
  auto m_Atx = make_gemv_ax(&Atx);
  
  m_Ax(Q.col(l), tmp, P.dim0() > 1000);

  vec_container<double> send_data(P.dim0(),0);
  for(size_t i = s_indx; i < s_indx + Ax.dim0(); ++i)
    send_data[i] = tmp.get(i-s_indx);
  MPI_Gather(&send_data[0], P.dim0(), MPI_DOUBLE, &recv_tmp[0], P.dim0(), MPI_DOUBLE, 0, MPI_COMM_WORLD);

  P.col(l) = 0;
  // Generate truly P.col(l)
  if(rank == 0) {
    local_union(P, recv_tmp, l, nprocs);
    // Step 2 & also in rank 0
    for (int j = locked; j < l; ++j) {
      P.col(l) += -rho(j) * P.col(j);
    }
  }
  
  MPI_Bcast(&(P.col(0)[0]), P.size(), MPI_DOUBLE, 0, MPI_COMM_WORLD); 
  //MPI_Bcast(&(P.col(l)[0]), P.size(), MPI_DOUBLE, 0, MPI_COMM_WORLD); 
  // Main loop
  vec_container<double> T(n);
  int recv_l = Q.dim0() * nprocs;
  vec_container<double> recv_t(recv_l);
  for (int j = l; j < n; ++j) {
    // Step 3   
    vec_container<double> tmp2(Atx.dim0());
    
    /* for print */
    if(rank == 0)
    	t_start = currenttime();
   
    local_start = currenttime();
    m_Atx(P.col(j), tmp2, Q.dim0() > 1000);
    local_end = currenttime();
    std::cout << "parallel mv time cost is " << (local_end - local_start) / 1.0e6 << std::endl;
     
    vec_container<double> s_data(Q.dim0(), 0); 
    for(size_t i = t_s_indx; i < t_s_indx + Atx.dim0(); ++i)
      s_data[i] = tmp2[i-t_s_indx];
    MPI_Gather(&s_data[0], Q.dim0(), MPI_DOUBLE, &recv_t[0], Q.dim0(), MPI_DOUBLE, 0, MPI_COMM_WORLD);
    local_start = currenttime();
    std::cout << "parallel mv time cost2 is " << (local_start - local_end) / 1.0e6 << std::endl;
    
    //Q.col(j+1) = 0;
    if(rank == 0) {
      // Generate truly Q.col(j+1) 
      local_union(Q, recv_t, j + 1, nprocs);
      local_end = currenttime();
      t_end = currenttime();
      std::cout << "parallel mv time cost3 is " << (local_end - local_start) / 1.0e6 << std::endl;
      std::cout << "time of step 3 is : " << (t_end - t_start) / 1.0e6 << std::endl;
      t_total3 += (t_end - t_start) / 1.0e6;
    }
      
    // Step 4
    for(size_t aa = 0; aa < Q.dim0(); ++aa) // row
      MPI_Bcast(&(Q.row(aa)[0]), j + 2, MPI_DOUBLE, 0, MPI_COMM_WORLD); 
    // MPI_Bcast(&(Q.col(0)[0]), Q.size(), MPI_DOUBLE, 0, MPI_COMM_WORLD); 
    
    if(rank == 0)
      t_end = currenttime();
    auto Qj = mat_cols(Q, 0, j + 1);
    auto Tj = make_vec(&T, j + 1);
    
    //Tj.assign(gemv(Qj.trans(), Q.col(j + 1)), j >= 3);
    parallel_gemv_task(Qj.trans(), Q.col(j+1), Tj);
    
    if(rank == 0) {
      t_start = currenttime();
      t_total4 += (t_start - t_end) / 1.0e6;
      std::cout << "time of step 4 is : " << (t_start - t_end) / 1.0e6 << std::endl;
    }

    // Step 5
    if(rank == 0) {
      double r = Q.col(j + 1).norm2();
      D[j] = vec_unit(P.col(j));
      Q.col(j + 1).scale(1. / D[j]);
      Tj = Tj / D[j];
      r /= D[j];
      Q.col(j + 1).plus_assign(- gemv(Qj, Tj), Q.dim0() > 1000);
      
      t_end = currenttime();
      t_total5 += (t_end - t_start) / 1.0e6;
      std::cout << "time of step 5 is : " << (t_end - t_start) / 1.0e6 << std::endl;

      // Step 6
      double beta = r * r - Tj.square_sum();
      if (beta < eta * r * r) {
        Tj.assign(gemv(Qj.trans(), Q.col(j + 1)), Q.dim0() > 1000);
        r = Q.col(j + 1).square_sum();
        Q.col(j + 1).plus_assign(-gemv(Qj, Tj), Q.dim0() > 1000);
        beta = r * r - Tj.square_sum();
      }
      beta = std::sqrt(beta);
      E[j] = beta;
      Q.col(j + 1).scale(1. / E[j]);
      
      t_start = currenttime();
      t_total6 += (t_start - t_end) / 1.0e6;
      std::cout << "time of step 6 is : " << (t_start - t_end) / 1.0e6 << std::endl;
    } 
    
    // Step 7
    // MPI_Bcast(&(Q.col(j+1)[0]), Q.size(), MPI_DOUBLE, 0, MPI_COMM_WORLD);
    // MPI_Bcast(&(Q.col(0)[0]), Q.size(), MPI_DOUBLE, 0, MPI_COMM_WORLD);
    for(size_t aa = 0; aa < Q.dim0(); ++aa)
      MPI_Bcast(&(Q.col(j+1)[aa]), 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);

    if (j + 1 < n) {
      if(rank == 0) 
        t_start = currenttime();
      vec_container<double> tmp3(Ax.dim0());
      vec_container<double> se_data(P.dim0(), 0);
      
      m_Ax(Q.col(j + 1), tmp3, P.dim0() > 1000);
      
      for(size_t k1 = s_indx; k1 < s_indx + Ax.dim0(); ++k1)
        se_data[k1] = tmp3[k1-s_indx];
      MPI_Gather(&se_data[0], P.dim0(), MPI_DOUBLE, &recv_tmp[0], P.dim0(), MPI_DOUBLE, 0, MPI_COMM_WORLD);
      
      // P.col(j+1) = 0;
      if(rank == 0) {
	local_union(P, recv_tmp, j + 1, nprocs);
	P.col(j + 1).plus_assign(- E[j] * P.col(j), P.dim0() > 1000);
      }
      
      /* for print */
      if(rank == 0) {
        t_end = currenttime();
        t_total7 += (t_end - t_start) / 1.0e6;
	std::cout << "time of step 7 is : " << (t_end - t_start) / 1.0e6 << std::endl;
      }

      // MPI_Bcast(&(P.col(l)[0]), P.size(), MPI_DOUBLE, 0, MPI_COMM_WORLD);
      // MPI_Bcast(&(P.col(0)[0]), P.size(), MPI_DOUBLE, 0, MPI_COMM_WORLD);
      for(size_t aa = 0; aa < P.dim0(); ++aa)
        MPI_Bcast(&(P.col(j+1)[aa]), 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);

    }  // end if
  }    // end while
  
  /* for print time of each step. */
  if(rank == 0) {
    std::cout << "total step 3 time is : " << t_total3 << std::endl; 
    std::cout << "total step 4 time is : " << t_total4 << std::endl; 
    std::cout << "total step 5 time is : " << t_total5 << std::endl; 
    std::cout << "total step 6 time is : " << t_total6 << std::endl; 
    std::cout << "total step 7 time is : " << t_total7 << std::endl; 
  }
  
  return ;
}
Exemplo n.º 3
0
/**
 * @brief Read in a list of array and check for each of the arrays whether they are in LMC form or not
 * @param argc
 * @param argv[]
 * @return
 */
int main (int argc, char *argv[]) {
        char *fname;
        int correct = 0, wrong = 0;

        /* parse command line options */
        AnyOption opt;
        opt.setFlag ("help", 'h'); /* a flag (takes no argument), supporting long and short form */
        opt.setOption ("loglevel", 'l');
        opt.setOption ("oaconfig", 'c');
        opt.setOption ("check");
        opt.setOption ("strength", 's');
        opt.setOption ("prune", 'p');
        opt.setOption ("output", 'o');
        opt.setOption ("mode", 'm');

        opt.addUsage ("oacheck: Check arrays for LMC form or reduce to LMC form");
        opt.addUsage ("Usage: oacheck [OPTIONS] [ARRAYFILE]");
        opt.addUsage ("");
        opt.addUsage (" -h  --help  			Prints this help");
        opt.addUsage (" -l [LEVEL]  --loglevel [LEVEL]	Set loglevel to number");
        opt.addUsage (" -s [STRENGTH]  --strength [STRENGTH] Set strength to use in checking");
        std::string ss = " --check [MODE]			Select mode: ";
        ss +=
            printfstring ("%d (default: check ), %d (reduce to LMC form), %d (apply random transformation and reduce)",
                          MODE_CHECK, MODE_REDUCE, MODE_REDUCERANDOM); //
        for (int i = 3; i < ncheckopts; ++i)
                ss += printfstring (", %d (%s)", static_cast< checkmode_t > (i), modeString ((checkmode_t)i).c_str ());
        opt.addUsage (ss.c_str ());
        opt.addUsage (" -o [OUTPUTFILE] Output file for LMC reduction");

        opt.processCommandArgs (argc, argv);

        algorithm_t algmethod = (algorithm_t)opt.getIntValue ("mode", MODE_AUTOSELECT);

        int loglevel = NORMAL;
        if (opt.getValue ("loglevel") != NULL || opt.getValue ('l') != NULL)
                loglevel = atoi (opt.getValue ('l')); // set custom loglevel
        setloglevel (loglevel);

        if (checkloglevel (QUIET)) {
                print_copyright ();
        }

        if (opt.getFlag ("help") || opt.getFlag ('h') || opt.getArgc () == 0) {
                opt.printUsage ();
                return 0;
        }

        checkmode_t mode = MODE_CHECK;
        if (opt.getValue ("check") != NULL)
                mode = (checkmode_t)atoi (opt.getValue ("check")); // set custom loglevel
        if (mode >= ncheckopts)
                mode = MODE_CHECK;

        logstream (QUIET) << "#time start: " << currenttime () << std::endl;

        double t = get_time_ms ();
        t = 1e3 * (t - floor (t));
        srand (t);

        int prune = opt.getIntValue ('p', 0);

        fname = opt.getArgv (0);
        setloglevel (loglevel);

        int strength = opt.getIntValue ('s', 2);
        if (strength < 1 || strength > 10) {
                printf ("Strength specfied (t=%d) is invalid\n", strength);
                exit (1);
        } else {
                log_print (NORMAL, "Using strength %d to increase speed of checking arrays\n", strength);
        }

        arraylist_t outputlist;
        char *outputfile = 0;
        bool writeoutput = false;
        if (opt.getValue ("output") != NULL) {
                writeoutput = true;
                outputfile = opt.getValue ('o');
        }

        arrayfile_t *afile = new arrayfile_t (fname);
        if (!afile->isopen ()) {
                printf ("Problem opening %s\n", fname);
                exit (1);
        }

        logstream (NORMAL) << "Check mode: " << mode << " (" << modeString (mode) << ")" << endl;

        /* start checking */
        double Tstart = get_time_ms (), dt;

        int index;
        array_link al (afile->nrows, afile->ncols, -1);
        for (int i = 0; i < afile->narrays; i++) {

                index = afile->read_array (al);
                array_t *array = al.array;

                arraydata_t arrayclass = arraylink2arraydata (al, 0, strength);
                arrayclass.lmc_overflow_check ();

                OAextend oaextend;

                lmc_t result = LMC_NONSENSE;

                LMCreduction_t *reduction = new LMCreduction_t (&arrayclass);
                LMCreduction_t *randtest = new LMCreduction_t (&arrayclass);
				array_link test_arraylink = al.clone();
				array_t *testarray = test_arraylink.array;
                randtest->transformation->randomize ();
                reduction->setArray ( al); 
                /* variables needed within the switch statement */
                switch (mode) {
                case MODE_CHECK:
				{
					/* LMC test with reduction code */
					reduction->mode = OA_TEST;
					result = LMCcheck(al, arrayclass, oaextend, *reduction);
					break;
				}
                case MODE_CHECKJ4: {
                        /* LMC test with special code */
                        reduction->mode = OA_TEST;
                        reduction->init_state = COPY;
                        oaextend.setAlgorithm (MODE_J4, &arrayclass);
                        result = LMCcheck (al, arrayclass, oaextend, *reduction);
                        break;
                }
                case MODE_REDUCEJ4: {
                        /* LMC test with special code */
                        reduction->mode = OA_REDUCE;
                        reduction->setArray (al);
                        result = LMCcheckj4 (al, arrayclass, *reduction, oaextend);
                        break;
                }
                case MODE_CHECK_SYMMETRY: {
					myprintf("MODE_CHECK_SYMMETRY not supported any more");
					exit(1);
                }
                case MODE_CHECKJ5X: {
                        oaextend.setAlgorithm (MODE_J5ORDERX, &arrayclass);

                        /* LMC test with special code */
                        reduction->mode = OA_TEST;
                        reduction->init_state = COPY;

                        result = LMCcheck (al, arrayclass, oaextend, *reduction);
                        break;
                }
                case MODE_CHECKJ5XFAST: {
                        oaextend.setAlgorithm (MODE_J5ORDERX, &arrayclass);

                        /* LMC test with special code */
                        reduction->mode = OA_TEST;
                        reduction->init_state = COPY;
                        if (1) {
                                array_link al (array, arrayclass.N, arrayclass.ncols, al.INDEX_NONE);
                                reduction->updateSDpointer (al);
                        }
                        result = LMCcheck (al, arrayclass, oaextend, *reduction);
                        break;
                }
                case MODE_REDUCEJ5X: {
                        OAextend oaextend;
                        oaextend.setAlgorithm (MODE_J5ORDERX, &arrayclass);

                        /* LMC test with special code */
                        printf ("oacheck: WARNING: MODE_CHECKJ5X: untested code, not complete\n");
                        reduction->mode = OA_REDUCE;
                        result = LMCcheck (al, arrayclass, oaextend, *reduction);
                        break;
                }

                case MODE_REDUCE:
                        /* LMC reduction */
				{
					reduction->mode = OA_REDUCE;
					copy_array(array, reduction->array, arrayclass.N, arrayclass.ncols);
					dyndata_t dynd = dyndata_t(arrayclass.N);

					result = LMCreduction(array, array, &arrayclass, &dynd, reduction, oaextend);
					break;
				}
				case MODE_REDUCERANDOM: 
					{
						/* random LMC reduction */
						oaextend.setAlgorithm(MODE_ORIGINAL, &arrayclass);
						reduction->mode = OA_REDUCE;
						randtest->transformation->apply(array, testarray);
						copy_array(testarray, reduction->array, arrayclass.N, arrayclass.ncols);
						reduction->init_state = INIT;
						array_link alp = arrayclass.create_root(arrayclass.ncols, 1000);
						reduction->setArray(alp);
						dyndata_t dynd = dyndata_t(arrayclass.N);

						result = LMCreduction(testarray, testarray, &arrayclass, &dynd, reduction, oaextend);

						if (log_print(NORMAL, "")) {
							reduction->transformation->show();
						}
					} break;
				
                case MODE_REDUCETRAIN:
                        /* LMC reduction with train*/
                        reduction->mode = OA_REDUCE;
                        result = LMCreduction_train (al, &arrayclass, reduction, oaextend);
                        break;
                case MODE_REDUCETRAINRANDOM:
                        /* random LMC reduction with train*/
                        reduction->mode = OA_REDUCE;

                        randtest->transformation->apply (array, testarray);
                        result = LMCreduction_train (test_arraylink, &arrayclass, reduction, oaextend);
                        break;
                case MODE_HADAMARD:
						myprintf("MODE_HADAMARD not supported any more\n");
						exit(1);
                default:
                        result = LMC_NONSENSE;
                        std::cout << "function " << __FUNCTION__ << "line " << __LINE__ << "Unknown mode" << std::endl;
                        exit (1);
                        break;
                }

                bool aequal;
                switch (mode) {
                case MODE_CHECK:
                        if (result == LMC_LESS) {
                                ++wrong;
                                log_print (NORMAL, "Found array nr %i/%i NOT in lmc form:\n", i, afile->narrays);
                        } else {
                                ++correct;
                                log_print (NORMAL, "Found array nr %i/%i in lmc form.\n", i, afile->narrays);
                        }

                        break;
                case MODE_CHECKJ4:
                case MODE_CHECKJ5X:
                case MODE_CHECKJ5XFAST:
                case MODE_CHECK_SYMMETRY:
                        if (result == LMC_LESS) {
                                ++wrong;
                                log_print (NORMAL, "Found array nr %i/%i NOT in minimal form:\n", i, afile->narrays);
                        } else {
                                ++correct;
                                log_print (NORMAL, "Found array nr %i/%i in minimal form.\n", i, afile->narrays);
                        }

                        break;
                case MODE_REDUCE:
                case MODE_REDUCEJ4:
                case MODE_REDUCEJ5X:
                case MODE_REDUCETRAIN:
                        aequal = std::equal (array, array + arrayclass.N * arrayclass.ncols, reduction->array);

                        if ((!aequal) || reduction->state == REDUCTION_CHANGED) {
                                ++wrong;
                                log_print (QUIET, "Reduced array %i/%i to lmc form.\n", i, afile->narrays);
                                if (checkloglevel (NORMAL)) {
                                        log_print (QUIET, "Original:\n");
										
                                        print_array (array, afile->nrows, afile->ncols);
                                        print_array ("Reduction:\n", reduction->array, afile->nrows, afile->ncols);
                                        printf ("---------------\n");
                                }
                                if (checkloglevel (DEBUG)) {
                                        cout << "Transformation: " << endl;
                                        reduction->transformation->show (cout);

                                        rowindex_t row;
                                        colindex_t column;
                                        array_diff (array, reduction->array, arrayclass.N, arrayclass.ncols, row, column);
                                        cout << "Difference at: ";
                                        printf (" row %d, col %d\n", row, column);
                                }
                        } else {
                                ++correct;
                                log_print (QUIET, "Array %i/%i was already in lmc form:\n", i, afile->narrays);
                        }
                        break;
                case MODE_REDUCETRAINRANDOM:
                case MODE_REDUCERANDOM:
                case MODE_REDUCEJ4RANDOM:
                        aequal = std::equal (array, array + arrayclass.N * arrayclass.ncols, reduction->array);

                        if (!aequal) {
                                ++wrong;
                                log_print (SYSTEM,
                                           "Array %i/%i: reduced random transformation not equal to original (BUG!)\n",
                                           i, afile->narrays);
                                if (checkloglevel (NORMAL)) {
                                        print_array ("Original:\n", array, afile->nrows, afile->ncols);
                                        print_array ("Randomized:\n", testarray, afile->nrows, afile->ncols);
                                        print_array ("Reduction:\n", reduction->array, afile->nrows, afile->ncols);
                                        printf ("---------------\n");
                                }
                        } else {
                                ++correct;
                                log_print (QUIET, "Array %i/%i: reduced random transformation to original\n", i,
                                           afile->narrays);
                        }

                        break;
                case MODE_HADAMARD:
                        break;
                default:
                        std::cout << "function " << __FUNCTION__ << "line " << __LINE__ << "unknown mode" << std::endl;
                        break;
                }

                array_link al = array_link ((carray_t *)reduction->array, afile->nrows, afile->ncols, -1);
                if (result == LMC_MORE || !prune) {
                        outputlist.push_back (al);
                }
                delete randtest;
                delete reduction;
                destroy_array (testarray);
        }

        afile->closefile ();
        delete afile;

        if (writeoutput) {
                logstream (NORMAL) << "Writing output (" << outputlist.size () << " arrays)" << endl;
                writearrayfile (outputfile, outputlist);
        }

        logstream (QUIET) << "#time end: " << currenttime () << std::endl;

        return 0;
}
Exemplo n.º 4
0
/**
 * @brief Main function for oaextendmpi and oaextendsingle
 * @param argc
 * @param argv[]
 * @return
 */
int main (int argc, char *argv[]) {
#ifdef OAEXTEND_SINGLECORE
        const int n_processors = 1;
        const int this_rank = 0;
#else
        MPI::Init (argc, argv);

        const int n_processors = MPI::COMM_WORLD.Get_size ();
        const int this_rank = MPI::COMM_WORLD.Get_rank ();
#endif

        // printf("MPI: this_rank %d\n", this_rank);

        /*----------SET STARTING ARRAY(S)-----------*/
        if (this_rank != MASTER) {
#ifdef OAEXTEND_MULTICORE
                slave_print (QUIET, "M: running core %d/%d\n", this_rank, n_processors);
#endif
                algorithm_t algorithm = MODE_INVALID;
                AnyOption *opt = parseOptions (argc, argv, algorithm);
                OAextend oaextend;
                oaextend.setAlgorithm (algorithm);

#ifdef OAEXTEND_MULTICORE
                log_print (NORMAL, "slave: receiving algorithm int\n");
                algorithm = (algorithm_t)receive_int_slave ();
                oaextend.setAlgorithm (algorithm);
// printf("slave %d: receive algorithm %d\n", this_rank, algorithm);
#endif

                extend_slave_code (this_rank, oaextend);

                delete opt;
        } else {
                double Tstart = get_time_ms ();
                int nr_extensions;
                arraylist_t solutions, extensions;

                algorithm_t algorithm = MODE_INVALID;
                AnyOption *opt = parseOptions (argc, argv, algorithm);
                print_copyright ();

                int loglevel = opt->getIntValue ('l', NORMAL);
                setloglevel (loglevel);

                int dosort = opt->getIntValue ('s', 1);
                int userowsymm = opt->getIntValue ("rowsymmetry", 1);
                int maxk = opt->getIntValue ("maxk", 100000);
                int initcolprev = opt->getIntValue ("initcolprev", 1);

                const bool streaming = opt->getFlag ("streaming");

                bool restart = false;
                if (opt->getValue ("restart") != NULL || opt->getValue ('r') != NULL) {
                        restart = true;
                }

                const char *oaconfigfile = opt->getStringValue ('c', "oaconfig.txt");
                const char *resultprefix = opt->getStringValue ('o', "result");

                arrayfile::arrayfilemode_t mode = arrayfile_t::parseModeString (opt->getStringValue ('f', "T"));

                OAextend oaextend;
                oaextend.setAlgorithm (algorithm);

                if (streaming) {
                        logstream (SYSTEM) << "operating in streaming mode, sorting of arrays will not work "
                                           << std::endl;
                        oaextend.extendarraymode = OAextend::STOREARRAY;
                }

                // J5_45
                int xx = opt->getFlag ('x');
                if (xx) {
                        oaextend.j5structure = J5_45;
                }

                if (userowsymm == 0) {
                        oaextend.use_row_symmetry = userowsymm;
                        printf ("use row symmetry -> %d\n", oaextend.use_row_symmetry);
                }
                if (opt->getFlag ('g')) {
                        std::cout << "only generating arrays (no LMC check)" << endl;
                        oaextend.checkarrays = 0;
                }

                if (opt->getFlag ("help") || (opt->getValue ("coptions") != NULL)) {
                        if (opt->getFlag ("help")) {
                                opt->printUsage ();
                        }
                        if (opt->getValue ("coptions") != NULL) {
                                print_options (cout);
                        }
                } else {
                        logstream (QUIET) << "#time start: " << currenttime () << std::endl;

                        arraydata_t *ad;
                        ad = readConfigFile (oaconfigfile);
                        ad->lmc_overflow_check ();

                        if (ad == 0) {
                                return 1;
                        }

                        log_print (NORMAL, "Using design file: %s (runs %d, strength %d)\n", oaconfigfile, ad->N,
                                   ad->strength);

                        if (oaextend.getAlgorithm () == MODE_AUTOSELECT) {
                                oaextend.setAlgorithmAuto (ad);
                        }

#ifdef OAEXTEND_SINGLECORE
                        if (initcolprev == 0) {
                                log_print (NORMAL, "setting oaextend.init_column_previous to %d\n", INITCOLUMN_ZERO);
                                oaextend.init_column_previous = INITCOLUMN_ZERO;
                        }
#endif

#ifdef OAEXTEND_MULTICORE
                        int alg = oaextend.getAlgorithm ();
                        for (int i = 0; i < n_processors; i++) {
                                if (i == MASTER) {
                                        continue;
                                }
                                log_print (NORMAL, "MASTER: sending algorithm %d to slave %d\n", alg, i);
                                send_int (alg, i);
                        }
#endif
                        colindex_t col_start;

                        log_print (SYSTEM, "using algorithm %d (%s)\n", oaextend.getAlgorithm (),
                                   oaextend.getAlgorithmName ().c_str ());
                        if (log_print (NORMAL, "")) {
                                cout << oaextend.__repr__ ();
                        }

                        if (restart) { // start from result file
                                int initres = init_restart (opt->getValue ('r'), col_start, solutions);
                                if (initres == 1) { // check if restarting went OK
                                        logstream (SYSTEM) << "Problem with restart from " << opt->getValue ('r') << ""
                                                           << endl;

#ifdef OAEXTEND_MPI
                                        MPI_Abort (MPI_COMM_WORLD, 1);
#endif
                                        exit (1);
                                }

                                if (dosort) {
                                        double Ttmp = get_time_ms ();
                                        sort (solutions.begin (), solutions.end ()); // solutions.sort();

                                        log_print (QUIET, "   sorting of initial solutions: %.3f [s]\n",
                                                   get_time_ms () - Ttmp);
                                }

                                // check that oaconfig agrees with loaded arrays
                                if (solutions.size () > 0) {
                                        if (ad->N != solutions[0].n_rows) {
                                                printf ("Problem: oaconfig does not agree with loaded arrays!\n");
                                                // free_sols(solutions); ??
                                                solutions.clear ();
                                        }
                                }

                        } else {
                                // starting with root
                                if (check_divisibility (ad) == false) { 
                                        log_print (SYSTEM, "ERROR: Failed divisibility test!\n");

#ifdef OAEXTEND_MPI
                                        MPI_Abort (MPI_COMM_WORLD, 1);
#endif
                                        exit (1);
                                }
                                create_root (ad, solutions);
                                col_start = ad->strength;
                        }

                        /*-----------MAIN EXTENSION LOOP-------------*/

                        log_print (SYSTEM, "M: running with %d procs\n", n_processors);

                        maxk = std::min (maxk, ad->ncols);

                        time_t seconds;
                        for (colindex_t current_col = col_start; current_col < maxk; current_col++) {
                                fflush (stdout);
                                arraydata_t *adcol = new arraydata_t (ad, current_col + 1);

                                if (streaming) {

                                        string fname = resultprefix;
                                        fname += "-streaming";
                                        fname += "-" + oafilestring (ad);
                                        logstream (NORMAL) << "oaextend: streaming mode: create file " << fname
                                                           << std::endl;
                                        int nb = arrayfile_t::arrayNbits (*ad);

                                        oaextend.storefile.createfile (fname, adcol->N, ad->ncols, -1, ABINARY, nb);
                                }

                                log_print (SYSTEM, "Starting with column %d (%d, total time: %.2f [s])\n",
                                           current_col + 1, (int)solutions.size (), get_time_ms () - Tstart);
                                nr_extensions = 0;
                                arraylist_t::const_iterator cur_extension;

                                int csol = 0;
                                for (cur_extension = solutions.begin (); cur_extension != solutions.end ();
                                     cur_extension++) {
                                        print_progress (csol, solutions, extensions, Tstart, current_col);
                                        logstream (NORMAL) << cur_extension[0];

                                        if (n_processors == 1) {
                                                nr_extensions += extend_array (*cur_extension, adcol,
                                                                               current_col, extensions, oaextend);
                                        } else {
#ifdef OAEXTEND_MPI
                                                throw_runtime_exception("mpi version of oextend is no longer supported");
                                                double Ttmp = get_time_ms ();
                                                int slave = collect_solutions_single (extensions, adcol);
                                                log_print (DEBUG, "   time: %.2f, collect time %.2f\n",
                                                           (get_time_ms () - Tstart), (get_time_ms () - Ttmp));

                                                /* OPTIMIZE: send multiple arrays to slave 1 once step */
                                                extend_array_mpi (cur_extension->array, 1, adcol, current_col, slave);
#endif
                                        }

#ifdef OAEXTEND_MPI
                                        if ((csol + 1) % nsolsync == 0) {
                                                collect_solutions_all (extensions, adcol);
                                        }
#endif
                                        // OPTIMIZE: periodically write part of the solutions to disk
                                        csol++; /* increase current solution */
                                }
#ifdef OAEXTEND_MPI
                                collect_solutions_all (extensions, adcol);
#endif

                                if (checkloglevel (NORMAL)) {
                                        csol = 0;
                                        for (cur_extension = extensions.begin (); cur_extension != extensions.end ();
                                             cur_extension++) {
                                                log_print (DEBUG, "%i: -----\n", ++csol);
                                                logstream (DEBUG) << cur_extension[0];
                                        }
                                }
                                if (dosort) {
                                        log_print (DEBUG, "Sorting solutions, necessary for multi-processor code\n");
                                        double Ttmp = get_time_ms ();
                                        sort (extensions.begin (), extensions.end ());
                                        log_print (DEBUG, "   sorting time: %.3f [s]\n", get_time_ms () - Ttmp);
                                }

                                save_arrays (extensions, adcol, resultprefix, mode);
                                solutions.swap (extensions); // swap old and newly found solutions
                                extensions.clear ();         // clear old to free up space for new extensions

                                log_print (SYSTEM, "Done with column %i, total of %i solutions (time %.2f s))\n",
                                           current_col + 1, (int)solutions.size (), get_time_ms () - Tstart);

                                delete adcol;

#ifdef OAANALYZE_DISCR
                                logstream (NORMAL) << "Discriminant: " << endl;
                                print_discriminant (ad->N, current_col + 1);
#endif
                        }
                        /*------------------------*/
                        time (&seconds);
                        struct tm *tminfo;
                        tminfo = localtime (&seconds);
                        log_print (SYSTEM, "TIME: %.2f s, %s", get_time_ms () - Tstart, asctime (tminfo));
                        logstream (QUIET) << "#time end: " << currenttime () << std::endl;
                        logstream (QUIET) << "#time total: " << printfstring ("%.1f", get_time_ms () - Tstart)
                                          << " [s]" << std::endl;

                        solutions.clear ();
                        delete ad;

#ifdef OAEXTEND_MPI
                        stop_slaves ();
#endif
                }

                delete opt;
        } /* end of master code */

#ifdef OAEXTEND_MPI
        MPI_Finalize ();
#endif

        return 0;
}
Exemplo n.º 5
0
          void game::start()
          {   float FPS=40;

                               SDL_Rect tmprect_surprises,tmprect_surprises2;
              int moneymove=0;

              Uint32 start;
              loadmap("map2.map");
            while(running)
            {
                start=SDL_GetTicks();
                handelevents();
                //logic
                if(direction[0])
                {
                    player1->setDirection('l');
                    if(player1->getRect()->x>80) //it was x>0
                        player1->setXvel(-1);
                    else{
                    camera.x--;
                    baseclass::coord.x--;
                    player1->setXvel(0);
                    }
                    if(camera.x<0)
                        camera.x=6400-screen_width;
                        //player1->set
                       // std::cout<<"la position de coord - est :"<<coord.x<<"la position de camera est :"<<camera.x<<std::endl;
                }
                     else if(direction[1])
                {

                    player1->setDirection('r');
                    if(player1->getRect()->x <80)
                        player1->setXvel(1);
                    else{
                     player1->setXvel(0);
                    camera.x++;
                    baseclass::coord.x++;
                    }
                    if(camera.x>=6400-screen_width)
                        camera.x=0;
                        // std::cout<<"la position de coord + est :"<<coord.x<<"la position de camera est :"<<camera.x<<std::endl;
                }
                else
                    player1->setXvel(0);
int start2=(baseclass::coord.x-(baseclass::coord.x%baseclass::tile_size))/baseclass::tile_size;
int end2=(baseclass::coord.x+baseclass::coord.w+(baseclass::tile_size-(baseclass::coord.x+baseclass::coord.w)%baseclass::tile_size))/baseclass::tile_size;
if(start2<0)
    start2=0;
if(end2>map1[0].size())
    end2=map1[0].size();
bool    nocollision=0;
for (int i=0;i<map1.size();i++)
    {
      for (int j=start2;j<end2;j++)
      {
         if( map1[i][j]==0)
            continue;
         SDL_Rect dest_rect={j*30-baseclass::coord.x,i*30,30,30};
          for (int g=0;g<bullets.size();g++)
          {
            if(collision(bullets[g]->getRect(),&dest_rect))
               {
                 b1->setFrame(1);
                               // b1->setX(bullets[g]->getRect()->x+20);
                               if(player1->getDirection()=='r')
                               b1->setX(j*30-14);
                               else
                                b1->setX(j*30+24);
                                b1->setY(bullets[g]->getRect()->y);

                delete bullets[g];

                bullets.erase(bullets.begin()+g);
                }
           }

                             for (int j=0;j<Champignons.size();j++)
                          {
                              SDL_Rect tmprect ={Champignons[j]->getRect()->x-baseclass::coord.x,Champignons[j]->getRect()->y,30,30};

        for (int k=0;k<Champignons.size();k++)
                              {
                                  if(k!=j){


                                SDL_Rect tmprect2 ={Champignons[k]->getRect()->x-baseclass::coord.x,Champignons[k]->getRect()->y,30,30};
                                if (collision(&tmprect,&tmprect2))
                                {
                                   Champignons[j]->setxvel(1);
                                   Champignons[j]->setdirection('r');
                                   Champignons[k]->setxvel(-1);
                                   Champignons[k]->setdirection('l');
                                   std::cout<<"here is collision between two enemies "<<std::endl;
                                }
                              }
                             }



                             }

                               for (int j=0;j<Champignons.size();j++)
                          {
                              SDL_Rect tmprect ={Champignons[j]->getRect()->x-baseclass::coord.x,Champignons[j]->getRect()->y,30,30};

                             for (int k=0;k<Tortues.size();k++)
                              {


                                SDL_Rect tmprect2 ={Tortues[k]->getRect()->x-baseclass::coord.x,Tortues[k]->getRect()->y,30,30};
                                if ((tmprect.x+30==tmprect2.x)&&(Tortues[k]->getetat()==2)&&(Champignons[j]->getPuissance()==1))
                                {
                                   Champignons[j]->setxvel(-1);
                                   Champignons[j]->setdirection('r');
                                   Tortues[k]->setxvel(1);
                                   Tortues[k]->setdirection('l');
                               }else
                                if ((tmprect.x==tmprect2.x+30)&&(Tortues[k]->getetat()==2)&&(Champignons[j]->getPuissance()==1))
                                {
                                   Champignons[j]->setxvel(1);
                                   Champignons[j]->setdirection('r');
                                   Tortues[k]->setxvel(-1);
                                   Tortues[k]->setdirection('l');
                               }else
                                if ((tmprect.x==tmprect2.x+30)&&(Tortues[k]->getetat()==1)&&(Champignons[j]->getPuissance()==1))
                                {
                                   delete Champignons[j];
                                   Champignons.erase(Champignons.begin()+j);

                               }
                               else
                                if ((tmprect.x+30==tmprect2.x)&&(Tortues[k]->getetat()==1)&&(Champignons[j]->getPuissance()==1))
                                {
                                   delete Champignons[j];
                                   Champignons.erase(Champignons.begin()+j);

                               }

                             }
                          }

                            for (int j=0;j<Tortues.size();j++)
                          {
                              SDL_Rect tmprect ={Tortues[j]->getRect()->x-baseclass::coord.x,Tortues[j]->getRect()->y,30,30};

                               for (int k=0;k<Tortues.size();k++)
                              {
                                  if(k!=j){


                                SDL_Rect tmprect2 ={Tortues[k]->getRect()->x-baseclass::coord.x,Tortues[k]->getRect()->y,30,30};
                                if ((collision(&tmprect,&tmprect2))&&(Tortues[j]->getetat()!=1)&&(Tortues[k]->getetat()!=1))
                                {
                                   Tortues[j]->setxvel(1);
                                   Tortues[j]->setdirection('r');
                                   Tortues[k]->setxvel(-1);
                                   Tortues[k]->setdirection('l');
                                   std::cout<<"here is collision between two tortues "<<std::endl;
                                }
                                if (collision(&tmprect,&tmprect2)&&Tortues[j]->getetat()==1)
                                {
                                     delete Tortues[k];
                                     Tortues[j]->setxvel(5);
                                    Tortues.erase(Tortues.begin()+k);
                                }
                              }
                             }
                          }







        }
        }
                   for (int i=0;i<bullets.size();i++)
                    {
                      if((bullets[i]->getRect()->x >= screen->w)||(bullets[i]->getRect()->x  <=0))
                        {
                         delete bullets[i];
                         bullets.erase(bullets.begin()+i);
                        }
                         }
                         for (int i=0;i<bullets.size();i++)
                         {
                          for (int j=0;j<Champignons.size();j++)
                          {
                              SDL_Rect tmprect ={Champignons[j]->getRect()->x-baseclass::coord.x,Champignons[j]->getRect()->y,30,30};
                              if(collision(&tmprect,bullets[i]->getRect()))
                              {
                                b1->setFrame(1);
                                b1->setX(Champignons[j]->getRect()->x);
                                b1->setY(Champignons[j]->getRect()->y);
                                 delete bullets[i];
                                 delete Champignons[j];
                                 bullets.erase(bullets.begin()+i);
                                 Champignons.erase(Champignons.begin()+j);
                              }
                          }
                          for (int j=0;j<Tortues.size();j++)
                          {
                              SDL_Rect tmprect ={Tortues[j]->getRect()->x-baseclass::coord.x,Tortues[j]->getRect()->y,30,30};
                              if(collision(&tmprect,bullets[i]->getRect()))
                              {
                                b1->setFrame(1);
                                b1->setX(Tortues[j]->getRect()->x);
                                b1->setY(Tortues[j]->getRect()->y);
                                 delete bullets[i];
                                 delete Tortues[j];
                                 bullets.erase(bullets.begin()+i);
                                 Tortues.erase(Tortues.begin()+j);
                              }
                          }




                         }


                         for (int i=0;i<bullets.size();i++)
                         {
                          for (int j=0;j<fleur_toxiques.size();j++)
                          {
                              SDL_Rect tmprect ={fleur_toxiques[j]->getRect()->x-baseclass::coord.x,fleur_toxiques[j]->getRect()->y,30,30};
                              if(collision(&tmprect,bullets[i]->getRect()))
                              {
                                b1->setFrame(1);
                                  b1->setX(fleur_toxiques[j]->getRect()->x);
                                b1->setY(tmprect.y);
                               delete bullets[i];
                                 delete fleur_toxiques[j];
                                 bullets.erase(bullets.begin()+i);
                                 fleur_toxiques.erase(fleur_toxiques.begin()+j);
                              }
                          }
                         }

                               for (int j=0;j<Champignons.size();j++)
                          {
                              int set_life_power=0;
                              SDL_Rect tmprect ={Champignons[j]->getRect()->x-baseclass::coord.x,Champignons[j]->getRect()->y,30,30};
                                 if(collision(&baseclass::coord,Champignons[j]->getRect()))
                                 {
                              if(collision(&tmprect,player1->getRect()))
                              {
                                 std::cout<<"collesion enemy yvel  "<<tmprect.y<< "pleyer y vel "<<player1->getRect()->y<<std::endl;
                               if((player1->getRect()->y< tmprect.y )&&(Champignons[j]->getPuissance()>0))
                               {
                                   Champignons[j]->setpuissance(0);
                                   std::cout<<"collesion enemy yvel  "<<Champignons[j]->getFrame()<<std::endl;
                                  // delete Champignons[j];
                                   // Champignons.erase(Champignons.begin()+j);
                               }
                               else
                                if((player1->getRect()->y==tmprect.y )&&(set_life_power>=0)&&(Champignons[j]->getPuissance()>0))
                                {

                                     player1->setHealth(-1);
                                   //std::cout<<"enemy killl me et mon lhealth est  :"<<player1->getHealth();
                                   delete Champignons[j];//version before i was neot here
                                    Champignons.erase(Champignons.begin()+j); //version before i was neot here
                                }
                              }
                              if((player1->getRect()->x> tmprect.x+60||player1->getRect()->x < tmprect.x-60)&&(Champignons[j]->getPuissance()==0))
                              {
                                  delete Champignons[j];//version before i was neot here
                                    Champignons.erase(Champignons.begin()+j); //version before i was neot here

                              }
                              Champignons[j]->move(map1);
                              }
                               }
                               for (int j=0;j<Tortues.size();j++)
                          {   bool setEtat =false;
                              SDL_Rect tmprect ={Tortues[j]->getRect()->x-baseclass::coord.x,Tortues[j]->getRect()->y,30,30};
                                 if(collision(&baseclass::coord,Tortues[j]->getRect()))
                                 {
                              if(collision(&tmprect,player1->getRect()))
                              {
                                 std::cout<<"collesion enemy yvel  "<<tmprect.y<< "pleyer y vel "<<player1->getRect()->y<<std::endl;
                               if((player1->getRect()->y< tmprect.y )&&(Tortues[j]->getetat()==2))
                               {
                                   Tortues[j]->setetat(1);
                                  // delete Tortues[j];
                                   // Tortues.erase(Tortues.begin()+j);
                               }
                               else  if((player1->getRect()->y== tmprect.y )&&(Tortues[j]->getetat()==2))

                                {
                                     player1->setHealth(-1);
                                   //std::cout<<"enemy killl me et mon lhealth est  :"<<player1->getHealth();
                                   delete Tortues[j];//version before i was neot here
                                    Tortues.erase(Tortues.begin()+j); //version before i was neot here
                                }
                              }
                              Tortues[j]->move(map1);
                              }
                               }








                               for (int i=0;i<moneis.size();i++)
                               {
                                   SDL_Rect tmprect ={moneis[i]->getRect()->x-baseclass::coord.x,moneis[i]->getRect()->y,30,30};


                                 if(collision(&tmprect,player1->getRect()))
                              {
                                   delete moneis[i];//version before i was neot here
                                    moneis.erase(moneis.begin()+i); //version before i was neot here
                                   player1->setmoney(1);
                                   if (player1->getmoney()==100)
                                   {
                                    player1->setmoney(0);
                                    player1->setHealth(1);
                                   }

                              }



                               }

                                for (int i=0;i<surprises.size();i++)
                               {
                                    tmprect_surprises ={surprises[i]->getRect()->x-baseclass::coord.x,surprises[i]->getRect()->y,30,30};
                                    if((player1->getRect()->x+15>=tmprect_surprises.x)&&(player1->getRect()->x<=tmprect_surprises.x+20)&&(player1->getRect()->y==tmprect_surprises.y+40))
                                      {
                                           moneymove=1;
                                           tmprect_surprises2={surprises[i]->getRect()->x-baseclass::coord.x,surprises[i]->getRect()->y,30,30};

                                          std::cout<<"player get y"<<player1->getRect()->y<<std::endl;

                                   if (player1->getmoney()==100)
                                   {
                                   }
                                     }
                                   }
                                   for (int i=0;i<fleur_ames.size();i++)
                               {
                                 SDL_Rect tmprect ={fleur_ames[i]->getRect()->x-baseclass::coord.x,fleur_ames[i]->getRect()->y,30,30};

                               if(collision(player1->getRect(),&tmprect))
                               {
                                  delete fleur_ames[i];
                                 fleur_ames.erase(fleur_ames.begin()+i);
                                    player1->setpower(1);
                               }
                               }

                                  for (int i=0;i<fleur_toxiques.size();i++)
                               {
                                 SDL_Rect tmprect ={fleur_toxiques[i]->getRect()->x-baseclass::coord.x,fleur_toxiques[i]->getRect()->y,30,30};

                               if(collision(player1->getRect(),&tmprect)&&fleur_toxiques[i]->getmouvement()==true)
                               {
                                    player1->setpower(-1);
                               }
                               }

                                   if (moneymove>0 && moneymove<30)
                                    {
                                    moneymove++;
                                     for (int i=0;i<surprises.size();i++)
                                     {
                                        tmprect_surprises ={surprises[i]->getRect()->x-baseclass::coord.x,surprises[i]->getRect()->y,30,30};
                                       if (tmprect_surprises.x==tmprect_surprises2.x&& surprises[i]->getmovement()==false)
                                        {




                                            if (i!=2&&moneymove==5)
                                                     {
                                                      monies_surp.push_back(new money(mon2,surprises[i]->getRect()->x,tmprect_surprises.y-60,-1,0)); //because every tile is TILE_SIZE width and height, we can calculate
                                                      }








                                        surprises[i]->setY(-1);


                                        }
                                     }



                                    }
                                    if (moneymove>=30 && moneymove<=59)
                                        {


                                            moneymove++;

                                        for (int i=0;i<surprises.size();i++)
                                     {
                                        tmprect_surprises ={surprises[i]->getRect()->x-baseclass::coord.x,surprises[i]->getRect()->y,30,30};
                                       if (tmprect_surprises.x==tmprect_surprises2.x&& surprises[i]->getmovement()==false)
                                        {   if (i==2&&moneymove==31)
                                        {
                                             fleur_ames.push_back(new fleur_ame(fleur_am1,surprises[i]->getRect()->x-1,tmprect_surprises.y,10,0)); //because every tile is TILE_SIZE width and height, we can calculate

                                           }

                                        surprises[i]->setY(1);
                                       }
                                     }


                                     }





                                       for (int i=0;i<monies_surp.size();i++)
                                     {

                                      if (monies_surp[i]->getFrame()>1.5)
                                      {
                                            delete monies_surp[i];
                                        monies_surp.erase(monies_surp.begin()+i);
                                        player1->setmoney(1);
                                         if (player1->getmoney()>100)
                                         {
                                             player1->setHealth(1);
                                             player1->setmoney(0);

                                         }

                                      }

                                     }





                                     if (moneymove==59)
                                        {
                                        for (int i=0;i<surprises.size();i++)
                                        {
                                        tmprect_surprises ={surprises[i]->getRect()->x-baseclass::coord.x,surprises[i]->getRect()->y,30,30};
                                       if (tmprect_surprises.x==tmprect_surprises2.x&& surprises[i]->getmovement()==false){


                                        surprises[i]->setmovement(true);
                                        surprises[i]->setFrame(3);
                                        player1->setpower(1);
                                        }
                                     }
                                     }

                                       /*for (int i=0;i<surprises.size();i++)
                               {*/
                                    //tmprect_surprises ={surprises[i]->getRect()->x-baseclass::coord.x,surprises[i]->getRect()->y,30,30};

                                     // }
                                     //surprises[i]->setmovement(true);








                    for (int i=0;i<bullets.size();i++)
                       {
                       bullets[i]->setangle(20);
                       bullets[i]->move();

                       }

                player1->move(map1);

                   if(1000/FPS>SDL_GetTicks()-start)
                    {
                    SDL_Delay(1000/FPS-(SDL_GetTicks()-start));
                       }

                time++;
                if(time>15)
                    {
                        time=0;
                        temps2--;
                    }
                //render

                SDL_BlitSurface(background,&camera,screen,NULL);
            b1->show2(screen);
               relatifdetails("Mario Bross World 1 ");
               currenttime();
                showmap();
                player1->showplayer(screen);

//                playe->show2(screen);
//                su->show(screen);
                 for (int i=0;i<bullets.size();i++)
                {
            bullets[i]->show("bullet2.bmp",screen);

               }
                for (int i=0;i<surprises.size();i++)
             {
            surprises[i]->show(screen);
             }
              for (int i=0;i<fleur_toxiques.size();i++)
              {
                  fleur_toxiques[i]->show(screen);
              }
              for (int i=0;i<fleur_ames.size();i++)
             {
            fleur_ames[i]->show(screen);
             }
               for (int i=0;i<moneis.size();i++)
             {
            moneis[i]->show(screen);
             }

              for (int i=0;i<monies_surp.size();i++)
             {
               monies_surp[i]->show2(screen);
             }
                 for (int i=0;i<Champignons.size();i++)
                  {
                    Champignons[i]->show(screen);
                 }
        for (int i=0;i<Tortues.size();i++)
                  {
                    Tortues[i]->show(screen);
                 }


                SDL_Flip(screen);
                if(temps2==0||player1->getHealth()==0 || player1->getRect()->y >=screen->h)//||player1->getRect())
                {
                    running=false;
                    SDL_Delay(3000);
                   showmessage("Game Over");
                }
                SDL_Rect tmprect2={finish.x-coord.x,finish.y,30,30};
                if(player1->getRect()->x+player1->getRect()->w>= tmprect2.x-tmprect2.w*2)
                {
                    showmessage("You win");
                    SDL_Delay(1000);
                    running=false;
                }

                   if(1000/FPS>SDL_GetTicks()-start)
                    {
                    SDL_Delay(1000/FPS-(SDL_GetTicks()-start));
                       }
            }
          }