Assignment Chef icon Assignment Chef

Browse assignments

Assignment catalog

33,401 assignments available

[SOLVED] Cmsc203 –

A property management company manages individual properties they will build to rent, and charges them a management fee as the percentages of the monthly rental amount. The properties cannot overlap each other, and each property must be within the limits of the management company’s plot. Write an application that lets the user create a management company and add the properties managed by the company to its list. Assume the maximum number of properties handled by the company is 5.• Aggregation • Passing object to method • Array Structure • Objects as elements of the Array • Processing array elements • Copy Constructor • Junit testingData Element class – Property.java The class Property will contain: 1. Instance variables for property name, city, rental amount, owner, and plot. Refer to JavaDoc for the data types of each instance variable. 2. toString method to represent a Property object. 3. Constructors and getter and setter methods. Refer to Javadoc of the Property class.Data Element class – Plot.java The class Plot will contain: 1. Instance variables to represent the x and y coordinates of the upper left corner of the location, and depth and width to represent the vertical and horizontal extents of the plot. 2. A toString method to represent a Plot object 3. Constructors, Refer to Javadoc for Plot class. 4. A method named overlaps that takes a Plot instance and determines if it is overlapped by the current plot. 5. A method named encompasses that takes a Plot instance and determines if the current plot contains it. Note that the determination should be inclusive, in other words, if an edge lies on the edge of the current plot, this is acceptable. Data Structure – An Array of Property objects to hold the properties that the management company handles. This array will be declared as an attribute of the ManagementCompany class.Data Manager class – ManagementCompany.java It will contain instance variables of name, tax Id, management fee, MAX_PROPERTY (a constant set to 5) and an array named properties of Property objects of size MAX_PROPERTY, as well as two constants MGMT_WIDTH and MGMT_DEPTH, both set to 10; an attribute plot of type Plot that defines the plot of the ManagementCompany Class. Refer to Javadoc for more details. The class ManagementCompany will contain the following methods in addition to get and set methods: 1. Constructors (refer to Javadoc for more details) 2. Method addProperty (3 versions): 2.1.1. Pass in a parameter of type Property object (calls Property copy constructor). It will add the copy of the Property object to the properties array. 2.2. Method addProperty version 2: 2.2.1. Pass in four parameters of types: • String propertyName, • String city, • double rent, • String ownerName. 2.2.2. Calls Property 4-arg constructor. 2.3. Method addProperty version 3: 2.3.1. Pass in eight parameters of types: • String propertyName, • String city, • double rent, • String ownerName, • int x, • int y, • int width • int depth. 2.3.2. Calls Property 8-arg constructor. 2.4. addProperty methods will return the index of the array where the property is added. If there is a problem adding the property, this method will return -1 if the array is full, -2 if the property is null, -3 if the plot for the property is not encompassed by the management company plot, or -4 if the plot for the property overlaps any other property’s plot. 3. Method totalRent– Returns the total rent of the properties in the properties array.4. Method maxRentPropertyIndex- returns the index of the property within the properties array that has the highest rent amount. This method will be private. 5. Method maxRentProp- Returns the highest rent amount of the property within the properties array. For simplicity assume that each “Property” object’s rent amount is different. This method should call the maxRentPropertyIndex method. 6. Method toString- returns information of ALL the properties within this management company by accessing the “Properties” array. The format is as following example:List of the properties for Alliance, taxID: 1235 ______________________________________________________ Property Name : Belmar Located in Silver Spring Belonging to:John Smith Rent Amount: 1200.0 Property Name : Camden Lakeway Located in Rockville Belonging to:Ann Taylor Rent Amount: 2450.0 Property Name : Hamptons Located in Rockville Belonging to:Rick Steves Rent Amount: 1250.0 ______________________________________________________total management Fee: 294.0Driver class – (provided) The provided PropertyMgmDriverNoGui.java is a class that allows you to test the methods of ManagementCompany.javaGUI Driver class – (provided) A Graphical User Interface (GUI) is provided. Be sure that the GUI will compile and run with your methods. The GUI will not compile if your methods in ManagementCompany.java are not exactly in the format specified. Do not modify the GUI.JUnit Test Run the JUnit test file (provided). Ensure that the JUnit tests all succeed. Do not modify the JUnit tests. Implement your tests in ManagementCompanyTestSTUDENT. These tests should be similar to the Junit tests.Write a Data Element Class named Property that has fields to hold the property name, the city where the property is located, the rent amount, the owner’s name, and the Plot to be occupied by the property, along with getters and setters to access and set these fields. Write a parameterized constructor (i.e., takes values for the fields as parameters) and a copy constructor (takes a Property object as the parameter). Follow the Javadoc file provided.A driver class is provided that creates rental properties to test the property manager. A Graphical User Interface is provided using JavaFX which duplicates this driver’s functionality. You are not required to read in any data, but the GUI will allow you to enter the property management company and each property by hand. A directory of images is provided. Be sure to place the “images” directory (provided) inside the “src” directory in Eclipse. The images do not need to display in order for the GUI to continue running.Upload the initial files from Blackboard and your final java files to GitHub in your repo from Lab 1, in a directory named CMSC203_Assignment4.Operation When driver-driven application starts, a driver class (provided) creates a management company, creates rental properties, adds them to the property manager, and prints information about the properties using the property manager’s methods. When the GUI-driven application starts (provided), a window is created as in the following screen shots which allows the user to enter applicable data and display the resulting property. The driver and the GUI will both use the same classes and methods for their operation. The JUnit test class also tests the same classes as the driver and the GUI. Expected output from running PropertyMgmDriverNoGui.javaExpected output from running with GUI:PropertyMgmGui.java at startupAdd Management Co Info (Note Mgmt Co Plot)Add property information – the Plot outlineAdd property information – successful additionAdd property information – unsuccessful: overlapsAdd property information – unsuccessful: Mgmt Co Plot does not encompass Property Plot Note: red rectangle’s width extends to right of window.Add property information – unsuccessful: too many propertiesResult of “Max Rent” button Result of “Total Rent” buttonResult of “List of Properties” button• Turn in a UML class diagram in a Word document. • Submit pseudo-code for the primary methods specified in ManagementCompany.java, Property.java, and Plot.java in a Word document. Do not just list what gets read in a printed out, but explain the algorithm being used. • Learning Experience: highlight your lessons learned and learning experience from working on this project. o What have you learned? o What did you struggle with? o What will you do differently on your next project? o Include what parts of the project you were successful at, and what parts (if any) you were not successful at. • GitHub: In your repository (see Lab 1), upload your Word file and java file. You will want to upload these files as contents of a directory so that future uploads can be kept separate. Take and submit a screen shot of the GitHub repository. Notes: • Proper naming conventions: All constants, except 0 and 1, should be named. Constant names should be all upper-case, variable names should begin in lower case, but subsequent words should be in title case. Variable and method names should be descriptive of the role of the variable or method. Single letter names should be avoided. Indentation: It must be consistent throughout the program and must reflect the control structureSubmission Detail Submit the following files: • Word document with a name FirstInitialLastName_Assignment3.docx should include: o UML Class Diagram o Pseudocode for each of the methods specified in ManagementCompany.java, Property.java, and Plot.java. o Screen snapshots of the GUI with several properties o Screen snapshot of GitHub submission o Lessons Learned o Check List o doc (a directory) containing your javadoc files o src (a directory) contains your (.java) files o File1.java (example) ▪ File2.java (example) ▪ File_Test.java (example)• A zip file will only contain the .java files and will be named: FirstInitialLastName_Assignment4_Moss.zip. This .zip will not have any folders in it – only .java files.Grading Rubric See attachment: CMSC203 Assignment 4 Rubric_Summer20.xlsxAssignment 4 Check List # Y/N Comments 1. Assignment files: • FirstInitialLastName_ Assignment#_Moss.zip • FirstInitialLastName_Assignment#.docx/.pdf • Source java files 2. Program compiles 3. Program runs with desired outputs related to a Test Plan 4. Documentation file: • Comprehensive Test Plan • Screenshots for each Test case listed in the Test Plan • Screenshots of your GitHub account with submitted Assignment# (if required) • UML Diagram • Algorithms/Pseudocode • Flowchart (if required) • Lessons Learned • Checklist is completed and included in the Documentation

$25.00 View

[SOLVED] Cmsc203 –

Concepts tested by this assignment• Input validation loops • Relational and logical operators • Use a worker class • Create a driver class • Currency format • Random number generation • GitHubCreate a driver class called Birthday. This class will use the Toy class provided for you. Refer to Assignment Details for implementing the Birthday class. You should not make any changes to the Toy class.• All input items and messages will use Dialog boxes. Only the title, list of gifts, total, order number, and programmer name will be printed on the console. NOTE: if you use a Mac, you must use Alerts and TextInputDialog; if you use a Windows machine, JOptionPane (See Chapter 2, Topic 2.14 Dialog Boxes) is slightly simpler, or you could use the Alerts/TextInputDialog option. (See Lecture_ 5_2 Using Library Classes) • Use a Dialog box to display the welcome message. • Ask for the name of the child. • Ask for the age of the child. • Ask for the toy choice and validate the input choice. • Print out a message if the toy is not age appropriate and ask if the user wants to cancel that toy request. • If the user replies “yes”, repeat the steps for the name, age, and toy choice. If the user replies “no”, process the toy requested. • Ask if a card or balloon should be added to the gift. • Display on the console the name, age and the total for gift. • Ask if another gift is desired. If yes, repeat the steps starting with the name of the child. • If no, display on the console the total amount of the order, a random five-digit order number, and the programmer name. • All costs displayed on the console should use currency format. • Write about your Learning Experience, highlighting your lessons learned and learning experience from working on this project. What have you learned? What did you struggle with? What would you do differently on your next project? What parts of this assignment were you successful with, and what parts (if any) were you not successful with. • GitHub: In your repository (see Lab 1), upload your design Word file and java files. You will want to upload these files as contents of a directory so that future uploads can be kept separate.Sample console output:BIRTHDAY GIFTSThe gift for Susie Smith 2 years old is plushie $25.00 The gift for Johnny Jones 5 years old is blocks $20.00 The total cost of your order is $45.00 Order number is 19578 Programmer: insert your name hereTo satisfy the “Good Faith Attempt” (see Blackboard) your code must compile and print the output without finding the name, age, type of toy, cost, or order number. Your GFA need not show the prompts, create the Toy object, or compute the cost or order number. The output for the GFA will be: The gift for x 0 years old is blocks $0.00 The total cost of your order is $0.00 Order number is 0 Programmer: insert your name hereTest your program with at least 3 test cases. Make sure your tests cover all the possible scenarios. Test Case # Input Expected Output Actual OutputDid the test pass?12 3DeliverablesImplementation: • Turn in your Design: pseudo-code and test cases • Turn in the working java file Birthday.java (not the .class file). • Learning Experience: highlight your lessons learned and learning experience from working on this project. What have you learned? What did you struggle with? What will you do differently on your next project? Include what parts of the project you were successful at, and what parts (if any) you were not successful at. • GitHub: In your repository (see Lab 1), upload the files initially provided in Blackboard for the project. When you are finished with the design and programming, upload your design file and java file. You will want to upload these files as contents of a directory so that future uploads can be kept separate. Take a screen shot of the GitHub repository.Submission Detail Submit the following files: • Word document with a name FirstInitialLastName_Assignment2.docx should include: o Pseudocode o Test Plan o Screen snapshots of outputs from Eclipse (related your Test Plan) o Screen snapshots of outputs from CmdLine o Screen snapshot of GitHub submission o Lessons Learned o Check List• A zip file will only contain the .java files and will be named: FirstInitialLastName_Assignment2_Moss.zip. This .zip will not have any folders in it – only .java files. Here’s an example for Assignment 2: R_Brown_Assignment2.docx R_Brown_Assignment2_Moss.zip [a compressed file containing only the following] Birthday.java

$25.00 View

[SOLVED] Cmis 320 project 2

Introduction This assignment allows students to demonstrate their skills in designing relational databases to satisfy specific business rules and requirements. The deliverables for this assignment include an Entity Relationship Diagram (ERD) and the associated detailed documentation describing the database design and structure. In this assignment you will be provided with a description of an application (below) to create an ERD and design accompanying table layout using sound relational modeling concepts and practices. The relationships between the entities and the attributes for the entities will be identified and described. This database will provide the foundation for the follow-on assignment. The following paragraphs provide the background and summary of the business requirements. Scenario You sit down with Mom and Pop to discuss their business and watch their operation for about a week. Mom and Pop rent legacy video/DVDs and discuss their need to move away from maintaining their rental records on paper. You discover for 1 title, they typically (but not always) offer two formats including a video (VCR) and DVD format. Both formats of a movie are kept in a separate plastic case when rented out. They have several copies of each rental movie. There are several videos and DVDs for each movie title. You learn that in their inventory, they have several thousand videos and DVDs, which they get wholesale from about a half dozen distributors. The video and DVD prices to them are based on the quantity of their shipment and the past business they have done with each company. Each video and DVD has a unique identification number that Mom and Pop assign in their inventory, in addition to the distributor’s serial number for the item. Each movie also has a unique identification number Mom and Pop assign in addition to the title, and any movie IDs the distributors use in their electronic catalogs. Distributors provide electronic catalogs to Mom and Pop and the information from these catalogs must be included in the database. Mom and Pop need to record when a video or DVD is rented, when a video or DVD is returned, and all customer charges such as late and damaged fees, failure to rewind fees, and taxes. They need a report of which videos are returned late because there are standard and late charges. On occasion there are discount prices for certain movies or types of movies. Customers want to rent movies based on actors or actresses, running length, type of movie, rating, year released, the director, and the academy awards won (by the movie, the actors, the actresses and/or the directors). Customers also want to know how many videos they have rented in the last month, year, and so forth. Mom and Pop need to keep only basic information on customers in their database, such as name, address, telephone numbers, etc. There must be no limit to the number of video and/or DVD copies of a movie that Mom and Pop can have in their inventory. Video/DVD ID numbers, movie ID numbers, and distributor ID numbers for videos, DVDs, and movies are all different. Also, each movie must be able to have an unlimited number of actors, actresses, directors, and academy awards (i.e., Oscars). Other types of awards (e.g., Golden Globe, People’s Choice, etc.) are not of interest for this application. The rental of equipment, sale of videos, DVDs, popcorn, etc., is not to be kept in the database. Directions Using this information, you should: 1. Review the course content that contains information about: a. Review the difference between a Conceptual Model and a Logical Model (keep in mind that for this assignment, we are not addressing a Physical Model). b. Review the readings about entities (e.g. tables), their attributes (e.g. fields), and the relationships that provide the linkage between pairs of entities (tables). c. Review what a key attribute is for an entity, as this is the main mechanism that can associate one entity to another, as a primary way of doing this in an RDBMS. 2. For your data model: a. First, determine a list of entities needed for the Mom and Pop database. c. Third, create relationship sentence pairs between those entities that are related. You should not have any many-to-many relationships. Hint: If you do have any many-to-many relationships in your preliminary design, you will need to break these down and use an association/intersection entity. 3. Draw an ER model using an ER tool. a. Use either ERAssistant or Visio to create an entity/relationship diagram (ERD) showing all your entities, attributes, and relationships. b. You will find ERAssistant and Visio in the virtual Lab Broker. c. Keep in mind that all entities should be related to at least one other entity. d. Your ERD should have all one-to-many relationships and must not have any many-to-many relationships.Figure 1: Example ERD4. Create ‘metadata’ (e.g., data about data) that describes each entity (table) along with the attributes (field/column) in the ERD. While this information can be done in the comments section of ERAssistant or denoted in Visio, consider using a spreadsheet to identify your metadata for the database. Keep in mind that metadata is typically kept in a “data dictionary” for a given project in the organization, but we’ll simply use a spreadsheet for this assignment. Please pay particular attention to the description of all primary key (via “PK”) and foreign key (via “FK”) columns, as these support the relationships that are designed between tables. A ‘starter’ example of the meta data is shown below. EXPAND on this example to fully describe the entities, attributes, and relationships in your database. (see the readings for this week). Example (starter) Meta Data Mom & Pop DatabaseEntity Name Attributes PK/FK? Data Type Description Producer ID PK integer Primary Key for Producer entity CompanyName no varchar (255) Producer Company Name Country no varchar (255) Producer Country Movie ID PK int Primary key for Movie ProducerID FK int This is the FK that points to Producer Title no varchar (255) Title of Movie Duration no int Length of Movie Rating no char(1) Customer rating of Movie Customer_Movie xxx xxx Customer xxx xxx Figure 2: Example (partial) meta data for the database5. Submit a Word document that contains two parts: (a) a screenshot of the ERD (completed in ERAssistant or Visio), AND your metadata. Name the file your last name, followed by Project 2. For example: Smith_Project_2.ERD. Grading rubric Attribute Meets Does Not Meet Entities and attributes 20 points Student identifies a large potential set of entities and their attributes for the application 0 points Major problems with identification of entities and their attributes Relationship sentence pairs 20 points Student properly formats all required relationship sentence pairs to describe one-to-many relationships 0 points Major problem with development of relationship sentences ERD 40 points ERD properly includes and depicts all entities, attributes and relationships identified 0 points ERD is missing many items and/or has major problems with relationships Metadata 20 points Spreadsheet of table specification metadata properly includes all tables, their columns, and all required details for the columns 0 points Major omissions for table specification metadataResources that you might explore: Note: If the videos are no longer available on YouTube, do a search for other relevant content. 1. Difference between conceptual logical and physical data model: 2. ER Diagramming using ERAssistant: https://www.youtube.com/watch?v=a6UCXWJZ2GE 3. ER Diagramming using Visio: https://www.youtube.com/watch?v=597BVMtMZ1w&t=568s

