Jump to content

How do I write a simple code in C++ for SJF scheduling (preemptive) With Gannt Chart?

Nagisa Shiota

Hii Iam not that good at c++ Programming yet Can i ask for a solution on this problem thanks !

Link to comment
Share on other sites

Link to post
Share on other sites

The standard template library already includes a priority queue, no reason to write it yourself

Desktop: Intel i9-10850K (R9 3900X died 😢 )| MSI Z490 Tomahawk | RTX 2080 (borrowed from work) - MSI GTX 1080 | 64GB 3600MHz CL16 memory | Corsair H100i (NF-F12 fans) | Samsung 970 EVO 512GB | Intel 665p 2TB | Samsung 830 256GB| 3TB HDD | Corsair 450D | Corsair RM550x | MG279Q

Laptop: Surface Pro 7 (i5, 16GB RAM, 256GB SSD)

Console: PlayStation 4 Pro

Link to comment
Share on other sites

Link to post
Share on other sites

Wait what is that ? mathijs727 Iam dunno what is that iam soo sorry about that ! Pls help me or elaborate it for me thanks soo much !

Link to comment
Share on other sites

Link to post
Share on other sites

6 hours ago, Nagisa Shiota said:

Wait what is that ? mathijs727 Iam dunno what is that iam soo sorry about that ! Pls help me or elaborate it for me thanks soo much !

I think the first paragraph of the wiki page describes a priority queue well:

https://en.wikipedia.org/wiki/Priority_queue

 

The standard template library is just a library of usefull data structures and platform abstractions that is available in every C++ compiler.

Desktop: Intel i9-10850K (R9 3900X died 😢 )| MSI Z490 Tomahawk | RTX 2080 (borrowed from work) - MSI GTX 1080 | 64GB 3600MHz CL16 memory | Corsair H100i (NF-F12 fans) | Samsung 970 EVO 512GB | Intel 665p 2TB | Samsung 830 256GB| 3TB HDD | Corsair 450D | Corsair RM550x | MG279Q

Laptop: Surface Pro 7 (i5, 16GB RAM, 256GB SSD)

Console: PlayStation 4 Pro

Link to comment
Share on other sites

Link to post
Share on other sites

On September 22, 2559 BE at 11:59 PM, Yamoto42 said:

I won't give you an answer, per se, but I will point you in the right direction.

 

https://en.wikipedia.org/wiki/Priority_queue

 

You can easily implement one using an std::multimap.

 

http://www.cplusplus.com/reference/map/multimap/

You're going to take the performance hit of a multimap when doing a scheduler? Come on...

 

And if you're about to ask "what perf penalty," Andrei Alexandrescu has a sentence for you: "because at the bottom, it's the damn doubly linked list!"

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to comment
Share on other sites

Link to post
Share on other sites

@patrickjp93

No, I am not going to ask "what performance penalty" when someone who is, and I quote, "not that good at c++ Programming yet," asks how to implement a scheduler. Mind you, he never said what the purpose of said scheduler was, therefore we have absolutely no implied constraints.

 

I am, however, going to ask what value you are contributing to the discussion.  Perhaps you could educate him on how to program an RB Tree?  Or if you really want to get academic we could discuss how true SJF requires us to solve the halting problem, because quite frankly that would be a more education than discussing whether said RB Trees (which at least in GCC are used to implement both map and multimap) are O(n) vs O(log(n)).

Link to comment
Share on other sites

Link to post
Share on other sites

27 minutes ago, Yamoto42 said:

@patrickjp93

No, I am not going to ask "what performance penalty" when someone who is, and I quote, "not that good at c++ Programming yet," asks how to implement a scheduler. Mind you, he never said what the purpose of said scheduler was, therefore we have absolutely no implied constraints.

 

I am, however, going to ask what value you are contributing to the discussion.  Perhaps you could educate him on how to program an RB Tree?  Or if you really want to get academic we could discuss how true SJF requires us to solve the halting problem, because quite frankly that would be a more education than discussing whether said RB Trees (which at least in GCC are used to implement both map and multimap) are O(n) vs O(log(n)).

A scheduler is still easier to implement with a vector imho.

 

And no, beneath the RB tree is just a DLL. If you don't want to take my word for it, I can go hunting for Alexandrescu's lecture on it.

 

Every data structure in the STL can be done with minimal modification to interacting with a vector and perform better thanks to not chasing pointers. This is a case the C++ standard actually gets in the way.

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to comment
Share on other sites

Link to post
Share on other sites

I'll just quote the GCC documentation https://gcc.gnu.org/onlinedocs/gcc-4.6.2/libstdc++/api/a00616.html

 

Quote

The private tree data is declared exactly the same way for map and multimap; the distinction is made entirely in how the tree functions are called (*_unique versus *_equal, same as the standard).

I will ask again, however, what value you have put forward towards answering the OP's question as opposed to simply criticizing me and my apparent lack of literacy.

And this will be my final response to you.

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Yamoto42 said:

I'll just quote the GCC documentation https://gcc.gnu.org/onlinedocs/gcc-4.6.2/libstdc++/api/a00616.html

 

I will ask again, however, what value you have put forward towards answering the OP's question as opposed to simply criticizing me and my apparent lack of literacy.

And this will be my final response to you.

Read all the way you ditz. The RB tree is backed by a DLL. Andrei Alexandrescu: code::dive writing fast code I and II. I think Facebook's second in command performance engineer knows GCC better than you since it is the only C++ compiler Facebook uses.

 

Also, because teaching poor programming habits up front just produces bad programmers. Just because something is easy does not mean it's right. Now, the C++ Standards Comittee is doing a lot of work to make easy be right and make a little work optimal, but the STL is not where that work is focused right now.

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×