1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

HELP with threads and processes

Discussion in 'Meet and Greet' started by alex_d, Feb 2, 2011.

  1. alex_d

    alex_d New Member

    Joined:
    Feb 2, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    Norway
    HEEEELP ME PLEASE, I DON'T KNOW HOW TO DO IT, WHO COULD HELP ME?!?!?!
    THANK YOU!! I REALLY NEED IT, IT MUST BE RUN INTO LINUX!!!



    Concurrent programming using processes and threads
    Objectives:
    The objectives of this project are:
    1. Being Familiar with programming using processes and threads.
    2. Familiar with thread communication mechanisms (shared memory) and processes
    (For files)
    3. Make use of library calls to manage processes and threads.
    4. Compare concurrent programming using threads versus processes.
    Statement:
    Develop a program in C to solve the 8 Queens problem. The problem is
    placing 8 queens on a chessboard without being able to capture each other using the motions
    traditional chess. In other words, look for settings in which the queens
    match on the same diagonal, column or row of the board. There are several solutions to this
    problem depend on the selected initial configuration, ie the selected position
    on the board for the first queen.
    You want to get a solution to this problem concurrently, creating multiple
    processes or threads so that each is responsible for seeking a solution. For this purpose, you must
    implement two versions of the program: reinas_p in which they use processes and reinas_t
    using threads.
    Programs:
    - queens_p [-n <num_trabajadores>] [-i {0 | 1}]
    - queens_t [-n <num_trabajadores>] [-i {0 | 1}]
    where
    Num_workers-n is the number of processes or threads (depending on the version
    run) to carry out the work, the default value is 81.
    -I <0 | 1> is an option to indicate whether workers should print their results after
    to complete its execution. If the option is 0 indicates that the option to print
    1 Note that if a command specifying a parameter appears between the symbols [] indicates that this parameter
    is optional. If you see in {}, are concerned that one must choose between the options presented.
    workers are not enabled. If the option is 1, print the result as workers
    indicated below. The default value is 0.
    Applications will be developed using the schema master / slave. In other words,
    be a process (or thread) that only coordinate the implementation of the task, and a set of processes / threads
    who will perform the processing.
    1. The process / thread teacher should:
    • distribute the work between processes / threads workers, giving each a
    leader board with a queen-up (from this board will start the worker
    placing the other 7 Queens). The initial generation and distribution boards are
    will be as follows:
    Initial board 1: Reina in position (0.0) 1 worker
    Initial Board 2: Queen in position (1.0) the worker 2
    ...
    Initial Board 8: Queen in position (7.0) to work 8
    Initial Panel 9: Queen in position (0.1) to work 9
    ...
    Initial Board 16: Queen in position (7.1) to work 16
    ...
    Initial board i: Reina in place ((i-1) mod8 (i-1) / 8) the worker
    i
    / / To complete the number of workers
    Note that the generation of the initial board shall be by column, starting with
    position (0.0) and following the training ((i-1) mod8 (i-1) / 8), where i is the i-th
    worker (workers are starting to list from 1).
    • while the processes / threads workers perform their calculations, the process / thread
    expected principal;
    • workers once completed, must report how many and which solutions
    several were found, with their respective times (for two equal solutions,
    report less time). The output format is as follows:
    Total No. of different solutions: 2
    Solution 1: (4.0) (2.1) (0.2) (5.3) (7.4) (1.5) (3.6) (6.7)
    Minimum time: 30 msec.
    No. of times found: 2
    Solution 2: (2.0) (5.1) (3.2) (0.3) (7.4) (4.5) (6.6) (1.7)
    Minimum time: 44 msec.
    No. of times found: 1
    Where the pairs (i, j) represent the positions of the 8 queens on the board. Weather
    reported is the least time consuming to find that solution when it was
    found by several workers.
    2. Processes / threads employees must:
    • seek a solution from the leader board. Your job ends when
    get a solution or determine that no solution to the initial board;
    • count the time from work;
    • inform the process / thread main screen and print the result and time
    consumed if the print option is active. Print Example
    screen:
    Results of the thread 1:
    Solution: Not Found
    Time: 20 ms.
    Initial board: (1.0)
    Results of the thread 2:
    Solution: (2.0) (5.1) (3.2) (0.3) (7.4) (4.5) (6.6) (1.7)
    Time: 20 ms.
    Initial board: (2.0)
    For the version with processes, workers must pass the necessary information
    Home page through a text file that will create when his work. The
    that each worker generates file should be named TI_i_j (Initial Board ij, where (i, j)
    represents the position of the first queen).
    For its part, the wireless version will use shared variables to transmit
    Main information workers.
    Important notes:
    1. If programs do not compile or not is not BE
    CORRECTED. Programs must be compiled and run on any
    stations (Linux) of the LDC. If you completed the program at home or USB, but some
    other hardware-software platform, you must ensure before the project delivery
    Linux works at stations above.
    2. Use the POSIX library calls for the establishment and operations on the strings
    3. For version reinas_p to use fork and exec calls
    4. Should not neglect the use of memory.
    5. Must conform to the output formats, but can complement it with graphics
    6. Should make use of the makefile, if not given a Makefile, be deemed to
    project can not be compiled.
    7. They should make a modular and clear. Remember to use libraries and headers files (. H).
    8. You can use the following routine to define the function that invoked the threads (reinas_t) and
    executable process child processes invoked through exec (reinas_p).
    This algorithm is in the book of Niklaus Wirth (Algorithms + Data Structures = Programs.)
    Must adapt to your project because you get all possible solutions. Note that it is not
    written in C.
    # Define FALSE 0
    # Define TRUE 1
    int a [1 .. 8] / / a = TRUE indicates that there is a queen in the i-th column
    int b [2 .. 16] / / b = TRUE indicates that there is a queen in the i-th
    / / Diagonal from the upper right
    / / To the lower left
    int c [-7 .. 7] / / c = TRUE indicates that there is a queen in the i-th
    / / Diagonal from the left end
    / / Top to the bottom right
    int x [1 .. 8] / / indicates the position of the queen in the ith column
    void try (int i)
    begin
    int j
    for (j = 1 to 8)
    if (a [j] and b [i + j] and c [i, j]) then
    begin
    x = j
    a [j] = FALSE
    b [i + j] = FALSE
    c [i, j] = FALSE
    if (i <8) Then try (i +1) else print result
    a [j] = TRUE
    b [i + j] = TRUE
    c [i, j] = TRUE
    end
    end
    main ()
    begin
    for (i = 1 to 8) a = TRUE
    for (i = 2 to 16) b = TRUE
    for 9i =- 7 to 7) c = TRUE
    try (1)
    end :crazy:
     

Share This Page