$25.00 View

[SOLVED] Cmis 320 project 1

In your paper, focus on how the information will be captured, manipulated, managed, and shared, and describe thevalue the relational database brings to the organization. Include brief examples of how other industries (both domestic and international) have successfully used relational databases to increase efficiency.Your paper must follow all APA Style Guide requirements. All sources must be properly cited using APA guidelines. Include an APA title page and an APA References page. The title page and References pages are in addition to the minimum of 2 pages of body text for your paper. In your paper you must include an introduction section with a heading, body text topic sections as appropriate with headings, and a conclusion section with a heading. Note that APA requires 12 point Times Roman font throughout and 1″ margins.Submission:Assignment 1 grading rubricAttribute Meets Does Not Meet Business justification 70 points Paper thoroughly provides good business, non-technical explanation of the benefits of a relational database solution 0 points Paper doesn’t provide adequate business justification Length and formatting 10 points Paper meets required length and is well formatted 0 points Paper doesn’t meet required length and is not properly formatted Grammar, typos, punctuation 10 points Paper is well-written, well- organized with minimal grammatical or spelling issues 0 points Major grammatical, typographical, and/or punctuation errors APA Requirements 10 points Paper meets APA citation, References page, and title page requirements 0 points Major problems with APA citations, Reference page, and/or title page

$25.00 View

[SOLVED] Cloud computing – 云计算lab4

