Hi,
I add one function to library.cpp as below. I tried to create a ragged matrix and get the information about bonds like atoms for each bonds and types of bonds. But I got two problems.
First one is I got **copy right but not **data. The total number of items of **data is 123. The first 61 items in **data are good. But after that I got “58 -1961300264” repeated for the rest of the items. I have no idea what happened.
The second problem is to free **copy. I first followed other functions in library.cpp and used lmp->memory->destroy(copy). But somehow it has influence on the transfer of **data back to the main C code which means when printing **data in main code it is full of negative numbers or very big numbers. But if I printed out the **copy and **data in the function itself, at least half of items are right as I stated in the first problem. I also tried
free(copy[0]);
free(copy);
Still the same problem. The reason why I think the transfer problem may result from lmp->memory->destroy(copy) is because I got the same **data printed from the main code as printed from the function when I accidently delete lmp->memory->destroy(copy).
/* ----------------------------------------------------------------------
gather the bonds across all processors
type=1 bond_type[m][num_bond[m]]
type=2 bond_atom[m][num_bond[m]]
------------------------------------------------------------------------- */
void lammps_gather_ragged_bonds(void *ptr,int type,int *num, int *data, FILE fpp)
{
LAMMPS *lmp = (LAMMPS *) ptr;
int natoms = static_cast (lmp->atom->natoms);
int nbonds = static_cast (lmp->atom->nbonds);
int i,j,offset;
int **tptr = lmp->atom->bond_type;
int **aptr = lmp->atom->bond_atom;
int **array;
if (type==1) {
array = (int **)tptr;
}else {
array = (int **)aptr;
}
int **copy,*numbond;
lmp->memory->create_ragged(copy,natoms,num,“lib/gather:copy”);
for (i = 0; i < natoms; i++)
{for (j=0;j<num[i];j++)
copy[i][j] = 0;
}
int *tag = lmp->atom->tag;
int nlocal = lmp->atom->nlocal;
for (i = 0; i < nlocal; i++) {
offset = tag[i]-1;
for (j = 0; j < num[offset]; j++){
copy[offset][j] = array[i][j];
}
}
MPI_Allreduce(copy,data,nbonds,MPI_INT,MPI_SUM,lmp->world);
fprintf(fpp,“hahah: %d \n”,nbonds);
for (i = 0; i < natoms; i++) {
for (j = 0; j < num[i]; j++) {
fprintf(fpp,"%d %d \n",data[i][j],copy[i][j]);
}
}
free(copy[0]);
free(copy);
}
I will really appreciated if you can help me with this.
Best,
Yumeng