0

favorite In my testcase, I write one program like below"

define NUM_TEST 10
program test();
   bit [31:0] a[NUM_TEST]; 
   bit [31:0] b[`NUM_TEST]; 
   .... 
   initial begin 
     ..... 
     fork 
        aaa (a[0], b[0]); 
        aaa (a[1], b[1]); 
        ................ 
        aaa (a[9], b[9]); 
     join 
     ..... 
  end 
  task aaa (bit [31:0] a, bit [31:0] b); 
    ..... 
  endtask 
endmodule

As you see, I call task aaa with NUM_TEST time (I want all tasks excuted at the same time). Is there any way to reduce my code such as:

  **fork
      genvar k;
      generate
         (for k=0; k<NUM_TEST; k++) 
            aaa(a[k], b[k]); 
      endgenerate 
    join** 

(Of course, above code is wrong syntax);

FYI: I don't want to use like :

   fork 
      for (int i=0; i<`NUM_TEST; i++) 
        aaa(a[i], b[i]); 
   join 

-> this is wrong for my idea because task executed in order, not the same time.

Please help me :(

1
  • Oh, it get wrong syntax when I submit this question. My old code is : Commented Oct 20, 2016 at 1:44

1 Answer 1

3

What you want is a combination of fork/join_none and wait fork

module test;
`define NUM_TEST 10
program test();
   bit [31:0] a[`NUM_TEST]; 
   bit [31:0] b[`NUM_TEST]; 
   .... 

 initial begin 
     ..... 
       for (int i=0; i<`NUM_TEST; i++) 
         fork
            automatic int j = i;        
            aaa(a[j], b[j]); 
         join_none
       wait fork;
     ....
   end
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your answer. I want to ask about wait fork. It will wait for all fork's submit task finished. In this case, I just want to wait all tasks aaa() finished, so If I have any other fork -join-none block, does it wait for those task too?
You can put the those for loop till the wait fork; codes in another task to make sure that the wait fork only wait the aaa() threads.
@ThinhNguyenQuoc, wait fork waits for all child processes of the process that executes the wait fork statement. Do not confuse that with task or function calling as that does not create another process by itself. Child processes are only created by statements inside fork block. It just so happens that your fork statement is task call, but any procedural statement inside a fork creates a process. So @AldoT's advice is not correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.