1. Overview 在 Lab 2 ä¸ï¼Œæˆ‘们完æˆäº†ä¸€ä¸ªç®€åŒ–çš„ HTTP/1.1 Web æœåŠ¡å™¨ï¼› 在 Lab 3 ä¸ï¼Œæˆ‘们完æˆäº†ä¸€ä¸ªç®€åŒ–çš„ åˆ†å¸ƒå¼æ•°æ®åº“系统。 现在让我们å°è¯•将两者组åˆå¹¶å®Œå–„,构建一个高性能的分布å¼é€‰è¯¾ç³»ç»Ÿã€‚ æˆ‘ä»¬çš„ç›®æ ‡ï¼š è¿ç”¨è¯¾ç¨‹çŸ¥è¯†ä¸Žè¿‡åŽ»çš„å®žéªŒé¡¹ç›®ï¼Œæž„å»ºä¸€ä¸ªåˆ†å¸ƒå¼é€‰è¯¾ç³»ç»Ÿ å¦ä¹ 如何æé«˜ä¸€ä¸ªç³»ç»Ÿçš„å¥å£®æ€§å’Œå¯æ‰©å±•性,尽å¯èƒ½æå‡å…¶æ€§èƒ½ 注æ„ï¼šå¦‚æžœä½ é€‰æ‹©å®Œæˆ Lab 4,那么将ä¸å†éœ€è¦å®Œæˆ Lab 3ï¼Œå› ä¸º Lab 4 å·²ç»æ¶µç›–了 Lab 3 çš„è¦æ±‚ï¼Œå…¶ä¸æ•°æ®åº“æ–¹é¢çš„è¦æ±‚,请查看Lab3ï¼Œæˆ‘ä»¬ä¼šæ ¹æ®ä½ çš„ Lab 4 å®Œæˆæƒ…况对 Lab 3 进行打分。2. Background ä½ æ‰€éœ€è¦çš„æœ‰å…³ Http Server 与 Distributed Database 的基础知识都在过去的实验ä¸ï¼Œå¦‚æžœä½ å¿˜è®°äº†æˆ–è€… 想è¦å¤ä¹ ,å¯ä»¥é‡æ–°æŸ¥çœ‹Â Lab 2 和 Lab 。 Dividing databases éšç€è¿‘些年信æ¯åŒ–大å‘展,越æ¥è¶Šå¤šçš„æ•°æ®å˜å…¥äº†æ•°æ®åº“ä¸ï¼Œè€Œç‰©ç†æœåŠ¡å™¨çš„CPUã€å†…å˜ã€å˜å‚¨ã€è¿žæŽ¥æ•°ç‰èµ„æºæ˜¯æœ‰é™çš„,æŸä¸ªæ—¶æ®µå¤§é‡è¿žæŽ¥åŒæ—¶æ‰§è¡Œæ“ä½œï¼Œä¼šå¯¼è‡ ´æ•°æ®åº“在处ç†ä¸Šé‡åˆ°æ€§èƒ½ç“¶é¢ˆã€‚为了解决这个问题,行业先驱门充 åˆ†å‘æ‰¬äº†åˆ†è€Œæ²»ä¹‹çš„æ€æƒ³ï¼Œå¯¹å¤§è¡¨è¿›è¡Œåˆ†å‰²ï¼Œç„¶åŽå®žæ–½æ›´å¥½çš„æŽ§åˆ¶å’Œç®¡ç†ï¼ŒåŒæ— ¶ä½¿ç”¨å¤šå°æœºå™¨çš„CPUã€å†…å˜ã€å˜å‚¨ï¼Œæä¾›æ›´å¥½çš„æ€§èƒ½ã€‚ å…¶ä¸ä¸€ç§ç®€å•的逻辑分割是垂直分库。比如我们的数æ®åº“ä¸‐ 有商å“表Productsã€è¿˜æœ‰å¯¹è®¢å•表Orders,还有积分表Scoresã€‚æŽ¥ä¸‹æ¥æˆ‘们就å¯ä»¥åˆ›å»ºä¸‰ä¸ªæ•°æ®åº“,一个数æ®åº“å‐ ˜æ”¾å•†å“,一个数æ®åº“å˜æ”¾è®¢å•,一个数æ®åº“å˜æ”¾ç§¯åˆ†ã€‚å¦‚ä¸‹å›¾æ‰€ç¤ºï¼šè¿™æ ·åšæœ‰ä»¥ä¸‹å‡ 个优点: è·Ÿéšä¸šåŠ¡è¿›è¡Œåˆ†å‰²ï¼Œå’Œæœ€è¿‘æµè¡Œçš„å¾®æœåŠ¡æ¦‚å¿µç›¸ä¼¼ï¼Œæ–¹ä¾¿è§£è€¦ä¹‹åŽçš„管ç†åŠæ‰©å±•。 高并å‘çš„åœºæ™¯ä¸‹ï¼Œåž‚ç›´æ‹†åˆ†ä½¿ç”¨å¤šå°æœåŠ¡å™¨çš„CPUã€I/Oã€å†…å˜èƒ½æå‡æ€§èƒ½ï¼ŒåŒæ— ¶å¯¹å•机数æ®åº“连接数ã€ä¸€äº›èµ„æºé™åˆ¶ä¹Ÿå¾—到了æå‡ã€‚ èƒ½å®žçŽ°å†·çƒæ•°æ®çš„分离。 å½“ç„¶ï¼Œåˆ†åº“åˆ†è¡¨åœ¨å®žé™…åº”ç”¨ä¸æ˜¯ä¸€ä¸ªååˆ†å¤æ‚的设计,在低并å‘的应用程åºä¸‐ ï¼Œåˆ†åº“åˆ†è¡¨çš„æ•ˆæžœå¹¶ä¸æ˜Žæ˜¾ï¼Œå› æ¤éœ€è¦æ ¹æ®ä¸šåŠ¡éœ€æ±‚ï¼Œå¹¶å‘æ‰¿è½½èƒ½åŠ›ç‰ç»¼åˆè€ƒè™‘。为了简化 这一过程,在实验ä¸ï¼Œæˆ‘ä»¬ä»…è¦æ±‚对数æ®è¿›è¡Œåž‚直分库,å³å°†è¯¾ç¨‹æ•°æ®å’Œå¦ç”Ÿä¿¡æ¯åˆ†åˆ«å˜å‚¨åˆ°ä¸åŒçš„节点ä¸ï¼Œä»¥æ¤æ¥å®žçŽ°è¯¾ç¨‹æ•°æ®è®¿é—®å’Œå¦ç”Ÿä¿¡æ¯è®¿é—®äº’ä¸å½±å“的效果。 Load Balancing 负载平衡(英è¯ï¼šload balancing)是一ç§ç”µå计算机技术,用æ¥åœ¨å¤šä¸ªè®¡ç®—机(计算 机集群)ã€ç½‘络连接ã€CPUã€ç£ç›˜é©±åŠ¨å™¨æˆ–å…¶ä»–èµ„æºä¸åˆ†é…负载,以达到优化资æºä½¿ç”¨ã€æœ€å¤§åŒ– åžåçŽ‡ã€æœ€å°åŒ–å“应时间ã€åŒæ—¶é¿å…过载的目的。 使用带有负载平衡的多个æœåŠ¡å™¨ç»„ä»¶ï¼Œå– ä»£å•一的组件,å¯ä»¥é€šè¿‡å†—ä½™æé«˜å¯é 性。负载平衡æœåŠ¡é€šå¸¸æ˜¯ç”±ä¸“ç”¨è½¯ä»¶å’Œç¡¬ä»¶æ¥å®Œæˆã€‚ 主è¦ä½œç”¨æ˜¯å°†å¤§é‡ä½œä¸šåˆç†åœ°åˆ†æ‘Šåˆ°å¤šä¸ªæ“作å•元上进行执行,用于解决互è”网架构ä¸çš„高并å‘和高å¯ç”¨çš„é —®é¢˜ã€‚ è´Ÿè½½å‡è¡¡æœ€é‡è¦çš„ä¸€ä¸ªåº”ç”¨æ˜¯åˆ©ç”¨å¤šå°æœåС噍æä¾›å•一æœåŠ¡ï¼Œå¯¹äºŽäº’è”网æœåŠ¡ï¼Œè ´Ÿè½½å¹³è¡¡å™¨é€šå¸¸æ˜¯ä¸€ä¸ªè½¯ä»¶ç¨‹åºï¼Œè¿™ä¸ªç¨‹åºä¾¦å¬ä¸€ä¸ªå¤–部端å£ï¼Œäº’è”网用户å¯ä»¥é€šè¿‡è¿™ä¸ªç«¯å£æ¥è®¿é— ®æœåŠ¡ï¼Œè€Œä½œä¸ºè´Ÿè½½å¹³è¡¡å™¨çš„è½¯ä»¶ä¼šå°†ç”¨æˆ·çš„è¯·æ±‚è½¬å‘ç»™åŽå°å†…网æœåŠ¡å™¨ï¼Œå†… 网æœåŠ¡å™¨å°†è¯·æ±‚çš„å“应返回给负载平衡器,负载平衡器å†å°†å“应å‘é€åˆ°ç”¨æˆ·ï¼Œè¿™æ ·å°±å‘互è”网用户éšè—了内 网结构,阻æ¢äº†ç”¨æˆ·ç›´æŽ¥è®¿é—®åŽå°ï¼ˆå†…网)æœåŠ¡å™¨ï¼Œä½¿å¾—æœåŠ¡å™¨æ›´åŠ å®‰å…¨ï¼Œå¯ä»¥é˜»æ‐ ¢å¯¹æ ¸å¿ƒç½‘ç»œæ ˆå’Œè¿è¡Œåœ¨å…¶å®ƒç«¯å£æœåŠ¡çš„æ”»å‡»ã€‚ 当所有åŽå°æœåŠ¡å™¨å‡ºçŽ°æ•…éšœæ—¶ï¼Œæœ‰äº›è´Ÿè½½å¹³è¡¡å™¨ä¼šæä¾›ä¸€äº›ç‰¹æ®Šçš„功能æ¥å¤„ç†è¿™ç§æƒ… 况。例如转å‘è¯·æ±‚åˆ°ä¸€ä¸ªå¤‡ç”¨çš„è´Ÿè½½å¹³è¡¡å™¨ã€æ˜¾ç¤ºä¸€æ¡å…³äºŽæœåС䏿–的消æ¯ç‰ã€‚负载平衡器使得 IT团队å¯ä»¥æ˜¾è‘—æé«˜å®¹é”™èƒ½åŠ›ã€‚å®ƒå¯ä»¥è‡ªåЍæä¾›å¤§é‡çš„容é‡ä»¥å¤„ç†ä»»ä½•åº”ç”¨ç¨‹åºæµé‡çš„å¢žåŠ æˆ–å‡å°‘。 为了更好的实现负载å‡è¡¡å™¨ï¼Œä½ å¯èƒ½éœ€è¦é€‰æ‹©ä¸€ç§æˆ–å‡ ç§åˆé€‚的调度算法。 Basic Version在 basic 版本ä¸ï¼Œä½ åªéœ€è¦è¿è¡Œä¸€ä¸ª Web æœåŠ¡å™¨ï¼Œä¸Žå…¶ç›¸è¿žçš„æ˜¯å¤šä¸ªå˜å‚¨å™¨é›†ç¾¤ã€‚ 对于WebæœåŠ¡å™¨ï¼Œæˆ‘ä»¬è¦æ±‚:支æŒé«˜å¹¶å‘,å¯ä»¥åŒæ—¶å“应多个客户端å‘é€çš„请求。 对于å˜å‚¨å™¨é›†ç¾¤ï¼Œæˆ‘ä»¬è¦æ±‚:集群数é‡ä¸å°äºŽ2,å•个集群之间的通信å¯ä»¥ä½¿ç”¨ 2PC 或 RAFT å议实现。 当å˜å‚¨å™¨é›†ç¾¤æ•°é‡å¢žå¤šæ—¶ï¼Œä½ å¯ä»¥å¯¹å˜å‚¨çš„æ•°æ®è¿›è¡Œåˆ†åº“å˜å‚¨ï¼Œå¦‚课程ä¸çš„æ•°æ®å¯ä»¥å˜å‚¨åœ¨ Cluster 1 ä¸ï¼Œè€Œå¦ç”Ÿä¸ªäººä¿¡æ¯ç›¸å…³çš„æ•°æ®å¯ä»¥å˜å‚¨åœ¨ Cluster 2 ä¸ã€‚ Advanced Version在advance版本ä¸ï¼Œä½ 需è¦è¿è¡Œä¸€ä¸ªè´Ÿè½½å‡è¡¡å™¨ï¼Œå¤šä¸ªWebæœåС噍以åŠå¤šä¸ªå˜å‚¨å™¨é›†ç¾¤ã€‚ 对于负载å‡è¡¡å™¨ï¼Œæˆ‘ä»¬è¦æ±‚:支æŒé«˜å¹¶å‘,能够动æ€åœ°é€‰æ‹©æ ´»è·ƒå¹¶ä¸”å¯ç”¨çš„WebæœåŠ¡å™¨ï¼Œå°†è¯·æ±‚å‘é€è‡³ç›¸åº”节点进行处ç†ã€‚ 对于WebæœåŠ¡å™¨å’Œå˜å‚¨å™¨é›†ç¾¤ï¼Œæˆ‘ä»¬è¦æ±‚ç‰åŒäºŽBasic版本。 4. Standardized Format 为了更好的进行测试与评阅,我们将对实验过程ä¸çš„ä¸€äº›æ•°æ®æ ¼å¼è¿›è¡Œæ ‡å‡†è§„定,请确ä¿ä½ 实现的最终系统在这些对外接å£ä¸Šæ˜¯æˆ‘ä»¬çš„æ ‡å‡†ä¸€è‡´çš„ã€‚ 在请求体和å“应体ä¸ï¼Œæˆ‘们采用JSONæ ¼å¼è¿›è¡Œé€šä¿¡ã€‚è¯·æ±‚ä½“æ ¹æ®è¯·æ±‚内容决定,而å“应体包 å«äº†ç‰¹å®šçš„æ•°æ®ç»“构,分别为code,dataå’Œmsg。其ä¸code表示状æ€ç ,200为æ£å¸¸å“应,其他 为错误å“应,å¯ä»¥æ ¹æ®å®žé™…情况返回ä¸åŒçš„éžé›¶å€¼ã€‚data表示å“应对象,里é¢åŒ…å«å“应结果,错误情 况下为空。msg表示å“应消æ¯ï¼Œæ£å¸¸æƒ…况下一般为okï¼Œé”™è¯¯æƒ…å†µä¸‹æ ¹æ®å®žé™…值返回错误消æ¯ã€‚ 除了特定的 api 之外,Web æœåС噍ä»éœ€è¦æ”¯æŒé™æ€æ–‡ä»¶è®¿é—®ç‰åŸºæœ¬åŠŸèƒ½ï¼ˆå¦‚æ”¯æŒæ˜¾ç¤º html 页é¢ï¼Œéžæ³• path 返回 404 页é¢ç‰ï¼‰ï¼Œåœ¨æ¤ç•¥å޻介ç»ï¼Œå…·ä½“ä¿¡æ¯å¯å‚考 Lab 2。 我们对 api 的设计进行了éžå¸¸å¤šçš„简化,现实ä¸å°†ä¼šè¿œæ¯”å®ƒä»¬å¤æ‚ï¼Œä½ å¯ä»¥ä½¿ç”¨è¦æ±‚以外的 path æ‰©å±•ä½ çš„ç³»ç»Ÿï¼Œå¦‚ï¼šä½ å¯ä»¥è‡ªè¡Œè®¾è®¡æŠ¥é”™ä¿¡æ¯ã€‚ 4.1 Web Server 一个完整的选课系统需è¦åŒ…å«ä¼—多功能,为了é™ä½Žå¤æ‚性,我们将其抽象为查询课程,选ä¸è¯¾ç¨‹å’Œé€€é€‰è¯¾ç¨‹è¿™å‡ 个模å—。 1. /api/search/course 介ç»ï¼šä¸»è¦ç”¨äºŽæŸ¥è¯¢è¯¾ç¨‹ä¿¡æ¯ï¼Œç›¸å…³çš„傿•°ä½¿ç”¨Â query æºå¸¦ï¼ŒæŸ¥è¯¢åŽç»™å‡ºçš„æ•°æ®è‡³å°‘需è¦åŒ… å«è¯¾ç¨‹çš„ ç¼–å·ï¼Œå称,容é‡å’Œå·²é€‰äººæ•°ã€‚ 方法:GET 傿•°ï¼šid=[course_id] 课程编å·ä»…由 [a-zA-Z0-9]组æˆï¼Œä¸å«æœ‰ç‰¹æ®Šå—符。 å“应体: json { “code”: 200, “data”: { “id”: course_id, // 课程id “name”: course_name , // 课程 “capacity”: capacity , // è¯¾ç¨‹å®¹é‡ “selected”: selected // 已选人数 }, “msg”: “ok” } 1. /api/search/all 介ç»ï¼šä¸ŽæŸ¥è¯¢å•个课程类似,但其 dataå—æ®µçš„值从å•个课程信æ¯å˜ä¸ºäº†åŒ… 嫿‰€æœ‰è¯¾ç¨‹ä¿¡æ¯çš„æ•°ç»„。 方法:GET å“应体: json { “code”: 200, “data”: [{ “id”: course_id, // 课程id “name”: course_name , // 课程 “capacity”: capacity , // è¯¾ç¨‹å®¹é‡ “selected”: selected // 已选人数 },{ “id”: course_id, “name”: course_name , // 课程 “capacity”: capacity , // è¯¾ç¨‹å®¹é‡ “selected”: selected // 已选人数 }, … ], “msg”: “ok” } 1. /api/search/student 介ç»ï¼šä¸»è¦ç”¨äºŽæŸ¥è¯¢å¦ç”Ÿæ‰€é€‰è¯¾ç¨‹ä¿¡æ¯ï¼Œç›¸å…³çš„傿•°ä½¿ç”¨Â query æºå¸¦ 方法:GET 傿•°ï¼šstuid=[student_id] å¦ç”Ÿå¦å·ä»…由 [a-zA-Z0-9]组æˆï¼Œä¸å«æœ‰ç‰¹æ®Šå—符。 å“应体: json { “code”: 200, “data”: { “stuid”: student_id, // å¦å· “name”: student_name , // å¦ç”Ÿå§“å “course”: [{ // å‐ ¦ç”Ÿé€‰çš„课程数组 “id”: course_id, “name”: course_name , // 课程 },{ “id”: course_id, “name”: course_name , // 课程 }, … ] }, “msg”: “ok” } 如果å¦ç”Ÿæœªé€‰è¯¾ç¨‹ï¼ŒÂ data.course = []å³å¯ã€‚ 1. /api/choose 介ç»ï¼šä¸»è¦ç”¨äºŽè¿›è¡Œé€‰è¯¾æ“ä½œï¼Œç›¸å…³çš„å‚æ•°ä½¿ç”¨Â http request bodyæºå¸¦ 方法:POST 请求体: json { “stuid”: student_id, // å¦ç”Ÿå¦å· “course_id”: course_id // è¯¾ç¨‹ç¼–å· } 当需è¦è¿›è¡Œé€‰è¯¾æ“作时,payloadÂ åº”è‡³å°‘åŒ…å« å¦ç”Ÿå¦å·ï¼Œè¯¾ç¨‹ç¼–å·ã€‚ å“应体: json { “code”: 200, “data”: [], “msg”: “ok” } 对于 payload æ ¼å¼æˆ–æ•°æ®éžæ³•ï¼Œæ— æ³•æŸ¥è¯¢åˆ°ç›¸å…³ä¿¡æ¯ï¼Œè¯¾ç¨‹å·²æ»¡ ç‰é”™è¯¯æƒ… 况,返回包å«é”™è¯¯ä¿¡æ¯çš„ JSON 对象å³å¯ã€‚ 1. /api/drop 介ç»ï¼šä¸»è¦ç”¨äºŽè¿›è¡Œé€€é€‰æ“ä½œï¼Œç›¸å…³çš„å‚æ•°ä½¿ç”¨Â http request bodyæºå¸¦ 方法:POST 请求体: json { “stuid”: student_id, // å¦ç”Ÿå¦å· “course_id”: course_id // è¯¾ç¨‹ç¼–å· } 当需è¦è¿›è¡Œé€‰è¯¾æ“作时,payloadÂ åº”è‡³å°‘åŒ…å« å¦ç”Ÿå¦å·ï¼Œè¯¾ç¨‹ç¼–å·ã€‚ å“应体: json { “code”: 200, “data”: [], “msg”: “ok” } 对于 payload æ ¼å¼æˆ–æ•°æ®éžæ³•ï¼Œæ— æ³•æŸ¥è¯¢åˆ°ç›¸å…³ä¿¡æ¯ï¼Œè¯¥å¦ç”Ÿæ²¡æœ‰é€‰æ‹©è¿™é—¨è¯¾ç‰é”™è¯¯æƒ…况,返回包å«é”™è¯¯ä¿¡æ¯çš„ JSON 对象å³å¯ã€‚ 4.2 Store Server Command Lines Arguments 由于我们系统使用了默认数æ®ï¼Œæ‰€ä»¥ä½ çš„å˜å‚¨å™¨åº”该在å¯åŠ¨æ—¶ï¼Œå¯¹è¿™äº›æ•°æ®è¿›è¡Œè¯»å–。 默认数æ®å¯ä»¥åœ¨Â data/Â æ–‡ä»¶å¤¹ä¸æ‰¾åˆ°ã€‚ 其余说明请å‚考 Lab 3。 Database Tables æ•°æ®åº“çš„åŸºç¡€æ ¼å¼æ˜¯å…³ç³»åž‹æ•°æ®åº“ï¼Œä½ ä¹Ÿå¯ä»¥æ ¹æ®éœ€è¦å¢žæ·»ä¿®æ”¹æ•°æ®çš„类型,也å¯ä»¥é€‰æ‹©è®¾è®¡æ– °ç±»åž‹çš„æ•°æ®åº“,但必须ä¿è¯é€šè¿‡æ•°æ®åº“å¯ä»¥æ£å¸¸å®Œæˆéœ€è¦çš„功能。 默认数æ®å¯ä»¥åœ¨Â data/Â æ–‡ä»¶å¤¹ä¸æ‰¾åˆ°ã€‚ Course | id(key) – string | name – string | capacity – int | selected – int | | — | — | — | — | | “CS06142” | “云计算技术” | 120 | 120 | Student | id(key) – string | name – string | | — | — | | “211926010111” | “å¼ ä¸‰” | Course Selection | Course id – string | Student id – string | | — | — | | “CS06142” | “211926010111” | Commands æ£å¸¸æƒ…况下,用户访问数æ®ä»…通过å‰ç«¯çš„ HTTP Web æœåŠ¡å™¨ï¼Œè€Œæ•°æ®æŸ¥è¯¢ç”± Web æœåŠ¡å™¨ä¸Žæ•°æ®åº“集群进行交互。 以下给出的数æ®åº“命令仅供å‚è€ƒï¼Œä½ å¯ä»¥é€‰æ‹©è‡ªå·±å®žçŽ°ä¸€ä¸ªæ»¡è¶³ç›¸åŒåŸºæœ¬åŠŸèƒ½çš„å‘½ä»¤é›†ã€‚ Check Courses Capacity å‘é€Â GET Course [course id], e.g., GET Course CS06142ï¼› 返回 [course id] [course name] [course capacity] [selected number], e.g., CS06142 云计算技术 120 120 特别的,å¯ä»¥ä¸€æ¬¡æŸ¥è¯¢æ‰€æœ‰çš„课程最大容é‡ä¿¡æ¯: å‘é€Â GET Course all, e.g., GET Course allï¼› 返回 多行 [course id] [course name] [course capacity] [selected number], e.g., CS04008 计算机网络 90 80 CS06142 云计算技术 120 120。 Check Student Selected Courses å‘é€Â GET Student Courses [student id], e.g., GET Student Courses 211926010111ï¼› 返回 多行 [course id] [course name], e.g., CS04008 计算机网络 CS06142 云计算技术。 Choose a Course å‘é€Â ADD Student Course [student id] [course id], e.g., ADD Student Course 211926010111 CS06142ï¼› 如果æˆåŠŸï¼Œè¿”å›žÂ +OK; 如果失败,返回 -ERROR。 Drop a Course å‘é€Â DEL Student Course [student id] [course id], e.g., DEL Student Course 211926010111 CS06142ï¼› 如果æˆåŠŸï¼Œè¿”å›žÂ +OK; 如果失败,返回 -ERROR。 4.3 Load Balancer 为了更好地统一测试,我们需è¦ä½ 的负载å‡è¡¡å™¨é‡‡ç”¨æ ‡å‡†çš„é…ç½®æ– ‡ä»¶å¯åŠ¨ï¼Œä¾‹å¦‚ï¼Œä½ å¯ä»¥è¿™æ ·å°†æ‰€æœ‰çš„WebæœåŠ¡çš„åœ°å€å’Œç«¯å£ä¼ 给负载å‡è¡¡å™¨ï¼Œç”±è ´Ÿè½½å‡è¡¡å™¨åЍæ€çš„转å‘请求到这些WebæœåŠ¡ä¸Šï¼š “` web_servers.conf æ¯ä¸€è¡Œéƒ½æ˜¯ä¸€ä¸ªå†… 部webæœåŠ¡è¿›ç¨‹çš„ç›‘å¬åœ°å€å’Œç«¯å£ 127.0.0.1 8081 127.0.0.1 8082 127.0.0.1 8083 127.0.0.1 8084 “` 5. Test 默认情况下,我们将在 Linux Ubuntu 20.04 x64 æœåŠ¡å™¨è¿›è¡Œæµ‹è¯•ã€‚ 我们预期的测试和评分项目有: API功能实现:上述æ¯ä¸ªAPIå‡ä¸º1分(5分) å˜å‚¨èŠ‚ç‚¹å®¹ç¾æµ‹è¯•ï¼šéšæœºç»ˆæ¢å˜å‚¨èŠ‚ç‚¹æœåŠ¡ï¼ŒæŽ¥å£è¿è¡Œæƒ…况(3分) è´Ÿè½½å‡è¡¡å®žçŽ°ï¼šé€šè¿‡è´Ÿè½½å‡è¡¡å™¨å¯¹å¤–æä¾›æŽ¥å£æœåŠ¡ï¼Œå¹¶ä¸”WebæœåŠ¡èƒ½å¤Ÿå®¹ç¾ï¼ˆ1分) 性能测试:在高并å‘下ã€åЍæ€åˆ‡æ¢çš„æƒ…å†µä¸‹ï¼Œç³»ç»Ÿçš„æ‰¿è½½èƒ½åŠ›ï¼Œæ ¹æ®æ‰€æœ‰å°ç»„的测试情 况进行内部评比得分(1分) ä¸ºäº†æ ‡å‡†åŒ–æµ‹è¯•ï¼Œä½ çš„ç³»ç»Ÿåœ¨è¿è¡Œä¸Šï¼Œéœ€è¦æ»¡è¶³ä¸€ä¸‹æ¡ä»¶ï¼š 1. æ³¨æ„æ–‡ä»¶ç»“构,ä¸åŒæ¨¡å—æºä»£ç 处于ä¸åŒæ–‡ä»¶å¤¹ä¸ï¼ˆæˆ‘ä»¬ä¼šæ£€æŸ¥ä½ çš„æºä»£ç ) 2. é¡¹ç›®çš„æ ¹ç›®å½•ä¸‹å¯ä»¥ä½¿ç”¨Â makeÂ å‘½ä»¤ç›´æŽ¥ç¼–è¯‘æ‰€æœ‰æ¨¡å— 3. 坿‰§è¡Œæ–‡ä»¶åˆ†ä¸º Web æœåС噍 å’Œ å˜å‚¨å™¨é›†ç¾¤ä¸¤ä¸ªéƒ¨åˆ†ï¼Œå…¶ä¸ Web æœåС噍坿‰§è¡Œæ–‡ä»¶ä¸ºÂ web-server,支æŒÂ -ip, -port, -config_path ç‰å‘½ä»¤è¡Œå‚数,例如./web- server –ip 127.0.0.1 –port 8080 –config_path ./conf/store_servers.conf å˜å‚¨å™¨ 坿‰§è¡Œæ–‡ä»¶ä¸ºÂ store-server,支æŒÂ -config_path ç‰å‘½ä»¤è¡Œå‚数,并使用é…ç½®æ– ‡ä»¶Â coordinator.conf 或 participant.conf 进行é…置,具体细节请查看Lab3。测试ä¸ï¼Œæ¯ä¸ªé›†ç¾¤çš„å˜å‚¨æœåŠ¡å™¨æ•°é‡ä¸º 4,2pcå’Œraft任选一ç§å®žçŽ°ï¼Œä¾‹å¦‚ï¼š “` å¯åЍå˜å‚¨æœåŠ¡å™¨é›†ç¾¤1(该集群主è¦å˜å‚¨ å¦ç”Ÿ-选课 æ•°æ®ï¼‰ – 2pc $ ./store-server –config_path ./conf/coordinator1.conf $ ./store-server –config_path ./conf/participant101.conf $ ./store-server –config_path ./conf/participant102.conf $ ./store-server –config_path ./conf/participant103.conf å¯åЍå˜å‚¨æœåŠ¡å™¨é›†ç¾¤2(该集群主è¦å˜å‚¨ 课程选课人数 æ•°æ®ï¼‰ – raft $ ./store-server –config_path ./conf/store201.conf $ ./store-server –config_path ./conf/store202.conf $ ./store-server –config_path ./conf/store203.conf $ ./store-server –config_path ./conf/store204.conf “` å¦‚æžœä½ å®žçŽ°äº†Â Load Balancerï¼Œå…¶å¯æ‰§è¡Œæ–‡ä»¶è¯·å‘½å为 load-balancer,支æŒÂ -ip –port -web_config_path -store_config_path  ç‰å‘½ä»¤è¡Œå‚数。例如 “` å¯åŠ¨è´Ÿè½½å‡è¡¡å™¨ $ ./load-balancer –ip 127.0.0.1 –port 8080 –store_config_path ./conf/store_servers.conf –web_config_path ./conf/web_servers.conf å¯åЍwebæœåŠ¡å™¨é›†ç¾¤ $ ./web-server01 –ip 127.0.0.1 –port 8081 –config_path ./conf/store_servers.conf $ ./web-server02 –ip 127.0.0.1 –port 8082 –config_path ./conf/store_servers.conf $ ./web-server02 –ip 127.0.0.1 –port 8083 –config_path ./conf/store_servers.conf $ ./web-server02 –ip 127.0.0.1 –port 8084 –config_path ./conf/store_servers.conf “` 坿‰§è¡Œæ–‡ä»¶ä¸Žé…ç½®æ–‡ä»¶çš„è¦æ±‚å¯ä»¥å‚考 Lab2, Lab 3。 4.æ¯æ¬¡è¿è¡Œç³»ç»Ÿï¼Œéƒ½å°†å…ˆå¯åŠ¨å¤šä¸ªå˜å‚¨å™¨é›†ç¾¤ä¸çš„æ¯ä¸ªå˜å‚¨æœåŠ¡å™¨ï¼ŒéšåŽå¯åŠ¨å¤šä¸ª Web æœåŠ¡å™¨ï¼Œæœ€åŽå†å¯åЍ Load Balancer(如果需è¦ï¼‰ï¼Œè¯·ä¿è¯æ¯ä¸ªå¯æ‰§è¡Œæ–‡ä»¶éƒ½èƒ½æ£å¸¸è¿è¡Œã€‚ 类似之å‰çš„实验,我们æä¾›äº†æµ‹è¯•程åºï¼Œè¯·ä»”细阅读 Lab 4 å®žéªŒæ–‡æ¡£å’Œæµ‹è¯•ç¨‹åºæ–‡æ¡£åŽä½¿ç”¨ã€‚6. Lab submission å°†ä½ çš„ä»£ç æäº¤åˆ°Â /Lab4/ 文件夹,并编写 Makefile 确ä¿å¯ä»¥ç›´æŽ¥ä½¿ç”¨Â make 命令编 译所有需è¦çš„坿‰§è¡Œæ–‡ä»¶ã€‚ 考虑到 Lab 4Â å®žçŽ°å®Œæ•´ç³»ç»Ÿè¾ƒä¸ºå¤æ‚,验收å¯èƒ½ä¼šå˜åœ¨é¢å¤–问题,请在æäº¤ä»£ç çš„åŒæ—¶ï¼Œç¼– 写一份 intro.mdÂ ï¼Œå¹¶æ·»åŠ ä¸€äº›è¯´æ˜Žï¼Œå¦‚ï¼šå¦‚ä½•ç¼–è¯‘ï¼Œå¦‚ä½•è¿è¡Œä½ 的程åºï¼›æ˜¯å¦è¿ç”¨äº†å…¶ä»–ä¾èµ– 库,如何安装ä¾èµ–ï¼›å¦‚ä½•ç®¡ç†æ•°æ®åº“,实现数æ®åˆ†å—ç‰ã€‚7. Grading standards å®Œæˆæ‰€æœ‰ Basic ç‰ˆæœ¬çš„è¦æ±‚ï¼Œä½ å°†èŽ·å¾— 8 分; å®Œæˆæ‰€æœ‰ Advanced ç‰ˆæœ¬çš„è¦æ±‚ï¼Œä½ å°†èŽ·å¾— 10 分。 å¦‚æžœä½ æœ‰éƒ¨åˆ†åŠŸèƒ½æ²¡æœ‰å®žçŽ°ï¼Œå°†æ ¹æ®ä½ çš„å®Œæˆæƒ…况进行细化打分。 æ¤åˆ†æ•°ä¸åŒ…å« Lab 3,Lab 3 çš„åˆ†æ•°ä¼šæ ¹æ® Lab 4 å®Œæˆæƒ…况å¦å¤–获得。

$25.00 View

[SOLVED] Cloud computing – lab2: your own http server

You can find this lab2’s instruction in Lab2/README.md All materials of lab2 are in folder Lab2/. 1. Overview Implement an HTTP server based on HTTP/1.1 from scratch by your own, using network programming knowledges learned from our class. Also, try to use high concurrency programming skills learned from the class to guarantee the web server’s performance. Our Goals: Practice basic network programming skills, such as using socket API, parsing packets; Get familiar with robust and high-performance concurrent programming. 2. Backround Please check background.md first to learn some basics about HTTP, HTTP messages , HTTP proxy, JSON & curl. 3. Your Lab Task Implement your own HTTP Server In this Lab, we won’t provide any basic code. You should implement an HTTP server based on HTTP/1.1, from scratch which satisfies the following requirements: HTTP Server Outline From a network standpoint, your HTTP server should implement the following: 1. Create a listening socket and bind it to a port; 2. Wait a client to connect to the port; 3. Accept the client and obtain a new connection socket; 4. Read in and parse the HTTP request; 5. Start delivering services (some are optional): 6. Handle HTTP GET/POST requests and return responses. 7. Proxy the request to another HTTP server. The server will be in either non-proxy mode or proxy mode (we have introduced the proxy in background section 2.3). It does not do both things at the same time. For better testing and scoring, we have made some functional requirements for your submitted works. ATTENTION: Lab 2 is a pre-lab of Lab 4. If you plan to complete Lab 4, please complete the advanced version of Lab 2. 3.1 Handle HTTP request & send HTTP response In this Lab, you just need to implement the GET method and the POST method in your HTTP server. For any other methods, your server should send a response with 501 status code (see 2.2). That is to say, if your HTTP server receive an HTTP request but the request method is neither GET nor POST, the HTTP server just need to return a 501 Not Implemented error message (a response message with Response line having status code to be 501, see 2.2). See examples in section 3.7. 3.1.1 Handle HTTP GET request The HTTP server should be able to handle HTTP GET requests for specific resources, e.g., web service data & static files. For a GET request, the server needs to check whether the path of request corresponds to a web service or an existed static file. What you need to do: basic version: A search service: use a specific url to get some data from the server that does not come from a file stored on the file system. The url don’t have query string, e.g. http://localhost:8080/api/check; Send response with plain text content. Static files access: use a specific url to access a text file stored on the file system. Clients only request *.html; Send response with the full content of html file. If the path is invalid or the static file does not exist Send response with the full content of 404 Not Found page. advanced version: A search service: use a specific url to get some data from the server that does not come from a file stored on the file system. Or if invalid, send response with json type content, including error messages; Static files access: use a specific url to access a text file stored on the file system. Send Response with the correct Content-Type & the full content of the file. If the path is invalid or the static file does not exist Send response with the full content of 404 Not Found page. You don’t need to implement to transmit base64 encoded binary files, such as image files like *.png. 3.1.2 Handle HTTP POST request The HTTP server should be able to handle HTTP POST requests. For a POST request, the server needs to check whether the path of request corresponds to a web service. What you need to do: basic version: A upload service: use a specific url to upload some data to the server The content type is application/x-www-form-urlencoded; The payload contains key-value pairs, keys are id & name; If the payload is valid, send response with 200 OK, Content-Type: text/plain & data; Or if the payload invalid, send response with send response with 404 Not Found, Content-Type: text/plain & error messages; If the path is invalid Send response with the full content of 404 Not Found page. advanced version: A upload service: use a specific url to upload some data from the server that does not come from a file stored on the file system. The content type is application/x-www-form-urlencoded, application/json; The payload contains key-value pairs, keys are id & name; If the payload is valid, send response with 200 OK, Content-Type: application/json & data; Or if the payload invalid, send response with send response with 404 Not Found, Content-Type: application/json & error messages; If the path is invalid Send response with the full content of 404 Not Found page. If you are not familiered with application/x-www-form-urlencoded, check MDN docs. 3.1.3 Other request Just return 501 Not Implemented page for other request method (e.g. DELETE, PUT, etc.). 3.2 Implement a proxy server (optional for advanced version) Enable your server to proxy HTTP requests to another HTTP server and forward the responses to the clients. 1. You should use the value of the –proxy command line argument, which contains the address and port number of the upstream HTTP server. 2. Your proxy server should wait for new data on both sockets (the HTTP client file descriptor, and the upstream HTTP server file descriptor). When data arrives, you should immediately read it to a buffer and then write it to the other socket. You are essentially maintaining 2-way communication between the HTTP client and the upstream HTTP server. Note that your proxy must support multiple requests/responses. 3. If either of the sockets closes, communication cannot continue, so you should close the other socket and exit the child process. Hints: 1) This is more tricky than writing to a file or reading from stdin, since you do not know which side of the 2-way stream will write data first, or whether they will write more data after receiving a response. 2) You should again use threads for this task. For example, consider using two threads to facilitate the two-way communication, one from A to B and the other from B to A. It is not our task to implement protocols other than HTTP. They often involve encryption algorithms and are difficult to implement directly using socket api. However, if you are interested in protocols such as HTTPS, you can try to use other libraries, e.g. openssl. 3.3 Use multi-thread to increase concurrency Your HTTP server should use multiple threads to handle as many concurrent clients’ requests as possible. You have at least the following three options to architect your multi-thread server: Combined. Combine above two styles together. For example, you can use thread pool to receive request and send response, and use ondemand threads to fetch large page files. Feel free to choose any one from the above three, or use other multi-thread architecture that you think is cool. 3.4 Support HTTP pipelining In the basic version, you have only one request per TCP connection going on at the same time. The client waits for response, and when it gets response, perhaps reuses the TCP connection for a new request (or use a new TCP connection). This is also what normal HTTP server supports. In the advanced version, multiple http requests can be fired concurrently on one TCP connection. This is also called HTTP pipelining which is supported by many real browsers and servers (such as Chrome). Note that HTTP requests that come from the same TCP connection should be responded in the same order. So take care the order problem when using complex multi-thread styles. 3.5 Specify arguments Your program should enable long options to accept arguments and specify those arguments during start. They are: | arguments | descriptions | | — | — | | -i, –ip | Specify the server IP address. | | -p, –port | Selects which port the HTTP server listens on for incoming connections. | | –proxy | Selects an “upstream” HTTP server to proxy. | | -t, –threads | Number of threads if you use multi-thread. | The –proxy can have a schema before :// and a port number after a colon (e.g. http://www.example.com:80). If a port number is not specified, port 80 is the default for HTTP. 3.6 Run your HTTP Server For advanced version: Your program should be able to start at terminal. If your program is called http-server, just typing: in the non-proxy mode: ./http-server –ip 127.0.0.1 –port 8888 –threads 8 It means that your HTTP server’s IP address is 127.0.0.1 and service port is 8888. The –number-thread indicates that there are 8 threads in the thread pool for handling multiple client request concurrently. in the proxy mode: ./http-server –ip 127.0.0.1 –port 8888 –threads 8 –proxy http://www.example.com:80 It means that this is an HTTP proxy server. This proxy’s IP address is 127.0.0.1 and service port is 8888. And the proxy has a thread pool with 8 threads. The –proxy indicates that the “upstream” HTTP server is http://www.example.com:80. So, if you send a request message to this proxy (i.e. 127.0.0.1:8888), it will forward this request message to the “upstream” HTTP server (i.e. http://www.example.com:80) and forward the response message to the client. If you want to access this server from other host, maybe you should open the firewall corresponding to the port and bind the ip to 0.0.0.0. When you run the command above, your HTTP server should run correctly. 3.7 Access Your HTTP Server We assume that the ip the server bound is 127.0.0.1 and the port is 8080. If the proxy feature is used, the remote server is www.example.com. For more efficient testing and scoring, we need you to implement some of the interfaces described below, and make sure that the content of the response is consistent with our expectations. That’s why we provide some standard static files. You can check those files in ./static/ & ./data/. Please make sure your server supports accessing them, and do not modify their content or relative paths. 3.7.1 Using GET method 1) access static files For basic version: | path | files in local fs | status code | content type | | — | — | — | — | | /, /index.html | /{static dir}/index.html | 200 | text/html | | /404.html | /{static dir}/404.html | 404 | text/html | | /501.html | /{static dir}/501.html | 501 | text/html | | any other error paths | /{static dir}/404.html | 404 |text/html | E.g.: “`shell user@linux:~/http-server$ curl -i -X GET http://localhost:8080/index.html HTTP/1.1 200 OK Content-Type: text/html Content-Length: 210 index.html “` For advanced version: | path | files in local fs | status code | content type | | — | — | — | — | | /, /index.html | /{static dir}/index.html | 200 | text/html | | /404.html | /{static dir}/404.html | 404 | text/html | | /501.html | /{static dir}/501.html | 501 | text/html | | [/*]/*.html | /{static dir}[/*]/*.html | 200 | text/html | | [/*]/*.js | /{static dir}[/*]/*.js | 200 | text/javascript | | [/*]/*.css | /{static dir}[/*]/*.css | 200 | text/css | | [/*]/*.json | /{static dir}[/*]/*.json | 200 | application/json | | any other error paths | /{static dir}/404.html | 404 | text/html | “` user@linux:~/http-server$ curl -i -X GET http://localhost:8080/data.json HTTP/1.1 200 OK Content-Type: application/json Content-Length: 93 [{“id”:1,”name”:”Foo”},{“id”:2,”name”:”Bar”},{“id”:3,”name”:”Foo Bar”},{“id”:4,”name”:”Foo”}] “` For standardized testing, output JSON data in one line without unnecessary spaces. 2) access web services for getting data For basic version: | path | get data | status code | content type | | — | — | — | — | | /api/check | strings in data.txt | 200 | text/plain | | any other error paths | /{static files}/404.html | 404 | text/html | E.g.: “`shell user@linux:~/http-server$ curl -i -X GET http://localhost:8080/api/check HTTP/1.1 200 OK Content-Type: text/plain Content-Length: 13 id=1&name=Foo “` For advanced version: | path | get data | status code | content type | | — | — | — | — | | /api/list | all objects in data.json | 200 | application/json | | /api/search? [id=value1&name=value2] | all objects that match *.id == value1 && *.name == value2 in /data/data.json | 200 | application/json | | /api/search?[id=value1&name=value2] | if no object matches, return all objects in /data/not_found.json | 404 |application/json | | any other error paths | /{static files}/404.html | 404 | text/html | The query string format is a regular expression: id=[0-9]+&name=[a-zA-Z0-9]+. If you do not want to parse json file, you could store the data in memory instead of reading file every time. E.g.: “`shell user@linux:~/http-server$ curl -i -G -d ‘id=1&name=Foo’ -X GET http://localhost:8080/api/search HTTP/1.1 200 OK Content-Type: application/json Content-Length: 23 [{“id”:1,”name”:”Foo”}] “` For standardized testing, output JSON data in one line without unnecessary spaces. 3.7.2 Using POST method access web services for uploading data All data you need to upload are two key/value pairs: id: {value1} & name: {value2}. For standardized testing, output in the order of id, name. Your server should check the data. In default case, the server should echo the data from the client. If the data format is error, e.g., id=1&name, id=1 or id=1&foo=a, send content error message. For basic version: The client should send requests with Content-Type: application/x-www-form-urlencoded. The echo data format is a regular expression: id=[0-9]+&name=[a-zA-Z0-9]+. After handling, send response: | path | content | status code | content type | | — | — | — | — | | /api/echo | echo the data received | 200 | application/x-www-form-urlencoded | | /api/echo | if the data format is error, send strings in /data/error.txt | 404 | text/plain | | any other error paths | /{static files}/404.html | 404 | text/html | E.g.: “`shell user@linux:~/http-server$ curl -i -d ‘id=1&name=Foo’ -H ‘Content-Type: application/x-www-form-urlencoded’ -X POST http://localhost:8080/api/echo HTTP/1.1 200 OK ContentType: application/x-www-form-urlencoded Content-Length: 13 id=1&name=Foo “` For advanced version: The client should send requests with Content-Type: * application/x-www-form-urlencoded, * application/json. After handling, send response: | path | content | status code | content type | | — | — | — | — | | /api/upload | echo the data received | 200 | application/json | | /api/upload | if the data format is error, send strings in /data/error.json | 404 | application/json | | any other error paths | /{static files}/404.html | 404 | text/html | E.g.: “`shell user@linux:~/http-server$ curl -i -d ‘{“id”:1,”name”:”Foo”}’ -H ‘Content-Type: application/json’ -X POST http://localhost:8080/api/upload HTTP/1.1 200 OK Content-Type: application/json Content-Length: 21 {“id”:1,”name”:”Foo”} “` For standardized testing, output JSON data in one line without unnecessary spaces. 3.7.3 Other method The HTTP server will not handle HTTP requests except GET requests and POST requests. If you send an HTTP request with DELETE (or PUT, HEAD, etc.) to delete the specified resource, your server should send /{static dir}/501.html: 3.8 Implementation requirements Version Basic version Complete all the tasks of the basic version described in section 3.1.1~3.1.7 except 3.1.3 & 3.1.4. Advanced version Complete all the tasks of the advanced version described in section 3.1.1~3.1.7 including 3.1.3 & 3.1.4. 4. Tester We provide some tools for testing. You can check the repos of the tester. Of course you can also use your own browser and other web tools like curl. 5. Lab submission Please submit your lab program following the guidance in the Overall Lab Instructions (../README.md) 6. Grading standards You can get 28 points if you can: finish all the requirements of the basic version You can get 30 points (full score) if you can: finish all the requirements of the advanced version If you missed some parts, you will get part of the points depending how much you finished.

$25.00 View

[SOLVED] Cloud computing – lab 1: “super-fast†sudoku solving

Enter in the folder you have cloned from our lab git repo, and pull the latest commit. You can find this lab1’s instruction in Lab1/README.md All materials of lab1 are in folder Lab1/ 1. Overview Implement a Sudoku solving program, using multiple threads or multiple processes, running on a single machine. Try to utilize all your CPU cores and make your program run as fast as possible! Goals Practice basic parallel programming skills, such as using multiple threads/processes; Get familiar with Unix OS environment development (eg., file I/O, get timestamp); Get familiar with source code version control tools (git), and learn to collaborate with others using github; 2. Background 2.1 Introduction to Sudoku Sudoku (originally called Number Place) is a logic-based combinatorial number-placement puzzle. You are given a 9×9 board of 81 squares logically separated into 9 columsn, 9 rows, and 9 3×3 subsquares. The goal is, given a board with some initial numbers filled in (we call it a Sudoku puzzle), fill in the rest of the board so that every column, row, and subsquare have all the digits from 1 to 9 and each digit appears only once (we call it a Sudoku solution). An example Sudoku puzzle:An example Sudoku solution to above puzzle:2.2 Some useful resources If you have no idea about what algorithms can be used to solve Sudoku puzzles, we suggest you read this. To simplify your work, we have provided a simple implementation (Lab1/src/Sudoku) of 4 Sudoku solving algorithms (some are slow, some are fast), but without using multiple threads/processes. The two files test1 and test1000 contain many puzzles for you to test. Of course, you are always encouraged (not mandatory) to implement those algorithms by yourselves and even your own algorithms (if you have time). 3. Your Lab Task 3.1 Write a program Implement a program which satisfies the following requirements: 3.1.1 Program input and output Input 1. When executing the compiled program from the code you submit, it must not take any parameters and the program must be named sudoku_solve. In other words, your program can be run normally by typing ./sudoku_solve in the terminal. 2. But after start, your program needs to be able to read multiple strings from stdin, which are separated by line breaks. The content of these strings are the paths of the Sudoku puzzles files. 3. In each input file, each line of the file represents a Sudoku puzzle that needs to be solved. Each line contains 81 digits, where the first 9 digits represent the first row of the Sudoku puzzle, the 10th to the 18th digits represent the second row of the puzzle, and so on. The digit 0 represents a blank that needs to be filled in when solving the puzzle. 3.1.1.1 Puzzle file example In the following image, we have printed three Sudoku puzzle files in the terminal. They contain one, two, and three puzzles, and their names are test1, test2, and test3.3.1.1.2 Example input from terminal In the following code snippet, we showed how to input Sudoku puzzle files that need to be solved from the terminal after your program starts running: ./test1 ./test2 ./test3 Output For each Sudoku puzzle in file, your program should only output the solution to the puzzle to stdout. The format of the solution should be the same as the puzzle, except that all 0s in the puzzle should be replaced with the correct numbers. Also, remember that the order of the answers should be consistent with the order of the input Sudoku puzzles. 3.1.1.3 Example output 312647985786953241945128367854379126273461859691285473437592618569814732128736594 693784512487512936125963874932651487568247391741398625319475268856129743274836159 869725413512934687374168529798246135231857946456319872683571294925483761147692358 693784512487512936125963874932651487568247391741398625319475268856129743274836159 364978512152436978879125634738651429691247385245389167923764851486512793517893246 378694512564218397291753684643125978712869453859437261435971826186542739927386145 3.1.1.4 Output order requirement Taking the three test files above as an example, your program needs to output the result of ./test1 first, then ./test2, and finally ./test3. Additionally, the order of answers corresponding to each file should be consistent with the order of puzzles in the file. In the example output, the 1st line corresponds to the solution of the Sudoku puzzle in ./test1. The 2nd and 3rd lines correspond to the 1st and 2nd puzzles in ./test2. The 4th, 5th, and 6th lines correspond to the 1st, 2nd, and 3rd puzzles in test3. 3.1.2 Implementation requirements 3.1.2.1 Basic version Your program should be able to: 1. Accept one input file name, and the size of the input file is smaller than 100MB. 2. Successfully solve the puzzles in the input file, and output the results in the format described before. 3. Use multiple threads/processes to make use of most of your machine’s CPU cores. [Tips]: 1. Use an event queue to dispatch tasks and merge results to/from worker threads. 2. Dynamically detect how many CPU cores your machine has to determine how many threads/processes your program should use. 3. Be careful about contention between multiple threads/processes. 3.1.2.2 Advanced version Your program should be able to: 1. Complete all the requirements in the basic version. 2. Accept any number of input file names, and the size of input file can be any large (as long as it can be stored on your disk) 3. When the program is solving puzzles in the previously input file(s), the program can meanwhile accept more input file names from stdin. [Tips]: 1. Use a dedicated thread to accept input. 2. To avoid exhausting all memory, read different parts of the file into memory and solve them one by one. 3. You are encouraged to try more optimizations, such as cache coherency processing. 3.2. Test script We have provided a script for you to use so that you can test your program before submitting, you can use this shell script on most Linux systems. It will verify the correctness of the program based on the output, and show you the time your program takes. 3.2.1 Get prepared 1. This script requires you to provide two input files. These two files need to be placed in the same directory as the script. The following describes how to prepare these two input files: a. The content of the first file is a list of Sudoku puzzle files which will be input to your program. For example, we name the first file as test_group, and we prepared 2 puzzle files(see in 3.1.1.1) to test our program, the first file is named as “test1” and it has 1 puzzle to be solved, and the other file is named “test1000” and it has 1000 puzzles to be solved. Then the content format of test_group is as follows:b. The content of the second file is a list of Sudoku solution files to the puzzles you prepared. Take the example of the first file above, we name the second file as answer_group. Same to the test_group above, answer_group should also contain 2 answer files, the first answer file corresponds to “”test1″” in test_group, it’s named “answer1” and it has 1 solution, the second answer file corresponds to “test1000” in test_group, it’s name is “answer1000” and it has 1000 solutions. Then the content format of answer_group is as follows:You can create your own test files and put them in the test group and answer group if you want. 1. Using this script requires installing the screen command. You can use the which screen command to check if screen is installed on your local machine. If it is not installed, you can install it using the following command: shell ubuntu(debian): sudo apt-get install screen #This or apt sudo apt install screen #This or apt-get centos(redhat): yum install screen 2. 2. The compiled executable file should be named sudoku_solve, and it need to be placed in the same directory as this script. shell df -h –type=ext41. The script will generate a sub-folder contains two files named Basic(Advanced)_Result and Basic(Advanced)_Answer, the Result file contains your program’s output and the Answer file contains reference output. The script will delete these two folders every time it runs, so if you need the data, make sure to copy them before running the script. 2. The script presents the time spent as relative, and there is a relatively fixed processing time for each run. For example, if your program takes 1300ms to solve a Sudoku problem, but the script takes 800ms for preparation, the final display will show 2100 milliseconds. Additionally, everyone’s configuration and performance are different, resulting in different times. This means that you only need to keep optimizing on your own machine instead of comparing with others. Rest assured that the same environment will be used for the final scoring. 3. (Very important) If you want to get a high score (script test), it is better to flush the data in the buffer in time. 3.2.2 Script Usage shell sudo ./Lab1.sh test_group answer_group The script takes two parameters, they are the 2 prepared files in 3.2.1. Note that this output below means that you are missing a line break at the end of your answer group, which will not be recognized. Of course, the path of your puzzle file should be in the same order as the answer path.An example:4. Lab submission Please submit your lab program and performance test report following the guidance in the Overall Lab Instructions (../README.md) 5. Grading standards 1. You can get 38 points if you can: 1) finish all the requirements of the basic version, and 2) your performance test report has finished the two requirements described before. If you missed some parts, you will get part of the points depending how much you finished 2. You can get 40 points (full score) if you can: 1) finish all the requirements of the advanced version, and 2) your performance test report has finished the two requirements described before. If you missed some parts, you will get part of the points depending how much you finished.

$25.00 View

[SOLVED] Embedded-systems – mini project 4

System Requirements Implement the following system to measure the distance using ultrasonic sensor HC-SR04 with the specifications listedbelow: 1. Use ATmega16 Microcontroller with frequency 8Mhz.2. Measure the distance using the Ultrasonic sensor HC-SR04. Check the “HC-SR04 Ultrasonic MT Student Tutorial” pdf file to understand how to interface with this sensor.3. The LCD should display the distance value like that:4. The project should be design and implemented based on the layered architecture model as follow:GPIO Driver Requirements 1. Use the Same GPIO driver implemented in the course. ICU Driver Requirements 1. Use the Same ICU driver implemented in the course. 2. The ICU should be configured with frequency F_CPU/8 and to detect the raising edge as the first edge. 3. ICU_init and ICU_setCallBack functions should be called inside the Ultrasonic_init function. LCD Driver Requirements 1. Use 4×16 LCD. 2. Use the Same LCD driver implemented in the course with 8-bits data mode. 3. Connect the LCD control pins and 8-bits data pins as follow: • RS → PB0 • RW → PB1 • E → PB2 • Data Bus → all PORTA pins. Ultrasonic Driver Requirements 1. Implement a full ultrasonic Driver using ATmega16 ICU driver. 2. The ultrasonic driver has 3 functions: a. void Ultrasonic_init(void) • Description ➢ Initialize the ICU driver as required. ➢ Setup the ICU call back function. ➢ Setup the direction for the trigger pin as output pin through the GPIO driver. • Inputs: None • Return: Noneb. void Ultrasonic_Trigger(void) • Description ➢ Send the Trigger pulse to the ultrasonic. • Inputs: None • Return: Nonec. uint16 Ultrasonic_readDistance(void) • Description ➢ Send the trigger pulse by using Ultrasonic_Trigger function. ➢ Start the measurements by the ICU from this moment. • Inputs: None • Return: The measured distance in Centimeter.d. void Ultrasonic_edgeProcessing(void) • Description ➢ This is the call back function called by the ICU driver. ➢ This is used to calculate the high time (pulse time) generated by the ultrasonic sensor. • Inputs: None • Return: NoneThe Project Hardware ConnectionsThanks and Good Luck Eng / Mohamed Tarek

$25.00 View

[SOLVED] Embedded-systems –

6. Connect 7447 decoder 4-pins to the first 4-pins in PORTC.7. Use first 6-pins in PORTA as the enable/disable pins for the six 7-segments.8. Stop Watch counting should start once the power is connected to the MCU.9. Configure External Interrupt INT0 with falling edge. Connect a push button with the internal pull-up resistor. If a falling edge detected the Stop Watch time should be reset.10. Configure External Interrupt INT1 with raising edge. Connect a push button with the external pull-down resistor. If a raising edge detected the Stop Watch time should be paused.11. Configure External Interrupt INT2 with falling edge. Connect a push button with the internal pull-up resistor. If a falling edge detected the Stop Watch time should be resumed.12. Check this video: https://youtu.be/yYCSIoMDszUThanks and Good Luck Eng / Mohamed Tarek

$25.00 View

[SOLVED] Ece250 – guidelines for submission

Theory Problems: • Submit a hard copy of your solutions in the wooden box kept on the 3rd Floor of Old Academic Block (right side of the lift). • Do all questions in sequence. Use A4 sheets (Plain). Staple your sheets properly • Clarifications: – Symbols have their usual meaning. Assume the missing information & mention it in the report. Use Google Classroom for any queries. In order to keep it fair for all, no email queries will be entertained. Programming Problems: • Use Matlab or python to solve the programming problems. • For your solutions, you need to submit a zipped file on Google classroom with the following: – program files (.m) or (.ipynb) with all dependencies. – a report (.pdf) with your coding outputs and generated plots. The report should be self-complete with all your assumptions and inferences clearly specified. • Before submission, please name your zipped file as: “A4 RollNo Name.zip”. • Codes/reports submitted without a zipped file or without following the naming convention will NOT be checked. • Important Note: Do not use inbuilt functions in MATLAB or PYTHON. Use mathematical equations/derivations to solve the required.Theory Problems (60 points) [CO4] Q1. A signal x(t) is represented by, ). Determine the following ), then determine g(t). [4 points] (b) Prove X(jω) is periodic signal. Specify X(jω) over one time period. [3 Points]. [CO4] Q2. Determine which, if any, of the real signals given in the following figure-1 have Fourier Transforms that satisfy each of the following conditions: [6×3 Points].Figure 1: Figure-Q1 (a) Re{X(jω)} = 0 (b) Img{X(jω)} = 0 (c) exp(jαω)X(jω) is real (for real value of α) (d) R−∞∞ X(jω)dω = 0 (e) R−∞∞ ωX(jω)dω = 0 (f) X(jω) is periodic [CO4] Q3. Consider the LTI system “S” with impulse response . Determine the output of “S” for each of the following inputs: [4×4 Points][CO4] Q4. The input and output of a causal LTI system are related by the differential equation- ) (1) (a) Find the impulse response of the system. [2 Points] (b) What is the response of the system if x(t) = t.e(−2t)u(t) [4 Points] (c) Repeat part (a) for the causal LTI system described by the following equation [4 Points] ) (2) [CO4] Q5. Let [5 Points] (3) where “*” denotes convolution and |ωc| ≤ π. Determine the stricter constraint on “ωc”, which ensure that- (4) [CO4] Q6. An input x[n] with length “3” is applied to an LTI system having an impulse response h[n] of length “5”. The output is y[n]. [4 points] y[n] ↔ Y (ejω) (5) |h[n]| ≤ L, |x[n]| ≤ B (6) Find the maximum value of Y (ej0). Programming Problems (10 points) [CO4] Q1. Let X(jω) be the Fourier transform of the signal x(t) given in Fig.2. (a) Determine and Plot the frequency domain signal X(jω). [1 Point]Figure 2: Q1 (b) Plot the magnitude spectrum of the frequency domain signal X(jω). [1 Point] (c) Plot the phase spectrum of the frequency domain signal X(jω). [1 Point] (d) Plot the inverse Fourier transform of real part of {X(jω)}. [1 Point] [CO4] Q2. Let x[n] be a discrete-time signal with Fourier Transform X(ejω), which is the given Fig. 3. Plot the frequency response, magnitude spectrum and phase spectrum of w[n] = x[n]p[n], for these p[n]Figure 3: Q2 (a) p[n] = cos(πn) [2 Points] (b) p[n] = sin(πn/2) [2 Points] (c) p[n] = P∞k=−∞ δ(n − 2k) [2 Points]

