UW Logo

CS 343 Concurrent and Parallel Programming

Answers to FAQ for CS343

The purpose of this material is to provide students with, or remind them of, the answers to Frequently-Asked Questions (FAQ) about course-related information, for example:

Do I need to read the whole FAQ?

Indeed not! Material in the FAQ is not part of the material for the course. However, in the interest of reducing question fatigue for the instructor and instructional coordinator, you should always look in the FAQ first for a possible answer to your question.

The course newsgroup Piazza cs343 is another source of information.

NOTE: Information of particular importance is preceded by "NOTE:".

Please send any corrections or suggestions to cs343@student.cs.


Course Software (Courseware) and other Resources

  1. What compiler is used to complete assignments?
  2. Is there a PC version of μC++ for WINDOWS?
  3. Is there a PC version of μC++ for OS X?
  4. Is there a PC version of μC++ for Linux?
  5. How to submit assignments?
  6. How to check assignment submissions?
  7. How to check number of lates?
  8. How to use make?
  9. How to test if a makefile is set up correctly?
  10. How to recover a file deleted or changed by accident?
  11. What to do with old files?
  12. How to keep files and reduce disk space?
  13. How to get account information, like disk quota?
  14. How to record shell output for assignments?
  15. How to use the course newsgroup?
  16. How to get UNIX help?
  17. Can you recommend a good C++ text book?

Assignment Submission and Marking Policies

  1. What is the course late policy for assignments?
  2. How do I get an assignment or test remarked?
  3. May I use feature/technique X on the assignment?
  4. Can I change the interface for this routine/class/module?
  5. How do I share files when working in a group?

Problems or Errors with Courseware and Assignments

  1. How to report errors or things that do not work properly?
  2. Which include files do I have to use?
  3. How do I do stream I/O in C++?
  4. Which random number generator should I use?
  5. How do I dynamically create a matrix in C++?
  6. Can I perform delete this in an object's member routine?
  7. How do I use the string class in C++?
  8. How do I convert an integer to a string in C++?
  9. Why does itoa not work for integer-to-string conversions?
  10. Why are floating point numbers not being saved in μC++?
  11. What does this C++ warning / error mean?
  12. What does this μC++ warning / error mean?
  13. How do I use gdb with μC++?


Course Software (Courseware) and other Resources

Various software, on-line documents, and services are provided to students to facilitate working on assignments. This section briefly summarizes these resources by answering the following questions:

  1. What compiler is used to complete assignments?

    The GNU C++ compiler g++, and the μC++ translator u++ are provided in the undergraduate environment for compiling assignments. See man gcc or the C++ Tutorial for more details on g++. See man u++ or the μC++ Annotated Reference Manual for more details on u++.

  2. Is there a PC version of μC++ for WINDOWS?

    There is no port of μC++ to WINDOWS.

  3. Is there a PC version of μC++ for OS X?

    There is no port of μC++ to OS X.

  4. Is there a Linux version of μC++?

    There is a port of μC++ to Linux.

  5. How to submit assignments?

    The submit command is provided to electronically submit assignments. See man submit for more information. For example, to submit files in directory a1 for assignment 1 enter:

        % submit cs343 1 a1
    

    which produces important messages describing its activities. Make sure you read these messages!

    NOTE: submit for CS343 completely replaces your submission every time you use it, and all *txt files greater than 250 lines in length are rejected. submit tells you about both of these actions in its output messages.

    If you accidentally submit an incorrect file or multiple versions of a file, please remove it using the -delete option of submit.

  6. How to check assignment submissions?

    To check on a previous submission enter:

        % submit cs343 1 -list
    

    which produces a listing of files previously submitted in a format similar to ls -l for the specified assignment.

    NOTE: try the -list option before deciding submit has not worked properly. It is your responsibility to make sure all of your files have been submitted.

    Alternatively, this link gives a list of the files expected by submit in one column of a table, and gives a list of the files copied by submit to our handin directory in the other column, so you can compare what is submitted against what is expected.

  7. How to check number of lates?

    This link gives you a means of checking the number of lates you have left.

  8. How to use make?

    This link gives you basic information on make files, including some sample makefiles.

  9. How to test if a makefile is set up correctly?

    This link gives you a means of checking that you are using the correct version of make, that your makefile has been set up correctly, and that your submitted code compiles into the requested executable names.

  10. How to recover a file deleted or changed by accident?

    In general, there is no way to do this. Once a file has been deleted (usually with rm) or altered and saved, the previous version is gone. However, you can attempt to deal with these accidents in two ways: recover an older version of the file from backup storage or prevent the accident in the first place.

    See MFCF's restore FAQ for detailed information on retrieving a backed up file.

    You can attempt to prevent accidental file changes by using the -i option of rm when deleting files (i.e., rm -i <files>), or by making backup copies of your files before editing them (e.g., cp <file> <file>.1), or by archiving old copies of your files.

  11. What to do with old files?

    Delete them! Do not leave junk lying around. If you want or need to keep some of your old files, read about keeping files.

  12. How to keep files and reduce disk space?

    If you want to keep a file or a directory containing a group of files for later reuse, then consider compressing it. A compressed file or directory contains the original file's or directory's contents in an encoded form that occupies less disk space. See MFCF's compress FAQ for detailed information on compressing a file or a directory of files.

  13. How to get account information, like disk quota?

    The amount of disk memory a user is permitted to occupy is called the disk quota. See MFCF's quota FAQ for detailed information on displaying quota information.

  14. How to record shell output for assignments?

    The UNIX commands script and scriptfix are available to make a record of shell activity. The script program, once invoked, copies all the activity of a shell session into a file, which is handy for recording a sequence of commands and their results for later inspection. Therefore, the script command lends itself to debugging, testing, and reporting errors. A typical use of script is given here:

        % script foo
    

    which makes a copy of all future shell activity in file foo. The exit command is used to end the script session.

    Since script records control characters (such as backspace) in their raw form, it is important to use the scriptfix command to make the file foo clean and legible. The scriptfix program cleans up extraneous characters from a script file so it is readable. A typical use of scriptfix is given here:

        % scriptfix foo > bar
    

    which cleans the script file foo and redirects the result into the file bar. The scriptfix command should always be run on script files that are submitted for assignments.

    NOTE: scriptfix does not remove DOS newlines. In order to remove these, use the dos2unix utility.

  15. How to use the course newsgroup?

    The newsgroup Piazza cs343 is for the posting of information and questions relevant to the material covered in the course and for discussion of assignments. Generally, appropriate postings include informational messages from course staff, and error reports or information requests from students.

    Other postings related to course material are also acceptable, but general discussions or personal requests should be carried on in other newsgroups, by email, or in person. A good rule of thumb is to make course material (e.g., assignments, class notes, etc.) the subject of your postings, rather than your own solutions or suggestions.

    NOTE: students are expected to read the newsgroup regularly (usually every day) to stay current on any course-related developments. Doing so is solely the student's responsibility.

    NOTE: there is an unfortunate tendency of newsgroup postings (and email messages) to become judgemental or to be interpreted uncharitably. This situation can result in so-called `flame wars' and unnecessarily aggressive posturing. Flaming is not tolerated in a course newsgroup! The most reasonable way to avoid this problem is to exercise patience when posting. "Is this posting really necessary?", "Is my phrasing clear and appropriate?", and "Would direct email be better than a public newsgroup?" are always good questions to ask yourself when regarding a potential posting. Finally, always read your posting twice before sending it.

  16. How to get UNIX help?

    Normally, a good way to get help on some aspect of the UNIX operating system and shell commands is to read the man page for the particular feature or command. Manual pages related to a certain topic can be searched for with the -k option of man (see man man for details).

    Also, MFCF has consultants in MC 3011 who can answer general questions and provide information about using UNIX in the undergraduate environment. You can also email them questions at consultant@math. See The Math Faculty Computing Facility for more details.

    NOTE: the consultants are NOT there to do your assignment for you!

  17. Can you recommend a good C++ text book?

    There is no single book that suits everyone's taste; it dependents on how you learn. For example, some people learn best with books that have lots of examples and explanations; others want only a reference book with just the facts and details. The point is that you must select a book that works for you. It is virtually impossible for someone else to do it.

    You may also want to consider the text books recommended in CS 246.



Assignment Submission and Marking Policies

This section briefly outlines the policies for the CS343 course regarding submissions and remarking of submissions.

  1. What is the course late policy for assignments?

    Assignments are usually considered due at 6pm on the date listed on the assignment itself. Assignments may usually be handed in late up to N days after they are due, where N is course dependent. For N = 2, an assignment due on a Tuesday, has a late date on Thursday. Should the late date be a University holiday, the late date is pushed to the next day the University is open. Assignments may not be due after the last day of lectures, so if an assignment due-date falls on the last day of lectures, there can be no corresponding late date.

    A student may submit up to M assignments late without penalty, where M is course dependent; any further late submissions are not accepted and a grade of 0 is assigned for that assignment. The submit command is configured to automatically enforce this policy. Requests for extensions may be granted provided there is good reason for the student not being able to complete the assignment on time (e.g., a note from a doctor). Extensions are rare.

    NOTE: Instructions given with any assignment always take precedence over these rules, so be sure to check the assignment statement carefully. It is solely the student's responsibility to comply with the requirements of any assignment.

  2. How do I get an assignment or exam remarked?

    Assignment

    Each marker puts their initials at the top of the marking sheet. If you have a question about your marks for an assignment, see the marker during their office hour. The office hours are posted on the CS343 people page after the first assignment.

    A student may request the remarking of an assignment up to 2 weeks after that assignment has been returned. A request for remarking must be made to the original marker and must include all the material returned to the student. This includes simple addition errors. The marker may also request a separate sheet, written by the student, that explains what is to be remarked and why. The marker then reports any change of grade to the course tutor or Instructional Support Coordinator.

    Midterm Exam

    The policy regarding midterm remarking is announced after the midterm is returned, and is similar to the assignment remarking.

    Final Exam

    If you are unhappy with your final grade because your final-exam mark is lower than you expected, you must file a formal grade appeal to have your final exam remarked. You do this by going to the Math Undergrad Office and filling out a grade-appeal form.

  3. May I use feature/technique X on the assignment?

    Never assume you can use a feature/technique in an assignment unless it has been discussed in class. In general, an assignment is a mechanism to practise some concept/idea/approach presented in class. Therefore, it is the purpose of the solution for an assignment to reflect this concept/idea/approach. Features/techniques discussed in class or explicitly specified in the assignment are usually the ones you are suppose to use. Solving the assignment using some other feature/technique does not provide the desired practise, even if the solution might be easier using the other feature/technique.

    However, in many cases an assignment may involve the use of many features/techniques, some of which are crucial and some not. Therefore, it never hurts to ask the assignment coordinator, if a particular feature/technique is allowed. It is always better to ask, and ask early, so you do not have to redo parts of your assignment or are surprised at your assignment mark when it is returned.

  4. Can I change the interface for this routine/class/module?

    NO! Interfaces provide the plugs that allow connecting parts of a program together. When you are given an interface you must respect it or other programs cannot plug into the service it provides. It does not matter that you are writing all the components of the program in an assignment, and hence, control all the interfaces. You must learn to develop programs from specifications, which often include specific interfaces. Hence, you can ask about altering an interface, but 99% of the time the answer will be NO.

  5. How do I share files when working in a group?

    Working in a group usually requires sharing access to files. Sharing files must not involve sharing account passwords or making files readable/writable by everyone. The proper way to share files for course-group access is to create a UNIX file-group, in which all userids for group members are listed. Then the UNIX file-group and file-group permissions (read/write) are added to each shared file, allowing only those userids associated with the file-group to access the files.

    A UNIX file-group can only be created indirectly through a request to the course Instructional Support Coordinator (ISC). MFCF does not create arbitrary UNIX file-groups for students. As well, funneling the requests through the ISC allows requests to be batched together so MFCF can create the UNIX file-groups for an entire course in a single operation.

    After MFCF has created the groups, the ISC emails the UNIX group-name to the requester. A group-name is usually of the form cs343_NN where NN is a number. See man -s i groups for further information on how to associate a UNIX group-name with a file so it can be shared among users (you will need to logout and back in again for the changes to your .cshrc file to take effect). NOTE: a shared file occupies space in only one account; other members of the group can create symbolic links (see man ln) to facilitate easy access to the shared file.



Problems or Errors with Courseware and Assignments

Problems with software for the course can and do occur. Also, problems occur when you are building software for your assignments. This section briefly summarizes some of these problems.

  1. How to report errors or things that do not work properly?

    The proper reporting of potential software errors is important in solving problems and keeping the course progressing smoothly. Vague or incomplete error reports may simply frustrate both reporter and fixer. Please follow these general steps when reporting an error (whether electronically or in person):

  2. Which include files do I have to use?

    See Headers. Notice, the standard assumes include files without ".h" as suffix.

  3. Which random number generator should I use?

    Routines rand and random are not thread-safe, and hence, are not safe to use in μC++. However, both often work fine in simple assignment programs. To be correct, use rand_r to generate random values, e.g.:

    unsigned int seed = getpid(); // initialize to some random starting value
    rand_r( &seed ); // pass the address of the seed, which is modified
    

    Note, each task must have its own variable seed rather than share the same variable or rand_r becomes thread unsafe.

  4. How do I do stream I/O in C++?

    There are example programs in the examples directory illustrating stream I/O in C++.

  5. How do I dynamically create a matrix in C++?

    See the C++ Tutorial for examples of creating and manipulating a matrix in C++.

  6. Can I perform delete this in an object's member routine?

    An object can commit suicide, i.e., it can "delete this", but it is a fragile operation: (from http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.14)

    [16.14] Is it legal (and moral) for a member function to say delete this?

    As long as you're careful, it's OK for an object to commit suicide (i.e., delete this).

    Here's how I define "careful":

    1. You must be absolutely 100% positive sure that this object was allocated via new (not by new[], nor by placement new, nor a local object on the stack, nor a global, nor a member of another object; but by plain ordinary new).
    2. You must be absolutely 100% positive sure that your member function will be the last member function invoked on this object.
    3. You must be absolutely 100% positive sure that the rest of your member function (after the delete this line) doesn't touch any piece of this object (including calling any other member functions or touching any data members).
    4. You must be absolutely 100% positive sure that no one even touches the this pointer after the delete this line. In other words, you must not examine it, compare it with another pointer, compare it with NULL, print it, cast it, do anything with it.

    Naturally the usual caveats apply in cases where your this pointer is a pointer to a base class when you don't have a virtual destructor.

    So yes it can be done, but it should only be done in special circumstances. Now the reason this works for objects is because the stack maintaining the routine calls is independent from the object allocation in the heap storage. Thus, it is possible to return from the object's member using the data on the stack even though the data for the object no longer exists.

    HOWEVER, this last point is not true for a coroutine or task object because it has its own stack. Hence, delete this executed by a routine call on the coroutine/task stack fails because it causes both the object and stack to vanish, so the routine cannot continue execution on the deleted stack. Hence, the following axiom is true "you can commit suicide but not bury yourself". For an object with its own execution stack, it is always necessary to delete this kind of object on a stack different from the one that is being deleted.

  7. How do I use the string class in C++?

    There are example programs in the examples directory illustrating the use of the string class in C++.

  8. How do I convert an integer to a string in C++?

    Unfortunately, the string type does not provide either an implicit or explicit conversion to integer, and therefore you have to write your own, e.g.:

    #include <sstream>
    #include <string>
    
    std::string itostring( long int i ) {
        std::stringstream ss;
        ss << i;
        return ss.str();
    }
    
    While converting from internal representation to a string is sometimes necessary, it should never be done to imitate Java style I/O in C++. For example, never do this:
        cout << "i = " + itostring( i ) + " j = " + itostring( 5 ) + "\n";
    
    instead do this:
        cout << "i = " << i << " j = " << j << endl;
    
  9. Why does itoa not work for integer-to-string conversions?

    itoa is not part of the ANSI C standard library. It is only implemented in some compilers. So, try something else, like stringstream, or sprintf.

  10. Why are floating point numbers not being saved in μC++?

    Floating-point registers are not saved by default during a context switch to reduce execution cost, particularly because most programs do not perform floating-point calculations. Therefore, each task using floating point has to explicitly indicate that the floating-point registers must be saved (see the μC++ Reference Manual on "User Specified Contexts" for details).

    One exception is the SUN/SPARC architecture, which implicitly saves both the integer and floating point registers when a context switch occurs, but it is an anomaly among architectures. If you are running μC++ on a PCs or a non-SUN undergraduate machine, you have to explicitly indicate that the floating registers need to be saved for each task.

  11. What does this C++ warning / error mean?

    The following is a list of some often-encountered warning/error-messages for C/C++ and the problems they typically indicate. Undoubtedly, not all the interesting ones are accounted for yet, so please feel free to request that other error messages be included here.

    Compile-time Warning

    Compile-time Errors

    Runtime Errors

  12. What does this μC++ warning / error mean?

    The following is a list of some often-encountered warning/error-messages for μC++ and the problems they typically indicate. These errors are generated by the μC++ translator not by the underlying C++ compiler. Undoubtedly, not all the interesting ones are accounted for yet, so please feel free to request that other error messages be included here.

    Compile-time Warning

    Compile-time Errors

    Runtime Warnings

    Runtime Errors

  13. How do I use gdb with μC++?

    The symbolic debugging tools (e.g., dbx, gdb) do not work perfectly with μC++, because each coroutine and task has its own stack, and the debugger does not know about these stacks. When a program terminates with an error, only the stack of the coroutine or task in execution at the time of the error is understood by the debugger. During execution, the debugger cannot step through a context switch for either a coroutine or task. Therefore, it is necessary to put break points after the suspend/resume or signal/wait to acquire control, and just continue execution through the context switch. Once the breakpoint is reached, it is possible to next/step through the lines of the coroutine/task until the next context switch. For debuggers that handle multiple kernel threads (corresponding to μC++ virtual processors), it is possible to examine the active task running on each kernel thread.

    (gdb) info threads	# list all kernel threads
    (gdb) thread 2		# switch to kernel thread 2
    

    Finally, it is necessary to tell the debugger that μC++ is handling UNIX signals SIGALRM and SIGUSR1 to perform pre-emptive scheduling. For gdb, the following debugger commands allows the application program to handle signal SIGALRM and SIGUSR1:

    (gdb) handle SIGALRM nostop noprint pass ignore
    (gdb) handle SIGUSR1 nostop noprint pass ignore
    

Valid XHTML 1.0 Strict