Skip to content

Commit

Permalink
multithreaded execution, specific ArrayList
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanPreibisch committed Aug 16, 2023
1 parent 829abde commit 2484afb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Function;

import org.janelia.render.client.newsolver.blockfactories.ZBlockFactory;
Expand Down Expand Up @@ -45,7 +48,7 @@ public static void main( final String[] args ) throws IOException
"--stack", "v5_acquire_trimmed",
"--targetStack", "v5_acquire_trimmed_test",
// "--minZ", "1234",
"--maxZ", "3001",
"--maxZ", "1001",

// "--completeTargetStack",
// "--visualizeResults",
Expand Down Expand Up @@ -80,15 +83,30 @@ public static void main( final String[] args ) throws IOException
final ArrayList< ? extends AffineAlignBlockWorker<?, ?, ZBlockFactory > > workers =
solverSetup.setupSolve( cmdLineSetup.blockModel(), cmdLineSetup.stitchingModel() );

try
final ExecutorService taskExecutor = Executors.newFixedThreadPool( cmdLineSetup.threadsGlobal );

taskExecutor.submit( () ->
workers.parallelStream().forEach( worker ->
{
try
{
worker.run();
}
catch (IOException | ExecutionException | InterruptedException | NoninvertibleModelException e)
{
e.printStackTrace();
System.exit( 1 );
}
}));

taskExecutor.shutdown();

for ( final AffineAlignBlockWorker<?, ?, ZBlockFactory > worker : workers )
{
workers.get( 0 ).run();
System.out.println( workers.get( 0 ).getBlockDataList().size() );

} catch (IOException | ExecutionException | InterruptedException | NoninvertibleModelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
List<?> blockData = worker.getBlockDataList();
}

System.out.println( workers.get( 0 ).getBlockDataList().size() );
}

public < M extends Model< M > & Affine2D< M >, S extends Model< S > & Affine2D< S > >
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.janelia.render.client.newsolver.solvers;

import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;

import org.janelia.render.client.RenderDataClient;
Expand Down Expand Up @@ -58,5 +58,5 @@ public Worker(
/**
* @return - the result(s) of the solve, multiple ones if they were not connected
*/
public abstract List< BlockData< M, R, P, F > > getBlockDataList();
public abstract ArrayList< BlockData< M, R, P, F > > getBlockDataList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public class AffineAlignBlockWorker< M extends Model< M > & Affine2D< M >, S ext
//final double blockMaxAllowedError;

final AffineBlockDataWrapper< M, S, F > inputSolveItem;
private List< AffineBlockDataWrapper< M, S, F > > solveItems;
private List< BlockData< M, AffineModel2D, FIBSEMAlignmentParameters< M, S >, F > > result;
private ArrayList< AffineBlockDataWrapper< M, S, F > > solveItems;
private ArrayList< BlockData< M, AffineModel2D, FIBSEMAlignmentParameters< M, S >, F > > result;

// to filter matches
final MatchFilter matchFilter;
Expand Down Expand Up @@ -133,7 +133,7 @@ public AffineAlignBlockWorker(
}

@Override
public List< BlockData< M, AffineModel2D, FIBSEMAlignmentParameters< M, S >, F > > getBlockDataList()
public ArrayList< BlockData< M, AffineModel2D, FIBSEMAlignmentParameters< M, S >, F > > getBlockDataList()
{
return result;
}
Expand Down Expand Up @@ -837,7 +837,7 @@ protected void stitchSectionsAndCreateGroupedTiles(
}
}

protected List< AffineBlockDataWrapper< M, S, F > > splitSolveItem( final AffineBlockDataWrapper< M, S, F > inputSolveItem, final int startId )
protected ArrayList< AffineBlockDataWrapper< M, S, F > > splitSolveItem( final AffineBlockDataWrapper< M, S, F > inputSolveItem, final int startId )
{
// assigning new id's to the solve items (they collide for now with other workers, fix upon merging)
int id = startId + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -112,7 +113,7 @@ private void addFilters(final ResolvedTileSpecCollection tileSpecs, final Map<St
* @return - the result(s) of the solve, multiple ones if they were not connected
*/
@Override
public List<BlockData<M, M, FIBSEMIntensityCorrectionParameters<M>, F>> getBlockDataList() {
public ArrayList<BlockData<M, M, FIBSEMIntensityCorrectionParameters<M>, F>> getBlockDataList() {
return null;
}

Expand Down

0 comments on commit 2484afb

Please sign in to comment.