Giter Club home page Giter Club logo

rainbrot's People

Contributors

programagor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

rainbrot's Issues

Choice of last iterated point isn't deterministic

When multithreading is enabled (--threads=2 or more), all threads compete for the last point. Consider this scenario:

+-----------------------------+-------------------------+
| Thread 1                    | Thread 2                |
+-----------------------------+-------------------------+
| Gets c1 from RNG            | Waits for RNG           |
| Runs preiterator            | Gets c2 from RNG        |
| Runs preiterator            | Runs preiterator        |
| Runs preiterator            | c2 valid, runs iterator |
| c1 valid, but runs exceeded | Runs iterator           |
| Quits                       | Returns c2 orbits       |
+-----------------------------+ Quits                   |
                              +-------------------------+

Here, c1 should have been the point to be ran through the iterator because it came first from the RNG, but c2 completed the preiterator first, so it entered the iterator stage first. This results in a race condition!

This is caused by 34412b9, which enabled multiple threads searching for the last point.

Unable to run program

I recently discovered this repository and have been attempting to run it, but am not entirely sure where to start. I've attempted to run raindraw_wrapper.m using MATLAB, but that just leads to an issue where the .rain file seems to not exist, not generate, or something else entirely. I'm a novice with MATLAB, though, so this might be entirely my fault...

[20-Sep-2023 12:41:19] Iteration 1 (10-49)
[20-Sep-2023 12:41:19]   Opening file...
[20-Sep-2023 12:41:19]   Reading file...
Error using fread
Invalid file identifier. Use fopen to generate a valid file identifier.

Error in raindraw (line 12)
        t(:,:,4-i)=fread(f,dim([2,1]),'uint64');

Error in raindraw_wrapper (line 10)
raindraw(dir,iter,dim,[r;g;b],1);```

Additionally, I couldn't figure out exactly how to use any of the documentation included in the `README.md`. This might be because I couldn't figure out how to open the files and get it to work to begin with, but... Again, that's likely just me. Apologies for my unlearned-ness; I'm very interested in this program regardless of how little I can understand its machinations. 

Thanks in advance for the help.

Window is inaccurate

The --window parameter seems to produce unexpected results. The documentation specifies that it is supposed to be of the following format:

  -w, --window=RE_MIN,IM_MIN,RE_MAX,IM_MAX
                             Displayed area of the Gauss plane

However, during testing, it was found that the results are only ever consistent if -RE_MIN == RE_MAX and -IM_MIN == IM_MAX.

Iteration count seems inaccurate

It looks like the lower bound is sometimes ignored.
bin/rainbrot-gen -v --threads 1 --iter 100000,1000000 --bail 2 --window -4,-4,4,4 --size 1000x1000 --runs 1 produces a file, which after summing contains less than 100000 hits. That seems wrong.

Use a better random number generator

Use of rand() is discouraged, because the quality of the produced distribution has some undesirable characteristics. I haven't noticed any effects of that in the images, but better play it safe.

rainbrot/src/worker.c

Lines 66 to 71 in baffa37

do
{
U1=rand();
}
while(U1==0);
U2=rand();

Replace busy wait with pthread_cond_wait

This code runs just fine, but wastes resources during the last run.

rainbrot/src/worker.c

Lines 135 to 146 in eeeb936

/* TODO: Replace busy wait with lock / pthread_cond_wait */
/* Wait for arg->queue to contain zeros */
uint16_t zeros;
do
{
zeros=0;
for(uint16_t i=0;i<arg->threads;i++)
{
if(arg->queue[i]==0) zeros++;
}
}
while(zeros);

The idea is that instead of looping immediately, it waits after the check. A thread which writes into the OK Queue then broadcasts a signal, so that all threads which are waiting can recheck.

Allow adjustment to the distribution of the starting points c

Currently, the distribution of the considered points is centered at 0+0i, and has a standard deviation of 1+1i
It would be nice to allow the user to pass their own custom parameters as a command line argument.

The associated code is here:

rainbrot/src/worker.c

Lines 94 to 98 in b782af7

/* TODO: Adjustable standard deviation and mean of iterator samples */
long double a1, a2, b1, b2;
a1=b1=1;
a2=b2=0;
c=(creall(c)*a1+a2)+((long double complex)I)*(cimagl(c)*b1+b2);

Implement "Remaining time"

On top of showing progress as percentage, it would be good to estimate the remaining time of the batch. This can be done as remaining_time=remaining_runs*elapsed_time/completed_runs

Implement file locking mechanism

For each .rain file which is being accessed, create a new .rain.lock file that is destroyed after the batch has completed. This is to avoid accidentally running 2 workers on a single file. Maybe it woj't cause issues, but I'd need to look at documentation of mmap().

Allow graceful exit on ^C

Right now, the program can be interrupted while a thread is writing its buffer into the output memory/file. This results in a band visible in the output image.

Let's implement SIGTERM handling, which interrupts the worker threads only at specified points (i.e. not while writing to a file)

Segfault when not enough memory available

Probably some malloc() fails and return isn't checked against NULL. The segfault occurs after workers are started.

  - 6. worker   ... done.
All workers up and running
Segmentation fault (core dumped)

Have one mutex lock per row, instead of one per file

Currently, the entire file is locked if a row in it is being modified. This is done here:

rainbrot/src/worker.c

Lines 143 to 151 in ffd7b1c

pthread_mutex_lock(&arg->locks[k]);
for(uint32_t y=0;y< arg->im_size;y++)
{
if(buff[x][y])
{
arg->maps[k][arg->im_size*x+y]+=buff[x][y];
}
}
pthread_mutex_unlock(&arg->locks[k]);

However, it would be more efficient if each row had its own lock.

SegFault for large pictures

When using the option --window with arguments much above 400x400, a segfault occurs after a few runs (and file syncs)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.