Content-Type: |
multipart/alternative; boundary=001a11c1640a1e9fc104f224fad7 |
Sender: |
|
Subject: |
|
From: |
|
Date: |
Tue, 11 Feb 2014 23:12:15 +0530 |
In-Reply-To: |
|
MIME-Version: |
1.0 |
Reply-To: |
|
Parts/Attachments: |
|
|
Dear all
I have model that terminates on a condition rather than iterate for n time.
Then how can I parallel .
On Feb 11, 2014 10:50 PM, "Ernesto Carrella" <[log in to unmask]> wrote:
> Just to add on the previous answer.
>
> The simplest way to run the model 300 times and run each model for 10000
> steps:
>
> public static void main(String[] args){
> final int NUMBER_OF_RUNS = 300;
> final int STEPS_PER_RUN = 10000;
>
> for(int run =0; run < NUMBER_OF_RUNS; run++)
> {
> private MySimState model = new MySimState(....);
> for(int i=0; i< STEPS_PER_RUN; i++)
> model.schedule.step(model);
> }}
>
> }
>
>
> Now if you want to run it multithreaded, the simplest way to do it is this:
>
> private static class OneRunOfTheModel implements Runnable
> {
>
> @Override
> public void run() {
>
> MacroII model = new MacroII(System.currentTimeMillis());
> model.start();
> for(int i=0; i< STEPS_PER_RUN; i++)
> model.schedule.step(model);
>
> }
> }
> public static void main(String[] args) throws ExecutionException, InterruptedException {
> ExecutorService executor = Executors.newCachedThreadPool();
> List<Future> receipts = new ArrayList<>(NUMBER_OF_RUNS);
>
> for(int i=0; i< NUMBER_OF_RUNS; i++)
> {
> Future receipt = executor.submit(new OneRunOfTheModel());
> receipts.add(receipt);
> }
>
> //here we make sure every run was completed
> for(Future receipt : receipts)
> receipt.get();
>
> executor.shutdown();
> }
>
>
>
>
> Notice that this is clearly not a good way to multithread. The runnables
> are all potentially very long. Rather, you'd want the runnable to be just a
> model step and build the whole blocking queue infrastructure; but hey, one
> thing at a time.
>
> Ernesto
>
>
> On Tue, Feb 11, 2014 at 2:59 AM, Mac Van Vien <[log in to unmask]> wrote:
>
>> Hi every body,
>> I need to run MaSon model more than 300 times to take data farming.
>> Therefore, I want kick off this model one time and then it can run
>> several
>> times sequncetly or parallelly. Please show me how to do it.
>>
>> I am looking forward to here from you soon.
>>
>> Thank you very much
>>
>>
>> Your sincerely
>>
>>
>>
>> Mac Van Vien
>>
>
>
|
|
|