$25.00 View

[SOLVED] Ece250 – assignment 1

Instructions • Use Matlab/Python to solve the programming problems. • For your solutions, you need to submit a zipped file on Google classroom with the following: – program files (.m) or (.ipynb/.py)with all dependencies. – a report (.pdf) with your coding outputs and generated plots. The report should be self-complete with all your assumptions and inferences clearly specified. • Before submission, please name your zipped file as: “A1 RollNo Name.zip”. • Codes/reports submitted without a zipped file or without following the naming convention will NOT be checked. Programming Problems (10 points)1. Generate and plot each of the following sequences. Also, calculate the fundamental frequency.[CO1] (6 points) ), 2. Find the even and odd components of the signal x(t) = 2e−αt. Plot these in three individual subplots for the interval (Take the interval and value of α as per your choice). Write a proper explanation for considering such value.[CO1] (4 points)1

$25.00 View

[SOLVED] Ece250 – assignment 2

Instructions • Use Matlab/Python to solve the programming problems. • For your solutions, you need to submit a zipped file on Google classroom with the following: – program files (.m) or (.ipynb/.py)with all dependencies. – a report (.pdf) with your coding outputs and generated plots. The report should be self-complete with all your assumptions and inferences clearly specified. • Before submission, please name your zipped file as: “A2 RollNo Name.zip”. • Codes/reports submitted without a zipped file or without following the naming convention will NOT be checked. Programming Problems (10 points)1. (5pts) Consider an LTI system with input x[n] = u[n − 3] and the impulse response h[n] = (0.8)nu[n − 2]. Determine and plot the signals x[n], h[n] and y[n] for n = [−10,10]. 2. (5 pts) Consider two sequences with (1) , otherwise. and (2) , otherwise. Plot x[n] and h[n]. Determine and plot the output y[n] of these two signals for a positive value of α > 1. 1

