Hello Community, i was wondering why the Hecules isnot optimezed to use all the thread of the cpu...
Hands on that, i try by myself doing some mods at the source and got no problems while compiling and using the modified source to play, here is a example:
/src/char/char.c
original:
int mapif_sendall(unsigned char *buf, unsigned int len){ int i, c; nullpo_ret(buf); c = 0; for(i = 0; i < ARRAYLENGTH(chr->server); i++) { int fd; if ((fd = chr->server[i].fd) > 0) { WFIFOHEAD(fd,len); memcpy(WFIFOP(fd,0), buf, len); WFIFOSET(fd,len); c++; } } return c;}
parallel:
#include <omp.h>int mapif_sendall(unsigned char *buf, unsigned int len){ int i, c; nullpo_ret(buf); c = 0; #pragma omp parallel reduction(+:c) //reduction to prevent race condition on c { #pragma omp for schedule(static) //will devide i/thread for(i = 0; i < ARRAYLENGTH(chr->server); i++) { int fd; if ((fd = chr->server[i].fd) > 0) { WFIFOHEAD(fd,len); memcpy(WFIFOP(fd,0), buf, len); WFIFOSET(fd,len); c++; } } } return c;}
So... Why not use? Just by respecting some rules and including one more library we can make a very efficient code with the same code...