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.
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.
What kind of simulator are you talking about? There are many kinds of simulators. Flight simulators, process simulators, hardware simulators etc.
Hi
I try to write hardware simulator, but also would like to have more knowledge about process simulator. Thanks!
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.
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.
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.
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.
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:
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.Code:struct time_table_element { int process_id; struct time start_time; struct time stop_time; struct time_table_element *next; };
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:
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.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];
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.
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!
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.
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!
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
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.
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.
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!