void Pthread_detach(pthread_t tid){ if(pthread_detach(tid) != 0) QUIT("pthread detach error"); }
void Pthread_cancel(pthread_t tid){ if(pthread_cancel(tid) != 0) QUIT("pthread cancel error"); }
void Pthread_create(pthread_t *tidp, void *(*start_rtn)(void*), void *arg){ if(pthread_create(tidp, NULL, start_rtn, arg) != 0) QUIT("pthread create error"); }
logical DLInterpreter :: Q ( ) { return(QUIT()); }
int main() { int exit_code = EXIT_SUCCESS; struct buf_t* buf = buf_new(MAX_SIZE); char s[MAX_SIZE + 1]; if (print_prompt() < 0) { QUIT(EXIT_FAILURE); } ssize_t size; while ((size = buf_getline(STDOUT_FILENO, buf, s, MAX_SIZE))) { if (size < 0) { QUIT(EXIT_FAILURE); } s[size] = 0; char** piped_programs = split(s, '|', 0); if (!piped_programs) { goto ERROR; } char** p; for (p = piped_programs; *p; p++) ; int len = p - piped_programs; execargs_t** programs = malloc(len * sizeof(execargs_t*)); if (!programs) { for (char** p = piped_programs; *p; p++) { free(*p); } free(piped_programs); goto ERROR; } for (int i = 0; i < len; i++) { programs[i] = execargs_parse(piped_programs[i]); if (!programs[i]) { for (int j = 0; j < i; j++) { free(programs[j]); } for (int j = 0; j < len; j++) { free(piped_programs[j]); } free(programs); free(piped_programs); goto ERROR; } } if (runpiped(programs, len) < 0) { goto ERROR; } if (print_prompt() < 0) { QUIT(EXIT_FAILURE); } continue; ERROR: if (print_prompt() < 0) { QUIT(EXIT_FAILURE); } } EXIT: buf_free(buf); return exit_code; }
/************************************************************************** Function: main This is the main control flow for the example. After reading and verifying the command line arguments, MPI is initialized. Depending on which option is chosen one of 3 computations are called for analytical, Jacobi iteration using OpenCL, or Jacabo iteration using host and no OpenCL. After the computation is complete, a bitmap representation of the final array is stored in a PPM format file. **************************************************************************/ int main(int argc, char *argv[]) { /* size of matrices for iteration - input parameter */ size_t mat_size[DIMENSIONS] = { DEFAULT_NODES, DEFAULT_NODES }; /* size of OpenCL workblock in each dimension - input parameter */ size_t block_size[DIMENSIONS] = { DEFAULT_BLOCK, DEFAULT_BLOCK }; /* my cartesian position in MPI space */ int my_position[DIMENSIONS] = { 0, 0 }; /* size of matrix for each rank */ size_t rank_size[DIMENSIONS] = {SIZE, SIZE}; /* size of the array needed */ size_t array_size = 100; /* discretion size in each dimension assuming a unit square */ value_type d[DIMENSIONS]; /* maximum number of iterations */ unsigned int max_iter = MAX_ITERATIONS; /* boolean for full copy of buffer or just ghost cells */ unsigned int full_copy = 0; /* boolean for verificaton against reference implementation */ unsigned int verify = 0; /* OpenCL device type - input parameter can override this */ cl_device_type dev_type = CL_DEVICE_TYPE_GPU; /* print welcome message */ printf("A simple %dD iterative Jacobi solver", DIMENSIONS); /* calculate size of each node in the unit square plate */ d[X] = (value_type)(1.0 / (mat_size[X]+1)); d[Y] = (value_type)(1.0 / (mat_size[Y]+1)); /* flush output before starting the compute */ fflush(stdout); /* calculate size of array and allocate the memory */ /* size is 2 bigger to account for "ghost cells" and/or boundaries */ /* exit_app takes care of cleaning up u */ array_size = sizeof(value_type) * (rank_size[X]+2*GHOST_CELL_WIDTH) * (rank_size[Y]+2*GHOST_CELL_WIDTH); u[OLD] = (value_type *)malloc(array_size); u[NEW] = (value_type *)malloc(array_size); /* At this point the main computation can occur. For the purposes of this example * we are using a simple Jacobi iteration technique. This converges very slowly. */ /* compute the exact solution, result in u[NEW] */ if (EXACT_CALC == (signed int)dev_type) { printf("Calculating solution using analytical formula.\n"); exact_compute(u[NEW], rank_size, d); } else if (REFERENCE_CALC == (signed int)dev_type) { /* compute solution using reference implementation, result in u[NEW] */ printf("Estimating solution using Jacobi reference implementation.\n"); reference_jacobi(u, max_iter, rank_size, DEFAULT_TOLERANCE, d); /* compute solution using OpenCL kernel, result in u[NEW] */ } else { ocl_jacobi(u, max_iter, rank_size, DEFAULT_TOLERANCE, d, block_size, dev_type, full_copy); } /* print solution */ print_array("Solve", u[NEW], rank_size, d); /* perform verification if required */ if (verify) { unsigned int i, j, ystride; value_type max_diff = 0.0; /* allocate for verification matrices */ v[OLD] = (value_type *)malloc(array_size); v[NEW] = (value_type *)malloc(array_size); /* compute verfication solution, result in v[NEW] */ printf("Starting verification using Jacobi reference implementation.\n"); reference_jacobi(v, max_iter, rank_size, DEFAULT_TOLERANCE, d); /* compute array differences and store in v[OLD] */ for (i=0; i<rank_size[X]+2*GHOST_CELL_WIDTH; ++i) { /* convenience for y stride in array */ ystride = rank_size[Y]+2*GHOST_CELL_WIDTH; for (j=0; j<ystride; ++j) { /* calculate difference and update maximum difference */ v[OLD][i * ystride + j] = v[NEW][i * ystride + j] - u[NEW][i * ystride + j]; max_diff = (value_type)fmax(max_diff, fabs(v[OLD][i * ystride + j])); } } /* output differences */ print_array("Verify Diff", v[OLD], rank_size, d); printf("Verification complete, max difference with reference implemention is %0.5f.\n", max_diff); /* return error code if max difference is too large */ if (max_diff > 0.0001) { QUIT("Error: max difference greater than required tolerance.\n"); } } /* save bitmap of computation */ save_bitmap(u[NEW], rank_size); /* deallocate arrays and finish use of MPI */ exit_app(0); return 0; }
Main_Window::Main_Window(std::string login_user, DStore dbase) { ds = dbase; currentuser = login_user; //Title setWindowTitle("Amazon Shop"); // Overall layout OverallLayout = new QHBoxLayout(); //this is smaller layout within overall layout SearchOptionLayout = new QVBoxLayout(); OverallLayout->addLayout(SearchOptionLayout); //Terms text SearchTermsLabel = new QLabel("Search Terms"); SearchOptionLayout->addWidget(SearchTermsLabel); //Creating line edit to enter terms to search SearchTermsInput = new QLineEdit(); SearchOptionLayout->addWidget(SearchTermsInput); //Creating exclusive group check-box CheckboxLayout = new QHBoxLayout(); SearchOptionLayout->addLayout(CheckboxLayout); AND = new QRadioButton(tr("AND")); CheckboxLayout->addWidget(AND); OR = new QRadioButton(tr("OR")); CheckboxLayout->addWidget(OR); AND->setAutoExclusive(true); AND->setChecked(true); //Add the search button SearchButton = new QPushButton("SEARCH"); connect(SearchButton, SIGNAL(clicked()), this, SLOT(SEARCH())); SearchOptionLayout->addWidget(SearchButton); //Add the alphabetical merge-sort button SortOptionLayout = new QHBoxLayout(); SearchOptionLayout->addLayout(SortOptionLayout); AlphaSortButton = new QPushButton("Sort Search Alphabetically"); connect(AlphaSortButton, SIGNAL(clicked()), this, SLOT(AlphaSort())); SortOptionLayout->addWidget(AlphaSortButton); //Add the review merge-sort button ReviewSortButton = new QPushButton("Sort Search by Average Rating"); connect(ReviewSortButton, SIGNAL(clicked()), this, SLOT(RSort())); SortOptionLayout->addWidget(ReviewSortButton); //Create dropdown menu to select user UserDropdown = new QComboBox(); //iterating through user vector to print into menu for(unsigned int i=0; i<ds.getUserVector().size(); i++) { std::vector<User*> myVector= ds.getUserVector(); User* user= myVector[i]; QString qstr= QString::fromStdString(user->getName()); UserDropdown->addItem(qstr); } SearchOptionLayout->addWidget(UserDropdown); connect(UserDropdown, SIGNAL(currentIndexChanged(int)), this, SLOT(filler(int))); //Horizontal layout for add and view cart buttons CartOptionLayout = new QHBoxLayout(); SearchOptionLayout->addLayout(CartOptionLayout); //Create add cart button AddCartButton = new QPushButton("Add-to-Cart"); connect(AddCartButton, SIGNAL(clicked()), this, SLOT(ADDCART())); CartOptionLayout->addWidget(AddCartButton); //Create view cart button ViewCartButton = new QPushButton("View-Cart"); connect(ViewCartButton, SIGNAL(clicked()), this, SLOT(VIEWCART())); CartOptionLayout->addWidget(ViewCartButton); //Enter valid file to save to text SaveLabel = new QLabel("Type valid file to save to"); SearchOptionLayout->addWidget(SaveLabel); //Creating line edit to enter terms to search SaveInput = new QLineEdit(); SearchOptionLayout->addWidget(SaveInput); //Save database to a file button SaveButton = new QPushButton("Save Text File"); connect(SaveButton, SIGNAL(clicked()), this, SLOT(SAVE())); SearchOptionLayout->addWidget(SaveButton); //Quit program button QuitButton = new QPushButton("QUIT"); connect(QuitButton, SIGNAL(clicked()), this, SLOT(QUIT())); SearchOptionLayout->addWidget(QuitButton); //Create product list and layout ProductLayout = new QVBoxLayout(); OverallLayout->addLayout(ProductLayout); //Create text for Products ProductsLabel = new QLabel("Products That Match Search"); ProductLayout->addWidget(ProductsLabel); //Create empty list that will have products from search ProductList = new QListWidget(); prodref = ProductList; connect(ProductList, SIGNAL(currentRowChanged(int)), this, SLOT(ProductChange(int))); ProductLayout->addWidget(ProductList); //Create review list and layout ReviewLayout = new QVBoxLayout(); OverallLayout->addLayout(ReviewLayout); //Create text for Reviews ReviewsLabel = new QLabel("Reviews of Product"); ReviewLayout->addWidget(ReviewsLabel); //Create empty list that will have reviews of products from search ReviewList = new QListWidget(); ReviewLayout->addWidget(ReviewList); //Create add reviews layout AddReviewLayout = new QVBoxLayout(); OverallLayout->addLayout(AddReviewLayout); //Create text for adding reviews AddReviewsLabel = new QLabel("Add a Review Section"); AddReviewLayout->addWidget(AddReviewsLabel); //Creating text for adding rating AddReviewsRating = new QLabel("Enter an integer between 1-5"); AddReviewLayout->addWidget(AddReviewsRating); //Creating line edit to enter rating of product RatingLine = new QLineEdit(); AddReviewLayout->addWidget(RatingLine); //Creating text for adding date AddReviewsDate = new QLabel("Enter a date: YYYY-MM-DD"); AddReviewLayout->addWidget(AddReviewsDate); //Creating line edit to enter date of product DateLine = new QLineEdit(); AddReviewLayout->addWidget(DateLine); //Creating text for string of text AddReviewsText = new QLabel("Type in review text"); AddReviewLayout->addWidget(AddReviewsText); //Creating line edit to enter string of text of product TextLine = new QLineEdit(); AddReviewLayout->addWidget(TextLine); AddReviewButton = new QPushButton("ADD REVIEW"); connect(AddReviewButton, SIGNAL(clicked()), this, SLOT(ADDREVIEW())); AddReviewLayout->addWidget(AddReviewButton); setLayout(OverallLayout); }