$25.00 View

[SOLVED] Csed211 – 1

In this lab you will be writing a dynamic storage allocator for C programs, i.e., your own version of the malloc, free and realloc routines. You are encouraged to explore the design space creatively and implement an allocator that is correct, efficient and fast. 2 Logistics As usual, this is an individual project. Clarifications and corrections will be posted on PLMS. If you have any question about the lab, check the FAQ and use the Q&A board in PLMS. 3 Hand Out Instructions Start by copying malloclab-handout.tar to a directory in which you plan to do your work. Then give the command: unix> tar -xvf malloclab.tar This will cause a number of files to be unpacked into the directory. The only file you will be modifying and handing in is mm.c. The mdriver.c program is a driver program that allows you to evaluate the performance of your solution. Use the command make to generate the driver code and run it with the command ./mdriver -V. (The -V flag displays helpful summary information.) 4 How to Work on the Lab Your dynamic storage allocator will consist of the following four functions, which are declared in mm.h and defined in mm.c. int mm_init(void); void *mm_malloc(size_t size); void mm_free(void *ptr); void *mm_realloc(void *ptr, size_t size); In the mm.c file, we have given you implements the simplest but still functionally correct malloc package that we could think of. Using this as a starting place, modify these functions (and possibly define other private static functions), so that they obey the following semantics: • mminit: Before calling mmmalloc, mmrealloc, or mmfree, the application program (i.e., the trace-driven driver program that you will use to evaluate your implementation) calls mminit to perform any necessary initializations, such as allocating the initial heap area. The return value should be -1 if there was a problem in performing the initialization, 0 otherwise. • mmmalloc: The mmmalloc routine returns a pointer to an allocated block payload of at least size bytes. The entire allocated block should lie within the heap region and should not overlap with any other allocated chunk. We will compare your implementation to the version of malloc supplied in the standard C library (libc). Since the libc malloc always returns payload pointers that are aligned to 8 bytes, your malloc implementation should do likewise and always return 8-byte aligned pointers. • mmfree: The mm free routine frees the block pointed to by ptr. It returns nothing. This routine is only guaranteed to work when the passed pointer (ptr) was returned by an earlier call to mmmalloc or mmrealloc and has not yet been freed. • mmrealloc: The mmrealloc routine returns a pointer to an allocated region of at least size bytes with the following constraints. – if ptr is NULL, the call is equivalent to mmmalloc(size); – if size is equal to zero, the call is equivalent to mmfree(ptr); – if ptr is not NULL, it must have been returned by an earlier call to mmmalloc or mmrealloc. The call to mmrealloc changes the size of the memory block pointed to by ptr (the old block) to size bytes and returns the address of the new block. Notice that the address of the new block might be the same as the old block, or it might be different, depending on your implementation, the amount of internal fragmentation in the old block, and the size of the realloc request. The contents of the new block are the same as those of the old ptr block, up to the minimum of the old and new sizes. Everything else is uninitialized. For example, if the old block is 8 bytes and the new block is 12 bytes, then the first 8 bytes of the new block are identical to the first 8 bytes of the old block and the last 4 bytes are uninitialized. Similarly, if the old block is 8 bytes and the new block is 4 bytes, then the contents of the new block are identical to the first 4 bytes of the old block. These semantics match the the semantics of the corresponding libcmalloc, realloc, and free routines. For the complete documentation, type the following command in Linux terminal: unix> man malloc 5 Heap Consistency Checker Dynamic memory allocators are notoriously tricky beasts to program correctly and efficiently. They are difficult to program correctly because they involve a lot of untyped pointer manipulation. You will find it very helpful to write a heap checker that scans the heap and checks it for consistency. Some examples of what a heap checker might check are: • Is every block in the free list marked as free? • Are there any contiguous free blocks that somehow escaped coalescing? • Is every free block actually in the free list? • Do the pointers in the free list point to valid free blocks? • Do any allocated blocks overlap? • Do the pointers in a heap block point to valid heap addresses? Your heap checker will consist of the function int mmcheck(void) in mm.c. It will check any invariants or consistency conditions you consider prudent. It returns a nonzero value if and only if your heap is consistent. You are not limited to the listed suggestions nor are you required to check all of them. You are encouraged to print out error messages when mmcheck fails. This consistency checker is for your own debugging during development. When you submit mm.c, make sure to remove any calls to mmcheck as they will slow down your throughput. Style points will be given for your mmcheck function. Make sure to put in comments and document what you are checking. 6 Support Routines The memlib.c package simulates the memory system for your dynamic memory allocator. You can invoke the following functions in memlib.c: • void *memsbrk(int incr): Expands the heap by incr bytes, where incr is a positive non-zero integer and returns a generic pointer to the first byte of the newly allocated heap area. The semantics are identical to the Unix sbrk function, except that memsbrk accepts only a positive non-zero integer argument. • void *memheaplo(void): Returns a generic pointer to the first byte in the heap. • void *memheaphi(void): Returns a generic pointer to the last byte in the heap. • sizet memheapsize(void): Returns the current size of the heap in bytes. • sizet mempagesize(void): Returns the system’s page size in bytes (4K on Linux systems). 7 The Trace-driven Driver Program The driver program mdriver.c in the malloclab-handout.tar distribution tests your mm.c package for correctness, space utilization, and throughput. The driver program is controlled by a set of trace files that are included in the malloclab-handout.tar distribution. Each trace file contains a sequence of allocate, reallocate, and free directions that instruct the driver to call your mmmalloc, mmrealloc, and mmfree routines in some sequence. The driver and the trace files are the same ones we will use when we grade your handin mm.c file. The driver mdriver.c accepts the following command line arguments: • -t : Look for the default trace files in directory tracedir instead of the default directory defined in config.h. • -f : Use one particular tracefile for testing instead of the default set of tracefiles. • -h: Print a summary of the command line arguments. • -l: Run and measure libc malloc in addition to the student’s malloc package. • -v: Verbose output. Print a performance breakdown for each tracefile in a compact table. • -V: More verbose output. Prints additional diagnostic information as each trace file is processed. Useful during debugging for determining which trace file is causing your malloc package to fail. For more information, read “Building and running the driver” part in README. 8 Programming Rules • You should not change any of the interfaces in mm.c. (do not modify function header) • You should not invoke any memory-management related library calls or system calls. This excludes the use of malloc, calloc, free, realloc, sbrk, brk or any variants of these calls in your code. • You are not allowed to define any global or static compound data structures such as arrays, structs, trees, or lists in your mm.c program. However, you are allowed to declare global scalar variables such as integers, floats, and pointers in mm.c. • For consistency with the libcmalloc package, which returns blocks aligned on 8-byte boundaries, your allocator must always return pointers that are aligned to 8-byte boundaries. The driver will enforce this requirement for you. 9 Evaluation You will receive zero points if you break any of the rules or your code is buggy and crashes the driver. Otherwise, your grade will be calculated as follows: • Correctness (20 points). You will receive full points if your solution passes the correctness tests performed by the driver program. You will receive partial credit for each correct trace. • Performance (35 points). Two performance metrics will be used to evaluate your solution: – Space utilization: The peak ratio between the aggregate amount of memory used by the driver (i.e., allocated via mmmalloc or mmrealloc but not yet freed via mmfree) and the size of the heap used by your allocator. The optimal ratio equals to 1. You should find good policies to minimize fragmentation in order to make this ratio as close as possible to the optimal. – Throughput: The average number of operations completed per second. The driver program summarizes the performance of your allocator by computing a performance index, P, which is a weighted sum of the space utilization and throughputwhere U is your space utilization, T is your throughput, and Tlibc is the estimated throughput of libc malloc on your system on the default traces. The performance index favors space utilization over throughput, with a default of w = 0.6. Observing that both memory and CPU cycles are expensive system resources, we adopt this formula to encourage balanced optimization of both memory utilization and throughput. Ideally, the performance index will reach P = w + (1 → w) = 1 or 100%. Since each metric will contribute at most w and 1 → w to the performance index, respectively, you should not go to extremes to optimize either the memory utilization or the throughput only. To receive a good score, you must achieve a balance between utilization and throughput. • Style (10 points). – Your code should be decomposed into functions and use as few global variables as possible. – Your code should begin with a header comment that describes the structure of your free and allocated blocks, the organization of the free list, and how your allocator manipulates the free list. each function should be preceeded by a header comment that describes what the function does. – Each subroutine should have a header comment that describes what it does and how it does it. – Your heap consistency checker mmcheck should be thorough and well-documented. You will be awarded 5 points for a good heap consistency checker and 5 points for good program structure and comments. 10 Handin Instructions Submit your code as [student id]mm.c (e.g., 2023xxxxmm.c) and your report as [student id].pdf (e.g., 2023xxxx.pdf). Do not compress the file, submit your code and report separately. 11 Hints • Use the mdriver-f option. During initial development, using tiny trace files will simplify debugging and testing. We have included two such trace files (short1,2-bal.rep) that you can use for initial debugging. • Use the mdriver-v and -V options. The -v option will give you a detailed summary for each trace file. The -V will also indicate when each trace file is read, which will help you isolate errors. • Compile with gcc -g and use a debugger. A debugger will help you isolate and identify out of bounds memory references. • Understand every line of the malloc implementation in the textbook. The textbook has a detailed example of a simple allocator based on an implicit free list. Use this is a point of departure. Don’t start working on your allocator until you understand everything about the simple implicit list allocator. • Encapsulate your pointer arithmetic in C preprocessor macros. Pointer arithmetic in memory managers is confusing and error-prone because of all the casting that is necessary. You can reduce the complexity significantly by writing macros for your pointer operations. See the text for examples. • Do your implementation in stages. The first 9 traces contain requests to malloc and free. The last 2 traces contain requests for realloc, malloc, and free. We recommend that you start by getting your malloc and free routines working correctly and efficiently on the first 9 traces. Only then should you turn your attention to the realloc implementation. For starters, build realloc on top of your existing malloc and free implementations. But to get really good performance, you will need to build a stand-alone realloc. • Start early! It is possible to write an efficient malloc package with a few pages of code. However, we can guarantee that it will be some of the most difficult and sophisticated code you have written so far in your career. So start early, and good luck!

