Advertisement
Guest User

Untitled

a guest
Mar 14th, 2021
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. const std = @import("std");
  2. var allocator = std.heap.page_allocator;
  3.  
  4. const N = 1000; // number of [M]T
  5. const M = 10000; // length of each vector.
  6.  
  7. pub fn main() !void {
  8.  
  9. var vec_of_vecs = std.ArrayList([]u32).init(allocator);
  10. defer vec_of_vecs.deinit();
  11. try vec_of_vecs.ensureCapacity(@intCast(u32, N+3)) ;
  12.  
  13. var j: u32 = 0;
  14. while (j<N) : (j+=1) {
  15.  
  16. var inner_buf = try allocator.alloc(u32, M);
  17.  
  18. // This line is more or less the entire runtime length of the program.
  19. // But getting rid of the cast or writing a while loop doesn't change
  20. // anything. Does this code fail to vectorize when zig cc succeeds or
  21. // something?
  22. for (inner_buf) |_, index| inner_buf[index] = @intCast(u32, index);
  23.  
  24. vec_of_vecs.appendAssumeCapacity(inner_buf);
  25. }
  26.  
  27. for (vec_of_vecs.items) |inner_buf| {
  28. allocator.free(inner_buf);
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement