Software Simulatior

This is a discussion on Software Simulatior within the C Programming forums, part of the General Programming Boards category; Hello Everyone, Are there anyone knows how to write a simulator? Please help me! I need to write a simulator ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    54

    Software Simulatior

    Hello Everyone,

    Are there anyone knows how to write a simulator? Please help me! I need to write a simulator and I would like to get any advice from everyone. Thanks in advance.

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    What kind of simulator are you talking about? There are many kinds of simulators. Flight simulators, process simulators, hardware simulators etc.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    54
    Hi

    I try to write hardware simulator, but also would like to have more knowledge about process simulator. Thanks!

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    And what kind of hardware do you want to simulate?

    A process simulator is a simulator which simulates for example a physical process. A physical process can often be described using differential equations. Such a process can be a simple electrical network, such a network can be described with equations. The equations can be numerically solved by a computer, this is also called simulation. You can create an input, consisting of a long row of numbers or a generating formula, which you use as input for the network and let the computer calculate the output. Another example, from biology, is simulating growth of a population using the model of Verhulst. Anyway, for process simulation you need to know about the process you're going to simulate and the mathematics which is required to model such a process and implement it in software.

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    54
    Hello Shiro,

    Now, I have a little idea about simulator. I think my project belongs to process simulator. For example, I have 3 processes running constanly and have 3 different durations and number times each process runs. My job is trying to keep track of the system time when these processes are running. If you have more advices for me, I really appreciate a lot. Thank you very much for your info.

  6. #6
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Hmmm, I still do not really understand what you are simulating. But I'm beginning to understand what your question is.

    You have a number of processes running (semi-)parallel on your computer. And you want to keep track of how long each process runs? What do you exactly want to measure? I mean, a scenario is that you start the system and at the end, you have some variables which show how much time each process has run.

    Or do you mean that each time a process starts running, you want to store the system time so that at the end you have a time table which tells when which process has started and finished?

    Like:

    00:00:02 process A start
    00:00:08 process A stop
    00:00:10 process B start
    00:00:16 process B stop
    00:00:20 process C start
    00:00:26 process C stop
    00:00:29 process A start
    00:00:34 process A stop
    etc.

    Note that this has little to do with simulation.

  7. #7
    Registered User
    Join Date
    Mar 2002
    Posts
    54
    Hi Shiro,

    Sorry for confusing you!

    >>You have a number of processes running (semi-)parallel on your computer. And you want to keep track of how long each process runs? What do you exactly want to measure? I mean, a scenario is that you start the system and at the end, you have some variables which show how much time each process has run.

    Yes, this is what I want to simulate. Would you please tell me a little more about this? Thanks!

    P.S. all the processes are running parallel
    Last edited by vnrabbit; 06-20-2002 at 01:47 PM.

  8. #8
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    You should define a global datastructure which will be accessed by the processes. When a process starts, it must update the datastructure and when it finishes it must update the datastructure. The datastructure could be a linked list which elements look like this:

    Code:
    struct time_table_element
    {
        int process_id;
        struct time start_time;
        struct time stop_time;
        struct time_table_element *next;
    };
    To make difference between the processes, each proces should have an unique ID. When a process starts, it puts its ID in the process_id and the current system time in start_time. When it finishes, it current system time in stop_time.

    I assume you are writing a scheduler which takes care of the round-robin algorithm you seem to use. This scheduler should also extend the time-table with a new element. This does take time, perhaps easier would be to implement a fixed time-table, like:

    Code:
    struct time_table_element
    {
        int process_id;
        struct time start_time;
        struct time stop_time;
    };
    
    struct time_table_element time_table [NR_OF_ELEMENTS];
    This requires you to have another global variable for keeping the index. The scheduler should update the index by increasing it by one each time a new process is starting. It should also check that no more elements can be stored than the maximum.

    BTW, what OS are you using?

    [edit]
    Since the processes are running parallel, you must make sure that no two processes can access the global data for writing at same time. To solve this you could implement a semaphore mechanism.

    Note that the time-table now can look like:

    00:00:02 process A start
    00:00:08 process B start
    00:00:10 process B stop
    00:00:16 process C start
    00:00:20 process A stop
    00:00:26 process C stop

    And you problably don't implement the scheduler,don't you? So your processes need to update the datastructure.
    [/edit]
    Last edited by Shiro; 06-20-2002 at 01:59 PM.

  9. #9
    Registered User
    Join Date
    Mar 2002
    Posts
    54
    I'm going to use Linux. According to you, should I use FCFS, Shortest-Job-First, or Round-Robin? Which one is the best in my case? Thanks a lot!

  10. #10
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    That depends on the purpose of your simulation. You could write trhee schedulers which support FCFS, SJF and RR and test them to see which algorithm fits your needs.

  11. #11
    Registered User
    Join Date
    Mar 2002
    Posts
    54
    Shiro,

    >And you problably don't implement the scheduler,don't you? So your processes need to update the datastructure

    Sorry, I'm not quite sure about your question. Would you please explain a little more?
    If I have 3 processes runing parallel, do I need to have 3
    struct time-table-element? Thank you!

  12. #12
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    You're probably using one microprocessor, this means that you're processes are not running parallel, they are running semi-parallel. If they were running parallel, then at same time instructions could be executed. But if you're using one microprocessor then you can only let the processes run semi-parallel. This means that the micprocessor switches between the processes.

    The mechamism which controls this switching is the scheduler. Modern operating systems usually have a scheduler, so you don't need to write one. But ofcourse you can, if you want to control your processes. But I'm not sure if that is really save, since your scheduler is also a process, which would then be controlled by the scheduler of the OS.

    >If I have 3 processes runing parallel, do I need to have 3
    >struct time-table-element?

    That depends on what information you want to store. If you want to store a table like I showed, than you need a list of struct time-table-element. This can be a fixed list (for example array of structs) or a dynamic list (for example linked-list). You don't need three of them, since you can store the process ID in the structure

  13. #13
    Registered User
    Join Date
    Mar 2002
    Posts
    54
    Yes, my processes are running semi-parallel.
    My software will simulates code execution on a microprocessor. So, it will give an estimate timing that the microprocessor need to run 3 processes with their maxima occurenness. My job would be writing a scheduler.

  14. #14
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    You don't need to write the processes? If your job is only writing a scheduler, then the scheduler should do the administration, since you don't have influence on the processes then. It should fill the time-table with the information.

  15. #15
    Registered User
    Join Date
    Mar 2002
    Posts
    54
    Sorry, I'm get confused now. I'm too stupid to get what you are saying. If you don't have time to answer my question, it's o.k.. I really appreciate what you have told me already. If you have time, please explain a little more the different between writing a scheduler and writing the scheduler and processes! Thanks a lot!

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Software Design/Test - Redmond, WA
    By IRVolt in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 06-11-2008, 10:26 AM
  2. Why C Matters
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 136
    Last Post: 01-16-2008, 08:09 AM
  3. Adding trial period to software
    By BobS0327 in forum C Programming
    Replies: 17
    Last Post: 01-03-2006, 01:13 PM
  4. software licences
    By trekker in forum Tech Board
    Replies: 3
    Last Post: 06-17-2003, 08:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21