$25.00 View

[SOLVED] Ece250: signals and systems

Guidelines for submission Theory Problems: • Submit a hard copy of your solutions in the wooden box kept on the 3rd Floor of Old Academic Block (right side of the lift). • Do all questions in sequence. • Use A4 sheets (Plain). Staple your sheets properly Programming Problems: • Use Matlab or python to solve the programming problems. • For your solutions, you need to submit a zipped file on Google classroom with the following: – program files (.m) or (.ipynb) with all dependencies. – a report (.pdf) with your coding outputs and generated plots. The report should be self-complete with all your assumptions and inferences clearly specified. • Before submission, please name your zipped file as: “A3 RollNo Name.zip”. • Codes/reports submitted without a zipped file or without following the naming convention will NOT be checked.Theory Problems (35 points) [CO3] Q1. Consider a causal continuous time LTI system whose input x(t) and output y(t) are related by the following differential equation:[2×5 Points] ) (1) Find the Fourier series representation of the output y(t) for each of the following inputs(b) x(t) = sin(4πt) + cos(6πt + π/4) [CO3] Q2. Consider a periodic signal x(t) with fourier series coefficient ak given below with the condition that the fundamental angular frequency w0 is equal to π for x(t), then Determine the signal x(t).[6 Points] 1Figure 1: Problem 2 [CO3] Q3. Determine the Fourier series coefficients for each of the following discrete-time periodic signa]s. Plot the magnitude and phase of each set of coefficients ak.[24 Points] (a) Each x[n] depicted in figure 2.[3×4 Points] (b) x[n] = sin(2πn/3)cos(πn/2)[4 Points] (c) x[n] is periodic with period 4 and[4 Points] x[n] = 1 − sin(πn/4) for 0 ≤ n ≤ 3 (2) (d) x[n] is periodic with period 12 and [4 Points] x[n] = 1 − sin(πn/4) for 0 ≤ n ≤ 11 (3) [CO3] Q4. The signal x(t) is defined as follows, with time period T = 6:  t + 2 for − 2 < t < −1  x(t) = 1 for − 1 < t < 1 (4) 2 − t for 1 < t < 2 (a) Determine the Fourier series representation for the signal x(t). [4 Points] (b) Determine the ratio of power in the 7th harmonic to the power in the 5th harmonic. [1 Points]Figure 2: Problem 3 Programming Problems (10 points) [CO3] Q1. 1. Given a discrete-time signal x[n]:[6 Points]  1 for − N1 ≤ n ≤ N1,N1 = 2 x[n] = (5) 0 for Compute the Fourier series for the following cases and give the inference. (a) N =4N1 + 1 (b) N =8N1 + 1 (c) N =10N1 + 1 [CO3] Q2. A periodic function is defined by:[4 Points] f(x) = x + π, -π ≤ x < π f(x + 2π) = f(x) (a) Sketch the graph of f(x) for three periods. (b) Find the Fourier series of f(x) on the interval −π < x < π. Hint: To simulate continuous signals use appropriate discretization (wherever required).

$25.00 View

[SOLVED] Csed211 – sucheol lee is the lead person for this assignment. if you have problem doing assignment, check the faq for shell lab or use the q&a board in plms.

1 Introduction The purpose of this assignment is to become more familiar with the concepts of process control and signalling. You’ll do this by writing a simple Unix shell program that supports job control. 2 Handout Instructions Download the shlab-handout.tar from PLMS. Upload the file to a programming server, move it to the directory you want to work on. Then give the command unix> tar xvf shlab-handout.tar This will cause a number of files to be unpacked in the directory. The only file you will be modifying is tsh.c. Looking at the tsh.c (tiny shell) file, we have already implemented the less interesting functions. Your assignment is to complete the remaining empty functions listed below. As a sanity check for you, we’ve listed the approximate number of lines of code for each of these functions in our reference solution (which includes lots of comments). • eval: Main routine that parses and interprets the command line. [70 lines] • builtin cmd: Recognizes and interprets the built-in commands: quit, fg, bg, and jobs. [25 lines] • dobgfg: Implements the bg and fg built-in commands. [50 lines] • waitfg: Waits for a foreground job to complete. [20 lines] • sigchld handler: Catches SIGCHILD signals. 80 lines] siginthandler: Catches SIGINT (ctrl-c) signals. [15 lines] • sigtstphandler: Catches SIGTSTP (ctrl-z) signals. [15 lines] Each time you modify your tsh.c file, type make to recompile it. To run your shell, type tsh to the command line: unix> ./tsh tsh> [type commands to your shell here] 3 General Overview of Unix Shells A shell is an interactive command-line interpreter that runs programs on behalf of the user. A shell repeatedly prints a prompt, waits for a command line on stdin, and then carries out some action, as directed by the contents of the command line. The command line is a sequence of ASCII text words delimited by whitespace. The first word in the command line is either the name of a built-in command or the pathname of an executable file. The remaining words are command-line arguments. If the first word is a built-in command, the shell immediately executes the command in the current process. Otherwise, the word is assumed to be the pathname of an executable program. In this case, the shell forks a child process, then loads and runs the program in the context of the child. The child processes created as a result of interpreting a single command line are known collectively as a job. In general, a job can consist of multiple child processes connected by Unix pipes. If the command line ends with an ampersand ”&”, then the job runs in the background, which means that the shell does not wait for the job to terminate before printing the prompt and awaiting the next command line. Otherwise, the job runs in the foreground, which means that the shell waits for the job to terminate before awaiting the next command line. Thus, at any point in time, at most one job can be running in the foreground. However, an arbitrary number of jobs can run in the background. For example, typing the command line tsh> jobs causes the shell to execute the built-in jobs command. Typing the command line tsh> /bin/ls -l -d runs the ls program in the foreground. By convention, the shell ensures that when the program begins executing its main routine int main(int argc, char *argv[]) the argc and argv arguments have the following values: argc == 3, • argv[0] == ‘‘/bin/ls’’, • argv[1]== ‘‘-l’’, • argv[2]== ‘‘-d’’. Alternatively, typing the command line tsh> /bin/ls -l -d & runs the ls program in the background. Unix shells support the notion of job control, which allows users to move jobs back and forth between background and foreground, and to change the process state (running, stopped, or terminated) of the processes in a job. Typing ctrl-c causes a SIGINT signal to be delivered to each process in the foreground job. The default action for SIGINT is to terminate the process. Similarly, typing ctrl-z causes a SIGTSTP signal to be delivered to each process in the foreground job. The default action for SIGTSTP is to place a process in the stopped state, where it remains until it is awakened by the receipt of a SIGCONT signal. Unix shells also provide various built-in commands that support job control. For example: • jobs: Lists the running and stopped background jobs. • bg : Changes a stopped background job to a running background job. • fg : Changes a stopped or running background job to a running in the foreground. • kill : Terminates a job. 4 The tsh Specification Your tsh shell should have the following features: • The prompt should be the string “tsh> ”. • The command line typed by the user should consist of a name and zero or more arguments, all separated by one or more spaces. If name is a built-in command, then tsh should handle it immediately and wait for the next command line. Otherwise, tsh should assume that name is the path of an executable file, which it loads and runs in the context of an initial child process (In this context, the term job refers to this initial child process). • tsh does not need to support pipes (|) or I/O redirection (< and >). • Typing ctrl-c (ctrl-z) should cause a SIGINT (SIGTSTP) signal to be sent to the current foreground job, as well as any descendents of that job (e.g., any child processes that it forked). If there is no foreground job, then the signal should have no effect. If the command line ends with an ampersand &, then tsh should run the job in the background. Otherwise, it should run the job in the foreground. • tsh should support the following built-in commands: – The quit command terminates the shell. – The jobs command lists all background jobs. – The bg command restarts by sending it a SIGCONT signal, and then runs it in the background. The argument can be either a PID or a JID. – The fg command restarts by sending it a SIGCONT signal, and then runs it in the foreground. The argument can be either a PID or a JID. • tsh should reap all of its zombie children. If any job terminates because it receives a signal that it didn’t catch, then tsh should recognize this event and print a message with the job’s PID and a description of the offending signal. 5 Checking Your Work We have provided some tools to help you check your work. Reference solution. The Linux executable tshref is the reference solution for the shell. Run this program to resolve any questions you have about how your shell should behave. Your shell should emit output that is identical to the reference solution (except for PIDs, of course, which change from run to run). Shell driver. The sdriver.pl program executes a shell as a child process, sends it commands and signals as directed by a trace file, and captures and displays the output from the shell. Use the -h argument to find out the usage of sdriver.pl: unix> ./sdriver.pl -h Usage: sdriver.pl [-hv] -t -s -a Options: -h Print this message -v Be more verbose -t Trace file -s Shell program to test -a Shell arguments -g Generate output for autograder We have also provided 16 trace files (trace{01-16}.txt) that you will use in conjunction with the shell driver to test the correctness of your shell. The lower-numbered trace files do very simple tests, and the highernumbered tests do more complicated tests.You can run the shell driver on your shell using trace file trace01.txt (for instance) by typing: unix> ./sdriver.pl -t trace01.txt -s ./tshref -a “-p” (the -a ”-p” argument tells your shell not to emit a prompt), or unix> make rtest01 For your reference, tshref.out gives the output of the reference solution on all races. This might be more convenient for you than manually running the shell driver on all trace files. The neat thing about the trace files is that they generate the same output you would have gotten had you run your shell interactively (except for an initial comment that identifies the trace). For example: bass> make test15 ./sdriver.pl -t trace15.txt -s ./tsh -a “-p” # # trace15.txt – Putting it all together # tsh> ./bogus ./bogus: Command not found. tsh> ./myspin 10 Job (9721) terminated by signal 2 tsh> ./myspin 3 & [1] (9723) ./myspin 3 & tsh> ./myspin 4 & [2] (9725) ./myspin 4 & tsh> jobs [1] (9723) Running ./myspin 3 & [2] (9725) Running ./myspin 4 & tsh> fg %1 Job [1] (9723) stopped by signal 20 tsh> jobs [1] (9723) Stopped ./myspin 3 & [2] (9725) Running ./myspin 4 & tsh> bg %3 %3: No such job tsh> bg %1 [1] (9723) ./myspin 3 & tsh> jobs [1] (9723) Running ./myspin 3 & [2] (9725) Running ./myspin 4 & tsh> fg %1 tsh> quit bass> 6 Hints • Read every word of Chapter 8 (Exceptional Control Flow) in your textbook. • Use the trace files to guide the development of your shell. Starting with trace01.txt, make sure that your shell produces the identical output as the reference shell. Then move on to trace file trace02.txt, and so on. • The waitpid, kill, fork, execve, setpgid, and sigprocmask functions will come in very handy. The WUNTRACED and WNOHANG options to waitpid will also be useful. • When you implement your signal handlers, be sure to send SIGINT and SIGTSTP signals to the entire foreground process group, using ”-pid” instead of ”pid” in the argument to the kill function. The sdriver.pl program tests for this error. • One of the tricky parts of the assignment is deciding on the allocation of work between the waitfg and sigchld handler functions. We recommend the following approach: – In waitfg, use a busy loop around the sleep function. – In sigchldhandler, use exactly one call to waitpid. While other solutions are possible, such as calling waitpid in both waitfg and sigchldhandler, these can be very confusing. It is simpler to do all reaping in the handler. • In eval, the parent must use sigprocmask to block SIGCHLD signals before it forks the child, and then unblock these signals, again using sigprocmask after it adds the child to the job list by calling addjob. Since children inherit the blocked vectors of their parents, the child must be sure to then unblock SIGCHLD signals before it execs the new program. The parent needs to block the SIGCHLD signals in this way in order to avoid the race condition where the child is reaped by sigchld handler (and thus removed from the job list) before the parent calls addjob. • Programs such as more, less, vi, and emacs do strange things with the terminal settings. Don’t run these programs from your shell. Stick with simple text-based programs such as /bin/ls, /bin/ps, and /bin/echo. • When you run your shell from the standard Unix shell, your shell is running in the foreground process group. If your shell then creates a child process, by default that child will also be a member of the foreground process group. Since typing ctrl-c sends a SIGINT to every process in the foreground group, typing ctrl-c will send a SIGINT to your shell, as well as to every process that your shell created, which obviously isn’t correct. Here is the workaround: After the fork, but before the execve, the child process should call setpgid(0, 0), which puts the child in a new process group whose group ID is identical to the child’s PID. This ensures that there will be only one process, your shell, in the foreground process group. When you type ctrl-c, the shell should catch the resulting SIGINT and then forward it to the appropriate foreground job (or more precisely, the process group that contains the foreground job). 7 Evaluation Your score will be computed out of a maximum of 100 points based on the following distribution: 10 pts Quiz. 40 pts Correctness: 16 trace files at 2.5 points each. 50 pts Report. Your solution shell will be tested for correctness on programming server, using the same shell driver and trace files that were included in shlab-handout.tar. Your shell should produce identical output on these traces as the reference shell, with only two exceptions: • The PIDs can (and will) be different. • The output of the /bin/ps commands in trace11.txt, trace12.txt, and trace13.txt will be different from run to run. However, the running states of any mysplit processes in the output of the /bin/ps command should be identical.

$25.00 View

[SOLVED] Csed211 – dowon son is the lead person for this assignment. if you have problem doing assignment, check the faq for cache lab or use the q&a board in plms.

1 Logistics This is an individual project. You must run this lab on a 64-bit x86-64 machine. 1.1 Cheating Policy You are allowed to refer to the following sources: • Internet sources that do not contain answers or codes related to the cache lab (e.g., the Valgrind manual) However, you should not refer to: • ChatGPT with direct query for answers or parts of a solution • Code and reports from seniors who have already taken this course • Blogs or GitHub repositories that contain solution codes (e.g., csim.c or trans.c) If you refer to illegal references, you will receive zero score for this assignment. 2 Overview This lab will help you understand the impact that cache memories can have on the performance of your C programs. The lab consists of two parts. In the first part you will write a small C program (about 200-300 lines) that simulates the behavior of a cache memory. In the second part, you will optimize a small matrix transpose function, with the goal of minimizing the number of cache misses. 3 Downloading the Assignment Download the assignment materials cachelab-handout.tar posted on PLMS. Start by copying cachelab-handout.tar to a protected Linux directory in which you plan to do your work. Then give the command linux> tar -xvf cachelab-handout.tar This will create a directory called cachelab-handout that contains a number of files. You will be modifying two files: csim.c and trans.c. To compile these files, type: linux> make clean linux> make 4 Description The lab has two parts. In Part A, you will implement a cache simulator. In Part B, you will write a matrix transpose function that is optimized for cache performance. 4.1 Reference Trace Files The traces subdirectory of the handout directory contains a collection of reference trace files that we will use to evaluate the correctness of the cache simulator you write in Part A. The trace files are generated by a Linux program called valgrind. For example, typing linux> valgrind –log-fd=1 –tool=lackey -v –trace-mem=yes ls -l on the command line runs the executable program “ls -l”, captures a trace of each of its memory accesses in the order they occur, and prints them on stdout. Valgrind memory traces have the following form: I 0400d7d4,8 M 0421c7f0,4 L 04f6b868,8 S 7ff0005c8,8 Each line denotes one or two memory accesses. The format of each line is [space]operation address,size The operation field denotes the type of memory access: “I” denotes an instruction load, “L” a data load, “S” a data store, and “M” a data modify (i.e., a data load followed by a data store). There is never a space before each “I”. There is always a space before each “M”, “L”, and “S”. The address field specifies a 64-bit hexadecimal memory address. The size field specifies the number of bytes accessed by the operation. 4.2 Part A: Writing a Cache Simulator In Part A, you will write a cache simulator in csim.c that takes a valgrind memory trace as input, simulates the hit/miss behavior of a cache memory on this trace, and outputs the total number of hits, misses, and evictions. We have provided you with the binary executable of a reference cache simulator, called csim-ref, that simulates the behavior of a cache with arbitrary size and associativity on a valgrind trace file. It uses the LRU (least-recently used) replacement policy when choosing which cache line to evict. The reference simulator takes the following command-line arguments: Usage: ./csim-ref [-hv] -s -E -b -t • -h: Optional help flag that prints usage info • -v: Optional verbose flag that displays trace info • -s : Number of set index bits (S =2s is the number of sets) • -E : Associativity (number of lines per set) • -b : Number of block bits (B =2b is the block size) • -t : Name of the valgrind trace to replay The command-line arguments are based on the notation (s, E, and b) from page 597 of the CS:APP2e textbook. For example: linux> ./csim-ref -s 4 -E 1 -b 4 -t traces/yi.trace hits:4 misses:5 evictions:3 The same example in verbose mode: linux> ./csim-ref -v -s 4 -E 1 -b 4 -t traces/yi.trace L 10,1 miss M 20,1 miss hit L 22,1 hit S 18,1 hit L 110,1 miss eviction L 210,1 miss eviction M 12,1 miss eviction hit hits:4 misses:5 evictions:3 Your job for Part A is to fill in the csim.c file so that it takes the same command line arguments and produces the identical output as the reference simulator. Notice that this file is almost completely empty. You’ll need to write it from scratch. Programming Rules for Part A • Your csim.c file must compile without warnings in order to receive credit. • Your simulator must work correctly for arbitrary s, E, and b. This means that you will need to allocate storage for your simulator’s data structures using the malloc function. Type “man malloc” for information about this function. • To receive credit for Part A, you must call the function printSummary, with the total number of hits, misses, and evictions, at the end of your main function: printSummary(hit_count, miss_count, eviction_count); • For this lab, you should assume that memory accesses are aligned properly, such that a single memory access never crosses block boundaries. By making this assumption, you can ignore the request sizes in the valgrind traces. 4.3 Part B: Optimizing Matrix Transpose In Part B, you will write a transpose function in trans.c that causes as few cache misses as possible. Let A denote a matrix, and Aij denote the component on the ith row and jth column. The transpose of A, denoted AT, is a matrix such that Aij = ATji. To help you get started, we have given you an example transpose function in trans.c that computes the transpose of N × M matrix A and stores the results in M × N matrix B: char trans_desc[] = “Simple row-wise scan transpose”; void trans(int M, int N, int A[N][M], int B[M][N]) The example transpose function is correct, but it is inefficient because the access pattern results in relatively many cache misses. Your job in Part B is to write a similar function, called transpose_submit, that minimizes the number of cache misses across different sized matrices: char transpose_submit_desc[] = “Transpose submission”; void transpose_submit(int M, int N, int A[N][M], int B[M][N]); Do not change the description string (“Transpose submission”) for your transpose_submit function. The autograder searches for this string to determine which transpose function to evaluate for credit. Programming Rules for Part B • Your code in trans.c must compile without warnings to receive credit. • You are allowed to define at most 12 local variables of type int per transpose function. • You are not allowed to side-step the previous rule by using any variables of type long or by using any bit tricks to store more than one value to a single variable. • You are NOT allowed to define any arrays in your code or to use any variant of malloc. 5 Evaluation This section describes how your work will be evaluated. The full score for this lab is 53 points: • Part A: 27 Points • Part B: 26 Points If you violate the Programming Rules in Part A or Part B, you will receive zero point for that Part. 5.1 Evaluation for Part A For Part A, we will run your cache simulator using different cache parameters and traces. There are eight test cases, each worth 3 points, except for the last case, which is worth 6 points: linux> ./csim -s 1 -E 1 -b 1 -t traces/yi2.trace linux> ./csim -s 4 -E 2 -b 4 -t traces/yi.trace linux> ./csim -s 2 -E 1 -b 4 -t traces/dave.trace linux> ./csim -s 2 -E 1 -b 3 -t traces/trans.trace linux> ./csim -s 2 -E 2 -b 3 -t traces/trans.trace linux> ./csim -s 2 -E 4 -b 3 -t traces/trans.trace linux> ./csim -s 5 -E 1 -b 5 -t traces/trans.trace linux> ./csim -s 5 -E 1 -b 5 -t traces/long.trace You can use the reference simulator csim-ref to obtain the correct answer for each of these test cases. During debugging, use the -v option for a detailed record of each hit and miss. For each test case, outputting the correct number of cache hits, misses and evictions will give you full credit for that test case. Each of your reported number of hits, misses and evictions is worth 1/3 of the credit for that test case. That is, if a particular test case is worth 3 points, and your simulator outputs the correct number of hits and misses, but reports the wrong number of evictions, then you will earn 2 points. 5.2 Evaluation for Part B For Part B, we will evaluate the correctness and performance of your transpose_submit function on three different-sized output matrices: • 32×32 (M =32, N =32) • 64×64 (M =64, N =64) • 61×67 (M =61, N =67) 5.2.1 Performance (26 pts) For each matrix size, the performance of your transpose_submit function is evaluated by using valgrind to extract the address trace for your function, and then using the reference simulator to replay this trace on a cache with parameters (s =5, E =1, b =5). Your performance score for each matrix size scales linearly with the number of misses, m, up to some threshold: • 32×32: 8 points if m < 300, 0 points if m > 600 • 64×64: 8 points if m < 1,300, 0 points if m > 2,000 • 61×67: 10 points if m < 2,000, 0 points if m > 3,000 Your code must be correct to receive any performance points for a particular size. Your code only needs to be correct for these three cases and you can optimize it specifically for these three cases. In particular, it is perfectly OK for your function to explicitly check for the input sizes and implement separate code optimized for each case. 6 Working on the Lab 6.1 Working on Part A We have provided you with an autograding program, called test-csim, that tests the correctness of your cache simulator on the reference traces. Be sure to compile your simulator before running the test: linux> make linux> ./test-csim Your simulator Reference simulator Points (s,E,b) Hits Misses Evicts Hits Misses Evicts 3 (1,1,1) 9 8 6 9 8 6 traces/yi2.trace 3 (4,2,4) 4 5 2 4 5 2 traces/yi.trace 3 (2,1,4) 2 3 1 2 3 1 traces/dave.trace 3 (2,1,3) 167 71 67 167 71 67 traces/trans.trace 3 (2,2,3) 201 37 29 201 37 29 traces/trans.trace 3 (2,4,3) 212 26 10 212 26 10 traces/trans.trace 3 (5,1,5) 231 7 0 231 7 0 traces/trans.trace 6 (5,1,5) 265189 21775 21743 265189 21775 21743 traces/long.trace 27 For each test, it shows the number of points you earned, the cache parameters, the input trace file, and a comparison of the results from your simulator and the reference simulator. Here are some hints and suggestions for working on Part A: • Do your initial debugging on the small traces, such as traces/dave.trace. • The reference simulator takes an optional -v argument that enables verbose output, displaying the hits, misses, and evictions that occur as a result of each memory access. You are not required to implement this feature in your csim.c code, but we strongly recommend that you do so. It will help you debug by allowing you to directly compare the behavior of your simulator with the reference simulator on the reference trace files. • We recommend that you use the getopt function to parse your command line arguments. You’ll need the following header files: #include #include #include See “man 3 getopt” for details. • Each data load (L) or store (S) operation can cause at most one cache miss. The data modify operation (M) is treated as a load followed by a store to the same address. Thus, an M operation can result in two cache hits, or a miss and a hit plus a possible eviction. 6.2 Working on Part B We have provided you with an autograding program, called test-trans.c, that tests the correctness and performance of each of the transpose functions that you have registered with the autograder. You can register up to 100 versions of the transpose function in your trans.c file. Each transpose version has the following form: /* Header comment */ char trans_simple_desc[] = “A simple transpose”; void trans_simple(int M, int N, int A[N][M], int B[M][N]) { /* your transpose code here */ } Register a particular transpose function with the autograder by making a call of the form: registerTransFunction(trans_simple, trans_simple_desc); in the registerFunctions routine in trans.c. At runtime, the autograder will evaluate each registered transpose function and print the results. Of course, one of the registered functions must be the transpose_submit function that you are submitting for credit: registerTransFunction(transpose_submit, transpose_submit_desc); See the default trans.c function for an example of how this works. The autograder takes the matrix size as input. It uses valgrind to generate a trace of each registered transpose function. It then evaluates each trace by running the reference simulator on a cache with parameters (s =5, E =1, b =5). For example, to test your registered transpose functions on a 32×32 matrix, rebuild test-trans, and then run it with the appropriate values for M and N: linux> make linux> ./test-trans -M 32 -N 32 Step 1: Evaluating registered transpose funcs for correctness: func 0 (Transpose submission): correctness: 1 func 1 (Simple row-wise scan transpose): correctness: 1 func 2 (column-wise scan transpose): correctness: 1 func 3 (using a zig-zag access pattern): correctness: 1 Step 2: Generating memory traces for registered transpose funcs. Step 3: Evaluating performance of registered transpose funcs (s=5, E=1, b=5) func 0 (Transpose submission): hits:1766, misses:287, evictions:255 func 1 (Simple row-wise scan transpose): hits:870, misses:1183, evictions:1151 func 2 (column-wise scan transpose): hits:870, misses:1183, evictions:1151 func 3 (using a zig-zag access pattern): hits:1076, misses:977, evictions:945 Summary for official submission (func 0): correctness=1 misses=287 In this example, we have registered four different transpose functions in trans.c. The test-trans program tests each of the registered functions, displays the results for each, and extracts the results for the official submission. Here are some hints and suggestions for working on Part B. • The test-trans program saves the trace for function i in file trace.fi. These trace files are invaluable debugging tools that can help you understand exactly where the hits and misses for each transpose function are coming from. To debug a particular function, simply run its trace through the reference simulator with the verbose option: linux> ./csim-ref -v -s 5 -E 1 -b 5 -t trace.f0 S 68312c,1 miss L 683140,8 miss L 683124,4 hit L 683120,4 hit L 603124,4 miss eviction S 6431a0,4 miss … • Since your transpose function is being evaluated on a direct-mapped cache, conflict misses are a potential problem. Think about the potential for conflict misses in your code, especially along the diagonal. Try to think of access patterns that will decrease the number of these conflict misses. • Blocking is a useful technique for reducing cache misses. See http://csapp.cs.cmu.edu/public/waside/waside-blocking.pdf for more information. 6.3 Putting it All Together To run the driver, type: linux> python2 driver.py 7 Handing in Your Work Please submit the csim.c, trans.c, and report files as[studentID]csim.c, [studentID]trans.c, and [studentID].pdf ex) 20242057_csim.c, 20242057_trans.c, 20242057.pdf IMPORTANT: You should submit all 3 files to get credit.

