camelcdr

joined 1 year ago
 

I created this with a few friends a while ago, though I might share it here

[–] [email protected] 3 points 1 year ago (1 children)

very cool, but you forgot the trunk

 

Write a function that prints an n big tree, e.g. for n=5:

     * 
    * * 
   * * * 
  * * * * 
 * * * * * 
    | |

Here is what I came up with in C:

N,i;a(n){for(i=N=N?N:n+2;i--;printf(i?"* "+(N-n-1<i):--n?"\n":"\n%*s",N,"| |"));n&&a(n);}

// the invocation isn't part of the golf:
main(){a(5);}

PS: Code blocks currently wrap around when they are too long, I've already submitted a patch to make them scroll horizontally instead.

 

Not mine, I just found it on YouTube.

[–] [email protected] 5 points 1 year ago (1 children)

I'm not a local programming.dev resident, but I'd be interested in a code golf community.

It could be really fun to host/participate in challenge threads, and posts about some fun golfs.

[–] [email protected] 2 points 1 year ago

That's one of my favorite C videos.

[–] [email protected] 2 points 1 year ago

The critical section makes sure that only ever a single thread can execute the section at a time. So when a thread what's to execute the section, it first needs to make sure no other thread is executing it and potentially wait for the other threads to finish executing the section.

Reductions however don't induce this synchronization overhead, instead each thread executes with an independent parent value, and after the loop is done, the reduction is applied to merge all parent values. The following, is essentially what the #pragma omp parallel for reduction(min : parent) is equivalent to:

unsigned int parents[8] = {v, v, v, v, v, v, v, v};

#pragma omp parallel for num_threads(8)
for(unsigned int j = 0; j < G.Out[v]._map.bucket_count(); j++) {
	for(auto ite = G.Out[v]._map.begin(j); ite != G.Out[v]._map.end(j); ite++) {
		unsigned int w = ite->first;
		if(v > w)
			parents[omp_get_thread_num()] = min(parents[omp_get_thread_num()],w);
	}
}

unsigned int parent = v;
for (unsigned int i = 0; i < 8; ++i) {
	parent = min(parent, parents[i]);
}
[–] [email protected] 2 points 1 year ago* (last edited 1 year ago) (1 children)

I mainly use metal-archives and bandcamp. On metal-archives, I mainly use the similar artists feature, and sometimes search for specific genres from specific countries.

view more: next ›