Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6475625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:43:37+00:00 2026-05-25T06:43:37+00:00

I have narrowed down the problem to this line: indg = nets[i]->adjlist[i].size(); // indg

  • 0

I have narrowed down the problem to this line:

    indg = nets[i]->adjlist[i].size();   // indg is in a method of the Ensemble class

Where the above variables are

    vector<DDNetwork*> nets;    // this vector is in the Ensemble class

    int indg;

    class DDNetwork
    {
        friend class Ensemble;
        ...
        public: 
            vector< vector<int> > adjlist;  // the adjacency list of the network
        ...
    };

I don’t understand why indg = nets[i]->adjlist[i].size(); would cause a segfault, is there something I am missing? Also if you need more information I can add it.

EDIT: I just realized what was wrong, I am using the same index for adjlist that I am for nets, the line

    indg = nets[i]->adjlist[i].size();

should be:

    indg = nets[i]->adjlist[j].size();

EDIT: After stepping through the debugger, I noticed that in the constructor of Ensemble, nets.size() = 10 (expected), but when the method Ensemble::alloc_dev_memory is called, nets.size() = 803384 (unexpected), so I think that JaredPar’s second suggestion might explain the problem. Here is the code that adds DDNetwork* instances into the nets variable:

    Ensemble::Ensemble(int N, float K, int S, bool seedrand, int ltype, int numNets)
    {
        this->N = N;
        this->K = K;
        this->S = S;
        this->ltype = ltype;
        this->numNets = numNets;

        if(seedrand)
            srand(time(0));

        nets.resize(numNets);    // make a vector of pointers to DDNetwork
        for(int i=0; i < numNets; ++i)
            nets[i] = new DDNetwork(N,K,S,seedrand,ltype);

        // pre-compute the S^k for k=0,1,...,Kmax
        Spow[0]=1;                  // S^0 = 1
        int k=1;
        while(k <= Kmax*2) {
            Spow[k] = S*Spow[k-1];  // S^k = S*(S^(k-1))
            ++k;
        }
    }

This constructor is called when I instantiate the ensemble variable in my main function:

    // instantiate ensemble of networks
    Ensemble ens(N, K, S, seed_rand, multiedge, numNets);
    // run_the ensemble one time step
    ens.run_gpu();

And after that, Ensemble::run_gpu calls Ensemble::alloc_dev_memory, then when nets[i]->adjlist[j].size() is called, that’s when I receive the segmentation fault.

How would the nets reference get uninitialized?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:43:38+00:00Added an answer on May 25, 2026 at 6:43 am

    I found the source of the segfault by accident, I was doing some crude debugging because GDB didn’t have information about my main.cpp file, and in order to print out nets.size(), I had to temporarily make vector<DDNetwork*> nets public, after doing that, I realized that the program didn’t segfault anymore. I thought it might have to do with the private/public distinction, but when I moved the line

    public:
        vector<DDNetwork*> nets;
    private:
    

    to

    public:
    private:
        vector<DDNetwork*> nets;
    

    line, the program still didn’t segfault, so I tried moving the line vector<DDNetwork*> nets; back to where it used to be, all the way below all of the other method and member declarations, just before the closing brace };, and the program began to segfault as before. What is it about the location of the line vector<DDNetwork*> nets; that was causing the segfault?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Demo http://people.mywot.com/dean/tour/ie6test.html I have narrowed down this problem into the test case above. You'll
I have narrowed down my problem to the mysql_connect call I am doing in
EDIT: I narrowed down the problem to the presence of the distribute==0.6.10 line in
Actually, I have a very complex problem, but I have narrowed it down here
I spoke about this in a previous question, but I have since narrowed down
With Java and Perl background, I have narrowed down the web framework choices to
This is an annoying problem I am having with Twisted.web. Basically, I have a
I have been unable to determine the cause of this problem, so I can
I have quite a complex MySQL query with a problem but I have narrowed
I have this problem i cant workaround. I cache data in serialized format in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.