$25.00 View

[SOLVED] Csed211 – seunghun oh is the lead person for this assignment. if you have problem doing assignment, check the faq for bomb lab or use the q&a board in plms.

1 Introduction The nefarious Dr. Evil has planted a slew of “binary bombs” on our class machines. A binary bomb is a program that consists of a sequence of phases. Each phase expects you to type a particular string on stdin. If you type the correct string, then the phase is defused and the bomb proceeds to the next phase. Otherwise, the bomb explodes by printing “BOOM!!!” and then terminating. The bomb is defused when every phase has been defused. Step 1: Get Your Bomb You can obtain your bomb by pointing your Web browser at: http://127.0.0.1:15213 This will display a binary bomb request form for you to fill in. Enter your user name and email address and hit the Submit button. The server will build your bomb and return it to your browser in a tar file called bombk.tar, where k is the unique number of your bomb. Save the bombk.tar file to a (protected) directory in which you plan to do your work. Then give the command: tar -xvf bombk.tar. This will create a directory called ./bombk with the following files: • README: Identifies the bomb and its owners. • bomb: The executable binary bomb. • bomb.c: Source file with the bomb’s main routine and a friendly greeting from Dr. Evil. If for some reason you request multiple bombs, this is not a problem. Choose the first downloaded bomb to work on and delete the rest Step 2: Defuse Your Bomb Your job for this lab is to defuse your bomb. You must do the assignment on one of the class machines. In fact, there is a rumor that Dr. Evil really is evil, and the bomb will always blow up if run elsewhere. There are several other tamper-proofing devices built into the bomb as well, or so we hear. You can use many tools to help you defuse your bomb. Please look at the hints section for some tips and ideas. The best way is to use your favorite debugger to step through the disassembled binary. Each time your bomb explodes it notifies the bomblab server, and you lose 1/2 point (up to a max of 20 points) in the final score for the lab. So there are consequences to exploding the bomb. You must be careful! The first four phases are worth 10 points each. Phases 5 and 6 are a little more difficult, so they are worth 15 points each. So the maximum score you can get is 70 points. Although phases get progressively harder to defuse, the expertise you gain as you move from phase to phase should offset this difficulty. However, the last phase will challenge even the best students, so please don’t wait until the last minute to start. The bomb ignores blank input lines. If you run your bomb with a command line argument, for example, $./bomb answers.txt then it will read the input lines from answers.txt until it reaches EOF (end of file), and then switch over to stdin (e.g., wait until you enter input via command line interface). In a moment of weakness, Dr. Evil added this feature so you don’t have to keep retyping the solutions to phases you have already defused. Note that after you run the program, you can use Ctrl+C (SIGINT) to terminate (or kill) the program instead of typing input (This does not cause bomb to explode). To avoid accidentally detonating the bomb, you will need to learn how to single-step through the assembly code and how to set breakpoints. You will also need to learn how to inspect both the registers and the memory states. One of the nice side-effects of doing the lab is that you will get very good at using a debugger. This is a crucial skill that will pay big dividends the rest of your career. Logistics This is an individual project. All handins are electronic. Clarifications and corrections will be posted on the course message board. Handin http://127.0.0.1:15213/scoreboard This web page is updated continuously to show the progress for each bomb. Hints (Please read this!) There are many ways of defusing your bomb. You can examine it in great detail without ever running the program, and figure out exactly what it does. This is a useful technique, but it not always easy to do. You can also run it under a debugger, watch what it does step by step, and use this information to defuse it. This is probably the fastest way of defusing it. We do make one request, please do not use brute force! You could write a program that will try every possible key to find the right one. But this is no good for several reasons: • You lose 1/2 point (up to a max of 20 points) every time you guess incorrectly and the bomb explodes. • Every time you guess wrong, a message is sent to the bomblab server. You could very quickly saturate the network with these messages, and cause the system administrators to revoke your computer access. Note that you need to defuse your own bomb. Your submission might be ignored if the bomb isn’t yours. Please double check when you download the bomb. • gdb The GNU debugger, this is a command line debugger tool available on virtually every platform. You can trace through a program line by line, examine memory and registers, look at both the source code and assembly code (we are not giving you the source code for most of your bomb), set breakpoints, set memory watch points, and write scripts. The CS:APP web site http://csapp.cs.cmu.edu/public/students.html has a very handy single-page gdb summary that you can print out and use as a reference. Here are some other tips for using gdb. – To keep the bomb from blowing up every time you type in a wrong input, you’ll want to learn how to set breakpoints. – For online documentation, type “help” at the gdb command prompt, or type “man gdb”, or “info gdb” at a Unix prompt. Some people also like to run gdb under gdb-mode in emacs. • objdump -t • objdump -d Use this to disassemble all of the code in the bomb. You can also just look at individual functions. Reading the assembler code can tell you how the bomb works. Although objdump -d gives you a lot of information, it doesn’t tell you the whole story. Calls to system-level functions are displayed in a cryptic form. For example, a call to sscanf might appear as: 8048c36: e8 99 fc ff ff call 80488d4 To determine that the call was to sscanf, you would need to disassemble within gdb. • strings This utility will display the printable strings in your bomb.

$25.00 View

[SOLVED] Csed211 – yonggon park is the lead person for this assignment. if you have problem doing assignment, check the faq for data lab2 or use the q&a board in plms.

1 Introduction The purpose of this assignment is to become more familiar with bit-level representations of integers and floating point numbers. You’ll do this by solving a series of programming “puzzles.” Many of these puzzles are quite artificial, but you’ll find yourself thinking much more about bits in working your way through them. 2 Handout Instructions Download the datalab-floating-point.tar from PLMS. Upload the file to a programming server, move it to the directory you want to work on. Then give the command unix> tar xvf datalab-floating-point.tar. This will cause a number of files to be unpacked in the directory. The only file you will be modifying and turning in is bits.c. The bits.c file contains a skeleton code for each of the 2 programming puzzles about two’s complement and 4 programming puzzles about floating point. See the comments in bits.c for detailed rules and a discussion of the desired coding style. 3 The Puzzles These are used as reference functions to express the correct behavior of your functions, although they don’t satisfy the coding rules for your functions. 3.1 Two’s Complement Arithmetic Your assignment is to complete each function skeleton using only straightline code for the integer puzzles (i.e., no loops or conditionals) and a limited number of C arithmetic and logical operators. Specifically, you are only allowed to use the following eight operators: ! ˜ & ˆ | + > Table 1 describes a set of functions that make use of the two’s complement representation of integers. Again, refer to the comments in bits.c and the reference versions in tests.c for more information. Name Description Rating Max Ops negate(x) Return -x 2 5 isLess(x,n) Returns 1 if x < y, and return 0 otherwise 3 24 Table 1: Arithmetic Functions 3.2 Floating-Point Operations Table 2 describes a set of functions that operate on the bit-level representations of floating-point numbers. Refer to the comments in bits.c and the reference versions in tests.c for more information. Name Description Rating Max Ops float_abs(uf) Compute absolute value of f 2 10 float_twice(uf) Compute 2 * f 4 30 float_i2f(x) Compute (float) x 4 30 float_f2i(uf) Compute (int) ff 4 30 Table 2: Floating-Point Functions. Value f is the floating-point number having the same bit representation as the unsigned integer uf. Functions float_abs and float_twice must handle the full range of possible argument values, including not-a-number (NaN) and infinity. The IEEE standard does not specify precisely how to handle NaN’s, and the IA32 behavior is a bit obscure. We will follow a convention that when of these functions is given a NaN value as ab argument, it will return the same value for the results (Refer to the comments in bits.c). 4 Evaluation Your score will be computed out of a maximum of 19 points. Correctness points. We will evaluate your functions using the btest and dlc program, which is described in the next section. You will get full credit for a problem if it passes all of the tests performed by btest and verified with dlc, and no credit otherwise. Autograding your work We have included some autograding tools in the handout directory — btest, dlc, and driver.pl — to help you check the correctness of your work. • btest: This program checks the functional correctness of the functions in bits.c. To build and use it, type the following two commands: unix> make unix> ./btest Notice that you must rebuild btest each time you modify your bits.c file. You’ll find it helpful to work through the functions one at a time, testing each one as you go. You can use the -f flag to instruct btest to test only a single function: unix> ./btest -f bitAnd You can feed it specific function arguments using the option flags -1, -2, and -3: unix> ./btest -f bitAnd -1 7 -2 0xf Check the file README for documentation on running the btest program. • dlc: This is a modified version of an ANSI C compiler from the MIT CILK group that you can use to check for compliance with the coding rules for each puzzle. The typical usage is: unix> ./dlc bits.c The program runs silently unless it detects a problem, such as an illegal operator, too many operators, or non-straightline code in the integer puzzles. Running with the -e switch: unix> ./dlc -e bits.c causes dlc to print counts of the number of operators used by each function. Type ./dlc -help for a list of command line options. • driver.pl: This is a driver program that uses btest and dlc to compute the correctness and performance points for your solution. It takes no arguments: unix> ./driver.pl 5 Handin Instructions Upload your bits.c file and report in PLMS with the following format: • Rename your bits.c file as: [student id].c (e.g., 20231234.c) • Submit your report with pdf format: [student id].pdf (e.g., 20231234.pdf) Submissions with incorrect format will not be graded, no exception (i.e., you will get 0 points for this entire lab). 6 Tips & Advice • We provide a program fshow that will help you to understand the structure of floating point numbers. To compile fshow, switch to the handout directory and type: unix> make You can use fshow to see what an arbitrary pattern represents as a floating-point number: unix> ./fshow 2080374784 Floating point value 2.658455992e+36 Bit Representation 0x7c000000, sign = 0, exponent = f8, fraction = 000000 Normalized. 1.0000000000 X 2ˆ(121) You can also give fshow hexadecimal and floating point values, and it will decipher their bit structure. • The dlc program enforces a stricter form of C declarations than is the case for C++ or that is enforced by gcc. In particular, any declaration must appear in a block (what you enclose in curly braces) before any statement that is not a declaration. For example, it will complain about the following code: int foo(int x) { int a = x; a *= 3; /* Statement that is not a declaration */ int b = a; /* ERROR: Declaration not allowed here */ }

$25.00 View