Coding Challenge 4!

The Partridge Family were neither partridges nor a family. Discuss.
AverageWhale
Posts: 57
Joined: August 13th, 2018, 2:33 pm

Re: Coding Challenge 4!

Post by AverageWhale » September 27th, 2018, 9:31 am

i have a question about saving difference between 2 values in a tmp or just use subtracting everytime we need difference. so i have a question which one is the fastest

Code: Select all

//1 i think this is the fastest
int difference = -1;
				if (input[j] > input[i])
				{
					difference = input[j] - input[i];
				
					if (difference > max_difference)
						max_difference = difference;
				}
//2
				if (input[j] > input[i])
					if (input[j] - input[i] > max_difference)
						max_difference = input[j] - input[i];;
//3
				if (input[j] - input[i] > max_difference)
					max_difference = input[j] - input[i];
//4 i think this is fast too
				int difference = input[j] - input[i];
				if (difference > max_difference)
					max_difference = difference;
Last edited by AverageWhale on September 27th, 2018, 9:37 am, edited 1 time in total.

AverageWhale
Posts: 57
Joined: August 13th, 2018, 2:33 pm

Re: Coding Challenge 4!

Post by AverageWhale » September 27th, 2018, 9:32 am

albinopapa wrote:I can try it if you'd like. Are you just wanting to check the time on someone else's machine?
i will pm u my solution

thesmallcreeper
Posts: 14
Joined: September 24th, 2018, 1:20 pm

Re: Coding Challenge 4!

Post by thesmallcreeper » September 27th, 2018, 9:36 am

Well... I used a "magic number" to overcome that problem. fun fact AVX-512 could do the trick for us but it is very fresh instruction set.

idk averagewhale.btw I would also like to learn the threads count sweatspot for my multithreading version on some other processors :)

thesmallcreeper
Posts: 14
Joined: September 24th, 2018, 1:20 pm

Re: Coding Challenge 4!

Post by thesmallcreeper » September 27th, 2018, 9:47 am

Albinopapa, how the fack did you managed to avoid std::async thread creation latency dude? I get hit when std::asych threadpool has not enough threads and has to create new ones ://

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Coding Challenge 4!

Post by albinopapa » September 27th, 2018, 9:51 am

Not sure, I only call on 8 threads, surely that doesn't weigh down the system. The test happens so fast, Task Manager doesn't even pick it up. Does your system have SMT ( AMD Ryzen ) or HyperThreading (Intel, don't remember when they started...Ivy Bridge maybe?)
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Coding Challenge 4!

Post by albinopapa » September 27th, 2018, 9:52 am

I've tried in the past to call 32 threads on async and got a crash, it's been so long so can't remember why the crash.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

thesmallcreeper
Posts: 14
Joined: September 24th, 2018, 1:20 pm

Re: Coding Challenge 4!

Post by thesmallcreeper » September 27th, 2018, 9:59 am

No it doesnt. I use a Piledriver over here :p

In my case every time program creates a new thread for std::async I get a 0.7ms hit :/
On my code I just emplace_back std::async calls to a std::future vector

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Coding Challenge 4!

Post by chili » September 27th, 2018, 11:16 am

Pretty fast times papa, should stack up well to what I've got.
Chili

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Coding Challenge 4!

Post by albinopapa » September 27th, 2018, 2:36 pm

thesmallcreeper wrote:No it doesnt. I use a Piledriver over here :p

In my case every time program creates a new thread for std::async I get a 0.7ms hit :/
On my code I just emplace_back std::async calls to a std::future vector
I didn't use emplace_back(), I presized the vector and just looped over the new elements.

Code: Select all

std::vector<std::future<std::pair<sse, sse>>> futures( 8 );

const int workload = int( input.size() );
const int job_size = ( workload / 8 ) & ~7;
std::pair<int, int>job_sizes[ 8 ] =
{
	{0 * job_size,( ( 0 * job_size ) + job_size ) },
	{1 * job_size,( ( 1 * job_size ) + job_size ) },
	{2 * job_size,( ( 2 * job_size ) + job_size ) },
	{3 * job_size,( ( 3 * job_size ) + job_size ) },
	{4 * job_size,( ( 4 * job_size ) + job_size ) },
	{5 * job_size,( ( 5 * job_size ) + job_size ) },
	{6 * job_size,( ( 6 * job_size ) + job_size ) },
	{7 * job_size,( ( 7 * job_size ) + job_size ) }
};
			
for( int i = 0; i < 8; ++i )
{
	const sse* beg_iter =
		reinterpret_cast< const sse* >( &input[ 0 ] + job_sizes[ i ].first);
	const sse* end_iter =
		reinterpret_cast< const sse* >( &input[ 0 ] + job_sizes[ i ].second );

	futures[ i ] = std::async( run_threaded, beg_iter, end_iter );
}
If wondering, sse is just an alias for __m128i and the pair<int,int> array was left over debug code. Now that I look at it, I know the count of threads, I should have just used a C-array instead of vector like I did with the pair<int,int> array.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

AverageWhale
Posts: 57
Joined: August 13th, 2018, 2:33 pm

Re: Coding Challenge 4!

Post by AverageWhale » September 27th, 2018, 3:04 pm

Image

is this good single thread? i was doing n^2 but i made it n now using 1 thread.

Post Reply