int main (int argc, const char * argv[]) { char c; FILE *file; int n=0, loop=0; int prodof5 = 1; int maxprod = 1; int num=1, firstnum=0; int firstfive[5] = {0}; int i=0; file = fopen("longnumber.txt", "r"); //to open the file in read mode, right now file is in the same directory as this file is printf("opend file\n"); if (file) { //initial set up for(i=0;i<5;i++) { if ((c = fgetc(file)) != EOF) { num = atoi2(c); firstfive[i] = num; prodof5 = prodof5 * num; } } maxprod = prodof5; while ((c = fgetc(file)) != EOF) { num = atoi2(c); if(num != 0){ // can improve a bit by checking if num==firstfive[0], in w/c case same result so can just continue in that case. prodof5 = prodof5/firstfive[0]; prodof5 = prodof5 * num; if (maxprod < prodof5) { maxprod = prodof5; reshuffle(firstfive, num); } else{ reshuffle(firstfive, num); } } //putchar(c); } fclose(file); } printf("consecutive sum is %d\n", maxprod); return 0; }
bool n3d_schedule_t::start(const uint32_t max_threads) { if (max_threads) { // todo: lets remove this in favour of thread_.size() num_threads_ = max_threads; // create the thread to bin mapping thread_map_.reset(new uint32_t[max_threads]); // create a bunch of worker threads for (uint32_t i = 0; i < max_threads; ++i) { thread_.emplace_back(new n3d_worker_t(*this)); } // shuffle the thread to bin mapping reshuffle(); // launch all of the workers for (auto& thread : thread_) { thread->start(); } } else { //todo: do we need to reshuffle? } return true; }
struct shuffle_track *shuffle_list_get_prev(struct list_head *head, struct shuffle_track *cur, int (*filter)(const struct simple_track *)) { struct list_head *item; if (cur == NULL) return to_shuffle_track(head->next); item = cur->node.prev; again: while (item != head) { struct shuffle_track *track = to_shuffle_track(item); if (filter((struct simple_track *)track)) return track; item = item->prev; } if (repeat) { if (auto_reshuffle) reshuffle(head); item = head->prev; goto again; } return NULL; }
/* This routine integrates the physical values with a stiffly stable scheme */ void Integrate_SS(int Je, double dt, Element_List *U, Element_List *Uf, double **u, double **uf) { register int i; int nq; nq = U->htot*U->nz; dcopy(nq, U->base_h, 1, u[0], 1); dcopy(nq, Uf->base_h, 1, uf[0], 1); dsmul(nq, Alpha_Int[Je-1], u[Je-1], 1,U->base_h, 1); for(i = 0; i < Je-1; ++i) daxpy(nq, Alpha_Int[i], u[i], 1, U->base_h, 1); for(i = 0; i < Je; ++i) daxpy(nq, Beta_Int[i]*dt, uf[i], 1, U->base_h, 1); reshuffle( u, Je); reshuffle(uf, Je); }
void n3d_schedule_t::next_frame() { reshuffle(); n3d_assert(counter_ == 0); const long new_val = (long)bins_.size(); const long old_val = n3d_atomic_xchg(counter_, new_val); n3d_assert(old_val == 0); n3d_atomic_inc(frame_num_); }
/* This routine integrates the transformed values */ void integrate_CNAB(int Je, double dt, Element_List *U, Element_List *Uf[]) { register int i; int nq = U->hjtot*U->nz; dsmul(nq, Beta_Int[Je-1]*dt, Uf[Je-1]->base_hj, 1, Uf[Je-1]->base_hj, 1); for(i = 0; i < Je-1; ++i) daxpy(nq, Beta_Int[i]*dt, Uf[i]->base_hj,1, Uf[Je-1]->base_hj, 1); dvadd(nq, Uf[Je-1]->base_hj,1, U->base_hj, 1, U->base_hj, 1); reshuffle(Uf,Je); }
/* This routine integrates the physical values */ void Integrate_CNAM(int Je, double dt, Element_List *U, Element_List *Uf, double **uf) { register int i; int nq; double theta = dparam("THETA"); nq = U->htot*U->nz; dcopy(nq, Uf->base_h, 1, uf[0], 1); /* multiply u^n by theta factor */ dscal(nq, 1.0/(1-theta),U->base_h,1); for(i = 0; i < Je; ++i) daxpy(nq, Beta_Int[i]*dt, uf[i], 1, U->base_h,1); reshuffle(uf,Je); }